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 2 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
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();
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved
}

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