Skip to content

Commit

Permalink
Added Java code snippets for cuckoo filters (#3679)
Browse files Browse the repository at this point in the history
* Add CuckooFilterExample

* Add step start comment

* Update CuckooFilterExample.java

---------

Co-authored-by: Ranjeet Singh <ranjeetsingh@192.168.1.7>
Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 13, 2024
1 parent 783f92e commit b21daab
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/test/java/io/redis/examples/CuckooFilterExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// EXAMPLE: cuckoo_tutorial

// HIDE_START
package io.redis.examples;

import org.junit.Assert;
import org.junit.Test;
import redis.clients.jedis.UnifiedJedis;

public class CuckooFilterExample {
@Test
public void run() {
UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379");
// HIDE_END

// REMOVE_START
jedis.del("bikes:models");
// REMOVE_END

// STEP_START cuckoo
String res1 = jedis.cfReserve("bikes:models", 1000000);
System.out.println(res1); // >>> OK

// REMOVE_START
Assert.assertEquals(res1, "OK");
// REMOVE_END

boolean res2 = jedis.cfAdd("bikes:models", "Smoky Mountain Striker");
System.out.println(res2); // >>> True

boolean res3 = jedis.cfExists("bikes:models", "Smoky Mountain Striker");
System.out.println(res3); // >>> True

boolean res4 = jedis.cfExists("bikes:models", "Terrible Bike Name");
System.out.println(res4); // >>> False

boolean res5 = jedis.cfDel("bikes:models", "Smoky Mountain Striker");
System.out.println(res5); // >>> True

// REMOVE_START
Assert.assertTrue(res5);
// REMOVE_END
// STEP_END
}
}

0 comments on commit b21daab

Please sign in to comment.