diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index 008cf2d21e..01d356ce89 100644 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -8,6 +8,7 @@ import org.json.JSONArray; import redis.clients.jedis.args.*; +import redis.clients.jedis.commands.DatabasePipelineCommands; import redis.clients.jedis.commands.PipelineBinaryCommands; import redis.clients.jedis.commands.PipelineCommands; import redis.clients.jedis.commands.ProtocolCommand; @@ -25,8 +26,8 @@ import redis.clients.jedis.search.aggr.AggregationBuilder; import redis.clients.jedis.search.aggr.AggregationResult; -public class Pipeline extends Queable implements PipelineCommands, PipelineBinaryCommands, - RedisModulePipelineCommands, Closeable { +public class Pipeline extends Queable implements PipelineCommands, PipelineBinaryCommands, + DatabasePipelineCommands, RedisModulePipelineCommands, Closeable { protected final Connection connection; // private final Jedis jedis; @@ -3330,6 +3331,74 @@ public Response waitReplicas(int replicas, long timeout) { return appendCommand(commandObjects.waitReplicas(replicas, timeout)); } + public Response> time() { + return appendCommand(new CommandObject<>(commandObjects.commandArguments(Protocol.Command.TIME), BuilderFactory.STRING_LIST)); + } + + @Override + public Response select(final int index) { + return appendCommand(new CommandObject<>(commandObjects.commandArguments(Protocol.Command.SELECT), BuilderFactory.STRING)); + } + + @Override + public Response dbSize() { + return appendCommand(new CommandObject<>(commandObjects.commandArguments(Protocol.Command.DBSIZE), BuilderFactory.LONG)); + } + + @Override + public Response swapDB(final int index1, final int index2) { + return appendCommand(new CommandObject<>(commandObjects.commandArguments(Protocol.Command.SWAPDB) + .add(index1).add(index2), BuilderFactory.STRING)); + } + + @Override + public Response move(String key, int dbIndex) { + return appendCommand(new CommandObject<>(commandObjects.commandArguments(Protocol.Command.MOVE) + .key(key).add(dbIndex), BuilderFactory.LONG)); + } + + @Override + public Response move(final byte[] key, final int dbIndex) { + return appendCommand(new CommandObject<>(commandObjects.commandArguments(Protocol.Command.MOVE) + .key(key).add(dbIndex), BuilderFactory.LONG)); + } + + @Override + public Response copy(String srcKey, String dstKey, int db, boolean replace) { + return appendCommand(commandObjects.copy(srcKey, dstKey, db, replace)); + } + + @Override + public Response copy(byte[] srcKey, byte[] dstKey, int db, boolean replace) { + return appendCommand(commandObjects.copy(srcKey, dstKey, db, replace)); + } + + @Override + public Response migrate(String host, int port, byte[] key, int destinationDB, int timeout) { + return appendCommand(new CommandObject<>(commandObjects.commandArguments(Protocol.Command.MIGRATE) + .add(host).add(port).key(key).add(destinationDB).add(timeout), BuilderFactory.STRING)); + } + + @Override + public Response migrate(String host, int port, String key, int destinationDB, int timeout) { + return appendCommand(new CommandObject<>(commandObjects.commandArguments(Protocol.Command.MIGRATE) + .add(host).add(port).key(key).add(destinationDB).add(timeout), BuilderFactory.STRING)); + } + + @Override + public Response migrate(String host, int port, int destinationDB, int timeout, MigrateParams params, byte[]... keys) { + return appendCommand(new CommandObject<>(commandObjects.commandArguments(Protocol.Command.MIGRATE) + .add(host).add(port).add(new byte[0]).add(destinationDB).add(timeout).addParams(params) + .add(Protocol.Keyword.KEYS).keys((Object[]) keys), BuilderFactory.STRING)); + } + + @Override + public Response migrate(String host, int port, int destinationDB, int timeout, MigrateParams params, String... keys) { + return appendCommand(new CommandObject<>(commandObjects.commandArguments(Protocol.Command.MIGRATE) + .add(host).add(port).add(new byte[0]).add(destinationDB).add(timeout).addParams(params) + .add(Protocol.Keyword.KEYS).keys((Object[]) keys), BuilderFactory.STRING)); + } + public Response sendCommand(ProtocolCommand cmd, String... args) { return sendCommand(new CommandArguments(cmd).addObjects((Object[]) args)); } diff --git a/src/main/java/redis/clients/jedis/commands/DatabasePipelineCommands.java b/src/main/java/redis/clients/jedis/commands/DatabasePipelineCommands.java new file mode 100644 index 0000000000..081c8a545b --- /dev/null +++ b/src/main/java/redis/clients/jedis/commands/DatabasePipelineCommands.java @@ -0,0 +1,30 @@ +package redis.clients.jedis.commands; + +import redis.clients.jedis.Response; +import redis.clients.jedis.params.MigrateParams; + +public interface DatabasePipelineCommands { + + Response select(int index); + + Response dbSize(); + + Response swapDB(int index1, int index2); + + Response move(String key, int dbIndex); + + Response move(byte[] key, int dbIndex); + + Response copy(String srcKey, String dstKey, int db, boolean replace); + + Response copy(byte[] srcKey, byte[] dstKey, int db, boolean replace); + + Response migrate(String host, int port, byte[] key, int destinationDB, int timeout); + + Response migrate(String host, int port, int destinationDB, int timeout, MigrateParams params, byte[]... keys); + + Response migrate(String host, int port, String key, int destinationDB, int timeout); + + Response migrate(String host, int port, int destinationDB, int timeout, MigrateParams params, String... keys); + +} diff --git a/src/test/java/redis/clients/jedis/PipeliningTest.java b/src/test/java/redis/clients/jedis/PipeliningTest.java index acadd25857..306e798e3f 100644 --- a/src/test/java/redis/clients/jedis/PipeliningTest.java +++ b/src/test/java/redis/clients/jedis/PipeliningTest.java @@ -153,13 +153,13 @@ private void verifyHasBothValues(byte[] firstKey, byte[] secondKey, byte[] value assertTrue(Arrays.equals(firstKey, value1) || Arrays.equals(firstKey, value2)); assertTrue(Arrays.equals(secondKey, value1) || Arrays.equals(secondKey, value2)); } -// -// @Test -// public void pipelineSelect() { -// Pipeline p = jedis.pipelined(); -// p.select(1); -// p.sync(); -// } + + @Test + public void pipelineSelect() { + Pipeline p = jedis.pipelined(); + p.select(1); + p.sync(); + } @Test public void pipelineResponseWithoutData() {