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; diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 560b05d46e..6db8c99328 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -9259,6 +9259,12 @@ public String lolwut(LolwutParams lolwutParams) { return connection.getBulkReply(); } + @Override + public String reset() { + connection.sendCommand(Command.RESET); + return connection.getStatusCodeReply(); + } + @Override public String latencyDoctor() { checkIsInMultiOrPipeline(); diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index 3f273877b5..d7c36503fc 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -272,7 +272,7 @@ public static enum Command implements ProtocolCommand { SSUBSCRIBE, SUNSUBSCRIBE, SPUBLISH, // <-- pub sub SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, PERSIST, ROLE, FAILOVER, SLOWLOG, OBJECT, CLIENT, TIME, SCAN, HSCAN, SSCAN, ZSCAN, WAIT, CLUSTER, ASKING, READONLY, READWRITE, SLAVEOF, REPLICAOF, COPY, - SENTINEL, MODULE, ACL, TOUCH, MEMORY, LOLWUT, COMMAND, LATENCY, WAITAOF; + SENTINEL, MODULE, ACL, TOUCH, MEMORY, LOLWUT, COMMAND, RESET, LATENCY, WAITAOF; 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 46f1220407..511357ac1d 100644 --- a/src/main/java/redis/clients/jedis/commands/ServerCommands.java +++ b/src/main/java/redis/clients/jedis/commands/ServerCommands.java @@ -229,6 +229,8 @@ default void shutdown(SaveMode saveMode) throws JedisException { String lolwut(LolwutParams lolwutParams); + String reset(); + /** * The LATENCY DOCTOR command reports about different latency-related issues and advises about * possible remedies. 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 fc3f4c9c3e..a681d4f4d8 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.Transaction; import redis.clients.jedis.args.ExpiryOption; import redis.clients.jedis.params.ScanParams; import redis.clients.jedis.resps.ScanResult; @@ -1124,4 +1125,32 @@ public void copy() { assertTrue(jedis.copy(bfoo1, bfoo2, true)); assertArrayEquals(bbar1, jedis.get(bfoo2)); } + + @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)); + } }