Skip to content

Commit

Permalink
Support RESET command (redis#2952)
Browse files Browse the repository at this point in the history
  • Loading branch information
ihaohong committed Jun 14, 2022
1 parent d6ba80a commit f45adc2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> hash) {
checkIsInMultiOrPipeline();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,6 @@ public interface ServerCommands {
String lolwut();

String lolwut(LolwutParams lolwutParams);

String reset();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}

0 comments on commit f45adc2

Please sign in to comment.