diff --git a/pom.xml b/pom.xml
index aee4077c83..402cd35842 100644
--- a/pom.xml
+++ b/pom.xml
@@ -127,6 +127,12 @@
${jackson.version}
test
+
+ net.javacrumbs.json-unit
+ json-unit
+ 2.38.0
+ test
+
diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsBitmapCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsBitmapCommandsTest.java
new file mode 100644
index 0000000000..5427447100
--- /dev/null
+++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsBitmapCommandsTest.java
@@ -0,0 +1,195 @@
+package redis.clients.jedis.commands.commandobjects;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.equalTo;
+
+import java.util.List;
+
+import org.junit.Test;
+import redis.clients.jedis.RedisProtocol;
+import redis.clients.jedis.args.BitCountOption;
+import redis.clients.jedis.args.BitOP;
+import redis.clients.jedis.params.BitPosParams;
+
+/**
+ * Tests related to Bitmap commands.
+ */
+public class CommandObjectsBitmapCommandsTest extends CommandObjectsStandaloneTestBase {
+
+ public CommandObjectsBitmapCommandsTest(RedisProtocol protocol) {
+ super(protocol);
+ }
+
+ @Test
+ public void testSetbitAndGetbit() {
+ String key = "bitKey";
+ long offset = 10;
+
+ Boolean initialValue = exec(commandObjects.getbit(key, offset));
+ assertThat(initialValue, equalTo(false));
+
+ Boolean setbit = exec(commandObjects.setbit(key, offset, true));
+ assertThat(setbit, equalTo(false)); // original value returned
+
+ Boolean finalValue = exec(commandObjects.getbit(key, offset));
+ assertThat(finalValue, equalTo(true));
+ }
+
+ @Test
+ public void testSetbitAndGetbitBinary() {
+ byte[] key = "bitKeyBytes".getBytes();
+ long offset = 10;
+
+ Boolean initialValue = exec(commandObjects.getbit(key, offset));
+ assertThat(initialValue, equalTo(false));
+
+ Boolean setbit = exec(commandObjects.setbit(key, offset, true));
+ assertThat(setbit, equalTo(false)); // original value returned
+
+ Boolean finalValue = exec(commandObjects.getbit(key, offset));
+ assertThat(finalValue, equalTo(true));
+ }
+
+ @Test
+ public void testBitcount() {
+ String key = "bitcountKey";
+ byte[] keyBytes = key.getBytes();
+
+ // Set some bits
+ exec(commandObjects.setbit(key, 1, true));
+ exec(commandObjects.setbit(key, 2, true));
+ exec(commandObjects.setbit(key, 7, true)); // This makes 1 byte with 3 bits set
+ exec(commandObjects.setbit(key, 8, true)); // Next byte, first bit set
+
+ Long bitcountFullString = exec(commandObjects.bitcount(key));
+ assertThat(bitcountFullString, equalTo(4L));
+
+ Long bitcountFirstByte = exec(commandObjects.bitcount(key, 0, 0));
+ assertThat(bitcountFirstByte, equalTo(3L));
+
+ Long bitcountFullStringBinary = exec(commandObjects.bitcount(keyBytes));
+ assertThat(bitcountFullStringBinary, equalTo(4L));
+
+ Long bitcountFirstByteBinary = exec(commandObjects.bitcount(keyBytes, 0, 0));
+ assertThat(bitcountFirstByteBinary, equalTo(3L));
+
+ Long bitcountFirstSixBits = exec(commandObjects.bitcount(key, 0, 5, BitCountOption.BIT));
+ assertThat(bitcountFirstSixBits, equalTo(2L));
+
+ Long bitcountFirstSixBitsBinary = exec(commandObjects.bitcount(keyBytes, 0, 5, BitCountOption.BIT));
+ assertThat(bitcountFirstSixBitsBinary, equalTo(2L));
+ }
+
+ @Test
+ public void testBitpos() {
+ String key = "bitposKey";
+ byte[] keyBytes = key.getBytes();
+
+ // Set some bits
+ exec(commandObjects.setbit(key, 10, true));
+ exec(commandObjects.setbit(key, 22, true));
+ exec(commandObjects.setbit(key, 30, true));
+
+ Long firstSetBit = exec(commandObjects.bitpos(key, true));
+ assertThat(firstSetBit, equalTo(10L));
+
+ Long firstUnsetBit = exec(commandObjects.bitpos(key, false));
+ assertThat(firstUnsetBit, equalTo(0L));
+
+ BitPosParams params = new BitPosParams(15, 25).modifier(BitCountOption.BIT);
+
+ Long firstSetBitInRange = exec(commandObjects.bitpos(key, true, params));
+ assertThat(firstSetBitInRange, equalTo(22L));
+
+ Long firstUnsetBitInRange = exec(commandObjects.bitpos(key, false, params));
+ assertThat(firstUnsetBitInRange, equalTo(15L));
+
+ Long firstSetBitBinary = exec(commandObjects.bitpos(keyBytes, true));
+ assertThat(firstSetBitBinary, equalTo(10L));
+
+ Long firstUnsetBitBinary = exec(commandObjects.bitpos(keyBytes, false));
+ assertThat(firstUnsetBitBinary, equalTo(0L));
+
+ Long firstSetBitInRangeBinary = exec(commandObjects.bitpos(keyBytes, true, params));
+ assertThat(firstSetBitInRangeBinary, equalTo(22L));
+
+ Long firstUnsetBitInRangeBinary = exec(commandObjects.bitpos(keyBytes, false, params));
+ assertThat(firstUnsetBitInRangeBinary, equalTo(15L));
+ }
+
+ @Test
+ public void testBitfield() {
+ String key = "bitfieldKey";
+
+ List bitfieldResult = exec(commandObjects.bitfield(
+ key, "INCRBY", "i5", "100", "7", "GET", "i5", "100"));
+
+ // Contains the result of the INCRBY operation, and the result of the GET operation.
+ assertThat(bitfieldResult, contains(7L, 7L));
+
+ List bitfieldRoResult = exec(commandObjects.bitfieldReadonly(
+ key, "GET", "i4", "100"));
+ assertThat(bitfieldRoResult, contains(3L));
+ }
+
+ @Test
+ public void testBitfieldBinary() {
+ byte[] key = "bitfieldKeyBytes".getBytes();
+
+ List bitfieldResult = exec(commandObjects.bitfield(key,
+ "INCRBY".getBytes(), "i5".getBytes(), "100".getBytes(), "7".getBytes(),
+ "GET".getBytes(), "i5".getBytes(), "100".getBytes()));
+
+ // Contains the result of the INCRBY operation, and the result of the GET operation.
+ assertThat(bitfieldResult, contains(7L, 7L));
+
+ List bitfieldRoResult = exec(commandObjects.bitfieldReadonly(key,
+ "GET".getBytes(), "i4".getBytes(), "100".getBytes()));
+ assertThat(bitfieldRoResult, contains(3L));
+ }
+
+ @Test
+ public void testBitop() {
+ String srcKey1 = "srcKey1";
+ String srcKey2 = "srcKey2";
+ String destKey = "destKey";
+
+ // Set some bits
+ exec(commandObjects.setbit(srcKey1, 1, true));
+ exec(commandObjects.setbit(srcKey1, 2, true));
+ exec(commandObjects.setbit(srcKey1, 3, true));
+
+ exec(commandObjects.setbit(srcKey2, 1, true));
+ exec(commandObjects.setbit(srcKey2, 3, true));
+
+ Long bitopResult = exec(commandObjects.bitop(BitOP.AND, destKey, srcKey1, srcKey2));
+ assertThat(bitopResult, equalTo(1L)); // 1 byte stored
+
+ assertThat(exec(commandObjects.getbit(destKey, 1)), equalTo(true));
+ assertThat(exec(commandObjects.getbit(destKey, 2)), equalTo(false));
+ assertThat(exec(commandObjects.getbit(destKey, 3)), equalTo(true));
+ }
+
+ @Test
+ public void testBitopBinary() {
+ byte[] srcKey1 = "srcKey1".getBytes();
+ byte[] srcKey2 = "srcKey2".getBytes();
+ byte[] destKey = "destKey".getBytes();
+
+ // Set some bits
+ exec(commandObjects.setbit(srcKey1, 1, true));
+ exec(commandObjects.setbit(srcKey1, 2, true));
+ exec(commandObjects.setbit(srcKey1, 3, true));
+
+ exec(commandObjects.setbit(srcKey2, 1, true));
+ exec(commandObjects.setbit(srcKey2, 3, true));
+
+ Long bitopResult = exec(commandObjects.bitop(BitOP.XOR, destKey, srcKey1, srcKey2));
+ assertThat(bitopResult, equalTo(1L)); // 1 byte stored
+
+ assertThat(exec(commandObjects.getbit(new String(destKey), 1)), equalTo(false));
+ assertThat(exec(commandObjects.getbit(new String(destKey), 2)), equalTo(true));
+ assertThat(exec(commandObjects.getbit(new String(destKey), 3)), equalTo(false));
+ }
+}
diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsBloomFilterCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsBloomFilterCommandsTest.java
new file mode 100644
index 0000000000..a69bd8b68e
--- /dev/null
+++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsBloomFilterCommandsTest.java
@@ -0,0 +1,138 @@
+package redis.clients.jedis.commands.commandobjects;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasEntry;
+import static org.hamcrest.Matchers.notNullValue;
+
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import redis.clients.jedis.RedisProtocol;
+import redis.clients.jedis.bloom.BFInsertParams;
+import redis.clients.jedis.bloom.BFReserveParams;
+
+/**
+ * Tests related to Bloom Filter commands.
+ */
+public class CommandObjectsBloomFilterCommandsTest extends CommandObjectsModulesTestBase {
+
+ public CommandObjectsBloomFilterCommandsTest(RedisProtocol protocol) {
+ super(protocol);
+ }
+
+ @Test
+ public void testBfAddAndExists() {
+ String key = "testBf";
+
+ String reserve = exec(commandObjects.bfReserve(key, 0.01, 1000));
+ assertThat(reserve, equalTo("OK"));
+
+ boolean add = exec(commandObjects.bfAdd(key, "item1"));
+ assertThat(add, equalTo(true));
+
+ boolean exists = exec(commandObjects.bfExists(key, "item1"));
+ assertThat(exists, equalTo(true));
+
+ boolean notExists = exec(commandObjects.bfExists(key, "item2"));
+ assertThat(notExists, equalTo(false));
+ }
+
+ @Test
+ public void testBfInsert() {
+ String key = "testBf";
+
+ String reserve = exec(commandObjects.bfReserve(key, 0.01, 1000));
+ assertThat(reserve, equalTo("OK"));
+
+ List insert = exec(commandObjects.bfInsert(key, "item1", "item2"));
+ assertThat(insert, contains(true, true));
+
+ BFInsertParams insertParams = new BFInsertParams().noCreate().capacity(1000);
+
+ List insertWithParams = exec(commandObjects.bfInsert(key, insertParams, "item1", "item2"));
+ assertThat(insertWithParams, contains(false, false));
+
+ assertThat(exec(commandObjects.bfExists(key, "item1")), equalTo(true));
+ assertThat(exec(commandObjects.bfExists(key, "item2")), equalTo(true));
+ assertThat(exec(commandObjects.bfExists(key, "item3")), equalTo(false));
+ }
+
+ @Test
+ public void testBfMAddMExistsAndCard() {
+ String key = "testBf";
+
+ String reserve = exec(commandObjects.bfReserve(key, 0.01, 1000));
+ assertThat(reserve, equalTo("OK"));
+
+ List mAdd = exec(commandObjects.bfMAdd(key, "item1", "item2", "item3"));
+ assertThat(mAdd, contains(true, true, true));
+
+ List mExists = exec(commandObjects.bfMExists(key, "item1", "item2", "item3", "item4"));
+ assertThat(mExists, contains(true, true, true, false));
+
+ Long card = exec(commandObjects.bfCard(key));
+ assertThat(card, equalTo(3L));
+ }
+
+ @Test
+ public void testBfScanDumpAndLoadChunk() {
+ String key = "test";
+
+ String reserve = exec(commandObjects.bfReserve(key, 0.01, 5000));
+ assertThat(reserve, equalTo("OK"));
+
+ for (int i = 0; i < 1000; i++) {
+ Boolean add = exec(commandObjects.bfAdd(key, "item" + i));
+ assertThat(add, equalTo(true));
+ }
+
+ String newKey = "testBfLoadChunk";
+
+ long iterator = 0;
+ do {
+ Map.Entry scanDumpResult = exec(commandObjects.bfScanDump(key, iterator));
+
+ iterator = scanDumpResult.getKey();
+
+ if (iterator > 0) {
+ byte[] data = scanDumpResult.getValue();
+
+ assertThat(data, notNullValue());
+
+ String loadChunk = exec(commandObjects.bfLoadChunk(newKey, iterator, data));
+ assertThat(loadChunk, equalTo("OK"));
+ }
+ } while (iterator != 0);
+
+ // verify destination
+ for (int i = 0; i < 1000; i++) {
+ Boolean exists = exec(commandObjects.bfExists(newKey, "item" + i));
+ assertThat(exists, equalTo(true));
+ }
+
+ Boolean missingItem = exec(commandObjects.bfExists(newKey, "item1001"));
+ assertThat(missingItem, equalTo(false));
+ }
+
+ @Test
+ public void testBfInfo() {
+ String key = "testBf";
+
+ double errorRate = 0.01;
+ long capacity = 1000;
+ BFReserveParams reserveParams = new BFReserveParams().expansion(2);
+
+ String reserve = exec(commandObjects.bfReserve(key, errorRate, capacity, reserveParams));
+ assertThat(reserve, equalTo("OK"));
+
+ Boolean add = exec(commandObjects.bfAdd(key, "item1"));
+ assertThat(add, equalTo(true));
+
+ Map info = exec(commandObjects.bfInfo(key));
+ assertThat(info, hasEntry("Capacity", 1000L));
+ assertThat(info, hasEntry("Number of items inserted", 1L));
+ }
+}
diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsCountMinSketchCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsCountMinSketchCommandsTest.java
new file mode 100644
index 0000000000..c1be92acb4
--- /dev/null
+++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsCountMinSketchCommandsTest.java
@@ -0,0 +1,203 @@
+package redis.clients.jedis.commands.commandobjects;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.hamcrest.Matchers.hasEntry;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.lessThanOrEqualTo;
+import static org.hamcrest.Matchers.notNullValue;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import redis.clients.jedis.RedisProtocol;
+
+/**
+ * Tests related to Count-min sketch commands.
+ */
+public class CommandObjectsCountMinSketchCommandsTest extends CommandObjectsModulesTestBase {
+
+ public CommandObjectsCountMinSketchCommandsTest(RedisProtocol protocol) {
+ super(protocol);
+ }
+
+ @Test
+ public void testIncrByAndQuery() {
+ String key = "testCMS";
+
+ String init = exec(commandObjects.cmsInitByDim(key, 10000, 5));
+ assertThat(init, equalTo("OK"));
+
+ Map itemIncrements = new HashMap<>();
+ itemIncrements.put("apple", 30L);
+ itemIncrements.put("banana", 20L);
+ itemIncrements.put("carrot", 10L);
+
+ List incrBy = exec(commandObjects.cmsIncrBy(key, itemIncrements));
+ // due to Map's unpredictable order, we can't assert ordering of the result
+ assertThat(incrBy, containsInAnyOrder(10L, 20L, 30L));
+
+ List query = exec(commandObjects.cmsQuery(key, "apple", "banana", "carrot", "date"));
+
+ assertThat(query, notNullValue());
+ assertThat(query.size(), equalTo(4));
+
+ assertThat(query.get(0), greaterThanOrEqualTo(30L)); // apple
+ assertThat(query.get(1), greaterThanOrEqualTo(20L)); // banana
+ assertThat(query.get(2), greaterThanOrEqualTo(10L)); // carrot
+ assertThat(query.get(3), lessThanOrEqualTo(1L)); // date, in practice, could be >0 due to estimation error
+ }
+
+ @Test
+ public void testCMSInitByProb() {
+ String key = "testCMS";
+
+ String init = exec(commandObjects.cmsInitByProb(key, 0.01, 0.99));
+ assertThat(init, equalTo("OK"));
+
+ Map itemIncrements = new HashMap<>();
+ itemIncrements.put("apple", 5L);
+ itemIncrements.put("banana", 3L);
+ itemIncrements.put("carrot", 8L);
+
+ List incrBy = exec(commandObjects.cmsIncrBy(key, itemIncrements));
+ assertThat(incrBy, containsInAnyOrder(3L, 5L, 8L));
+
+ List query = exec(commandObjects.cmsQuery(key, "apple", "banana", "carrot", "dragonfruit"));
+
+ assertThat(query, notNullValue());
+ assertThat(query.size(), equalTo(4));
+
+ assertThat(query.get(0), greaterThanOrEqualTo(5L)); // apple
+ assertThat(query.get(1), greaterThanOrEqualTo(3L)); // banana
+ assertThat(query.get(2), greaterThanOrEqualTo(8L)); // carrot
+ // "dragonfruit" was not incremented, its count should be minimal, but due to the probabilistic nature of CMS, it might not be exactly 0.
+ assertThat(query.get(3), lessThanOrEqualTo(1L));
+ }
+
+ @Test
+ public void testCMSMerge() {
+ String cmsKey1 = "testCMS1";
+ String cmsKey2 = "testCMS2";
+ String cmsDestKey = "testCMSMerged";
+
+ long width = 10000;
+ long depth = 5;
+
+ String init1 = exec(commandObjects.cmsInitByDim(cmsKey1, width, depth));
+ assertThat(init1, equalTo("OK"));
+
+ String init2 = exec(commandObjects.cmsInitByDim(cmsKey2, width, depth));
+ assertThat(init2, equalTo("OK"));
+
+ Map itemIncrements1 = new HashMap<>();
+ itemIncrements1.put("apple", 2L);
+ itemIncrements1.put("banana", 3L);
+
+ List incrBy1 = exec(commandObjects.cmsIncrBy(cmsKey1, itemIncrements1));
+ assertThat(incrBy1, containsInAnyOrder(2L, 3L));
+
+ Map itemIncrements2 = new HashMap<>();
+ itemIncrements2.put("carrot", 5L);
+ itemIncrements2.put("date", 4L);
+
+ List incrBy2 = exec(commandObjects.cmsIncrBy(cmsKey2, itemIncrements2));
+ assertThat(incrBy2, containsInAnyOrder(4L, 5L));
+
+ String init3 = exec(commandObjects.cmsInitByDim(cmsDestKey, width, depth));
+ assertThat(init3, equalTo("OK"));
+
+ String merge = exec(commandObjects.cmsMerge(cmsDestKey, cmsKey1, cmsKey2));
+ assertThat(merge, equalTo("OK"));
+
+ List query = exec(commandObjects.cmsQuery(cmsDestKey, "apple", "banana", "carrot", "date"));
+
+ assertThat(query, notNullValue());
+ assertThat(query.size(), equalTo(4));
+
+ assertThat(query.get(0), greaterThanOrEqualTo(2L)); // apple
+ assertThat(query.get(1), greaterThanOrEqualTo(3L)); // banana
+ assertThat(query.get(2), greaterThanOrEqualTo(5L)); // carrot
+ assertThat(query.get(3), greaterThanOrEqualTo(4L)); // date
+ }
+
+ @Test
+ public void testCMSMergeWithWeights() {
+ String cmsKey1 = "testCMS1";
+ String cmsKey2 = "testCMS2";
+ String cmsDestKey = "testCMSMerged";
+
+ long width = 10000;
+ long depth = 5;
+
+ String init1 = exec(commandObjects.cmsInitByDim(cmsKey1, width, depth));
+ assertThat(init1, equalTo("OK"));
+
+ String init2 = exec(commandObjects.cmsInitByDim(cmsKey2, width, depth));
+ assertThat(init2, equalTo("OK"));
+
+ Map itemIncrements1 = new HashMap<>();
+ itemIncrements1.put("apple", 2L);
+ itemIncrements1.put("banana", 3L);
+
+ List incrBy1 = exec(commandObjects.cmsIncrBy(cmsKey1, itemIncrements1));
+ assertThat(incrBy1, containsInAnyOrder(2L, 3L));
+
+ Map itemIncrements2 = new HashMap<>();
+ itemIncrements2.put("carrot", 5L);
+ itemIncrements2.put("date", 4L);
+
+ List incrBy2 = exec(commandObjects.cmsIncrBy(cmsKey2, itemIncrements2));
+ assertThat(incrBy2, containsInAnyOrder(4L, 5L));
+
+ String init3 = exec(commandObjects.cmsInitByDim(cmsDestKey, width, depth));
+ assertThat(init3, equalTo("OK"));
+
+ // Weights for the CMS keys to be merged
+ Map keysAndWeights = new HashMap<>();
+ keysAndWeights.put(cmsKey1, 1L);
+ keysAndWeights.put(cmsKey2, 2L);
+
+ String merge = exec(commandObjects.cmsMerge(cmsDestKey, keysAndWeights));
+ assertThat(merge, equalTo("OK"));
+
+ List query = exec(commandObjects.cmsQuery(cmsDestKey, "apple", "banana", "carrot", "date"));
+
+ assertThat(query, notNullValue());
+ assertThat(query.size(), equalTo(4));
+
+ assertThat(query.get(0), greaterThanOrEqualTo(2L)); // apple, weight of 1
+ assertThat(query.get(1), greaterThanOrEqualTo(3L)); // banana, weight of 1
+ assertThat(query.get(2), greaterThanOrEqualTo(10L)); // carrot, weight of 2, so 5 * 2
+ assertThat(query.get(3), greaterThanOrEqualTo(8L)); // date, weight of 2, so 4 * 2
+ }
+
+ @Test
+ public void testCMSInfo() {
+ String key = "testCMS";
+
+ long width = 10000;
+ long depth = 5;
+
+ String init = exec(commandObjects.cmsInitByDim(key, width, depth));
+ assertThat(init, equalTo("OK"));
+
+ Map itemIncrements = new HashMap<>();
+ itemIncrements.put("apple", 3L);
+ itemIncrements.put("banana", 2L);
+ itemIncrements.put("carrot", 1L);
+
+ List incrBy = exec(commandObjects.cmsIncrBy(key, itemIncrements));
+ assertThat(incrBy, hasSize(3));
+
+ Map info = exec(commandObjects.cmsInfo(key));
+
+ assertThat(info, hasEntry("width", 10000L));
+ assertThat(info, hasEntry("depth", 5L));
+ assertThat(info, hasEntry("count", 6L)); // 3 + 2 + 1
+ }
+}
diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsCuckooFilterCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsCuckooFilterCommandsTest.java
new file mode 100644
index 0000000000..68bc9b7060
--- /dev/null
+++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsCuckooFilterCommandsTest.java
@@ -0,0 +1,192 @@
+package redis.clients.jedis.commands.commandobjects;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.everyItem;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.hamcrest.Matchers.hasEntry;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.notNullValue;
+
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import redis.clients.jedis.RedisProtocol;
+import redis.clients.jedis.bloom.CFInsertParams;
+import redis.clients.jedis.bloom.CFReserveParams;
+
+/**
+ * Tests related to Cuckoo filter commands.
+ */
+public class CommandObjectsCuckooFilterCommandsTest extends CommandObjectsModulesTestBase {
+
+ public CommandObjectsCuckooFilterCommandsTest(RedisProtocol protocol) {
+ super(protocol);
+ }
+
+ @Test
+ public void testCuckooFilterAdd() {
+ String key = "testCuckooFilter";
+
+ String reserve = exec(commandObjects.cfReserve(key, 1000));
+ assertThat(reserve, equalTo("OK"));
+
+ Boolean add = exec(commandObjects.cfAdd(key, "apple"));
+ assertThat(add, equalTo(true));
+
+ Boolean addNx = exec(commandObjects.cfAddNx(key, "apple"));
+ assertThat(addNx, equalTo(false)); // "apple" already exists, NX makes this fail
+
+ Boolean addNx2 = exec(commandObjects.cfAddNx(key, "banana"));
+ assertThat(addNx2, equalTo(true));
+
+ Long count = exec(commandObjects.cfCount(key, "apple"));
+ assertThat(count, greaterThanOrEqualTo(1L));
+ }
+
+ @Test
+ public void testCuckooFilterReserveInsertAndCount() {
+ String key = "testCuckooFilterAdvanced";
+
+ CFReserveParams reserveParams = new CFReserveParams()
+ .bucketSize(4).maxIterations(500).expansion(1);
+
+ String reserve = exec(commandObjects.cfReserve(key, 5000, reserveParams));
+ assertThat(reserve, equalTo("OK"));
+
+ List insert = exec(commandObjects.cfInsert(
+ key, "apple", "banana", "carrot", "date"));
+ assertThat(insert, everyItem(equalTo(true)));
+
+ CFInsertParams insertParams = new CFInsertParams().noCreate();
+
+ List insertWithParams = exec(commandObjects.cfInsert(
+ key, insertParams, "eggplant", "fig", "grape", "apple"));
+ assertThat(insertWithParams, everyItem(equalTo(true)));
+
+ Long countApple = exec(commandObjects.cfCount(key, "apple"));
+ assertThat(countApple, greaterThanOrEqualTo(2L));
+
+ Long countBanana = exec(commandObjects.cfCount(key, "banana"));
+ assertThat(countBanana, greaterThanOrEqualTo(1L));
+
+ Long countNonExisting = exec(commandObjects.cfCount(key, "watermelon"));
+ assertThat(countNonExisting, equalTo(0L));
+ }
+
+ @Test
+ public void testCuckooFilterInsertNx() {
+ String key = "testCf";
+
+ String[] items = { "item1", "item2", "item3" };
+
+ CFInsertParams insertParams = new CFInsertParams().capacity(1000L).noCreate();
+
+ List insertNx1 = exec(commandObjects.cfInsertNx(key, items));
+ assertThat(insertNx1, not(empty()));
+ assertThat(insertNx1, everyItem(equalTo(true)));
+
+ long countAfterFirstInsert = exec(commandObjects.cfCount(key, "item1"));
+ assertThat(countAfterFirstInsert, greaterThanOrEqualTo(1L));
+
+ List insertNx2 = exec(commandObjects.cfInsertNx(key, insertParams, items));
+ assertThat(insertNx2, not(empty()));
+ assertThat(insertNx2, everyItem(equalTo(false)));
+
+ long countAfterSecondInsert = exec(commandObjects.cfCount(key, "item1"));
+ assertThat(countAfterSecondInsert, greaterThanOrEqualTo(1L)); // count should remain the same
+ }
+
+ @Test
+ public void testCuckooFilterExistsAndDel() {
+ String key = "testCf";
+ String item = "item1";
+
+ boolean existsBeforeInsert = exec(commandObjects.cfExists(key, item));
+ assertThat(existsBeforeInsert, equalTo(false));
+
+ Boolean add = exec(commandObjects.cfAdd(key, item));
+ assertThat(add, equalTo(true));
+
+ boolean existsAfterInsert = exec(commandObjects.cfExists(key, item));
+ assertThat(existsAfterInsert, equalTo(true));
+
+ boolean delete = exec(commandObjects.cfDel(key, item));
+ assertThat(delete, equalTo(true));
+
+ boolean existsAfterDelete = exec(commandObjects.cfExists(key, item));
+ assertThat(existsAfterDelete, equalTo(false));
+ }
+
+ @Test
+ public void testCuckooFilterMExists() {
+ String key = "testCf";
+
+ exec(commandObjects.cfInsert(key, "item1", "item2", "item3"));
+
+ List mExists = exec(commandObjects.cfMExists(
+ key, "item1", "item2", "item3", "item4", "item5"));
+
+ assertThat(mExists, contains(true, true, true, false, false));
+ }
+
+ @Test
+ public void testCuckooFilterScanDumpAndLoadChunk() {
+ long capacity = 5000;
+
+ CFReserveParams reserveParams = new CFReserveParams()
+ .bucketSize(4).maxIterations(500).expansion(1);
+
+ String key = "testCf";
+
+ String reserve = exec(commandObjects.cfReserve(key, capacity, reserveParams));
+ assertThat(reserve, equalTo("OK"));
+
+ // add some items to the source
+ for (int i = 0; i < 1000; i++) {
+ exec(commandObjects.cfAdd(key, "item" + i));
+ }
+
+ String newKey = "testCfLoadChunk";
+
+ // scandump and load
+ long iterator = 0;
+ do {
+ Map.Entry scanDumpResult = exec(commandObjects.cfScanDump(key, iterator));
+
+ iterator = scanDumpResult.getKey();
+ if (iterator > 0) {
+ byte[] data = scanDumpResult.getValue();
+ assertThat(data, notNullValue());
+
+ String loadChunk = exec(commandObjects.cfLoadChunk(newKey, iterator, data));
+ assertThat(loadChunk, equalTo("OK"));
+ }
+ } while (iterator != 0);
+
+ // verify destination
+ for (int i = 0; i < 1000; i++) {
+ boolean exists = exec(commandObjects.cfExists(newKey, "item" + i));
+ assertThat(exists, equalTo(true));
+ }
+
+ boolean missingItem = exec(commandObjects.cfExists(newKey, "item1001"));
+ assertThat(missingItem, equalTo(false));
+ }
+
+ @Test
+ public void testCuckooFilterInfo() {
+ String key = "testCfInfo";
+
+ exec(commandObjects.cfReserve(key, 1000));
+
+ exec(commandObjects.cfAdd(key, "item1"));
+
+ Map info = exec(commandObjects.cfInfo(key));
+
+ assertThat(info, hasEntry("Number of items inserted", 1L));
+ }
+}
diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsGenericCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsGenericCommandsTest.java
new file mode 100644
index 0000000000..0182de207f
--- /dev/null
+++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsGenericCommandsTest.java
@@ -0,0 +1,81 @@
+package redis.clients.jedis.commands.commandobjects;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+
+import org.junit.Test;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.RedisProtocol;
+
+/**
+ * Tests related to Generic commands.
+ */
+public class CommandObjectsGenericCommandsTest extends CommandObjectsStandaloneTestBase {
+
+ public CommandObjectsGenericCommandsTest(RedisProtocol protocol) {
+ super(protocol);
+ }
+
+ @Test
+ public void testCopy() {
+ String srcKey = "sourceKey";
+ String dstKey = "destinationKey";
+ int dstDB = 1;
+
+ exec(commandObjects.set(srcKey, "initialValue"));
+
+ Boolean existsAfterSet = exec(commandObjects.exists(srcKey));
+ assertThat(existsAfterSet, equalTo(true));
+
+ Boolean copy = exec(commandObjects.copy(srcKey, dstKey, dstDB, true));
+ assertThat(copy, equalTo(true));
+
+ assertKeyExists(dstDB, dstKey, "initialValue");
+
+ // Update source
+ exec(commandObjects.set(srcKey, "newValue"));
+
+ // Copy again without replace, it fails since dstKey already exists
+ Boolean secondCopy = exec(commandObjects.copy(srcKey, dstKey, dstDB, false));
+ assertThat(secondCopy, equalTo(false));
+
+ assertKeyExists(dstDB, dstKey, "initialValue");
+ }
+
+ @Test
+ public void testCopyBinary() {
+ String srcKey = "sourceKey";
+ String dstKey = "destinationKey";
+ int dstDB = 1;
+
+ exec(commandObjects.set(srcKey, "initialValue"));
+
+ Boolean existsAfterSet = exec(commandObjects.exists(srcKey));
+ assertThat(existsAfterSet, equalTo(true));
+
+ Boolean copy = exec(commandObjects.copy(
+ srcKey.getBytes(), dstKey.getBytes(), dstDB, true));
+ assertThat(copy, equalTo(true));
+
+ assertKeyExists(dstDB, dstKey, "initialValue");
+
+ // Update source
+ exec(commandObjects.set(srcKey, "newValue"));
+
+ // Copy again without replace, it will fail
+ Boolean secondCopy = exec(commandObjects.copy(srcKey.getBytes(), dstKey.getBytes(), dstDB, false));
+ assertThat(secondCopy, equalTo(false));
+
+ assertKeyExists(dstDB, dstKey, "initialValue");
+ }
+
+ private void assertKeyExists(int dstDb, String key, Object expectedValue) {
+ // Cheat and use Jedis, it gives us access to any db.
+ try (Jedis jedis = new Jedis(nodeInfo)) {
+ jedis.auth("foobared");
+ jedis.select(dstDb);
+ assertThat(jedis.get(key), equalTo(expectedValue));
+ }
+ }
+
+}
diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsGeospatialCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsGeospatialCommandsTest.java
new file mode 100644
index 0000000000..bcdcd54092
--- /dev/null
+++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsGeospatialCommandsTest.java
@@ -0,0 +1,701 @@
+package redis.clients.jedis.commands.commandobjects;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.closeTo;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import org.junit.Test;
+import redis.clients.jedis.GeoCoordinate;
+import redis.clients.jedis.RedisProtocol;
+import redis.clients.jedis.args.GeoUnit;
+import redis.clients.jedis.params.GeoAddParams;
+import redis.clients.jedis.params.GeoRadiusParam;
+import redis.clients.jedis.params.GeoRadiusStoreParam;
+import redis.clients.jedis.params.GeoSearchParam;
+import redis.clients.jedis.resps.GeoRadiusResponse;
+
+/**
+ * Tests related to Geospatial commands.
+ */
+public class CommandObjectsGeospatialCommandsTest extends CommandObjectsStandaloneTestBase {
+
+ // Some coordinates for testing
+ public static final String CATANIA = "Catania";
+ public static final double CATANIA_LATITUDE = 37.502669;
+ public static final double CATANIA_LONGITUDE = 15.087269;
+
+ public static final String PALERMO = "Palermo";
+ public static final double PALERMO_LONGITUDE = 13.361389;
+ public static final double PALERMO_LATITUDE = 38.115556;
+
+ public static final String SYRACUSE = "Syracuse";
+ public static final double SYRACUSE_LONGITUDE = 15.293331;
+ public static final double SYRACUSE_LATITUDE = 37.075474;
+
+ public static final String AGRIGENTO = "Agrigento";
+ public static final double AGRIGENTO_LONGITUDE = 13.583333;
+ public static final double AGRIGENTO_LATITUDE = 37.316667;
+
+ public CommandObjectsGeospatialCommandsTest(RedisProtocol protocol) {
+ super(protocol);
+ }
+
+ @Test
+ public void testGeoAddAndRadius() {
+ String key = "locations";
+
+ Map cataniaCoordinates = new HashMap<>();
+ cataniaCoordinates.put(CATANIA, new GeoCoordinate(CATANIA_LONGITUDE, CATANIA_LATITUDE));
+
+ Map syracuseCoordinates = new HashMap<>();
+ syracuseCoordinates.put(SYRACUSE, new GeoCoordinate(SYRACUSE_LONGITUDE, SYRACUSE_LATITUDE));
+
+ Long addPalermo = exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO));
+ assertThat(addPalermo, equalTo(1L));
+
+ List radiusFromPalermo = exec(commandObjects.georadius(
+ key, PALERMO_LONGITUDE, PALERMO_LATITUDE, 100, GeoUnit.KM));
+ assertThat(radiusFromPalermo.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ contains(equalTo(PALERMO)));
+
+ Long addCatania = exec(commandObjects.geoadd(key, cataniaCoordinates));
+ assertThat(addCatania, equalTo(1L));
+
+ List radiusFromCatania = exec(commandObjects.georadius(
+ key, CATANIA_LONGITUDE, CATANIA_LATITUDE, 100, GeoUnit.KM));
+ assertThat(radiusFromCatania.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ contains(equalTo(CATANIA)));
+
+ Long addSyracuse = exec(commandObjects.geoadd(key, GeoAddParams.geoAddParams().nx(), syracuseCoordinates));
+ assertThat(addSyracuse, equalTo(1L));
+
+ List radiusEverything = exec(commandObjects.georadius(
+ key, 15, 37, 200, GeoUnit.KM));
+ assertThat(radiusEverything.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(equalTo(CATANIA), equalTo(SYRACUSE), equalTo(PALERMO)));
+ }
+
+ @Test
+ public void testGeoAddAndRadiusBinary() {
+ byte[] key = "locations".getBytes();
+
+ Map cataniaCoordinates = new HashMap<>();
+ cataniaCoordinates.put(CATANIA.getBytes(), new GeoCoordinate(CATANIA_LONGITUDE, CATANIA_LATITUDE));
+
+ Map syracuseCoordinates = new HashMap<>();
+ syracuseCoordinates.put(SYRACUSE.getBytes(), new GeoCoordinate(SYRACUSE_LONGITUDE, SYRACUSE_LATITUDE));
+
+ Long addPalermo = exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO.getBytes()));
+ assertThat(addPalermo, equalTo(1L));
+
+ List radiusFromPalermo = exec(commandObjects.georadius(
+ key, PALERMO_LONGITUDE, PALERMO_LATITUDE, 100, GeoUnit.KM));
+ assertThat(radiusFromPalermo.stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()),
+ contains(equalTo(PALERMO.getBytes())));
+
+ Long addCatania = exec(commandObjects.geoadd(key, cataniaCoordinates));
+ assertThat(addCatania, equalTo(1L));
+
+ List radiusFromCatania = exec(commandObjects.georadius(
+ key, CATANIA_LONGITUDE, CATANIA_LATITUDE, 100, GeoUnit.KM));
+ assertThat(radiusFromCatania.stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()),
+ contains(equalTo(CATANIA.getBytes())));
+
+ Long addSyracuse = exec(commandObjects.geoadd(key, GeoAddParams.geoAddParams().nx(), syracuseCoordinates));
+ assertThat(addSyracuse, equalTo(1L));
+
+ List radiusEverything = exec(commandObjects.georadius(
+ key, 15, 37, 200, GeoUnit.KM));
+ assertThat(radiusEverything.stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()),
+ containsInAnyOrder(equalTo(CATANIA.getBytes()), equalTo(PALERMO.getBytes()), equalTo(SYRACUSE.getBytes())));
+ }
+
+ @Test
+ public void testGeoDist() {
+ String key = "locations";
+ byte[] binaryKey = key.getBytes();
+
+ // Add locations to calculate distance
+ exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA));
+ exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO));
+
+ Double distance = exec(commandObjects.geodist(key, CATANIA, PALERMO));
+ // This is in meters, we don't try to accurately assert it. We refer to it later.
+ assertThat(distance, notNullValue());
+
+ Double distanceWithUnit = exec(commandObjects.geodist(key, CATANIA, PALERMO, GeoUnit.KM));
+ assertThat(distanceWithUnit, closeTo(distance / 1000, 0.001));
+
+ Double binaryDistance = exec(commandObjects.geodist(binaryKey, CATANIA.getBytes(), PALERMO.getBytes()));
+ assertThat(binaryDistance, closeTo(distance, 0.001));
+
+ Double binaryDistanceWithUnit = exec(commandObjects.geodist(binaryKey, CATANIA.getBytes(), PALERMO.getBytes(), GeoUnit.KM));
+ assertThat(binaryDistanceWithUnit, closeTo(distance / 1000, 0.001));
+ }
+
+ @Test
+ public void testGeoHash() {
+ String key = "locations";
+ byte[] binaryKey = key.getBytes();
+
+ exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA));
+ exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO));
+
+ List hashes = exec(commandObjects.geohash(key, CATANIA, PALERMO));
+ assertThat(hashes, contains(notNullValue(), notNullValue()));
+
+ List binaryHashes = exec(commandObjects.geohash(binaryKey, CATANIA.getBytes(), PALERMO.getBytes()));
+ assertThat(binaryHashes, contains(hashes.get(0).getBytes(), hashes.get(1).getBytes()));
+ }
+
+ @Test
+ public void testGeoPos() {
+ String key = "locations";
+ byte[] binaryKey = key.getBytes();
+
+ exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA));
+ exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO));
+
+ List positions = exec(commandObjects.geopos(key, CATANIA, PALERMO));
+ assertThat(positions.size(), equalTo(2));
+
+ assertThat(positions.get(0), notNullValue());
+ assertThat(positions.get(0).getLongitude(), closeTo(CATANIA_LONGITUDE, 0.001));
+ assertThat(positions.get(0).getLatitude(), closeTo(CATANIA_LATITUDE, 0.001));
+
+ assertThat(positions.get(1), notNullValue());
+ assertThat(positions.get(1).getLongitude(), closeTo(PALERMO_LONGITUDE, 0.001));
+ assertThat(positions.get(1).getLatitude(), closeTo(PALERMO_LATITUDE, 0.001));
+
+ List binaryPositions = exec(commandObjects.geopos(binaryKey, CATANIA.getBytes(), PALERMO.getBytes()));
+ assertThat(binaryPositions.size(), equalTo(2));
+
+ assertThat(binaryPositions.get(0), notNullValue());
+ assertThat(binaryPositions.get(0).getLongitude(), closeTo(CATANIA_LONGITUDE, 0.001));
+ assertThat(binaryPositions.get(0).getLatitude(), closeTo(CATANIA_LATITUDE, 0.001));
+
+ assertThat(binaryPositions.get(1), notNullValue());
+ assertThat(binaryPositions.get(1).getLongitude(), closeTo(PALERMO_LONGITUDE, 0.001));
+ assertThat(binaryPositions.get(1).getLatitude(), closeTo(PALERMO_LATITUDE, 0.001));
+ }
+
+ @Test
+ public void testGeoRadius() {
+ String key = "locations";
+ byte[] binaryKey = key.getBytes();
+
+ GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withCoord().withDist();
+
+ exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA));
+ exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO));
+
+ List responses = exec(commandObjects.georadius(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, 200, GeoUnit.KM));
+
+ // we got distances, but no coordinates
+ assertThat(responses.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(CATANIA, PALERMO));
+ assertThat(responses.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(responses.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()),
+ containsInAnyOrder(nullValue(), nullValue()));
+
+ List responsesWithParam = exec(commandObjects.georadius(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, 200, GeoUnit.KM, param));
+
+ // we got distances, and coordinates
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(CATANIA, PALERMO));
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLatitude).collect(Collectors.toList()),
+ containsInAnyOrder(closeTo(PALERMO_LATITUDE, 0.001), closeTo(CATANIA_LATITUDE, 0.001)));
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLongitude).collect(Collectors.toList()),
+ containsInAnyOrder(closeTo(PALERMO_LONGITUDE, 0.001), closeTo(CATANIA_LONGITUDE, 0.001)));
+
+ List binaryResponses = exec(commandObjects.georadius(binaryKey, CATANIA_LONGITUDE, CATANIA_LATITUDE, 200, GeoUnit.KM));
+
+ // distances, but no coordinates
+ assertThat(binaryResponses.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(CATANIA, PALERMO));
+ assertThat(binaryResponses.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(binaryResponses.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()),
+ containsInAnyOrder(nullValue(), nullValue()));
+
+ List binaryResponsesWithParam = exec(commandObjects.georadius(binaryKey, CATANIA_LONGITUDE, CATANIA_LATITUDE, 200, GeoUnit.KM, param));
+
+ // distances, and coordinates
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()),
+ containsInAnyOrder(CATANIA.getBytes(), PALERMO.getBytes()));
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLatitude).collect(Collectors.toList()),
+ containsInAnyOrder(closeTo(PALERMO_LATITUDE, 0.001), closeTo(CATANIA_LATITUDE, 0.001)));
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLongitude).collect(Collectors.toList()),
+ containsInAnyOrder(closeTo(PALERMO_LONGITUDE, 0.001), closeTo(CATANIA_LONGITUDE, 0.001)));
+ }
+
+ @Test
+ public void testGeoRadiusReadonly() {
+ String key = "locations";
+ byte[] binaryKey = key.getBytes();
+
+ GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withCoord().withDist();
+
+ exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA));
+ exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO));
+
+ List responses = exec(commandObjects.georadiusReadonly(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, 200, GeoUnit.KM));
+
+ // we got distances, but no coordinates
+ assertThat(responses.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(CATANIA, PALERMO));
+ assertThat(responses.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(responses.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()),
+ containsInAnyOrder(nullValue(), nullValue()));
+
+ List responsesWithParam = exec(commandObjects.georadiusReadonly(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, 200, GeoUnit.KM, param));
+
+ // we got distances, and coordinates
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(CATANIA, PALERMO));
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLatitude).collect(Collectors.toList()),
+ containsInAnyOrder(closeTo(PALERMO_LATITUDE, 0.001), closeTo(CATANIA_LATITUDE, 0.001)));
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLongitude).collect(Collectors.toList()),
+ containsInAnyOrder(closeTo(PALERMO_LONGITUDE, 0.001), closeTo(CATANIA_LONGITUDE, 0.001)));
+
+ List binaryResponses = exec(commandObjects.georadiusReadonly(binaryKey, CATANIA_LONGITUDE, CATANIA_LATITUDE, 200, GeoUnit.KM));
+
+ // distances, but no coordinates
+ assertThat(binaryResponses.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(CATANIA, PALERMO));
+ assertThat(binaryResponses.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(binaryResponses.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()),
+ containsInAnyOrder(nullValue(), nullValue()));
+
+ List binaryResponsesWithParam = exec(commandObjects.georadiusReadonly(binaryKey, CATANIA_LONGITUDE, CATANIA_LATITUDE, 200, GeoUnit.KM, param));
+
+ // distances, and coordinates
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()),
+ containsInAnyOrder(CATANIA.getBytes(), PALERMO.getBytes()));
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLatitude).collect(Collectors.toList()),
+ containsInAnyOrder(closeTo(PALERMO_LATITUDE, 0.001), closeTo(CATANIA_LATITUDE, 0.001)));
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLongitude).collect(Collectors.toList()),
+ containsInAnyOrder(closeTo(PALERMO_LONGITUDE, 0.001), closeTo(CATANIA_LONGITUDE, 0.001)));
+ }
+
+ @Test
+ public void testGeoRadiusByMember() {
+ String key = "locations";
+ byte[] binaryKey = key.getBytes();
+
+ GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withCoord().withDist();
+
+ exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA));
+ exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO));
+ exec(commandObjects.geoadd(key, AGRIGENTO_LONGITUDE, AGRIGENTO_LATITUDE, AGRIGENTO));
+
+ List responses = exec(commandObjects.georadiusByMember(key, AGRIGENTO, 100, GeoUnit.KM));
+
+ assertThat(responses.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(AGRIGENTO, PALERMO));
+ assertThat(responses.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(responses.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()),
+ containsInAnyOrder(nullValue(), nullValue()));
+
+ List responsesWithParam = exec(commandObjects.georadiusByMember(key, AGRIGENTO, 100, GeoUnit.KM, param));
+
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(AGRIGENTO, PALERMO));
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLatitude).collect(Collectors.toList()),
+ containsInAnyOrder(closeTo(PALERMO_LATITUDE, 0.001), closeTo(AGRIGENTO_LATITUDE, 0.001)));
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLongitude).collect(Collectors.toList()),
+ containsInAnyOrder(closeTo(PALERMO_LONGITUDE, 0.001), closeTo(AGRIGENTO_LONGITUDE, 0.001)));
+
+ List binaryResponses = exec(commandObjects.georadiusByMember(binaryKey, AGRIGENTO.getBytes(), 100, GeoUnit.KM));
+
+ assertThat(binaryResponses.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(AGRIGENTO, PALERMO));
+ assertThat(binaryResponses.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(binaryResponses.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()),
+ containsInAnyOrder(nullValue(), nullValue()));
+
+ List binaryResponsesWithParam = exec(commandObjects.georadiusByMember(binaryKey, AGRIGENTO.getBytes(), 100, GeoUnit.KM, param));
+
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()),
+ containsInAnyOrder(AGRIGENTO.getBytes(), PALERMO.getBytes()));
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLatitude).collect(Collectors.toList()),
+ containsInAnyOrder(closeTo(PALERMO_LATITUDE, 0.001), closeTo(AGRIGENTO_LATITUDE, 0.001)));
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLongitude).collect(Collectors.toList()),
+ containsInAnyOrder(closeTo(PALERMO_LONGITUDE, 0.001), closeTo(AGRIGENTO_LONGITUDE, 0.001)));
+ }
+
+ @Test
+ public void testGeoRadiusByMemberReadonly() {
+ String key = "locations";
+ byte[] binaryKey = key.getBytes();
+
+ GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().withCoord().withDist();
+
+ exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA));
+ exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO));
+ exec(commandObjects.geoadd(key, AGRIGENTO_LONGITUDE, AGRIGENTO_LATITUDE, AGRIGENTO));
+
+ List responses = exec(commandObjects.georadiusByMemberReadonly(key, AGRIGENTO, 100, GeoUnit.KM));
+
+ assertThat(responses.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(AGRIGENTO, PALERMO));
+ assertThat(responses.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(responses.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()),
+ containsInAnyOrder(nullValue(), nullValue()));
+
+ List responsesWithParam = exec(commandObjects.georadiusByMemberReadonly(key, AGRIGENTO, 100, GeoUnit.KM, param));
+
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(AGRIGENTO, PALERMO));
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLatitude).collect(Collectors.toList()),
+ containsInAnyOrder(closeTo(PALERMO_LATITUDE, 0.001), closeTo(AGRIGENTO_LATITUDE, 0.001)));
+ assertThat(responsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLongitude).collect(Collectors.toList()),
+ containsInAnyOrder(closeTo(PALERMO_LONGITUDE, 0.001), closeTo(AGRIGENTO_LONGITUDE, 0.001)));
+
+ List binaryResponses = exec(commandObjects.georadiusByMemberReadonly(binaryKey, AGRIGENTO.getBytes(), 100, GeoUnit.KM));
+
+ assertThat(binaryResponses.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(AGRIGENTO, PALERMO));
+ assertThat(binaryResponses.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(binaryResponses.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()),
+ containsInAnyOrder(nullValue(), nullValue()));
+
+ List binaryResponsesWithParam = exec(commandObjects.georadiusByMemberReadonly(binaryKey, AGRIGENTO.getBytes(), 100, GeoUnit.KM, param));
+
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getMember).collect(Collectors.toList()),
+ containsInAnyOrder(AGRIGENTO.getBytes(), PALERMO.getBytes()));
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getDistance).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).collect(Collectors.toList()),
+ containsInAnyOrder(notNullValue(), notNullValue()));
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLatitude).collect(Collectors.toList()),
+ containsInAnyOrder(closeTo(PALERMO_LATITUDE, 0.001), closeTo(AGRIGENTO_LATITUDE, 0.001)));
+ assertThat(binaryResponsesWithParam.stream().map(GeoRadiusResponse::getCoordinate).map(GeoCoordinate::getLongitude).collect(Collectors.toList()),
+ containsInAnyOrder(closeTo(PALERMO_LONGITUDE, 0.001), closeTo(AGRIGENTO_LONGITUDE, 0.001)));
+ }
+
+ @Test
+ public void testGeoradiusStore() {
+ String key = "locations";
+ byte[] binaryKey = key.getBytes();
+
+ String destinationKey = "result";
+ String binaryDestinationKey = "resultBinary";
+
+ GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().sortAscending();
+
+ exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO));
+ exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA));
+
+ GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam().store(destinationKey);
+
+ Long store = exec(commandObjects.georadiusStore(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, 200, GeoUnit.KM, param, storeParam));
+ assertThat(store, equalTo(2L));
+
+ List destination = exec(commandObjects.zrange(destinationKey, 0, -1));
+ assertThat(destination, containsInAnyOrder(PALERMO, CATANIA));
+
+ GeoRadiusStoreParam storeParamForBinary = GeoRadiusStoreParam.geoRadiusStoreParam().store(binaryDestinationKey);
+
+ Long storeBinary = exec(commandObjects.georadiusStore(binaryKey, PALERMO_LONGITUDE, PALERMO_LATITUDE, 200, GeoUnit.KM, param, storeParamForBinary));
+ assertThat(storeBinary, equalTo(2L));
+
+ destination = exec(commandObjects.zrange(binaryDestinationKey, 0, -1));
+ assertThat(destination, containsInAnyOrder(PALERMO, CATANIA));
+ }
+
+ @Test
+ public void testGeoradiusByMemberStore() {
+ String key = "locations";
+ byte[] binaryKey = key.getBytes();
+
+ String destinationKey = "result";
+ String binaryDestinationKey = "resultBinary";
+
+ GeoRadiusParam param = GeoRadiusParam.geoRadiusParam().sortAscending();
+
+ exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO));
+ exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA));
+
+ GeoRadiusStoreParam storeParam = GeoRadiusStoreParam.geoRadiusStoreParam().store(destinationKey);
+
+ Long store = exec(commandObjects.georadiusByMemberStore(key, PALERMO, 200, GeoUnit.KM, param, storeParam));
+ assertThat(store, equalTo(2L));
+
+ List storedResults = exec(commandObjects.zrange(destinationKey, 0, -1));
+ assertThat(storedResults, containsInAnyOrder(PALERMO, CATANIA));
+
+ GeoRadiusStoreParam storeParamForBinary = GeoRadiusStoreParam.geoRadiusStoreParam().store(binaryDestinationKey);
+
+ Long storeBinary = exec(commandObjects.georadiusByMemberStore(binaryKey, PALERMO.getBytes(), 200, GeoUnit.KM, param, storeParamForBinary));
+ assertThat(storeBinary, equalTo(2L));
+
+ storedResults = exec(commandObjects.zrange(binaryDestinationKey, 0, -1));
+ assertThat(storedResults, containsInAnyOrder(PALERMO, CATANIA));
+ }
+
+ @Test
+ public void testGeosearch() {
+ String key = "locations";
+
+ GeoCoordinate palermoCoord = new GeoCoordinate(PALERMO_LONGITUDE, PALERMO_LATITUDE);
+
+ exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO));
+ exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA));
+
+ List resultsByMember = exec(commandObjects.geosearch(key, PALERMO, 200, GeoUnit.KM));
+
+ assertThat(resultsByMember.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(PALERMO, CATANIA));
+
+ List resultsByCoord = exec(commandObjects.geosearch(key, palermoCoord, 200, GeoUnit.KM));
+
+ assertThat(resultsByCoord.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(PALERMO, CATANIA));
+
+ List resultsByMemberBox = exec(commandObjects.geosearch(key, PALERMO, 200, 200, GeoUnit.KM));
+
+ assertThat(resultsByMemberBox.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(PALERMO));
+
+ List resultsByCoordBox = exec(commandObjects.geosearch(key, palermoCoord, 200, 200, GeoUnit.KM));
+
+ assertThat(resultsByCoordBox.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(PALERMO));
+
+ GeoSearchParam params = GeoSearchParam.geoSearchParam()
+ .byRadius(200, GeoUnit.KM).withCoord().withDist().fromMember(PALERMO);
+
+ List resultsWithParams = exec(commandObjects.geosearch(key, params));
+
+ assertThat(resultsWithParams.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(PALERMO, CATANIA));
+
+ List resultsInvalidKey = exec(commandObjects.geosearch("invalidKey", PALERMO, 100, GeoUnit.KM));
+
+ assertThat(resultsInvalidKey, empty());
+ }
+
+ @Test
+ public void testGeosearchBinary() {
+ byte[] key = "locations".getBytes();
+
+ GeoCoordinate palermoCoord = new GeoCoordinate(PALERMO_LONGITUDE, PALERMO_LATITUDE);
+
+ exec(commandObjects.geoadd(key, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO.getBytes()));
+ exec(commandObjects.geoadd(key, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA.getBytes()));
+
+ List resultsByMember = exec(commandObjects.geosearch(key, PALERMO.getBytes(), 200, GeoUnit.KM));
+
+ assertThat(resultsByMember.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(PALERMO, CATANIA));
+
+ List resultsByCoord = exec(commandObjects.geosearch(key, palermoCoord, 200, GeoUnit.KM));
+
+ assertThat(resultsByCoord.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(PALERMO, CATANIA));
+
+ List resultsByMemberBox = exec(commandObjects.geosearch(key, PALERMO.getBytes(), 200, 200, GeoUnit.KM));
+
+ assertThat(resultsByMemberBox.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(PALERMO));
+
+ List resultsByCoordBox = exec(commandObjects.geosearch(key, palermoCoord, 200, 200, GeoUnit.KM));
+
+ assertThat(resultsByCoordBox.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(PALERMO));
+
+ GeoSearchParam params = GeoSearchParam.geoSearchParam()
+ .byRadius(200, GeoUnit.KM).withCoord().withDist().fromMember(PALERMO);
+
+ List resultsWithParams = exec(commandObjects.geosearch(key, params));
+
+ assertThat(resultsWithParams.stream().map(GeoRadiusResponse::getMemberByString).collect(Collectors.toList()),
+ containsInAnyOrder(PALERMO, CATANIA));
+
+ List resultsInvalidKey = exec(commandObjects.geosearch("invalidKey".getBytes(), PALERMO.getBytes(), 100, GeoUnit.KM));
+
+ assertThat(resultsInvalidKey, empty());
+ }
+
+ @Test
+ public void testGeosearchStore() {
+ String srcKey = "locations";
+ String destKey = "locationsStore";
+
+ GeoCoordinate palermoCoord = new GeoCoordinate(PALERMO_LONGITUDE, PALERMO_LATITUDE);
+
+ exec(commandObjects.geoadd(srcKey, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO));
+ exec(commandObjects.geoadd(srcKey, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA));
+
+ Long storeByMember = exec(commandObjects.geosearchStore(destKey, srcKey, PALERMO, 200, GeoUnit.KM));
+ assertThat(storeByMember, equalTo(2L));
+
+ List storedResultsByMember = exec(commandObjects.zrange(destKey, 0, -1));
+ assertThat(storedResultsByMember, containsInAnyOrder(PALERMO, CATANIA));
+
+ // Reset
+ exec(commandObjects.del(destKey));
+
+ Long storeByCoord = exec(commandObjects.geosearchStore(destKey, srcKey, palermoCoord, 200, GeoUnit.KM));
+ assertThat(storeByCoord, equalTo(2L));
+
+ List storedResultsByCoord = exec(commandObjects.zrange(destKey, 0, -1));
+ assertThat(storedResultsByCoord, containsInAnyOrder(PALERMO, CATANIA));
+
+ exec(commandObjects.del(destKey));
+
+ Long storeByMemberBox = exec(commandObjects.geosearchStore(destKey, srcKey, PALERMO, 200, 200, GeoUnit.KM));
+ assertThat(storeByMemberBox, equalTo(1L));
+
+ List storedResultsByMemberBox = exec(commandObjects.zrange(destKey, 0, -1));
+ assertThat(storedResultsByMemberBox, containsInAnyOrder(PALERMO));
+
+ exec(commandObjects.del(destKey));
+
+ Long storeByCoordBox = exec(commandObjects.geosearchStore(destKey, srcKey, palermoCoord, 200, 200, GeoUnit.KM));
+ assertThat(storeByCoordBox, equalTo(1L));
+
+ List storedResultsByCoordBox = exec(commandObjects.zrange(destKey, 0, -1));
+ assertThat(storedResultsByCoordBox, containsInAnyOrder(PALERMO));
+
+ exec(commandObjects.del(destKey));
+
+ GeoSearchParam params = GeoSearchParam.geoSearchParam()
+ .byRadius(200, GeoUnit.KM).fromMember(PALERMO);
+
+ Long storeWithParams = exec(commandObjects.geosearchStore(destKey, srcKey, params));
+ assertThat(storeWithParams, equalTo(2L));
+
+ List storedResultsWithParams = exec(commandObjects.zrange(destKey, 0, -1));
+ assertThat(storedResultsWithParams, containsInAnyOrder(PALERMO, CATANIA));
+ }
+
+ @Test
+ public void testGeosearchStoreBinary() {
+ byte[] srcKey = "locations".getBytes();
+ byte[] destKey = "locationsStore".getBytes();
+
+ GeoCoordinate palermoCoord = new GeoCoordinate(PALERMO_LONGITUDE, PALERMO_LATITUDE);
+
+ exec(commandObjects.geoadd(srcKey, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO.getBytes()));
+ exec(commandObjects.geoadd(srcKey, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA.getBytes()));
+
+ Long storeByMember = exec(commandObjects.geosearchStore(destKey, srcKey, PALERMO.getBytes(), 200, GeoUnit.KM));
+ assertThat(storeByMember, equalTo(2L));
+
+ List storedResultsByMember = exec(commandObjects.zrange(destKey, 0, -1));
+ assertThat(storedResultsByMember, containsInAnyOrder(PALERMO.getBytes(), CATANIA.getBytes()));
+
+ // Reset
+ exec(commandObjects.del(destKey));
+
+ Long storeByCoord = exec(commandObjects.geosearchStore(destKey, srcKey, palermoCoord, 200, GeoUnit.KM));
+ assertThat(storeByCoord, equalTo(2L));
+
+ List storedResultsByCoord = exec(commandObjects.zrange(destKey, 0, -1));
+ assertThat(storedResultsByCoord, containsInAnyOrder(PALERMO.getBytes(), CATANIA.getBytes()));
+
+ exec(commandObjects.del(destKey));
+
+ Long storeByMemberBox = exec(commandObjects.geosearchStore(destKey, srcKey, PALERMO.getBytes(), 200, 200, GeoUnit.KM));
+ assertThat(storeByMemberBox, equalTo(1L));
+
+ List storedResultsByMemberBox = exec(commandObjects.zrange(destKey, 0, -1));
+ assertThat(storedResultsByMemberBox, containsInAnyOrder(PALERMO.getBytes()));
+
+ exec(commandObjects.del(destKey));
+
+ Long storeByCoordBox = exec(commandObjects.geosearchStore(destKey, srcKey, palermoCoord, 200, 200, GeoUnit.KM));
+ assertThat(storeByCoordBox, equalTo(1L));
+
+ List storedResultsByCoordBox = exec(commandObjects.zrange(destKey, 0, -1));
+ assertThat(storedResultsByCoordBox, containsInAnyOrder(PALERMO.getBytes()));
+
+ exec(commandObjects.del(destKey));
+
+ GeoSearchParam params = GeoSearchParam.geoSearchParam()
+ .byRadius(200, GeoUnit.KM).fromMember(PALERMO);
+
+ Long storeWithParams = exec(commandObjects.geosearchStore(destKey, srcKey, params));
+ assertThat(storeWithParams, equalTo(2L));
+
+ List storedResultsWithParams = exec(commandObjects.zrange(destKey, 0, -1));
+ assertThat(storedResultsWithParams, containsInAnyOrder(PALERMO.getBytes(), CATANIA.getBytes()));
+ }
+
+ @Test
+ public void testGeosearchStoreStoreDist() {
+ String srcKey = "locations";
+ byte[] srcKeyBytes = srcKey.getBytes();
+
+ String destKey = "resultKey";
+ byte[] destKeyBytes = destKey.getBytes();
+
+ exec(commandObjects.geoadd(srcKey, PALERMO_LONGITUDE, PALERMO_LATITUDE, PALERMO));
+ exec(commandObjects.geoadd(srcKey, CATANIA_LONGITUDE, CATANIA_LATITUDE, CATANIA));
+ exec(commandObjects.geoadd(srcKey, SYRACUSE_LONGITUDE, SYRACUSE_LATITUDE, SYRACUSE));
+
+ GeoSearchParam params = new GeoSearchParam()
+ .byRadius(100, GeoUnit.KM).fromLonLat(15, 37);
+
+ Long store = exec(commandObjects.geosearchStoreStoreDist(destKey, srcKey, params));
+ assertThat(store, equalTo(2L));
+
+ List dstContent = exec(commandObjects.zrange(destKey, 0, -1));
+ assertThat(dstContent, containsInAnyOrder(CATANIA, SYRACUSE));
+
+ exec(commandObjects.del(destKey));
+
+ Long storeWithBytes = exec(commandObjects.geosearchStoreStoreDist(destKeyBytes, srcKeyBytes, params));
+ assertThat(storeWithBytes, equalTo(2L));
+
+ List dstContentWithBytes = exec(commandObjects.zrange(destKeyBytes, 0, -1));
+ assertThat(dstContentWithBytes, containsInAnyOrder(CATANIA.getBytes(), SYRACUSE.getBytes()));
+ }
+}
diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsHashCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsHashCommandsTest.java
new file mode 100644
index 0000000000..b025b85440
--- /dev/null
+++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsHashCommandsTest.java
@@ -0,0 +1,405 @@
+package redis.clients.jedis.commands.commandobjects;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.anyOf;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.everyItem;
+import static org.hamcrest.Matchers.hasEntry;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.lessThanOrEqualTo;
+import static org.hamcrest.Matchers.nullValue;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Test;
+import redis.clients.jedis.RedisProtocol;
+import redis.clients.jedis.params.ScanParams;
+import redis.clients.jedis.resps.ScanResult;
+
+/**
+ * Tests related to Hash commands.
+ */
+public class CommandObjectsHashCommandsTest extends CommandObjectsStandaloneTestBase {
+
+ public CommandObjectsHashCommandsTest(RedisProtocol protocol) {
+ super(protocol);
+ }
+
+ @Test
+ public void testHashSetGet() {
+ String key = "hashKey";
+ String field = "name";
+ String value = "John";
+
+ String getInitial = exec(commandObjects.hget(key, field));
+ assertThat(getInitial, nullValue());
+
+ Long set = exec(commandObjects.hset(key, field, value));
+ assertThat(set, equalTo(1L));
+
+ String get = exec(commandObjects.hget(key, field));
+ assertThat(get, equalTo(value));
+ }
+
+ @Test
+ public void testHashSetGetBinary() {
+ byte[] key = "hashKeyBytes".getBytes();
+ byte[] field = "field".getBytes();
+ byte[] value = "value".getBytes();
+
+ byte[] getInitial = exec(commandObjects.hget(key, field));
+ assertThat(getInitial, nullValue());
+
+ Long set = exec(commandObjects.hset(key, field, value));
+ assertThat(set, equalTo(1L));
+
+ byte[] get = exec(commandObjects.hget(key, field));
+ assertThat(get, equalTo(value));
+ }
+
+ @Test
+ public void testHashBulkSet() {
+ String key = "hashKey";
+
+ Map hash = new HashMap<>();
+ hash.put("field1", "value1");
+ hash.put("field2", "value2");
+
+ Long set = exec(commandObjects.hset(key, hash));
+ assertThat(set, equalTo((long) hash.size()));
+
+ List mget = exec(commandObjects.hmget(key, "field1", "field2"));
+ assertThat(mget, contains("value1", "value2"));
+ }
+
+ @Test
+ public void testHashBulkSetBinary() {
+ byte[] key = "hashKey".getBytes();
+
+ Map hash = new HashMap<>();
+ hash.put("field1".getBytes(), "value1".getBytes());
+ hash.put("field2".getBytes(), "value2".getBytes());
+
+ Long set = exec(commandObjects.hset(key, hash));
+ assertThat(set, equalTo((long) hash.size()));
+
+ List mget = exec(commandObjects.hmget(key, "field1".getBytes(), "field2".getBytes()));
+ assertThat(mget, contains("value1".getBytes(), "value2".getBytes()));
+ }
+
+ @Test
+ public void testHashMsetMget() {
+ String key = "bulkHashKey";
+
+ Map hash = new HashMap<>();
+ hash.put("field1", "value1");
+ hash.put("field2", "value2");
+
+ String mset = exec(commandObjects.hmset(key, hash));
+ assertThat(mset, equalTo("OK"));
+
+ List mget = exec(commandObjects.hmget(key, "field1", "field2"));
+ assertThat(mget, contains("value1", "value2"));
+ }
+
+ @Test
+ public void testHashMsetMgetBinary() {
+ byte[] key = "hashKey".getBytes();
+
+ Map hash = new HashMap<>();
+ hash.put("field1".getBytes(), "value1".getBytes());
+ hash.put("field2".getBytes(), "value2".getBytes());
+
+ String mset = exec(commandObjects.hmset(key, hash));
+ assertThat(mset, equalTo("OK"));
+
+ List mget = exec(commandObjects.hmget(key, "field1".getBytes(), "field2".getBytes()));
+ assertThat(mget, contains("value1".getBytes(), "value2".getBytes()));
+ }
+
+ @Test
+ public void testHsetnx() {
+ String key = "hashKey";
+ String field = "field";
+ String value = "value";
+
+ String initialGet = exec(commandObjects.hget(key, field));
+ assertThat(initialGet, nullValue());
+
+ Long initialSet = exec(commandObjects.hsetnx(key, field, value));
+ assertThat(initialSet, equalTo(1L));
+
+ String get = exec(commandObjects.hget(key, field));
+ assertThat(get, equalTo(value));
+
+ Long secondSet = exec(commandObjects.hsetnx(key, field, "newValue"));
+ assertThat(secondSet, equalTo(0L));
+
+ String secondGet = exec(commandObjects.hget(key, field));
+ assertThat(secondGet, equalTo(value));
+ }
+
+ @Test
+ public void testHsetnxBinary() {
+ byte[] key = "hashKey".getBytes();
+ byte[] field = "field".getBytes();
+ byte[] value = "value".getBytes();
+
+ byte[] initialGet = exec(commandObjects.hget(key, field));
+ assertThat(initialGet, nullValue());
+
+ Long set = exec(commandObjects.hsetnx(key, field, value));
+ assertThat(set, equalTo(1L));
+
+ byte[] get = exec(commandObjects.hget(key, field));
+ assertThat(get, equalTo(value));
+
+ Long secondSet = exec(commandObjects.hsetnx(key, field, "newValue".getBytes()));
+ assertThat(secondSet, equalTo(0L));
+
+ byte[] secondGet = exec(commandObjects.hget(key, field));
+ assertThat(secondGet, equalTo(value));
+ }
+
+ @Test
+ public void testHincrBy() {
+ String key = "incrementHashKey";
+ String field = "incrementField";
+
+ Long initialSet = exec(commandObjects.hset(key, field, "0"));
+ assertThat(initialSet, equalTo(1L));
+
+ String initialGet = exec(commandObjects.hget(key, field));
+ assertThat(initialGet, equalTo("0"));
+
+ Long incrByLong = exec(commandObjects.hincrBy(key, field, 10L));
+ assertThat(incrByLong, equalTo(10L));
+
+ String getAfterIncrByLong = exec(commandObjects.hget(key, field));
+ assertThat(getAfterIncrByLong, equalTo("10"));
+
+ Double incrByFloat = exec(commandObjects.hincrByFloat(key, field, 2.5));
+ assertThat(incrByFloat, equalTo(12.5));
+
+ String getAfterIncrByFloat = exec(commandObjects.hget(key, field));
+ assertThat(getAfterIncrByFloat, equalTo("12.5"));
+ }
+
+ @Test
+ public void testHincrByBinary() {
+ byte[] key = "key".getBytes();
+ byte[] field = "field".getBytes();
+
+ Long initialSet = exec(commandObjects.hset(key, field, "0".getBytes()));
+ assertThat(initialSet, equalTo(1L));
+
+ byte[] initialGet = exec(commandObjects.hget(key, field));
+ assertThat(initialGet, equalTo("0".getBytes()));
+
+ Long incrByLong = exec(commandObjects.hincrBy(key, field, 10L));
+ assertThat(incrByLong, equalTo(10L));
+
+ byte[] getAfterIncrByLong = exec(commandObjects.hget(key, field));
+ assertThat(getAfterIncrByLong, equalTo("10".getBytes()));
+
+ Double incrByDouble = exec(commandObjects.hincrByFloat(key, field, 2.5));
+ assertThat(incrByDouble, equalTo(12.5));
+
+ byte[] getAfterIncrByDouble = exec(commandObjects.hget(key, field));
+ assertThat(getAfterIncrByDouble, equalTo("12.5".getBytes()));
+ }
+
+ @Test
+ public void testHashExistsDel() {
+ String key = "key";
+ String field1 = "field1";
+ String field2 = "field2";
+ String value = "value";
+
+ exec(commandObjects.hset(key, field1, value));
+ exec(commandObjects.hset(key, field2, value));
+
+ Boolean exists = exec(commandObjects.hexists(key, field1));
+ assertThat(exists, equalTo(true));
+
+ Long len = exec(commandObjects.hlen(key));
+ assertThat(len, equalTo(2L));
+
+ Long del = exec(commandObjects.hdel(key, field1));
+ assertThat(del, equalTo(1L));
+
+ Boolean existsAfterDel = exec(commandObjects.hexists(key, field1));
+ assertThat(existsAfterDel, equalTo(false));
+
+ Long lenAfterDel = exec(commandObjects.hlen(key));
+ assertThat(lenAfterDel, equalTo(1L));
+ }
+
+ @Test
+ public void testHashExistsDelBinary() {
+ byte[] key = "key".getBytes();
+ byte[] field1 = "field1".getBytes();
+ byte[] field2 = "field2".getBytes();
+ byte[] value = "value".getBytes();
+
+ exec(commandObjects.hset(key, field1, value));
+ exec(commandObjects.hset(key, field2, value));
+
+ Boolean exists = exec(commandObjects.hexists(key, field1));
+ assertThat(exists, equalTo(true));
+
+ Long len = exec(commandObjects.hlen(key));
+ assertThat(len, equalTo(2L));
+
+ Long del = exec(commandObjects.hdel(key, field1));
+ assertThat(del, equalTo(1L));
+
+ Boolean existsAfterDel = exec(commandObjects.hexists(key, field1));
+ assertThat(existsAfterDel, equalTo(false));
+
+ Long lenAfterDel = exec(commandObjects.hlen(key));
+ assertThat(lenAfterDel, equalTo(1L));
+ }
+
+ @Test
+ public void testHashKeysValsGetAll() {
+ String key = "hashKey";
+ byte[] keyBinary = key.getBytes();
+
+ String field1 = "field1";
+ String field2 = "field2";
+ String value1 = "value1";
+ String value2 = "value2";
+
+ exec(commandObjects.hset(key, field1, value1));
+ exec(commandObjects.hset(key, field2, value2));
+
+ Set keys = exec(commandObjects.hkeys(key));
+ assertThat(keys, containsInAnyOrder(field1, field2));
+
+ List values = exec(commandObjects.hvals(key));
+ assertThat(values, containsInAnyOrder(value1, value2));
+
+ Map hash = exec(commandObjects.hgetAll(key));
+ assertThat(hash, allOf(
+ hasEntry(field1, value1),
+ hasEntry(field2, value2)));
+
+ // binary
+ Set keysBinary = exec(commandObjects.hkeys(keyBinary));
+ assertThat(keysBinary, containsInAnyOrder(field1.getBytes(), field2.getBytes()));
+
+ List valuesBinary = exec(commandObjects.hvals(keyBinary));
+ assertThat(valuesBinary, containsInAnyOrder(value1.getBytes(), value2.getBytes()));
+
+ Map hashBinary = exec(commandObjects.hgetAll(keyBinary));
+ assertThat(hashBinary, allOf(
+ hasEntry(field1.getBytes(), value1.getBytes()),
+ hasEntry(field2.getBytes(), value2.getBytes())));
+ }
+
+ @Test
+ public void testHashRandfield() {
+ String key = "testHash";
+ byte[] bkey = key.getBytes();
+
+ exec(commandObjects.hset(key, "field1", "value1"));
+ exec(commandObjects.hset(key, "field2", "value2"));
+
+ String singleField = exec(commandObjects.hrandfield(key));
+ assertThat(singleField, anyOf(equalTo("field1"), equalTo("field2")));
+
+ List fields = exec(commandObjects.hrandfield(key, 2));
+ assertThat(fields, containsInAnyOrder("field1", "field2"));
+
+ List> fieldsWithValues = exec(commandObjects.hrandfieldWithValues(key, 2));
+
+ assertThat(fieldsWithValues, hasSize(2));
+ fieldsWithValues.forEach(entry ->
+ assertThat(entry.getValue(), anyOf(equalTo("value1"), equalTo("value2"))));
+
+ // binary
+ byte[] singleFieldBinary = exec(commandObjects.hrandfield(bkey));
+ assertThat(singleFieldBinary, anyOf(equalTo("field1".getBytes()), equalTo("field2".getBytes())));
+
+ List fieldsBinary = exec(commandObjects.hrandfield(bkey, 2));
+ assertThat(fieldsBinary, containsInAnyOrder("field1".getBytes(), "field2".getBytes()));
+
+ List> fieldsWithValuesBinary = exec(commandObjects.hrandfieldWithValues(bkey, 2));
+
+ assertThat(fieldsWithValuesBinary, hasSize(2));
+ fieldsWithValuesBinary.forEach(entry ->
+ assertThat(entry.getValue(), anyOf(equalTo("value1".getBytes()), equalTo("value2".getBytes()))));
+ }
+
+ @Test
+ public void testHscan() {
+ String key = "testHashScan";
+ byte[] bkey = key.getBytes();
+
+ exec(commandObjects.hset(key, "field1", "value1"));
+ exec(commandObjects.hset(key, "field2", "value2"));
+
+ ScanParams params = new ScanParams().count(2);
+
+ ScanResult> scanResult = exec(commandObjects.hscan(key, ScanParams.SCAN_POINTER_START, params));
+
+ assertThat(scanResult.getResult(), hasSize(lessThanOrEqualTo(2)));
+
+ scanResult.getResult().forEach(entry ->
+ assertThat(entry.getKey(), anyOf(equalTo("field1"), equalTo("field2"))));
+ scanResult.getResult().forEach(entry ->
+ assertThat(entry.getValue(), anyOf(equalTo("value1"), equalTo("value2"))));
+
+ ScanResult scanResultNoValues = exec(commandObjects.hscanNoValues(key, ScanParams.SCAN_POINTER_START, params));
+
+ assertThat(scanResultNoValues.getResult(), hasSize(lessThanOrEqualTo(2)));
+
+ assertThat(scanResultNoValues.getResult(),
+ everyItem(anyOf(equalTo("field1"), equalTo("field2"))));
+
+ // binary
+ ScanResult> bscanResult = exec(commandObjects.hscan(bkey, ScanParams.SCAN_POINTER_START_BINARY, params));
+
+ assertThat(bscanResult.getResult(), hasSize(lessThanOrEqualTo(2)));
+
+ bscanResult.getResult().forEach(entry ->
+ assertThat(entry.getKey(), anyOf(equalTo("field1".getBytes()), equalTo("field2".getBytes()))));
+ bscanResult.getResult().forEach(entry ->
+ assertThat(entry.getValue(), anyOf(equalTo("value1".getBytes()), equalTo("value2".getBytes()))));
+
+ ScanResult bscanResultNoValues = exec(commandObjects.hscanNoValues(bkey, ScanParams.SCAN_POINTER_START_BINARY, params));
+
+ assertThat(bscanResultNoValues.getResult(), hasSize(lessThanOrEqualTo(2)));
+
+ assertThat(bscanResultNoValues.getResult(),
+ everyItem(anyOf(equalTo("field1".getBytes()), equalTo("field2".getBytes()))));
+ }
+
+ @Test
+ public void testHashStrlen() {
+ String key = "testHashStrlen";
+ byte[] bkey = key.getBytes();
+
+ exec(commandObjects.hset(key, "field1", "value1"));
+
+ Long strlen = exec(commandObjects.hstrlen(key, "field1"));
+ assertThat(strlen, equalTo(6L));
+
+ Long strlenNonExistingField = exec(commandObjects.hstrlen(key, "nonExistingField"));
+ assertThat(strlenNonExistingField, equalTo(0L));
+
+ // binary
+ Long strlenBinary = exec(commandObjects.hstrlen(bkey, "field1".getBytes()));
+ assertThat(strlenBinary, equalTo(6L));
+
+ Long strlenNonExistingFieldBinary = exec(commandObjects.hstrlen(bkey, "nonExistingField".getBytes()));
+ assertThat(strlenNonExistingFieldBinary, equalTo(0L));
+ }
+}
diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsHyperloglogCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsHyperloglogCommandsTest.java
new file mode 100644
index 0000000000..cdfe5aa7bd
--- /dev/null
+++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsHyperloglogCommandsTest.java
@@ -0,0 +1,94 @@
+package redis.clients.jedis.commands.commandobjects;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+
+import org.junit.Test;
+import redis.clients.jedis.RedisProtocol;
+
+/**
+ * Tests related to HyperLogLog commands.
+ */
+public class CommandObjectsHyperloglogCommandsTest extends CommandObjectsStandaloneTestBase {
+
+ public CommandObjectsHyperloglogCommandsTest(RedisProtocol protocol) {
+ super(protocol);
+ }
+
+ @Test
+ public void testPfaddAndCount() {
+ String key = "hyperloglogKey";
+
+ Long add = exec(commandObjects.pfadd(key, "element1", "element2", "element3"));
+ assertThat(add, equalTo(1L));
+
+ Long count = exec(commandObjects.pfcount(key));
+ assertThat(count, greaterThanOrEqualTo(3L)); // approximate, expect at least 3
+
+ Long addNewElement = exec(commandObjects.pfadd(key, "element4"));
+ assertThat(addNewElement, equalTo(1L));
+
+ Long countWithNewElement = exec(commandObjects.pfcount(key));
+ assertThat(countWithNewElement, greaterThan(count));
+ }
+
+ @Test
+ public void testPfaddAndCountBinary() {
+ byte[] key = "hyperloglogKey".getBytes();
+
+ Long add = exec(commandObjects.pfadd(key, "element1".getBytes(), "element2".getBytes(), "element3".getBytes()));
+ assertThat(add, equalTo(1L));
+
+ Long count = exec(commandObjects.pfcount(key));
+ assertThat(count, greaterThanOrEqualTo(3L));
+ }
+
+ @Test
+ public void testPfmerge() {
+ String key1 = "hyperloglog1";
+ String key2 = "hyperloglog2";
+
+ exec(commandObjects.pfadd(key1, "elementA", "elementB"));
+ exec(commandObjects.pfadd(key2, "elementC", "elementD"));
+
+ String destKey = "mergedHyperloglog";
+ byte[] destKeyBytes = "mergedHyperloglogBytes".getBytes();
+
+ String mergeResultWithString = exec(commandObjects.pfmerge(destKey, key1, key2));
+ assertThat(mergeResultWithString, equalTo("OK"));
+
+ Long countAfterMergeWithString = exec(commandObjects.pfcount(destKey));
+ assertThat(countAfterMergeWithString, greaterThanOrEqualTo(4L));
+
+ // binary
+ String mergeResultWithBytes = exec(commandObjects.pfmerge(destKeyBytes, key1.getBytes(), key2.getBytes()));
+ assertThat(mergeResultWithBytes, equalTo("OK"));
+
+ Long countAfterMergeWithBytes = exec(commandObjects.pfcount(destKeyBytes));
+ assertThat(countAfterMergeWithBytes, greaterThanOrEqualTo(4L));
+ }
+
+ @Test
+ public void testPfcount() {
+ String key1 = "hyperloglogCount1";
+ String key2 = "hyperloglogCount2";
+
+ exec(commandObjects.pfadd(key1, "element1", "element2", "element3"));
+ exec(commandObjects.pfadd(key2, "element4", "element5", "element6"));
+
+ Long countForKey1 = exec(commandObjects.pfcount(key1));
+ assertThat(countForKey1, greaterThanOrEqualTo(3L));
+
+ Long countForBothKeys = exec(commandObjects.pfcount(key1, key2));
+ assertThat(countForBothKeys, greaterThanOrEqualTo(6L));
+
+ // binary
+ Long countForKey1Binary = exec(commandObjects.pfcount(key1.getBytes()));
+ assertThat(countForKey1Binary, greaterThanOrEqualTo(3L));
+
+ Long countForBothKeysBinary = exec(commandObjects.pfcount(key1.getBytes(), key2.getBytes()));
+ assertThat(countForBothKeysBinary, greaterThanOrEqualTo(6L));
+ }
+}
diff --git a/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsJsonCommandsTest.java b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsJsonCommandsTest.java
new file mode 100644
index 0000000000..a416be2103
--- /dev/null
+++ b/src/test/java/redis/clients/jedis/commands/commandobjects/CommandObjectsJsonCommandsTest.java
@@ -0,0 +1,1434 @@
+package redis.clients.jedis.commands.commandobjects;
+
+import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.hasEntry;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assume.assumeThat;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.junit.Test;
+import redis.clients.jedis.RedisProtocol;
+import redis.clients.jedis.json.JsonSetParams;
+import redis.clients.jedis.json.Path;
+import redis.clients.jedis.json.Path2;
+
+/**
+ * Tests related to JSON commands.
+ */
+public class CommandObjectsJsonCommandsTest extends CommandObjectsModulesTestBase {
+
+ public CommandObjectsJsonCommandsTest(RedisProtocol protocol) {
+ super(protocol);
+ }
+
+ @Test
+ public void testJsonSetAndJsonGet() {
+ String key = "jsonKey";
+
+ JSONObject person = new JSONObject();
+ person.put("name", "John Doe");
+ person.put("age", 30);
+
+ String setRoot = exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, person));
+ assertThat(setRoot, equalTo("OK"));
+
+ Object getRoot = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(getRoot, jsonEquals(new JSONArray().put(person)));
+
+ JSONObject details = new JSONObject();
+ details.put("city", "New York");
+
+ String setDeep = exec(commandObjects.jsonSet(key, new Path2("$.details"), details));
+ assertThat(setDeep, equalTo("OK"));
+
+ Object getDeep = exec(commandObjects.jsonGet(key, new Path2("$.details")));
+ assertThat(getDeep, jsonEquals(new JSONArray().put(details)));
+
+ Object getFull = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ person.put("details", details);
+ assertThat(getFull, jsonEquals(new JSONArray().put(person)));
+ }
+
+ @Test
+ public void testJsonSetWithEscape() {
+ String key = "jsonKey";
+
+ Map book = new HashMap<>();
+ book.put("title", "Learning JSON");
+
+ String setRoot = exec(commandObjects.jsonSetWithEscape(key, Path2.ROOT_PATH, book));
+ assertThat(setRoot, equalTo("OK"));
+
+ Object getRoot = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONArray expected = new JSONArray().put(new JSONObject(book));
+ assertThat(getRoot, jsonEquals(expected));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonSetJsonGetOldPath() {
+ String key = "jsonKey";
+
+ Map book = new HashMap<>();
+ book.put("author", "Jane Doe");
+ book.put("title", "Advanced JSON Techniques");
+
+ String setRoot = exec(commandObjects.jsonSet(key, Path.ROOT_PATH, book));
+ assertThat(setRoot, equalTo("OK"));
+
+ Object getRoot = exec(commandObjects.jsonGet(key, Path.ROOT_PATH));
+ assertThat(getRoot, instanceOf(Map.class));
+
+ @SuppressWarnings("unchecked")
+ Map getRootMap = (Map) getRoot;
+ assertThat(getRootMap, hasEntry("author", "Jane Doe"));
+ assertThat(getRootMap, hasEntry("title", "Advanced JSON Techniques"));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonSetWithPlainString() {
+ String key = "jsonKey";
+ String jsonString = "{\"name\":\"John\"}";
+
+ String setRoot = exec(commandObjects.jsonSetWithPlainString(key, Path.ROOT_PATH, jsonString));
+ assertThat(setRoot, equalTo("OK"));
+
+ Object getRoot = exec(commandObjects.jsonGet(key, Path.ROOT_PATH));
+ assertThat(getRoot, instanceOf(Map.class));
+
+ @SuppressWarnings("unchecked")
+ Map getRootMap = (Map) getRoot;
+ assertThat(getRootMap, hasEntry("name", "John"));
+ }
+
+ @Test
+ public void testJsonSetWithParams() {
+ String key = "jsonKey";
+
+ JSONObject book = new JSONObject();
+ book.put("author", "Jane Doe");
+ book.put("title", "Advanced JSON Techniques");
+
+ JsonSetParams params = new JsonSetParams().nx();
+
+ String setRoot = exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, book, params));
+ assertThat(setRoot, equalTo("OK"));
+
+ Object getRoot = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONArray expected = new JSONArray().put(book);
+ assertThat(getRoot, jsonEquals(expected));
+ }
+
+ @Test
+ public void testJsonSetWithEscapeAndParams() {
+ String key = "jsonKey";
+
+ Map book = new HashMap<>();
+ book.put("author", "John Smith");
+ book.put("title", "JSON Escaping 101");
+
+ JsonSetParams params = new JsonSetParams().nx();
+
+ String setRoot = exec(commandObjects.jsonSetWithEscape(key, Path2.ROOT_PATH, book, params));
+ assertThat(setRoot, equalTo("OK"));
+
+ Object getRoot = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONArray expected = new JSONArray().put(new JSONObject(book));
+ assertThat(getRoot, jsonEquals(expected));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonSetOldPathWithParams() {
+ String key = "jsonKey";
+
+ Map user = new HashMap<>();
+ user.put("username", "johndoe");
+ user.put("accountType", "premium");
+
+ JsonSetParams params = new JsonSetParams().nx();
+
+ String setRoot = exec(commandObjects.jsonSet(key, Path.ROOT_PATH, user, params));
+ assertThat(setRoot, equalTo("OK"));
+
+ Object getRoot = exec(commandObjects.jsonGet(key, Path.ROOT_PATH));
+ assertThat(getRoot, instanceOf(Map.class));
+
+ @SuppressWarnings("unchecked")
+ Map readResultMap = (Map) getRoot;
+ assertThat(readResultMap, hasEntry("username", "johndoe"));
+ assertThat(readResultMap, hasEntry("accountType", "premium"));
+ }
+
+ @Test
+ public void testJsonMerge() {
+ String key = "jsonKey";
+
+ JSONObject initialUser = new JSONObject();
+ initialUser.put("name", "John Doe");
+ initialUser.put("age", 30);
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, initialUser));
+
+ JSONObject mergeUser = new JSONObject();
+ mergeUser.put("occupation", "Software Developer");
+ mergeUser.put("age", 31); // Assuming we're updating the age as well
+
+ String mergeRoot = exec(commandObjects.jsonMerge(key, Path2.ROOT_PATH, mergeUser));
+ assertThat(mergeRoot, equalTo("OK"));
+
+ Object getRoot = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(getRoot, notNullValue());
+
+ JSONObject expectedUser = new JSONObject();
+ expectedUser.put("name", "John Doe");
+ expectedUser.put("age", 31);
+ expectedUser.put("occupation", "Software Developer");
+
+ JSONArray expected = new JSONArray().put(expectedUser);
+ assertThat(getRoot, jsonEquals(expected));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonMergeOldPath() {
+ String key = "jsonKey";
+
+ Map initialUser = new HashMap<>();
+ initialUser.put("name", "Jane Doe");
+
+ exec(commandObjects.jsonSet(key, Path.ROOT_PATH, initialUser));
+
+ Map mergeUser = new HashMap<>();
+ mergeUser.put("occupation", "Data Scientist");
+ mergeUser.put("name", "Jane Smith"); // update the name as well
+
+ String mergeRoot = exec(commandObjects.jsonMerge(key, Path.ROOT_PATH, mergeUser));
+ assertThat(mergeRoot, equalTo("OK"));
+
+ Object getRoot = exec(commandObjects.jsonGet(key, Path.ROOT_PATH));
+ assertThat(getRoot, instanceOf(Map.class));
+
+ @SuppressWarnings("unchecked")
+ Map resultMap = (Map) getRoot;
+ assertThat(resultMap, hasEntry("name", "Jane Smith"));
+ assertThat(resultMap, hasEntry("occupation", "Data Scientist"));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonGenericObjectResp2() {
+ assumeThat(protocol, not(equalTo(RedisProtocol.RESP3)));
+
+ String key = "user:1000";
+
+ Person person = new Person();
+ person.setName("John Doe");
+ person.setAge(30);
+
+ String setRoot = exec(commandObjects.jsonSet(key, Path.ROOT_PATH, person));
+ assertThat(setRoot, equalTo("OK"));
+
+ Object getRoot = exec(commandObjects.jsonGet(key));
+ assertThat(getRoot, instanceOf(Map.class));
+
+ @SuppressWarnings("unchecked")
+ Map resultMap = (Map) getRoot;
+ assertThat(resultMap, hasEntry("name", "John Doe"));
+ assertThat(resultMap, hasEntry("age", 30.0));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonGenericObjectResp3() {
+ assumeThat(protocol, equalTo(RedisProtocol.RESP3));
+
+ String key = "user:1000";
+
+ Person person = new Person("John Doe", 30);
+
+ String setResult = exec(commandObjects.jsonSet(key, Path.ROOT_PATH, person));
+ assertThat(setResult, equalTo("OK"));
+
+ Object getRoot = exec(commandObjects.jsonGet(key));
+ assertThat(getRoot, instanceOf(JSONArray.class));
+
+ JSONObject expectedPerson = new JSONObject();
+ expectedPerson.put("name", "John Doe");
+ expectedPerson.put("age", 30);
+
+ JSONArray expected = new JSONArray().put(expectedPerson);
+ assertThat(getRoot, jsonEquals(expected));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonGetWithClass() {
+ assumeThat(protocol, not(equalTo(RedisProtocol.RESP3)));
+
+ String key = "user:2000";
+
+ String jsonObject = "{\"name\":\"Jane Doe\",\"age\":25}";
+
+ exec(commandObjects.jsonSetWithPlainString(key, Path.ROOT_PATH, jsonObject));
+
+ Person getRoot = exec(commandObjects.jsonGet(key, Person.class));
+
+ assertThat(getRoot.getName(), equalTo("Jane Doe"));
+ assertThat(getRoot.getAge(), equalTo(25));
+ }
+
+ @Test
+ public void testJsonMGet() {
+ String keyBob = "user:bob";
+ String keyCharlie = "user:charlie";
+
+ JSONObject bob = new JSONObject();
+ bob.put("name", "Bob");
+ bob.put("age", 30);
+
+ JSONObject charlie = new JSONObject();
+ charlie.put("name", "Charlie");
+ charlie.put("age", 25);
+
+ String setBobRoot = exec(commandObjects.jsonSet(keyBob, Path2.ROOT_PATH, bob));
+ assertThat(setBobRoot, equalTo("OK"));
+
+ String setCharlieRoot = exec(commandObjects.jsonSet(keyCharlie, Path2.ROOT_PATH, charlie));
+ assertThat(setCharlieRoot, equalTo("OK"));
+
+ List getNames = exec(commandObjects.jsonMGet(Path2.of("name"), keyBob, keyCharlie));
+ assertThat(getNames, contains(
+ jsonEquals(new JSONArray().put("Bob")),
+ jsonEquals(new JSONArray().put("Charlie"))
+ ));
+
+ List getRoots = exec(commandObjects.jsonMGet(Path2.ROOT_PATH, keyBob, keyCharlie));
+ assertThat(getRoots, contains(
+ jsonEquals(new JSONArray().put(bob)),
+ jsonEquals(new JSONArray().put(charlie))
+ ));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonMGetOldPath() {
+ String keyBob = "user:bob";
+ String keyCharlie = "user:charlie";
+
+ JSONObject bob = new JSONObject();
+ bob.put("name", "Bob");
+ bob.put("age", 30);
+
+ JSONObject charlie = new JSONObject();
+ charlie.put("name", "Charlie");
+ charlie.put("age", 25);
+
+ String setBobRoot = exec(commandObjects.jsonSet(keyBob, Path2.ROOT_PATH, bob));
+ assertThat(setBobRoot, equalTo("OK"));
+
+ String setCharlieRoot = exec(commandObjects.jsonSet(keyCharlie, Path2.ROOT_PATH, charlie));
+ assertThat(setCharlieRoot, equalTo("OK"));
+
+ List getNamesTyped = exec(commandObjects.jsonMGet(Path.of("name"), String.class, keyBob, keyCharlie));
+ assertThat(getNamesTyped, contains("Bob", "Charlie"));
+
+ List getPersonsTyped = exec(commandObjects.jsonMGet(Path.ROOT_PATH, Person.class, keyBob, keyCharlie));
+ assertThat(getPersonsTyped, contains(
+ new Person("Bob", 30),
+ new Person("Charlie", 25)
+ ));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonGetAsPlainString() {
+ String key = "user:3000";
+
+ Person person = new Person("John Smith", 30);
+
+ exec(commandObjects.jsonSet(key, Path.ROOT_PATH, person));
+
+ String getName = exec(commandObjects.jsonGetAsPlainString(key, Path.of(".name")));
+ assertThat(getName, equalTo("\"John Smith\""));
+
+ String getRoot = exec(commandObjects.jsonGetAsPlainString(key, Path.ROOT_PATH));
+ assertThat(getRoot, jsonEquals(person));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonGetWithPathAndClass() {
+ String key = "user:4000";
+
+ String jsonObject = "{\"person\":{\"name\":\"Alice Johnson\",\"age\":28}}";
+
+ String setRoot = exec(commandObjects.jsonSetWithPlainString(key, Path.ROOT_PATH, jsonObject));
+ assertThat(setRoot, equalTo("OK"));
+
+ Person getPerson = exec(commandObjects.jsonGet(key, Person.class, Path.of(".person")));
+ assertThat(getPerson.getName(), equalTo("Alice Johnson"));
+ assertThat(getPerson.getAge(), equalTo(28));
+ }
+
+ @Test
+ public void testJsonDel() {
+ String key = "user:11000";
+
+ JSONObject person = new JSONObject();
+ person.put("name", "Gina");
+ person.put("age", 29);
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, person));
+
+ Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(preCheck, jsonEquals(new JSONArray().put(person)));
+
+ Long del = exec(commandObjects.jsonDel(key));
+ assertThat(del, equalTo(1L));
+
+ Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(postCheck, nullValue());
+ }
+
+ @Test
+ public void testJsonDelPath() {
+ String key = "user:11000";
+
+ JSONObject person = new JSONObject();
+ person.put("name", "Gina");
+ person.put("age", 29);
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, person));
+
+ Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(preCheck, jsonEquals(new JSONArray().put(person)));
+
+ Long delAge = exec(commandObjects.jsonDel(key, Path2.of(".age")));
+ assertThat(delAge, equalTo(1L));
+
+ Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONObject expected = new JSONObject();
+ expected.put("name", "Gina");
+ assertThat(postCheck, jsonEquals(new JSONArray().put(expected)));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonDelOldPath() {
+ String key = "user:11000";
+
+ JSONObject person = new JSONObject();
+ person.put("name", "Gina");
+ person.put("age", 29);
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, person));
+
+ Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(preCheck, jsonEquals(new JSONArray().put(person)));
+
+ Long delAge = exec(commandObjects.jsonDel(key, Path.of(".age")));
+ assertThat(delAge, equalTo(1L));
+
+ Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONObject expected = new JSONObject();
+ expected.put("name", "Gina");
+ assertThat(postCheck, jsonEquals(new JSONArray().put(expected)));
+ }
+
+ @Test
+ public void testJsonClear() {
+ String key = "user:11000";
+
+ JSONObject person = new JSONObject();
+ person.put("name", "Gina");
+ person.put("age", 29);
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, person));
+
+ Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(preCheck, jsonEquals(new JSONArray().put(person)));
+
+ Long clear = exec(commandObjects.jsonClear(key));
+ assertThat(clear, equalTo(1L));
+
+ Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONArray expected = new JSONArray().put(new JSONObject());
+ assertThat(postCheck, jsonEquals(expected));
+ }
+
+ @Test
+ public void testJsonClearPath() {
+ String key = "user:11000";
+
+ JSONObject person = new JSONObject();
+ person.put("name", "Gina");
+ person.put("age", 29);
+ person.put("occupations", new JSONArray().put("Data Scientist").put("Developer"));
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, person));
+
+ Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(preCheck, jsonEquals(new JSONArray().put(person)));
+
+ Long clearOccupations = exec(commandObjects.jsonClear(key, Path2.of(".occupations")));
+ assertThat(clearOccupations, equalTo(1L));
+
+ Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONObject expected = new JSONObject();
+ expected.put("name", "Gina");
+ expected.put("age", 29);
+ expected.put("occupations", new JSONArray());
+ assertThat(postCheck, jsonEquals(new JSONArray().put(expected)));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonClearOldPath() {
+ String key = "user:11000";
+
+ JSONObject person = new JSONObject();
+ person.put("name", "Gina");
+ person.put("age", 29);
+ person.put("occupations", new JSONArray().put("Data Scientist").put("Developer"));
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, person));
+
+ Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(preCheck, jsonEquals(new JSONArray().put(person)));
+
+ Long clearOccupations = exec(commandObjects.jsonClear(key, Path.of(".occupations")));
+ assertThat(clearOccupations, equalTo(1L));
+
+ Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONObject expected = new JSONObject();
+ expected.put("name", "Gina");
+ expected.put("age", 29);
+ expected.put("occupations", new JSONArray());
+ assertThat(postCheck, jsonEquals(new JSONArray().put(expected)));
+ }
+
+ @Test
+ public void testJsonToggle() {
+ String key = "user:13000";
+
+ JSONObject item = new JSONObject();
+ item.put("active", true);
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, item));
+
+ Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(preCheck, jsonEquals(new JSONArray().put(item)));
+
+ List toggle = exec(commandObjects.jsonToggle(key, Path2.of(".active")));
+ assertThat(toggle, contains(false));
+
+ Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONObject expected = new JSONObject();
+ expected.put("active", false);
+ assertThat(postCheck, jsonEquals(new JSONArray().put(expected)));
+ }
+
+ @Test
+ public void testJsonType() {
+ String key = "jsonKey";
+
+ JSONObject item = new JSONObject();
+ item.put("active", true);
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, item));
+
+ List> type = exec(commandObjects.jsonType(key, Path2.of(".active")));
+ assertThat(type, contains(boolean.class));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonTypeOldPath() {
+ assumeThat(protocol, not(equalTo(RedisProtocol.RESP3)));
+
+ String key = "jsonKey";
+
+ JSONObject item = new JSONObject();
+ item.put("active", true);
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, item));
+
+ Class> type = exec(commandObjects.jsonType(key, Path.of(".active")));
+ assertThat(type, equalTo(boolean.class));
+ }
+
+ @Test
+ public void testJsonStrAppend() {
+ String key = "user:1000";
+
+ JSONObject person = new JSONObject();
+ person.put("name", "Gina");
+ person.put("age", 29);
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, person));
+
+ Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(preCheck, jsonEquals(new JSONArray().put(person)));
+
+ List strAppend = exec(commandObjects.jsonStrAppend(key, Path2.of(".name"), " Smith"));
+ assertThat(strAppend, contains(10L));
+
+ Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONObject expected = new JSONObject();
+ expected.put("name", "Gina Smith");
+ expected.put("age", 29);
+ assertThat(postCheck, jsonEquals(new JSONArray().put(expected)));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonStrAppendOldPath() {
+ String key = "user:1000";
+
+ JSONObject person = new JSONObject();
+ person.put("name", "Gina");
+ person.put("age", 29);
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, person));
+
+ Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(preCheck, jsonEquals(new JSONArray().put(person)));
+
+ Long strAppend = exec(commandObjects.jsonStrAppend(key, Path.of(".name"), " Smith"));
+ assertThat(strAppend, equalTo(10L));
+
+ Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONObject expected = new JSONObject();
+ expected.put("name", "Gina Smith");
+ expected.put("age", 29);
+ assertThat(postCheck, jsonEquals(new JSONArray().put(expected)));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonStrAppendRootPath() {
+ assumeThat(protocol, not(equalTo(RedisProtocol.RESP3)));
+
+ String key = "user:1000";
+
+ String setRoot = exec(commandObjects.jsonSetWithPlainString(key, Path.ROOT_PATH, "\"John\""));
+ assertThat(setRoot, equalTo("OK"));
+
+ Object getBefore = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(getBefore, jsonEquals(new JSONArray().put("John")));
+
+ Long strAppend = exec(commandObjects.jsonStrAppend(key, " Doe"));
+ assertThat(strAppend, equalTo(8L));
+
+ Object getAfter = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(getAfter, jsonEquals(new JSONArray().put("John Doe")));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonStrLenRootPath() {
+ assumeThat(protocol, not(equalTo(RedisProtocol.RESP3)));
+
+ String key = "user:1001";
+
+ String setRoot = exec(commandObjects.jsonSetWithPlainString(key, Path.ROOT_PATH, "\"Hello World\""));
+ assertThat(setRoot, equalTo("OK"));
+
+ Long strLen = exec(commandObjects.jsonStrLen(key));
+ assertThat(strLen, equalTo(11L)); // "Hello World" length
+ }
+
+ @Test
+ public void testJsonStrLen() {
+ String key = "user:1002";
+
+ JSONObject item = new JSONObject();
+ item.put("message", "Hello, Redis!");
+
+ String setResponse = exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, item));
+ assertThat(setResponse, equalTo("OK"));
+
+ List strLenResponse = exec(commandObjects.jsonStrLen(key, Path2.of(".message")));
+ assertThat(strLenResponse, contains(13L)); // "Hello, Redis!" length
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonStrLenOldPath() {
+ String key = "user:1003";
+
+ JSONObject item = new JSONObject();
+ item.put("message", "Hello, Redis!");
+
+ String setResponse = exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, item));
+ assertThat(setResponse, equalTo("OK"));
+
+ Long strLenResponse = exec(commandObjects.jsonStrLen(key, Path.of(".message")));
+ assertThat(strLenResponse, equalTo(13L)); // "Hello, Redis!" length
+ }
+
+ @Test
+ public void testJsonNumIncrBy() {
+ String key = "user:12000";
+
+ JSONObject item = new JSONObject();
+ item.put("balance", 100);
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, item));
+
+ Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(preCheck, jsonEquals(new JSONArray().put(item)));
+
+ Object numIncrBy = exec(commandObjects.jsonNumIncrBy(key, Path2.of("$.balance"), 50.0));
+ assertThat(numIncrBy, jsonEquals(new JSONArray().put(150.0)));
+
+ Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONObject expected = new JSONObject();
+ expected.put("balance", 150.0);
+ assertThat(postCheck, jsonEquals(new JSONArray().put(expected)));
+ }
+
+ @Test
+ public void testJsonArrAppendWithEscape() {
+ String key = "json";
+
+ JSONArray data = new JSONArray()
+ .put("Elixir")
+ .put("Swift");
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data));
+
+ Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(preCheck, jsonEquals(new JSONArray().put(data)));
+
+ List arrAppend = exec(commandObjects.jsonArrAppendWithEscape(
+ key, Path2.ROOT_PATH, "Kotlin", "TypeScript"));
+ assertThat(arrAppend, contains(4L));
+
+ Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONArray expected = new JSONArray()
+ .put("Elixir")
+ .put("Swift")
+ .put("Kotlin")
+ .put("TypeScript");
+ assertThat(postCheck, jsonEquals(new JSONArray().put(expected)));
+ }
+
+ @Test
+ public void testJsonArrAppend() {
+ String key = "json";
+
+ JSONArray data = new JSONArray()
+ .put("Java")
+ .put("Python");
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data));
+
+ JSONObject person = new JSONObject();
+ person.put("name", "John");
+
+ List arrAppend = exec(commandObjects.jsonArrAppend(key, Path2.ROOT_PATH,
+ "\"C++\"", "\"JavaScript\"", person));
+ assertThat(arrAppend, contains(5L));
+
+ Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONArray expected = new JSONArray()
+ .put("Java")
+ .put("Python")
+ .put("C++")
+ .put("JavaScript")
+ .put(person);
+ assertThat(postCheck, jsonEquals(new JSONArray().put(expected)));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonArrAppendOldPath() {
+ String key = "json";
+
+ JSONArray data = new JSONArray()
+ .put(new JSONArray()
+ .put("Java")
+ .put("Python"))
+ .put(1);
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data));
+
+ Person person = new Person("John", 45);
+
+ Long arrAppend = exec(
+ commandObjects.jsonArrAppend(key, Path.of(".[0]"), "Swift", "Go", person));
+ assertThat(arrAppend, equalTo(5L));
+
+ Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONArray expected = new JSONArray()
+ .put(new JSONArray()
+ .put("Java")
+ .put("Python")
+ .put("Swift")
+ .put("Go")
+ .put(new JSONObject()
+ .put("name", "John")
+ .put("age", 45)))
+ .put(1);
+ assertThat(postCheck, jsonEquals(new JSONArray().put(expected)));
+ }
+
+ @Test
+ public void testJsonArrIndex() {
+ String key = "json";
+
+ JSONArray data = new JSONArray()
+ .put("Java")
+ .put("Python")
+ .put("Java"); // duplicate
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data));
+
+ List arrIndex = exec(commandObjects.jsonArrIndex(key, Path2.ROOT_PATH, "\"Java\""));
+ assertThat(arrIndex, contains(0L));
+
+ List arrIndexNotFound = exec(commandObjects.jsonArrIndex(key, Path2.ROOT_PATH, "\"C++\""));
+ assertThat(arrIndexNotFound, contains(-1L));
+ }
+
+ @Test
+ public void testJsonArrIndexWithEscape() {
+ String key = "json";
+
+ JSONArray data = new JSONArray()
+ .put("Java")
+ .put("Python")
+ .put("Java"); // duplicate
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data));
+
+ List arrIndex = exec(commandObjects.jsonArrIndexWithEscape(key, Path2.ROOT_PATH, "Java"));
+ assertThat(arrIndex, contains(0L));
+
+ List arrIndexNotFound = exec(commandObjects.jsonArrIndexWithEscape(key, Path2.ROOT_PATH, "Go"));
+ assertThat(arrIndexNotFound, contains(-1L));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonArrIndexDeprecated() {
+ String key = "json";
+
+ JSONArray data = new JSONArray()
+ .put(new JSONArray()
+ .put("Java")
+ .put("Python")
+ .put("Java")); // duplicate
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data));
+
+ Long arrIndex = exec(commandObjects.jsonArrIndex(key, Path.of(".[0]"), "Java"));
+ assertThat(arrIndex, equalTo(0L));
+
+ Long arrIndexNotFound = exec(commandObjects.jsonArrIndex(key, Path.of(".[0]"), "Swift"));
+ assertThat(arrIndexNotFound, equalTo(-1L));
+ }
+
+ @Test
+ public void testJsonArrInsert() {
+ String key = "json";
+
+ JSONArray data = new JSONArray()
+ .put("Java")
+ .put("Python");
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data));
+
+ Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(preCheck, jsonEquals(new JSONArray().put(data)));
+
+ List arrInsert = exec(
+ commandObjects.jsonArrInsert(key, Path2.ROOT_PATH, 1, "\"C++\""));
+ assertThat(arrInsert, contains(3L));
+
+ Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONArray expected = new JSONArray()
+ .put("Java")
+ .put("C++")
+ .put("Python");
+ assertThat(postCheck, jsonEquals(new JSONArray().put(expected)));
+ }
+
+ @Test
+ public void testJsonArrInsertWithEscape() {
+ String key = "json";
+
+ JSONArray data = new JSONArray()
+ .put("Java")
+ .put("Python");
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data));
+
+ Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(preCheck, jsonEquals(new JSONArray().put(data)));
+
+ List arrInsert = exec(commandObjects.jsonArrInsertWithEscape(key, Path2.ROOT_PATH, 1, "Go"));
+ assertThat(arrInsert, contains(3L));
+
+ Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONArray expected = new JSONArray()
+ .put("Java")
+ .put("Go")
+ .put("Python");
+ assertThat(postCheck, jsonEquals(new JSONArray().put(expected)));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonArrInsertOldPath() {
+ String key = "json";
+
+ JSONArray data = new JSONArray()
+ .put(1)
+ .put(new JSONArray()
+ .put("Scala")
+ .put("Kotlin"));
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data));
+
+ Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(preCheck, jsonEquals(new JSONArray().put(data)));
+
+ Long arrInsert = exec(commandObjects.jsonArrInsert(key, Path.of(".[1]"), 1, "Swift"));
+ assertThat(arrInsert, equalTo(3L));
+
+ Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONArray expected = new JSONArray()
+ .put(1)
+ .put(new JSONArray()
+ .put("Scala")
+ .put("Swift")
+ .put("Kotlin"));
+ assertThat(postCheck, jsonEquals(new JSONArray().put(expected)));
+ }
+
+ @Test
+ @Deprecated
+ public void testJsonArrPopRoot() {
+ String key = "json";
+
+ JSONArray data = new JSONArray()
+ .put("apple")
+ .put("banana")
+ .put("cherry");
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data));
+
+ Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(preCheck, jsonEquals(new JSONArray().put(data)));
+
+ Object arrPop = exec(commandObjects.jsonArrPop(key));
+ assertThat(arrPop, equalTo("cherry"));
+
+ Object postCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+
+ JSONArray expected = new JSONArray()
+ .put("apple")
+ .put("banana");
+ assertThat(postCheck, jsonEquals(new JSONArray().put(expected)));
+ }
+
+ @Test
+ public void testJsonArrPopWithPath2() {
+ String key = "json";
+
+ JSONObject data = new JSONObject()
+ .put("fruits", new JSONArray()
+ .put("apple")
+ .put("banana")
+ .put("cherry"));
+
+ exec(commandObjects.jsonSet(key, Path2.ROOT_PATH, data));
+
+ Object preCheck = exec(commandObjects.jsonGet(key, Path2.ROOT_PATH));
+ assertThat(preCheck, jsonEquals(new JSONArray().put(data)));
+
+ List