Support CLUSTER SLOTS command

* CLUSTER SLOTS returns a Redis-formatted mapping from slot ranges to IP/Port pairs serving that slot range
* description link including output format
** e14829de30
* Unit test included
This commit is contained in:
Jungtaek Lim
2014-07-02 06:46:58 +09:00
parent e05eaa2b07
commit fd23f8b8f7
5 changed files with 45 additions and 0 deletions

View File

@@ -1011,4 +1011,8 @@ public void clusterSetSlotStable(final int slot) {
public void clusterFailover() {
cluster(Protocol.CLUSTER_FAILOVER);
}
public void clusterSlots() {
cluster(Protocol.CLUSTER_SLOTS);
}
}

View File

@@ -38,4 +38,6 @@ public interface ClusterCommands {
List<String> clusterSlaves(final String nodeId);
String clusterFailover();
List<Object> clusterSlots();
}

View File

@@ -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();

View File

@@ -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";

View File

@@ -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);
}
}
}
}