Skip to content

Commit

Permalink
Added Java code snippets for Bloom #3630 (#3671)
Browse files Browse the repository at this point in the history
* Added java example for bloom filter

* Removed space

* fix and format imports

* fix compile error

* format spaces

* Add del command and rename obj

* Add del command and fix format

* change to junit assert

* Update BloomFilterExample.java

* Add correct output comment

---------

Co-authored-by: Ranjeet Singh <ranjeetsingh@192.168.1.11>
Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com>
Co-authored-by: Ranjeet Singh <ranjeetsingh@192.168.1.7>
  • Loading branch information
4 people authored Jan 13, 2024
1 parent da8e25c commit 7878e46
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/test/java/io/redis/examples/BloomFilterExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// EXAMPLE: bf_tutorial

// HIDE_START
package io.redis.examples;

import redis.clients.jedis.UnifiedJedis;
import org.junit.Test;
import org.junit.Assert;
import java.util.List;

public class BloomFilterExample {

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

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

// STEP_START bloom
String res1 = jedis.bfReserve("bikes:models", 0.01, 1000);
System.out.println(res1); // >>> OK

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

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

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

List<Boolean> res4 = jedis.bfMAdd("bikes:models",
"Rocky Mountain Racer",
"Cloudy City Cruiser",
"Windy City Wippet");
System.out.println(res4); // >>> [True, True, True]

List<Boolean> res5 = jedis.bfMExists("bikes:models",
"Rocky Mountain Racer",
"Cloudy City Cruiser",
"Windy City Wippet");
System.out.println(res5); // >>> [True, True, True]
// STEP_END
}
}

0 comments on commit 7878e46

Please sign in to comment.