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
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
}
}
Loading