Refactor to have interfaces.
Add cluster pipeline commands.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
23
src/main/java/redis/clients/jedis/ClusterCommands.java
Normal file
23
src/main/java/redis/clients/jedis/ClusterCommands.java
Normal file
@@ -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<String> 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);
|
||||
}
|
||||
23
src/main/java/redis/clients/jedis/ClusterPipeline.java
Normal file
23
src/main/java/redis/clients/jedis/ClusterPipeline.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ClusterPipeline {
|
||||
Response<String> clusterNodes();
|
||||
|
||||
Response<String> clusterMeet(final String ip, final int port);
|
||||
|
||||
Response<String> clusterAddSlots(final int... slots);
|
||||
|
||||
Response<String> clusterDelSlots(final int... slots);
|
||||
|
||||
Response<String> clusterInfo();
|
||||
|
||||
Response<List<String>> clusterGetKeysInSlot(final int slot, final int count);
|
||||
|
||||
Response<String> clusterSetSlotNode(final int slot, final String nodeId);
|
||||
|
||||
Response<String> clusterSetSlotMigrating(final int slot, final String nodeId);
|
||||
|
||||
Response<String> clusterSetSlotImporting(final int slot, final String nodeId);
|
||||
}
|
||||
@@ -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<String> 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String> clusterNodes() {
|
||||
client.clusterNodes();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> clusterMeet(final String ip, final int port) {
|
||||
client.clusterMeet(ip, port);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> clusterAddSlots(final int... slots) {
|
||||
client.clusterAddSlots(slots);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> clusterDelSlots(final int... slots) {
|
||||
client.clusterDelSlots(slots);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> clusterInfo() {
|
||||
client.clusterInfo();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<List<String>> clusterGetKeysInSlot(final int slot, final int count) {
|
||||
client.clusterGetKeysInSlot(slot, count);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<String> clusterSetSlotNode(final int slot, final String nodeId) {
|
||||
client.clusterSetSlotNode(slot, nodeId);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> clusterSetSlotMigrating(final int slot, final String nodeId) {
|
||||
client.clusterSetSlotMigrating(slot, nodeId);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> clusterSetSlotImporting(final int slot, final String nodeId) {
|
||||
client.clusterSetSlotImporting(slot, nodeId);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user