Skip to content

Commit

Permalink
Support RESET command (#3015)
Browse files Browse the repository at this point in the history
* Support RESET command (#2952)

* Fix import conflict

---------

Co-authored-by: M Sazzadul Hoque <[email protected]>
  • Loading branch information
ihaohong and sazzad16 authored Nov 2, 2023
1 parent 9e1a731 commit 65ed601
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -2845,7 +2845,8 @@ public final CommandObject<String> scriptKill(byte[] sampleKey) {
return new CommandObject<>(commandArguments(SCRIPT).add(KILL).processKey(sampleKey), BuilderFactory.STRING);
}

private final CommandObject<String> SLOWLOG_RESET_COMMAND_OBJECT = new CommandObject<>(commandArguments(SLOWLOG).add(RESET), BuilderFactory.STRING);
private final CommandObject<String> SLOWLOG_RESET_COMMAND_OBJECT
= new CommandObject<>(commandArguments(SLOWLOG).add(Keyword.RESET), BuilderFactory.STRING);

public final CommandObject<String> slowlogReset() {
return SLOWLOG_RESET_COMMAND_OBJECT;
Expand Down
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 @@ -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();
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 @@ -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;

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

0 comments on commit 65ed601

Please sign in to comment.