From f05e0444ef76a5ad2f633dcbd03b52d41d5bbf25 Mon Sep 17 00:00:00 2001 From: Avital-Fine Date: Tue, 22 Feb 2022 20:15:19 +0100 Subject: [PATCH 01/23] Commands [..] commands --- .../redis/clients/jedis/BuilderFactory.java | 88 +++++++++++++++++ .../redis/clients/jedis/CommandObjects.java | 39 ++++++++ src/main/java/redis/clients/jedis/Jedis.java | 55 +++++++++++ .../java/redis/clients/jedis/Protocol.java | 4 +- .../redis/clients/jedis/UnifiedJedis.java | 45 +++++++++ .../jedis/commands/CommandCommands.java | 73 ++++++++++++++ .../clients/jedis/commands/JedisCommands.java | 2 +- .../clients/jedis/resps/CommandDocs.java | 45 +++++++++ .../clients/jedis/resps/CommandInfo.java | 99 +++++++++++++++++++ .../redis/clients/jedis/resps/KeyedFlags.java | 21 ++++ .../jedis/AllKindOfValuesCommandsTest.java | 70 +++++++++++++ 11 files changed, 538 insertions(+), 3 deletions(-) create mode 100644 src/main/java/redis/clients/jedis/commands/CommandCommands.java create mode 100644 src/main/java/redis/clients/jedis/resps/CommandDocs.java create mode 100644 src/main/java/redis/clients/jedis/resps/CommandInfo.java create mode 100644 src/main/java/redis/clients/jedis/resps/KeyedFlags.java diff --git a/src/main/java/redis/clients/jedis/BuilderFactory.java b/src/main/java/redis/clients/jedis/BuilderFactory.java index 67b17e0d2c..93f6b4b762 100644 --- a/src/main/java/redis/clients/jedis/BuilderFactory.java +++ b/src/main/java/redis/clients/jedis/BuilderFactory.java @@ -691,6 +691,94 @@ public String toString() { } }; + public static final Builder> COMMAND_DOCS_RESPONSE = new Builder>() { + @Override + public List build(Object data) { + if (data == null) { + return null; + } + + List rawList = (List) data; + List list = new ArrayList<>(rawList.size()); + + for (int i = 0; i < rawList.size();) { + String name = STRING.build(rawList.get(i++)); + List commandData = (List) rawList.get(i++); + String summary = STRING.build(commandData.get(1)); + String since = STRING.build(commandData.get(3)); + String group = STRING.build(commandData.get(5)); + String complexity = STRING.build(commandData.get(7)); + List history = null; + if (STRING.build(commandData.get(8)).equals("history")) { + List> rawHistory = (List>) commandData.get(9); + history = new ArrayList<>(rawHistory.size()); + for (List timePoint : rawHistory) { + history.add(STRING.build(timePoint.get(0)) + ": " + STRING.build(timePoint.get(1))); + } + } + + list.add(new CommandDocs(name, summary, since, group, complexity, history)); + } + + return list; + } + }; + + public static final Builder> KEYS_AND_FLAGS = new Builder>() { + @Override + public List build(Object data) { + if (data == null) { + return null; + } + + List rawList = (List) data; + List list = new ArrayList<>(rawList.size()); + + for (Object rawKeyInfo : rawList) { + List keyInfo = (List) rawKeyInfo; + String name = STRING.build(keyInfo.get(0)); + List flags = STRING_LIST.build(keyInfo.get(1)); + list.add(new KeyedFlags(name, flags)); + } + + return list; + } + }; + + public static final Builder> COMMAND_INFO_RESPONSE = new Builder>() { + @Override + public List build(Object data) { + if (data == null) { + return null; + } + + List rawList = (List) data; + List list = new ArrayList<>(rawList.size()); + + for (Object rawCommandInfo : rawList) { + if (rawCommandInfo == null) { + list.add(null); + break; + } + + List commandInfo = (List) rawCommandInfo; + String name = STRING.build(commandInfo.get(0)); + long arity = LONG.build(commandInfo.get(1)); + List flags = STRING_LIST.build(commandInfo.get(2)); + long firstKey = LONG.build(commandInfo.get(3)); + long lastKey = LONG.build(commandInfo.get(4)); + long step = LONG.build(commandInfo.get(5)); + List aclCategories = STRING_LIST.build(commandInfo.get(6)); + List tips = STRING_LIST.build(commandInfo.get(7)); + List subcommands = STRING_LIST.build(commandInfo.get(9)); + + list.add(new CommandInfo(name, arity, flags, firstKey, lastKey, step, aclCategories, tips, subcommands)); + } + + return list; + } + }; + public static final Builder> MODULE_LIST = new Builder>() { @Override public List build(Object data) { diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index b25055e0b8..a5ca1e5a61 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -2811,6 +2811,45 @@ public final CommandObject publish(byte[] channel, byte[] message) { } // Miscellaneous commands + public final CommandObject commandCount() { + return new CommandObject<>(commandArguments(COMMAND).add(COUNT), BuilderFactory.LONG); + } + + public final CommandObject> commandDocs(String... commands) { + return new CommandObject<>(commandArguments(COMMAND).add(DOCS).addObjects((Object[]) commands), BuilderFactory.COMMAND_DOCS_RESPONSE); + } + + public final CommandObject> commandGetKeys(String... command) { + return new CommandObject<>(commandArguments(COMMAND).add(GETKEYS).addObjects((Object[]) command), BuilderFactory.STRING_LIST); + } + + public final CommandObject> commandGetKeysSandFlags(String... command) { + return new CommandObject<>(commandArguments(COMMAND).add(GETKEYSANDFLAGS).addObjects((Object[]) command), BuilderFactory.KEYS_AND_FLAGS); + } + + public final CommandObject> commandInfo(String... commands) { + return new CommandObject<>(commandArguments(COMMAND).add(Keyword.INFO).addObjects((Object[]) commands), BuilderFactory.COMMAND_INFO_RESPONSE); + } + + public final CommandObject> commandList() { + return new CommandObject<>(commandArguments(COMMAND).add(LIST), BuilderFactory.STRING_LIST); + } + + public final CommandObject> commandListFilterByModule(String moduleName) { + return new CommandObject<>(commandArguments(COMMAND).add(LIST).add(FILTERBY).add(MODULE).add(moduleName), + BuilderFactory.STRING_LIST); + } + + public final CommandObject> commandListFilterByAclcat(String moduleName) { + return new CommandObject<>(commandArguments(COMMAND).add(LIST).add(FILTERBY).add(ACLCAT).add(moduleName), + BuilderFactory.STRING_LIST); + } + + public final CommandObject> commandListFilterByPattern(String pattern) { + return new CommandObject<>(commandArguments(COMMAND).add(LIST).add(FILTERBY).add(PATTERN).add(pattern), + BuilderFactory.STRING_LIST); + } + // RediSearch commands public CommandObject ftCreate(String indexName, IndexOptions indexOptions, Schema schema) { CommandArguments args = commandArguments(SearchCommand.CREATE).add(indexName) diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 0b9a12d6dd..66ad35eff2 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -7939,6 +7939,61 @@ public long bitop(final BitOP op, final String destKey, final String... srcKeys) return connection.executeCommand(commandObjects.bitop(op, destKey, srcKeys)); } + @Override + public long commandCount() { + checkIsInMultiOrPipeline(); + connection.sendCommand(COMMAND, COUNT); + return connection.getIntegerReply(); + } + + @Override + public List commandDocs(String... commands) { + checkIsInMultiOrPipeline(); + return connection.executeCommand(commandObjects.commandDocs(commands)); + } + + @Override + public List commandGetKeys(String... command) { + checkIsInMultiOrPipeline(); + return connection.executeCommand(commandObjects.commandGetKeys(command)); + } + + @Override + public List commandGetKeysSandFlags(String... command) { + checkIsInMultiOrPipeline(); + return connection.executeCommand(commandObjects.commandGetKeysSandFlags(command)); + } + + @Override + public List commandInfo(String... commands) { + checkIsInMultiOrPipeline(); + return connection.executeCommand(commandObjects.commandInfo(commands)); + } + + @Override + public List commandList() { + checkIsInMultiOrPipeline(); + return connection.executeCommand(commandObjects.commandList()); + } + + @Override + public List commandListFilterByModule(String moduleName) { + checkIsInMultiOrPipeline(); + return connection.executeCommand(commandObjects.commandListFilterByModule(moduleName)); + } + + @Override + public List commandListFilterByAclcat(String category) { + checkIsInMultiOrPipeline(); + return connection.executeCommand(commandObjects.commandListFilterByAclcat(category)); + } + + @Override + public List commandListFilterByPattern(String pattern) { + checkIsInMultiOrPipeline(); + return connection.executeCommand(commandObjects.commandListFilterByPattern(pattern)); + } + @Override public String sentinelMyId() { connection.sendCommand(SENTINEL, MYID); diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index 189b50c773..9d2fc610a4 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -236,7 +236,7 @@ public static enum Command implements ProtocolCommand { GEORADIUSBYMEMBER, GEORADIUSBYMEMBER_RO, BITFIELD, TOUCH, SWAPDB, MEMORY, BZPOPMIN, BZPOPMAX, XADD, XLEN, XDEL, XTRIM, XRANGE, XREVRANGE, XREAD, XACK, XGROUP, XREADGROUP, XPENDING, XCLAIM, XAUTOCLAIM, XINFO, BITFIELD_RO, ROLE, FAILOVER, GEOSEARCH, GEOSEARCHSTORE, EVAL_RO, EVALSHA_RO, - LOLWUT, EXPIRETIME, PEXPIRETIME, @Deprecated STRALGO; + LOLWUT, EXPIRETIME, PEXPIRETIME, @Deprecated STRALGO, COMMAND, DOCS, GETKEYS, GETKEYSANDFLAGS; private final byte[] raw; @@ -261,7 +261,7 @@ public static enum Keyword implements Rawable { TIMEOUT, ABORT, NX, XX, EX, PX, EXAT, PXAT, CH, WITHCOORD, WITHDIST, WITHHASH, STOREDIST, COPY, KEEPTTL, AUTH, AUTH2, INFO, CHANNELS, NUMPAT, NUMSUB, FULL, NOW, VERSION, KEYS, IDX, SCHEDULE, ANY, FROMMEMBER, FROMLONLAT, BYRADIUS, BYBOX, BYLEX, BYSCORE, REV, MINMATCHLEN, WITHMATCHLEN, - PURGE, STATS, @Deprecated LCS, @Deprecated STRINGS; + PURGE, STATS, @Deprecated LCS, @Deprecated STRINGS, FILTERBY, ACLCAT, PATTERN; private final byte[] raw; diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index 372dc5a83c..b3a2118f6d 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -504,6 +504,51 @@ public Set keys(String pattern) { return executeCommand(commandObjects.keys(pattern)); } + @Override + public long commandCount() { + return executeCommand(commandObjects.commandCount()); + } + + @Override + public List commandDocs(String... commands) { + return executeCommand(commandObjects.commandDocs(commands)); + } + + @Override + public List commandGetKeys(String... command) { + return executeCommand(commandObjects.commandGetKeys(command)); + } + + @Override + public List commandGetKeysSandFlags(String... command) { + return executeCommand(commandObjects.commandGetKeysSandFlags(command)); + } + + @Override + public List commandInfo(String... commands) { + return executeCommand(commandObjects.commandInfo(commands)); + } + + @Override + public List commandList() { + return executeCommand(commandObjects.commandList()); + } + + @Override + public List commandListFilterByModule(String moduleName) { + return executeCommand(commandObjects.commandListFilterByModule(moduleName)); + } + + @Override + public List commandListFilterByAclcat(String category) { + return executeCommand(commandObjects.commandListFilterByAclcat(category)); + } + + @Override + public List commandListFilterByPattern(String pattern) { + return executeCommand(commandObjects.commandListFilterByPattern(pattern)); + } + @Override public ScanResult scan(String cursor) { return executeCommand(commandObjects.scan(cursor)); diff --git a/src/main/java/redis/clients/jedis/commands/CommandCommands.java b/src/main/java/redis/clients/jedis/commands/CommandCommands.java new file mode 100644 index 0000000000..3658738022 --- /dev/null +++ b/src/main/java/redis/clients/jedis/commands/CommandCommands.java @@ -0,0 +1,73 @@ +package redis.clients.jedis.commands; + +import redis.clients.jedis.resps.CommandDocs; +import redis.clients.jedis.resps.CommandInfo; +import redis.clients.jedis.resps.KeyedFlags; + +import java.util.List; + +public interface CommandCommands { + + /** + * The number of total commands in this Redis server + * @return The number of total commands + */ + long commandCount(); + + /** + * Return documentary information about commands. + * If not specifying commands, the reply includes all the server's commands. + * @param commands specify the names of one or more commands + * @return list of {@link CommandDocs} + */ + + List commandDocs(String... commands); + + /** + * Return list of keys from a full Redis command + * @param command + * @return list of keys + */ + List commandGetKeys(String... command); + + /** + * Return list of keys from a full Redis command and their usage flags + * @param command + * @return list of {@link KeyedFlags} + */ + List commandGetKeysSandFlags(String... command); + + /** + * Return details about multiple Redis commands + * @param commands + * @return list of {@link CommandInfo} + */ + List commandInfo(String... commands); + + /** + * Return a list of the server's command names + * @return commands list + */ + List commandList(); + + /** + * Return a list of the server's command names filter by module's name + * @param moduleName + * @return commands list + */ + List commandListFilterByModule(String moduleName); + + /** + * Return a list of the server's command names filter by ACL category + * @param category + * @return commands list + */ + List commandListFilterByAclcat(String category); + + /** + * Return a list of the server's command names filter by glob-like pattern + * @param pattern + * @return commands list + */ + List commandListFilterByPattern(String pattern); +} diff --git a/src/main/java/redis/clients/jedis/commands/JedisCommands.java b/src/main/java/redis/clients/jedis/commands/JedisCommands.java index a00b5329f2..9b34869629 100644 --- a/src/main/java/redis/clients/jedis/commands/JedisCommands.java +++ b/src/main/java/redis/clients/jedis/commands/JedisCommands.java @@ -2,5 +2,5 @@ public interface JedisCommands extends KeyCommands, StringCommands, ListCommands, HashCommands, SetCommands, SortedSetCommands, GeoCommands, HyperLogLogCommands, StreamCommands, - ScriptingKeyCommands { + ScriptingKeyCommands, CommandCommands { } diff --git a/src/main/java/redis/clients/jedis/resps/CommandDocs.java b/src/main/java/redis/clients/jedis/resps/CommandDocs.java new file mode 100644 index 0000000000..3cb729ee7f --- /dev/null +++ b/src/main/java/redis/clients/jedis/resps/CommandDocs.java @@ -0,0 +1,45 @@ +package redis.clients.jedis.resps; + +import java.util.List; + +public class CommandDocs { + private final String name; + private final String summary; + private final String since; + private final String group; + private final String complexity; + private final List history; + + public CommandDocs(String name, String summary, String since, String group, String complexity, List history) { + this.name = name; + this.summary = summary; + this.since = since; + this.group = group; + this.complexity = complexity; + this.history = history; + } + + public String getName() { + return name; + } + + public String getSummary() { + return summary; + } + + public String getSince() { + return since; + } + + public String getGroup() { + return group; + } + + public String getComplexity() { + return complexity; + } + + public List getHistory() { + return history; + } +} diff --git a/src/main/java/redis/clients/jedis/resps/CommandInfo.java b/src/main/java/redis/clients/jedis/resps/CommandInfo.java new file mode 100644 index 0000000000..4a905e8498 --- /dev/null +++ b/src/main/java/redis/clients/jedis/resps/CommandInfo.java @@ -0,0 +1,99 @@ +package redis.clients.jedis.resps; + +import java.util.List; + +public class CommandInfo { + private final String name; + private final long arity; + private final List flags; + private final long firstKey; + private final long lastKey; + private final long step; + private final List aclCategories; + private final List tips; + private final List subcommands; + + public CommandInfo(String name, long arity, List flags, long firstKey, long lastKey, long step, + List aclCategories, List tips, List subcommands) { + this.name = name; + this.arity = arity; + this.flags = flags; + this.firstKey = firstKey; + this.lastKey = lastKey; + this.step = step; + this.aclCategories = aclCategories; + this.tips = tips; + this.subcommands = subcommands; + } + + /** + * Command's name in lowercase + */ + public String getName() { + return name; + } + + /** + * Arity is the number of arguments a command expects. It follows a simple pattern: + * A positive integer means a fixed number of arguments. + * A negative integer means a minimal number of arguments. + * + * Examples: + * + * GET's arity is 2 since the command only accepts one argument and always has the format GET _key_. + * MGET's arity is -2 since the command accepts at least one argument, but possibly multiple ones: MGET _key1_ [key2] [key3] .... + */ + public long getArity() { + return arity; + } + + /** + * Command flags + */ + public List getFlags() { + return flags; + } + + /** + * The position of the command's first key name argument + */ + public long getFirstKey() { + return firstKey; + } + + /** + * The position of the command's last key name argument + * Commands that accept a single key have both first key and last key set to 1 + */ + public long getLastKey() { + return lastKey; + } + + /** + * This value is the step, or increment, between the first key and last key values where the keys are + */ + public long getStep() { + return step; + } + + /** + * An array of simple strings that are the ACL categories to which the command belongs + */ + public List getAclCategories() { + return aclCategories; + } + + /** + * Helpful information about the command + */ + public List getTips() { + return tips; + } + + /** + * All the command's subcommands, if any + */ + public List getSubcommands() { + return subcommands; + } +} diff --git a/src/main/java/redis/clients/jedis/resps/KeyedFlags.java b/src/main/java/redis/clients/jedis/resps/KeyedFlags.java new file mode 100644 index 0000000000..c6aa35eb39 --- /dev/null +++ b/src/main/java/redis/clients/jedis/resps/KeyedFlags.java @@ -0,0 +1,21 @@ +package redis.clients.jedis.resps; + +import java.util.List; + +public class KeyedFlags { + private final String key; + private final List flags; + + public KeyedFlags(String name, List flags) { + this.key = name; + this.flags = flags; + } + + public String getKey() { + return key; + } + + public List getFlags() { + return flags; + } +} diff --git a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java index 1e6c379075..384870e8a7 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java @@ -36,6 +36,9 @@ import redis.clients.jedis.args.ExpiryOption; import redis.clients.jedis.params.LolwutParams; import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.resps.CommandDocs; +import redis.clients.jedis.resps.CommandInfo; +import redis.clients.jedis.resps.KeyedFlags; import redis.clients.jedis.resps.ScanResult; import redis.clients.jedis.StreamEntryID; import redis.clients.jedis.args.FlushMode; @@ -1055,4 +1058,71 @@ public void copy() { assertTrue(jedis.copy(bfoo1, bfoo2, true)); assertArrayEquals(bbar1, jedis.get(bfoo2)); } + + @Test + public void commandCount() { + assertTrue(jedis.commandCount() > 100); + } + + @Test + public void commandDocs() { + List docs = jedis.commandDocs("SORT", "SET"); + + CommandDocs sortDoc = docs.get(0); + assertEquals("sort", sortDoc.getName()); + assertEquals("generic", sortDoc.getGroup()); + assertEquals("Sort the elements in a list, set or sorted set", sortDoc.getSummary()); + assertNull(sortDoc.getHistory()); + + CommandDocs setDoc = docs.get(1); + assertEquals("1.0.0", setDoc.getSince()); + assertEquals("O(1)", setDoc.getComplexity()); + assertEquals("2.6.12: Added the `EX`, `PX`, `NX` and `XX` options.", setDoc.getHistory().get(0)); + } + + @Test + public void commandGetKeys() { + List keys = jedis.commandGetKeys("SORT", "mylist", "ALPHA", "STORE", "outlist"); + assertEquals(2, keys.size()); + + List keySandFlags = jedis.commandGetKeysSandFlags("SET", "k1", "v1"); + assertEquals("k1", keySandFlags.get(0).getKey()); + assertEquals(2, keySandFlags.get(0).getFlags().size()); + } + + @Test + public void commandInfo() { + List infos = jedis.commandInfo("GET", "SET", "foo"); + + CommandInfo getInfo = infos.get(0); + assertEquals(2, getInfo.getArity()); + assertEquals(2, getInfo.getFlags().size()); + assertEquals(1, getInfo.getFirstKey()); + assertEquals(1, getInfo.getLastKey()); + assertEquals(1, getInfo.getStep()); + + CommandInfo setInfo = infos.get(1); + assertEquals("set", setInfo.getName()); + assertEquals(3, setInfo.getAclCategories().size()); + assertEquals(0, setInfo.getTips().size()); + assertEquals(0, setInfo.getSubcommands().size()); + + assertNull(infos.get(2)); // non-existing command + } + + @Test + public void commandList() { + List commands = jedis.commandList(); + assertTrue(commands.size() > 100); + + commands = jedis.commandListFilterByModule("JSON"); + assertEquals(0, commands.size()); // json module was not loaded + + commands = jedis.commandListFilterByAclcat("admin"); + assertTrue(commands.size() > 10); + + commands = jedis.commandListFilterByPattern("a*"); + assertTrue(commands.size() > 10); + } + } From 4be5a482f6477e29a13a6a923a80e30a66c26790 Mon Sep 17 00:00:00 2001 From: Avital-Fine <98389525+Avital-Fine@users.noreply.github.com> Date: Tue, 22 Feb 2022 21:26:03 +0100 Subject: [PATCH 02/23] Update CommandInfo.java --- src/main/java/redis/clients/jedis/resps/CommandInfo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/redis/clients/jedis/resps/CommandInfo.java b/src/main/java/redis/clients/jedis/resps/CommandInfo.java index 4a905e8498..ef2ccd81f7 100644 --- a/src/main/java/redis/clients/jedis/resps/CommandInfo.java +++ b/src/main/java/redis/clients/jedis/resps/CommandInfo.java @@ -30,7 +30,7 @@ public CommandInfo(String name, long arity, List flags, long firstKey, l * Command's name in lowercase */ public String getName() { - return name; + return name; } /** @@ -44,7 +44,7 @@ public String getName() { * MGET's arity is -2 since the command accepts at least one argument, but possibly multiple ones: MGET _key1_ [key2] [key3] .... */ public long getArity() { - return arity; + return arity; } /** From 3c7e7d6d78a44cc567255550389ce2f9be4ae01a Mon Sep 17 00:00:00 2001 From: Avital-Fine <98389525+Avital-Fine@users.noreply.github.com> Date: Tue, 22 Feb 2022 21:26:21 +0100 Subject: [PATCH 03/23] Update KeyedFlags.java --- src/main/java/redis/clients/jedis/resps/KeyedFlags.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/resps/KeyedFlags.java b/src/main/java/redis/clients/jedis/resps/KeyedFlags.java index c6aa35eb39..fe7c713a2d 100644 --- a/src/main/java/redis/clients/jedis/resps/KeyedFlags.java +++ b/src/main/java/redis/clients/jedis/resps/KeyedFlags.java @@ -12,7 +12,7 @@ public KeyedFlags(String name, List flags) { } public String getKey() { - return key; + return key; } public List getFlags() { From 9ea6e52347dca54c16a30284e298e394cb90e582 Mon Sep 17 00:00:00 2001 From: Avital-Fine <98389525+Avital-Fine@users.noreply.github.com> Date: Tue, 22 Feb 2022 21:27:47 +0100 Subject: [PATCH 04/23] Update CommandDocs.java --- src/main/java/redis/clients/jedis/resps/CommandDocs.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/resps/CommandDocs.java b/src/main/java/redis/clients/jedis/resps/CommandDocs.java index 3cb729ee7f..8f013394b4 100644 --- a/src/main/java/redis/clients/jedis/resps/CommandDocs.java +++ b/src/main/java/redis/clients/jedis/resps/CommandDocs.java @@ -20,7 +20,7 @@ public CommandDocs(String name, String summary, String since, String group, Stri } public String getName() { - return name; + return name; } public String getSummary() { From b31c554ed2f6600b54b8c1137a2d8783f5695c2e Mon Sep 17 00:00:00 2001 From: Avital-Fine Date: Tue, 22 Feb 2022 21:28:08 +0100 Subject: [PATCH 05/23] indentation --- .../jedis/commands/CommandCommands.java | 106 +++++++++--------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/src/main/java/redis/clients/jedis/commands/CommandCommands.java b/src/main/java/redis/clients/jedis/commands/CommandCommands.java index 3658738022..62eebfc171 100644 --- a/src/main/java/redis/clients/jedis/commands/CommandCommands.java +++ b/src/main/java/redis/clients/jedis/commands/CommandCommands.java @@ -8,66 +8,66 @@ public interface CommandCommands { - /** - * The number of total commands in this Redis server - * @return The number of total commands - */ - long commandCount(); + /** + * The number of total commands in this Redis server + * @return The number of total commands + */ + long commandCount(); - /** - * Return documentary information about commands. - * If not specifying commands, the reply includes all the server's commands. - * @param commands specify the names of one or more commands - * @return list of {@link CommandDocs} - */ + /** + * Return documentary information about commands. + * If not specifying commands, the reply includes all the server's commands. + * @param commands specify the names of one or more commands + * @return list of {@link CommandDocs} + */ - List commandDocs(String... commands); + List commandDocs(String... commands); - /** - * Return list of keys from a full Redis command - * @param command - * @return list of keys - */ - List commandGetKeys(String... command); + /** + * Return list of keys from a full Redis command + * @param command + * @return list of keys + */ + List commandGetKeys(String... command); - /** - * Return list of keys from a full Redis command and their usage flags - * @param command - * @return list of {@link KeyedFlags} - */ - List commandGetKeysSandFlags(String... command); + /** + * Return list of keys from a full Redis command and their usage flags + * @param command + * @return list of {@link KeyedFlags} + */ + List commandGetKeysSandFlags(String... command); - /** - * Return details about multiple Redis commands - * @param commands - * @return list of {@link CommandInfo} - */ - List commandInfo(String... commands); + /** + * Return details about multiple Redis commands + * @param commands + * @return list of {@link CommandInfo} + */ + List commandInfo(String... commands); - /** - * Return a list of the server's command names - * @return commands list - */ - List commandList(); + /** + * Return a list of the server's command names + * @return commands list + */ + List commandList(); - /** - * Return a list of the server's command names filter by module's name - * @param moduleName - * @return commands list - */ - List commandListFilterByModule(String moduleName); + /** + * Return a list of the server's command names filter by module's name + * @param moduleName + * @return commands list + */ + List commandListFilterByModule(String moduleName); - /** - * Return a list of the server's command names filter by ACL category - * @param category - * @return commands list - */ - List commandListFilterByAclcat(String category); + /** + * Return a list of the server's command names filter by ACL category + * @param category + * @return commands list + */ + List commandListFilterByAclcat(String category); - /** - * Return a list of the server's command names filter by glob-like pattern - * @param pattern - * @return commands list - */ - List commandListFilterByPattern(String pattern); + /** + * Return a list of the server's command names filter by glob-like pattern + * @param pattern + * @return commands list + */ + List commandListFilterByPattern(String pattern); } From 0e800a0131b903eb96312247c4add649dd49827d Mon Sep 17 00:00:00 2001 From: Avital-Fine Date: Thu, 24 Feb 2022 11:14:12 +0100 Subject: [PATCH 06/23] fix function name --- src/main/java/redis/clients/jedis/CommandObjects.java | 2 +- src/main/java/redis/clients/jedis/Jedis.java | 4 ++-- src/main/java/redis/clients/jedis/UnifiedJedis.java | 4 ++-- .../java/redis/clients/jedis/commands/CommandCommands.java | 2 +- .../jedis/commands/jedis/AllKindOfValuesCommandsTest.java | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index a5ca1e5a61..f63331cdb5 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -2823,7 +2823,7 @@ public final CommandObject> commandGetKeys(String... command) { return new CommandObject<>(commandArguments(COMMAND).add(GETKEYS).addObjects((Object[]) command), BuilderFactory.STRING_LIST); } - public final CommandObject> commandGetKeysSandFlags(String... command) { + public final CommandObject> commandGetKeysAndFlags(String... command) { return new CommandObject<>(commandArguments(COMMAND).add(GETKEYSANDFLAGS).addObjects((Object[]) command), BuilderFactory.KEYS_AND_FLAGS); } diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 66ad35eff2..11108ec68b 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -7959,9 +7959,9 @@ public List commandGetKeys(String... command) { } @Override - public List commandGetKeysSandFlags(String... command) { + public List commandGetKeysAndFlags(String... command) { checkIsInMultiOrPipeline(); - return connection.executeCommand(commandObjects.commandGetKeysSandFlags(command)); + return connection.executeCommand(commandObjects.commandGetKeysAndFlags(command)); } @Override diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index b3a2118f6d..b18f6b48a9 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -520,8 +520,8 @@ public List commandGetKeys(String... command) { } @Override - public List commandGetKeysSandFlags(String... command) { - return executeCommand(commandObjects.commandGetKeysSandFlags(command)); + public List commandGetKeysAndFlags(String... command) { + return executeCommand(commandObjects.commandGetKeysAndFlags(command)); } @Override diff --git a/src/main/java/redis/clients/jedis/commands/CommandCommands.java b/src/main/java/redis/clients/jedis/commands/CommandCommands.java index 62eebfc171..a777a57824 100644 --- a/src/main/java/redis/clients/jedis/commands/CommandCommands.java +++ b/src/main/java/redis/clients/jedis/commands/CommandCommands.java @@ -35,7 +35,7 @@ public interface CommandCommands { * @param command * @return list of {@link KeyedFlags} */ - List commandGetKeysSandFlags(String... command); + List commandGetKeysAndFlags(String... command); /** * Return details about multiple Redis commands diff --git a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java index 384870e8a7..85a7995929 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java @@ -1085,7 +1085,7 @@ public void commandGetKeys() { List keys = jedis.commandGetKeys("SORT", "mylist", "ALPHA", "STORE", "outlist"); assertEquals(2, keys.size()); - List keySandFlags = jedis.commandGetKeysSandFlags("SET", "k1", "v1"); + List keySandFlags = jedis.commandGetKeysAndFlags("SET", "k1", "v1"); assertEquals("k1", keySandFlags.get(0).getKey()); assertEquals(2, keySandFlags.get(0).getFlags().size()); } From b05cd5c7b197de14ceede4dc1189474203c2a741 Mon Sep 17 00:00:00 2001 From: Avital-Fine <98389525+Avital-Fine@users.noreply.github.com> Date: Sun, 6 Mar 2022 09:46:36 +0100 Subject: [PATCH 07/23] Update src/main/java/redis/clients/jedis/Protocol.java Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --- src/main/java/redis/clients/jedis/Protocol.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index 340545c5cc..16efc61c9a 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -236,8 +236,8 @@ public static enum Command implements ProtocolCommand { GEORADIUSBYMEMBER, GEORADIUSBYMEMBER_RO, BITFIELD, TOUCH, SWAPDB, MEMORY, BZPOPMIN, BZPOPMAX, XADD, XLEN, XDEL, XTRIM, XRANGE, XREVRANGE, XREAD, XACK, XGROUP, XREADGROUP, XPENDING, XCLAIM, XAUTOCLAIM, XINFO, BITFIELD_RO, ROLE, FAILOVER, GEOSEARCH, GEOSEARCHSTORE, EVAL_RO, EVALSHA_RO, - LOLWUT, EXPIRETIME, PEXPIRETIME, FUNCTION, FCALL, FCALL_RO, LMPOP, BLMPOP, ZMPOP, BZMPOP,COMMAND, - DOCS, GETKEYS, GETKEYSANDFLAGS, @Deprecated STRALGO; + LOLWUT, EXPIRETIME, PEXPIRETIME, FUNCTION, FCALL, FCALL_RO, LMPOP, BLMPOP, ZMPOP, BZMPOP, + COMMAND, DOCS, GETKEYS, GETKEYSANDFLAGS, @Deprecated STRALGO; private final byte[] raw; From 5fb4bf46740da974ce0614e6c5e0c595fa1199ac Mon Sep 17 00:00:00 2001 From: Avital-Fine <98389525+Avital-Fine@users.noreply.github.com> Date: Sun, 6 Mar 2022 09:46:51 +0100 Subject: [PATCH 08/23] Update src/main/java/redis/clients/jedis/Jedis.java Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --- src/main/java/redis/clients/jedis/Jedis.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 387562b8a8..000daa8bb1 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -8045,8 +8045,7 @@ public long bitop(final BitOP op, final String destKey, final String... srcKeys) @Override public long commandCount() { checkIsInMultiOrPipeline(); - connection.sendCommand(COMMAND, COUNT); - return connection.getIntegerReply(); + return connection.executeCommand(commandObjects.commandCount()); } @Override From 06eace6ed51c4b6b5d139ca16deb8ab0366a4db2 Mon Sep 17 00:00:00 2001 From: Avital-Fine Date: Sun, 6 Mar 2022 16:00:54 +0100 Subject: [PATCH 09/23] fix --- .../redis/clients/jedis/BuilderFactory.java | 37 ++++++------------- .../redis/clients/jedis/CommandObjects.java | 6 +-- src/main/java/redis/clients/jedis/Jedis.java | 4 +- .../redis/clients/jedis/UnifiedJedis.java | 4 +- .../jedis/commands/CommandCommands.java | 13 ++++--- ...{CommandDocs.java => CommandDocument.java} | 10 +---- .../redis/clients/jedis/resps/KeyedFlags.java | 21 ----------- .../jedis/AllKindOfValuesCommandsTest.java | 24 +++++------- 8 files changed, 37 insertions(+), 82 deletions(-) rename src/main/java/redis/clients/jedis/resps/{CommandDocs.java => CommandDocument.java} (72%) delete mode 100644 src/main/java/redis/clients/jedis/resps/KeyedFlags.java diff --git a/src/main/java/redis/clients/jedis/BuilderFactory.java b/src/main/java/redis/clients/jedis/BuilderFactory.java index b9884f5f9f..759f4b4ce3 100644 --- a/src/main/java/redis/clients/jedis/BuilderFactory.java +++ b/src/main/java/redis/clients/jedis/BuilderFactory.java @@ -426,6 +426,14 @@ public String toString() { } }; + public static final Builder>>> LIST_KEYED_STRING_LIST = new Builder>>>() { + @Override + public List>> build(Object data) { + List list = (List) data; + return list.stream().map(KEYED_STRING_LIST::build).collect(Collectors.toList()); + } + }; + public static final Builder>> KEYED_BINARY_LIST = new Builder>>() { @Override @@ -772,15 +780,15 @@ public String toString() { } }; - public static final Builder> COMMAND_DOCS_RESPONSE = new Builder>() { + public static final Builder> COMMAND_DOCS_RESPONSE = new Builder>() { @Override - public List build(Object data) { + public Map build(Object data) { if (data == null) { return null; } List rawList = (List) data; - List list = new ArrayList<>(rawList.size()); + Map list = new HashMap<>(rawList.size()); for (int i = 0; i < rawList.size();) { String name = STRING.build(rawList.get(i++)); @@ -798,28 +806,7 @@ public List build(Object data) { } } - list.add(new CommandDocs(name, summary, since, group, complexity, history)); - } - - return list; - } - }; - - public static final Builder> KEYS_AND_FLAGS = new Builder>() { - @Override - public List build(Object data) { - if (data == null) { - return null; - } - - List rawList = (List) data; - List list = new ArrayList<>(rawList.size()); - - for (Object rawKeyInfo : rawList) { - List keyInfo = (List) rawKeyInfo; - String name = STRING.build(keyInfo.get(0)); - List flags = STRING_LIST.build(keyInfo.get(1)); - list.add(new KeyedFlags(name, flags)); + list.put(name, new CommandDocument(summary, since, group, complexity, history)); } return list; diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index 5f1b1b9d4f..c0aa612336 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -3036,7 +3036,7 @@ public final CommandObject commandCount() { return new CommandObject<>(commandArguments(COMMAND).add(COUNT), BuilderFactory.LONG); } - public final CommandObject> commandDocs(String... commands) { + public final CommandObject> commandDocs(String... commands) { return new CommandObject<>(commandArguments(COMMAND).add(DOCS).addObjects((Object[]) commands), BuilderFactory.COMMAND_DOCS_RESPONSE); } @@ -3044,8 +3044,8 @@ public final CommandObject> commandGetKeys(String... command) { return new CommandObject<>(commandArguments(COMMAND).add(GETKEYS).addObjects((Object[]) command), BuilderFactory.STRING_LIST); } - public final CommandObject> commandGetKeysAndFlags(String... command) { - return new CommandObject<>(commandArguments(COMMAND).add(GETKEYSANDFLAGS).addObjects((Object[]) command), BuilderFactory.KEYS_AND_FLAGS); + public final CommandObject>>> commandGetKeysAndFlags(String... command) { + return new CommandObject<>(commandArguments(COMMAND).add(GETKEYSANDFLAGS).addObjects((Object[]) command), BuilderFactory.LIST_KEYED_STRING_LIST); } public final CommandObject> commandInfo(String... commands) { diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 000daa8bb1..18bb65516f 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -8049,7 +8049,7 @@ public long commandCount() { } @Override - public List commandDocs(String... commands) { + public Map commandDocs(String... commands) { checkIsInMultiOrPipeline(); return connection.executeCommand(commandObjects.commandDocs(commands)); } @@ -8061,7 +8061,7 @@ public List commandGetKeys(String... command) { } @Override - public List commandGetKeysAndFlags(String... command) { + public List>> commandGetKeysAndFlags(String... command) { checkIsInMultiOrPipeline(); return connection.executeCommand(commandObjects.commandGetKeysAndFlags(command)); } diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index ef65b507b2..5c44318ab9 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -511,7 +511,7 @@ public long commandCount() { } @Override - public List commandDocs(String... commands) { + public Map commandDocs(String... commands) { return executeCommand(commandObjects.commandDocs(commands)); } @@ -521,7 +521,7 @@ public List commandGetKeys(String... command) { } @Override - public List commandGetKeysAndFlags(String... command) { + public List>> commandGetKeysAndFlags(String... command) { return executeCommand(commandObjects.commandGetKeysAndFlags(command)); } diff --git a/src/main/java/redis/clients/jedis/commands/CommandCommands.java b/src/main/java/redis/clients/jedis/commands/CommandCommands.java index a777a57824..ab43b7764e 100644 --- a/src/main/java/redis/clients/jedis/commands/CommandCommands.java +++ b/src/main/java/redis/clients/jedis/commands/CommandCommands.java @@ -1,10 +1,11 @@ package redis.clients.jedis.commands; -import redis.clients.jedis.resps.CommandDocs; +import redis.clients.jedis.resps.CommandDocument; import redis.clients.jedis.resps.CommandInfo; -import redis.clients.jedis.resps.KeyedFlags; +import redis.clients.jedis.util.KeyValue; import java.util.List; +import java.util.Map; public interface CommandCommands { @@ -18,10 +19,10 @@ public interface CommandCommands { * Return documentary information about commands. * If not specifying commands, the reply includes all the server's commands. * @param commands specify the names of one or more commands - * @return list of {@link CommandDocs} + * @return list of {@link CommandDocument} */ - List commandDocs(String... commands); + Map commandDocs(String... commands); /** * Return list of keys from a full Redis command @@ -33,9 +34,9 @@ public interface CommandCommands { /** * Return list of keys from a full Redis command and their usage flags * @param command - * @return list of {@link KeyedFlags} + * @return list of {@link KeyValue} */ - List commandGetKeysAndFlags(String... command); + List>> commandGetKeysAndFlags(String... command); /** * Return details about multiple Redis commands diff --git a/src/main/java/redis/clients/jedis/resps/CommandDocs.java b/src/main/java/redis/clients/jedis/resps/CommandDocument.java similarity index 72% rename from src/main/java/redis/clients/jedis/resps/CommandDocs.java rename to src/main/java/redis/clients/jedis/resps/CommandDocument.java index 8f013394b4..b70c8080ab 100644 --- a/src/main/java/redis/clients/jedis/resps/CommandDocs.java +++ b/src/main/java/redis/clients/jedis/resps/CommandDocument.java @@ -2,16 +2,14 @@ import java.util.List; -public class CommandDocs { - private final String name; +public class CommandDocument { private final String summary; private final String since; private final String group; private final String complexity; private final List history; - public CommandDocs(String name, String summary, String since, String group, String complexity, List history) { - this.name = name; + public CommandDocument(String summary, String since, String group, String complexity, List history) { this.summary = summary; this.since = since; this.group = group; @@ -19,10 +17,6 @@ public CommandDocs(String name, String summary, String since, String group, Stri this.history = history; } - public String getName() { - return name; - } - public String getSummary() { return summary; } diff --git a/src/main/java/redis/clients/jedis/resps/KeyedFlags.java b/src/main/java/redis/clients/jedis/resps/KeyedFlags.java deleted file mode 100644 index fe7c713a2d..0000000000 --- a/src/main/java/redis/clients/jedis/resps/KeyedFlags.java +++ /dev/null @@ -1,21 +0,0 @@ -package redis.clients.jedis.resps; - -import java.util.List; - -public class KeyedFlags { - private final String key; - private final List flags; - - public KeyedFlags(String name, List flags) { - this.key = name; - this.flags = flags; - } - - public String getKey() { - return key; - } - - public List getFlags() { - return flags; - } -} diff --git a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java index 452df54153..636ee03c78 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java @@ -22,13 +22,8 @@ import static redis.clients.jedis.util.AssertUtil.assertByteArrayListEquals; import static redis.clients.jedis.util.AssertUtil.assertCollectionContains; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; + import org.junit.Test; import redis.clients.jedis.HostAndPort; @@ -36,14 +31,14 @@ import redis.clients.jedis.args.ExpiryOption; import redis.clients.jedis.params.LolwutParams; import redis.clients.jedis.params.ScanParams; -import redis.clients.jedis.resps.CommandDocs; +import redis.clients.jedis.resps.CommandDocument; import redis.clients.jedis.resps.CommandInfo; -import redis.clients.jedis.resps.KeyedFlags; import redis.clients.jedis.resps.ScanResult; import redis.clients.jedis.StreamEntryID; import redis.clients.jedis.args.FlushMode; import redis.clients.jedis.params.RestoreParams; import redis.clients.jedis.HostAndPorts; +import redis.clients.jedis.util.KeyValue; import redis.clients.jedis.util.SafeEncoder; import redis.clients.jedis.exceptions.JedisDataException; @@ -1078,15 +1073,14 @@ public void commandCount() { @Test public void commandDocs() { - List docs = jedis.commandDocs("SORT", "SET"); + Map docs = jedis.commandDocs("SORT", "SET"); - CommandDocs sortDoc = docs.get(0); - assertEquals("sort", sortDoc.getName()); + CommandDocument sortDoc = docs.get("sort"); assertEquals("generic", sortDoc.getGroup()); assertEquals("Sort the elements in a list, set or sorted set", sortDoc.getSummary()); assertNull(sortDoc.getHistory()); - CommandDocs setDoc = docs.get(1); + CommandDocument setDoc = docs.get("set"); assertEquals("1.0.0", setDoc.getSince()); assertEquals("O(1)", setDoc.getComplexity()); assertEquals("2.6.12: Added the `EX`, `PX`, `NX` and `XX` options.", setDoc.getHistory().get(0)); @@ -1097,9 +1091,9 @@ public void commandGetKeys() { List keys = jedis.commandGetKeys("SORT", "mylist", "ALPHA", "STORE", "outlist"); assertEquals(2, keys.size()); - List keySandFlags = jedis.commandGetKeysAndFlags("SET", "k1", "v1"); + List>> keySandFlags = jedis.commandGetKeysAndFlags("SET", "k1", "v1"); assertEquals("k1", keySandFlags.get(0).getKey()); - assertEquals(2, keySandFlags.get(0).getFlags().size()); + assertEquals(2, keySandFlags.get(0).getValue().size()); } @Test From 62d7f7158515b6ff5ad2a29a86b6a6d805714e8e Mon Sep 17 00:00:00 2001 From: Avital-Fine Date: Sun, 6 Mar 2022 16:39:28 +0100 Subject: [PATCH 10/23] add CommandListFilterByParams --- .../redis/clients/jedis/BuilderFactory.java | 17 +++---- .../redis/clients/jedis/CommandObjects.java | 16 ++---- src/main/java/redis/clients/jedis/Jedis.java | 26 +++------- .../java/redis/clients/jedis/Protocol.java | 2 +- .../redis/clients/jedis/UnifiedJedis.java | 16 ++---- .../jedis/commands/CommandCommands.java | 23 ++------- .../params/CommandListFilterByParams.java | 49 +++++++++++++++++++ .../clients/jedis/resps/CommandInfo.java | 11 +---- .../jedis/AllKindOfValuesCommandsTest.java | 16 +++--- 9 files changed, 85 insertions(+), 91 deletions(-) create mode 100644 src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java diff --git a/src/main/java/redis/clients/jedis/BuilderFactory.java b/src/main/java/redis/clients/jedis/BuilderFactory.java index 759f4b4ce3..2965804553 100644 --- a/src/main/java/redis/clients/jedis/BuilderFactory.java +++ b/src/main/java/redis/clients/jedis/BuilderFactory.java @@ -788,7 +788,7 @@ public Map build(Object data) { } List rawList = (List) data; - Map list = new HashMap<>(rawList.size()); + Map map = new HashMap<>(rawList.size()); for (int i = 0; i < rawList.size();) { String name = STRING.build(rawList.get(i++)); @@ -806,26 +806,25 @@ public Map build(Object data) { } } - list.put(name, new CommandDocument(summary, since, group, complexity, history)); + map.put(name, new CommandDocument(summary, since, group, complexity, history)); } - return list; + return map; } }; - public static final Builder> COMMAND_INFO_RESPONSE = new Builder>() { + public static final Builder> COMMAND_INFO_RESPONSE = new Builder>() { @Override - public List build(Object data) { + public Map build(Object data) { if (data == null) { return null; } List rawList = (List) data; - List list = new ArrayList<>(rawList.size()); + Map map = new HashMap<>(rawList.size()); for (Object rawCommandInfo : rawList) { if (rawCommandInfo == null) { - list.add(null); break; } @@ -840,10 +839,10 @@ public List build(Object data) { List tips = STRING_LIST.build(commandInfo.get(7)); List subcommands = STRING_LIST.build(commandInfo.get(9)); - list.add(new CommandInfo(name, arity, flags, firstKey, lastKey, step, aclCategories, tips, subcommands)); + map.put(name, new CommandInfo(arity, flags, firstKey, lastKey, step, aclCategories, tips, subcommands)); } - return list; + return map; } }; diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index c0aa612336..edcd06bab8 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -3048,7 +3048,7 @@ public final CommandObject>>> commandGetKeysA return new CommandObject<>(commandArguments(COMMAND).add(GETKEYSANDFLAGS).addObjects((Object[]) command), BuilderFactory.LIST_KEYED_STRING_LIST); } - public final CommandObject> commandInfo(String... commands) { + public final CommandObject> commandInfo(String... commands) { return new CommandObject<>(commandArguments(COMMAND).add(Keyword.INFO).addObjects((Object[]) commands), BuilderFactory.COMMAND_INFO_RESPONSE); } @@ -3056,18 +3056,8 @@ public final CommandObject> commandList() { return new CommandObject<>(commandArguments(COMMAND).add(LIST), BuilderFactory.STRING_LIST); } - public final CommandObject> commandListFilterByModule(String moduleName) { - return new CommandObject<>(commandArguments(COMMAND).add(LIST).add(FILTERBY).add(MODULE).add(moduleName), - BuilderFactory.STRING_LIST); - } - - public final CommandObject> commandListFilterByAclcat(String moduleName) { - return new CommandObject<>(commandArguments(COMMAND).add(LIST).add(FILTERBY).add(ACLCAT).add(moduleName), - BuilderFactory.STRING_LIST); - } - - public final CommandObject> commandListFilterByPattern(String pattern) { - return new CommandObject<>(commandArguments(COMMAND).add(LIST).add(FILTERBY).add(PATTERN).add(pattern), + public final CommandObject> commandListFilterBy(CommandListFilterByParams filterByParams) { + return new CommandObject<>(commandArguments(COMMAND).add(LIST).addParams(filterByParams), BuilderFactory.STRING_LIST); } diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 18bb65516f..8b6f01ce54 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -8067,7 +8067,7 @@ public List>> commandGetKeysAndFlags(String... com } @Override - public List commandInfo(String... commands) { + public Map commandInfo(String... commands) { checkIsInMultiOrPipeline(); return connection.executeCommand(commandObjects.commandInfo(commands)); } @@ -8079,21 +8079,9 @@ public List commandList() { } @Override - public List commandListFilterByModule(String moduleName) { + public List commandListFilterBy(CommandListFilterByParams filterByParams) { checkIsInMultiOrPipeline(); - return connection.executeCommand(commandObjects.commandListFilterByModule(moduleName)); - } - - @Override - public List commandListFilterByAclcat(String category) { - checkIsInMultiOrPipeline(); - return connection.executeCommand(commandObjects.commandListFilterByAclcat(category)); - } - - @Override - public List commandListFilterByPattern(String pattern) { - checkIsInMultiOrPipeline(); - return connection.executeCommand(commandObjects.commandListFilterByPattern(pattern)); + return connection.executeCommand(commandObjects.commandListFilterBy(filterByParams)); } @Override @@ -9047,28 +9035,28 @@ public long geosearchStoreStoreDist(String dest, String src, GeoSearchParam para @Override public String moduleLoad(final String path) { checkIsInMultiOrPipeline(); - connection.sendCommand(MODULE, LOAD.name(), path); + connection.sendCommand(Command.MODULE, LOAD.name(), path); return connection.getStatusCodeReply(); } @Override public String moduleLoad(String path, String... args) { checkIsInMultiOrPipeline(); - connection.sendCommand(MODULE, joinParameters(LOAD.name(), path, args)); + connection.sendCommand(Command.MODULE, joinParameters(LOAD.name(), path, args)); return connection.getStatusCodeReply(); } @Override public String moduleUnload(final String name) { checkIsInMultiOrPipeline(); - connection.sendCommand(MODULE, UNLOAD.name(), name); + connection.sendCommand(Command.MODULE, UNLOAD.name(), name); return connection.getStatusCodeReply(); } @Override public List moduleList() { checkIsInMultiOrPipeline(); - connection.sendCommand(MODULE, LIST); + connection.sendCommand(Command.MODULE, LIST); return BuilderFactory.MODULE_LIST.build(connection.getObjectMultiBulkReply()); } diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index 16efc61c9a..970bd77870 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -262,7 +262,7 @@ public static enum Keyword implements Rawable { TIMEOUT, ABORT, NX, XX, EX, PX, EXAT, PXAT, CH, WITHCOORD, WITHDIST, WITHHASH, STOREDIST, COPY, KEEPTTL, AUTH, AUTH2, INFO, CHANNELS, NUMPAT, NUMSUB, FULL, NOW, VERSION, KEYS, IDX, SCHEDULE, ANY, FROMMEMBER, FROMLONLAT, BYRADIUS, BYBOX, BYLEX, BYSCORE, REV, MINMATCHLEN, WITHMATCHLEN, - PURGE, STATS, CREATECONSUMER, DELETE, LIBRARYNAME, WITHCODE, DESCRIPTION, FILTERBY, ACLCAT, + PURGE, STATS, CREATECONSUMER, DELETE, LIBRARYNAME, WITHCODE, DESCRIPTION, FILTERBY, MODULE, ACLCAT, PATTERN, @Deprecated LCS, @Deprecated STRINGS; private final byte[] raw; diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index 5c44318ab9..26e9343ac3 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -526,7 +526,7 @@ public List>> commandGetKeysAndFlags(String... com } @Override - public List commandInfo(String... commands) { + public Map commandInfo(String... commands) { return executeCommand(commandObjects.commandInfo(commands)); } @@ -536,18 +536,8 @@ public List commandList() { } @Override - public List commandListFilterByModule(String moduleName) { - return executeCommand(commandObjects.commandListFilterByModule(moduleName)); - } - - @Override - public List commandListFilterByAclcat(String category) { - return executeCommand(commandObjects.commandListFilterByAclcat(category)); - } - - @Override - public List commandListFilterByPattern(String pattern) { - return executeCommand(commandObjects.commandListFilterByPattern(pattern)); + public List commandListFilterBy(CommandListFilterByParams filterByParams) { + return executeCommand(commandObjects.commandListFilterBy(filterByParams)); } @Override diff --git a/src/main/java/redis/clients/jedis/commands/CommandCommands.java b/src/main/java/redis/clients/jedis/commands/CommandCommands.java index ab43b7764e..8b09eff80d 100644 --- a/src/main/java/redis/clients/jedis/commands/CommandCommands.java +++ b/src/main/java/redis/clients/jedis/commands/CommandCommands.java @@ -1,5 +1,6 @@ package redis.clients.jedis.commands; +import redis.clients.jedis.params.CommandListFilterByParams; import redis.clients.jedis.resps.CommandDocument; import redis.clients.jedis.resps.CommandInfo; import redis.clients.jedis.util.KeyValue; @@ -43,7 +44,7 @@ public interface CommandCommands { * @param commands * @return list of {@link CommandInfo} */ - List commandInfo(String... commands); + Map commandInfo(String... commands); /** * Return a list of the server's command names @@ -52,23 +53,9 @@ public interface CommandCommands { List commandList(); /** - * Return a list of the server's command names filter by module's name - * @param moduleName + * Return a list of the server's command names filtered by module's name, ACL category or pattern + * @param filterByParams {@link CommandListFilterByParams} * @return commands list */ - List commandListFilterByModule(String moduleName); - - /** - * Return a list of the server's command names filter by ACL category - * @param category - * @return commands list - */ - List commandListFilterByAclcat(String category); - - /** - * Return a list of the server's command names filter by glob-like pattern - * @param pattern - * @return commands list - */ - List commandListFilterByPattern(String pattern); + List commandListFilterBy(CommandListFilterByParams filterByParams); } diff --git a/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java b/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java new file mode 100644 index 0000000000..a29b4925ad --- /dev/null +++ b/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java @@ -0,0 +1,49 @@ +package redis.clients.jedis.params; + +import redis.clients.jedis.CommandArguments; + +import static redis.clients.jedis.Protocol.Keyword.FILTERBY; +import static redis.clients.jedis.Protocol.Keyword.MODULE; +import static redis.clients.jedis.Protocol.Keyword.ACLCAT; +import static redis.clients.jedis.Protocol.Keyword.PATTERN; + +public class CommandListFilterByParams implements IParams{ + private String moduleName; + private String category; + private String pattern; + + public static CommandListFilterByParams commandListFilterByParams() { + return new CommandListFilterByParams(); + } + + public CommandListFilterByParams filterByModule(String moduleName) { + this.moduleName = moduleName; + return this; + } + + public CommandListFilterByParams filterByAclcat(String category) { + this.category = category; + return this; + } + + public CommandListFilterByParams filterByPattern(String pattern) { + this.pattern = pattern; + return this; + } + + @Override + public void addParams(CommandArguments args) { + args.add(FILTERBY); + + if (moduleName != null) { + args.add(MODULE); + args.add(moduleName); + } else if (category != null) { + args.add(ACLCAT); + args.add(category); + } else if (pattern != null) { + args.add(PATTERN); + args.add(pattern); + } + } +} diff --git a/src/main/java/redis/clients/jedis/resps/CommandInfo.java b/src/main/java/redis/clients/jedis/resps/CommandInfo.java index ef2ccd81f7..2e447c922c 100644 --- a/src/main/java/redis/clients/jedis/resps/CommandInfo.java +++ b/src/main/java/redis/clients/jedis/resps/CommandInfo.java @@ -3,7 +3,6 @@ import java.util.List; public class CommandInfo { - private final String name; private final long arity; private final List flags; private final long firstKey; @@ -13,9 +12,8 @@ public class CommandInfo { private final List tips; private final List subcommands; - public CommandInfo(String name, long arity, List flags, long firstKey, long lastKey, long step, + public CommandInfo(long arity, List flags, long firstKey, long lastKey, long step, List aclCategories, List tips, List subcommands) { - this.name = name; this.arity = arity; this.flags = flags; this.firstKey = firstKey; @@ -26,13 +24,6 @@ public CommandInfo(String name, long arity, List flags, long firstKey, l this.subcommands = subcommands; } - /** - * Command's name in lowercase - */ - public String getName() { - return name; - } - /** * Arity is the number of arguments a command expects. It follows a simple pattern: * A positive integer means a fixed number of arguments. diff --git a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java index 636ee03c78..a9f2f8f799 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java @@ -29,6 +29,7 @@ import redis.clients.jedis.HostAndPort; import redis.clients.jedis.Jedis; import redis.clients.jedis.args.ExpiryOption; +import redis.clients.jedis.params.CommandListFilterByParams; import redis.clients.jedis.params.LolwutParams; import redis.clients.jedis.params.ScanParams; import redis.clients.jedis.resps.CommandDocument; @@ -1098,22 +1099,21 @@ public void commandGetKeys() { @Test public void commandInfo() { - List infos = jedis.commandInfo("GET", "SET", "foo"); + Map infos = jedis.commandInfo("GET", "SET", "foo"); - CommandInfo getInfo = infos.get(0); + CommandInfo getInfo = infos.get("get"); assertEquals(2, getInfo.getArity()); assertEquals(2, getInfo.getFlags().size()); assertEquals(1, getInfo.getFirstKey()); assertEquals(1, getInfo.getLastKey()); assertEquals(1, getInfo.getStep()); - CommandInfo setInfo = infos.get(1); - assertEquals("set", setInfo.getName()); + CommandInfo setInfo = infos.get("set"); assertEquals(3, setInfo.getAclCategories().size()); assertEquals(0, setInfo.getTips().size()); assertEquals(0, setInfo.getSubcommands().size()); - assertNull(infos.get(2)); // non-existing command + assertNull(infos.get("foo")); // non-existing command } @Test @@ -1121,13 +1121,13 @@ public void commandList() { List commands = jedis.commandList(); assertTrue(commands.size() > 100); - commands = jedis.commandListFilterByModule("JSON"); + commands = jedis.commandListFilterBy(CommandListFilterByParams.commandListFilterByParams().filterByModule("JSON")); assertEquals(0, commands.size()); // json module was not loaded - commands = jedis.commandListFilterByAclcat("admin"); + commands = jedis.commandListFilterBy(CommandListFilterByParams.commandListFilterByParams().filterByAclcat("admin")); assertTrue(commands.size() > 10); - commands = jedis.commandListFilterByPattern("a*"); + commands = jedis.commandListFilterBy(CommandListFilterByParams.commandListFilterByParams().filterByPattern("a*")); assertTrue(commands.size() > 10); } From d790655b9f027808592e46303ff7711fb9ff9194 Mon Sep 17 00:00:00 2001 From: Avital-Fine <98389525+Avital-Fine@users.noreply.github.com> Date: Sun, 6 Mar 2022 17:31:46 +0100 Subject: [PATCH 11/23] Update src/main/java/redis/clients/jedis/BuilderFactory.java Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --- src/main/java/redis/clients/jedis/BuilderFactory.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/BuilderFactory.java b/src/main/java/redis/clients/jedis/BuilderFactory.java index 2965804553..f6a794673a 100644 --- a/src/main/java/redis/clients/jedis/BuilderFactory.java +++ b/src/main/java/redis/clients/jedis/BuilderFactory.java @@ -426,7 +426,8 @@ public String toString() { } }; - public static final Builder>>> LIST_KEYED_STRING_LIST = new Builder>>>() { + public static final Builder>>> LIST_KEYED_STRING_LIST + = new Builder>>>() { @Override public List>> build(Object data) { List list = (List) data; From d44b4f7817d55b46e1ea38943609adaef4c92eda Mon Sep 17 00:00:00 2001 From: Avital-Fine Date: Sun, 6 Mar 2022 17:39:02 +0100 Subject: [PATCH 12/23] resolve conflicts --- src/main/java/redis/clients/jedis/BuilderFactory.java | 2 +- src/main/java/redis/clients/jedis/CommandObjects.java | 2 +- src/main/java/redis/clients/jedis/Protocol.java | 6 +++--- .../clients/jedis/params/CommandListFilterByParams.java | 2 +- .../jedis/commands/jedis/AllKindOfValuesCommandsTest.java | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BuilderFactory.java b/src/main/java/redis/clients/jedis/BuilderFactory.java index f6a794673a..c087d5f9ee 100644 --- a/src/main/java/redis/clients/jedis/BuilderFactory.java +++ b/src/main/java/redis/clients/jedis/BuilderFactory.java @@ -426,7 +426,7 @@ public String toString() { } }; - public static final Builder>>> LIST_KEYED_STRING_LIST + public static final Builder>>> KEYED_STRING_LIST_LIST = new Builder>>>() { @Override public List>> build(Object data) { diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index edcd06bab8..ddc0771e5d 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -3045,7 +3045,7 @@ public final CommandObject> commandGetKeys(String... command) { } public final CommandObject>>> commandGetKeysAndFlags(String... command) { - return new CommandObject<>(commandArguments(COMMAND).add(GETKEYSANDFLAGS).addObjects((Object[]) command), BuilderFactory.LIST_KEYED_STRING_LIST); + return new CommandObject<>(commandArguments(COMMAND).add(GETKEYSANDFLAGS).addObjects((Object[]) command), BuilderFactory.KEYED_STRING_LIST_LIST); } public final CommandObject> commandInfo(String... commands) { diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index 970bd77870..c924395f00 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -237,7 +237,7 @@ public static enum Command implements ProtocolCommand { XADD, XLEN, XDEL, XTRIM, XRANGE, XREVRANGE, XREAD, XACK, XGROUP, XREADGROUP, XPENDING, XCLAIM, XAUTOCLAIM, XINFO, BITFIELD_RO, ROLE, FAILOVER, GEOSEARCH, GEOSEARCHSTORE, EVAL_RO, EVALSHA_RO, LOLWUT, EXPIRETIME, PEXPIRETIME, FUNCTION, FCALL, FCALL_RO, LMPOP, BLMPOP, ZMPOP, BZMPOP, - COMMAND, DOCS, GETKEYS, GETKEYSANDFLAGS, @Deprecated STRALGO; + COMMAND, @Deprecated STRALGO; private final byte[] raw; @@ -262,8 +262,8 @@ public static enum Keyword implements Rawable { TIMEOUT, ABORT, NX, XX, EX, PX, EXAT, PXAT, CH, WITHCOORD, WITHDIST, WITHHASH, STOREDIST, COPY, KEEPTTL, AUTH, AUTH2, INFO, CHANNELS, NUMPAT, NUMSUB, FULL, NOW, VERSION, KEYS, IDX, SCHEDULE, ANY, FROMMEMBER, FROMLONLAT, BYRADIUS, BYBOX, BYLEX, BYSCORE, REV, MINMATCHLEN, WITHMATCHLEN, - PURGE, STATS, CREATECONSUMER, DELETE, LIBRARYNAME, WITHCODE, DESCRIPTION, FILTERBY, MODULE, ACLCAT, - PATTERN, @Deprecated LCS, @Deprecated STRINGS; + PURGE, STATS, CREATECONSUMER, DELETE, LIBRARYNAME, WITHCODE, DESCRIPTION, GETKEYS, GETKEYSANDFLAGS, + DOCS, FILTERBY, MODULE, ACLCAT, PATTERN, @Deprecated LCS, @Deprecated STRINGS; private final byte[] raw; diff --git a/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java b/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java index a29b4925ad..f18ae48ede 100644 --- a/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java +++ b/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java @@ -21,7 +21,7 @@ public CommandListFilterByParams filterByModule(String moduleName) { return this; } - public CommandListFilterByParams filterByAclcat(String category) { + public CommandListFilterByParams filterByAclCat(String category) { this.category = category; return this; } diff --git a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java index a9f2f8f799..6423c258a4 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java @@ -1124,7 +1124,7 @@ public void commandList() { commands = jedis.commandListFilterBy(CommandListFilterByParams.commandListFilterByParams().filterByModule("JSON")); assertEquals(0, commands.size()); // json module was not loaded - commands = jedis.commandListFilterBy(CommandListFilterByParams.commandListFilterByParams().filterByAclcat("admin")); + commands = jedis.commandListFilterBy(CommandListFilterByParams.commandListFilterByParams().filterByAclCat("admin")); assertTrue(commands.size() > 10); commands = jedis.commandListFilterBy(CommandListFilterByParams.commandListFilterByParams().filterByPattern("a*")); From 11ba5fe86b30f74e8116ddacb9edba93dc89e8e8 Mon Sep 17 00:00:00 2001 From: Avital-Fine Date: Sun, 6 Mar 2022 17:47:52 +0100 Subject: [PATCH 13/23] fix bug --- src/main/java/redis/clients/jedis/BuilderFactory.java | 2 +- .../jedis/commands/jedis/AllKindOfValuesCommandsTest.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BuilderFactory.java b/src/main/java/redis/clients/jedis/BuilderFactory.java index c087d5f9ee..0ab34ec7bb 100644 --- a/src/main/java/redis/clients/jedis/BuilderFactory.java +++ b/src/main/java/redis/clients/jedis/BuilderFactory.java @@ -826,7 +826,7 @@ public Map build(Object data) { for (Object rawCommandInfo : rawList) { if (rawCommandInfo == null) { - break; + continue; } List commandInfo = (List) rawCommandInfo; diff --git a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java index 6423c258a4..50ca293718 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java @@ -1099,7 +1099,7 @@ public void commandGetKeys() { @Test public void commandInfo() { - Map infos = jedis.commandInfo("GET", "SET", "foo"); + Map infos = jedis.commandInfo("GET", "foo", "SET"); CommandInfo getInfo = infos.get("get"); assertEquals(2, getInfo.getArity()); @@ -1108,12 +1108,12 @@ public void commandInfo() { assertEquals(1, getInfo.getLastKey()); assertEquals(1, getInfo.getStep()); + assertNull(infos.get("foo")); // non-existing command + CommandInfo setInfo = infos.get("set"); assertEquals(3, setInfo.getAclCategories().size()); assertEquals(0, setInfo.getTips().size()); assertEquals(0, setInfo.getSubcommands().size()); - - assertNull(infos.get("foo")); // non-existing command } @Test From 19403d6104b7d0998f588f2d1c6938919470ed23 Mon Sep 17 00:00:00 2001 From: Avital-Fine <98389525+Avital-Fine@users.noreply.github.com> Date: Tue, 8 Mar 2022 00:18:57 +0100 Subject: [PATCH 14/23] Update src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --- .../redis/clients/jedis/params/CommandListFilterByParams.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java b/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java index f18ae48ede..ca012e5412 100644 --- a/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java +++ b/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java @@ -7,7 +7,7 @@ import static redis.clients.jedis.Protocol.Keyword.ACLCAT; import static redis.clients.jedis.Protocol.Keyword.PATTERN; -public class CommandListFilterByParams implements IParams{ +public class CommandListFilterByParams implements IParams { private String moduleName; private String category; private String pattern; From 4d10d8d83945a0d68409efc1501884ed00ee950a Mon Sep 17 00:00:00 2001 From: Avital-Fine Date: Tue, 8 Mar 2022 10:11:55 +0100 Subject: [PATCH 15/23] clean builders --- .../redis/clients/jedis/BuilderFactory.java | 37 ++++--------------- .../params/CommandListFilterByParams.java | 6 +-- .../clients/jedis/resps/CommandDocument.java | 25 +++++++++++++ .../clients/jedis/resps/CommandInfo.java | 23 ++++++++++++ 4 files changed, 59 insertions(+), 32 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BuilderFactory.java b/src/main/java/redis/clients/jedis/BuilderFactory.java index 0ab34ec7bb..45581b21ee 100644 --- a/src/main/java/redis/clients/jedis/BuilderFactory.java +++ b/src/main/java/redis/clients/jedis/BuilderFactory.java @@ -788,26 +788,13 @@ public Map build(Object data) { return null; } - List rawList = (List) data; - Map map = new HashMap<>(rawList.size()); - - for (int i = 0; i < rawList.size();) { - String name = STRING.build(rawList.get(i++)); - List commandData = (List) rawList.get(i++); - String summary = STRING.build(commandData.get(1)); - String since = STRING.build(commandData.get(3)); - String group = STRING.build(commandData.get(5)); - String complexity = STRING.build(commandData.get(7)); - List history = null; - if (STRING.build(commandData.get(8)).equals("history")) { - List> rawHistory = (List>) commandData.get(9); - history = new ArrayList<>(rawHistory.size()); - for (List timePoint : rawHistory) { - history.add(STRING.build(timePoint.get(0)) + ": " + STRING.build(timePoint.get(1))); - } - } + List list = (List) data; + Map map = new HashMap<>(list.size()); - map.put(name, new CommandDocument(summary, since, group, complexity, history)); + for (int i = 0; i < list.size();) { + String name = STRING.build(list.get(i++)); + CommandDocument doc = CommandDocument.COMMAND_DOCUMENT_BUILDER.build(list.get(i++)); + map.put(name, doc); } return map; @@ -831,16 +818,8 @@ public Map build(Object data) { List commandInfo = (List) rawCommandInfo; String name = STRING.build(commandInfo.get(0)); - long arity = LONG.build(commandInfo.get(1)); - List flags = STRING_LIST.build(commandInfo.get(2)); - long firstKey = LONG.build(commandInfo.get(3)); - long lastKey = LONG.build(commandInfo.get(4)); - long step = LONG.build(commandInfo.get(5)); - List aclCategories = STRING_LIST.build(commandInfo.get(6)); - List tips = STRING_LIST.build(commandInfo.get(7)); - List subcommands = STRING_LIST.build(commandInfo.get(9)); - - map.put(name, new CommandInfo(arity, flags, firstKey, lastKey, step, aclCategories, tips, subcommands)); + CommandInfo info = CommandInfo.COMMAND_INFO_BUILDER.build(commandInfo); + map.put(name, info); } return map; diff --git a/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java b/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java index ca012e5412..63a55bbbe0 100644 --- a/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java +++ b/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java @@ -35,13 +35,13 @@ public CommandListFilterByParams filterByPattern(String pattern) { public void addParams(CommandArguments args) { args.add(FILTERBY); - if (moduleName != null) { + if (moduleName != null && category == null && pattern == null) { args.add(MODULE); args.add(moduleName); - } else if (category != null) { + } else if (moduleName == null && category != null && pattern == null) { args.add(ACLCAT); args.add(category); - } else if (pattern != null) { + } else if (moduleName == null && category == null && pattern != null) { args.add(PATTERN); args.add(pattern); } diff --git a/src/main/java/redis/clients/jedis/resps/CommandDocument.java b/src/main/java/redis/clients/jedis/resps/CommandDocument.java index b70c8080ab..219397811e 100644 --- a/src/main/java/redis/clients/jedis/resps/CommandDocument.java +++ b/src/main/java/redis/clients/jedis/resps/CommandDocument.java @@ -1,5 +1,10 @@ package redis.clients.jedis.resps; +import redis.clients.jedis.Builder; + +import static redis.clients.jedis.BuilderFactory.STRING; + +import java.util.ArrayList; import java.util.List; public class CommandDocument { @@ -36,4 +41,24 @@ public String getComplexity() { public List getHistory() { return history; } + + public static final Builder COMMAND_DOCUMENT_BUILDER = new Builder() { + @Override + public CommandDocument build(Object data) { + List commandData = (List) data; + String summary = STRING.build(commandData.get(1)); + String since = STRING.build(commandData.get(3)); + String group = STRING.build(commandData.get(5)); + String complexity = STRING.build(commandData.get(7)); + List history = null; + if (STRING.build(commandData.get(8)).equals("history")) { + List> rawHistory = (List>) commandData.get(9); + history = new ArrayList<>(rawHistory.size()); + for (List timePoint : rawHistory) { + history.add(STRING.build(timePoint.get(0)) + ": " + STRING.build(timePoint.get(1))); + } + } + return new CommandDocument(summary, since, group, complexity, history); + } + }; } diff --git a/src/main/java/redis/clients/jedis/resps/CommandInfo.java b/src/main/java/redis/clients/jedis/resps/CommandInfo.java index 2e447c922c..9f3481b5a1 100644 --- a/src/main/java/redis/clients/jedis/resps/CommandInfo.java +++ b/src/main/java/redis/clients/jedis/resps/CommandInfo.java @@ -1,7 +1,12 @@ package redis.clients.jedis.resps; +import redis.clients.jedis.Builder; + import java.util.List; +import static redis.clients.jedis.BuilderFactory.STRING_LIST; +import static redis.clients.jedis.BuilderFactory.LONG; + public class CommandInfo { private final long arity; private final List flags; @@ -87,4 +92,22 @@ public List getTips() { public List getSubcommands() { return subcommands; } + + public static final Builder COMMAND_INFO_BUILDER = new Builder() { + @Override + public CommandInfo build(Object data) { + List commandData = (List) data; + + long arity = LONG.build(commandData.get(1)); + List flags = STRING_LIST.build(commandData.get(2)); + long firstKey = LONG.build(commandData.get(3)); + long lastKey = LONG.build(commandData.get(4)); + long step = LONG.build(commandData.get(5)); + List aclCategories = STRING_LIST.build(commandData.get(6)); + List tips = STRING_LIST.build(commandData.get(7)); + List subcommands = STRING_LIST.build(commandData.get(9)); + + return new CommandInfo(arity, flags, firstKey, lastKey, step, aclCategories, tips, subcommands); + } + }; } From ec2400906305721002a46ea9340f3511c32c094c Mon Sep 17 00:00:00 2001 From: Avital-Fine <98389525+Avital-Fine@users.noreply.github.com> Date: Tue, 8 Mar 2022 10:17:09 +0100 Subject: [PATCH 16/23] Update src/main/java/redis/clients/jedis/CommandObjects.java Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --- .../redis/clients/jedis/CommandObjects.java | 29 ------------------- 1 file changed, 29 deletions(-) diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index ddc0771e5d..1f5230a5c7 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -3032,35 +3032,6 @@ public final CommandObject publish(byte[] channel, byte[] message) { } // Miscellaneous commands - public final CommandObject commandCount() { - return new CommandObject<>(commandArguments(COMMAND).add(COUNT), BuilderFactory.LONG); - } - - public final CommandObject> commandDocs(String... commands) { - return new CommandObject<>(commandArguments(COMMAND).add(DOCS).addObjects((Object[]) commands), BuilderFactory.COMMAND_DOCS_RESPONSE); - } - - public final CommandObject> commandGetKeys(String... command) { - return new CommandObject<>(commandArguments(COMMAND).add(GETKEYS).addObjects((Object[]) command), BuilderFactory.STRING_LIST); - } - - public final CommandObject>>> commandGetKeysAndFlags(String... command) { - return new CommandObject<>(commandArguments(COMMAND).add(GETKEYSANDFLAGS).addObjects((Object[]) command), BuilderFactory.KEYED_STRING_LIST_LIST); - } - - public final CommandObject> commandInfo(String... commands) { - return new CommandObject<>(commandArguments(COMMAND).add(Keyword.INFO).addObjects((Object[]) commands), BuilderFactory.COMMAND_INFO_RESPONSE); - } - - public final CommandObject> commandList() { - return new CommandObject<>(commandArguments(COMMAND).add(LIST), BuilderFactory.STRING_LIST); - } - - public final CommandObject> commandListFilterBy(CommandListFilterByParams filterByParams) { - return new CommandObject<>(commandArguments(COMMAND).add(LIST).addParams(filterByParams), - BuilderFactory.STRING_LIST); - } - // RediSearch commands public CommandObject ftCreate(String indexName, IndexOptions indexOptions, Schema schema) { CommandArguments args = commandArguments(SearchCommand.CREATE).add(indexName) From b2c03f1c16a53d7bb6849743b646f2a763ea6d2e Mon Sep 17 00:00:00 2001 From: Avital-Fine <98389525+Avital-Fine@users.noreply.github.com> Date: Tue, 8 Mar 2022 10:17:18 +0100 Subject: [PATCH 17/23] Update src/main/java/redis/clients/jedis/UnifiedJedis.java Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --- .../redis/clients/jedis/UnifiedJedis.java | 35 ------------------- 1 file changed, 35 deletions(-) diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index 26e9343ac3..ced889b91c 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -505,41 +505,6 @@ public Set keys(String pattern) { return executeCommand(commandObjects.keys(pattern)); } - @Override - public long commandCount() { - return executeCommand(commandObjects.commandCount()); - } - - @Override - public Map commandDocs(String... commands) { - return executeCommand(commandObjects.commandDocs(commands)); - } - - @Override - public List commandGetKeys(String... command) { - return executeCommand(commandObjects.commandGetKeys(command)); - } - - @Override - public List>> commandGetKeysAndFlags(String... command) { - return executeCommand(commandObjects.commandGetKeysAndFlags(command)); - } - - @Override - public Map commandInfo(String... commands) { - return executeCommand(commandObjects.commandInfo(commands)); - } - - @Override - public List commandList() { - return executeCommand(commandObjects.commandList()); - } - - @Override - public List commandListFilterBy(CommandListFilterByParams filterByParams) { - return executeCommand(commandObjects.commandListFilterBy(filterByParams)); - } - @Override public ScanResult scan(String cursor) { return executeCommand(commandObjects.scan(cursor)); From e16e557a7dd4a8c3067b7f8c97d4bece50750952 Mon Sep 17 00:00:00 2001 From: Avital-Fine Date: Tue, 8 Mar 2022 12:16:59 +0100 Subject: [PATCH 18/23] restore commands in Jedis.java --- .../redis/clients/jedis/CommandObjects.java | 23 +++++++++++++++++++ src/main/java/redis/clients/jedis/Jedis.java | 7 ------ .../clients/jedis/commands/JedisCommands.java | 2 +- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index 1f5230a5c7..00efbc605e 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -632,6 +632,29 @@ public final CommandObject bitop(BitOP op, byte[] destKey, byte[]... srcKe return new CommandObject<>(commandArguments(BITOP).add(op).key(destKey).keys((Object[]) srcKeys), BuilderFactory.LONG); } + public final CommandObject commandCount() { + return new CommandObject<>(commandArguments(COMMAND).add(COUNT), BuilderFactory.LONG); + } + public final CommandObject> commandDocs(String... commands) { + return new CommandObject<>(commandArguments(COMMAND).add(DOCS).addObjects((Object[]) commands), BuilderFactory.COMMAND_DOCS_RESPONSE); + } + public final CommandObject> commandGetKeys(String... command) { + return new CommandObject<>(commandArguments(COMMAND).add(GETKEYS).addObjects((Object[]) command), BuilderFactory.STRING_LIST); + } + public final CommandObject>>> commandGetKeysAndFlags(String... command) { + return new CommandObject<>(commandArguments(COMMAND).add(GETKEYSANDFLAGS).addObjects((Object[]) command), BuilderFactory.KEYED_STRING_LIST_LIST); + } + public final CommandObject> commandInfo(String... commands) { + return new CommandObject<>(commandArguments(COMMAND).add(Keyword.INFO).addObjects((Object[]) commands), BuilderFactory.COMMAND_INFO_RESPONSE); + } + public final CommandObject> commandList() { + return new CommandObject<>(commandArguments(COMMAND).add(LIST), BuilderFactory.STRING_LIST); + } + public final CommandObject> commandListFilterBy(CommandListFilterByParams filterByParams) { + return new CommandObject<>(commandArguments(COMMAND).add(LIST).addParams(filterByParams), + BuilderFactory.STRING_LIST); + } + /** * @deprecated STRALGO LCS command will be removed from Redis 7. * LCS can be used instead of this method. diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 8b6f01ce54..e9e8975f2f 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -8042,43 +8042,36 @@ public long bitop(final BitOP op, final String destKey, final String... srcKeys) return connection.executeCommand(commandObjects.bitop(op, destKey, srcKeys)); } - @Override public long commandCount() { checkIsInMultiOrPipeline(); return connection.executeCommand(commandObjects.commandCount()); } - @Override public Map commandDocs(String... commands) { checkIsInMultiOrPipeline(); return connection.executeCommand(commandObjects.commandDocs(commands)); } - @Override public List commandGetKeys(String... command) { checkIsInMultiOrPipeline(); return connection.executeCommand(commandObjects.commandGetKeys(command)); } - @Override public List>> commandGetKeysAndFlags(String... command) { checkIsInMultiOrPipeline(); return connection.executeCommand(commandObjects.commandGetKeysAndFlags(command)); } - @Override public Map commandInfo(String... commands) { checkIsInMultiOrPipeline(); return connection.executeCommand(commandObjects.commandInfo(commands)); } - @Override public List commandList() { checkIsInMultiOrPipeline(); return connection.executeCommand(commandObjects.commandList()); } - @Override public List commandListFilterBy(CommandListFilterByParams filterByParams) { checkIsInMultiOrPipeline(); return connection.executeCommand(commandObjects.commandListFilterBy(filterByParams)); diff --git a/src/main/java/redis/clients/jedis/commands/JedisCommands.java b/src/main/java/redis/clients/jedis/commands/JedisCommands.java index 91b6f4ce56..46aefe52b8 100644 --- a/src/main/java/redis/clients/jedis/commands/JedisCommands.java +++ b/src/main/java/redis/clients/jedis/commands/JedisCommands.java @@ -2,5 +2,5 @@ public interface JedisCommands extends KeyCommands, StringCommands, ListCommands, HashCommands, SetCommands, SortedSetCommands, GeoCommands, HyperLogLogCommands, StreamCommands, - ScriptingKeyCommands, FunctionCommands, CommandCommands { + ScriptingKeyCommands, FunctionCommands { } From 13768ea19c94d8c1de2d669c6900b66a640dfece Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Tue, 8 Mar 2022 17:30:29 +0600 Subject: [PATCH 19/23] format --- .../jedis/commands/jedis/AllKindOfValuesCommandsTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java index 50ca293718..cc11655560 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java @@ -23,7 +23,6 @@ import static redis.clients.jedis.util.AssertUtil.assertCollectionContains; import java.util.*; - import org.junit.Test; import redis.clients.jedis.HostAndPort; From 1e4226a0c8b6845a4bb10615a5304e7dff7f6b07 Mon Sep 17 00:00:00 2001 From: Avital-Fine Date: Tue, 8 Mar 2022 16:44:33 +0100 Subject: [PATCH 20/23] implement commands in jedis --- .../redis/clients/jedis/CommandObjects.java | 23 ------------------- src/main/java/redis/clients/jedis/Jedis.java | 22 ++++++++++++------ .../params/CommandListFilterByParams.java | 3 +++ 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index 00efbc605e..1f5230a5c7 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -632,29 +632,6 @@ public final CommandObject bitop(BitOP op, byte[] destKey, byte[]... srcKe return new CommandObject<>(commandArguments(BITOP).add(op).key(destKey).keys((Object[]) srcKeys), BuilderFactory.LONG); } - public final CommandObject commandCount() { - return new CommandObject<>(commandArguments(COMMAND).add(COUNT), BuilderFactory.LONG); - } - public final CommandObject> commandDocs(String... commands) { - return new CommandObject<>(commandArguments(COMMAND).add(DOCS).addObjects((Object[]) commands), BuilderFactory.COMMAND_DOCS_RESPONSE); - } - public final CommandObject> commandGetKeys(String... command) { - return new CommandObject<>(commandArguments(COMMAND).add(GETKEYS).addObjects((Object[]) command), BuilderFactory.STRING_LIST); - } - public final CommandObject>>> commandGetKeysAndFlags(String... command) { - return new CommandObject<>(commandArguments(COMMAND).add(GETKEYSANDFLAGS).addObjects((Object[]) command), BuilderFactory.KEYED_STRING_LIST_LIST); - } - public final CommandObject> commandInfo(String... commands) { - return new CommandObject<>(commandArguments(COMMAND).add(Keyword.INFO).addObjects((Object[]) commands), BuilderFactory.COMMAND_INFO_RESPONSE); - } - public final CommandObject> commandList() { - return new CommandObject<>(commandArguments(COMMAND).add(LIST), BuilderFactory.STRING_LIST); - } - public final CommandObject> commandListFilterBy(CommandListFilterByParams filterByParams) { - return new CommandObject<>(commandArguments(COMMAND).add(LIST).addParams(filterByParams), - BuilderFactory.STRING_LIST); - } - /** * @deprecated STRALGO LCS command will be removed from Redis 7. * LCS can be used instead of this method. diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index e9e8975f2f..80016799a0 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -8044,37 +8044,45 @@ public long bitop(final BitOP op, final String destKey, final String... srcKeys) public long commandCount() { checkIsInMultiOrPipeline(); - return connection.executeCommand(commandObjects.commandCount()); + connection.sendCommand(COMMAND, COUNT); + return connection.getIntegerReply(); } public Map commandDocs(String... commands) { checkIsInMultiOrPipeline(); - return connection.executeCommand(commandObjects.commandDocs(commands)); + connection.sendCommand(COMMAND, joinParameters(DOCS.name(), commands)); + return BuilderFactory.COMMAND_DOCS_RESPONSE.build(connection.getOne()); } public List commandGetKeys(String... command) { checkIsInMultiOrPipeline(); - return connection.executeCommand(commandObjects.commandGetKeys(command)); + connection.sendCommand(COMMAND, joinParameters(GETKEYS.name(), command)); + return BuilderFactory.STRING_LIST.build(connection.getOne()); } public List>> commandGetKeysAndFlags(String... command) { checkIsInMultiOrPipeline(); - return connection.executeCommand(commandObjects.commandGetKeysAndFlags(command)); + connection.sendCommand(COMMAND, joinParameters(GETKEYSANDFLAGS.name(), command)); + return BuilderFactory.KEYED_STRING_LIST_LIST.build(connection.getOne()); } public Map commandInfo(String... commands) { checkIsInMultiOrPipeline(); - return connection.executeCommand(commandObjects.commandInfo(commands)); + connection.sendCommand(COMMAND, joinParameters(Keyword.INFO.name(), commands)); + return BuilderFactory.COMMAND_INFO_RESPONSE.build(connection.getOne()); } public List commandList() { checkIsInMultiOrPipeline(); - return connection.executeCommand(commandObjects.commandList()); + connection.sendCommand(COMMAND, LIST); + return BuilderFactory.STRING_LIST.build(connection.getOne()); } public List commandListFilterBy(CommandListFilterByParams filterByParams) { checkIsInMultiOrPipeline(); - return connection.executeCommand(commandObjects.commandListFilterBy(filterByParams)); + CommandArguments args = new CommandArguments(COMMAND).add(LIST).addParams(filterByParams); + connection.sendCommand(args); + return BuilderFactory.STRING_LIST.build(connection.getOne()); } @Override diff --git a/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java b/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java index 63a55bbbe0..2cdee1799a 100644 --- a/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java +++ b/src/main/java/redis/clients/jedis/params/CommandListFilterByParams.java @@ -1,6 +1,7 @@ package redis.clients.jedis.params; import redis.clients.jedis.CommandArguments; +import redis.clients.jedis.exceptions.JedisDataException; import static redis.clients.jedis.Protocol.Keyword.FILTERBY; import static redis.clients.jedis.Protocol.Keyword.MODULE; @@ -44,6 +45,8 @@ public void addParams(CommandArguments args) { } else if (moduleName == null && category == null && pattern != null) { args.add(PATTERN); args.add(pattern); + } else { + throw new JedisDataException("Must choose exactly one filter"); } } } From 87e356a72809112cc2203c4c1651fc36b619ef45 Mon Sep 17 00:00:00 2001 From: Avital-Fine Date: Tue, 8 Mar 2022 16:49:17 +0100 Subject: [PATCH 21/23] test exception --- .../jedis/AllKindOfValuesCommandsTest.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java index cc11655560..dbdccd062b 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java @@ -1,13 +1,6 @@ package redis.clients.jedis.commands.jedis; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; - +import static org.junit.Assert.*; import static redis.clients.jedis.Protocol.Command.BLPOP; import static redis.clients.jedis.Protocol.Command.HGETALL; import static redis.clients.jedis.Protocol.Command.GET; @@ -1128,6 +1121,12 @@ public void commandList() { commands = jedis.commandListFilterBy(CommandListFilterByParams.commandListFilterByParams().filterByPattern("a*")); assertTrue(commands.size() > 10); + + try { + jedis.commandListFilterBy(CommandListFilterByParams.commandListFilterByParams()); + } catch (Exception e) { + assertSame(JedisDataException.class, e.getClass()); + } } } From 0af1881559371c060701a3cfb2bf906d666680b6 Mon Sep 17 00:00:00 2001 From: Avital-Fine Date: Tue, 8 Mar 2022 16:49:56 +0100 Subject: [PATCH 22/23] test exception --- .../jedis/commands/jedis/AllKindOfValuesCommandsTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java index dbdccd062b..886f20111f 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java @@ -21,6 +21,7 @@ import redis.clients.jedis.HostAndPort; import redis.clients.jedis.Jedis; import redis.clients.jedis.args.ExpiryOption; +import redis.clients.jedis.exceptions.JedisException; import redis.clients.jedis.params.CommandListFilterByParams; import redis.clients.jedis.params.LolwutParams; import redis.clients.jedis.params.ScanParams; @@ -1124,8 +1125,8 @@ public void commandList() { try { jedis.commandListFilterBy(CommandListFilterByParams.commandListFilterByParams()); - } catch (Exception e) { - assertSame(JedisDataException.class, e.getClass()); + } catch (JedisException e) { + assertTrue(true); } } From a750c34baf5d61d0db25b86c62e1827159b9daec Mon Sep 17 00:00:00 2001 From: Avital-Fine Date: Tue, 8 Mar 2022 16:50:26 +0100 Subject: [PATCH 23/23] test exception --- .../jedis/commands/jedis/AllKindOfValuesCommandsTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java index 886f20111f..f84cfc94f6 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java @@ -1125,6 +1125,7 @@ public void commandList() { try { jedis.commandListFilterBy(CommandListFilterByParams.commandListFilterByParams()); + fail(); } catch (JedisException e) { assertTrue(true); }