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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +33,10 @@ public final class Protocol {
|
||||
public static final String SENTINEL_GET_MASTER_ADDR_BY_NAME = "get-master-addr-by-name";
|
||||
public static final String SENTINEL_RESET = "reset";
|
||||
public static final String SENTINEL_SLAVES = "slaves";
|
||||
public static final String SENTINEL_FAILOVER = "failover";
|
||||
public static final String SENTINEL_MONITOR = "monitor";
|
||||
public static final String SENTINEL_REMOVE = "remove";
|
||||
public static final String SENTINEL_SET = "set";
|
||||
|
||||
public static final String CLUSTER_NODES = "nodes";
|
||||
public static final String CLUSTER_MEET = "meet";
|
||||
|
||||
22
src/main/java/redis/clients/jedis/SentinelCommands.java
Normal file
22
src/main/java/redis/clients/jedis/SentinelCommands.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface SentinelCommands {
|
||||
public List<Map<String, String>> sentinelMasters();
|
||||
|
||||
public List<String> sentinelGetMasterAddrByName(String masterName);
|
||||
|
||||
public Long sentinelReset(String pattern);
|
||||
|
||||
public List<Map<String, String>> sentinelSlaves(String masterName);
|
||||
|
||||
public String sentinelFailover(String masterName);
|
||||
|
||||
public String sentinelMonitor(String masterName, String ip, int port, int quorum);
|
||||
|
||||
public String sentinelRemove(String masterName);
|
||||
|
||||
public String sentinelSet(String masterName, Map<String, String> parameterMap);
|
||||
}
|
||||
Reference in New Issue
Block a user