Skip to content

Commit

Permalink
Support CF.MEXISTS command (#2951)
Browse files Browse the repository at this point in the history
* Support CF.MEXISTS command

* Minor: code review

Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com>

* Minor: code review

Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com>

* Minor: remove empty sequence checks

Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com>
  • Loading branch information
doumdoum and sazzad16 authored Mar 19, 2022
1 parent 44be77d commit 16cddcc
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -3567,6 +3567,11 @@ public final CommandObject<Boolean> cfExists(String key, String item) {
return new CommandObject<>(commandArguments(CuckooFilterCommand.EXISTS).key(key).add(item), BuilderFactory.BOOLEAN);
}

public final CommandObject<List<Boolean>> cfMExists(String key, String... items) {
return new CommandObject<>(commandArguments(CuckooFilterCommand.MEXISTS).key(key)
.addObjects((Object[]) items), BuilderFactory.BOOLEAN_LIST);
}

public final CommandObject<Boolean> cfDel(String key, String item) {
return new CommandObject<>(commandArguments(CuckooFilterCommand.DEL).key(key).add(item), BuilderFactory.BOOLEAN);
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/redis/clients/jedis/UnifiedJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -3975,6 +3975,11 @@ public boolean cfExists(String key, String item) {
return executeCommand(commandObjects.cfExists(key, item));
}

@Override
public List<Boolean> cfMExists(String key, String... items) {
return executeCommand(commandObjects.cfMExists(key, items));
}

@Override
public boolean cfDel(String key, String item) {
return executeCommand(commandObjects.cfDel(key, item));
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/redis/clients/jedis/bloom/CuckooFilterCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ public interface CuckooFilterCommands {
*/
boolean cfExists(String key, String item);

/**
* {@code CF.MEXISTS {key} {item ...}}
*
* @param key The name of the filter
* @param items Items to check for (non empty sequence)
* @return a list of booleans where false if the item certainly does not exist,
* true if the item may exist.
*/
List<Boolean> cfMExists(String key, String... items);

/**
* CF.DEL Deletes an item once from the filter. If the item exists only once, it
* will be removed from the filter. If the item was added multiple times, it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public enum CuckooFilterCommand implements ProtocolCommand {
INSERT("CF.INSERT"), //
INSERTNX("CF.INSERTNX"), //
EXISTS("CF.EXISTS"), //
MEXISTS("CF.MEXISTS"), //
DEL("CF.DEL"), //
COUNT("CF.COUNT"), //
SCANDUMP("CF.SCANDUMP"), //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,9 @@ public void insertExpansion() {
"o", "i", "u", "y", "t", "r", "e", "w", "q");
assertEquals(20, insert.size());
}

@Test(expected = JedisDataException.class)
public void testNoItemMExists() {
client.bfMExists("simpleBloom");
}
}
14 changes: 14 additions & 0 deletions src/test/java/redis/clients/jedis/modules/bloom/CuckooTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.junit.Assert.fail;

import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -180,12 +181,25 @@ public void testInsertNxNoCreate() {
@Test
public void testExistsItemDoesntExist() {
assertFalse(client.cfExists("cuckoo16", "foo"));
assertEquals(Collections.singletonList(false), client.cfMExists("cuckoo16", "foo"));
}

@Test
public void testExistsItemExists() {
client.cfInsert("cuckoo17", "foo");
assertTrue(client.cfExists("cuckoo17", "foo"));
assertEquals(Collections.singletonList(true), client.cfMExists("cuckoo17", "foo"));
}

@Test(expected = JedisDataException.class)
public void testNoItemMExists() {
client.cfMExists("cuckoo17");
}

@Test
public void testMixedItemsMExists() {
client.cfInsert("cuckoo18", "foo");
assertEquals(Arrays.asList(true, false), client.cfMExists("cuckoo18", "foo", "bar"));
}

@Test
Expand Down

0 comments on commit 16cddcc

Please sign in to comment.