Merge branch 'support-cluster-slots' of https://github.com/HeartSaVioR/jedis into HeartSaVioR-support-cluster-slots
This commit is contained in:
@@ -1011,4 +1011,8 @@ public void clusterSetSlotStable(final int slot) {
|
||||
public void clusterFailover() {
|
||||
cluster(Protocol.CLUSTER_FAILOVER);
|
||||
}
|
||||
|
||||
public void clusterSlots() {
|
||||
cluster(Protocol.CLUSTER_SLOTS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,4 +38,6 @@ public interface ClusterCommands {
|
||||
List<String> clusterSlaves(final String nodeId);
|
||||
|
||||
String clusterFailover();
|
||||
|
||||
List<Object> clusterSlots();
|
||||
}
|
||||
|
||||
@@ -3489,6 +3489,13 @@ public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
client.clusterFailover();
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> clusterSlots() {
|
||||
checkIsInMulti();
|
||||
client.clusterSlots();
|
||||
return client.getObjectMultiBulkReply();
|
||||
}
|
||||
|
||||
public String asking() {
|
||||
checkIsInMulti();
|
||||
|
||||
@@ -59,6 +59,7 @@ public final class Protocol {
|
||||
public static final String CLUSTER_REPLICATE = "replicate";
|
||||
public static final String CLUSTER_SLAVES = "slaves";
|
||||
public static final String CLUSTER_FAILOVER = "failover";
|
||||
public static final String CLUSTER_SLOTS = "slots";
|
||||
public static final String PUBSUB_CHANNELS= "channels";
|
||||
public static final String PUBSUB_NUMSUB = "numsub";
|
||||
public static final String PUBSUB_NUM_PAT = "numpat";
|
||||
|
||||
@@ -45,6 +45,8 @@ public class ClusterCommandsTest extends JedisTestBase {
|
||||
node1.clusterDelSlots(1, 2, 3, 4, 5, 500);
|
||||
node1.clusterSetSlotNode(5000, node1Id);
|
||||
node1.clusterDelSlots(5000, 10000);
|
||||
node1.clusterDelSlots(3000, 3001, 3002);
|
||||
node2.clusterDelSlots(4000, 4001, 4002);
|
||||
node1.clusterAddSlots(6000);
|
||||
node1.clusterDelSlots(6000);
|
||||
waitForGossip();
|
||||
@@ -134,5 +136,34 @@ public class ClusterCommandsTest extends JedisTestBase {
|
||||
String status = node1.clusterSetSlotMigrating(5000, nodeId);
|
||||
assertEquals("OK", status);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clusterSlots() {
|
||||
// please see cluster slot output format from below commit
|
||||
// @see:
|
||||
// https://github.com/antirez/redis/commit/e14829de3025ffb0d3294e5e5a1553afd9f10b60
|
||||
String status = node1.clusterAddSlots(3000, 3001, 3002);
|
||||
assertEquals("OK", status);
|
||||
status = node2.clusterAddSlots(4000, 4001, 4002);
|
||||
assertEquals("OK", status);
|
||||
|
||||
List<Object> slots = node1.clusterSlots();
|
||||
assertNotNull(slots);
|
||||
assertTrue(slots.size() > 0);
|
||||
|
||||
for (Object slotInfoObj : slots) {
|
||||
List<Object> slotInfo = (List<Object>) slotInfoObj;
|
||||
assertNotNull(slots);
|
||||
assertTrue(slots.size() >= 2);
|
||||
|
||||
assertTrue(slotInfo.get(0) instanceof Long);
|
||||
assertTrue(slotInfo.get(1) instanceof Long);
|
||||
|
||||
if (slots.size() > 2) {
|
||||
// assigned slots
|
||||
assertTrue(slotInfo.get(2) instanceof List);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user