From f45adc20e54c015b9b8b31cbcdf7d46c7b325039 Mon Sep 17 00:00:00 2001 From: ihaohong Date: Tue, 14 Jun 2022 22:15:46 +0800 Subject: [PATCH 1/2] Support RESET command (#2952) --- src/main/java/redis/clients/jedis/Jedis.java | 6 ++++ .../java/redis/clients/jedis/Protocol.java | 2 +- .../jedis/commands/ServerCommands.java | 2 ++ .../jedis/AllKindOfValuesCommandsTest.java | 28 +++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 2128861c68..3d289c59b4 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -9176,6 +9176,12 @@ public String lolwut(LolwutParams lolwutParams) { return connection.getBulkReply(); } + @Override + public String reset() { + connection.sendCommand(Command.RESET); + return connection.getStatusCodeReply(); + } + @Override public StreamEntryID xadd(final String key, final StreamEntryID id, final Map hash) { checkIsInMultiOrPipeline(); diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index 8318173ecb..cce61636d0 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, @Deprecated STRALGO; + COMMAND, @Deprecated STRALGO, RESET; private final byte[] raw; diff --git a/src/main/java/redis/clients/jedis/commands/ServerCommands.java b/src/main/java/redis/clients/jedis/commands/ServerCommands.java index e8f31261c5..5c4f7427c3 100644 --- a/src/main/java/redis/clients/jedis/commands/ServerCommands.java +++ b/src/main/java/redis/clients/jedis/commands/ServerCommands.java @@ -221,4 +221,6 @@ public interface ServerCommands { String lolwut(); String lolwut(LolwutParams lolwutParams); + + String reset(); } 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 7243fb7b99..af260fe123 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/AllKindOfValuesCommandsTest.java @@ -20,6 +20,7 @@ import redis.clients.jedis.HostAndPort; import redis.clients.jedis.Jedis; +import redis.clients.jedis.Transaction; import redis.clients.jedis.args.ExpiryOption; import redis.clients.jedis.exceptions.JedisException; import redis.clients.jedis.params.CommandListFilterByParams; @@ -1131,4 +1132,31 @@ public void commandList() { } } + @Test + public void reset() { + // response test + String status = jedis.reset(); + assertEquals("RESET", status); + + // auth reset + String counter = "counter"; + Exception ex1 = assertThrows(JedisDataException.class, () -> { + jedis.set(counter, "1"); + }); + assertEquals("NOAUTH Authentication required.", ex1.getMessage()); + + // multi reset + jedis.auth("foobared"); + jedis.set(counter, "1"); + + Transaction trans = jedis.multi(); + trans.incr(counter); + jedis.reset(); + + Exception ex2 = assertThrows(JedisDataException.class, trans::exec); + assertEquals("EXECABORT Transaction discarded because of: NOAUTH Authentication required.", ex2.getMessage()); + + jedis.auth("foobared"); + assertEquals("1", jedis.get(counter)); + } } From 546968080be22089743bfd58c4b4362cba8ca30c Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Thu, 2 Nov 2023 12:39:03 +0600 Subject: [PATCH 2/2] Fix import conflict --- src/main/java/redis/clients/jedis/CommandObjects.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index 0cca329106..afd973a3dc 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -2845,7 +2845,8 @@ public final CommandObject scriptKill(byte[] sampleKey) { return new CommandObject<>(commandArguments(SCRIPT).add(KILL).processKey(sampleKey), BuilderFactory.STRING); } - private final CommandObject SLOWLOG_RESET_COMMAND_OBJECT = new CommandObject<>(commandArguments(SLOWLOG).add(RESET), BuilderFactory.STRING); + private final CommandObject SLOWLOG_RESET_COMMAND_OBJECT + = new CommandObject<>(commandArguments(SLOWLOG).add(Keyword.RESET), BuilderFactory.STRING); public final CommandObject slowlogReset() { return SLOWLOG_RESET_COMMAND_OBJECT;