diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index 708db5fc5a..d51d3a89ff 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -2688,27 +2688,27 @@ public final CommandObject> xreadGroup(byte[] groupName, byte[] con // Scripting commands public final CommandObject eval(String script) { - return new CommandObject<>(commandArguments(EVAL).add(script).add(0), BuilderFactory.ENCODED_OBJECT); + return new CommandObject<>(commandArguments(EVAL).add(script).add(0), BuilderFactory.AGGRESSIVE_ENCODED_OBJECT); } public final CommandObject eval(String script, String sampleKey) { - return new CommandObject<>(commandArguments(EVAL).add(script).add(0).processKey(sampleKey), BuilderFactory.ENCODED_OBJECT); + return new CommandObject<>(commandArguments(EVAL).add(script).add(0).processKey(sampleKey), BuilderFactory.AGGRESSIVE_ENCODED_OBJECT); } public final CommandObject eval(String script, int keyCount, String... params) { return new CommandObject<>(commandArguments(EVAL).add(script).add(keyCount) .addObjects((Object[]) params).processKeys(Arrays.copyOf(params, keyCount)), - BuilderFactory.ENCODED_OBJECT); + BuilderFactory.AGGRESSIVE_ENCODED_OBJECT); } public final CommandObject eval(String script, List keys, List args) { return new CommandObject<>(commandArguments(EVAL).add(script).add(keys.size()) - .keys(keys).addObjects(args), BuilderFactory.ENCODED_OBJECT); + .keys(keys).addObjects(args), BuilderFactory.AGGRESSIVE_ENCODED_OBJECT); } public final CommandObject evalReadonly(String script, List keys, List args) { return new CommandObject<>(commandArguments(EVAL_RO).add(script).add(keys.size()) - .keys(keys).addObjects(args), BuilderFactory.ENCODED_OBJECT); + .keys(keys).addObjects(args), BuilderFactory.AGGRESSIVE_ENCODED_OBJECT); } public final CommandObject eval(byte[] script) { @@ -2736,27 +2736,27 @@ public final CommandObject evalReadonly(byte[] script, List keys } public final CommandObject evalsha(String sha1) { - return new CommandObject<>(commandArguments(EVALSHA).add(sha1).add(0), BuilderFactory.ENCODED_OBJECT); + return new CommandObject<>(commandArguments(EVALSHA).add(sha1).add(0), BuilderFactory.AGGRESSIVE_ENCODED_OBJECT); } public final CommandObject evalsha(String sha1, String sampleKey) { - return new CommandObject<>(commandArguments(EVALSHA).add(sha1).add(0).processKey(sampleKey), BuilderFactory.ENCODED_OBJECT); + return new CommandObject<>(commandArguments(EVALSHA).add(sha1).add(0).processKey(sampleKey), BuilderFactory.AGGRESSIVE_ENCODED_OBJECT); } public final CommandObject evalsha(String sha1, int keyCount, String... params) { return new CommandObject<>(commandArguments(EVALSHA).add(sha1).add(keyCount) .addObjects((Object[]) params).processKeys(Arrays.copyOf(params, keyCount)), - BuilderFactory.ENCODED_OBJECT); + BuilderFactory.AGGRESSIVE_ENCODED_OBJECT); } public final CommandObject evalsha(String sha1, List keys, List args) { return new CommandObject<>(commandArguments(EVALSHA).add(sha1).add(keys.size()) - .keys(keys).addObjects(args), BuilderFactory.ENCODED_OBJECT); + .keys(keys).addObjects(args), BuilderFactory.AGGRESSIVE_ENCODED_OBJECT); } public final CommandObject evalshaReadonly(String sha1, List keys, List args) { return new CommandObject<>(commandArguments(EVALSHA_RO).add(sha1).add(keys.size()) - .keys(keys).addObjects(args), BuilderFactory.ENCODED_OBJECT); + .keys(keys).addObjects(args), BuilderFactory.AGGRESSIVE_ENCODED_OBJECT); } public final CommandObject evalsha(byte[] sha1) { @@ -2853,12 +2853,12 @@ public final CommandObject slowlogReset() { public final CommandObject fcall(String name, List keys, List args) { return new CommandObject<>(commandArguments(FCALL).add(name).add(keys.size()) - .keys(keys).addObjects(args), BuilderFactory.ENCODED_OBJECT); + .keys(keys).addObjects(args), BuilderFactory.AGGRESSIVE_ENCODED_OBJECT); } public final CommandObject fcallReadonly(String name, List keys, List args) { return new CommandObject<>(commandArguments(FCALL_RO).add(name).add(keys.size()) - .keys(keys).addObjects(args), BuilderFactory.ENCODED_OBJECT); + .keys(keys).addObjects(args), BuilderFactory.AGGRESSIVE_ENCODED_OBJECT); } public final CommandObject functionDelete(String libraryName) { @@ -4206,12 +4206,12 @@ public final CommandObject> tFunctionList(TFunctionListPa public final CommandObject tFunctionCall(String library, String function, List keys, List args) { return new CommandObject<>(commandArguments(GearsCommand.TFCALL).add(library + "." + function) - .add(keys.size()).keys(keys).addObjects(args), BuilderFactory.ENCODED_OBJECT); + .add(keys.size()).keys(keys).addObjects(args), BuilderFactory.AGGRESSIVE_ENCODED_OBJECT); } public final CommandObject tFunctionCallAsync(String library, String function, List keys, List args) { return new CommandObject<>(commandArguments(GearsCommand.TFCALLASYNC).add(library + "." + function) - .add(keys.size()).keys(keys).addObjects(args), BuilderFactory.ENCODED_OBJECT); + .add(keys.size()).keys(keys).addObjects(args), BuilderFactory.AGGRESSIVE_ENCODED_OBJECT); } // RedisGears commands diff --git a/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java b/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java index d30b282b30..e4dc10a82d 100644 --- a/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java +++ b/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java @@ -12,7 +12,6 @@ import redis.clients.jedis.gears.TFunctionLoadParams; import redis.clients.jedis.modules.RedisModuleCommandsTestBase; import redis.clients.jedis.gears.resps.GearsLibraryInfo; -import redis.clients.jedis.util.KeyValue; import java.io.IOException; import java.nio.file.Files; @@ -429,44 +428,21 @@ public void testLibraryCallHashResult() throws IOException { Object result = client.tFunctionCall("hashitout", "hashy", Collections.singletonList("hash1"), Collections.emptyList()); - assertEquals(ArrayList.class, result.getClass()); - List list = (List) result; - assertFalse(list.isEmpty()); - boolean isResp3 = list.get(0) instanceof KeyValue; - assertEquals(isResp3 ? 7 : 14, list.size()); + final Map asMap; if (protocol != RedisProtocol.RESP3) { - List asList = (List) result; - int indexOfJava = asList.indexOf("Java"); - assertTrue(indexOfJava >= 0); - assertEquals("James Gosling", asList.get(indexOfJava + 1)); - int indexOfJavaScript = asList.indexOf("JavaScript"); - assertTrue(indexOfJavaScript >= 0); - assertEquals("Brendan Eich", asList.get(indexOfJavaScript + 1)); - int indexOfC = asList.indexOf("C"); - assertTrue(indexOfC >= 0); - assertEquals("Dennis Ritchie", asList.get(indexOfC + 1)); - int indexOfRuby = asList.indexOf("Ruby"); - assertTrue(indexOfRuby >= 0); - assertEquals("Yukihiro Matsumoto", asList.get(indexOfRuby + 1)); - int indexOfPython = asList.indexOf("Python"); - assertTrue(indexOfPython >= 0); - assertEquals("Guido van Rossum", asList.get(indexOfPython + 1)); - int indexOfCPP = asList.indexOf("C++"); - assertTrue(indexOfCPP >= 0); - assertEquals("Bjarne Stroustrup", asList.get(indexOfCPP + 1)); - int indexOfLastUpdated = asList.indexOf("__last_updated__"); - assertTrue(indexOfLastUpdated >= 0); - assertTrue(Integer.parseInt(asList.get(indexOfLastUpdated + 1)) > 0); + final List asList = (List) result; + asMap = flatMapToMap(asList); + } else { - for (KeyValue kv : (List>) result) { - if (!kv.getKey().toString().equalsIgnoreCase("__last_updated__")) { - assertTrue(payload.containsKey(kv.getKey())); - assertEquals(payload.get(kv.getKey()), kv.getValue()); - } - } + asMap = (Map) result; } + + payload.forEach((language, author) -> { + assertThat(asMap, Matchers.hasEntry(language, author)); + }); + assertThat(Long.parseLong(asMap.get("__last_updated__")), Matchers.greaterThan(0L)); } @Test @@ -540,4 +516,12 @@ private static Map>> initializeTestLibr return libraryConditions; } + + private static Map flatMapToMap(List list) { + Map map = new HashMap(list.size() / 2); + for (int i = 0; i < list.size(); i += 2) { + map.put(list.get(i), list.get(i + 1)); + } + return map; + } }