Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support RESET command #3015

Merged
merged 4 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved
}

@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));
}
}
Loading