Add CLUSTER ADDSLOTS and CLUSTER DELSLOTS commands
This commit is contained in:
@@ -808,11 +808,27 @@ public class Client extends BinaryClient implements Commands {
|
|||||||
hincrByFloat(SafeEncoder.encode(key), SafeEncoder.encode(field), increment);
|
hincrByFloat(SafeEncoder.encode(key), SafeEncoder.encode(field), increment);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cluster(final Object... args) {
|
public void cluster(final String subcommand, final int... args) {
|
||||||
final byte[][] arg = new byte[args.length][];
|
final byte[][] arg = new byte[args.length+1][];
|
||||||
for (int i = 0; i < arg.length; i++) {
|
for (int i = 1; i < arg.length; i++) {
|
||||||
arg[i] = SafeEncoder.encode(args[i].toString());
|
arg[i] = toByteArray(args[i-1]);
|
||||||
}
|
}
|
||||||
|
arg[0] = SafeEncoder.encode(subcommand);
|
||||||
|
cluster(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cluster(final String subcommand, final String... args) {
|
||||||
|
final byte[][] arg = new byte[args.length+1][];
|
||||||
|
for (int i = 1; i < arg.length; i++) {
|
||||||
|
arg[i] = SafeEncoder.encode(args[i-1]);
|
||||||
|
}
|
||||||
|
arg[0] = SafeEncoder.encode(subcommand);
|
||||||
|
cluster(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cluster(final String subcommand) {
|
||||||
|
final byte[][] arg = new byte[1][];
|
||||||
|
arg[0] = SafeEncoder.encode(subcommand);
|
||||||
cluster(arg);
|
cluster(arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3085,7 +3085,19 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
|||||||
|
|
||||||
public String clusterMeet(final String ip, final int port) {
|
public String clusterMeet(final String ip, final int port) {
|
||||||
checkIsInMulti();
|
checkIsInMulti();
|
||||||
client.cluster(Protocol.CLUSTER_MEET, ip, port);
|
client.cluster(Protocol.CLUSTER_MEET, ip, String.valueOf(port));
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String clusterAddSlots(final int ...slots) {
|
||||||
|
checkIsInMulti();
|
||||||
|
client.cluster(Protocol.CLUSTER_ADDSLOTS, slots);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String clusterDelSlots(final int ...slots) {
|
||||||
|
checkIsInMulti();
|
||||||
|
client.cluster(Protocol.CLUSTER_DELSLOTS, slots);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ public final class Protocol {
|
|||||||
|
|
||||||
public static final String CLUSTER_NODES = "nodes";
|
public static final String CLUSTER_NODES = "nodes";
|
||||||
public static final String CLUSTER_MEET = "meet";
|
public static final String CLUSTER_MEET = "meet";
|
||||||
|
public static final String CLUSTER_ADDSLOTS = "addslots";
|
||||||
|
public static final String CLUSTER_DELSLOTS = "delslots";
|
||||||
|
|
||||||
private Protocol() {
|
private Protocol() {
|
||||||
// this prevent the class from instantiation
|
// this prevent the class from instantiation
|
||||||
|
|||||||
@@ -45,4 +45,17 @@ public class ClusterCommandsTest extends JedisTestBase {
|
|||||||
String status = node1.clusterMeet("127.0.0.1", nodeInfo2.getPort());
|
String status = node1.clusterMeet("127.0.0.1", nodeInfo2.getPort());
|
||||||
assertEquals("OK", status);
|
assertEquals("OK", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void clusterAddSlots() {
|
||||||
|
String status = node1.clusterAddSlots(1, 2, 3, 4, 5);
|
||||||
|
assertEquals("OK", status);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void clusterDelSlots() {
|
||||||
|
node1.clusterAddSlots(900);
|
||||||
|
String status = node1.clusterDelSlots(900);
|
||||||
|
assertEquals("OK", status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user