-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Java code snippets for cuckoo filters (#3679)
* 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
1 parent
783f92e
commit b21daab
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |