Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Java code snippets for Bloom #3630 #3671

Merged
merged 12 commits into from
Jan 13, 2024
45 changes: 45 additions & 0 deletions src/test/java/io/redis/examples/BloomFilterExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 unifiedJedis = new UnifiedJedis("redis://localhost:6379");
// HIDE_END

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

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

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

List<Boolean> res4 = unifiedJedis.bfMAdd("bikes:models",
"Rocky Mountain Racer",
"Cloudy City Cruiser",
"Windy City Wippet");
System.out.println(res4); // >>> True
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved

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

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