From 5b15d48803078397b3af487bdad289dc9a0ba21a Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Mon, 2 Dec 2013 14:34:05 -0500 Subject: [PATCH] Refactor to have interfaces. Add cluster pipeline commands. --- src/main/java/redis/clients/jedis/Client.java | 37 ++++++++++++++ .../redis/clients/jedis/ClusterCommands.java | 23 +++++++++ .../redis/clients/jedis/ClusterPipeline.java | 23 +++++++++ src/main/java/redis/clients/jedis/Jedis.java | 21 ++++---- .../clients/jedis/MultiKeyPipelineBase.java | 48 ++++++++++++++++++- 5 files changed, 140 insertions(+), 12 deletions(-) create mode 100644 src/main/java/redis/clients/jedis/ClusterCommands.java create mode 100644 src/main/java/redis/clients/jedis/ClusterPipeline.java diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index 90621f3..bbe7045 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -831,4 +831,41 @@ public class Client extends BinaryClient implements Commands { arg[0] = SafeEncoder.encode(subcommand); cluster(arg); } + + public void clusterNodes() { + cluster(Protocol.CLUSTER_NODES); + } + + public void clusterMeet(final String ip, final int port) { + cluster(Protocol.CLUSTER_MEET, ip, String.valueOf(port)); + } + + public void clusterAddSlots(final int ...slots) { + cluster(Protocol.CLUSTER_ADDSLOTS, slots); + } + + public void clusterDelSlots(final int ...slots) { + cluster(Protocol.CLUSTER_DELSLOTS, slots); + } + + public void clusterInfo() { + cluster(Protocol.CLUSTER_INFO); + } + + public void clusterGetKeysInSlot(final int slot, final int count) { + final int[] args = new int[]{ slot, count }; + cluster(Protocol.CLUSTER_GETKEYSINSLOT, args); + } + + public void clusterSetSlotNode(final int slot, final String nodeId) { + cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot), Protocol.CLUSTER_SETSLOT_NODE, nodeId); + } + + public void clusterSetSlotMigrating(final int slot, final String nodeId) { + cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot), Protocol.CLUSTER_SETSLOT_MIGRATING, nodeId); + } + + public void clusterSetSlotImporting(final int slot, final String nodeId) { + cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot), Protocol.CLUSTER_SETSLOT_IMPORTING, nodeId); + } } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/ClusterCommands.java b/src/main/java/redis/clients/jedis/ClusterCommands.java new file mode 100644 index 0000000..fff4533 --- /dev/null +++ b/src/main/java/redis/clients/jedis/ClusterCommands.java @@ -0,0 +1,23 @@ +package redis.clients.jedis; + +import java.util.List; + +public interface ClusterCommands { + String clusterNodes(); + + String clusterMeet(final String ip, final int port); + + String clusterAddSlots(final int... slots); + + String clusterDelSlots(final int... slots); + + String clusterInfo(); + + List clusterGetKeysInSlot(final int slot, final int count); + + String clusterSetSlotNode(final int slot, final String nodeId); + + String clusterSetSlotMigrating(final int slot, final String nodeId); + + String clusterSetSlotImporting(final int slot, final String nodeId); +} diff --git a/src/main/java/redis/clients/jedis/ClusterPipeline.java b/src/main/java/redis/clients/jedis/ClusterPipeline.java new file mode 100644 index 0000000..73330d4 --- /dev/null +++ b/src/main/java/redis/clients/jedis/ClusterPipeline.java @@ -0,0 +1,23 @@ +package redis.clients.jedis; + +import java.util.List; + +public interface ClusterPipeline { + Response clusterNodes(); + + Response clusterMeet(final String ip, final int port); + + Response clusterAddSlots(final int... slots); + + Response clusterDelSlots(final int... slots); + + Response clusterInfo(); + + Response> clusterGetKeysInSlot(final int slot, final int count); + + Response clusterSetSlotNode(final int slot, final String nodeId); + + Response clusterSetSlotMigrating(final int slot, final String nodeId); + + Response clusterSetSlotImporting(final int slot, final String nodeId); +} diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 6451f30..c6add77 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -7,7 +7,7 @@ import redis.clients.util.Slowlog; import java.net.URI; import java.util.*; -public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommands, AdvancedJedisCommands, ScriptingCommands { +public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommands, AdvancedJedisCommands, ScriptingCommands, ClusterCommands { public Jedis(final String host) { super(host); } @@ -3079,56 +3079,55 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand public String clusterNodes() { checkIsInMulti(); - client.cluster(Protocol.CLUSTER_NODES); + client.clusterNodes(); return client.getBulkReply(); } public String clusterMeet(final String ip, final int port) { checkIsInMulti(); - client.cluster(Protocol.CLUSTER_MEET, ip, String.valueOf(port)); + client.clusterMeet(ip, port); return client.getStatusCodeReply(); } public String clusterAddSlots(final int ...slots) { checkIsInMulti(); - client.cluster(Protocol.CLUSTER_ADDSLOTS, slots); + client.clusterAddSlots(slots); return client.getStatusCodeReply(); } public String clusterDelSlots(final int ...slots) { checkIsInMulti(); - client.cluster(Protocol.CLUSTER_DELSLOTS, slots); + client.clusterDelSlots(slots); return client.getStatusCodeReply(); } public String clusterInfo() { checkIsInMulti(); - client.cluster(Protocol.CLUSTER_INFO); + client.clusterInfo(); return client.getStatusCodeReply(); } public List clusterGetKeysInSlot(final int slot, final int count) { checkIsInMulti(); - final int[] args = new int[]{ slot, count }; - client.cluster(Protocol.CLUSTER_GETKEYSINSLOT, args); + client.clusterGetKeysInSlot(slot, count); return client.getMultiBulkReply(); } public String clusterSetSlotNode(final int slot, final String nodeId) { checkIsInMulti(); - client.cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot), Protocol.CLUSTER_SETSLOT_NODE, nodeId); + client.clusterSetSlotNode(slot, nodeId); return client.getStatusCodeReply(); } public String clusterSetSlotMigrating(final int slot, final String nodeId) { checkIsInMulti(); - client.cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot), Protocol.CLUSTER_SETSLOT_MIGRATING, nodeId); + client.clusterSetSlotMigrating(slot, nodeId); return client.getStatusCodeReply(); } public String clusterSetSlotImporting(final int slot, final String nodeId) { checkIsInMulti(); - client.cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot), Protocol.CLUSTER_SETSLOT_IMPORTING, nodeId); + client.clusterSetSlotImporting(slot, nodeId); return client.getStatusCodeReply(); } } diff --git a/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java b/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java index be9d89a..04bdc80 100644 --- a/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java +++ b/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java @@ -7,7 +7,8 @@ import java.util.Set; abstract class MultiKeyPipelineBase extends PipelineBase implements BasicRedisPipeline, MultiKeyBinaryRedisPipeline, - MultiKeyCommandsPipeline { + MultiKeyCommandsPipeline, + ClusterPipeline { protected Client client = null; @@ -398,4 +399,49 @@ abstract class MultiKeyPipelineBase extends PipelineBase implements client.bitop(op, destKey, srcKeys); return getResponse(BuilderFactory.LONG); } + + public Response clusterNodes() { + client.clusterNodes(); + return getResponse(BuilderFactory.STRING); + } + + public Response clusterMeet(final String ip, final int port) { + client.clusterMeet(ip, port); + return getResponse(BuilderFactory.STRING); + } + + public Response clusterAddSlots(final int... slots) { + client.clusterAddSlots(slots); + return getResponse(BuilderFactory.STRING); + } + + public Response clusterDelSlots(final int... slots) { + client.clusterDelSlots(slots); + return getResponse(BuilderFactory.STRING); + } + + public Response clusterInfo() { + client.clusterInfo(); + return getResponse(BuilderFactory.STRING); + } + + public Response> clusterGetKeysInSlot(final int slot, final int count) { + client.clusterGetKeysInSlot(slot, count); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response clusterSetSlotNode(final int slot, final String nodeId) { + client.clusterSetSlotNode(slot, nodeId); + return getResponse(BuilderFactory.STRING); + } + + public Response clusterSetSlotMigrating(final int slot, final String nodeId) { + client.clusterSetSlotMigrating(slot, nodeId); + return getResponse(BuilderFactory.STRING); + } + + public Response clusterSetSlotImporting(final int slot, final String nodeId) { + client.clusterSetSlotImporting(slot, nodeId); + return getResponse(BuilderFactory.STRING); + } }