Add CLUSTER MEET command

This commit is contained in:
Jonathan Leibiusky
2013-12-02 10:01:19 -05:00
parent e7e2bfaedf
commit 403f2b292c
4 changed files with 19 additions and 5 deletions

View File

@@ -808,10 +808,10 @@ 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 String... args) { public void cluster(final Object... args) {
final byte[][] arg = new byte[args.length][]; final byte[][] arg = new byte[args.length][];
for (int i = 0; i < arg.length; i++) { for (int i = 0; i < arg.length; i++) {
arg[i] = SafeEncoder.encode(args[i]); arg[i] = SafeEncoder.encode(args[i].toString());
} }
cluster(arg); cluster(arg);
} }

View File

@@ -3082,4 +3082,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
client.cluster(Protocol.CLUSTER_NODES); client.cluster(Protocol.CLUSTER_NODES);
return client.getBulkReply(); return client.getBulkReply();
} }
public String clusterMeet(final String ip, final int port) {
checkIsInMulti();
client.cluster(Protocol.CLUSTER_MEET, ip, port);
return client.getStatusCodeReply();
}
} }

View File

@@ -31,6 +31,7 @@ public final class Protocol {
public static final String SENTINEL_SLAVES = "slaves"; public static final String SENTINEL_SLAVES = "slaves";
public static final String CLUSTER_NODES = "nodes"; public static final String CLUSTER_NODES = "nodes";
public static final String CLUSTER_MEET = "meet";
private Protocol() { private Protocol() {
// this prevent the class from instantiation // this prevent the class from instantiation

View File

@@ -13,10 +13,11 @@ public class ClusterCommandsTest extends JedisTestBase {
private Jedis node1; private Jedis node1;
private Jedis node2; private Jedis node2;
private HostAndPort nodeInfo1 = HostAndPortUtil.getClusterServers().get(0);
private HostAndPort nodeInfo2 = HostAndPortUtil.getClusterServers().get(1);
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
HostAndPort nodeInfo1 = HostAndPortUtil.getClusterServers().get(0);
HostAndPort nodeInfo2 = HostAndPortUtil.getClusterServers().get(1);
node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort()); node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort());
node1.connect(); node1.connect();
@@ -36,6 +37,12 @@ public class ClusterCommandsTest extends JedisTestBase {
@Test @Test
public void clusterNodes() { public void clusterNodes() {
String nodes = node1.clusterNodes(); String nodes = node1.clusterNodes();
assertEquals(1, nodes.split("\n").length); assertTrue(nodes.split("\n").length > 0);
}
@Test
public void clusterMeet() {
String status = node1.clusterMeet("127.0.0.1", nodeInfo2.getPort());
assertEquals("OK", status);
} }
} }