DATAREDIS-184 - Add support for 'SAVE/NOSAVE' to shutdown.
Created and added 'ShutdownOptions' to 'RedisServerCommands'. The full implementation is available for 'lettuce' and 'srp'. When using 'jedis' the command is emulated using lua script via 'eval'. For 'jredis' the method is not available and will throw 'UnsupportedOperationException'. Original Pull Request: #47
This commit is contained in:
committed by
Thomas Darimont
parent
4b2ccbecb9
commit
d116d3825a
@@ -760,6 +760,15 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
|
||||
delegate.shutdown();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisServerCommands#shutdown(org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption)
|
||||
*/
|
||||
@Override
|
||||
public void shutdown(ShutdownOption option) {
|
||||
delegate.shutdown(option);
|
||||
}
|
||||
|
||||
public Set<byte[]> sInter(byte[]... keys) {
|
||||
Set<byte[]> results = delegate.sInter(keys);
|
||||
if (isFutureConversion()) {
|
||||
|
||||
@@ -27,6 +27,10 @@ import java.util.Properties;
|
||||
*/
|
||||
public interface RedisServerCommands {
|
||||
|
||||
public enum ShutdownOption {
|
||||
SAVE, NOSAVE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start an {@literal Append Only File} rewrite process on server.
|
||||
*
|
||||
@@ -116,6 +120,14 @@ public interface RedisServerCommands {
|
||||
*/
|
||||
void shutdown();
|
||||
|
||||
/**
|
||||
* Shutdown server.
|
||||
*
|
||||
* @see http://redis.io/commands/shutdown
|
||||
* @since 1.3
|
||||
*/
|
||||
void shutdown(ShutdownOption option);
|
||||
|
||||
/**
|
||||
* Load configuration parameters for given {@code pattern} from server.
|
||||
*
|
||||
|
||||
@@ -76,6 +76,8 @@ public class JedisConnection implements RedisConnection {
|
||||
private static final Method SEND_COMMAND;
|
||||
private static final Method GET_RESPONSE;
|
||||
|
||||
private static final String SHUTDOWN_SCRIPT = "return redis.call('SHUTDOWN','%s')";
|
||||
|
||||
static {
|
||||
CLIENT_FIELD = ReflectionUtils.findField(BinaryJedis.class, "client", Client.class);
|
||||
ReflectionUtils.makeAccessible(CLIENT_FIELD);
|
||||
@@ -624,6 +626,21 @@ public class JedisConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisServerCommands#shutdown(org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption)
|
||||
*/
|
||||
@Override
|
||||
public void shutdown(ShutdownOption option) {
|
||||
|
||||
if (option == null) {
|
||||
shutdown();
|
||||
return;
|
||||
}
|
||||
|
||||
eval(String.format(SHUTDOWN_SCRIPT, option.name()).getBytes(), ReturnType.STATUS, 0);
|
||||
}
|
||||
|
||||
public byte[] echo(byte[] message) {
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
|
||||
@@ -291,6 +291,15 @@ public class JredisConnection implements RedisConnection {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisServerCommands#shutdown(org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption)
|
||||
*/
|
||||
@Override
|
||||
public void shutdown(ShutdownOption option) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Long del(byte[]... keys) {
|
||||
try {
|
||||
return jredis.del(keys);
|
||||
|
||||
@@ -662,6 +662,30 @@ public class LettuceConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisServerCommands#shutdown(org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption)
|
||||
*/
|
||||
@Override
|
||||
public void shutdown(ShutdownOption option) {
|
||||
|
||||
if (option == null) {
|
||||
shutdown();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean save = ShutdownOption.SAVE.equals(option);
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
getAsyncConnection().shutdown(save);
|
||||
return;
|
||||
}
|
||||
getConnection().shutdown(save);
|
||||
} catch (Exception ex) {
|
||||
throw convertLettuceAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] echo(byte[] message) {
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
@@ -149,7 +150,7 @@ public class SrpConnection implements RedisConnection {
|
||||
|
||||
public void addCommand(FutureResult result) {
|
||||
futureResults.add(result);
|
||||
if (!(result instanceof SrpTxResult)) {
|
||||
if (!(result instanceof SrpTxResult) && result.getResultHolder() != null) {
|
||||
Futures.addCallback(((SrpGenericResult) result).getResultHolder(), this);
|
||||
}
|
||||
}
|
||||
@@ -208,6 +209,13 @@ public class SrpConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
SrpConnection(RedisClient client) {
|
||||
|
||||
Assert.notNull(client);
|
||||
this.client = client;
|
||||
this.queue = new ArrayBlockingQueue<SrpConnection>(50);
|
||||
}
|
||||
|
||||
public SrpConnection(String host, int port, BlockingQueue<SrpConnection> queue) {
|
||||
try {
|
||||
this.client = new RedisClient(host, port);
|
||||
@@ -481,6 +489,31 @@ public class SrpConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisServerCommands#shutdown(org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption)
|
||||
*/
|
||||
@Override
|
||||
public void shutdown(ShutdownOption option) {
|
||||
|
||||
if (option == null) {
|
||||
shutdown();
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] save = option.name().getBytes(Charsets.UTF_8);
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(new SrpStatusResult(pipeline.shutdown(save, null)));
|
||||
return;
|
||||
}
|
||||
client.shutdown(save, null);
|
||||
} catch (Exception ex) {
|
||||
throw convertSrpAccessException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public byte[] echo(byte[] message) {
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
|
||||
Reference in New Issue
Block a user