Skip to content

Commit

Permalink
SHUTDOWN with optional modifier (#2544)
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 committed May 18, 2021
1 parent 0bcb1b9 commit 7ccb1f4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import redis.clients.jedis.Protocol.Keyword;
import redis.clients.jedis.args.ListDirection;
import redis.clients.jedis.args.FlushMode;
import redis.clients.jedis.args.SaveMode;
import redis.clients.jedis.args.UnblockType;
import redis.clients.jedis.params.*;
import redis.clients.jedis.util.SafeEncoder;
Expand Down Expand Up @@ -1051,6 +1052,14 @@ public void shutdown() {
sendCommand(SHUTDOWN);
}

public void shutdown(SaveMode saveMode) {
if (saveMode == null) {
sendCommand(SHUTDOWN);
} else {
sendCommand(SHUTDOWN, saveMode.getRaw());
}
}

public void info() {
sendCommand(INFO);
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import redis.clients.jedis.commands.MultiKeyBinaryCommands;
import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.exceptions.InvalidURIException;
import redis.clients.jedis.exceptions.JedisConnectionException;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.exceptions.JedisException;
import redis.clients.jedis.params.*;
import redis.clients.jedis.util.JedisURIHelper;
Expand Down Expand Up @@ -3483,6 +3485,16 @@ public String shutdown() {
return status;
}

@Override
public void shutdown(final SaveMode saveMode) throws JedisException {
client.shutdown(saveMode);
try {
throw new JedisDataException(client.getStatusCodeReply());
} catch (JedisConnectionException ex) {
// expected
}
}

/**
* Provide information and statistics about the server.
* <p>
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/redis/clients/jedis/args/SaveMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package redis.clients.jedis.args;

import redis.clients.jedis.util.SafeEncoder;

public enum SaveMode implements Rawable {

/**
* Prevent a DB saving operation even if one or more save points are configured.
*/
NOSAVE,

/**
* Force a DB saving operation even if no save points are configured.
*/
SAVE;

private final byte[] raw;

private SaveMode() {
raw = SafeEncoder.encode(name());
}

@Override
public byte[] getRaw() {
return raw;
}
}
10 changes: 10 additions & 0 deletions src/main/java/redis/clients/jedis/commands/BasicCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import redis.clients.jedis.DebugParams;
import redis.clients.jedis.args.FlushMode;
import redis.clients.jedis.args.SaveMode;
import redis.clients.jedis.exceptions.JedisException;

public interface BasicCommands {

Expand Down Expand Up @@ -136,6 +138,14 @@ public interface BasicCommands {
*/
String shutdown();

/**
* @see SaveMode
* @param saveMode modifier to alter the data save behavior of SHUTDOWN. {@code null} would
* trigger the default behavior.
* @throws JedisException
*/
void shutdown(SaveMode saveMode) throws JedisException;

/**
* The INFO command returns information and statistics about the server in a format that is simple
* to parse by computers and easy to read by humans.
Expand Down

0 comments on commit 7ccb1f4

Please sign in to comment.