Apply Sentinel runtime configuration API introduced on Redis 2.8.4
* Implements new sentinel commands (failover, monitor, remove, set) * unit test included ** added 2 redis-server and 1 sentinel for failover test * with some refactoring ** SentinelCommands : refactor to have interface ** HostAndPortUtil : same format to cluster setup
This commit is contained in:
@@ -8,15 +8,14 @@ import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
import redis.clients.util.Slowlog;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
|
||||
public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommands, AdvancedJedisCommands, ScriptingCommands, BasicCommands, ClusterCommands {
|
||||
public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommands, AdvancedJedisCommands, ScriptingCommands, BasicCommands, ClusterCommands, SentinelCommands {
|
||||
public Jedis(final String host) {
|
||||
super(host);
|
||||
}
|
||||
@@ -3006,6 +3005,38 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
return slaves;
|
||||
}
|
||||
|
||||
public String sentinelFailover(String masterName) {
|
||||
client.sentinel(Protocol.SENTINEL_FAILOVER, masterName);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sentinelMonitor(String masterName, String ip, int port,
|
||||
int quorum) {
|
||||
client.sentinel(Protocol.SENTINEL_MONITOR, masterName, ip, String.valueOf(port), String.valueOf(quorum));
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sentinelRemove(String masterName) {
|
||||
client.sentinel(Protocol.SENTINEL_REMOVE, masterName);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sentinelSet(String masterName, Map<String, String> parameterMap) {
|
||||
int index = 0;
|
||||
int paramsLength = parameterMap.size() * 2 + 2;
|
||||
String[] params = new String[paramsLength];
|
||||
|
||||
params[index++] = Protocol.SENTINEL_SET;
|
||||
params[index++] = masterName;
|
||||
for (Entry<String, String> entry : parameterMap.entrySet()) {
|
||||
params[index++] = entry.getKey();
|
||||
params[index++] = entry.getValue();
|
||||
}
|
||||
|
||||
client.sentinel(params);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public byte[] dump(final String key) {
|
||||
checkIsInMulti();
|
||||
client.dump(key);
|
||||
@@ -3214,4 +3245,5 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
client.asking();
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user