From 33ceb6da0fe60583b7e67bceda7e475ebe9a173a Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Tue, 15 Feb 2011 20:51:36 -0500 Subject: [PATCH 001/112] set keepAlive on pub/sub sockets (infinite timeout) in case we don't see the connection close --- src/main/java/redis/clients/jedis/Connection.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index 4136fd3..bdb5d02 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -34,6 +34,7 @@ public class Connection { public void setTimeoutInfinite() { try { + socket.setKeepAlive(true); socket.setSoTimeout(0); } catch (SocketException ex) { throw new JedisException(ex); @@ -43,6 +44,7 @@ public class Connection { public void rollbackTimeout() { try { socket.setSoTimeout(timeout); + socket.setKeepAlive(false); } catch (SocketException ex) { throw new JedisException(ex); } From 8ddba03add9319d1300eea3233e372040bc184c6 Mon Sep 17 00:00:00 2001 From: Eric Hauser Date: Thu, 2 Jun 2011 20:25:19 -0400 Subject: [PATCH 002/112] switch SharededJedisPipeline to use return Response and deprecate existing API --- .../clients/jedis/BinaryShardedJedis.java | 15 +- .../redis/clients/jedis/ShardedJedis.java | 6 +- .../clients/jedis/ShardedJedisPipeline.java | 403 +++++++++++------- .../jedis/tests/SharedJedisPipelineTest.java | 109 +++++ 4 files changed, 379 insertions(+), 154 deletions(-) create mode 100644 src/test/java/redis/clients/jedis/tests/SharedJedisPipelineTest.java diff --git a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java index 113511b..9c1abd2 100644 --- a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java @@ -1,5 +1,9 @@ package redis.clients.jedis; +import redis.clients.jedis.BinaryClient.LIST_POSITION; +import redis.clients.util.Hashing; +import redis.clients.util.Sharded; + import java.io.IOException; import java.util.Collection; import java.util.List; @@ -7,10 +11,6 @@ import java.util.Map; import java.util.Set; import java.util.regex.Pattern; -import redis.clients.jedis.BinaryClient.LIST_POSITION; -import redis.clients.util.Hashing; -import redis.clients.util.Sharded; - public class BinaryShardedJedis extends Sharded implements BinaryJedisCommands { public BinaryShardedJedis(List shards) { @@ -395,9 +395,16 @@ public class BinaryShardedJedis extends Sharded return j.linsert(key, where, pivot, value); } + @Deprecated public List pipelined(ShardedJedisPipeline shardedJedisPipeline) { shardedJedisPipeline.setShardedJedis(this); shardedJedisPipeline.execute(); return shardedJedisPipeline.getResults(); } + + public ShardedJedisPipeline pipelined() { + ShardedJedisPipeline pipeline = new ShardedJedisPipeline(); + pipeline.setShardedJedis(this); + return pipeline; + } } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/ShardedJedis.java b/src/main/java/redis/clients/jedis/ShardedJedis.java index ca95af9..b8c00e7 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedis.java +++ b/src/main/java/redis/clients/jedis/ShardedJedis.java @@ -1,13 +1,13 @@ package redis.clients.jedis; +import redis.clients.jedis.BinaryClient.LIST_POSITION; +import redis.clients.util.Hashing; + import java.util.List; import java.util.Map; import java.util.Set; import java.util.regex.Pattern; -import redis.clients.jedis.BinaryClient.LIST_POSITION; -import redis.clients.util.Hashing; - public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { public ShardedJedis(List shards) { super(shards); diff --git a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java index 544ce73..cb0dc61 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java +++ b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java @@ -2,13 +2,12 @@ package redis.clients.jedis; import redis.clients.jedis.BinaryClient.LIST_POSITION; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; -public abstract class ShardedJedisPipeline { +public class ShardedJedisPipeline extends Queable { private BinaryShardedJedis jedis; private List results = new ArrayList(); + private Queue clients = new LinkedList(); private class FutureResult { private Client client; @@ -26,427 +25,498 @@ public abstract class ShardedJedisPipeline { this.jedis = jedis; } - protected void set(String key, String value) { - Client c = jedis.getShard(key).getClient(); + public Response set(String key, String value) { + Client c = getClient(key); c.set(key, value); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); } - protected void get(String key) { - Client c = jedis.getShard(key).getClient(); + public Response get(String key) { + Client c = getClient(key); c.get(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); } - protected void exists(String key) { - Client c = jedis.getShard(key).getClient(); + public Response exists(String key) { + Client c = getClient(key); c.exists(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.BOOLEAN); } - protected void type(String key) { - Client c = jedis.getShard(key).getClient(); + public Response type(String key) { + Client c = getClient(key); c.type(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.BOOLEAN); } - protected void expire(String key, int seconds) { - Client c = jedis.getShard(key).getClient(); + public Response expire(String key, int seconds) { + Client c = getClient(key); c.expire(key, seconds); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void expireAt(String key, long unixTime) { - Client c = jedis.getShard(key).getClient(); + public Response expireAt(String key, long unixTime) { + Client c = getClient(key); c.expireAt(key, unixTime); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void ttl(String key) { - Client c = jedis.getShard(key).getClient(); + public Response ttl(String key) { + Client c = getClient(key); c.ttl(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void getSet(String key, String value) { - Client c = jedis.getShard(key).getClient(); + public Response getSet(String key, String value) { + Client c = getClient(key); c.getSet(key, value); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); } - protected void setnx(String key, String value) { - Client c = jedis.getShard(key).getClient(); + public Response setnx(String key, String value) { + Client c = getClient(key); c.setnx(key, value); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void setex(String key, int seconds, String value) { - Client c = jedis.getShard(key).getClient(); + public Response setex(String key, int seconds, String value) { + Client c = getClient(key); c.setex(key, seconds, value); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void decrBy(String key, int integer) { - Client c = jedis.getShard(key).getClient(); + public Response decrBy(String key, long integer) { + Client c = getClient(key); c.decrBy(key, integer); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void decr(String key) { - Client c = jedis.getShard(key).getClient(); + public Response decr(String key) { + Client c = getClient(key); c.decr(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void incrBy(String key, int integer) { - Client c = jedis.getShard(key).getClient(); + public Response incrBy(String key, int integer) { + Client c = getClient(key); c.incrBy(key, integer); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void incr(String key) { - Client c = jedis.getShard(key).getClient(); + public Response incr(String key) { + Client c = getClient(key); c.incr(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void append(String key, String value) { - Client c = jedis.getShard(key).getClient(); + public Response append(String key, String value) { + Client c = getClient(key); c.append(key, value); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void substr(String key, int start, int end) { - Client c = jedis.getShard(key).getClient(); + public Response substr(String key, int start, int end) { + Client c = getClient(key); c.substr(key, start, end); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); } - protected void hset(String key, String field, String value) { - Client c = jedis.getShard(key).getClient(); + public Response hset(String key, String field, String value) { + Client c = getClient(key); c.hset(key, field, value); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void hget(String key, String field) { - Client c = jedis.getShard(key).getClient(); + public Response hget(String key, String field) { + Client c = getClient(key); c.hget(key, field); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); } - protected void hsetnx(String key, String field, String value) { - Client c = jedis.getShard(key).getClient(); + public Response hsetnx(String key, String field, String value) { + Client c = getClient(key); c.hsetnx(key, field, value); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void hmset(String key, Map hash) { - Client c = jedis.getShard(key).getClient(); + public Response hmset(String key, Map hash) { + Client c = getClient(key); c.hmset(key, hash); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); } - protected void hmget(String key, String... fields) { - Client c = jedis.getShard(key).getClient(); + public Response> hmget(String key, String... fields) { + Client c = getClient(key); c.hmget(key, fields); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_LIST); } - protected void hincrBy(String key, String field, int value) { - Client c = jedis.getShard(key).getClient(); + public Response hincrBy(String key, String field, int value) { + Client c = getClient(key); c.hincrBy(key, field, value); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void hexists(String key, String field) { - Client c = jedis.getShard(key).getClient(); + public Response hexists(String key, String field) { + Client c = getClient(key); c.hexists(key, field); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.BOOLEAN); } - protected void hdel(String key, String field) { - Client c = jedis.getShard(key).getClient(); + public Response hdel(String key, String field) { + Client c = getClient(key); c.hdel(key, field); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void hlen(String key) { - Client c = jedis.getShard(key).getClient(); + public Response hlen(String key) { + Client c = getClient(key); c.hlen(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void hkeys(String key) { - Client c = jedis.getShard(key).getClient(); + public Response> hkeys(String key) { + Client c = getClient(key); c.hkeys(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_SET); } - protected void hvals(String key) { - Client c = jedis.getShard(key).getClient(); + public Response> hvals(String key) { + Client c = getClient(key); c.hvals(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_SET); } - protected void hgetAll(String key) { - Client c = jedis.getShard(key).getClient(); + public Response> hgetAll(String key) { + Client c = getClient(key); c.hgetAll(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_MAP); } - protected void rpush(String key, String string) { - Client c = jedis.getShard(key).getClient(); + public Response rpush(String key, String string) { + Client c = getClient(key); c.rpush(key, string); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void lpush(String key, String string) { - Client c = jedis.getShard(key).getClient(); + public Response lpush(String key, String string) { + Client c = getClient(key); c.lpush(key, string); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void llen(String key) { - Client c = jedis.getShard(key).getClient(); + public Response llen(String key) { + Client c = getClient(key); c.llen(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void lrange(String key, int start, int end) { - Client c = jedis.getShard(key).getClient(); + public Response> lrange(String key, int start, int end) { + Client c = getClient(key); c.lrange(key, start, end); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_LIST); } - protected void ltrim(String key, int start, int end) { - Client c = jedis.getShard(key).getClient(); + public Response ltrim(String key, int start, int end) { + Client c = getClient(key); c.ltrim(key, start, end); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); } - protected void lindex(String key, int index) { - Client c = jedis.getShard(key).getClient(); + public Response lindex(String key, int index) { + Client c = getClient(key); c.lindex(key, index); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); } - protected void lset(String key, int index, String value) { - Client c = jedis.getShard(key).getClient(); + public Response lset(String key, int index, String value) { + Client c = getClient(key); c.lset(key, index, value); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); } - protected void lrem(String key, int count, String value) { - Client c = jedis.getShard(key).getClient(); + public Response lrem(String key, int count, String value) { + Client c = getClient(key); c.lrem(key, count, value); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void lpop(String key) { - Client c = jedis.getShard(key).getClient(); + public Response lpop(String key) { + Client c = getClient(key); c.lpop(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); } - protected void rpop(String key) { - Client c = jedis.getShard(key).getClient(); + public Response rpop(String key) { + Client c = getClient(key); c.rpop(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); } - protected void sadd(String key, String member) { - Client c = jedis.getShard(key).getClient(); + public Response sadd(String key, String member) { + Client c = getClient(key); c.sadd(key, member); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void smembers(String key) { - Client c = jedis.getShard(key).getClient(); + public Response> smembers(String key) { + Client c = getClient(key); c.smembers(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_SET); } - protected void srem(String key, String member) { - Client c = jedis.getShard(key).getClient(); + public Response srem(String key, String member) { + Client c = getClient(key); c.srem(key, member); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void spop(String key) { - Client c = jedis.getShard(key).getClient(); + public Response spop(String key) { + Client c = getClient(key); c.spop(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); } - protected void scard(String key) { - Client c = jedis.getShard(key).getClient(); + public Response scard(String key) { + Client c = getClient(key); c.scard(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void sismember(String key, String member) { - Client c = jedis.getShard(key).getClient(); + public Response sismember(String key, String member) { + Client c = getClient(key); c.sismember(key, member); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.BOOLEAN); } - protected void srandmember(String key) { - Client c = jedis.getShard(key).getClient(); + public Response srandmember(String key) { + Client c = getClient(key); c.srandmember(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); } - protected void zadd(String key, double score, String member) { - Client c = jedis.getShard(key).getClient(); + public Response zadd(String key, double score, String member) { + Client c = getClient(key); c.zadd(key, score, member); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void zrange(String key, int start, int end) { - Client c = jedis.getShard(key).getClient(); + public Response> zrange(String key, int start, int end) { + Client c = getClient(key); c.zrange(key, start, end); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_SET); } - protected void zrem(String key, String member) { - Client c = jedis.getShard(key).getClient(); + public Response zrem(String key, String member) { + Client c = getClient(key); c.zrem(key, member); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void zincrby(String key, double score, String member) { - Client c = jedis.getShard(key).getClient(); + public Response zincrby(String key, double score, String member) { + Client c = getClient(key); c.zincrby(key, score, member); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.DOUBLE); } - protected void zrank(String key, String member) { - Client c = jedis.getShard(key).getClient(); + public Response zrank(String key, String member) { + Client c = getClient(key); c.zrank(key, member); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void zrevrank(String key, String member) { - Client c = jedis.getShard(key).getClient(); + public Response zrevrank(String key, String member) { + Client c = getClient(key); c.zrevrank(key, member); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void zrevrange(String key, int start, int end) { - Client c = jedis.getShard(key).getClient(); + public Response> zrevrange(String key, int start, int end) { + Client c = getClient(key); c.zrevrange(key, start, end); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_ZSET); } - protected void zrangeWithScores(String key, int start, int end) { - Client c = jedis.getShard(key).getClient(); + public Response> zrangeWithScores(String key, int start, int end) { + Client c = getClient(key); c.zrangeWithScores(key, start, end); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.TUPLE_ZSET); } - protected void zrevrangeWithScores(String key, int start, int end) { - Client c = jedis.getShard(key).getClient(); + public Response> zrevrangeWithScores(String key, int start, int end) { + Client c = getClient(key); c.zrevrangeWithScores(key, start, end); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.TUPLE_ZSET); } - protected void zcard(String key) { - Client c = jedis.getShard(key).getClient(); + public Response zcard(String key) { + Client c = getClient(key); c.zcard(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void zscore(String key, String member) { - Client c = jedis.getShard(key).getClient(); + public Response zscore(String key, String member) { + Client c = getClient(key); c.zscore(key, member); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.DOUBLE); } - protected void sort(String key) { - Client c = jedis.getShard(key).getClient(); + public Response sort(String key) { + Client c = getClient(key); c.sort(key); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.DOUBLE); } - protected void sort(String key, SortingParams sortingParameters) { - Client c = jedis.getShard(key).getClient(); + public Response> sort(String key, SortingParams sortingParameters) { + Client c = getClient(key); c.sort(key, sortingParameters); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_LIST); } - protected void zcount(String key, double min, double max) { - Client c = jedis.getShard(key).getClient(); + public Response zcount(String key, double min, double max) { + Client c = getClient(key); c.zcount(key, min, max); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void zrangeByScore(String key, double min, double max) { - Client c = jedis.getShard(key).getClient(); + public Response> zrangeByScore(String key, double min, double max) { + Client c = getClient(key); c.zrangeByScore(key, min, max); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_ZSET); } - protected void zrangeByScore(String key, double min, double max, - int offset, int count) { - Client c = jedis.getShard(key).getClient(); + public Response> zrangeByScore(String key, double min, double max, + int offset, int count) { + Client c = getClient(key); c.zrangeByScore(key, min, max, offset, count); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_ZSET); } - protected void zrangeByScoreWithScores(String key, double min, double max) { - Client c = jedis.getShard(key).getClient(); + public Response> zrangeByScoreWithScores(String key, double min, double max) { + Client c = getClient(key); c.zrangeByScoreWithScores(key, min, max); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.TUPLE_ZSET); } - protected void zrangeByScoreWithScores(String key, double min, double max, + public Response> zrangeByScoreWithScores(String key, double min, double max, int offset, int count) { - Client c = jedis.getShard(key).getClient(); + Client c = getClient(key); c.zrangeByScoreWithScores(key, min, max, offset, count); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.TUPLE_ZSET); } - protected void zremrangeByRank(String key, int start, int end) { - Client c = jedis.getShard(key).getClient(); + public Response zremrangeByRank(String key, int start, int end) { + Client c = getClient(key); c.zremrangeByRank(key, start, end); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void zremrangeByScore(String key, double start, double end) { - Client c = jedis.getShard(key).getClient(); + public Response zremrangeByScore(String key, double start, double end) { + Client c = getClient(key); c.zremrangeByScore(key, start, end); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void linsert(String key, LIST_POSITION where, String pivot, - String value) { - Client c = jedis.getShard(key).getClient(); + public Response linsert(String key, LIST_POSITION where, String pivot, + String value) { + Client c = getClient(key); c.linsert(key, where, pivot, value); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } - protected void getbit(String key, long offset) { - Client c = jedis.getShard(key).getClient(); + public Response getbit(String key, long offset) { + Client c = getClient(key); c.getbit(key, offset); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.BOOLEAN); } - public void setbit(String key, long offset, boolean value) { - Client c = jedis.getShard(key).getClient(); + public Response setbit(String key, long offset, boolean value) { + Client c = getClient(key); c.setbit(key, offset, value); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.BOOLEAN); } - public void setrange(String key, long offset, String value) { - Client c = jedis.getShard(key).getClient(); + public Response setrange(String key, long offset, String value) { + Client c = getClient(key); c.setrange(key, offset, value); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } - public void getrange(String key, long startOffset, long endOffset) { - Client c = jedis.getShard(key).getClient(); + public Response getrange(String key, long startOffset, long endOffset) { + Client c = getClient(key); c.getrange(key, startOffset, endOffset); results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); } public List getResults() { @@ -457,5 +527,44 @@ public abstract class ShardedJedisPipeline { return r; } - public abstract void execute(); + /** + * Syncronize pipeline by reading all responses. This operation closes the + * pipeline. In order to get return values from pipelined commands, capture + * the different Response<?> of the commands you execute. + */ + public void sync() { + for (Client client : clients) { + generateResponse(client.getOne()); + } + } + + /** + * Syncronize pipeline by reading all responses. This operation closes the + * pipeline. Whenever possible try to avoid using this version and use + * ShardedJedisPipeline.sync() as it won't go through all the responses and generate the + * right response type (usually it is a waste of time). + * + * @return A list of all the responses in the order you executed them. + */ + public List syncAndReturnAll() { + List formatted = new ArrayList(); + for (Client client : clients) { + formatted.add(generateResponse(client.getOne()).get()); + } + return formatted; + } + + /** + * This method will be removed in Jedis 3.0. Use the methods that return Response's and call + * sync(). + */ + @Deprecated + public void execute() { + } + + private Client getClient(String key) { + Client client = jedis.getShard(key).getClient(); + clients.add(client); + return client; + } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/SharedJedisPipelineTest.java b/src/test/java/redis/clients/jedis/tests/SharedJedisPipelineTest.java new file mode 100644 index 0000000..7ca2a52 --- /dev/null +++ b/src/test/java/redis/clients/jedis/tests/SharedJedisPipelineTest.java @@ -0,0 +1,109 @@ +package redis.clients.jedis.tests; + +import org.junit.Before; +import org.junit.Test; +import redis.clients.jedis.*; +import redis.clients.jedis.exceptions.JedisDataException; + +import java.io.UnsupportedEncodingException; +import java.util.*; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + +public class SharedJedisPipelineTest { + private static HostAndPortUtil.HostAndPort redis1 = HostAndPortUtil.getRedisServers() + .get(0); + private static HostAndPortUtil.HostAndPort redis2 = HostAndPortUtil.getRedisServers() + .get(1); + + private ShardedJedis jedis; + + @Before + public void setUp() throws Exception { + Jedis jedis = new Jedis(redis1.host, redis1.port); + jedis.flushAll(); + jedis.disconnect(); + jedis = new Jedis(redis2.host, redis2.port); + jedis.flushAll(); + jedis.disconnect(); + + List shards = new ArrayList(); + shards.add(new JedisShardInfo(redis1.host, redis1.port)); + shards.add(new JedisShardInfo(redis2.host, redis2.port)); + this.jedis = new ShardedJedis(shards); + } + + @Test + public void pipeline() throws UnsupportedEncodingException { + ShardedJedisPipeline p = jedis.pipelined(); + p.set("foo", "bar"); + p.get("foo"); + List results = p.syncAndReturnAll(); + + assertEquals(2, results.size()); + assertEquals("OK", results.get(0)); + assertEquals("bar", results.get(1)); + + } + + @Test + public void pipelineResponse() { + jedis.set("string", "foo"); + jedis.lpush("list", "foo"); + jedis.hset("hash", "foo", "bar"); + jedis.zadd("zset", 1, "foo"); + jedis.sadd("set", "foo"); + + ShardedJedisPipeline p = jedis.pipelined(); + Response string = p.get("string"); + Response list = p.lpop("list"); + Response hash = p.hget("hash", "foo"); + Response> zset = p.zrange("zset", 0, -1); + Response set = p.spop("set"); + Response blist = p.exists("list"); + Response zincrby = p.zincrby("zset", 1, "foo"); + Response zcard = p.zcard("zset"); + p.lpush("list", "bar"); + Response> lrange = p.lrange("list", 0, -1); + Response> hgetAll = p.hgetAll("hash"); + p.sadd("set", "foo"); + Response> smembers = p.smembers("set"); + Response> zrangeWithScores = p.zrangeWithScores("zset", 0, + -1); + p.sync(); + + assertEquals("foo", string.get()); + assertEquals("foo", list.get()); + assertEquals("bar", hash.get()); + assertEquals("foo", zset.get().iterator().next()); + assertEquals("foo", set.get()); + assertFalse(blist.get()); + assertEquals(new Double(2), zincrby.get()); + assertEquals(new Long(1), zcard.get()); + assertEquals(1, lrange.get().size()); + assertNotNull(hgetAll.get().get("foo")); + assertEquals(1, smembers.get().size()); + assertEquals(1, zrangeWithScores.get().size()); + } + + @Test(expected = JedisDataException.class) + public void pipelineResponseWithinPipeline() { + jedis.set("string", "foo"); + + ShardedJedisPipeline p = jedis.pipelined(); + Response string = p.get("string"); + string.get(); + p.sync(); + } + + @Test + public void canRetrieveUnsetKey() { + ShardedJedisPipeline p = jedis.pipelined(); + Response shouldNotExist = p.get(UUID.randomUUID().toString()); + p.sync(); + assertNull(shouldNotExist.get()); + } +} From 6e4e1c39f4d0b732d48fea86daaddaf6468de511 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Wed, 15 Jun 2011 09:46:48 +0100 Subject: [PATCH 003/112] Throwing Jedis connection exception on IO error rather than JedisException --- src/main/java/redis/clients/util/RedisInputStream.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/redis/clients/util/RedisInputStream.java b/src/main/java/redis/clients/util/RedisInputStream.java index f30ddf5..221e756 100644 --- a/src/main/java/redis/clients/util/RedisInputStream.java +++ b/src/main/java/redis/clients/util/RedisInputStream.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.InputStream; import redis.clients.jedis.exceptions.JedisConnectionException; -import redis.clients.jedis.exceptions.JedisException; public class RedisInputStream extends FilterInputStream { @@ -84,7 +83,7 @@ public class RedisInputStream extends FilterInputStream { } } } catch (IOException e) { - throw new JedisException(e); + throw new JedisConnectionException(e); } String reply = sb.toString(); if (reply.length() == 0) { From f25901d64e963f5261feb0acfee1b523ba74dae1 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 23 Jun 2011 14:56:46 -0700 Subject: [PATCH 004/112] Fence code blocks in README with languages. --- README.md | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 558111b..3f8f39d 100644 --- a/README.md +++ b/README.md @@ -48,20 +48,23 @@ You can download the latest build at: Or use it as a maven dependency: - - redis.clients - jedis - 2.0.0 - jar - compile - - +```xml + + redis.clients + jedis + 2.0.0 + jar + compile + +``` To use it just: - Jedis jedis = new Jedis("localhost"); - jedis.set("foo", "bar"); - String value = jedis.get("foo"); +```java +Jedis jedis = new Jedis("localhost"); +jedis.set("foo", "bar"); +String value = jedis.get("foo"); +``` For more usage examples check the tests. From 234336b58bfb60fa4ea5ea088f74100dca05c10c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 23 Jun 2011 16:49:28 -0700 Subject: [PATCH 005/112] Fix @see tags referencing int params that are now long --- src/main/java/redis/clients/jedis/Jedis.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 497277d..60768fa 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -508,7 +508,7 @@ public class Jedis extends BinaryJedis implements JedisCommands { * * @see #incr(String) * @see #decr(String) - * @see #incrBy(String, int) + * @see #incrBy(String, long) * * @param key * @param integer @@ -536,8 +536,8 @@ public class Jedis extends BinaryJedis implements JedisCommands { * Time complexity: O(1) * * @see #incr(String) - * @see #incrBy(String, int) - * @see #decrBy(String, int) + * @see #incrBy(String, long) + * @see #decrBy(String, long) * * @param key * @return Integer reply, this commands will reply with the new value of key @@ -564,7 +564,7 @@ public class Jedis extends BinaryJedis implements JedisCommands { * * @see #incr(String) * @see #decr(String) - * @see #decrBy(String, int) + * @see #decrBy(String, long) * * @param key * @param integer @@ -591,9 +591,9 @@ public class Jedis extends BinaryJedis implements JedisCommands { *

* Time complexity: O(1) * - * @see #incrBy(String, int) + * @see #incrBy(String, long) * @see #decr(String) - * @see #decrBy(String, int) + * @see #decrBy(String, long) * * @param key * @return Integer reply, this commands will reply with the new value of key @@ -1042,7 +1042,7 @@ public class Jedis extends BinaryJedis implements JedisCommands { * O(N) (with N being the length of the list), setting the first or last * elements of the list is O(1). * - * @see #lindex(String, int) + * @see #lindex(String, long) * * @param key * @param index @@ -1278,7 +1278,7 @@ public class Jedis extends BinaryJedis implements JedisCommands { /** * Return the members of a set resulting from the intersection of all the * sets hold at the specified keys. Like in - * {@link #lrange(String, int, int) LRANGE} the result is sent to the client + * {@link #lrange(String, long, long) LRANGE} the result is sent to the client * as a multi-bulk reply (see the protocol specification for more * information). If just a single key is specified, then this command * produces the same result as {@link #smembers(String) SMEMBERS}. Actually @@ -1320,7 +1320,7 @@ public class Jedis extends BinaryJedis implements JedisCommands { /** * Return the members of a set resulting from the union of all the sets hold - * at the specified keys. Like in {@link #lrange(String, int, int) LRANGE} + * at the specified keys. Like in {@link #lrange(String, long, long) LRANGE} * the result is sent to the client as a multi-bulk reply (see the protocol * specification for more information). If just a single key is specified, * then this command produces the same result as {@link #smembers(String) From 97bbfdc2d6a9bc3e9ce7b4dd17bbb6733e53e4cf Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 24 Jun 2011 16:40:36 -0700 Subject: [PATCH 006/112] Iterate over entry set instead of key set. --- src/main/java/redis/clients/jedis/BinaryClient.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index 050964a..4a76a63 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -11,6 +11,7 @@ import static redis.clients.jedis.Protocol.Keyword.WITHSCORES; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import redis.clients.jedis.Protocol.Command; import redis.clients.jedis.Protocol.Keyword; @@ -205,9 +206,9 @@ public class BinaryClient extends Connection { final List params = new ArrayList(); params.add(key); - for (final byte[] field : hash.keySet()) { - params.add(field); - params.add(hash.get(field)); + for (final Entry entry : hash.entrySet()) { + params.add(entry.getKey()); + params.add(entry.getValue()); } sendCommand(HMSET, params.toArray(new byte[params.size()][])); } From e9644a45291302d797ce769d51082fb52726a19a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 24 Jun 2011 16:44:12 -0700 Subject: [PATCH 007/112] Add JedisPool constructor that takes only host string --- src/main/java/redis/clients/jedis/JedisPool.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/JedisPool.java b/src/main/java/redis/clients/jedis/JedisPool.java index 0f4fe4b..251741d 100644 --- a/src/main/java/redis/clients/jedis/JedisPool.java +++ b/src/main/java/redis/clients/jedis/JedisPool.java @@ -14,11 +14,15 @@ public class JedisPool extends Pool { null); } - public JedisPool(String host, int port) { + public JedisPool(final String host, final int port) { super(new Config(), new JedisFactory(host, port, Protocol.DEFAULT_TIMEOUT, null)); } + public JedisPool(final String host) { + this(host, Protocol.DEFAULT_PORT); + } + public JedisPool(final Config poolConfig, final String host, int port, int timeout, final String password) { super(poolConfig, new JedisFactory(host, port, timeout, password)); From bbb6d666ac556bf229213b296aa80c5cb7615c8a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 28 Jun 2011 10:52:46 -0700 Subject: [PATCH 008/112] Fix broken @see and @link tags --- .../java/redis/clients/jedis/BinaryJedis.java | 155 +++++++++--------- 1 file changed, 77 insertions(+), 78 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 6b6c626..3a74f71 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -258,7 +258,7 @@ public class BinaryJedis implements BinaryJedisCommands { *

* Since Redis 2.1.3 you can update the value of the timeout of a key * already having an expire set. It is also possible to undo the expire at - * all turning the key into a normal key using the {@link #persist(String) + * all turning the key into a normal key using the {@link #persist(byte[]) * PERSIST} command. *

* Time complexity: O(1) @@ -280,7 +280,7 @@ public class BinaryJedis implements BinaryJedisCommands { } /** - * EXPIREAT works exctly like {@link #expire(String, int) EXPIRE} but + * EXPIREAT works exctly like {@link #expire(byte[], int) EXPIRE} but * instead to get the number of seconds representing the Time To Live of the * key as a second argument (that is a relative way of specifing the TTL), * it takes an absolute one in the form of a UNIX timestamp (Number of @@ -294,7 +294,7 @@ public class BinaryJedis implements BinaryJedisCommands { *

* Since Redis 2.1.3 you can update the value of the timeout of a key * already having an expire set. It is also possible to undo the expire at - * all turning the key into a normal key using the {@link #persist(String) + * all turning the key into a normal key using the {@link #persist(byte[]) * PERSIST} command. *

* Time complexity: O(1) @@ -317,7 +317,7 @@ public class BinaryJedis implements BinaryJedisCommands { /** * The TTL command returns the remaining time to live in seconds of a key - * that has an {@link #expire(String, int) EXPIRE} set. This introspection + * that has an {@link #expire(byte[], int) EXPIRE} set. This introspection * capability allows a Redis client to check how many seconds a given key * will continue to be part of the dataset. * @@ -410,7 +410,7 @@ public class BinaryJedis implements BinaryJedisCommands { } /** - * SETNX works exactly like {@link #set(String, String) SET} with the only + * SETNX works exactly like {@link #set(byte[], byte[]) SET} with the only * difference that if the key already exists no operation is performed. * SETNX actually means "SET if Not eXists". *

@@ -429,7 +429,7 @@ public class BinaryJedis implements BinaryJedisCommands { /** * The command is exactly equivalent to the following group of commands: - * {@link #set(String, String) SET} + {@link #expire(String, int) EXPIRE}. + * {@link #set(byte[], byte[]) SET} + {@link #expire(byte[], int) EXPIRE}. * The operation is atomic. *

* Time complexity: O(1) @@ -511,9 +511,9 @@ public class BinaryJedis implements BinaryJedisCommands { *

* Time complexity: O(1) * - * @see #incr(String) - * @see #decr(String) - * @see #incrBy(String, int) + * @see #incr(byte[]) + * @see #decr(byte[]) + * @see #incrBy(byte[], long) * * @param key * @param integer @@ -540,9 +540,9 @@ public class BinaryJedis implements BinaryJedisCommands { *

* Time complexity: O(1) * - * @see #incr(String) - * @see #incrBy(String, int) - * @see #decrBy(String, int) + * @see #incr(byte[]) + * @see #incrBy(byte[], long) + * @see #decrBy(byte[], long) * * @param key * @return Integer reply, this commands will reply with the new value of key @@ -555,7 +555,7 @@ public class BinaryJedis implements BinaryJedisCommands { } /** - * INCRBY work just like {@link #incr(String) INCR} but instead to increment + * INCRBY work just like {@link #incr(byte[]) INCR} but instead to increment * by 1 the increment is integer. *

* INCR commands are limited to 64 bit signed integers. @@ -567,9 +567,9 @@ public class BinaryJedis implements BinaryJedisCommands { *

* Time complexity: O(1) * - * @see #incr(String) - * @see #decr(String) - * @see #decrBy(String, int) + * @see #incr(byte[]) + * @see #decr(byte[]) + * @see #decrBy(byte[], long) * * @param key * @param integer @@ -596,9 +596,9 @@ public class BinaryJedis implements BinaryJedisCommands { *

* Time complexity: O(1) * - * @see #incrBy(String, int) - * @see #decr(String) - * @see #decrBy(String, int) + * @see #incrBy(byte[], long) + * @see #decr(byte[]) + * @see #decrBy(byte[], long) * * @param key * @return Integer reply, this commands will reply with the new value of key @@ -881,7 +881,7 @@ public class BinaryJedis implements BinaryJedisCommands { *

* Time complexity: O(1) * - * @see BinaryJedis#lpush(String, String) + * @see BinaryJedis#lpush(byte[], byte[]) * * @param key * @param string @@ -902,7 +902,7 @@ public class BinaryJedis implements BinaryJedisCommands { *

* Time complexity: O(1) * - * @see BinaryJedis#rpush(String, String) + * @see BinaryJedis#rpush(byte[], byte[]) * * @param key * @param string @@ -1053,7 +1053,7 @@ public class BinaryJedis implements BinaryJedisCommands { * O(N) (with N being the length of the list), setting the first or last * elements of the list is O(1). * - * @see #lindex(String, int) + * @see #lindex(byte[], int) * * @param key * @param index @@ -1071,7 +1071,7 @@ public class BinaryJedis implements BinaryJedisCommands { * count is zero all the elements are removed. If count is negative elements * are removed from tail to head, instead to go from head to tail that is * the normal behaviour. So for example LREM with count -2 and hello as - * value to remove against the list (a,b,c,hello,x,hello,hello) will lave + * value to remove against the list (a,b,c,hello,x,hello,hello) will have * the list (a,b,c,hello,x). The number of removed elements is returned as * an integer, see below for more information about the returned value. Note * that non existing keys are considered like empty lists by LREM, so LREM @@ -1099,7 +1099,7 @@ public class BinaryJedis implements BinaryJedisCommands { * If the key does not exist or the list is already empty the special value * 'nil' is returned. * - * @see #rpop(String) + * @see #rpop(byte[]) * * @param key * @return Bulk reply @@ -1118,7 +1118,7 @@ public class BinaryJedis implements BinaryJedisCommands { * If the key does not exist or the list is already empty the special value * 'nil' is returned. * - * @see #lpop(String) + * @see #lpop(byte[]) * * @param key * @return Bulk reply @@ -1210,7 +1210,7 @@ public class BinaryJedis implements BinaryJedisCommands { * Remove a random element from a Set returning it as return value. If the * Set is empty or the key does not exist, a nil object is returned. *

- * The {@link #srandmember(String)} command does a similar work but the + * The {@link #srandmember(byte[])} command does a similar work but the * returned element is not removed from the Set. *

* Time complexity O(1) @@ -1225,7 +1225,7 @@ public class BinaryJedis implements BinaryJedisCommands { } /** - * Move the specifided member from the set at srckey to the set at dstkey. + * Move the specified member from the set at srckey to the set at dstkey. * This operation is atomic, in every given moment the element will appear * to be in the source or destination set for accessing clients. *

@@ -1289,10 +1289,10 @@ public class BinaryJedis implements BinaryJedisCommands { /** * Return the members of a set resulting from the intersection of all the * sets hold at the specified keys. Like in - * {@link #lrange(String, int, int) LRANGE} the result is sent to the client + * {@link #lrange(byte[], int, int) LRANGE} the result is sent to the client * as a multi-bulk reply (see the protocol specification for more * information). If just a single key is specified, then this command - * produces the same result as {@link #smembers(String) SMEMBERS}. Actually + * produces the same result as {@link #smembers(byte[]) SMEMBERS}. Actually * SMEMBERS is just syntax sugar for SINTER. *

* Non existing keys are considered like empty sets, so if one of the keys @@ -1331,10 +1331,10 @@ public class BinaryJedis implements BinaryJedisCommands { /** * Return the members of a set resulting from the union of all the sets hold - * at the specified keys. Like in {@link #lrange(String, int, int) LRANGE} + * at the specified keys. Like in {@link #lrange(byte[], int, int) LRANGE} * the result is sent to the client as a multi-bulk reply (see the protocol * specification for more information). If just a single key is specified, - * then this command produces the same result as {@link #smembers(String) + * then this command produces the same result as {@link #smembers(byte[]) * SMEMBERS}. *

* Non existing keys are considered like empty sets. @@ -1531,7 +1531,7 @@ public class BinaryJedis implements BinaryJedisCommands { *

* O(log(N)) * - * @see #zrevrank(String, String) + * @see #zrevrank(byte[], byte[]) * * @param key * @param member @@ -1557,7 +1557,7 @@ public class BinaryJedis implements BinaryJedisCommands { *

* O(log(N)) * - * @see #zrank(String, String) + * @see #zrank(byte[], byte[]) * * @param key * @param member @@ -1678,9 +1678,9 @@ public class BinaryJedis implements BinaryJedisCommands { * By default sorting is numeric with elements being compared as double * precision floating point numbers. This is the simplest form of SORT. * - * @see #sort(String, String) - * @see #sort(String, SortingParams) - * @see #sort(String, SortingParams, String) + * @see #sort(byte[], byte[]) + * @see #sort(byte[], SortingParams) + * @see #sort(byte[], SortingParams, byte[]) * * * @param key @@ -1763,8 +1763,8 @@ public class BinaryJedis implements BinaryJedisCommands { * -> [3, x, 2, y, 1, z] * * - * @see #sort(String) - * @see #sort(String, SortingParams, String) + * @see #sort(byte[]) + * @see #sort(byte[], SortingParams, byte[]) * * @param key * @param sortingParameters @@ -1868,9 +1868,9 @@ public class BinaryJedis implements BinaryJedisCommands { * Sort a Set or a List accordingly to the specified parameters and store * the result at dstkey. * - * @see #sort(String, SortingParams) - * @see #sort(String) - * @see #sort(String, String) + * @see #sort(byte[], SortingParams) + * @see #sort(byte[]) + * @see #sort(byte[], byte[]) * * @param key * @param sortingParameters @@ -1892,9 +1892,9 @@ public class BinaryJedis implements BinaryJedisCommands { * elements being compared as double precision floating point numbers. This * is the simplest form of SORT. * - * @see #sort(String) - * @see #sort(String, SortingParams) - * @see #sort(String, SortingParams, String) + * @see #sort(byte[]) + * @see #sort(byte[], SortingParams) + * @see #sort(byte[], SortingParams, byte[]) * * @param key * @param dstkey @@ -2070,13 +2070,13 @@ public class BinaryJedis implements BinaryJedisCommands { * does not involve further computation). *

* Using the optional - * {@link #zrangeByScore(String, double, double, int, int) LIMIT} it's + * {@link #zrangeByScore(byte[], double, double, int, int) LIMIT} it's * possible to get only a range of the matching elements in an SQL-alike * way. Note that if offset is large the commands needs to traverse the list * for offset elements and this adds up to the O(M) figure. *

- * The {@link #zcount(String, double, double) ZCOUNT} command is similar to - * {@link #zrangeByScore(String, double, double) ZRANGEBYSCORE} but instead + * The {@link #zcount(byte[], double, double) ZCOUNT} command is similar to + * {@link #zrangeByScore(byte[], double, double) ZRANGEBYSCORE} but instead * of returning the actual elements in the specified interval, it just * returns the number of matching elements. *

@@ -2105,12 +2105,11 @@ public class BinaryJedis implements BinaryJedisCommands { * (for instance you always ask for the first ten elements with LIMIT) you * can consider it O(log(N)) * - * @see #zrangeByScore(String, double, double) - * @see #zrangeByScore(String, double, double, int, int) - * @see #zrangeByScoreWithScores(String, double, double) - * @see #zrangeByScoreWithScores(String, String, String) - * @see #zrangeByScoreWithScores(String, double, double, int, int) - * @see #zcount(String, double, double) + * @see #zrangeByScore(byte[], double, double) + * @see #zrangeByScore(byte[], double, double, int, int) + * @see #zrangeByScoreWithScores(byte[], double, double) + * @see #zrangeByScoreWithScores(byte[], double, double, int, int) + * @see #zcount(byte[], double, double) * * @param key * @param min @@ -2141,13 +2140,13 @@ public class BinaryJedis implements BinaryJedisCommands { * does not involve further computation). *

* Using the optional - * {@link #zrangeByScore(String, double, double, int, int) LIMIT} it's + * {@link #zrangeByScore(byte[], double, double, int, int) LIMIT} it's * possible to get only a range of the matching elements in an SQL-alike * way. Note that if offset is large the commands needs to traverse the list * for offset elements and this adds up to the O(M) figure. *

- * The {@link #zcount(String, double, double) ZCOUNT} command is similar to - * {@link #zrangeByScore(String, double, double) ZRANGEBYSCORE} but instead + * The {@link #zcount(byte[], double, double) ZCOUNT} command is similar to + * {@link #zrangeByScore(byte[], double, double) ZRANGEBYSCORE} but instead * of returning the actual elements in the specified interval, it just * returns the number of matching elements. *

@@ -2176,11 +2175,11 @@ public class BinaryJedis implements BinaryJedisCommands { * (for instance you always ask for the first ten elements with LIMIT) you * can consider it O(log(N)) * - * @see #zrangeByScore(String, double, double) - * @see #zrangeByScore(String, double, double, int, int) - * @see #zrangeByScoreWithScores(String, double, double) - * @see #zrangeByScoreWithScores(String, double, double, int, int) - * @see #zcount(String, double, double) + * @see #zrangeByScore(byte[], double, double) + * @see #zrangeByScore(byte[], double, double, int, int) + * @see #zrangeByScoreWithScores(byte[], double, double) + * @see #zrangeByScoreWithScores(byte[], double, double, int, int) + * @see #zcount(byte[], double, double) * * @param key * @param min @@ -2204,13 +2203,13 @@ public class BinaryJedis implements BinaryJedisCommands { * does not involve further computation). *

* Using the optional - * {@link #zrangeByScore(String, double, double, int, int) LIMIT} it's + * {@link #zrangeByScore(byte[], double, double, int, int) LIMIT} it's * possible to get only a range of the matching elements in an SQL-alike * way. Note that if offset is large the commands needs to traverse the list * for offset elements and this adds up to the O(M) figure. *

- * The {@link #zcount(String, double, double) ZCOUNT} command is similar to - * {@link #zrangeByScore(String, double, double) ZRANGEBYSCORE} but instead + * The {@link #zcount(byte[], double, double) ZCOUNT} command is similar to + * {@link #zrangeByScore(byte[], double, double) ZRANGEBYSCORE} but instead * of returning the actual elements in the specified interval, it just * returns the number of matching elements. *

@@ -2239,11 +2238,11 @@ public class BinaryJedis implements BinaryJedisCommands { * (for instance you always ask for the first ten elements with LIMIT) you * can consider it O(log(N)) * - * @see #zrangeByScore(String, double, double) - * @see #zrangeByScore(String, double, double, int, int) - * @see #zrangeByScoreWithScores(String, double, double) - * @see #zrangeByScoreWithScores(String, double, double, int, int) - * @see #zcount(String, double, double) + * @see #zrangeByScore(byte[], double, double) + * @see #zrangeByScore(byte[], double, double, int, int) + * @see #zrangeByScoreWithScores(byte[], double, double) + * @see #zrangeByScoreWithScores(byte[], double, double, int, int) + * @see #zcount(byte[], double, double) * * @param key * @param min @@ -2268,13 +2267,13 @@ public class BinaryJedis implements BinaryJedisCommands { * does not involve further computation). *

* Using the optional - * {@link #zrangeByScore(String, double, double, int, int) LIMIT} it's + * {@link #zrangeByScore(byte[], double, double, int, int) LIMIT} it's * possible to get only a range of the matching elements in an SQL-alike * way. Note that if offset is large the commands needs to traverse the list * for offset elements and this adds up to the O(M) figure. *

- * The {@link #zcount(String, double, double) ZCOUNT} command is similar to - * {@link #zrangeByScore(String, double, double) ZRANGEBYSCORE} but instead + * The {@link #zcount(byte[], double, double) ZCOUNT} command is similar to + * {@link #zrangeByScore(byte[], double, double) ZRANGEBYSCORE} but instead * of returning the actual elements in the specified interval, it just * returns the number of matching elements. *

@@ -2303,11 +2302,11 @@ public class BinaryJedis implements BinaryJedisCommands { * (for instance you always ask for the first ten elements with LIMIT) you * can consider it O(log(N)) * - * @see #zrangeByScore(String, double, double) - * @see #zrangeByScore(String, double, double, int, int) - * @see #zrangeByScoreWithScores(String, double, double) - * @see #zrangeByScoreWithScores(String, double, double, int, int) - * @see #zcount(String, double, double) + * @see #zrangeByScore(byte[], double, double) + * @see #zrangeByScore(byte[], double, double, int, int) + * @see #zrangeByScoreWithScores(byte[], double, double) + * @see #zrangeByScoreWithScores(byte[], double, double, int, int) + * @see #zcount(byte[], double, double) * * @param key * @param min @@ -2896,7 +2895,7 @@ public class BinaryJedis implements BinaryJedisCommands { } /** - * Undo a {@link #expire(String, int) expire} at turning the expire key into + * Undo a {@link #expire(byte[], int) expire} at turning the expire key into * a normal key. *

* Time complexity: O(1) From 3abaf71e0a4255294985c1a358d4dd7a3b387262 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 29 Jun 2011 09:34:57 -0700 Subject: [PATCH 009/112] Mark inner classes static that don't reference parent class. --- src/main/java/redis/clients/jedis/ShardedJedisPipeline.java | 2 +- src/main/java/redis/clients/util/JedisByteHashMap.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java index 544ce73..913c6c5 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java +++ b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java @@ -10,7 +10,7 @@ public abstract class ShardedJedisPipeline { private BinaryShardedJedis jedis; private List results = new ArrayList(); - private class FutureResult { + private static class FutureResult { private Client client; public FutureResult(Client client) { diff --git a/src/main/java/redis/clients/util/JedisByteHashMap.java b/src/main/java/redis/clients/util/JedisByteHashMap.java index d9c7866..e13f3b0 100644 --- a/src/main/java/redis/clients/util/JedisByteHashMap.java +++ b/src/main/java/redis/clients/util/JedisByteHashMap.java @@ -88,7 +88,7 @@ public class JedisByteHashMap implements Map, Cloneable, return internalMap.values(); } - private final class ByteArrayWrapper { + private static final class ByteArrayWrapper { private final byte[] data; public ByteArrayWrapper(byte[] data) { @@ -110,7 +110,7 @@ public class JedisByteHashMap implements Map, Cloneable, } } - private final class JedisByteEntry implements Entry { + private static final class JedisByteEntry implements Entry { private byte[] value; private byte[] key; From 22d4d3fc535890d1ca3c0ba400191ee0efbfe009 Mon Sep 17 00:00:00 2001 From: Vladimir Soskov Date: Sun, 31 Jul 2011 19:50:16 -0700 Subject: [PATCH 010/112] fixing Issue 188 --- .../clients/jedis/BinaryTransaction.java | 22 +++++++++++- .../java/redis/clients/jedis/Connection.java | 7 +++- .../java/redis/clients/jedis/Protocol.java | 6 +++- .../java/redis/clients/jedis/Response.java | 3 ++ .../clients/jedis/tests/PipeliningTest.java | 16 +++++++++ .../commands/TransactionCommandsTest.java | 36 +++++++++++++++++++ 6 files changed, 87 insertions(+), 3 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryTransaction.java b/src/main/java/redis/clients/jedis/BinaryTransaction.java index 7f50a68..35c500e 100644 --- a/src/main/java/redis/clients/jedis/BinaryTransaction.java +++ b/src/main/java/redis/clients/jedis/BinaryTransaction.java @@ -6,6 +6,7 @@ import java.util.Map; import java.util.Set; import redis.clients.jedis.BinaryClient.LIST_POSITION; +import redis.clients.jedis.exceptions.JedisDataException; public class BinaryTransaction extends Queable { protected Client client = null; @@ -28,10 +29,29 @@ public class BinaryTransaction extends Queable { } List formatted = new ArrayList(); for (Object o : unformatted) { - formatted.add(generateResponse(o).get()); + try{ + formatted.add(generateResponse(o).get()); + }catch(JedisDataException e){ + formatted.add(e); + } } return formatted; } + + public List> execGetResponse() { + client.exec(); + client.getAll(1); // Discard all but the last reply + + List unformatted = client.getObjectMultiBulkReply(); + if (unformatted == null) { + return null; + } + List> response = new ArrayList>(); + for (Object o : unformatted) { + response.add(generateResponse(o)); + } + return response; + } public String discard() { client.discard(); diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index be5e664..abf0e99 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -9,6 +9,7 @@ import java.util.List; import redis.clients.jedis.Protocol.Command; import redis.clients.jedis.exceptions.JedisConnectionException; +import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.exceptions.JedisException; import redis.clients.util.RedisInputStream; import redis.clients.util.RedisOutputStream; @@ -204,7 +205,11 @@ public class Connection { List all = new ArrayList(); flush(); while (pipelinedCommands > except) { - all.add(protocol.read(inputStream)); + try{ + all.add(protocol.read(inputStream)); + }catch(JedisDataException e){ + all.add(e); + } pipelinedCommands--; } return all; diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index c2ad2b5..1b5b130 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -113,7 +113,11 @@ public final class Protocol { } List ret = new ArrayList(num); for (int i = 0; i < num; i++) { - ret.add(process(is)); + try{ + ret.add(process(is)); + }catch(JedisDataException e){ + ret.add(e); + } } return ret; } diff --git a/src/main/java/redis/clients/jedis/Response.java b/src/main/java/redis/clients/jedis/Response.java index 062e97d..a662c10 100644 --- a/src/main/java/redis/clients/jedis/Response.java +++ b/src/main/java/redis/clients/jedis/Response.java @@ -24,6 +24,9 @@ public class Response { "Please close pipeline or multi block before calling this method."); } if (!built) { + if (data instanceof JedisDataException){ + throw new JedisDataException((JedisDataException)data); + } response = builder.build(data); this.data = null; built = true; diff --git a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java index 82d28a4..2a409d3 100644 --- a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java +++ b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java @@ -118,4 +118,20 @@ public class PipeliningTest extends Assert { p.sync(); assertNull(shouldNotExist.get()); } + + @Test + public void piplineWithError(){ + Pipeline p = jedis.pipelined(); + p.set("foo", "bar"); + Response> error = p.smembers("foo"); + Response r = p.get("foo"); + p.sync(); + try{ + error.get(); + fail(); + }catch(JedisDataException e){ + //that is fine we should be here + } + assertEquals(r.get(), "bar"); + } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java index f7d8d4d..f123a4a 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java @@ -11,6 +11,7 @@ import org.junit.Before; import org.junit.Test; import redis.clients.jedis.Jedis; +import redis.clients.jedis.Pipeline; import redis.clients.jedis.Response; import redis.clients.jedis.Transaction; import redis.clients.jedis.TransactionBlock; @@ -241,4 +242,39 @@ public class TransactionCommandsTest extends JedisCommandTestBase { string.get(); t.exec(); } + + @Test + public void transactionResponseWithError() { + Transaction t = jedis.multi(); + t.set("foo", "bar"); + Response> error = t.smembers("foo"); + Response r = t.get("foo"); + List l = t.exec(); + assertEquals(JedisDataException.class, l.get(1).getClass()); + try{ + error.get(); + fail("We expect exception here!"); + }catch(JedisDataException e){ + //that is fine we should be here + } + assertEquals(r.get(), "bar"); + } + + @Test + public void execGetResponse() { + Transaction t = jedis.multi(); + + t.set("foo", "bar"); + t.smembers("foo"); + t.get("foo"); + + List> lr = t.execGetResponse(); + try{ + lr.get(1).get(); + fail("We expect exception here!"); + }catch(JedisDataException e){ + //that is fine we should be here + } + assertEquals("bar", lr.get(2).get()); + } } \ No newline at end of file From ec0b58e1836355d78d2649719c3cbc51579aaacc Mon Sep 17 00:00:00 2001 From: Vladimir Soskov Date: Sun, 31 Jul 2011 20:28:51 -0700 Subject: [PATCH 011/112] fixing Issue 188 - Pipline.syncAndReturnAll changes --- src/main/java/redis/clients/jedis/Pipeline.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index 20aa9e5..8cbad9a 100644 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -6,6 +6,7 @@ import java.util.Map; import java.util.Set; import redis.clients.jedis.BinaryClient.LIST_POSITION; +import redis.clients.jedis.exceptions.JedisDataException; public class Pipeline extends Queable { private Client client; @@ -39,7 +40,11 @@ public class Pipeline extends Queable { List unformatted = client.getAll(); List formatted = new ArrayList(); for (Object o : unformatted) { - formatted.add(generateResponse(o).get()); + try{ + formatted.add(generateResponse(o).get()); + }catch(JedisDataException e){ + formatted.add(e); + } } return formatted; } From 0aab8cb63b85599db1ad76b3b9486fac9980df2d Mon Sep 17 00:00:00 2001 From: Justin Sanders Date: Tue, 16 Aug 2011 11:15:07 -0400 Subject: [PATCH 012/112] Fixed comments in exists, return values were incorrect --- src/main/java/redis/clients/jedis/BinaryJedis.java | 6 +++--- src/main/java/redis/clients/jedis/Jedis.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 6b6c626..48f76db 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -84,8 +84,8 @@ public class BinaryJedis implements BinaryJedisCommands { } /** - * Test if the specified key exists. The command returns "0" if the key - * exists, otherwise "1" is returned. Note that even keys set with an empty + * Test if the specified key exists. The command returns "1" if the key + * exists, otherwise "0" is returned. Note that even keys set with an empty * string as value will return "1". * * Time complexity: O(1) @@ -3007,4 +3007,4 @@ public class BinaryJedis implements BinaryJedisCommands { public Long getDB() { return client.getDB(); } -} \ No newline at end of file +} diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 497277d..936ee4f 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -77,8 +77,8 @@ public class Jedis extends BinaryJedis implements JedisCommands { /** * Test if the specified key exists. The command returns "1" if the key - * exists, otherwise "1" is returned. Note that even keys set with an empty - * string as value will return "0". + * exists, otherwise "0" is returned. Note that even keys set with an empty + * string as value will return "1". * * Time complexity: O(1) * From fb33b262e499a0d50364ead9f75255e841c02634 Mon Sep 17 00:00:00 2001 From: Michael Cameron Date: Fri, 26 Aug 2011 16:47:37 -0500 Subject: [PATCH 013/112] Add ability to specify database number in pool config --- .../java/redis/clients/jedis/JedisPool.java | 34 +++++++++++-------- .../java/redis/clients/jedis/Protocol.java | 1 + .../clients/jedis/tests/JedisPoolTest.java | 18 ++++++++++ 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/main/java/redis/clients/jedis/JedisPool.java b/src/main/java/redis/clients/jedis/JedisPool.java index 0f4fe4b..55ca94f 100644 --- a/src/main/java/redis/clients/jedis/JedisPool.java +++ b/src/main/java/redis/clients/jedis/JedisPool.java @@ -8,30 +8,30 @@ import redis.clients.util.Pool; public class JedisPool extends Pool { - public JedisPool(final GenericObjectPool.Config poolConfig, - final String host) { - this(poolConfig, host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, - null); + public JedisPool(final Config poolConfig, final String host) { + this(poolConfig, host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE); } public JedisPool(String host, int port) { - super(new Config(), new JedisFactory(host, port, - Protocol.DEFAULT_TIMEOUT, null)); + this(new Config(), host, port, Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE); } public JedisPool(final Config poolConfig, final String host, int port, int timeout, final String password) { - super(poolConfig, new JedisFactory(host, port, timeout, password)); + this(poolConfig, host, port, timeout, password, Protocol.DEFAULT_DATABASE); } - public JedisPool(final GenericObjectPool.Config poolConfig, - final String host, final int port) { - this(poolConfig, host, port, Protocol.DEFAULT_TIMEOUT, null); + public JedisPool(final Config poolConfig, final String host, final int port) { + this(poolConfig, host, port, Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE); } - public JedisPool(final GenericObjectPool.Config poolConfig, - final String host, final int port, final int timeout) { - this(poolConfig, host, port, timeout, null); + public JedisPool(final Config poolConfig, final String host, final int port, final int timeout) { + this(poolConfig, host, port, timeout, null, Protocol.DEFAULT_DATABASE); + } + + public JedisPool(final Config poolConfig, final String host, int port, int timeout, final String password, + final int database) { + super(poolConfig, new JedisFactory(host, port, timeout, password, database)); } /** @@ -42,14 +42,16 @@ public class JedisPool extends Pool { private final int port; private final int timeout; private final String password; + private final int database; public JedisFactory(final String host, final int port, - final int timeout, final String password) { + final int timeout, final String password, final int database) { super(); this.host = host; this.port = port; this.timeout = timeout; this.password = password; + this.database = database; } public Object makeObject() throws Exception { @@ -59,6 +61,10 @@ public class JedisPool extends Pool { if (null != this.password) { jedis.auth(this.password); } + if( database != 0 ) { + jedis.select(database); + } + return jedis; } diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index c2ad2b5..40f4f6b 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -14,6 +14,7 @@ public final class Protocol { public static final int DEFAULT_PORT = 6379; public static final int DEFAULT_TIMEOUT = 2000; + public static final int DEFAULT_DATABASE = 0; public static final String CHARSET = "UTF-8"; diff --git a/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java b/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java index 158adbf..5fd76fe 100644 --- a/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java +++ b/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java @@ -95,4 +95,22 @@ public class JedisPoolTest extends Assert { pool.returnResource(jedis); pool.destroy(); } + + @Test + public void nonDefaultDatabase() { + JedisPool pool0 = new JedisPool(new JedisPoolConfig(), hnp.host, + hnp.port, 2000, "foobared"); + Jedis jedis0 = pool0.getResource(); + jedis0.set("foo", "bar"); + assertEquals( "bar", jedis0.get("foo") ); + pool0.returnResource(jedis0); + pool0.destroy(); + + JedisPool pool1 = new JedisPool(new JedisPoolConfig(), hnp.host, + hnp.port, 2000, "foobared", 1); + Jedis jedis1 = pool1.getResource(); + assertNull( jedis1.get("foo") ); + pool1.returnResource(jedis0); + pool1.destroy(); + } } \ No newline at end of file From 420192ba0512bb29aa3a63f0e8a4cf927782b34b Mon Sep 17 00:00:00 2001 From: Eric Hauser Date: Sat, 10 Sep 2011 00:57:58 -0400 Subject: [PATCH 014/112] adding intellij generated files to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index e917613..cf63247 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ .classpath +*.iml +*.ipr +*.iws .project .settings/ .gradle/ From b178e25d3793a225746b060107dcf0050d270f50 Mon Sep 17 00:00:00 2001 From: Eric Hauser Date: Mon, 12 Sep 2011 22:38:39 -0400 Subject: [PATCH 015/112] ignoring broken test until jonathon can comment on the correct logic --- .../jedis/tests/commands/PublishSubscribeCommandsTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/redis/clients/jedis/tests/commands/PublishSubscribeCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/PublishSubscribeCommandsTest.java index 39f8465..f2ebb4c 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/PublishSubscribeCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/PublishSubscribeCommandsTest.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.net.UnknownHostException; import java.util.Arrays; +import org.junit.Ignore; import org.junit.Test; import redis.clients.jedis.BinaryJedisPubSub; @@ -503,7 +504,7 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase { } } - @Test(expected = JedisConnectionException.class) + @Test(expected = JedisConnectionException.class) @Ignore public void unsubscribeWhenNotSusbscribed() throws InterruptedException { JedisPubSub pubsub = new JedisPubSub() { public void onMessage(String channel, String message) { @@ -527,4 +528,4 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase { }; pubsub.unsubscribe(); } -} \ No newline at end of file +} From a688c610ae6d4927e9778833921950b7c04ff01a Mon Sep 17 00:00:00 2001 From: wjw465150 Date: Tue, 30 Aug 2011 17:23:49 +0800 Subject: [PATCH 016/112] wjw465150 add socket performance --- src/main/java/redis/clients/jedis/Connection.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index be5e664..64e8de9 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -116,6 +116,13 @@ public class Connection { if (!isConnected()) { try { socket = new Socket(); + //->@wjw_add + socket.setReuseAddress(true); + socket.setKeepAlive(true); //Will monitor the TCP connection is valid + socket.setTcpNoDelay(true); //Socket buffer Whetherclosed, to ensure timely delivery of data + socket.setSoLinger(true,0); //Control calls close () method, the underlying socket is closed immediately + //<-@wjw_add + socket.connect(new InetSocketAddress(host, port), timeout); socket.setSoTimeout(timeout); outputStream = new RedisOutputStream(socket.getOutputStream()); From a9ef10bb00404164e5c348389a14e30f3eaea1a0 Mon Sep 17 00:00:00 2001 From: Eric Hauser Date: Mon, 12 Sep 2011 22:48:58 -0400 Subject: [PATCH 017/112] fix ignore that was placed on wrong test --- .../jedis/tests/commands/PublishSubscribeCommandsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/redis/clients/jedis/tests/commands/PublishSubscribeCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/PublishSubscribeCommandsTest.java index f2ebb4c..c7a94f4 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/PublishSubscribeCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/PublishSubscribeCommandsTest.java @@ -472,7 +472,7 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase { t.join(); } - @Test + @Test @Ignore public void subscribeWithoutConnecting() { try { Jedis jedis = new Jedis(hnp.host, hnp.port); @@ -504,7 +504,7 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase { } } - @Test(expected = JedisConnectionException.class) @Ignore + @Test(expected = JedisConnectionException.class) public void unsubscribeWhenNotSusbscribed() throws InterruptedException { JedisPubSub pubsub = new JedisPubSub() { public void onMessage(String channel, String message) { From fd0c57599ce0020cb1256a44d64dbe6a7509158c Mon Sep 17 00:00:00 2001 From: Yaourt Date: Fri, 16 Sep 2011 17:22:59 +0200 Subject: [PATCH 018/112] Fix broken test due to missing authent --- .../clients/jedis/tests/SharedJedisPipelineTest.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/test/java/redis/clients/jedis/tests/SharedJedisPipelineTest.java b/src/test/java/redis/clients/jedis/tests/SharedJedisPipelineTest.java index 7ca2a52..20f5094 100644 --- a/src/test/java/redis/clients/jedis/tests/SharedJedisPipelineTest.java +++ b/src/test/java/redis/clients/jedis/tests/SharedJedisPipelineTest.java @@ -24,18 +24,25 @@ public class SharedJedisPipelineTest { @Before public void setUp() throws Exception { Jedis jedis = new Jedis(redis1.host, redis1.port); + jedis.auth("foobared"); jedis.flushAll(); jedis.disconnect(); jedis = new Jedis(redis2.host, redis2.port); + jedis.auth("foobared"); jedis.flushAll(); jedis.disconnect(); List shards = new ArrayList(); - shards.add(new JedisShardInfo(redis1.host, redis1.port)); - shards.add(new JedisShardInfo(redis2.host, redis2.port)); + JedisShardInfo si1 = new JedisShardInfo(redis1.host, redis1.port); + si1.setPassword("foobared"); + shards.add(si1); + JedisShardInfo si2 = new JedisShardInfo(redis2.host, redis2.port); + si2.setPassword("foobared"); + shards.add(si2); this.jedis = new ShardedJedis(shards); } + @Test public void pipeline() throws UnsupportedEncodingException { ShardedJedisPipeline p = jedis.pipelined(); From dcba7bd3b34fa221b867ae8b6e4e051a9d36dc90 Mon Sep 17 00:00:00 2001 From: Yaourt Date: Fri, 16 Sep 2011 17:23:59 +0200 Subject: [PATCH 019/112] Rename test : Shar<>edJedisPipelineTest to ShardedJedisPipelineTest --- ...SharedJedisPipelineTest.java => ShardedJedisPipelineTest.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/test/java/redis/clients/jedis/tests/{SharedJedisPipelineTest.java => ShardedJedisPipelineTest.java} (100%) diff --git a/src/test/java/redis/clients/jedis/tests/SharedJedisPipelineTest.java b/src/test/java/redis/clients/jedis/tests/ShardedJedisPipelineTest.java similarity index 100% rename from src/test/java/redis/clients/jedis/tests/SharedJedisPipelineTest.java rename to src/test/java/redis/clients/jedis/tests/ShardedJedisPipelineTest.java From f82fb50897ed5f1391fda0a85256254a7cd56d13 Mon Sep 17 00:00:00 2001 From: Yaourt Date: Fri, 16 Sep 2011 22:40:39 +0200 Subject: [PATCH 020/112] Update ShardedJedisPipelineTest class name. --- .../redis/clients/jedis/tests/ShardedJedisPipelineTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/redis/clients/jedis/tests/ShardedJedisPipelineTest.java b/src/test/java/redis/clients/jedis/tests/ShardedJedisPipelineTest.java index 20f5094..22f1d10 100644 --- a/src/test/java/redis/clients/jedis/tests/ShardedJedisPipelineTest.java +++ b/src/test/java/redis/clients/jedis/tests/ShardedJedisPipelineTest.java @@ -13,7 +13,7 @@ import static junit.framework.Assert.assertNull; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -public class SharedJedisPipelineTest { +public class ShardedJedisPipelineTest { private static HostAndPortUtil.HostAndPort redis1 = HostAndPortUtil.getRedisServers() .get(0); private static HostAndPortUtil.HostAndPort redis2 = HostAndPortUtil.getRedisServers() From 9d4d11ef466d7a890e763bb1b98b044e3d8635b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istva=CC=81n?= Date: Mon, 26 Sep 2011 15:37:15 +0200 Subject: [PATCH 021/112] no need to instantiate the Protocol class that can be static --- .../java/redis/clients/jedis/Connection.java | 21 ++++++++-------- .../java/redis/clients/jedis/Protocol.java | 24 ++++++++++++------- .../clients/jedis/tests/ProtocolTest.java | 24 +++++++------------ 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index 0ea973f..c533301 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -19,7 +19,6 @@ public class Connection { private String host; private int port = Protocol.DEFAULT_PORT; private Socket socket; - private Protocol protocol = new Protocol(); private RedisOutputStream outputStream; private RedisInputStream inputStream; private int pipelinedCommands = 0; @@ -78,14 +77,14 @@ public class Connection { protected Connection sendCommand(final Command cmd, final byte[]... args) { connect(); - protocol.sendCommand(outputStream, cmd, args); + Protocol.sendCommand(outputStream, cmd, args); pipelinedCommands++; return this; } protected Connection sendCommand(final Command cmd) { connect(); - protocol.sendCommand(outputStream, cmd, new byte[0][]); + Protocol.sendCommand(outputStream, cmd, new byte[0][]); pipelinedCommands++; return this; } @@ -125,7 +124,7 @@ public class Connection { socket.setTcpNoDelay(true); //Socket buffer Whetherclosed, to ensure timely delivery of data socket.setSoLinger(true,0); //Control calls close () method, the underlying socket is closed immediately //<-@wjw_add - + socket.connect(new InetSocketAddress(host, port), timeout); socket.setSoTimeout(timeout); outputStream = new RedisOutputStream(socket.getOutputStream()); @@ -159,7 +158,7 @@ public class Connection { protected String getStatusCodeReply() { flush(); pipelinedCommands--; - final byte[] resp = (byte[]) protocol.read(inputStream); + final byte[] resp = (byte[]) Protocol.read(inputStream); if (null == resp) { return null; } else { @@ -179,13 +178,13 @@ public class Connection { public byte[] getBinaryBulkReply() { flush(); pipelinedCommands--; - return (byte[]) protocol.read(inputStream); + return (byte[]) Protocol.read(inputStream); } public Long getIntegerReply() { flush(); pipelinedCommands--; - return (Long) protocol.read(inputStream); + return (Long) Protocol.read(inputStream); } public List getMultiBulkReply() { @@ -196,14 +195,14 @@ public class Connection { public List getBinaryMultiBulkReply() { flush(); pipelinedCommands--; - return (List) protocol.read(inputStream); + return (List) Protocol.read(inputStream); } @SuppressWarnings("unchecked") public List getObjectMultiBulkReply() { flush(); pipelinedCommands--; - return (List) protocol.read(inputStream); + return (List) Protocol.read(inputStream); } public List getAll() { @@ -215,7 +214,7 @@ public class Connection { flush(); while (pipelinedCommands > except) { try{ - all.add(protocol.read(inputStream)); + all.add(Protocol.read(inputStream)); }catch(JedisDataException e){ all.add(e); } @@ -227,6 +226,6 @@ public class Connection { public Object getOne() { flush(); pipelinedCommands--; - return protocol.read(inputStream); + return Protocol.read(inputStream); } } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index a4f1c7e..d64eecd 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -24,12 +24,18 @@ public final class Protocol { public static final byte MINUS_BYTE = '-'; public static final byte COLON_BYTE = ':'; - public void sendCommand(final RedisOutputStream os, final Command command, + private Protocol() { + // this prevent the class from instantiation + } + + public static void sendCommand(final RedisOutputStream os, + final Command command, final byte[]... args) { sendCommand(os, command.raw, args); } - private void sendCommand(final RedisOutputStream os, final byte[] command, + private static void sendCommand(final RedisOutputStream os, + final byte[] command, final byte[]... args) { try { os.write(ASTERISK_BYTE); @@ -50,12 +56,12 @@ public final class Protocol { } } - private void processError(final RedisInputStream is) { + private static void processError(final RedisInputStream is) { String message = is.readLine(); throw new JedisDataException(message); } - private Object process(final RedisInputStream is) { + private static Object process(final RedisInputStream is) { try { byte b = is.readByte(); if (b == MINUS_BYTE) { @@ -77,11 +83,11 @@ public final class Protocol { return null; } - private byte[] processStatusCodeReply(final RedisInputStream is) { + private static byte[] processStatusCodeReply(final RedisInputStream is) { return SafeEncoder.encode(is.readLine()); } - private byte[] processBulkReply(final RedisInputStream is) { + private static byte[] processBulkReply(final RedisInputStream is) { int len = Integer.parseInt(is.readLine()); if (len == -1) { return null; @@ -102,12 +108,12 @@ public final class Protocol { return read; } - private Long processInteger(final RedisInputStream is) { + private static Long processInteger(final RedisInputStream is) { String num = is.readLine(); return Long.valueOf(num); } - private List processMultiBulkReply(final RedisInputStream is) { + private static List processMultiBulkReply(final RedisInputStream is) { int num = Integer.parseInt(is.readLine()); if (num == -1) { return null; @@ -123,7 +129,7 @@ public final class Protocol { return ret; } - public Object read(final RedisInputStream is) { + public static Object read(final RedisInputStream is) { return process(is); } diff --git a/src/test/java/redis/clients/jedis/tests/ProtocolTest.java b/src/test/java/redis/clients/jedis/tests/ProtocolTest.java index e0b9fb1..60b82aa 100644 --- a/src/test/java/redis/clients/jedis/tests/ProtocolTest.java +++ b/src/test/java/redis/clients/jedis/tests/ProtocolTest.java @@ -24,8 +24,7 @@ public class ProtocolTest extends JedisTestBase { PipedOutputStream pos = new PipedOutputStream(pis); RedisOutputStream ros = new RedisOutputStream(pos); - Protocol protocol = new Protocol(); - protocol.sendCommand(ros, Protocol.Command.GET, + Protocol.sendCommand(ros, Protocol.Command.GET, "SOMEKEY".getBytes(Protocol.CHARSET)); ros.flush(); pos.close(); @@ -43,8 +42,7 @@ public class ProtocolTest extends JedisTestBase { @Test public void bulkReply() { InputStream is = new ByteArrayInputStream("$6\r\nfoobar\r\n".getBytes()); - Protocol protocol = new Protocol(); - byte[] response = (byte[]) protocol.read(new RedisInputStream(is)); + byte[] response = (byte[]) Protocol.read(new RedisInputStream(is)); assertArrayEquals(SafeEncoder.encode("foobar"), response); } @@ -52,8 +50,7 @@ public class ProtocolTest extends JedisTestBase { public void fragmentedBulkReply() { FragmentedByteArrayInputStream fis = new FragmentedByteArrayInputStream( "$30\r\n012345678901234567890123456789\r\n".getBytes()); - Protocol protocol = new Protocol(); - byte[] response = (byte[]) protocol.read(new RedisInputStream(fis)); + byte[] response = (byte[]) Protocol.read(new RedisInputStream(fis)); assertArrayEquals(SafeEncoder.encode("012345678901234567890123456789"), response); } @@ -61,24 +58,21 @@ public class ProtocolTest extends JedisTestBase { @Test public void nullBulkReply() { InputStream is = new ByteArrayInputStream("$-1\r\n".getBytes()); - Protocol protocol = new Protocol(); - String response = (String) protocol.read(new RedisInputStream(is)); + String response = (String) Protocol.read(new RedisInputStream(is)); assertEquals(null, response); } @Test public void singleLineReply() { InputStream is = new ByteArrayInputStream("+OK\r\n".getBytes()); - Protocol protocol = new Protocol(); - byte[] response = (byte[]) protocol.read(new RedisInputStream(is)); + byte[] response = (byte[]) Protocol.read(new RedisInputStream(is)); assertArrayEquals(SafeEncoder.encode("OK"), response); } @Test public void integerReply() { InputStream is = new ByteArrayInputStream(":123\r\n".getBytes()); - Protocol protocol = new Protocol(); - long response = (Long) protocol.read(new RedisInputStream(is)); + long response = (Long) Protocol.read(new RedisInputStream(is)); assertEquals(123, response); } @@ -88,8 +82,7 @@ public class ProtocolTest extends JedisTestBase { InputStream is = new ByteArrayInputStream( "*4\r\n$3\r\nfoo\r\n$3\r\nbar\r\n$5\r\nHello\r\n$5\r\nWorld\r\n" .getBytes()); - Protocol protocol = new Protocol(); - List response = (List) protocol + List response = (List) Protocol .read(new RedisInputStream(is)); List expected = new ArrayList(); expected.add(SafeEncoder.encode("foo")); @@ -104,8 +97,7 @@ public class ProtocolTest extends JedisTestBase { @Test public void nullMultiBulkReply() { InputStream is = new ByteArrayInputStream("*-1\r\n".getBytes()); - Protocol protocol = new Protocol(); - List response = (List) protocol + List response = (List) Protocol .read(new RedisInputStream(is)); assertNull(response); } From 04f603820f377f2ffa7fcbcd22fd7d46445f89f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istva=CC=81n?= Date: Mon, 26 Sep 2011 17:05:39 +0200 Subject: [PATCH 022/112] fixed some FindBugs errors --- .../clients/jedis/tests/PipeliningTest.java | 6 ++-- .../jedis/tests/ShardedJedisPoolTest.java | 6 ++-- .../jedis/tests/SharedJedisPipelineTest.java | 30 ++++++++++++------- .../tests/commands/JedisCommandTestBase.java | 6 ++-- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java index 2a409d3..a7aa22c 100644 --- a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java +++ b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java @@ -82,8 +82,8 @@ public class PipeliningTest extends Assert { assertEquals("foo", zset.get().iterator().next()); assertEquals("foo", set.get()); assertEquals(false, blist.get()); - assertEquals(new Double(2), zincrby.get()); - assertEquals(new Long(1), zcard.get()); + assertEquals(Double.valueOf(2), zincrby.get()); + assertEquals(Long.valueOf(1), zcard.get()); assertEquals(1, lrange.get().size()); assertNotNull(hgetAll.get().get("foo")); assertEquals(1, smembers.get().size()); @@ -134,4 +134,4 @@ public class PipeliningTest extends Assert { } assertEquals(r.get(), "bar"); } -} \ No newline at end of file +} diff --git a/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java b/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java index 5444f84..ce9b093 100644 --- a/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java +++ b/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java @@ -152,8 +152,8 @@ public class ShardedJedisPoolTest extends Assert { shards.set(1, new JedisShardInfo("nohost", 1234)); pool = new ShardedJedisPool(redisConfig, shards); jedis = pool.getResource(); - Long actual = new Long(0); - Long fails = new Long(0); + Long actual = Long.valueOf(0); + Long fails = Long.valueOf(0); for (int i = 0; i < 1000; i++) { try { jedis.get("a-test-" + i); @@ -167,4 +167,4 @@ public class ShardedJedisPoolTest extends Assert { assertEquals(actual, c1); assertEquals(fails, c2); } -} \ No newline at end of file +} diff --git a/src/test/java/redis/clients/jedis/tests/SharedJedisPipelineTest.java b/src/test/java/redis/clients/jedis/tests/SharedJedisPipelineTest.java index 7ca2a52..4fba955 100644 --- a/src/test/java/redis/clients/jedis/tests/SharedJedisPipelineTest.java +++ b/src/test/java/redis/clients/jedis/tests/SharedJedisPipelineTest.java @@ -1,18 +1,28 @@ package redis.clients.jedis.tests; -import org.junit.Before; -import org.junit.Test; -import redis.clients.jedis.*; -import redis.clients.jedis.exceptions.JedisDataException; - -import java.io.UnsupportedEncodingException; -import java.util.*; - import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNull; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +import org.junit.Before; +import org.junit.Test; + +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisShardInfo; +import redis.clients.jedis.Response; +import redis.clients.jedis.ShardedJedis; +import redis.clients.jedis.ShardedJedisPipeline; +import redis.clients.jedis.Tuple; +import redis.clients.jedis.exceptions.JedisDataException; + public class SharedJedisPipelineTest { private static HostAndPortUtil.HostAndPort redis1 = HostAndPortUtil.getRedisServers() .get(0); @@ -81,8 +91,8 @@ public class SharedJedisPipelineTest { assertEquals("foo", zset.get().iterator().next()); assertEquals("foo", set.get()); assertFalse(blist.get()); - assertEquals(new Double(2), zincrby.get()); - assertEquals(new Long(1), zcard.get()); + assertEquals(Double.valueOf(2), zincrby.get()); + assertEquals(Long.valueOf(1), zcard.get()); assertEquals(1, lrange.get().size()); assertNotNull(hgetAll.get().get("foo")); assertEquals(1, smembers.get().size()); diff --git a/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java b/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java index 842b48e..c88b388 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java +++ b/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java @@ -64,8 +64,8 @@ public abstract class JedisCommandTestBase extends JedisTestBase { } } if (!contained) { - throw new ComparisonFailure("element is missing", next - .toString(), actual.toString()); + throw new ComparisonFailure("element is missing", + Arrays.toString(next), actual.toString()); } } } @@ -93,4 +93,4 @@ public abstract class JedisCommandTestBase extends JedisTestBase { } return false; } -} \ No newline at end of file +} From d97f30a01a4b5fdfe215317e8c45cb4d346d4201 Mon Sep 17 00:00:00 2001 From: ivos Date: Tue, 13 Dec 2011 21:33:14 +0100 Subject: [PATCH 023/112] Pipeline tests are authenticated. bgrewriteaof command test now supports scheduled status. --- .../clients/jedis/tests/SharedJedisPipelineTest.java | 11 ++++++++--- .../jedis/tests/commands/ControlCommandsTest.java | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/test/java/redis/clients/jedis/tests/SharedJedisPipelineTest.java b/src/test/java/redis/clients/jedis/tests/SharedJedisPipelineTest.java index 7ca2a52..b95caf0 100644 --- a/src/test/java/redis/clients/jedis/tests/SharedJedisPipelineTest.java +++ b/src/test/java/redis/clients/jedis/tests/SharedJedisPipelineTest.java @@ -24,15 +24,21 @@ public class SharedJedisPipelineTest { @Before public void setUp() throws Exception { Jedis jedis = new Jedis(redis1.host, redis1.port); + jedis.auth("foobared"); jedis.flushAll(); jedis.disconnect(); jedis = new Jedis(redis2.host, redis2.port); + jedis.auth("foobared"); jedis.flushAll(); jedis.disconnect(); + JedisShardInfo shardInfo1 = new JedisShardInfo(redis1.host, redis1.port); + JedisShardInfo shardInfo2 = new JedisShardInfo(redis2.host, redis2.port); + shardInfo1.setPassword("foobared"); + shardInfo2.setPassword("foobared"); List shards = new ArrayList(); - shards.add(new JedisShardInfo(redis1.host, redis1.port)); - shards.add(new JedisShardInfo(redis2.host, redis2.port)); + shards.add(shardInfo1); + shards.add(shardInfo2); this.jedis = new ShardedJedis(shards); } @@ -46,7 +52,6 @@ public class SharedJedisPipelineTest { assertEquals(2, results.size()); assertEquals("OK", results.get(0)); assertEquals("bar", results.get(1)); - } @Test diff --git a/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java index c6b6698..7e59335 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java @@ -29,8 +29,13 @@ public class ControlCommandsTest extends JedisCommandTestBase { @Test public void bgrewriteaof() { + String scheduled = "Background append only file rewriting scheduled"; + String started = "Background append only file rewriting started"; + String status = jedis.bgrewriteaof(); - assertEquals("Background append only file rewriting started", status); + + boolean ok = status.equals(scheduled) || status.equals(started); + assertTrue(ok); } @Test From b17692ad9aa0f05f560d04a73aaeb7e2d0873314 Mon Sep 17 00:00:00 2001 From: Hamza Kaya Date: Fri, 16 Sep 2011 16:31:27 +0000 Subject: [PATCH 024/112] Pipeline uses wrong response builder for get and getSet --- src/main/java/redis/clients/jedis/Pipeline.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index 8cbad9a..692ab72 100644 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -154,9 +154,9 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING); } - public Response get(byte[] key) { + public Response get(byte[] key) { client.get(key); - return getResponse(BuilderFactory.STRING); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response getbit(String key, long offset) { @@ -175,9 +175,9 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING); } - public Response getSet(byte[] key, byte[] value) { + public Response getSet(byte[] key, byte[] value) { client.getSet(key, value); - return getResponse(BuilderFactory.STRING); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response hdel(String key, String field) { From fb723db86de2078751ba8c12e1d730abbe122357 Mon Sep 17 00:00:00 2001 From: ivos Date: Wed, 14 Dec 2011 05:43:52 +0100 Subject: [PATCH 025/112] Issue #158 is fixed: Response.get() returns null if redis returned null (i.e. when using zscore for a non existing member) --- .../java/redis/clients/jedis/Response.java | 8 ++++--- .../clients/jedis/tests/PipeliningTest.java | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Response.java b/src/main/java/redis/clients/jedis/Response.java index a662c10..058985f 100644 --- a/src/main/java/redis/clients/jedis/Response.java +++ b/src/main/java/redis/clients/jedis/Response.java @@ -24,10 +24,12 @@ public class Response { "Please close pipeline or multi block before calling this method."); } if (!built) { - if (data instanceof JedisDataException){ - throw new JedisDataException((JedisDataException)data); + if(data != null ){ + if (data instanceof JedisDataException){ + throw new JedisDataException((JedisDataException)data); + } + response = builder.build(data); } - response = builder.build(data); this.data = null; built = true; } diff --git a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java index 2a409d3..2b02279 100644 --- a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java +++ b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java @@ -89,6 +89,29 @@ public class PipeliningTest extends Assert { assertEquals(1, smembers.get().size()); assertEquals(1, zrangeWithScores.get().size()); } + + @Test + public void pipelineResponseWithData() { + jedis.zadd("zset", 1, "foo"); + + Pipeline p = jedis.pipelined(); + Response score = p.zscore("zset", "foo"); + p.sync(); + + assertNotNull(score.get()); + } + + @Test + public void pipelineResponseWithoutData() { + jedis.zadd("zset", 1, "foo"); + + Pipeline p = jedis.pipelined(); + Response score = p.zscore("zset", "bar"); + p.sync(); + + assertNull(score.get()); + } + @Test(expected = JedisDataException.class) public void pipelineResponseWithinPipeline() { From f3a5d62e2b9a6a608343d4a816be45cfa53ce41b Mon Sep 17 00:00:00 2001 From: ivos Date: Wed, 14 Dec 2011 05:43:52 +0100 Subject: [PATCH 026/112] Issue #158 is fixed: Response.get() returns null if redis returned null (i.e. when using zscore for a non existing member) --- .../java/redis/clients/jedis/Response.java | 8 ++++--- .../clients/jedis/tests/PipeliningTest.java | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Response.java b/src/main/java/redis/clients/jedis/Response.java index a662c10..058985f 100644 --- a/src/main/java/redis/clients/jedis/Response.java +++ b/src/main/java/redis/clients/jedis/Response.java @@ -24,10 +24,12 @@ public class Response { "Please close pipeline or multi block before calling this method."); } if (!built) { - if (data instanceof JedisDataException){ - throw new JedisDataException((JedisDataException)data); + if(data != null ){ + if (data instanceof JedisDataException){ + throw new JedisDataException((JedisDataException)data); + } + response = builder.build(data); } - response = builder.build(data); this.data = null; built = true; } diff --git a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java index a7aa22c..1b18e52 100644 --- a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java +++ b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java @@ -89,6 +89,29 @@ public class PipeliningTest extends Assert { assertEquals(1, smembers.get().size()); assertEquals(1, zrangeWithScores.get().size()); } + + @Test + public void pipelineResponseWithData() { + jedis.zadd("zset", 1, "foo"); + + Pipeline p = jedis.pipelined(); + Response score = p.zscore("zset", "foo"); + p.sync(); + + assertNotNull(score.get()); + } + + @Test + public void pipelineResponseWithoutData() { + jedis.zadd("zset", 1, "foo"); + + Pipeline p = jedis.pipelined(); + Response score = p.zscore("zset", "bar"); + p.sync(); + + assertNull(score.get()); + } + @Test(expected = JedisDataException.class) public void pipelineResponseWithinPipeline() { From 6f4a32d2a1904b4e95085be83a5438dcc52eb2b4 Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Fri, 23 Dec 2011 11:44:39 -0300 Subject: [PATCH 027/112] add select to transaction --- .../redis/clients/jedis/BinaryTransaction.java | 5 +++++ .../java/redis/clients/jedis/Transaction.java | 1 - .../commands/TransactionCommandsTest.java | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/BinaryTransaction.java b/src/main/java/redis/clients/jedis/BinaryTransaction.java index 35c500e..54f6483 100644 --- a/src/main/java/redis/clients/jedis/BinaryTransaction.java +++ b/src/main/java/redis/clients/jedis/BinaryTransaction.java @@ -563,4 +563,9 @@ public class BinaryTransaction extends Queable { client.brpoplpush(source, destination, timeout); return getResponse(BuilderFactory.BYTE_ARRAY); } + + public Response select(final int index) { + client.select(index); + return getResponse(BuilderFactory.STRING); + } } diff --git a/src/main/java/redis/clients/jedis/Transaction.java b/src/main/java/redis/clients/jedis/Transaction.java index b1dd14a..18c5f29 100644 --- a/src/main/java/redis/clients/jedis/Transaction.java +++ b/src/main/java/redis/clients/jedis/Transaction.java @@ -576,5 +576,4 @@ public class Transaction extends BinaryTransaction { client.publish(channel, message); return getResponse(BuilderFactory.LONG); } - } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java index f123a4a..8167658 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java @@ -277,4 +277,22 @@ public class TransactionCommandsTest extends JedisCommandTestBase { } assertEquals("bar", lr.get(2).get()); } + + @Test + public void select() { + jedis.select(1); + jedis.set("foo", "bar"); + jedis.watch("foo"); + Transaction t = jedis.multi(); + t.select(0); + t.set("bar", "foo"); + + Jedis jedis2 = createJedis(); + jedis2.select(1); + jedis2.set("foo", "bar2"); + + List results = t.exec(); + + assertNull(results); + } } \ No newline at end of file From 72ca4943627bced9fafc316d0487e3f939a02009 Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Fri, 23 Dec 2011 12:31:32 -0300 Subject: [PATCH 028/112] add missing command to Transaction, BinaryTransaction and Pipeline --- .../redis/clients/jedis/BinaryClient.java | 8 +- .../java/redis/clients/jedis/BinaryJedis.java | 18 ++-- .../clients/jedis/BinaryTransaction.java | 82 +++++++++++++++- src/main/java/redis/clients/jedis/Client.java | 8 ++ src/main/java/redis/clients/jedis/Jedis.java | 98 ++++++++++++++++--- .../redis/clients/jedis/JedisCommands.java | 6 +- .../java/redis/clients/jedis/Pipeline.java | 47 +++++++-- .../redis/clients/jedis/ShardedJedis.java | 6 +- .../jedis/tests/commands/BitCommandsTest.java | 6 +- 9 files changed, 235 insertions(+), 44 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index 4a76a63..812defe 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -643,12 +643,12 @@ public class BinaryClient extends Connection { sendCommand(SLAVEOF, NO.raw, ONE.raw); } - public void configGet(final String pattern) { - sendCommand(CONFIG, Keyword.GET.name(), pattern); + public void configGet(final byte[] pattern) { + sendCommand(CONFIG, Keyword.GET.raw, pattern); } - public void configSet(final String parameter, final String value) { - sendCommand(CONFIG, Keyword.SET.name(), parameter, value); + public void configSet(final byte[] parameter, final byte[] value) { + sendCommand(CONFIG, Keyword.SET.raw, parameter, value); } public void strlen(final byte[] key) { diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 8632497..7b4cd30 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -2822,9 +2822,9 @@ public class BinaryJedis implements BinaryJedisCommands { * @param pattern * @return Bulk reply. */ - public List configGet(final String pattern) { + public List configGet(final byte[] pattern) { client.configGet(pattern); - return client.getMultiBulkReply(); + return client.getBinaryMultiBulkReply(); } /** @@ -2871,9 +2871,9 @@ public class BinaryJedis implements BinaryJedisCommands { * @param value * @return Status code reply */ - public String configSet(final String parameter, final String value) { + public byte[] configSet(final byte[] parameter, final byte[] value) { client.configSet(parameter, value); - return client.getStatusCodeReply(); + return client.getBinaryBulkReply(); } public boolean isConnected() { @@ -2959,9 +2959,9 @@ public class BinaryJedis implements BinaryJedisCommands { * @param value * @return */ - public Long setbit(byte[] key, long offset, byte[] value) { + public Boolean setbit(byte[] key, long offset, byte[] value) { client.setbit(key, offset, value); - return client.getIntegerReply(); + return client.getIntegerReply() == 1; } /** @@ -2971,12 +2971,12 @@ public class BinaryJedis implements BinaryJedisCommands { * @param offset * @return */ - public Long getbit(byte[] key, long offset) { + public Boolean getbit(byte[] key, long offset) { client.getbit(key, offset); - return client.getIntegerReply(); + return client.getIntegerReply() == 1; } - public long setrange(byte[] key, long offset, byte[] value) { + public Long setrange(byte[] key, long offset, byte[] value) { client.setrange(key, offset, value); return client.getIntegerReply(); } diff --git a/src/main/java/redis/clients/jedis/BinaryTransaction.java b/src/main/java/redis/clients/jedis/BinaryTransaction.java index 54f6483..3a6893d 100644 --- a/src/main/java/redis/clients/jedis/BinaryTransaction.java +++ b/src/main/java/redis/clients/jedis/BinaryTransaction.java @@ -568,4 +568,84 @@ public class BinaryTransaction extends Queable { client.select(index); return getResponse(BuilderFactory.STRING); } -} + + public Response flushDB() { + client.flushDB(); + return getResponse(BuilderFactory.STRING); + } + + public Response flushAll() { + client.flushAll(); + return getResponse(BuilderFactory.STRING); + } + + public Response save() { + client.save(); + return getResponse(BuilderFactory.STRING); + } + + public Response info() { + client.info(); + return getResponse(BuilderFactory.STRING); + } + + public Response lastsave() { + client.lastsave(); + return getResponse(BuilderFactory.LONG); + } + + public Response dbSize() { + client.dbSize(); + return getResponse(BuilderFactory.LONG); + } + + public Response> configGet(final byte[] pattern) { + client.configGet(pattern); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response configSet(final byte[] parameter, final byte[] value) { + client.configSet(parameter, value); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response configResetStat() { + client.configResetStat(); + return getResponse(BuilderFactory.STRING); + } + + public Response shutdown() { + client.shutdown(); + return getResponse(BuilderFactory.STRING); + } + + public Response getbit(final byte[] key, final long offset) { + client.getbit(key, offset); + return getResponse(BuilderFactory.BOOLEAN); + } + + public Response setbit(final byte[] key, final long offset, final byte[] value) { + client.setbit(key, offset, value); + return getResponse(BuilderFactory.BOOLEAN); + } + + public Response ping() { + client.ping(); + return getResponse(BuilderFactory.STRING); + } + + public Response setrange(byte[] key, long offset, byte[] value) { + client.setrange(key, offset, value); + return getResponse(BuilderFactory.LONG); + } + + public Response randomKey() { + client.randomKey(); + return getResponse(BuilderFactory.STRING); + } + + public Response publish(byte[] channel, byte[] message) { + client.publish(channel, message); + return getResponse(BuilderFactory.LONG); + } +} \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index fb35c10..1f493e0 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -587,4 +587,12 @@ public class Client extends BinaryClient implements Commands { } subscribe(cs); } + + public void configSet(String parameter, String value) { + configSet(SafeEncoder.encode(parameter), SafeEncoder.encode(value)); + } + + public void configGet(String pattern) { + configGet(SafeEncoder.encode(pattern)); + } } diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index b43b00a..c71d9aa 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -226,18 +226,6 @@ public class Jedis extends BinaryJedis implements JedisCommands { return client.getIntegerReply(); } - /** - * Return the number of keys in the currently selected database. - * - * @return Integer reply - */ - - public Long dbSize() { - checkIsInMulti(); - client.dbSize(); - return client.getIntegerReply(); - } - /** * Set a timeout on the specified key. After the timeout the key will be * automatically deleted by the server. A key with an associated timeout is @@ -2595,7 +2583,7 @@ public class Jedis extends BinaryJedis implements JedisCommands { * @param value * @return */ - public boolean setbit(String key, long offset, boolean value) { + public Boolean setbit(String key, long offset, boolean value) { client.setbit(key, offset, value); return client.getIntegerReply() == 1; } @@ -2607,12 +2595,12 @@ public class Jedis extends BinaryJedis implements JedisCommands { * @param offset * @return */ - public boolean getbit(String key, long offset) { + public Boolean getbit(String key, long offset) { client.getbit(key, offset); return client.getIntegerReply() == 1; } - public long setrange(String key, long offset, String value) { + public Long setrange(String key, long offset, String value) { client.setrange(key, offset, value); return client.getIntegerReply(); } @@ -2621,4 +2609,84 @@ public class Jedis extends BinaryJedis implements JedisCommands { client.getrange(key, startOffset, endOffset); return client.getBulkReply(); } + + /** + * Retrieve the configuration of a running Redis server. Not all the + * configuration parameters are supported. + *

+ * CONFIG GET returns the current configuration parameters. This sub command + * only accepts a single argument, that is glob style pattern. All the + * configuration parameters matching this parameter are reported as a list + * of key-value pairs. + *

+ * Example: + * + *

+     * $ redis-cli config get '*'
+     * 1. "dbfilename"
+     * 2. "dump.rdb"
+     * 3. "requirepass"
+     * 4. (nil)
+     * 5. "masterauth"
+     * 6. (nil)
+     * 7. "maxmemory"
+     * 8. "0\n"
+     * 9. "appendfsync"
+     * 10. "everysec"
+     * 11. "save"
+     * 12. "3600 1 300 100 60 10000"
+     * 
+     * $ redis-cli config get 'm*'
+     * 1. "masterauth"
+     * 2. (nil)
+     * 3. "maxmemory"
+     * 4. "0\n"
+     * 
+ * + * @param pattern + * @return Bulk reply. + */ + public List configGet(final String pattern) { + client.configGet(pattern); + return client.getMultiBulkReply(); + } + + /** + * Alter the configuration of a running Redis server. Not all the + * configuration parameters are supported. + *

+ * The list of configuration parameters supported by CONFIG SET can be + * obtained issuing a {@link #configGet(String) CONFIG GET *} command. + *

+ * The configuration set using CONFIG SET is immediately loaded by the Redis + * server that will start acting as specified starting from the next + * command. + *

+ * + * Parameters value format + *

+ * The value of the configuration parameter is the same as the one of the + * same parameter in the Redis configuration file, with the following + * exceptions: + *

+ *

    + *
  • The save paramter is a list of space-separated integers. Every pair + * of integers specify the time and number of changes limit to trigger a + * save. For instance the command CONFIG SET save "3600 10 60 10000" will + * configure the server to issue a background saving of the RDB file every + * 3600 seconds if there are at least 10 changes in the dataset, and every + * 60 seconds if there are at least 10000 changes. To completely disable + * automatic snapshots just set the parameter as an empty string. + *
  • All the integer parameters representing memory are returned and + * accepted only using bytes as unit. + *
+ * + * @param parameter + * @param value + * @return Status code reply + */ + public String configSet(final String parameter, final String value) { + client.configSet(parameter, value); + return client.getStatusCodeReply(); + } } diff --git a/src/main/java/redis/clients/jedis/JedisCommands.java b/src/main/java/redis/clients/jedis/JedisCommands.java index 806bfbb..603b60c 100644 --- a/src/main/java/redis/clients/jedis/JedisCommands.java +++ b/src/main/java/redis/clients/jedis/JedisCommands.java @@ -22,11 +22,11 @@ public interface JedisCommands { Long ttl(String key); - boolean setbit(String key, long offset, boolean value); + Boolean setbit(String key, long offset, boolean value); - boolean getbit(String key, long offset); + Boolean getbit(String key, long offset); - long setrange(String key, long offset, String value); + Long setrange(String key, long offset, String value); String getrange(String key, long startOffset, long endOffset); diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index 692ab72..95bc773 100644 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -40,11 +40,11 @@ public class Pipeline extends Queable { List unformatted = client.getAll(); List formatted = new ArrayList(); for (Object o : unformatted) { - try{ - formatted.add(generateResponse(o).get()); - }catch(JedisDataException e){ - formatted.add(e); - } + try { + formatted.add(generateResponse(o).get()); + } catch (JedisDataException e) { + formatted.add(e); + } } return formatted; } @@ -1191,4 +1191,39 @@ public class Pipeline extends Queable { client.publish(channel, message); return getResponse(BuilderFactory.LONG); } -} + + public Response flushDB() { + client.flushDB(); + return getResponse(BuilderFactory.STRING); + } + + public Response flushAll() { + client.flushAll(); + return getResponse(BuilderFactory.STRING); + } + + public Response info() { + client.info(); + return getResponse(BuilderFactory.STRING); + } + + public Response dbSize() { + client.dbSize(); + return getResponse(BuilderFactory.LONG); + } + + public Response shutdown() { + client.shutdown(); + return getResponse(BuilderFactory.STRING); + } + + public Response ping() { + client.ping(); + return getResponse(BuilderFactory.STRING); + } + + public Response randomKey() { + client.randomKey(); + return getResponse(BuilderFactory.STRING); + } +} \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/ShardedJedis.java b/src/main/java/redis/clients/jedis/ShardedJedis.java index b8c00e7..b294149 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedis.java +++ b/src/main/java/redis/clients/jedis/ShardedJedis.java @@ -68,17 +68,17 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { return j.ttl(key); } - public boolean setbit(String key, long offset, boolean value) { + public Boolean setbit(String key, long offset, boolean value) { Jedis j = getShard(key); return j.setbit(key, offset, value); } - public boolean getbit(String key, long offset) { + public Boolean getbit(String key, long offset) { Jedis j = getShard(key); return j.getbit(key, offset); } - public long setrange(String key, long offset, String value) { + public Long setrange(String key, long offset, String value) { Jedis j = getShard(key); return j.setrange(key, offset, value); } diff --git a/src/test/java/redis/clients/jedis/tests/commands/BitCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/BitCommandsTest.java index 204caa8..047ca20 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/BitCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/BitCommandsTest.java @@ -11,11 +11,11 @@ public class BitCommandsTest extends JedisCommandTestBase { bit = jedis.getbit("foo", 0); assertEquals(true, bit); - long bbit = jedis.setbit("bfoo".getBytes(), 0, "1".getBytes()); - assertEquals(0, bbit); + boolean bbit = jedis.setbit("bfoo".getBytes(), 0, "1".getBytes()); + assertFalse(bbit); bbit = jedis.getbit("bfoo".getBytes(), 0); - assertEquals(1, bbit); + assertTrue(bbit); } @Test From 12a1a70d39dc5d4ac793d05fb478a32e4308e6a9 Mon Sep 17 00:00:00 2001 From: Alan Krueger Date: Fri, 23 Dec 2011 12:56:05 -0600 Subject: [PATCH 029/112] update Gradle support --- build.gradle | 5 ++ gradle/wrapper/gradle-wrapper.jar | Bin 10727 -> 13031 bytes gradle/wrapper/gradle-wrapper.properties | 7 +-- gradlew | 40 +++++++++++--- gradlew.bat | 64 ++++------------------- 5 files changed, 50 insertions(+), 66 deletions(-) mode change 100755 => 100644 gradlew diff --git a/build.gradle b/build.gradle index a956f7e..71aab8c 100644 --- a/build.gradle +++ b/build.gradle @@ -25,3 +25,8 @@ uploadArchives { } } */ + +task createWrapper(type: Wrapper) { + gradleVersion = '1.0-milestone-6' +} + diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index b7853efcb81821ea5118d4ed8cf562f7822f4b2d..45bfb5c85ea4b9b0d02616718f2637b2075acb1c 100644 GIT binary patch literal 13031 zcmaKT1ymf{vNpjrxI=Jv2ofM9ID-XuAKcv`=-}=i26uONcXtaGJh%iN=Rfz|b5H(r z-=5Vyd)BJ@c6YB?RlC0WT22ZI8W92l9v-3~B1Hh=bwK`cdL0O_hm5F_AQM1Vj0Flp z?r(+!l6*geUk#*Q53K(*lo6B#h>0pHG0TWu%8ZUkOEED|p-3^&kB?5&D6r0QZ0`P) z86BN*8V4{k*DDONNG?dRNJrHFTJDnEzwZmT#CJU)TBf z)j_|`ZR}0{c45EUApOh6#9rUf(&%rdzuzq8-%VZY^=)m9?EgO(2|fOuuGgg>ULOwq zKf8$kzr|Gl1d!1;vt|Zb>N_|@D6gojh+(ZE_Ogdc_yOR3(IiNFCt-1?^Km5<{E5He z*|H@OEH`(nL|~}f8-4hEwt#w&bybbyI%jcRh5D7%#zb9`M(=E?C*>|LC?P9x@`H&cm1@nZ%oyVl zM)Of<)m&LZulf7EqMQEh2{2*E_2`qv`@~=qE`^J_(e5AiTHT)+7~-@vW%?K9XHxQ9 zQ;YY%*B*pGa)68)zfjf&4!}Hsm*2#dPc1NEHoOc#548qZ3)OcAHRP;JIP7&#bZst03nIf zL6?uQ@7Qakwk{poOw;cN8+R!<(Thwlgv9U~Y{8nvo;eenIFk2Ps$55cm+O};O2!R~ zN4a&pqe&MtYh=k58|qXg#RReTR+xp5X>syrkv>fRSlgD& zld?L~Skb{+CB=RuY-&VyMr^K74C{LaS1*d}37Qrs&#znH1L~Rh$ukPe?>2+tsk5tX zrbW59YP#Zmimfc)8d-M%+(jXaCC89c{A zIcZXbw^Pz+Gv~$iyeQ(^u?x=BG9D7xk2tFa{EF`0!Ti*0(de^)muj3^=C3j884WRX zdY^Ll=2P`>48lZXXx4d6K#Z!HAvrgiic8j!dQ!%`UdGL4N|+9z{pQc+5>1v5ocdX0 z=N3=puu(%?P7$Cv@Lv3t;?L$RrbuzsJ4@X#vaq0rhF`GG7r7kyzj93oa*W02QLikQ zj8I&j_LgwFEu?i*bV=rHc~dI)4o^Pf&sSR{$AAJ-2yUxZc%P9{McLA_)0`(dP$=4M z6frleRVb%9KcT9v8Z1SG4j~0KH?_h4;|n}H~@Upg)9L!5HJ8-vi2AKIP5twU{4He2X62)nxX4K_Oh+&W!> za+)wF*jnibFs(g1^xv=8{C1Qbb02M#v!k1p0#nPsUE(E0+2w_ne0L%yoAo&*!(t6^ zUKOPQ0XBLV+p>!7ENoo~&uq_fDbBV(HZSzx6}UC~;Qw41a+6-T3n~ulv#X$ULIggl+)mshLXQ|<(3Z8C0mAZC_%G`#!ojqB{)nee#{MaX^k|W(IiVl zzE-uhFnb~??B?ZIyVW%H0Z6iN*7RG^Sk~N7U{3&FGoU5p4^_P~3#iYXv)ZgR3_z%zV zc^C)?bYut!)_)F!if#^$Mpkn6Hm`xy(agv}Lf`r|3fuoH9ID)_Vya?2gBUTpgG;v? z!C+8jvnGy}d?{^MXdoC&+#MYb0;Eero8M}*tgNZ5?4bS%%;Fz-_a!G$@mJedrITCg zH`QiaMC%?+x9yMZk6veM-?P5HxFhP}dS3$xL5Ar+bD)I<(rHppx-h_Vqff&ybz+#s$wVD1;F2$i~k#__0>3q3Ed z_!G`Fm?G6Ecmh9XB@zz-VeA(h!zxaF?NH%57trjY(Yg+0g38kCAs%}NZeLl_g8*{>k;P)6w!Y99v;wjkVeQF?FjJi70$V|8q^D`CUVZS*Csp#>PsNeJ zNZ>D9$_};$$ko(qx~pXwVGQ({W*G;@%`^kvuBIAsqN$=oIEp#N$rgPP3h5F(+!iok z4l6)Prr;9P5K#M2zEp3W(ifdB*@9O`owVF^N8a{mkLirv%}`5Z&^@hBVQKC>Z4imc z@Xe_&gd1+!nPT2~H28<;_X~XL9VaXIqVLj{S@>U;&2W1t$xF0<-lANOgRUB_dZCGz zmfy-~%?ooyaH`W>$8e8DBA}1#NO4OL2?;ZQMtF9eC)SKhFuFfwE56+gEK4SRv1K$1 zyn3IA!r}^9W>De>Ynde1|25-swrsc2KtGk?>;x1>3k3uB%M z*NfV0xxY4Zw{*lLm&QzlrjKKF-a?(N#G4wNc0HBM1qP@e}7`oHxLcNpk|AJ_Z#O&SAf_S=F9-Pr4)T%?IbUN^Gg0 z^RuuI1Yy?|p`L^u0-73&kv#Z|^D4WmP8x1Zltjo_?L9(Lz^Z{_!wvR#CWh}!jGh@V zb$PahB-C1thflG{yD>xiF~}p(6lZ^7JRsTVn&^0@YN40$$XH};Ddh{#_{(9r|>ki&B9!$$zalb zh42HCquzvnbUv68pA3xS*YTTY3m=#?gpPqA-tYftj zSJM}eZgjm>b}raFIxnggAI&Rf37qzzwNdagKg7J##%tS(*~@xayXq8V(yIf913!9} z7NlcyR^}T=dZ>TFB_lRc`Xm@N%`F?{^GP&VTP+Ib^o9+b%GppIZj3WMzTwDzd)8&W z+*;TPvEbpRf$~s^`nV-V9JvLd`c9tq?KILJejmdDDcdejgzO%RpbMzD_6$umh?rN` ziPnQjcuCm!YU+8P+^7p{__TZGO79IKN(n5EoPZdc3MyAau3Xp4up2G0b(P%O#Gd@8 zMxP&5Fte=9_2x2&PSRCeFm=1=^B+qzzQDkyDK4Hv6H+-gD&JyS#x5#Eh0YnL@-xxn zSKu1B22x`ITYfn8+V*C{*U1#GGJ@+_SMGahH>B&S}I7%oBpp@}_#pFh+ zGN?|w&0{qH%}TKi3B4zVT9`xTyPiJKPSN$U(_E6F{eVfQt4-?2O&rnY2%S}m3sl-3 z;dC_&dxpzf*8aW>LcE2MIjd5K-h?K;1Bo9-1@I=ElDZhAR)W$gynFx?={0jG^ z_Xgg?VVR_NEC)uHGm@R{!!J$D`P2|Rq5eHb#LT{1Vt&mLaj*3S^*`qbIekY{K?esT zD}#S$h6H6ZRZJ5sZ&*moess1_q&co_oNAThe0e%bOD;wkADp~xN;ia@A?frKTJyQn zx?gZ7hf&}5YeNb$=g)r0e{4G&H6#mQCfU-CGQdcnRN@YvBuwpk8x)*|F@GKs;NRFc zu|Ty7>Yk|f9CVA>=eRWJ3G)k(DO~-*#B%Ctrz#@fIdypD%Ffx;o}MCIF~K-0Q*M$t zU2{1D=~=`#>_w%bR4c>?#4lC}Mq138Zy`#jlI-)`ch!A8)TA^qwOUsT!a#)OG-i4R4N^_n=zz{eGh-2r$_T%JdTJsXjw$BA1XAS^>=*0Ip%N*3H)GV>8f`$a z7-kE$WzubC>6q^D0XD_J9T}CiI5}8LxF6n+eVl^yv-NA{^`%tS=bIK0W!g(2%Ylw) z>@(C7(*i}Zb31+M$AkZfrN;2-9ZMp20!{XyhCnS&9vJ}GJ%+u#dm&!8VXknTepY*`)jar4tiQokR;F*pdFjjjbxD2)cx~> z`=Uf#v?acc7R(-`jp+=EH$hOuNSBV9P|lSd3KL#ZRTzSZ+*P;^?nRbKv!85N$|MGH zHFq)7LSyuA>7_@i-fE1kFZLOhughE8q}=2<0maRa*bdevQDQM{i=Y^3OBPjWn`+Vnt4dtUg>{<9)kpIzv)RnS4lV#E$l1P7XJqO&$0_*YZnFNBAK-EVag zCRfpuc;GeBRG3r`KTh~hD`0&Bs?;~1_@U9V6OQ4@Lh;5{JJZU2>0-ZEV{oG({|YV7 zPw)oAfOpBry+i^udAB8667NE1wketQX6w|&SPmh4lMZxHK<4MIA`|8)ZCmsrSxF$h zT#!I&NwoQ5!`kQLIyYF$+;6}fUo29SiN;%-sp1ixwg{KtJRg@An&ws-cURP_TY`h6 z<;j-2o@4OWF9_SIIYjE2mnUC+y&(lyNs0_M#fdyZ{7VF~_FafHPTm^nY}%suSCD7Y zN4|F>%9i$JpOs=GChdrf-Pac~|4CqVPEhwjZYZ`FJ8c0XVOCkI#w~)=6~A^rRXCeI zay-zDC{mm69@D*hWh*XoMVZKEphFs%PQQ<+-ik=FWWJ5cc^;(o^bUF3i%>Ve8Gj%k z;>#y4+?NlB7s*t@?b-A?k8jpDSq_%p-pekwyvbzT7{YaJ198{8MX%=GKgAcKO{^BV z_rvPevB}6eQ6o6Tl5>g@8EepUF6pJ_K5{tc$u2$2eEn@#9uSdNlln?eys|kEWd9s- zMQmKGEp7A-|J;UqDQi1mD&u*}rjAjstf*WOI zdxWY9xd}C%nr+2wi24alh)jrxnTgWnnSY2Tql=$4o{JYvEO}e80gdf%(rQ?*Uwo|XMq@o32iWqR44%EYEl{!rPM=ZKE~VGnfgldfG## z%u6e#GdH4j4})X^W=o@d-_G!2ui({@>qbDJD5hwy1|^l0 zzV~#WdIWk z0%#pq=H7Y$pne_=)D*ZU_KiD!^~U#yHQ8Rgdsl$PVPK53x28Da?NNIv2+nc2CIiQn zjLp~lhe*Y>LaE?AR-!-qv9&U3Gm}UC#QMSamJU-U_)%vA8D!7Prq0~aho*B)iZJ4OAbLI1ZC{3Gx`D%?q6&td4P)ObW{BErS?4YWO z*#a3uB#E4VRiEjKxfb>8mhae-b^tJ&K>K1QLkX8f#<3`JMsc;jtXb@oCtLT@B>9uT z-1YM|>bdf{7Q++Az@w@=HYJ;AtZqr-Ji!p z2^9{K=1nPF>^psIU-`5doW z8!u1KG(KK;OHpBOv|=w1sSPC>kAvuQVB*-pgK%eEsdi9__x~f6-5_d zjnqgJCPfw*lElir0Qq7y^C8{>oRZXl$he_nQ|b?_T&Y9=nQ$YJ7A$Yl5G=-$V3O_S zy`eifA8#zaWg=roqHK8PP5V4$%t*fcytLE;J;pNev9c6P|4f9#wko1~V3o9jK|E!t z)0Jc@HpvJjoo&-S@XR@ zUOHyjpzu}={({uz#RXKa`EXg+6%eumuYgr?AQ-2^y4a{WJc^G)+Y+9|h5jk{yxi37 zDA!u@z)ayhQbjB7pmr=_u#3>GjL`tM3J0Yw+PMm6QcAiuf1K-dQm|U7Tw|Q=Y!C&i zv>caYgyF#>rSrgLpTFZKonk` zDgwfiK3jS;nl<9u(#WCozgAtUTs0^ zsNG;Jq+0g@PB5=@_nJb;O#wJW{NOON@W!_*}WB|`D@C?k$r&{%XO0zW+BI}HK zqI|w|&YVNJ>hbJ;_r{9KTpE9`)EvNbur;_wn7-=qsUvtmdtvAx+)NAi6vEm#cq1#iDTh1U@cNmsaLYw zdSZS3N*F}^^m%ENC13gAGs(mK8>}5`m=|6&my-pDmw1bgxJR$@U)HBt&L=K*9UFBU z{@+Xmwctcmt4y3J#=U=3mf7)luhHE#Le`7mknZ|1oC1wd+F@$Ho12z(eO;(`j?Wpz zUzED~$kU&&z1m~f+Nr)MJ!_SJmq+EeVwE1w^tcY1s@rP4=CrWozNym2<*1)f|X9DxnN6lK4jqM;5PUtiJ9b(4w{h0h=<739&G@#G+e4gk!jNWQ1o7 z+SU0TUDhWcy+Hmw0h!w`D22c7tPx)ue@y?JfP`#p9332A`+k2k{S+Pb?H&IjyERn_ zUdirAWMo-!e^)@Iycs8U>*v(`dU*?AX+Kgbt+}K$3lx$5C@V0iD|tQhf#zX3shx`@ zSy^@F_Bre+rv4Eb7hOWtj?H1b-Fsu*gyiYyY(w{rE6FE%_|0-ZGREOX8X!OrEsIX= zwdsd?%AnSl>RS3(MMjD6iOa}xD46!38wwv4+Y%@)HXWtC)k^d3ar@i zHH4D6!C(Dqw8W~`y4nvR{vBv<>zoT~9_TUSFO|WG~Ggs}MoQYn+4w)6|7|Li(Fv7EBt-R0f;*f0x zQ;hhI1bTRDG3e+zEZ&E}pu63_?};K_V-I6*&sQP(Va%1CFe;t7!kn@tp_q}HA{ErU zLOfPKK-(!8w!TSCw@4ryB#T64mT-)$Yu6@pLV$~ju7nH}=|dJUXnX)ovlT`VU=vKU zv(r~^cE8Ap$%?*f4yE9yVs^AQND%7_rypAMa$%V+VU;881TXjI7U|JTt0DU$UHD(2 zW9#-;h1$r$DH_R|tWM5A!npC$7V&g(fE56rw52`~r@0DwTHzPaXYOeJI1}~Dh&?=j z(K$o!`5CLsUadc4-wo@uyroYw(Swb+r7?Q`uq~^`ZLwV{3o}1Mg-*urox}4^@q)M= zchXxA?vL!~t{X~hq|Nz+QAQ!3~^rZbEUWQRC@Z^I|UR%kJ- z@J&-BY|OTCTD6`ZWbjQBW4;JF9GEKfK0D`mNkgMDrG=-$*B1c^{jNu?{LglXABvDZ zd-CgT>tvfGJKMQ)xO>oycj`=n{iWYzF%b2(Tq!ZY;`QOR9U5+ati~9x7?RDuz3H9B z=dB;#0sy{#mUPP>IZxb@$`s5@(CH?L9X>z?2<06b=jvuLG54pydZ@=_6iJM<+5{P3uBDNls`Xduc}J}bQmo#P>AKClvD6V&rs z?4&H?$J*h_XGIAChrg1}y*Nee+=p3^B-YA@Dvl)4r(6KaSWgN01M+f}2-g_SO1nrs zbM{3KP&@krcYzL*t8uQk*#U02^tDt2^c*{^pXx~C4TmS$nawA_@xoV~EQ)xnGsp+}RJ_>Kb%)v+!Qa6&!tcO{H-Qa4zF9>rvB-8kL8Qvn4 zQNF3riA8BZ1J5B@XMXv8U%h{<=1}|^&Q@Lz@_!C%fWI>aq7hw)-K@xfyaS6JiIrUfr|4B zeB2@RzUp{9?UFujpziQ{O%sKH8VWMCH3Rwh6crQHk0TylY*mG~0fMzp>SIU3-D+v^ zc_12v%HeY`8ie)Q)-dQwtBGz>^F zQc^a(P8FIVB;@f?!i`ooJ#Gs#3kwTX%`WEoVl$>P11iCt`3Q}&HA@T46-nHdm9hHz z`ULO&wiLryY&7&%v{BKqIQpHcoR1ZcyV@?&}4_7IEX(Du)Kd#7?9*I*iz+H z*=j=bChoQox+{|n`>Gncv4aYJzDIkez04As%Hn(y9e{mO2H_5$b3bW=zM8tq4^aD> z#zAE7WObjjps<+THAIH(c5*$5AHP%_x0de2`<2Jjll6VcJFm|7M9j7>;ZCSDSVOGg z*1XAl_~=~9r$2wYT;;f2d!#wPf1^qlKY-Cz1(k9wOf$<2)1ztmB@d{rN*^vYkluF0 zj?b}_!fF-h))!#S@I8BT^Zr6T`Y>g+he1j`s_E`6A%O2kj>hju-_!|3%zc+R9^lbi1G4>hl0 z#~&*V4W&QZF{)-WAGii03vQmW7{Xff8kIZ9GFe4S;-t?)3wFca;3jF)0I zD4aMO1XI~0@gy@wRE2xovpv{9`hD|rmf=6KL)ylztMV>>~(R~$u`2LK$r8@F+>sW2vg|wJ6HnmD*Yv5gp$a$7P?RxUbA)8f=M+^Ru zGgNQZH;SReQ>A2i+c2y8IU{5Ch$Yuuyhg=X7C4^=nFIa{JqCG~Ug?a=LEoNbk8^|r!mq|7J#s4QDiONS7) z46Y3o8dYl>P{@Q|E(mG0-24=%PubRX#=T6b&qB~;@(R<84@pX}nOWf*v-(ub*K_!6N+gnE(u&477(JvAeeB&LA8nzu6C zKtN!#z9!Oqkj#3j6G*jfP$J@7vx|(t%E;_wcDvxvPnJ89*3g9_1rxGx-Pq`ad8TG{ z(8whNo^`Sa5?055fuKauGv zBe$c}l-*x~;3%%mYs?2q9mJ+bAvDJ*Uzjz7YAB||N@H>6Cr+SHeT9V)1(A@gA1kE)vSDt8a{JPEn+UA#v?3h$%SNH4lZj$e$WS7@$W zUPK@~S8VTIAW_Dqlwmn0;Ls#rXkJ|%VvTz=%0SRzui0%lm+t|d9t1PWsl#6Tn!Zx- zox@@tKsxdCEUKuQh48(nm31LpGnIViK6ax*cc;jF976LD4f8^WIrh_QckD5_kvT-+ zi~<#Q%&>f3bTpgwQiAt&!*cslsii6wKN};9xIxXI)o_aIj+=9`S){i;`M=wj+Dggk znru?s6=oACe^!(MX;h?g)^*7d&IKa>oN>8qbKq>)i^cTHqX7v4cS~%}?p65n z>yr97jxOnhYpFJz0qAd29|6X>`^m?n$54@~<q#^WzF92 zRWu+zv%#vL>dwwnupB~Y`bh3x)`pqy26>FDD}8JzUTg#3>Bp;5jGNBpk{iGaX|!WZ z(}rrt){pVeq}ez6M|zH7J5QpueNJYnTAYQyZypa%805{r6+>i4k7IKNCy36Td2@1q zpQDzuRAe;D+x9eYvoBD=IefPMWP-I4snsAid#-7+oh&-Er?$GJw`3iE86z+2MWJz7 z>vuq~WL$u2vurSwyH&OdWC~I#^{9C?WRRwAc^g|gE9ay%!PIZoZd>T8V{Z3ab3=DjK zYjg5J=6hWu%R=~m5tyY(;@uTFODUZwH=d6NFoh}6ii>8H(gF&dQ7YvzV|D*PGCJ&o znAuNBXH)wH+;!_-j&sL1X!tijli@VJG3X;0$AuE@UQ=NVDmAspPbOaaiJz@clL&PmIa#T>cz)Qm#~Z<{I438CyX&layV z#t*Bje8P5DLjDYdC)%|}klqrE2EsToex}0#r+?k2xrlOsRzBDoZ_1=R?$YVZ>xJA^ zFc1!r3ULxh!ti)njRKO~nnpaZlrijTX*!WWa@NiLg6Dz;BoXyv$+q{dl^5E3vrp8gyN6J&fI&6u?dNc4}{gfMPyHA2aT zoLBEIb}QXl`iV~9CL0&{p**%H_$~P|dM2SO{3WmFoE5RRI*ScoWDOka3%V)*#tzSZ z(ph>>4GGE#8RXt<&X#C^K=9!-+ap#D)S&+%tCqnQkHLD0Kmm~3+n39j+t-&{PQL3vmlnT~$DRx6c`+6! zOeZMmfuOEHz^Ut7qCM1R4Z(0+K-BKshNc`9lcr%8OV+%J_9Wg{H@6jdwTUyw8$2Aj zDXccTg`|p}&8m+$dzF)K1yP6c9Na^(CkjL&a1*+MfTS&1>MitX7mhbk>?m-99|j@M-%EAY#An`~%@y_^ox2Z32w)#A6ok+&-{9r(=XFiEn@2*0}rt)=;tIC#Q32{l_fxy9bQ?=8-3p0&^1K| zs=gVkO42re_r<#J8(Ojx#I*{;)1l_vHb*?1HWy_n%9rO>$(p+$g|Skqa4PC!`xmSi zeP~bdw+~7iMJ7YMW{bgY)@X=~s`3eAN+YaYMDy*8=67uY=es3(Fiq>Coxk3j39LsD zy1Dr)Uw(A0u=p8D)~K@S#jGXyY~rqr#xhB)U{)q*c~JPSQ;a2+*|MyS#1bKBQf!+% zP`qjg>0~U3RmNI@f<)6b$-DOSnD1ICL21C-lDLR;29a8E^7xV`!fvPgH@{*8a4V}Uu)sUGxER-aRitM3F{1B2}8Rqr*No*$1 z!8WiQi8F-(2)5QsqlE#Cwb76G^Y287 z17D_l?WKX_Ydpifd|KKr&#&^8H;`CR|6L9LS|Gg+G>8+yKfeF1jsM;4cWwM1#(#`l zU%J=xzuo>rDgU1czl+%a5W4?4{#ZEkb^3?w{r~d#L-zjX_`{?7b^3?LzeMo=>G)3~ z_`e)a{_gm{lK9^NewW1m3Gm0=lD_%d%Kr=SUj*{M-IJv-!6M6b9x9ch5u>;_fH#h zCqok()Bn>HCk{rhwJs(y1uQN?|cOP?V77LuG?To_oH zOG;ahgc?anU~5UJu(~=e1k!38vDA=o+cgvJxf+1+oh|`(a!i)e!|z5jYvIpgIo?)& zd{I1hZ){RwG9x>1$@fG!#nb0Af#s?2mv033y@3M+i86&MY~ zfi`NkB#4wGZ8tT5or5;J%nsdRUO?%isa0HKV+iwvaCcyjgmP^uIYm!0Q5<^W;+ww8 z>+VTgIkK+XT{)dy{?P);04E}LFc^2G>fC?0QLCZKK&=qCIb7@Se>hcQbGFaSPpAZs zi)u7}N`Xp`_q_q%W@M*_(jv1Jms6Dwp|bpCeASxB<0} zovISz=lQi$5?1p4y0pwr+^RpFP8;+ zbzd{eO5~ni&Lu-H@jIw(72GuCmKh=w<;|Lt9LMAJmUJN&Y&Mu`+5pv5GZV)jy+8B!{ZT# zf}?7Iu`=xt3$cQDXefMYE-JD-gJobcJUx*SB^-p8qpu3V#H$(Cx7WgK;gswS!>6A0 z7oMj;?~=PSArAS+{;G#0|F!$&fxugH8hNglH4?7}7Po+Lf$%3q z+}%gjPCr7In+;`mzYjhYs0WmuStY3Mvv69k(EVNp*U(E61gApus6W6VGDYIs1n_@a z7G;w5pz0hPVGC^%v`=<`LNBvkluOui&w2*(KJD2Zj+2faR=UJ07i@Vq5;Sfv9HGj= z5OOp63lbH2AShpxO_{p|Mw$1sfHX0bi7Gn;Ot$BtZ(a7F^5N(awGE&Lq0>u{yjzfZlVbD@l}8y$i)K@Z605m397d^(VVIVg%C-6wzBIqqxk5vW-zRs9R@?)}J~(ah z@pe1wdVPE*^tXNx?4Q%vbJP}r$Vl-JfoiAQ`Oq)&P(#xjhE^OMC9x&POc~FkM5OhV zf?(piDx1mjSF#=13bb1=IxO`q@z5xr^@A5DN{^#ol{Z z;Qm~S&l4evUy~x)Whp9%n?G{O685%H-$)5c*BORUPR>KWcE;8E{v*(G1d5v2nlwcC zn-x=IQuNSVRg5p(j0zXlhw9>jtE5T?3N%MbZ?^o1N)@i`=y_|aCQ_jz(iEq!Vrda1 z%8hX;-&(U8?9_$E&Qpb1M;|pPk|OEErZ5Q;igBz28|)k{aB-#_E+$y!mT2dQzS5M3B$DEwi`F=&#PFETZ6gK6E8wNXj@+>jgiTh2 z`629L$c3~P=gVVq#Uz(0sIAK>kxDNFnmZ*gcN(RZ>1`2kZKT}t=1WE6?j`1n!X^xT z+D_DCavIGa^+=)Gn`FpA4)jRAzPpysGLBN^9d;9g8;BQ8q+s$)T*I~!EVCaRF({6I zm8m%n7Z(f!62ZB}eh7s`L640O_FYSH@b8;5pxfyqRsCjm>zZ9)a`^pAFpNje2YiVK zMEt7U9|hr);b|qw1*PsgzuHi_<_FuH%}1!2 z47xRGvs8~1gEmw(H)bIkQfpm=9otn2Z~Awg0s33gqyDa+(E4|&0s6Z*pEji)5H{z2 z`23nE1(9a2t2(I&4yBc@f;EWZrzZ=QxKmbZpfN=}m=8|g|7u=hJ-lWrY@1VyQ(x_A zkx!?ycRu7*ZuvRX*nF(GZi}O4WpW?5&g(2V@)iu@I>7?He5JNBJCwvhkhWLc@+3G^ zcBg`35_(2?o%{P|dGDTCdF@i?@q|i*Sa?t-kuWyeqC}X2c&GSU}ZgChRdD;thyxy9C)K?w3ovUEE91d+Wj#szh5Hjkx{RXuLr!( zHi?y+{`xt1P*cC#9endA;Md8S?9f&$0d8Ik{1s-(=l(7GFLKjD$@2C3bOo$i)CHB% zcT8O1op+N=tuG??6@HNdu@Dvu+PY9><(;FW@+U84F1fAPE^4McoZn2uJ9i>|LWtx) z8JA*vdofL;UZybmsJ%dukgn(GYVrw-_+)=_FXS(GaD zt1Vqc%6=oRO((9lafM)?k>JDMLDwtdFCDv$y2Z|l$?=hkdqv9Ul}YAX<&@uq;?5cF z`a2EgPT@A&zR}=202mnUpJ`CY-rmL8<&6tv4K3}IT@0OEOr8G0i7{%L?sIRP2u)v$ zCWuV_4ws;imSxh+Jr6bWi%>86u|JME2%u}?{T0n*Bxw)Py}(=FkGO6(p5n;QaehID%KJMz45yx(zP!R%3>Oq z_7Tr+kWofm#Kghw1%+u529k*Grfb4#z23;lP+18zfvQ-~8VNPP`+@k_tJYtr5@u%b)b>1n9T`46r=W1 z>F{<}iP}zemt|IFXU&>R(wJev?L4D7EVDJ2Y3P@vKDWeLldPmOUlnm7)GDgiMHlwd zMx>J#q1=;R1ErFNZnHr}@y~nCNP05O@@z!-6nrn>Z{9pT?a%z`W85}ujj(SnO@W-n ze4-W?B|@=hXDSKH4Xf8X2G9Emb_BMEJg?AyH!rw05S9hH2oF6J<*6sD+PW2PBDV@n z3y-m~+_gYsd$B%HmM8x>j$b+eSaxYi!JtSy=Y1KghoyQ6C_|PQ3*CL<46nmikj~Eq z(gI@9Yzhc%{HV5>p>lTNp!9bDeeZu*)+XiRt6nEd!*QVcgj7@VDPns;JWZ=!e&{qk z^zP|YUoMoAe30w8e+V!<{W9gxbsrMfVda`S$!Zg(4#H(~uT7Rr&V=qO>d(`YXv*ea zB4wk$agEh-N=RmTYP~11_%vPc9xhFgmTP_BhoE@n&xEdUV=tQH5Rs+uL4*`|-g|$| z5;DwH?*z?w4w3__q|@8v7UxQX46pTV%>~fIp&ONw6|3M;;+{g2&anJ2qk0Mk2;p}UVE_NSsZeEo+{0Kw=Vt$`=&z#J6yR)ud)3wN7WyN@lu(ZDuW8lp5!rxu$0yK19ow@}DI z$tb!ynj_JOdm1;BV@~jsDWrDHHBk!whA4;6FiJGDA};BjjA_YaUT(RC!ooc{j6ZRJ zKc$8w&_A-yoE)*tG)2AmTz>4oe%FI;{uNNasiZ_7g{Q5I=U4%$P5U%DrPRA@Q={{QxkhC_&1f+K~+;l{QeJ$icQ`rPwV= zJfcr5AASx<(WiEIOz$p?8e*0)Om{#mA;|(axgig{VTFufJN!6?6RZh^F+2p-3ljXa z(JOlWg6ivmlY-c@kKUS1BU_8L0~x_Ay-97y`u*kI-+2ohr?NZ~9t`Xr>%XRNl6KB6 zhBh|;OyAT!eRNdOUhJ4gGTPgVZD$L!s)UzL^Jr}?Tc^z|GvW&^XG02AQ_1Mhx=l7X zZi;PTDc(nd!_t+~=7$@AQ7h$2N`pBHiz1=vI0zp{Mn+PcFJ82>r=^i7kK+HlNzp&& zzTa@3Z6B(|@2$ddMzw+CfPiU2e}1<5RMsMyR-nhsu!gLv-kn>)v)9 zlaHJlAN@Rr$wPi9xr*HoOd&fgE(EQSd zuQTRi_{F{BA=@Ws&U5F!;~@ZpAN5+C>6b?6LB~UcLwoLaVrY)n6*K*3I=HTB#Zdjx zOKLp&oh7|rVtw|k?Id-ZM;eivCmMnL9#^$KuZIKFT(%Dhq5LNrA?mEZM2E23j|cQS z9x^ceruz6V5Klu(^02yi=@>Rw8Muw|TBgii)dgVZGTq)mS`;P@P`3 zbykBAEUcC*Zs=Brwys^rj(rG7V};2Nkm!$IWML(_^OO@La3Pq+x0aA9rGx6zUHb%t zY^5)tjq~rY_oXqrI|HOChP0$5HWu9|IG!IHa9C8UTF{&wd)ZP?R#n-A1(s|aGoq2P z!StC~x7){Jt)p)hKTI7X1iL}z3#O5y^WJqD$QYUpCJfZ&A;!$N6_|Ci;RG^jZ%@u% z1w6b~C7KF_+TDw`2F865Y%vQML#nqjnOy%Bw`?C9`u@8I%eWk|_$hJu=0v|_!qg)s0Mjj!w!j7tbm#8u4-RrTjTT@y&Jp+FJV=}7TkNoZYx zRty6(Ub{VZ%tkl4sl~;VGEr%6yMlGxcG9P-;}-f1WM&MX2e6EY42I*k-A(@GY!9LOhF zzD!snt*qRCE zx0o#iSt7@5d*on!An~C`bX8<`ZC@10mpN@DdY0XmSSvm<%azaLGPPdy8r`FHRp^gVaOHka^3KW%7wkr|E^P~o#H!ZYjJ(MX1IUWau` z;bs9`tbz+Ud^J>S7;Uv-SfQvn@^kg2Pf3SKqhghf@< zTeTt2>e7%1BxpbZ4;i~+t3C6%D{m6*xoNbsQ+FB_3Htc{Tk>Z2kYhdwbJ_2Pnu%wyGYY9_=f(DRVCr9l4MJ(mOQo6o3tpr;xqPy zq)~jyBr3mZw8|n^(lqJ#Kzaz7HD2LLl?JCZDl9eXZUyUko@5nDqXouI$&jx+e!VVrSLRV-%l6D5o7xDzZ zkmr-WYF2t?6;|wqeN414lCn2G(NCdZyW&i#nCXL3j@)jeDn`%H1chacPOKP({|)3Q zN?BxSxEIuOz00p1puYU9Z*9rcNc7mF(I?T%)O_9RE(t<-{m2c94&6(K@pO~X)AfXX zZXjRVsgHdm($M#*Z;$S!(OCS>3pH1)BGNWxx* zWvth1NpXnZ?F|p@jWK;PYEdKdvq>*$K(<*)c_MV>gsf8U=j{`r2$pkH={vs!CDZZ8 zN1}=2JK$byPyL4x=5JPw2&pq(CGYS#8M4TC1F)kiJsqSkuvQPrN@Rg8d{fI~G1h=1 zn9Xo$=3CtXEcWm`-vEs$G*%p8GkoQQxUr8JFlYTPHbkup%E&brOm`4_Rgzs-rQa`Q zwtp1S;4d}qyM)nP87o37wuD?o&>g?VK?XXo*!RVnmJj#*$;4Jd{%m{GQ>9!e{zI!wgFa#x7`IF5mg=; zYPrI`_~K??V-3YA^WAVbjg^}m-{6M1jVl^EX3F;Yi(XDoM^Fr)CeD0us!})Lqe9v~ z_pCB%2Pk&u^%LwX7%3$SN7Sq!kbd`+7%*^-9W-_AjRF@qqw#yMWtud#JBAh9#Ac7_ znbp}&c-X+@?gY$D%~>O+xI79P=8x9V-+1mNHsYH&KoitICxAy9aTmSzeGE!fFibzEa5A0K*+ua^i1~ggJ(`X-ipWH4b2{ zJIAy*J2y*o59t0eRRT-JTMzP z(918u)pkWI2F98N&ub z00jy{_#ARfp0uwJCSl4wzhB6M;0gu84Qq{8sS@r;OZ={2Pq;rI(g0A88|`yx2sOV5 z1ELr0Ru*1c?o#ROE<4f2-d)Z&UGca*+p(3BgBHfJl*dCu!nQfdwn`~9>XANbV?Ddg z=LMlzaCbBZUA2a1pBDZiov+7nuTxtW|A|R_NkBa->BKjR{R7u}9!|!!M}(fZ7GKo^ zW<%0mKc=O5BVt?We8V3HD@iLk%zb-3`p5cSGl1RsOfbwVR+&JKRC<(>e37QZ1N)*# ztz}NxBPS?}=8-U^)JZo}vL#KgIh)T1%r&UgzKX&IQ^a^NYxoLxf-ikMMCc&e_e)L( zDUH;e2JOH(vbyk&O;E@Y#N-MrKFQ>|vsEUi24~tD=yucju3|^T?Wk*cs)cWT&pe0aciu^MQ87+FX^-4Q7(k-9U%a8eok@J>(=`bMW4&HdZgA z5?YR5eldRj#{n0>;mftgDjhtZD@@A;&f za5TcdT`>-6QpX2q1#n}2YQgt2Z(G2tMtm=0q|vv$tjQQGOBb4Mx6% zy7EeQBql?$=OeP=V^ou*sU(bCWbEyTw*Ar=j78RRrB z8vY=T$@f4u$7xRML;k;?Y#4nR#JArnGGK3oX{tY0WW@hp&+?z;>A$Kn|18I-S}UWN zqkh%{teEQ3LyFoFX+^!G1}$u$Rt7*$i%0+hpuZJMFNZFW;;`d<*_hXR5qTBpx(#Yz z?oLemd@KAa@G4s}bsmanFyzQocffn^ob9~9{`%{FX%nn!2Lmc7HQrIZhqrL`K~lQ8 zI(Gq0uFXYEY_KSYDpgc%Ff%$c(33{uL8b>FBRMRsp@Qfb`w_K0W(qB{7XxQ;y+hjy=+`RXe1Vp%bT)C|3N zj`=E>{!EI5e5d7B$Iyu_TY?;}g=S86Voe@4lb3?Z#LQe{LZ|bK)b}GViK*~TsvV5> zO+Fs0#199J0@5zwX~MgUOwzn@Y@beGLdTXu2+apdVd0Bu z+fb=jR%<~+i?)?YGiS?%Lv#;oz7rHEann>F0rT4)!}j*mbX}u%AXr1Uo`4mym1Dg(yba;9Gjc*9-%?2 z(3XmC;3*$PmYX;rygY3UD*3{3AgFNXA%E%}8tm)d2c{Ma*!w%#&qBOgjs9NIU#{w#B)Up`SRJ1P?LO?gMH925JUtf=!8?(dkWKT{^-?ab z%`yi`cMe&-8H?^1xK;qIS`0w$iK;Ksl)}Aqp+VKE&ra7=Zf_K4pq!os&vfWov~A$x z;{=X|BWHqbCIallP@b>+sAPJpn07<{ifTs>bn7)2c|lZ^p#A*%I$9f6;d+yy9w7cj zgnkis@?3Bl1wFNQ^HM-}TFA>2=wyS{DbRXmbDCp~*H-{cau$xZRz*iy#9v~m^UC$} z(_H4Cypgy4;#ZE`>IhJL4a`ZpSSB1@`Wz2mksH_&dZ}Et9W8f^bJS!*RCt z?Y)&L@6U2syFwg9R)cXZ3sPNBM#+F|l&b2U6`Dtm-#GY=A1@uOVaP4KojhR99ydDi zM21~Yw^Tmklr&AZgfMd-=2v*5@Op>bqevQn)rOryMQ;-+@k}7Cn~Pkwmi&ku9BLL! zH_~Qj93?vl-=ob2Zn5nXO7R&6`E(p>&?@Z;&0rj@i|JcEpecGIagKT2P+t5(ex}Dx zxb!U>puwD*fl^Maak7T08t3GI18g{PAE;05%frz`wXuhN_oVI`8 z@M~kZ;7edf@QSSSnh395E#rxGHtBR5cW4vlMpnP5AG}}wCX^D3t-!}F6uq*M*WXG& zjPFvYYSxu1wr_nr#LozD((ktw*adPePlT|$ zq055{ZG{|Q2L+U1N<`hwB-2C!%-zNzQEqB={CeInp+7y9%k_6{h7ueAnl&a&vzczVdm8 zI|lmxjFp@x6%JgFTt27pM@$E;h8asiv&2Lnn;gCy(?%7qm@4FUJIW=dR1BkzqsfaM zps5-E{gml+Q3EYD{P}C~32)Nzln600m0}??={~Bp9Adb5;8U%uj%ppjaPw+a*I8+U z?tpcbx2#_*JuK@w^W5kd1zgTnZ3rR!G%b%j^CoHo)jjQ=p>}hWH~e_9`E2h!g);CL z^Gf5!O_TbNFC4W-QSDBK9~4GwedvnM}q9UIiI9roJcPE=k_6-ymTq0WFKnb zzR_@kITt^d4)Q7$?(r|4OQIyQC2QqvVLtREVn>H+SY(^!VUAbVd?9)+{SJ;5wsqc9 zIf`sA%}4Wr&iW#Sre;1*Hsf;yd#+STWF6nVRpcH}^{3^FVqZ7_@cH-<2F)UBFs&n> zeEQA_MRtkTB*Tj(PfAQ==O*_o?;uar_kUtllARH-$Kdjln~2H{D+o~pZl@Z=@f1~4 z0%}_}XB5jLxy|A&Bt}dydy-ObI0sy3?Ye|^dI0q{=a5-L62-1s zWG_$&$e8u;R`s|AC#6Xopgmw|@Dg#Enh=hDSunCL>3rTaMP9IwaWIP)KhTEe0K+Sx zu;UVcPej5q?Q9{2$~7dsrKrkZr=rR~LPIyNs0y(>!6IIPyrZPLYJpAmaq9c*`p{Rs z?%|hEV1Z7nxTfyWJbtsoEo{ff9idtLxcbcbR3Ju~w%u%#c{S5Ke-we{&PJJb~FkZ4pu4Zmf(A+um?dyyH2~#n~LlmI4Z&1 | %FIND_EXE% /I /C "%JAVA_HOME%" >nul -if not errorlevel 1 goto init - -echo. -echo ERROR: JAVA_HOME might be set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation if there are problems. -echo. - :init -@rem get name of script to launch with full path @rem Get command-line arguments, handling Windowz variants -SET _marker=%JAVA_HOME: =% -@rem IF NOT "%_marker%" == "%JAVA_HOME%" ECHO JAVA_HOME "%JAVA_HOME%" contains spaces. Please change to a location without spaces if this causes problems. if not "%OS%" == "Windows_NT" goto win9xME_args if "%eval[2+2]" == "4" goto 4NT_args -IF "%_marker%" == "%JAVA_HOME%" goto :win9xME_args - -set _FIXPATH= -call :fixpath "%JAVA_HOME%" -set JAVA_HOME=%_FIXPATH:~1% - -goto win9xME_args - -:fixpath -if not %1.==. ( -for /f "tokens=1* delims=;" %%a in (%1) do ( -call :shortfilename "%%a" & call :fixpath "%%b" -) -) -goto :EOF -:shortfilename -for %%i in (%1) do set _FIXPATH=%_FIXPATH%;%%~fsi -goto :EOF - - :win9xME_args @rem Slurp the command line arguments. set CMD_LINE_ARGS= @@ -103,10 +59,10 @@ set CMD_LINE_ARGS=%$ set STARTER_MAIN_CLASS=org.gradle.wrapper.GradleWrapperMain set CLASSPATH=%DIRNAME%\gradle\wrapper\gradle-wrapper.jar set WRAPPER_PROPERTIES=%DIRNAME%\gradle\wrapper\gradle-wrapper.properties -set JAVA_EXE=%JAVA_HOME%\bin\java.exe set GRADLE_OPTS=%JAVA_OPTS% %GRADLE_OPTS% -Dorg.gradle.wrapper.properties="%WRAPPER_PROPERTIES%" +@rem Execute Gradle "%JAVA_EXE%" %GRADLE_OPTS% -classpath "%CLASSPATH%" %STARTER_MAIN_CLASS% %CMD_LINE_ARGS% :end From 4d6f4c7a94686a77f7dc9b1e21e05524c77600f1 Mon Sep 17 00:00:00 2001 From: Alan Krueger Date: Fri, 23 Dec 2011 12:53:48 -0600 Subject: [PATCH 030/112] add Eclipse support --- .gitignore | 1 + build.gradle | 1 + 2 files changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index cf63247..d77754e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ .gradle/ target/ build/ +bin/ diff --git a/build.gradle b/build.gradle index 71aab8c..e9076f3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'java' apply plugin: 'maven' +apply plugin: 'eclipse' group = 'com.googlecode.jedis' archiveBaseName = 'jedis' From f010bc0f325b6579815fb9d4497317ada2b7b4c3 Mon Sep 17 00:00:00 2001 From: Shaofeng Niu Date: Tue, 14 Feb 2012 17:42:06 +0800 Subject: [PATCH 031/112] add variadic arguments support to lpush and rpush --- .../java/redis/clients/jedis/BinaryClient.java | 14 ++++++++++---- .../java/redis/clients/jedis/BinaryJedis.java | 4 ++-- .../clients/jedis/BinaryJedisCommands.java | 4 ++-- .../clients/jedis/BinaryShardedJedis.java | 6 +++--- src/main/java/redis/clients/jedis/Client.java | 18 ++++++++++++++---- .../java/redis/clients/jedis/Commands.java | 6 +++--- src/main/java/redis/clients/jedis/Jedis.java | 4 ++-- .../redis/clients/jedis/JedisCommands.java | 4 ++-- .../java/redis/clients/jedis/ShardedJedis.java | 4 ++-- .../jedis/tests/commands/ListCommandsTest.java | 11 ++++++++++- 10 files changed, 50 insertions(+), 25 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index 812defe..9997e58 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -248,12 +248,18 @@ public class BinaryClient extends Connection { sendCommand(HGETALL, key); } - public void rpush(final byte[] key, final byte[] string) { - sendCommand(RPUSH, key, string); + public void rpush(final byte[] key, final byte[]... vals) { + byte[][] args = new byte[vals.length+1][]; + args[0] = key; + System.arraycopy(vals, 0, args, 1, vals.length); + sendCommand(RPUSH, args); } - public void lpush(final byte[] key, final byte[] string) { - sendCommand(LPUSH, key, string); + public void lpush(final byte[] key, final byte[]... vals) { + byte [][] args = new byte[vals.length+1][]; + args[0] = key; + System.arraycopy(vals, 0, args, 1, vals.length); + sendCommand(LPUSH, args); } public void llen(final byte[] key) { diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 7b4cd30..de0d756 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -888,7 +888,7 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Integer reply, specifically, the number of elements inside the * list after the push operation. */ - public Long rpush(final byte[] key, final byte[] string) { + public Long rpush(final byte[] key, final byte[]... string) { checkIsInMulti(); client.rpush(key, string); return client.getIntegerReply(); @@ -909,7 +909,7 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Integer reply, specifically, the number of elements inside the * list after the push operation. */ - public Long lpush(final byte[] key, final byte[] string) { + public Long lpush(final byte[] key, final byte[]... string) { checkIsInMulti(); client.lpush(key, string); return client.getIntegerReply(); diff --git a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java index ef8aebd..8aa8344 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java +++ b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java @@ -67,9 +67,9 @@ public interface BinaryJedisCommands { Map hgetAll(byte[] key); - Long rpush(byte[] key, byte[] string); + Long rpush(byte[] key, byte[]... string); - Long lpush(byte[] key, byte[] string); + Long lpush(byte[] key, byte[]... string); Long llen(byte[] key); diff --git a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java index 9c1abd2..fb782e8 100644 --- a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java @@ -180,12 +180,12 @@ public class BinaryShardedJedis extends Sharded return j.hgetAll(key); } - public Long rpush(byte[] key, byte[] string) { + public Long rpush(byte[] key, byte[]... string) { Jedis j = getShard(key); return j.rpush(key, string); } - public Long lpush(byte[] key, byte[] string) { + public Long lpush(byte[] key, byte[]... string) { Jedis j = getShard(key); return j.lpush(key, string); } @@ -407,4 +407,4 @@ public class BinaryShardedJedis extends Sharded pipeline.setShardedJedis(this); return pipeline; } -} \ No newline at end of file +} diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index 1f493e0..3f07d8e 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -189,12 +189,22 @@ public class Client extends BinaryClient implements Commands { hgetAll(SafeEncoder.encode(key)); } - public void rpush(final String key, final String string) { - rpush(SafeEncoder.encode(key), SafeEncoder.encode(string)); + + public void rpush(final String key, final String... vals) { + final byte[][] bvals = new byte[vals.length][]; + for (int i = 0; i < bvals.length; i++) { + bvals[i] = SafeEncoder.encode(vals[i]); + } + rpush(SafeEncoder.encode(key), bvals); } - public void lpush(final String key, final String string) { - lpush(SafeEncoder.encode(key), SafeEncoder.encode(string)); + + public void lpush(final String key, final String... vals) { + final byte[][] bvals = new byte[vals.length][]; + for (int i = 0; i < bvals.length; i++) { + bvals[i] = SafeEncoder.encode(vals[i]); + } + lpush(SafeEncoder.encode(key), bvals); } public void llen(final String key) { diff --git a/src/main/java/redis/clients/jedis/Commands.java b/src/main/java/redis/clients/jedis/Commands.java index 235ee88..21e3855 100644 --- a/src/main/java/redis/clients/jedis/Commands.java +++ b/src/main/java/redis/clients/jedis/Commands.java @@ -86,9 +86,9 @@ public interface Commands { public void hgetAll(final String key); - public void rpush(final String key, final String string); + public void rpush(final String key, final String... string); - public void lpush(final String key, final String string); + public void lpush(final String key, final String... string); public void llen(final String key); @@ -259,4 +259,4 @@ public interface Commands { public void exec(); public void discard(); -} \ No newline at end of file +} diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index c71d9aa..591ac2a 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -865,7 +865,7 @@ public class Jedis extends BinaryJedis implements JedisCommands { * @return Integer reply, specifically, the number of elements inside the * list after the push operation. */ - public Long rpush(final String key, final String string) { + public Long rpush(final String key, final String... string) { checkIsInMulti(); client.rpush(key, string); return client.getIntegerReply(); @@ -886,7 +886,7 @@ public class Jedis extends BinaryJedis implements JedisCommands { * @return Integer reply, specifically, the number of elements inside the * list after the push operation. */ - public Long lpush(final String key, final String string) { + public Long lpush(final String key, final String... string) { checkIsInMulti(); client.lpush(key, string); return client.getIntegerReply(); diff --git a/src/main/java/redis/clients/jedis/JedisCommands.java b/src/main/java/redis/clients/jedis/JedisCommands.java index 603b60c..8ed6219 100644 --- a/src/main/java/redis/clients/jedis/JedisCommands.java +++ b/src/main/java/redis/clients/jedis/JedisCommands.java @@ -72,9 +72,9 @@ public interface JedisCommands { Map hgetAll(String key); - Long rpush(String key, String string); + Long rpush(String key, String... string); - Long lpush(String key, String string); + Long lpush(String key, String... string); Long llen(String key); diff --git a/src/main/java/redis/clients/jedis/ShardedJedis.java b/src/main/java/redis/clients/jedis/ShardedJedis.java index b294149..f24e394 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedis.java +++ b/src/main/java/redis/clients/jedis/ShardedJedis.java @@ -198,12 +198,12 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { return j.hgetAll(key); } - public Long rpush(String key, String string) { + public Long rpush(String key, String... string) { Jedis j = getShard(key); return j.rpush(key, string); } - public Long lpush(String key, String string) { + public Long lpush(String key, String... string) { Jedis j = getShard(key); return j.lpush(key, string); } diff --git a/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java index a2e5a4b..5653687 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java @@ -30,12 +30,17 @@ public class ListCommandsTest extends JedisCommandTestBase { assertEquals(1, size); size = jedis.rpush("foo", "foo"); assertEquals(2, size); + size = jedis.rpush("foo", "bar", "foo"); + assertEquals(4, size); + // Binary long bsize = jedis.rpush(bfoo, bbar); assertEquals(1, bsize); bsize = jedis.rpush(bfoo, bfoo); assertEquals(2, bsize); + bsize = jedis.rpush(bfoo, bbar, bfoo); + assertEquals(4, bsize); } @@ -45,12 +50,16 @@ public class ListCommandsTest extends JedisCommandTestBase { assertEquals(1, size); size = jedis.lpush("foo", "foo"); assertEquals(2, size); + size = jedis.lpush("foo", "bar", "foo"); + assertEquals(4, size); // Binary long bsize = jedis.lpush(bfoo, bbar); assertEquals(1, bsize); bsize = jedis.lpush(bfoo, bfoo); assertEquals(2, bsize); + bsize = jedis.lpush(bfoo, bbar, bfoo); + assertEquals(4, bsize); } @@ -620,4 +629,4 @@ public class ListCommandsTest extends JedisCommandTestBase { assertEquals("a", jedis.lrange("bar", 0, -1).get(0)); } -} \ No newline at end of file +} From df3c57940a324f3095371ecf1c7587089dfb7105 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Fri, 23 Mar 2012 17:02:16 +0000 Subject: [PATCH 032/112] Fixing Sharded Pipeline as the zrange should be built with a STRING_ZSET --- src/main/java/redis/clients/jedis/ShardedJedisPipeline.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java index 5ca21e1..f58e5a7 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java +++ b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java @@ -351,7 +351,7 @@ public class ShardedJedisPipeline extends Queable { Client c = getClient(key); c.zrange(key, start, end); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_SET); + return getResponse(BuilderFactory.STRING_ZSET); } public Response zrem(String key, String member) { From 9dc89626acd935af65460c0ebd071c245e68328a Mon Sep 17 00:00:00 2001 From: Ivo Ramirez Date: Thu, 15 Dec 2011 15:51:45 +0100 Subject: [PATCH 033/112] Eval and Evalsha is now supported Conflicts: src/main/java/redis/clients/jedis/Client.java src/main/java/redis/clients/jedis/Jedis.java --- .../redis/clients/jedis/BinaryClient.java | 26 +++++++ .../java/redis/clients/jedis/BinaryJedis.java | 22 ++++++ .../clients/jedis/BinaryJedisCommands.java | 1 + .../clients/jedis/BinaryShardedJedis.java | 1 + src/main/java/redis/clients/jedis/Client.java | 26 +++++++ .../java/redis/clients/jedis/Connection.java | 2 +- src/main/java/redis/clients/jedis/Jedis.java | 55 +++++++++++++- .../java/redis/clients/jedis/Protocol.java | 2 +- .../tests/commands/EvalCommandsTest.java | 76 +++++++++++++++++++ 9 files changed, 207 insertions(+), 4 deletions(-) create mode 100644 src/test/java/redis/clients/jedis/tests/commands/EvalCommandsTest.java diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index 812defe..9292b21 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -718,4 +718,30 @@ public class BinaryClient extends Connection { db = 0; super.disconnect(); } + + private void sendEvalCommand(Command command, byte[] script, List keys, List args){ + int keysSize = keys.size(); + int argsSize = args.size(); + + final byte[][] allArgs = new byte[keysSize + argsSize + 2][]; + + allArgs[0] = script; + allArgs[1] =toByteArray(keysSize); + + for(int i=0;i keys, List args){ + sendEvalCommand(EVAL, script, keys, args ); + } + + public void evalsha(byte[] sha1, List keys, List args){ + sendEvalCommand(EVALSHA, sha1, keys, args); + } } diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 7b4cd30..de27283 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -3006,4 +3006,26 @@ public class BinaryJedis implements BinaryJedisCommands { public Long getDB() { return client.getDB(); } + + /** + * Evaluates scripts using the Lua interpreter built into Redis starting from version 2.6.0. + *

+ * + * @return Script result + */ + public Object eval(byte[] script, List keys, List args) { + client.setTimeoutInfinite(); + client.eval(script, keys, args); + return client.getOne(); + } + + /** + * Evaluates scripts using the Lua interpreter built into Redis starting from version 2.6.0. + *

+ * + * @return Script result + */ + public Object eval(byte[] script, List keys) { + return eval(script,keys, new ArrayList()); + } } diff --git a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java index ef8aebd..c8479df 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java +++ b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java @@ -154,4 +154,5 @@ public interface BinaryJedisCommands { Long zremrangeByScore(byte[] key, double start, double end); Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value); + } diff --git a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java index 9c1abd2..41306c9 100644 --- a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java @@ -5,6 +5,7 @@ import redis.clients.util.Hashing; import redis.clients.util.Sharded; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index 1f493e0..c69f9a1 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -2,7 +2,9 @@ package redis.clients.jedis; import redis.clients.util.SafeEncoder; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -595,4 +597,28 @@ public class Client extends BinaryClient implements Commands { public void configGet(String pattern) { configGet(SafeEncoder.encode(pattern)); } + + public void eval(String script, List keys, String... args) { + List k = new ArrayList(); + for(String key:keys){ + k.add(SafeEncoder.encode(key)); + } + List a = new ArrayList(); + for(String arg:args){ + a.add(SafeEncoder.encode(arg)); + } + eval(SafeEncoder.encode(script),k,a); + } + + public void evalsha(String sha1, List keys, String... args) { + List k = new ArrayList(); + for(String key:keys){ + k.add(SafeEncoder.encode(key)); + } + List a = new ArrayList(); + for(String arg:args){ + a.add(SafeEncoder.encode(arg)); + } + evalsha(SafeEncoder.encode(sha1),k,a); + } } diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index 0ea973f..67a7dd6 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -82,7 +82,7 @@ public class Connection { pipelinedCommands++; return this; } - + protected Connection sendCommand(final Command cmd) { connect(); protocol.sendCommand(outputStream, cmd, new byte[0][]); diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index c71d9aa..9281ff3 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -8,7 +8,10 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.hamcrest.core.IsInstanceOf; + import redis.clients.jedis.BinaryClient.LIST_POSITION; +import redis.clients.util.SafeEncoder; public class Jedis extends BinaryJedis implements JedisCommands { public Jedis(final String host) { @@ -2688,5 +2691,53 @@ public class Jedis extends BinaryJedis implements JedisCommands { public String configSet(final String parameter, final String value) { client.configSet(parameter, value); return client.getStatusCodeReply(); - } -} + } + + public Object eval(String script, String... keys) { + List s = new ArrayList(keys.length); + for(String key : keys) + s.add(key); + + return eval(script, s); + } + + public Object eval(String script, List keys, String... args) { + client.setTimeoutInfinite(); + client.eval(script, keys, args); + + return getEvalResult(); + } + + private Object getEvalResult(){ + Object result = client.getOne(); + + if(result instanceof byte[]) + return SafeEncoder.encode((byte[])result); + + if(result instanceof List) { + List list = (List)result; + List listResult = new ArrayList(list.size()); + for(Object bin: list) + listResult.add(SafeEncoder.encode((byte[])bin)); + + return listResult; + } + + return result; + } + + public Object evalsha(String sha1, String... keys) { + List s = new ArrayList(keys.length); + for(String key : keys) + s.add(key); + + return evalsha(sha1, s); + } + + public Object evalsha(String sha1, List keys, String... args) { + checkIsInMulti(); + client.evalsha(sha1, keys, args); + + return getEvalResult(); + } +} \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index a4f1c7e..dc43e16 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -140,7 +140,7 @@ public final class Protocol { } public static enum Command { - PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE; + PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA; public final byte[] raw; diff --git a/src/test/java/redis/clients/jedis/tests/commands/EvalCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/EvalCommandsTest.java new file mode 100644 index 0000000..adcccf9 --- /dev/null +++ b/src/test/java/redis/clients/jedis/tests/commands/EvalCommandsTest.java @@ -0,0 +1,76 @@ +package redis.clients.jedis.tests.commands; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import redis.clients.jedis.exceptions.JedisDataException; +import redis.clients.jedis.exceptions.JedisException; + +public class EvalCommandsTest extends JedisCommandTestBase { + + @SuppressWarnings("unchecked") + @Test + public void evalMultiBulk() { + String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}"; + List keys = new ArrayList(); + keys.add("key1"); + keys.add("key2"); + + List response = (List)jedis.eval(script, keys, "first", "second" ); + + assertEquals(4, response.size()); + assertEquals("key1", response.get(0)); + assertEquals("key2", response.get(1)); + assertEquals("first", response.get(2)); + assertEquals("second", response.get(3)); + } + + @Test + public void evalBulk() { + String script = "return KEYS[1]"; + List keys = new ArrayList(); + keys.add("key1"); + + String response = (String)jedis.eval(script, keys); + + assertEquals("key1", response); + } + + @Test + public void evalInt() { + String script = "return 2"; + List keys = new ArrayList(); + keys.add("key1"); + + Long response = (Long)jedis.eval(script, keys); + + assertEquals(new Long(2), response); + } + + @Test + public void evalNoArgs() { + String script = "return KEYS[1]"; + + String response = (String)jedis.eval(script, "key1"); + + assertEquals("key1", response); + } + + @SuppressWarnings("unchecked") + @Test + public void evalsha() { + jedis.set("foo", "bar"); + jedis.eval("return redis.call('get','foo')"); + String result = (String)jedis.evalsha("6b1bf486c81ceb7edf3c093f4c48582e38c0e791"); + + assertEquals("bar", result); + } + + @SuppressWarnings("unchecked") + @Test(expected=JedisDataException.class) + public void evalshaShaNotFound() { + Exception result = (Exception)jedis.evalsha("ffffffffffffffffffffffffffffffffffffffff"); + } +} \ No newline at end of file From 3c86ebcd362c49868a936c230fc0cc0a5837252e Mon Sep 17 00:00:00 2001 From: Ivo Ramirez Date: Thu, 15 Dec 2011 17:45:14 +0100 Subject: [PATCH 034/112] Script commands are supported. --- .../redis/clients/jedis/BinaryClient.java | 21 ++++ .../java/redis/clients/jedis/BinaryJedis.java | 24 +++- src/main/java/redis/clients/jedis/Client.java | 14 +++ src/main/java/redis/clients/jedis/Jedis.java | 22 ++++ .../java/redis/clients/jedis/Protocol.java | 4 +- .../tests/commands/ScriptingCommandsTest.java | 107 ++++++++++++++++++ 6 files changed, 189 insertions(+), 3 deletions(-) create mode 100644 src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index 9292b21..aa5fbad 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -744,4 +744,25 @@ public class BinaryClient extends Connection { public void evalsha(byte[] sha1, List keys, List args){ sendEvalCommand(EVALSHA, sha1, keys, args); } + + public void scriptFlush(){ + sendCommand(SCRIPT, Keyword.FLUSH.raw); + } + + public void scriptExists(byte[]... sha1){ + byte[][] args = new byte[sha1.length + 1][]; + args[0] = Keyword.EXISTS.raw; + for(int i=0;i keys) { return eval(script,keys, new ArrayList()); } + + public byte[] scriptFlush(){ + client.scriptFlush(); + return client.getBinaryBulkReply(); + } + + public List scriptExists(byte[]... sha1){ + client.scriptExists(sha1); + return client.getBinaryMultiBulkReply(); + } + + public byte[] scriptLoad(byte[] script){ + client.scriptLoad(script); + return client.getBinaryBulkReply(); + } + + public void scriptKill(){ + client.scriptKill(); + } } diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index c69f9a1..97b3e66 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -1,5 +1,6 @@ package redis.clients.jedis; +import redis.clients.jedis.Protocol.Keyword; import redis.clients.util.SafeEncoder; import java.util.ArrayList; @@ -9,6 +10,7 @@ import java.util.Map; import java.util.Map.Entry; import static redis.clients.jedis.Protocol.toByteArray; +import static redis.clients.jedis.Protocol.Command.SCRIPT; public class Client extends BinaryClient implements Commands { public Client(final String host) { @@ -621,4 +623,16 @@ public class Client extends BinaryClient implements Commands { } evalsha(SafeEncoder.encode(sha1),k,a); } + + public void scriptExists(String... sha1){ + final byte[][] bsha1 = new byte[sha1.length][]; + for (int i = 0; i < bsha1.length; i++) { + bsha1[i] = SafeEncoder.encode(sha1[i]); + } + scriptExists(bsha1); + } + + public void scriptLoad(String script){ + scriptLoad(SafeEncoder.encode(script)); + } } diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 9281ff3..303cb26 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -2740,4 +2740,26 @@ public class Jedis extends BinaryJedis implements JedisCommands { return getEvalResult(); } + + public Boolean scriptExists(String sha1){ + String[] a = new String[1]; + a[0] = sha1; + return scriptExists(a).get(0); + } + + public List scriptExists(String... sha1){ + client.scriptExists(sha1); + List result = client.getObjectMultiBulkReply(); + List exists = new ArrayList(); + + for(Object value : result) + exists.add(((Long)value) == 1); + + return exists; + } + + public String scriptLoad(String script){ + client.scriptLoad(script); + return client.getBulkReply(); + } } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index dc43e16..72756df 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -140,7 +140,7 @@ public final class Protocol { } public static enum Command { - PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA; + PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT; public final byte[] raw; @@ -150,7 +150,7 @@ public final class Protocol { } public static enum Keyword { - AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT; + AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT, FLUSH, EXISTS, LOAD, KILL; public final byte[] raw; Keyword() { diff --git a/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java new file mode 100644 index 0000000..4270ec1 --- /dev/null +++ b/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java @@ -0,0 +1,107 @@ +package redis.clients.jedis.tests.commands; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import redis.clients.jedis.exceptions.JedisDataException; +import redis.clients.jedis.exceptions.JedisException; + +public class ScriptingCommandsTest extends JedisCommandTestBase { + + @SuppressWarnings("unchecked") + @Test + public void evalMultiBulk() { + String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}"; + List keys = new ArrayList(); + keys.add("key1"); + keys.add("key2"); + + List response = (List)jedis.eval(script, keys, "first", "second" ); + + assertEquals(4, response.size()); + assertEquals("key1", response.get(0)); + assertEquals("key2", response.get(1)); + assertEquals("first", response.get(2)); + assertEquals("second", response.get(3)); + } + + @Test + public void evalBulk() { + String script = "return KEYS[1]"; + List keys = new ArrayList(); + keys.add("key1"); + + String response = (String)jedis.eval(script, keys); + + assertEquals("key1", response); + } + + @Test + public void evalInt() { + String script = "return 2"; + List keys = new ArrayList(); + keys.add("key1"); + + Long response = (Long)jedis.eval(script, keys); + + assertEquals(new Long(2), response); + } + + @Test + public void evalNoArgs() { + String script = "return KEYS[1]"; + + String response = (String)jedis.eval(script, "key1"); + + assertEquals("key1", response); + } + + @SuppressWarnings("unchecked") + @Test + public void evalsha() { + jedis.set("foo", "bar"); + jedis.eval("return redis.call('get','foo')"); + String result = (String)jedis.evalsha("6b1bf486c81ceb7edf3c093f4c48582e38c0e791"); + + assertEquals("bar", result); + } + + @SuppressWarnings("unchecked") + @Test(expected=JedisDataException.class) + public void evalshaShaNotFound() { + jedis.evalsha("ffffffffffffffffffffffffffffffffffffffff"); + } + + @SuppressWarnings("unchecked") + @Test + public void scriptFlush() { + jedis.set("foo", "bar"); + jedis.eval("return redis.call('get','foo')"); + jedis.scriptFlush(); + assertFalse(jedis.scriptExists("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); + } + + @SuppressWarnings("unchecked") + @Test + public void scriptExists() { + jedis.scriptLoad("return redis.call('get','foo')"); + List exists = jedis.scriptExists("ffffffffffffffffffffffffffffffffffffffff","6b1bf486c81ceb7edf3c093f4c48582e38c0e791"); + assertFalse(exists.get(0)); + assertTrue(exists.get(1)); + } + + @SuppressWarnings("unchecked") + @Test + public void scriptLoad() { + jedis.scriptLoad("return redis.call('get','foo')"); + assertTrue(jedis.scriptExists("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); + } + + @SuppressWarnings("unchecked") + @Test + public void scriptKill() { + jedis.scriptKill(); + } +} \ No newline at end of file From 96d405a6e3539f4a99f73b826c2e0b424dbb1fdf Mon Sep 17 00:00:00 2001 From: ivowiblo Date: Sat, 14 Apr 2012 09:10:00 -0300 Subject: [PATCH 035/112] scripting support --- .../tests/commands/EvalCommandsTest.java | 76 ------------------- 1 file changed, 76 deletions(-) delete mode 100644 src/test/java/redis/clients/jedis/tests/commands/EvalCommandsTest.java diff --git a/src/test/java/redis/clients/jedis/tests/commands/EvalCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/EvalCommandsTest.java deleted file mode 100644 index adcccf9..0000000 --- a/src/test/java/redis/clients/jedis/tests/commands/EvalCommandsTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package redis.clients.jedis.tests.commands; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - -import redis.clients.jedis.exceptions.JedisDataException; -import redis.clients.jedis.exceptions.JedisException; - -public class EvalCommandsTest extends JedisCommandTestBase { - - @SuppressWarnings("unchecked") - @Test - public void evalMultiBulk() { - String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}"; - List keys = new ArrayList(); - keys.add("key1"); - keys.add("key2"); - - List response = (List)jedis.eval(script, keys, "first", "second" ); - - assertEquals(4, response.size()); - assertEquals("key1", response.get(0)); - assertEquals("key2", response.get(1)); - assertEquals("first", response.get(2)); - assertEquals("second", response.get(3)); - } - - @Test - public void evalBulk() { - String script = "return KEYS[1]"; - List keys = new ArrayList(); - keys.add("key1"); - - String response = (String)jedis.eval(script, keys); - - assertEquals("key1", response); - } - - @Test - public void evalInt() { - String script = "return 2"; - List keys = new ArrayList(); - keys.add("key1"); - - Long response = (Long)jedis.eval(script, keys); - - assertEquals(new Long(2), response); - } - - @Test - public void evalNoArgs() { - String script = "return KEYS[1]"; - - String response = (String)jedis.eval(script, "key1"); - - assertEquals("key1", response); - } - - @SuppressWarnings("unchecked") - @Test - public void evalsha() { - jedis.set("foo", "bar"); - jedis.eval("return redis.call('get','foo')"); - String result = (String)jedis.evalsha("6b1bf486c81ceb7edf3c093f4c48582e38c0e791"); - - assertEquals("bar", result); - } - - @SuppressWarnings("unchecked") - @Test(expected=JedisDataException.class) - public void evalshaShaNotFound() { - Exception result = (Exception)jedis.evalsha("ffffffffffffffffffffffffffffffffffffffff"); - } -} \ No newline at end of file From 9bf19c623725fd75e3d445d156f0bad0d7ec5d94 Mon Sep 17 00:00:00 2001 From: Ivo Ramirez Date: Thu, 15 Dec 2011 17:56:14 +0100 Subject: [PATCH 036/112] Binary scripting API is tested --- .../java/redis/clients/jedis/BinaryJedis.java | 4 ++-- .../java/redis/clients/jedis/Connection.java | 7 +++++++ src/main/java/redis/clients/jedis/Jedis.java | 6 +++--- .../tests/commands/ScriptingCommandsTest.java | 18 ++++++++++++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index de7aeec..20fd083 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -3037,9 +3037,9 @@ public class BinaryJedis implements BinaryJedisCommands { return client.getBinaryBulkReply(); } - public List scriptExists(byte[]... sha1){ + public List scriptExists(byte[]... sha1){ client.scriptExists(sha1); - return client.getBinaryMultiBulkReply(); + return client.getIntegerMultiBulkReply(); } public byte[] scriptLoad(byte[] script){ diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index 67a7dd6..09e0453 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -205,6 +205,13 @@ public class Connection { pipelinedCommands--; return (List) protocol.read(inputStream); } + + @SuppressWarnings("unchecked") + public List getIntegerMultiBulkReply() { + flush(); + pipelinedCommands--; + return (List) protocol.read(inputStream); + } public List getAll() { return getAll(0); diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 303cb26..78561a5 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -2749,11 +2749,11 @@ public class Jedis extends BinaryJedis implements JedisCommands { public List scriptExists(String... sha1){ client.scriptExists(sha1); - List result = client.getObjectMultiBulkReply(); + List result = client.getIntegerMultiBulkReply(); List exists = new ArrayList(); - for(Object value : result) - exists.add(((Long)value) == 1); + for(Long value : result) + exists.add(value == 1); return exists; } diff --git a/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java index 4270ec1..07b0059 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java @@ -7,6 +7,7 @@ import org.junit.Test; import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.exceptions.JedisException; +import redis.clients.util.SafeEncoder; public class ScriptingCommandsTest extends JedisCommandTestBase { @@ -92,6 +93,15 @@ public class ScriptingCommandsTest extends JedisCommandTestBase { assertTrue(exists.get(1)); } + @SuppressWarnings("unchecked") + @Test + public void scriptExistsBinary() { + jedis.scriptLoad(SafeEncoder.encode("return redis.call('get','foo')")); + List exists = jedis.scriptExists(SafeEncoder.encode("ffffffffffffffffffffffffffffffffffffffff"),SafeEncoder.encode("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); + assertEquals(new Long(0), exists.get(0)); + assertEquals(new Long(1), exists.get(1)); + } + @SuppressWarnings("unchecked") @Test public void scriptLoad() { @@ -99,6 +109,14 @@ public class ScriptingCommandsTest extends JedisCommandTestBase { assertTrue(jedis.scriptExists("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); } + @SuppressWarnings("unchecked") + @Test + public void scriptLoadBinary() { + jedis.scriptLoad(SafeEncoder.encode("return redis.call('get','foo')")); + List exists = jedis.scriptExists(SafeEncoder.encode("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); + assertEquals(new Long(1), exists.get(0)); + } + @SuppressWarnings("unchecked") @Test public void scriptKill() { From df1dfce3271f2c44c24edb5850a2868a91260ef7 Mon Sep 17 00:00:00 2001 From: Ivo Ramirez Date: Thu, 15 Dec 2011 18:44:44 +0100 Subject: [PATCH 037/112] SCRIPT KILL command fixed --- src/main/java/redis/clients/jedis/BinaryJedis.java | 3 ++- .../jedis/tests/commands/ScriptingCommandsTest.java | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 20fd083..f0b9d73 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -3047,7 +3047,8 @@ public class BinaryJedis implements BinaryJedisCommands { return client.getBinaryBulkReply(); } - public void scriptKill(){ + public byte[] scriptKill(){ client.scriptKill(); + return client.getBinaryBulkReply(); } } diff --git a/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java index 07b0059..78825a9 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java @@ -120,6 +120,11 @@ public class ScriptingCommandsTest extends JedisCommandTestBase { @SuppressWarnings("unchecked") @Test public void scriptKill() { - jedis.scriptKill(); - } + try { + jedis.scriptKill(); + } + catch(JedisDataException e) { + assertEquals("ERR No scripts in execution right now.", e.getMessage()); + } + } } \ No newline at end of file From ef08981ba3593a4c8d4725e04aeac6f202f9ff42 Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Sat, 14 Apr 2012 10:44:40 -0300 Subject: [PATCH 038/112] add makefile to run tests easier --- Makefile | 26 ++++ conf/redis.conf | 332 ----------------------------------------------- conf/redis2.conf | 332 ----------------------------------------------- 3 files changed, 26 insertions(+), 664 deletions(-) create mode 100644 Makefile delete mode 100644 conf/redis.conf delete mode 100644 conf/redis2.conf diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0e31379 --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +define REDIS1_CONF +daemonize yes +port 6379 +requirepass foobared +pidfile /tmp/redis1.pid +endef + +define REDIS2_CONF +daemonize yes +port 6380 +requirepass foobared +pidfile /tmp/redis2.pid +endef + +export REDIS1_CONF +export REDIS2_CONF +test: + echo "$$REDIS1_CONF" | redis-server - + echo "$$REDIS2_CONF" | redis-server - + + mvn clean compile test + + kill `cat /tmp/redis1.pid` + kill `cat /tmp/redis2.pid` + +.PHONY: test diff --git a/conf/redis.conf b/conf/redis.conf deleted file mode 100644 index eceedb6..0000000 --- a/conf/redis.conf +++ /dev/null @@ -1,332 +0,0 @@ -# Redis configuration file example - -# Note on units: when memory size is needed, it is possible to specifiy -# it in the usual form of 1k 5GB 4M and so forth: -# -# 1k => 1000 bytes -# 1kb => 1024 bytes -# 1m => 1000000 bytes -# 1mb => 1024*1024 bytes -# 1g => 1000000000 bytes -# 1gb => 1024*1024*1024 bytes -# -# units are case insensitive so 1GB 1Gb 1gB are all the same. - -# By default Redis does not run as a daemon. Use 'yes' if you need it. -# Note that Redis will write a pid file in /var/run/redis.pid when daemonized. -daemonize no - -# When running daemonized, Redis writes a pid file in /var/run/redis.pid by -# default. You can specify a custom pid file location here. -pidfile /var/run/redis.pid - -# Accept connections on the specified port, default is 6379 -port 6379 - -# If you want you can bind a single interface, if the bind option is not -# specified all the interfaces will listen for incoming connections. -# -# bind 127.0.0.1 - -# Close the connection after a client is idle for N seconds (0 to disable) -timeout 300 - -# Set server verbosity to 'debug' -# it can be one of: -# debug (a lot of information, useful for development/testing) -# verbose (many rarely useful info, but not a mess like the debug level) -# notice (moderately verbose, what you want in production probably) -# warning (only very important / critical messages are logged) -loglevel verbose - -# Specify the log file name. Also 'stdout' can be used to force -# Redis to log on the standard output. Note that if you use standard -# output for logging but daemonize, logs will be sent to /dev/null -logfile stdout - -# Set the number of databases. The default database is DB 0, you can select -# a different one on a per-connection basis using SELECT where -# dbid is a number between 0 and 'databases'-1 -databases 16 - -################################ SNAPSHOTTING ################################# -# -# Save the DB on disk: -# -# save -# -# Will save the DB if both the given number of seconds and the given -# number of write operations against the DB occurred. -# -# In the example below the behaviour will be to save: -# after 900 sec (15 min) if at least 1 key changed -# after 300 sec (5 min) if at least 10 keys changed -# after 60 sec if at least 10000 keys changed -# -# Note: you can disable saving at all commenting all the "save" lines. - -save 900 1 -save 300 10 -save 60 10000 - -# Compress string objects using LZF when dump .rdb databases? -# For default that's set to 'yes' as it's almost always a win. -# If you want to save some CPU in the saving child set it to 'no' but -# the dataset will likely be bigger if you have compressible values or keys. -rdbcompression yes - -# The filename where to dump the DB -dbfilename dump.rdb - -# The working directory. -# -# The DB will be written inside this directory, with the filename specified -# above using the 'dbfilename' configuration directive. -# -# Also the Append Only File will be created inside this directory. -# -# Note that you must specify a directory here, not a file name. -dir ./ - -################################# REPLICATION ################################# - -# Master-Slave replication. Use slaveof to make a Redis instance a copy of -# another Redis server. Note that the configuration is local to the slave -# so for example it is possible to configure the slave to save the DB with a -# different interval, or to listen to another port, and so on. -# -# slaveof - -# If the master is password protected (using the "requirepass" configuration -# directive below) it is possible to tell the slave to authenticate before -# starting the replication synchronization process, otherwise the master will -# refuse the slave request. -# -# masterauth - -################################## SECURITY ################################### - -# Require clients to issue AUTH before processing any other -# commands. This might be useful in environments in which you do not trust -# others with access to the host running redis-server. -# -# This should stay commented out for backward compatibility and because most -# people do not need auth (e.g. they run their own servers). -# -# Warning: since Redis is pretty fast an outside user can try up to -# 150k passwords per second against a good box. This means that you should -# use a very strong password otherwise it will be very easy to break. -# -requirepass foobared - -################################### LIMITS #################################### - -# Set the max number of connected clients at the same time. By default there -# is no limit, and it's up to the number of file descriptors the Redis process -# is able to open. The special value '0' means no limits. -# Once the limit is reached Redis will close all the new connections sending -# an error 'max number of clients reached'. -# -# maxclients 128 - -# Don't use more memory than the specified amount of bytes. -# When the memory limit is reached Redis will try to remove keys with an -# EXPIRE set. It will try to start freeing keys that are going to expire -# in little time and preserve keys with a longer time to live. -# Redis will also try to remove objects from free lists if possible. -# -# If all this fails, Redis will start to reply with errors to commands -# that will use more memory, like SET, LPUSH, and so on, and will continue -# to reply to most read-only commands like GET. -# -# WARNING: maxmemory can be a good idea mainly if you want to use Redis as a -# 'state' server or cache, not as a real DB. When Redis is used as a real -# database the memory usage will grow over the weeks, it will be obvious if -# it is going to use too much memory in the long run, and you'll have the time -# to upgrade. With maxmemory after the limit is reached you'll start to get -# errors for write operations, and this may even lead to DB inconsistency. -# -# maxmemory - -############################## APPEND ONLY MODE ############################### - -# By default Redis asynchronously dumps the dataset on disk. If you can live -# with the idea that the latest records will be lost if something like a crash -# happens this is the preferred way to run Redis. If instead you care a lot -# about your data and don't want to that a single record can get lost you should -# enable the append only mode: when this mode is enabled Redis will append -# every write operation received in the file appendonly.aof. This file will -# be read on startup in order to rebuild the full dataset in memory. -# -# Note that you can have both the async dumps and the append only file if you -# like (you have to comment the "save" statements above to disable the dumps). -# Still if append only mode is enabled Redis will load the data from the -# log file at startup ignoring the dump.rdb file. -# -# IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append -# log file in background when it gets too big. - -appendonly no - -# The name of the append only file (default: "appendonly.aof") -# appendfilename appendonly.aof - -# The fsync() call tells the Operating System to actually write data on disk -# instead to wait for more data in the output buffer. Some OS will really flush -# data on disk, some other OS will just try to do it ASAP. -# -# Redis supports three different modes: -# -# no: don't fsync, just let the OS flush the data when it wants. Faster. -# always: fsync after every write to the append only log . Slow, Safest. -# everysec: fsync only if one second passed since the last fsync. Compromise. -# -# The default is "everysec" that's usually the right compromise between -# speed and data safety. It's up to you to understand if you can relax this to -# "no" that will will let the operating system flush the output buffer when -# it wants, for better performances (but if you can live with the idea of -# some data loss consider the default persistence mode that's snapshotting), -# or on the contrary, use "always" that's very slow but a bit safer than -# everysec. -# -# If unsure, use "everysec". - -# appendfsync always -appendfsync everysec -# appendfsync no - -# When the AOF fsync policy is set to always or everysec, and a background -# saving process (a background save or AOF log background rewriting) is -# performing a lot of I/O against the disk, in some Linux configurations -# Redis may block too long on the fsync() call. Note that there is no fix for -# this currently, as even performing fsync in a different thread will block -# our synchronous write(2) call. -# -# In order to mitigate this problem it's possible to use the following option -# that will prevent fsync() from being called in the main process while a -# BGSAVE or BGREWRITEAOF is in progress. -# -# This means that while another child is saving the durability of Redis is -# the same as "appendfsync none", that in pratical terms means that it is -# possible to lost up to 30 seconds of log in the worst scenario (with the -# default Linux settings). -# -# If you have latency problems turn this to "yes". Otherwise leave it as -# "no" that is the safest pick from the point of view of durability. -no-appendfsync-on-rewrite no - -################################ VIRTUAL MEMORY ############################### - -# Virtual Memory allows Redis to work with datasets bigger than the actual -# amount of RAM needed to hold the whole dataset in memory. -# In order to do so very used keys are taken in memory while the other keys -# are swapped into a swap file, similarly to what operating systems do -# with memory pages. -# -# To enable VM just set 'vm-enabled' to yes, and set the following three -# VM parameters accordingly to your needs. - -vm-enabled no -# vm-enabled yes - -# This is the path of the Redis swap file. As you can guess, swap files -# can't be shared by different Redis instances, so make sure to use a swap -# file for every redis process you are running. Redis will complain if the -# swap file is already in use. -# -# The best kind of storage for the Redis swap file (that's accessed at random) -# is a Solid State Disk (SSD). -# -# *** WARNING *** if you are using a shared hosting the default of putting -# the swap file under /tmp is not secure. Create a dir with access granted -# only to Redis user and configure Redis to create the swap file there. -vm-swap-file /tmp/redis.swap - -# vm-max-memory configures the VM to use at max the specified amount of -# RAM. Everything that deos not fit will be swapped on disk *if* possible, that -# is, if there is still enough contiguous space in the swap file. -# -# With vm-max-memory 0 the system will swap everything it can. Not a good -# default, just specify the max amount of RAM you can in bytes, but it's -# better to leave some margin. For instance specify an amount of RAM -# that's more or less between 60 and 80% of your free RAM. -vm-max-memory 0 - -# Redis swap files is split into pages. An object can be saved using multiple -# contiguous pages, but pages can't be shared between different objects. -# So if your page is too big, small objects swapped out on disk will waste -# a lot of space. If you page is too small, there is less space in the swap -# file (assuming you configured the same number of total swap file pages). -# -# If you use a lot of small objects, use a page size of 64 or 32 bytes. -# If you use a lot of big objects, use a bigger page size. -# If unsure, use the default :) -vm-page-size 32 - -# Number of total memory pages in the swap file. -# Given that the page table (a bitmap of free/used pages) is taken in memory, -# every 8 pages on disk will consume 1 byte of RAM. -# -# The total swap size is vm-page-size * vm-pages -# -# With the default of 32-bytes memory pages and 134217728 pages Redis will -# use a 4 GB swap file, that will use 16 MB of RAM for the page table. -# -# It's better to use the smallest acceptable value for your application, -# but the default is large in order to work in most conditions. -vm-pages 134217728 - -# Max number of VM I/O threads running at the same time. -# This threads are used to read/write data from/to swap file, since they -# also encode and decode objects from disk to memory or the reverse, a bigger -# number of threads can help with big objects even if they can't help with -# I/O itself as the physical device may not be able to couple with many -# reads/writes operations at the same time. -# -# The special value of 0 turn off threaded I/O and enables the blocking -# Virtual Memory implementation. -vm-max-threads 4 - -############################### ADVANCED CONFIG ############################### - -# Glue small output buffers together in order to send small replies in a -# single TCP packet. Uses a bit more CPU but most of the times it is a win -# in terms of number of queries per second. Use 'yes' if unsure. -glueoutputbuf yes - -# Hashes are encoded in a special way (much more memory efficient) when they -# have at max a given numer of elements, and the biggest element does not -# exceed a given threshold. You can configure this limits with the following -# configuration directives. -hash-max-zipmap-entries 64 -hash-max-zipmap-value 512 - -# Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in -# order to help rehashing the main Redis hash table (the one mapping top-level -# keys to values). The hash table implementation redis uses (see dict.c) -# performs a lazy rehashing: the more operation you run into an hash table -# that is rhashing, the more rehashing "steps" are performed, so if the -# server is idle the rehashing is never complete and some more memory is used -# by the hash table. -# -# The default is to use this millisecond 10 times every second in order to -# active rehashing the main dictionaries, freeing memory when possible. -# -# If unsure: -# use "activerehashing no" if you have hard latency requirements and it is -# not a good thing in your environment that Redis can reply form time to time -# to queries with 2 milliseconds delay. -# -# use "activerehashing yes" if you don't have such hard requirements but -# want to free memory asap when possible. -activerehashing yes - -################################## INCLUDES ################################### - -# Include one or more other config files here. This is useful if you -# have a standard template that goes to all redis server but also need -# to customize a few per-server settings. Include files can include -# other files, so use this wisely. -# -# include /path/to/local.conf -# include /path/to/other.conf diff --git a/conf/redis2.conf b/conf/redis2.conf deleted file mode 100644 index c59e989..0000000 --- a/conf/redis2.conf +++ /dev/null @@ -1,332 +0,0 @@ -# Redis configuration file example - -# Note on units: when memory size is needed, it is possible to specifiy -# it in the usual form of 1k 5GB 4M and so forth: -# -# 1k => 1000 bytes -# 1kb => 1024 bytes -# 1m => 1000000 bytes -# 1mb => 1024*1024 bytes -# 1g => 1000000000 bytes -# 1gb => 1024*1024*1024 bytes -# -# units are case insensitive so 1GB 1Gb 1gB are all the same. - -# By default Redis does not run as a daemon. Use 'yes' if you need it. -# Note that Redis will write a pid file in /var/run/redis.pid when daemonized. -daemonize no - -# When running daemonized, Redis writes a pid file in /var/run/redis.pid by -# default. You can specify a custom pid file location here. -pidfile /var/run/redis.pid - -# Accept connections on the specified port, default is 6379 -port 6380 - -# If you want you can bind a single interface, if the bind option is not -# specified all the interfaces will listen for incoming connections. -# -# bind 127.0.0.1 - -# Close the connection after a client is idle for N seconds (0 to disable) -timeout 300 - -# Set server verbosity to 'debug' -# it can be one of: -# debug (a lot of information, useful for development/testing) -# verbose (many rarely useful info, but not a mess like the debug level) -# notice (moderately verbose, what you want in production probably) -# warning (only very important / critical messages are logged) -loglevel verbose - -# Specify the log file name. Also 'stdout' can be used to force -# Redis to log on the standard output. Note that if you use standard -# output for logging but daemonize, logs will be sent to /dev/null -logfile stdout - -# Set the number of databases. The default database is DB 0, you can select -# a different one on a per-connection basis using SELECT where -# dbid is a number between 0 and 'databases'-1 -databases 16 - -################################ SNAPSHOTTING ################################# -# -# Save the DB on disk: -# -# save -# -# Will save the DB if both the given number of seconds and the given -# number of write operations against the DB occurred. -# -# In the example below the behaviour will be to save: -# after 900 sec (15 min) if at least 1 key changed -# after 300 sec (5 min) if at least 10 keys changed -# after 60 sec if at least 10000 keys changed -# -# Note: you can disable saving at all commenting all the "save" lines. - -save 900 1 -save 300 10 -save 60 10000 - -# Compress string objects using LZF when dump .rdb databases? -# For default that's set to 'yes' as it's almost always a win. -# If you want to save some CPU in the saving child set it to 'no' but -# the dataset will likely be bigger if you have compressible values or keys. -rdbcompression yes - -# The filename where to dump the DB -dbfilename dump.rdb - -# The working directory. -# -# The DB will be written inside this directory, with the filename specified -# above using the 'dbfilename' configuration directive. -# -# Also the Append Only File will be created inside this directory. -# -# Note that you must specify a directory here, not a file name. -dir ./ - -################################# REPLICATION ################################# - -# Master-Slave replication. Use slaveof to make a Redis instance a copy of -# another Redis server. Note that the configuration is local to the slave -# so for example it is possible to configure the slave to save the DB with a -# different interval, or to listen to another port, and so on. -# -# slaveof - -# If the master is password protected (using the "requirepass" configuration -# directive below) it is possible to tell the slave to authenticate before -# starting the replication synchronization process, otherwise the master will -# refuse the slave request. -# -# masterauth - -################################## SECURITY ################################### - -# Require clients to issue AUTH before processing any other -# commands. This might be useful in environments in which you do not trust -# others with access to the host running redis-server. -# -# This should stay commented out for backward compatibility and because most -# people do not need auth (e.g. they run their own servers). -# -# Warning: since Redis is pretty fast an outside user can try up to -# 150k passwords per second against a good box. This means that you should -# use a very strong password otherwise it will be very easy to break. -# -requirepass foobared - -################################### LIMITS #################################### - -# Set the max number of connected clients at the same time. By default there -# is no limit, and it's up to the number of file descriptors the Redis process -# is able to open. The special value '0' means no limits. -# Once the limit is reached Redis will close all the new connections sending -# an error 'max number of clients reached'. -# -# maxclients 128 - -# Don't use more memory than the specified amount of bytes. -# When the memory limit is reached Redis will try to remove keys with an -# EXPIRE set. It will try to start freeing keys that are going to expire -# in little time and preserve keys with a longer time to live. -# Redis will also try to remove objects from free lists if possible. -# -# If all this fails, Redis will start to reply with errors to commands -# that will use more memory, like SET, LPUSH, and so on, and will continue -# to reply to most read-only commands like GET. -# -# WARNING: maxmemory can be a good idea mainly if you want to use Redis as a -# 'state' server or cache, not as a real DB. When Redis is used as a real -# database the memory usage will grow over the weeks, it will be obvious if -# it is going to use too much memory in the long run, and you'll have the time -# to upgrade. With maxmemory after the limit is reached you'll start to get -# errors for write operations, and this may even lead to DB inconsistency. -# -# maxmemory - -############################## APPEND ONLY MODE ############################### - -# By default Redis asynchronously dumps the dataset on disk. If you can live -# with the idea that the latest records will be lost if something like a crash -# happens this is the preferred way to run Redis. If instead you care a lot -# about your data and don't want to that a single record can get lost you should -# enable the append only mode: when this mode is enabled Redis will append -# every write operation received in the file appendonly.aof. This file will -# be read on startup in order to rebuild the full dataset in memory. -# -# Note that you can have both the async dumps and the append only file if you -# like (you have to comment the "save" statements above to disable the dumps). -# Still if append only mode is enabled Redis will load the data from the -# log file at startup ignoring the dump.rdb file. -# -# IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append -# log file in background when it gets too big. - -appendonly no - -# The name of the append only file (default: "appendonly.aof") -# appendfilename appendonly.aof - -# The fsync() call tells the Operating System to actually write data on disk -# instead to wait for more data in the output buffer. Some OS will really flush -# data on disk, some other OS will just try to do it ASAP. -# -# Redis supports three different modes: -# -# no: don't fsync, just let the OS flush the data when it wants. Faster. -# always: fsync after every write to the append only log . Slow, Safest. -# everysec: fsync only if one second passed since the last fsync. Compromise. -# -# The default is "everysec" that's usually the right compromise between -# speed and data safety. It's up to you to understand if you can relax this to -# "no" that will will let the operating system flush the output buffer when -# it wants, for better performances (but if you can live with the idea of -# some data loss consider the default persistence mode that's snapshotting), -# or on the contrary, use "always" that's very slow but a bit safer than -# everysec. -# -# If unsure, use "everysec". - -# appendfsync always -appendfsync everysec -# appendfsync no - -# When the AOF fsync policy is set to always or everysec, and a background -# saving process (a background save or AOF log background rewriting) is -# performing a lot of I/O against the disk, in some Linux configurations -# Redis may block too long on the fsync() call. Note that there is no fix for -# this currently, as even performing fsync in a different thread will block -# our synchronous write(2) call. -# -# In order to mitigate this problem it's possible to use the following option -# that will prevent fsync() from being called in the main process while a -# BGSAVE or BGREWRITEAOF is in progress. -# -# This means that while another child is saving the durability of Redis is -# the same as "appendfsync none", that in pratical terms means that it is -# possible to lost up to 30 seconds of log in the worst scenario (with the -# default Linux settings). -# -# If you have latency problems turn this to "yes". Otherwise leave it as -# "no" that is the safest pick from the point of view of durability. -no-appendfsync-on-rewrite no - -################################ VIRTUAL MEMORY ############################### - -# Virtual Memory allows Redis to work with datasets bigger than the actual -# amount of RAM needed to hold the whole dataset in memory. -# In order to do so very used keys are taken in memory while the other keys -# are swapped into a swap file, similarly to what operating systems do -# with memory pages. -# -# To enable VM just set 'vm-enabled' to yes, and set the following three -# VM parameters accordingly to your needs. - -vm-enabled no -# vm-enabled yes - -# This is the path of the Redis swap file. As you can guess, swap files -# can't be shared by different Redis instances, so make sure to use a swap -# file for every redis process you are running. Redis will complain if the -# swap file is already in use. -# -# The best kind of storage for the Redis swap file (that's accessed at random) -# is a Solid State Disk (SSD). -# -# *** WARNING *** if you are using a shared hosting the default of putting -# the swap file under /tmp is not secure. Create a dir with access granted -# only to Redis user and configure Redis to create the swap file there. -vm-swap-file /tmp/redis.swap - -# vm-max-memory configures the VM to use at max the specified amount of -# RAM. Everything that deos not fit will be swapped on disk *if* possible, that -# is, if there is still enough contiguous space in the swap file. -# -# With vm-max-memory 0 the system will swap everything it can. Not a good -# default, just specify the max amount of RAM you can in bytes, but it's -# better to leave some margin. For instance specify an amount of RAM -# that's more or less between 60 and 80% of your free RAM. -vm-max-memory 0 - -# Redis swap files is split into pages. An object can be saved using multiple -# contiguous pages, but pages can't be shared between different objects. -# So if your page is too big, small objects swapped out on disk will waste -# a lot of space. If you page is too small, there is less space in the swap -# file (assuming you configured the same number of total swap file pages). -# -# If you use a lot of small objects, use a page size of 64 or 32 bytes. -# If you use a lot of big objects, use a bigger page size. -# If unsure, use the default :) -vm-page-size 32 - -# Number of total memory pages in the swap file. -# Given that the page table (a bitmap of free/used pages) is taken in memory, -# every 8 pages on disk will consume 1 byte of RAM. -# -# The total swap size is vm-page-size * vm-pages -# -# With the default of 32-bytes memory pages and 134217728 pages Redis will -# use a 4 GB swap file, that will use 16 MB of RAM for the page table. -# -# It's better to use the smallest acceptable value for your application, -# but the default is large in order to work in most conditions. -vm-pages 134217728 - -# Max number of VM I/O threads running at the same time. -# This threads are used to read/write data from/to swap file, since they -# also encode and decode objects from disk to memory or the reverse, a bigger -# number of threads can help with big objects even if they can't help with -# I/O itself as the physical device may not be able to couple with many -# reads/writes operations at the same time. -# -# The special value of 0 turn off threaded I/O and enables the blocking -# Virtual Memory implementation. -vm-max-threads 4 - -############################### ADVANCED CONFIG ############################### - -# Glue small output buffers together in order to send small replies in a -# single TCP packet. Uses a bit more CPU but most of the times it is a win -# in terms of number of queries per second. Use 'yes' if unsure. -glueoutputbuf yes - -# Hashes are encoded in a special way (much more memory efficient) when they -# have at max a given numer of elements, and the biggest element does not -# exceed a given threshold. You can configure this limits with the following -# configuration directives. -hash-max-zipmap-entries 64 -hash-max-zipmap-value 512 - -# Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in -# order to help rehashing the main Redis hash table (the one mapping top-level -# keys to values). The hash table implementation redis uses (see dict.c) -# performs a lazy rehashing: the more operation you run into an hash table -# that is rhashing, the more rehashing "steps" are performed, so if the -# server is idle the rehashing is never complete and some more memory is used -# by the hash table. -# -# The default is to use this millisecond 10 times every second in order to -# active rehashing the main dictionaries, freeing memory when possible. -# -# If unsure: -# use "activerehashing no" if you have hard latency requirements and it is -# not a good thing in your environment that Redis can reply form time to time -# to queries with 2 milliseconds delay. -# -# use "activerehashing yes" if you don't have such hard requirements but -# want to free memory asap when possible. -activerehashing yes - -################################## INCLUDES ################################### - -# Include one or more other config files here. This is useful if you -# have a standard template that goes to all redis server but also need -# to customize a few per-server settings. Include files can include -# other files, so use this wisely. -# -# include /path/to/local.conf -# include /path/to/other.conf From df75c72825b74a85ec381bbbaeac24708c8994c7 Mon Sep 17 00:00:00 2001 From: ivowiblo Date: Sat, 14 Apr 2012 22:54:43 -0300 Subject: [PATCH 039/112] Eval and Evalsha api improved --- .DS_Store | Bin 0 -> 6148 bytes src/.DS_Store | Bin 0 -> 6148 bytes .../redis/clients/jedis/BinaryClient.java | 23 +++----- .../java/redis/clients/jedis/BinaryJedis.java | 28 +++++---- src/main/java/redis/clients/jedis/Client.java | 34 +++++------ src/main/java/redis/clients/jedis/Jedis.java | 53 +++++++++++------- src/test/.DS_Store | Bin 0 -> 6148 bytes src/test/java/.DS_Store | Bin 0 -> 6148 bytes src/test/java/redis/.DS_Store | Bin 0 -> 6148 bytes src/test/java/redis/clients/.DS_Store | Bin 0 -> 6148 bytes src/test/java/redis/clients/jedis/.DS_Store | Bin 0 -> 6148 bytes .../java/redis/clients/jedis/tests/.DS_Store | Bin 0 -> 6148 bytes .../tests/commands/ScriptingCommandsTest.java | 18 ++++-- 13 files changed, 87 insertions(+), 69 deletions(-) create mode 100644 .DS_Store create mode 100644 src/.DS_Store create mode 100644 src/test/.DS_Store create mode 100644 src/test/java/.DS_Store create mode 100644 src/test/java/redis/.DS_Store create mode 100644 src/test/java/redis/clients/.DS_Store create mode 100644 src/test/java/redis/clients/jedis/.DS_Store create mode 100644 src/test/java/redis/clients/jedis/tests/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9a874b5768f336915163bb88cd434575b859f936 GIT binary patch literal 6148 zcmeH~Jr2S!425ml0g0s}V-^m;4I%_5-~tF3k&vj^b9A16778<}(6eNJu~Vz<8=6`~ zboab&MFtUB!i}=AFfm2m$tVxGT*u4pe81nUlA49C} z?O@64YO)2RT{MRe%{!}2F))pG(Sih~)xkgosK7*lF7m<7{{#Hn{6A@7N(HFEpDCdI z{f4mh3n7#7gpu zObo#Gk7);t0M>LTwjO3?%m>_Y#trxB_H+5ZUN2sxtvcW-eZ*`(w*@I61*Cu!kOER* zK?>wCzTPb8ne-@9Kng5F0slS}y0a!*XM8#sVgw)umczJ?S%NHHAZxO9vO=?*9xPie z#t^SZJ6ZC&nrxlD9hSp~<(h|QedXQN6$w;|Bv*)=KooXQYjz> z{+R+c98QNlUn keys, List args){ - int keysSize = keys.size(); - int argsSize = args.size(); + private void sendEvalCommand(Command command, byte[] script, byte[] keyCount, byte[][] params){ - final byte[][] allArgs = new byte[keysSize + argsSize + 2][]; + final byte[][] allArgs = new byte[params.length + 2][]; allArgs[0] = script; - allArgs[1] =toByteArray(keysSize); + allArgs[1] = keyCount; - for(int i=0;i keys, List args){ - sendEvalCommand(EVAL, script, keys, args ); + public void eval(byte[] script, byte[] keyCount, byte[][] params){ + sendEvalCommand(EVAL, script, keyCount, params ); } - public void evalsha(byte[] sha1, List keys, List args){ - sendEvalCommand(EVALSHA, sha1, keys, args); + public void evalsha(byte[] sha1, byte[] keyCount, byte[][] params){ + sendEvalCommand(EVALSHA, sha1, keyCount, params); } public void scriptFlush(){ diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index f0b9d73..044ff56 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -16,6 +16,7 @@ import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.exceptions.JedisException; import redis.clients.util.JedisByteHashMap; import redis.clients.util.SafeEncoder; +import static redis.clients.jedis.Protocol.toByteArray; public class BinaryJedis implements BinaryJedisCommands { protected Client client = null; @@ -3018,18 +3019,25 @@ public class BinaryJedis implements BinaryJedisCommands { */ public Object eval(byte[] script, List keys, List args) { client.setTimeoutInfinite(); - client.eval(script, keys, args); + client.eval(script, toByteArray(keys.size()), getParams(keys, args)); return client.getOne(); } - - /** - * Evaluates scripts using the Lua interpreter built into Redis starting from version 2.6.0. - *

- * - * @return Script result - */ - public Object eval(byte[] script, List keys) { - return eval(script,keys, new ArrayList()); + private byte[][] getParams(List keys, List args){ + int keyCount = keys.size(); + byte[][] params = new byte[keyCount + args.size()][]; + + for(int i=0;i keys, String... args) { - List k = new ArrayList(); - for(String key:keys){ - k.add(SafeEncoder.encode(key)); - } - List a = new ArrayList(); - for(String arg:args){ - a.add(SafeEncoder.encode(arg)); - } - eval(SafeEncoder.encode(script),k,a); + private byte[][] getByteParams(String... params){ + byte[][] p = new byte[params.length][]; + for(int i=0;i keys, String... args) { - List k = new ArrayList(); - for(String key:keys){ - k.add(SafeEncoder.encode(key)); - } - List a = new ArrayList(); - for(String arg:args){ - a.add(SafeEncoder.encode(arg)); - } - evalsha(SafeEncoder.encode(sha1),k,a); + + public void evalsha(String sha1, int keyCount, String... params) { + evalsha(SafeEncoder.encode(sha1),toByteArray(keyCount), getByteParams(params)); } public void scriptExists(String... sha1){ diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 78561a5..226ff65 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -2693,19 +2693,38 @@ public class Jedis extends BinaryJedis implements JedisCommands { return client.getStatusCodeReply(); } - public Object eval(String script, String... keys) { - List s = new ArrayList(keys.length); - for(String key : keys) - s.add(key); - - return eval(script, s); - } - - public Object eval(String script, List keys, String... args) { - client.setTimeoutInfinite(); - client.eval(script, keys, args); + public Object eval(String script, int keyCount, String... params) { + client.setTimeoutInfinite(); + client.eval(script, keyCount, params); return getEvalResult(); + } + + private String[] getParams(List keys, List args){ + int keyCount = keys.size(); + int argCount = args.size(); + + String[] params = new String[keyCount + args.size()]; + + for(int i=0;i keys, List args) { + return eval(script, keys.size(), getParams(keys, args)); + } + + public Object eval(String script) { + return eval(script,0); + } + + public Object evalsha(String script) { + return evalsha(script,0); } private Object getEvalResult(){ @@ -2726,17 +2745,13 @@ public class Jedis extends BinaryJedis implements JedisCommands { return result; } - public Object evalsha(String sha1, String... keys) { - List s = new ArrayList(keys.length); - for(String key : keys) - s.add(key); - - return evalsha(sha1, s); + public Object evalsha(String sha1, List keys, List args) { + return evalsha(sha1, keys.size(), getParams(keys, args)); } - public Object evalsha(String sha1, List keys, String... args) { + public Object evalsha(String sha1, int keyCount, String... params) { checkIsInMulti(); - client.evalsha(sha1, keys, args); + client.evalsha(sha1, keyCount, params); return getEvalResult(); } diff --git a/src/test/.DS_Store b/src/test/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..55c1fcbeb4ba2bef02771ea2748f3e4b0ea5c07d GIT binary patch literal 6148 zcmeH~J&wXa427SU6iC~oq@0EW>)m< zk%er^j=Knh3!DIf); zz>E~gV|@8Jqi52iNC7D@4+Z@DQ0UH@Y@PAxV2BZb99RzHI%Wy7c!8|R*2xOZa(b|A zwHQOZ9_?hw>uR!f_I6kfAC`AEpJHg%+hK(X&1yhF3P^#80*juHe*W+1ujcQ^n8@Auu4PPqH)~DC=`aY|^Zges(XZZ6Iz{HQ@6+Mjm#TR5vwoX=P`Vj~j6r{kv GD)0dNyb`AX literal 0 HcmV?d00001 diff --git a/src/test/java/.DS_Store b/src/test/java/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d209edf2f0edc098a632ffe3bb1f8b7136f12568 GIT binary patch literal 6148 zcmeH~O^O0R4256R0l|$+m$mT#bAv+k1akoy+l3$q%Ixdt^ODNO9@o+gFOYhbRHc8u zMOO!a?S6(&U=3hNcg5C+ks0F;+;PT$3m(Jcbp5{FuAas$_j*9*HJ;aVSt0@=AOa#F z0wORW0&$4*{9jGzne-?kAOh1M;NOQrcdeM&FdfEu^b*wK32IGkU74X- zb`O@N7Hx>qlW;H~E2#COlz`Vz6KmQN(SN;E} zM4T<57=SAD-J*T z$HBK`Qa}nw0VyB_q`;LGr~*5Gyz;p^P6|kY+gHH94~_2F3&+Ixba03kfH-3~jPvLv zh|L4UUN|N)LbIe2lWNssSkf79mDdZ$#H7Qj`LMd#szb53o#(emhxJ5_Qa}ovD{!C7 zh1dTL{X+kLPSQ#WNP&N)fX&w1^@>lb+B$ih*V;yZrhCp8-Hr30aENkDjB?C{m*Zt5 bWnS|+_j}=(7<9&iPSnqU>mri^f33hbA{Z5> literal 0 HcmV?d00001 diff --git a/src/test/java/redis/clients/.DS_Store b/src/test/java/redis/clients/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..20845bd710c96181dc755ee637042cc04a94eef9 GIT binary patch literal 6148 zcmeH~J&pn~427Q;kXG7;k}?ek;06(5Pp}t2%TR!jC=h*)&a>l&S!y&|Jxk7uop^q} zVloC`+xxHqmHY zKm;a4AP#Y!|6db&COwJ>h`=-m`1hgEU2AIV8lMgh(E?ECOowqEy#%#*f?88sS7vCI z-GgPRMH}MzD5sX(S5sTpUJlFV!}8ANT@1~7Ijk_CSq;%30wORXFzfNs&;M`wtNwpf zqEG}x;GYq&`R-@8r2wyw<3^dk@$ KG>E`k2|NJGpc9Ay literal 0 HcmV?d00001 diff --git a/src/test/java/redis/clients/jedis/.DS_Store b/src/test/java/redis/clients/jedis/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0b9a44bd2ada453415acdcb4f1a3b8e052beac74 GIT binary patch literal 6148 zcmeH~Jr2S!425kd5)w;C#w;9w8$_s_fD0ff8xlid&(V2yytFW*3O!5qi=CuD-_X<| zqK8+%7imRg4L6mYg^4Nhl|1Dp1LDvR*Zbx1xLa8kvDOket}&jEX$lFD011!)36Q{y z2>2n6^M5m=XX2xf013>4fPEhl+%$)ls{ZLf@D>2tpzMaR_Y%-#1!xW}RZ)RybPpO^ z)!PuO`*vuGbvd+Dt=mPT`OvttS{DP;x?MCOfoXPOAORAX5Lni{we$Z7|JMIcwlF0D z68JL$+H|MxfR~E1_2c!devYb*3modp5k@}&NbD%y!rd^RYyi!nr79{g{s=e*1`_xw Ffj1-y6RZFL literal 0 HcmV?d00001 diff --git a/src/test/java/redis/clients/jedis/tests/.DS_Store b/src/test/java/redis/clients/jedis/tests/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..534c0929912ac332544f9d7c58ced2a84156069e GIT binary patch literal 6148 zcmeHKyKciU3_PY83}ngJQNPeX5Q6jz@&jq(F|CK7yQh9vKdr~d(7^4MF2T{DPNH}+ ze1m8Lu-(V_1Z)8ebVq#pur%LyU)ZW5Mx^tM7rbM{WxSlui|pS6&K+>Vgf~7v_^;D+ z_Dz`-kOERb3P=Gda8m`Uybhb2o~py7fE2g~1^j+!bjMyeC&tymAzA?9n&B|cqn98y z4-k9doX7~xl1fafRf}OsXS`KjFPsyT4y)$F>djUiipAS`ev5QiPt+&{q`LzpI^#hn>Sw@pkx7C7R^S^YG!=&c literal 0 HcmV?d00001 diff --git a/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java index 78825a9..acee2cf 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java @@ -19,7 +19,11 @@ public class ScriptingCommandsTest extends JedisCommandTestBase { keys.add("key1"); keys.add("key2"); - List response = (List)jedis.eval(script, keys, "first", "second" ); + List args = new ArrayList(); + args.add("first"); + args.add("second"); + + List response = (List)jedis.eval(script, keys, args ); assertEquals(4, response.size()); assertEquals("key1", response.get(0)); @@ -34,7 +38,10 @@ public class ScriptingCommandsTest extends JedisCommandTestBase { List keys = new ArrayList(); keys.add("key1"); - String response = (String)jedis.eval(script, keys); + List args = new ArrayList(); + args.add("first"); + + String response = (String)jedis.eval(script, keys, args); assertEquals("key1", response); } @@ -45,7 +52,7 @@ public class ScriptingCommandsTest extends JedisCommandTestBase { List keys = new ArrayList(); keys.add("key1"); - Long response = (Long)jedis.eval(script, keys); + Long response = (Long)jedis.eval(script, keys, new ArrayList()); assertEquals(new Long(2), response); } @@ -53,8 +60,9 @@ public class ScriptingCommandsTest extends JedisCommandTestBase { @Test public void evalNoArgs() { String script = "return KEYS[1]"; - - String response = (String)jedis.eval(script, "key1"); + List keys = new ArrayList(); + keys.add("key1"); + String response = (String)jedis.eval(script, keys, new ArrayList()); assertEquals("key1", response); } From 9e13233bbf5ef64dda4e63b665edab33a2e1afd4 Mon Sep 17 00:00:00 2001 From: ivowiblo Date: Tue, 17 Apr 2012 16:06:03 -0400 Subject: [PATCH 040/112] DS_Store files removed --- .DS_Store | Bin 6148 -> 0 bytes src/.DS_Store | Bin 6148 -> 0 bytes src/test/.DS_Store | Bin 6148 -> 0 bytes src/test/java/.DS_Store | Bin 6148 -> 0 bytes src/test/java/redis/.DS_Store | Bin 6148 -> 0 bytes src/test/java/redis/clients/.DS_Store | Bin 6148 -> 0 bytes src/test/java/redis/clients/jedis/.DS_Store | Bin 6148 -> 0 bytes .../java/redis/clients/jedis/tests/.DS_Store | Bin 6148 -> 0 bytes 8 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store delete mode 100644 src/.DS_Store delete mode 100644 src/test/.DS_Store delete mode 100644 src/test/java/.DS_Store delete mode 100644 src/test/java/redis/.DS_Store delete mode 100644 src/test/java/redis/clients/.DS_Store delete mode 100644 src/test/java/redis/clients/jedis/.DS_Store delete mode 100644 src/test/java/redis/clients/jedis/tests/.DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 9a874b5768f336915163bb88cd434575b859f936..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425ml0g0s}V-^m;4I%_5-~tF3k&vj^b9A16778<}(6eNJu~Vz<8=6`~ zboab&MFtUB!i}=AFfm2m$tVxGT*u4pe81nUlA49C} z?O@64YO)2RT{MRe%{!}2F))pG(Sih~)xkgosK7*lF7m<7{{#Hn{6A@7N(HFEpDCdI z{f4mh3n7#7gpu zObo#Gk7);t0M>LTwjO3?%m>_Y#trxB_H+5ZUN2sxtvcW-eZ*`(w*@I61*Cu!kOER* zK?>wCzTPb8ne-@9Kng5F0slS}y0a!*XM8#sVgw)umczJ?S%NHHAZxO9vO=?*9xPie z#t^SZJ6ZC&nrxlD9hSp~<(h|QedXQN6$w;|Bv*)=KooXQYjz> z{+R+c98QNlUn)m< zk%er^j=Knh3!DIf); zz>E~gV|@8Jqi52iNC7D@4+Z@DQ0UH@Y@PAxV2BZb99RzHI%Wy7c!8|R*2xOZa(b|A zwHQOZ9_?hw>uR!f_I6kfAC`AEpJHg%+hK(X&1yhF3P^#80*juHe*W+1ujcQ^n8@Auu4PPqH)~DC=`aY|^Zges(XZZ6Iz{HQ@6+Mjm#TR5vwoX=P`Vj~j6r{kv GD)0dNyb`AX diff --git a/src/test/java/.DS_Store b/src/test/java/.DS_Store deleted file mode 100644 index d209edf2f0edc098a632ffe3bb1f8b7136f12568..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~O^O0R4256R0l|$+m$mT#bAv+k1akoy+l3$q%Ixdt^ODNO9@o+gFOYhbRHc8u zMOO!a?S6(&U=3hNcg5C+ks0F;+;PT$3m(Jcbp5{FuAas$_j*9*HJ;aVSt0@=AOa#F z0wORW0&$4*{9jGzne-?kAOh1M;NOQrcdeM&FdfEu^b*wK32IGkU74X- zb`O@N7Hx>qlW;H~E2#COlz`Vz6KmQN(SN;E} zM4T<57=SAD-J*T z$HBK`Qa}nw0VyB_q`;LGr~*5Gyz;p^P6|kY+gHH94~_2F3&+Ixba03kfH-3~jPvLv zh|L4UUN|N)LbIe2lWNssSkf79mDdZ$#H7Qj`LMd#szb53o#(emhxJ5_Qa}ovD{!C7 zh1dTL{X+kLPSQ#WNP&N)fX&w1^@>lb+B$ih*V;yZrhCp8-Hr30aENkDjB?C{m*Zt5 bWnS|+_j}=(7<9&iPSnqU>mri^f33hbA{Z5> diff --git a/src/test/java/redis/clients/.DS_Store b/src/test/java/redis/clients/.DS_Store deleted file mode 100644 index 20845bd710c96181dc755ee637042cc04a94eef9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~J&pn~427Q;kXG7;k}?ek;06(5Pp}t2%TR!jC=h*)&a>l&S!y&|Jxk7uop^q} zVloC`+xxHqmHY zKm;a4AP#Y!|6db&COwJ>h`=-m`1hgEU2AIV8lMgh(E?ECOowqEy#%#*f?88sS7vCI z-GgPRMH}MzD5sX(S5sTpUJlFV!}8ANT@1~7Ijk_CSq;%30wORXFzfNs&;M`wtNwpf zqEG}x;GYq&`R-@8r2wyw<3^dk@$ KG>E`k2|NJGpc9Ay diff --git a/src/test/java/redis/clients/jedis/.DS_Store b/src/test/java/redis/clients/jedis/.DS_Store deleted file mode 100644 index 0b9a44bd2ada453415acdcb4f1a3b8e052beac74..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425kd5)w;C#w;9w8$_s_fD0ff8xlid&(V2yytFW*3O!5qi=CuD-_X<| zqK8+%7imRg4L6mYg^4Nhl|1Dp1LDvR*Zbx1xLa8kvDOket}&jEX$lFD011!)36Q{y z2>2n6^M5m=XX2xf013>4fPEhl+%$)ls{ZLf@D>2tpzMaR_Y%-#1!xW}RZ)RybPpO^ z)!PuO`*vuGbvd+Dt=mPT`OvttS{DP;x?MCOfoXPOAORAX5Lni{we$Z7|JMIcwlF0D z68JL$+H|MxfR~E1_2c!devYb*3modp5k@}&NbD%y!rd^RYyi!nr79{g{s=e*1`_xw Ffj1-y6RZFL diff --git a/src/test/java/redis/clients/jedis/tests/.DS_Store b/src/test/java/redis/clients/jedis/tests/.DS_Store deleted file mode 100644 index 534c0929912ac332544f9d7c58ced2a84156069e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKyKciU3_PY83}ngJQNPeX5Q6jz@&jq(F|CK7yQh9vKdr~d(7^4MF2T{DPNH}+ ze1m8Lu-(V_1Z)8ebVq#pur%LyU)ZW5Mx^tM7rbM{WxSlui|pS6&K+>Vgf~7v_^;D+ z_Dz`-kOERb3P=Gda8m`Uybhb2o~py7fE2g~1^j+!bjMyeC&tymAzA?9n&B|cqn98y z4-k9doX7~xl1fafRf}OsXS`KjFPsyT4y)$F>djUiipAS`ev5QiPt+&{q`LzpI^#hn>Sw@pkx7C7R^S^YG!=&c From c9b413c323df9ea47c1c72af6f85d37c14e5db44 Mon Sep 17 00:00:00 2001 From: ivowiblo Date: Tue, 17 Apr 2012 16:40:54 -0400 Subject: [PATCH 041/112] Select support to pipeline. Thanks to @ib84 --- src/main/java/redis/clients/jedis/Pipeline.java | 5 +++++ .../java/redis/clients/jedis/tests/PipeliningTest.java | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index 95bc773..520e975 100644 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -1226,4 +1226,9 @@ public class Pipeline extends Queable { client.randomKey(); return getResponse(BuilderFactory.STRING); } + + public Response select(int index){ + client.select(index); + return getResponse(BuilderFactory.STRING); + } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java index 1b18e52..0a2f7d4 100644 --- a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java +++ b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java @@ -101,6 +101,13 @@ public class PipeliningTest extends Assert { assertNotNull(score.get()); } + @Test + public void pipelineSelect() { + Pipeline p = jedis.pipelined(); + p.select(1); + p.sync(); + } + @Test public void pipelineResponseWithoutData() { jedis.zadd("zset", 1, "foo"); From 53f829fb1087ea33c0bd044aeaf70eedad233d45 Mon Sep 17 00:00:00 2001 From: Ivo Ramirez Date: Wed, 21 Dec 2011 06:56:56 +0100 Subject: [PATCH 042/112] JedisPool accepts BinaryJedis as a resource for return. Issue #171 Conflicts: src/main/java/redis/clients/util/Pool.java --- src/main/java/redis/clients/jedis/JedisPool.java | 10 +++++++++- src/main/java/redis/clients/util/Pool.java | 14 +++++++++++--- .../redis/clients/jedis/tests/JedisPoolTest.java | 10 ++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/main/java/redis/clients/jedis/JedisPool.java b/src/main/java/redis/clients/jedis/JedisPool.java index e513570..0d7c089 100644 --- a/src/main/java/redis/clients/jedis/JedisPool.java +++ b/src/main/java/redis/clients/jedis/JedisPool.java @@ -38,6 +38,15 @@ public class JedisPool extends Pool { super(poolConfig, new JedisFactory(host, port, timeout, password, database)); } + + public void returnBrokenResource(final BinaryJedis resource) { + returnBrokenResourceObject(resource); + } + + public void returnResource(final BinaryJedis resource) { + returnResourceObject(resource); + } + /** * PoolableObjectFactory custom impl. */ @@ -101,6 +110,5 @@ public class JedisPool extends Pool { return false; } } - } } diff --git a/src/main/java/redis/clients/util/Pool.java b/src/main/java/redis/clients/util/Pool.java index 3f74370..7f5e533 100644 --- a/src/main/java/redis/clients/util/Pool.java +++ b/src/main/java/redis/clients/util/Pool.java @@ -23,8 +23,8 @@ public abstract class Pool { "Could not get a resource from the pool", e); } } - - public void returnResource(final T resource) { + + public void returnResourceObject(final Object resource) { try { internalPool.returnObject(resource); } catch (Exception e) { @@ -32,8 +32,16 @@ public abstract class Pool { "Could not return the resource to the pool", e); } } - + public void returnBrokenResource(final T resource) { + returnBrokenResourceObject(resource); + } + + public void returnResource(final T resource) { + returnResourceObject(resource); + } + + protected void returnBrokenResourceObject(final Object resource) { try { internalPool.invalidateObject(resource); } catch (Exception e) { diff --git a/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java b/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java index 5fd76fe..b0a489e 100644 --- a/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java +++ b/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java @@ -5,6 +5,7 @@ import org.apache.commons.pool.impl.GenericObjectPool.Config; import org.junit.Assert; import org.junit.Test; +import redis.clients.jedis.BinaryJedis; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; @@ -113,4 +114,13 @@ public class JedisPoolTest extends Assert { pool1.returnResource(jedis0); pool1.destroy(); } + + @Test + public void returnBinary() { + JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.host, + hnp.port, 2000); + BinaryJedis jedis = pool.getResource(); + pool.returnResource(jedis); + pool.destroy(); + } } \ No newline at end of file From f632182657aee7a00f0ca5b21cc1518471249dfd Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Tue, 17 Apr 2012 18:09:16 -0300 Subject: [PATCH 043/112] update how to run tests --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3f8f39d..ae89c9f 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ To run the tests: - Use the latest redis master branch. -- Run 2 instances of redis [using conf files in conf folder](https://github.com/xetorthio/jedis/wiki). For the tests we use 2 redis servers, one on default port (6379) and the other one on (6380). Both have authentication enabled with default password (foobared). This way we can test both sharding and auth command. +- Run ```make test```. This will run 2 instances of redis. We use 2 redis servers, one on default port (6379) and the other one on (6380). Both have authentication enabled with default password (foobared). This way we can test both sharding and auth command. Thanks for helping! From d13622528166565f6777600a1cc3f0e6af6d3ec3 Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Tue, 17 Apr 2012 18:45:31 -0300 Subject: [PATCH 044/112] remove unused import --- src/main/java/redis/clients/jedis/JedisPool.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/JedisPool.java b/src/main/java/redis/clients/jedis/JedisPool.java index 0d7c089..9a73cc3 100644 --- a/src/main/java/redis/clients/jedis/JedisPool.java +++ b/src/main/java/redis/clients/jedis/JedisPool.java @@ -1,7 +1,6 @@ package redis.clients.jedis; import org.apache.commons.pool.BasePoolableObjectFactory; -import org.apache.commons.pool.impl.GenericObjectPool; import org.apache.commons.pool.impl.GenericObjectPool.Config; import redis.clients.util.Pool; From 0f978f5236469ff4661131358d2cd862307e79ff Mon Sep 17 00:00:00 2001 From: ivowiblo Date: Tue, 17 Apr 2012 21:13:37 -0400 Subject: [PATCH 045/112] Unused import is removed --- src/main/java/redis/clients/jedis/Jedis.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 226ff65..25e5511 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -8,8 +8,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.hamcrest.core.IsInstanceOf; - import redis.clients.jedis.BinaryClient.LIST_POSITION; import redis.clients.util.SafeEncoder; From 75e52b9a26055476ff584e0e6836d9ccdd46cdc6 Mon Sep 17 00:00:00 2001 From: Ivo Ramirez Date: Thu, 22 Dec 2011 22:40:36 +0100 Subject: [PATCH 046/112] z*range commands now receive long instead of int. #242 --- .../java/redis/clients/jedis/BinaryClient.java | 14 +++++++------- src/main/java/redis/clients/jedis/Client.java | 14 +++++++------- src/main/java/redis/clients/jedis/Commands.java | 14 +++++++------- .../java/redis/clients/jedis/Connection.java | 3 ++- src/main/java/redis/clients/jedis/Jedis.java | 16 ++++++++-------- .../java/redis/clients/jedis/JedisCommands.java | 10 +++++----- .../java/redis/clients/jedis/ShardedJedis.java | 10 +++++----- 7 files changed, 41 insertions(+), 40 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index 812defe..5d681fe 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -362,7 +362,7 @@ public class BinaryClient extends Connection { sendCommand(ZADD, key, toByteArray(score), member); } - public void zrange(final byte[] key, final int start, final int end) { + public void zrange(final byte[] key, final long start, final long end) { sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end)); } @@ -383,18 +383,18 @@ public class BinaryClient extends Connection { sendCommand(ZREVRANK, key, member); } - public void zrevrange(final byte[] key, final int start, final int end) { + public void zrevrange(final byte[] key, final long start, final long end) { sendCommand(ZREVRANGE, key, toByteArray(start), toByteArray(end)); } - public void zrangeWithScores(final byte[] key, final int start, - final int end) { + public void zrangeWithScores(final byte[] key, final long start, + final long end) { sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end), WITHSCORES.raw); } - public void zrevrangeWithScores(final byte[] key, final int start, - final int end) { + public void zrevrangeWithScores(final byte[] key, final long start, + final long end) { sendCommand(ZREVRANGE, key, toByteArray(start), toByteArray(end), WITHSCORES.raw); } @@ -558,7 +558,7 @@ public class BinaryClient extends Connection { WITHSCORES.raw); } - public void zremrangeByRank(final byte[] key, final int start, final int end) { + public void zremrangeByRank(final byte[] key, final long start, final long end) { sendCommand(ZREMRANGEBYRANK, key, toByteArray(start), toByteArray(end)); } diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index 1f493e0..0e264da 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -319,7 +319,7 @@ public class Client extends BinaryClient implements Commands { zadd(SafeEncoder.encode(key), score, SafeEncoder.encode(member)); } - public void zrange(final String key, final int start, final int end) { + public void zrange(final String key, final long start, final long end) { zrange(SafeEncoder.encode(key), start, end); } @@ -340,17 +340,17 @@ public class Client extends BinaryClient implements Commands { zrevrank(SafeEncoder.encode(key), SafeEncoder.encode(member)); } - public void zrevrange(final String key, final int start, final int end) { + public void zrevrange(final String key, final long start, final long end) { zrevrange(SafeEncoder.encode(key), start, end); } - public void zrangeWithScores(final String key, final int start, - final int end) { + public void zrangeWithScores(final String key, final long start, + final long end) { zrangeWithScores(SafeEncoder.encode(key), start, end); } - public void zrevrangeWithScores(final String key, final int start, - final int end) { + public void zrevrangeWithScores(final String key, final long start, + final long end) { zrevrangeWithScores(SafeEncoder.encode(key), start, end); } @@ -462,7 +462,7 @@ public class Client extends BinaryClient implements Commands { count); } - public void zremrangeByRank(final String key, final int start, final int end) { + public void zremrangeByRank(final String key, final long start, final long end) { zremrangeByRank(SafeEncoder.encode(key), start, end); } diff --git a/src/main/java/redis/clients/jedis/Commands.java b/src/main/java/redis/clients/jedis/Commands.java index 235ee88..103ded1 100644 --- a/src/main/java/redis/clients/jedis/Commands.java +++ b/src/main/java/redis/clients/jedis/Commands.java @@ -139,7 +139,7 @@ public interface Commands { public void zadd(final String key, final double score, final String member); - public void zrange(final String key, final int start, final int end); + public void zrange(final String key, final long start, final long end); public void zrem(final String key, final String member); @@ -150,13 +150,13 @@ public interface Commands { public void zrevrank(final String key, final String member); - public void zrevrange(final String key, final int start, final int end); + public void zrevrange(final String key, final long start, final long end); - public void zrangeWithScores(final String key, final int start, - final int end); + public void zrangeWithScores(final String key, final long start, + final long end); - public void zrevrangeWithScores(final String key, final int start, - final int end); + public void zrevrangeWithScores(final String key, final long start, + final long end); public void zcard(final String key); @@ -212,7 +212,7 @@ public interface Commands { public void zrevrangeByScoreWithScores(final String key, final double max, final double min, final int offset, final int count); - public void zremrangeByRank(final String key, final int start, final int end); + public void zremrangeByRank(final String key, final long start, final long end); public void zremrangeByScore(final String key, final double start, final double end); diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index 0ea973f..19b3cf3 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -113,6 +113,7 @@ public class Connection { } public Connection() { + } public void connect() { @@ -185,7 +186,7 @@ public class Connection { public Long getIntegerReply() { flush(); pipelinedCommands--; - return (Long) protocol.read(inputStream); + return (Long)protocol.read(inputStream); } public List getMultiBulkReply() { diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index c71d9aa..6d320e8 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -1436,7 +1436,7 @@ public class Jedis extends BinaryJedis implements JedisCommands { return client.getIntegerReply(); } - public Set zrange(final String key, final int start, final int end) { + public Set zrange(final String key, final long start, final long end) { checkIsInMulti(); client.zrange(key, start, end); final List members = client.getMultiBulkReply(); @@ -1548,24 +1548,24 @@ public class Jedis extends BinaryJedis implements JedisCommands { return client.getIntegerReply(); } - public Set zrevrange(final String key, final int start, - final int end) { + public Set zrevrange(final String key, final long start, + final long end) { checkIsInMulti(); client.zrevrange(key, start, end); final List members = client.getMultiBulkReply(); return new LinkedHashSet(members); } - public Set zrangeWithScores(final String key, final int start, - final int end) { + public Set zrangeWithScores(final String key, final long start, + final long end) { checkIsInMulti(); client.zrangeWithScores(key, start, end); Set set = getTupledSet(); return set; } - public Set zrevrangeWithScores(final String key, final int start, - final int end) { + public Set zrevrangeWithScores(final String key, final long start, + final long end) { checkIsInMulti(); client.zrevrangeWithScores(key, start, end); Set set = getTupledSet(); @@ -2310,7 +2310,7 @@ public class Jedis extends BinaryJedis implements JedisCommands { * operation * */ - public Long zremrangeByRank(final String key, final int start, final int end) { + public Long zremrangeByRank(final String key, final long start, final long end) { checkIsInMulti(); client.zremrangeByRank(key, start, end); return client.getIntegerReply(); diff --git a/src/main/java/redis/clients/jedis/JedisCommands.java b/src/main/java/redis/clients/jedis/JedisCommands.java index 603b60c..2fcb790 100644 --- a/src/main/java/redis/clients/jedis/JedisCommands.java +++ b/src/main/java/redis/clients/jedis/JedisCommands.java @@ -108,7 +108,7 @@ public interface JedisCommands { Long zadd(String key, double score, String member); - Set zrange(String key, int start, int end); + Set zrange(String key, long start, long end); Long zrem(String key, String member); @@ -118,11 +118,11 @@ public interface JedisCommands { Long zrevrank(String key, String member); - Set zrevrange(String key, int start, int end); + Set zrevrange(String key, long start, long end); - Set zrangeWithScores(String key, int start, int end); + Set zrangeWithScores(String key, long start, long end); - Set zrevrangeWithScores(String key, int start, int end); + Set zrevrangeWithScores(String key, long start, long end); Long zcard(String key); @@ -154,7 +154,7 @@ public interface JedisCommands { Set zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count); - Long zremrangeByRank(String key, int start, int end); + Long zremrangeByRank(String key, long start, long end); Long zremrangeByScore(String key, double start, double end); diff --git a/src/main/java/redis/clients/jedis/ShardedJedis.java b/src/main/java/redis/clients/jedis/ShardedJedis.java index b294149..890581c 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedis.java +++ b/src/main/java/redis/clients/jedis/ShardedJedis.java @@ -288,7 +288,7 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { return j.zadd(key, score, member); } - public Set zrange(String key, int start, int end) { + public Set zrange(String key, long start, long end) { Jedis j = getShard(key); return j.zrange(key, start, end); } @@ -313,17 +313,17 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { return j.zrevrank(key, member); } - public Set zrevrange(String key, int start, int end) { + public Set zrevrange(String key, long start, long end) { Jedis j = getShard(key); return j.zrevrange(key, start, end); } - public Set zrangeWithScores(String key, int start, int end) { + public Set zrangeWithScores(String key, long start, long end) { Jedis j = getShard(key); return j.zrangeWithScores(key, start, end); } - public Set zrevrangeWithScores(String key, int start, int end) { + public Set zrevrangeWithScores(String key, long start, long end) { Jedis j = getShard(key); return j.zrevrangeWithScores(key, start, end); } @@ -398,7 +398,7 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { return j.zrevrangeByScoreWithScores(key, max, min, offset, count); } - public Long zremrangeByRank(String key, int start, int end) { + public Long zremrangeByRank(String key, long start, long end) { Jedis j = getShard(key); return j.zremrangeByRank(key, start, end); } From 088f84b6b2e667501050cb99b52a2d9666430d24 Mon Sep 17 00:00:00 2001 From: ivowiblo Date: Tue, 17 Apr 2012 21:37:33 -0400 Subject: [PATCH 047/112] Extra space is removed --- src/main/java/redis/clients/jedis/Connection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index 19b3cf3..409b2cb 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -186,7 +186,7 @@ public class Connection { public Long getIntegerReply() { flush(); pipelinedCommands--; - return (Long)protocol.read(inputStream); + return (Long) protocol.read(inputStream); } public List getMultiBulkReply() { From e8c27e0d15096289598fbea946d03e29402fd5bb Mon Sep 17 00:00:00 2001 From: Ivo Ramirez Date: Wed, 21 Dec 2011 06:19:05 +0100 Subject: [PATCH 048/112] Jedis does support lpushx and rpushx Conflicts: src/main/java/redis/clients/jedis/BinaryJedisCommands.java src/main/java/redis/clients/jedis/Pipeline.java --- .../java/redis/clients/jedis/BinaryJedisCommands.java | 4 ++++ .../java/redis/clients/jedis/BinaryShardedJedis.java | 11 +++++++++++ src/main/java/redis/clients/jedis/JedisCommands.java | 4 ++++ src/main/java/redis/clients/jedis/ShardedJedis.java | 10 ++++++++++ src/main/java/redis/clients/util/Pool.java | 2 +- 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java index ef8aebd..673f2fe 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java +++ b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java @@ -154,4 +154,8 @@ public interface BinaryJedisCommands { Long zremrangeByScore(byte[] key, double start, double end); Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value); + + Long lpushx(byte[] key, byte[] string); + + Long rpushx(byte[] key, byte[] string); } diff --git a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java index 9c1abd2..4e056ab 100644 --- a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java @@ -190,6 +190,17 @@ public class BinaryShardedJedis extends Sharded return j.lpush(key, string); } + public Long lpushx(byte[] key, byte[] string) { + Jedis j = getShard(key); + return j.lpushx(key, string); + } + + + public Long rpushx(byte[] key, byte[] string) { + Jedis j = getShard(key); + return j.rpushx(key, string); + } + public Long llen(byte[] key) { Jedis j = getShard(key); return j.llen(key); diff --git a/src/main/java/redis/clients/jedis/JedisCommands.java b/src/main/java/redis/clients/jedis/JedisCommands.java index 603b60c..176f0ac 100644 --- a/src/main/java/redis/clients/jedis/JedisCommands.java +++ b/src/main/java/redis/clients/jedis/JedisCommands.java @@ -160,4 +160,8 @@ public interface JedisCommands { Long linsert(String key, Client.LIST_POSITION where, String pivot, String value); + + Long lpushx(String key, String string); + + Long rpushx(String key, String string); } diff --git a/src/main/java/redis/clients/jedis/ShardedJedis.java b/src/main/java/redis/clients/jedis/ShardedJedis.java index b294149..64769a5 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedis.java +++ b/src/main/java/redis/clients/jedis/ShardedJedis.java @@ -207,6 +207,16 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { Jedis j = getShard(key); return j.lpush(key, string); } + + public Long lpushx(String key, String string) { + Jedis j = getShard(key); + return j.lpushx(key, string); + } + + public Long rpushx(String key, String string) { + Jedis j = getShard(key); + return j.rpushx(key, string); + } public Long llen(String key) { Jedis j = getShard(key); diff --git a/src/main/java/redis/clients/util/Pool.java b/src/main/java/redis/clients/util/Pool.java index 3f74370..651f15f 100644 --- a/src/main/java/redis/clients/util/Pool.java +++ b/src/main/java/redis/clients/util/Pool.java @@ -24,7 +24,7 @@ public abstract class Pool { } } - public void returnResource(final T resource) { + public void returnResource(final Object resource) { try { internalPool.returnObject(resource); } catch (Exception e) { From ded776f85989b5acb9b52eef394af84b2c812191 Mon Sep 17 00:00:00 2001 From: ivowiblo Date: Wed, 18 Apr 2012 00:27:00 -0400 Subject: [PATCH 049/112] Pool.java back to the original --- src/main/java/redis/clients/util/Pool.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/util/Pool.java b/src/main/java/redis/clients/util/Pool.java index 651f15f..3f74370 100644 --- a/src/main/java/redis/clients/util/Pool.java +++ b/src/main/java/redis/clients/util/Pool.java @@ -24,7 +24,7 @@ public abstract class Pool { } } - public void returnResource(final Object resource) { + public void returnResource(final T resource) { try { internalPool.returnObject(resource); } catch (Exception e) { From e4f7f61d00206ab2e2295accaaef5027a898a71f Mon Sep 17 00:00:00 2001 From: ivowiblo Date: Wed, 18 Apr 2012 00:33:20 -0400 Subject: [PATCH 050/112] Pipeline.sort with dstkey uses right Response type --- src/main/java/redis/clients/jedis/Pipeline.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index 95bc773..9b3413c 100644 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -672,14 +672,14 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.LONG); } - public Response> sort(String key) { + public Response sort(String key) { client.sort(key); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.LONG); } - public Response> sort(byte[] key) { + public Response sort(byte[] key) { client.sort(key); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.LONG); } public Response> sort(String key, From 8aca0b77f92ecad3e1832362bafee208a2941120 Mon Sep 17 00:00:00 2001 From: ivowiblo Date: Wed, 18 Apr 2012 15:22:43 -0400 Subject: [PATCH 051/112] Variadic commands --- .../redis/clients/jedis/BinaryClient.java | 50 ++++++++++++++----- .../java/redis/clients/jedis/BinaryJedis.java | 42 +++++++++------- .../clients/jedis/BinaryJedisCommands.java | 14 +++--- .../clients/jedis/BinaryShardedJedis.java | 29 ++++++----- src/main/java/redis/clients/jedis/Client.java | 34 ++++++++----- .../java/redis/clients/jedis/Commands.java | 14 +++--- src/main/java/redis/clients/jedis/Jedis.java | 42 +++++++++------- .../redis/clients/jedis/JedisCommands.java | 14 +++--- .../redis/clients/jedis/ShardedJedis.java | 29 ++++++----- .../java/redis/clients/util/SafeEncoder.java | 10 ++++ 10 files changed, 176 insertions(+), 102 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index 812defe..f258676 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -9,6 +9,7 @@ import static redis.clients.jedis.Protocol.Keyword.STORE; import static redis.clients.jedis.Protocol.Keyword.WITHSCORES; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -44,6 +45,15 @@ public class BinaryClient extends Connection { public BinaryClient(final String host, final int port) { super(host, port); } + + private byte[][] joinParameters(byte[] first, byte[][] rest){ + byte[][] result = new byte[rest.length+1][]; + result[0] = first; + for(int i=0;i scoreMembers) { + ArrayList args = new ArrayList(scoreMembers.size() * 2 + 1); + + args.add(key); + + for(Map.Entry entry : scoreMembers.entrySet()){ + args.add(toByteArray(entry.getKey())); + args.add(entry.getValue()); + } + + byte[][] argsArray = new byte[args.size()][]; + args.toArray(argsArray); + + sendCommand(ZADD, argsArray); + } + public void zrange(final byte[] key, final int start, final int end) { sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end)); } - public void zrem(final byte[] key, final byte[] member) { - sendCommand(ZREM, key, member); + public void zrem(final byte[] key, final byte[]... members) { + sendCommand(ZREM, joinParameters( key, members)); } public void zincrby(final byte[] key, final double score, diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 7b4cd30..1c19306 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -796,13 +796,13 @@ public class BinaryJedis implements BinaryJedisCommands { * Time complexity: O(1) * * @param key - * @param field + * @param fields * @return If the field was present in the hash it is deleted and 1 is * returned, otherwise 0 is returned and no operation is performed. */ - public Long hdel(final byte[] key, final byte[] field) { + public Long hdel(final byte[] key, final byte[]... fields) { checkIsInMulti(); - client.hdel(key, field); + client.hdel(key, fields); return client.getIntegerReply(); } @@ -881,16 +881,16 @@ public class BinaryJedis implements BinaryJedisCommands { *

* Time complexity: O(1) * - * @see BinaryJedis#lpush(byte[], byte[]) + * @see BinaryJedis#rpush(byte[], byte[]...) * * @param key - * @param string + * @param strings * @return Integer reply, specifically, the number of elements inside the * list after the push operation. */ - public Long rpush(final byte[] key, final byte[] string) { + public Long rpush(final byte[] key, final byte[]... strings) { checkIsInMulti(); - client.rpush(key, string); + client.rpush(key, strings); return client.getIntegerReply(); } @@ -902,16 +902,16 @@ public class BinaryJedis implements BinaryJedisCommands { *

* Time complexity: O(1) * - * @see BinaryJedis#rpush(byte[], byte[]) + * @see BinaryJedis#rpush(byte[], byte[]...) * * @param key - * @param string + * @param strings * @return Integer reply, specifically, the number of elements inside the * list after the push operation. */ - public Long lpush(final byte[] key, final byte[] string) { + public Long lpush(final byte[] key, final byte[]... strings) { checkIsInMulti(); - client.lpush(key, string); + client.lpush(key, strings); return client.getIntegerReply(); } @@ -1162,13 +1162,13 @@ public class BinaryJedis implements BinaryJedisCommands { * Time complexity O(1) * * @param key - * @param member + * @param members * @return Integer reply, specifically: 1 if the new element was added 0 if * the element was already a member of the set */ - public Long sadd(final byte[] key, final byte[] member) { + public Long sadd(final byte[] key, final byte[]... members) { checkIsInMulti(); - client.sadd(key, member); + client.sadd(key, members); return client.getIntegerReply(); } @@ -1200,7 +1200,7 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Integer reply, specifically: 1 if the new element was removed 0 * if the new element was not a member of the set */ - public Long srem(final byte[] key, final byte[] member) { + public Long srem(final byte[] key, final byte[]... member) { checkIsInMulti(); client.srem(key, member); return client.getIntegerReply(); @@ -1458,6 +1458,12 @@ public class BinaryJedis implements BinaryJedisCommands { client.zadd(key, score, member); return client.getIntegerReply(); } + + public Long zadd(final byte[] key, final Map scoreMembers) { + checkIsInMulti(); + client.zaddBinary(key, scoreMembers); + return client.getIntegerReply(); + } public Set zrange(final byte[] key, final int start, final int end) { checkIsInMulti(); @@ -1477,13 +1483,13 @@ public class BinaryJedis implements BinaryJedisCommands { * * * @param key - * @param member + * @param members * @return Integer reply, specifically: 1 if the new element was removed 0 * if the new element was not a member of the set */ - public Long zrem(final byte[] key, final byte[] member) { + public Long zrem(final byte[] key, final byte[]... members) { checkIsInMulti(); - client.zrem(key, member); + client.zrem(key, members); return client.getIntegerReply(); } diff --git a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java index ef8aebd..7040e53 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java +++ b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java @@ -57,7 +57,7 @@ public interface BinaryJedisCommands { Boolean hexists(byte[] key, byte[] field); - Long hdel(byte[] key, byte[] field); + Long hdel(byte[] key, byte[]... field); Long hlen(byte[] key); @@ -67,9 +67,9 @@ public interface BinaryJedisCommands { Map hgetAll(byte[] key); - Long rpush(byte[] key, byte[] string); + Long rpush(byte[] key, byte[]... string); - Long lpush(byte[] key, byte[] string); + Long lpush(byte[] key, byte[]... string); Long llen(byte[] key); @@ -87,11 +87,11 @@ public interface BinaryJedisCommands { byte[] rpop(byte[] key); - Long sadd(byte[] key, byte[] member); + Long sadd(byte[] key, byte[]... member); Set smembers(byte[] key); - Long srem(byte[] key, byte[] member); + Long srem(byte[] key, byte[]... member); byte[] spop(byte[] key); @@ -102,10 +102,12 @@ public interface BinaryJedisCommands { byte[] srandmember(byte[] key); Long zadd(byte[] key, double score, byte[] member); + + Long zadd(byte[] key, Map scoreMembers); Set zrange(byte[] key, int start, int end); - Long zrem(byte[] key, byte[] member); + Long zrem(byte[] key, byte[]... member); Double zincrby(byte[] key, double score, byte[] member); diff --git a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java index 9c1abd2..01b14b0 100644 --- a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java @@ -155,9 +155,9 @@ public class BinaryShardedJedis extends Sharded return j.hexists(key, field); } - public Long hdel(byte[] key, byte[] field) { + public Long hdel(byte[] key, byte[]... fields) { Jedis j = getShard(key); - return j.hdel(key, field); + return j.hdel(key, fields); } public Long hlen(byte[] key) { @@ -180,14 +180,14 @@ public class BinaryShardedJedis extends Sharded return j.hgetAll(key); } - public Long rpush(byte[] key, byte[] string) { + public Long rpush(byte[] key, byte[]... strings) { Jedis j = getShard(key); - return j.rpush(key, string); + return j.rpush(key, strings); } - public Long lpush(byte[] key, byte[] string) { + public Long lpush(byte[] key, byte[]... strings) { Jedis j = getShard(key); - return j.lpush(key, string); + return j.lpush(key, strings); } public Long llen(byte[] key) { @@ -230,9 +230,9 @@ public class BinaryShardedJedis extends Sharded return j.rpop(key); } - public Long sadd(byte[] key, byte[] member) { + public Long sadd(byte[] key, byte[]... members) { Jedis j = getShard(key); - return j.sadd(key, member); + return j.sadd(key, members); } public Set smembers(byte[] key) { @@ -240,9 +240,9 @@ public class BinaryShardedJedis extends Sharded return j.smembers(key); } - public Long srem(byte[] key, byte[] member) { + public Long srem(byte[] key, byte[]... members) { Jedis j = getShard(key); - return j.srem(key, member); + return j.srem(key, members); } public byte[] spop(byte[] key) { @@ -269,15 +269,20 @@ public class BinaryShardedJedis extends Sharded Jedis j = getShard(key); return j.zadd(key, score, member); } + + public Long zadd(byte[] key, Map scoreMembers) { + Jedis j = getShard(key); + return j.zadd(key, scoreMembers); + } public Set zrange(byte[] key, int start, int end) { Jedis j = getShard(key); return j.zrange(key, start, end); } - public Long zrem(byte[] key, byte[] member) { + public Long zrem(byte[] key, byte[]... members) { Jedis j = getShard(key); - return j.zrem(key, member); + return j.zrem(key, members); } public Double zincrby(byte[] key, double score, byte[] member) { diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index 1f493e0..9c1e43d 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -169,8 +169,8 @@ public class Client extends BinaryClient implements Commands { hexists(SafeEncoder.encode(key), SafeEncoder.encode(field)); } - public void hdel(final String key, final String field) { - hdel(SafeEncoder.encode(key), SafeEncoder.encode(field)); + public void hdel(final String key, final String... fields) { + hdel(SafeEncoder.encode(key), SafeEncoder.encodeMany(fields)); } public void hlen(final String key) { @@ -189,12 +189,12 @@ public class Client extends BinaryClient implements Commands { hgetAll(SafeEncoder.encode(key)); } - public void rpush(final String key, final String string) { - rpush(SafeEncoder.encode(key), SafeEncoder.encode(string)); + public void rpush(final String key, final String... string) { + rpush(SafeEncoder.encode(key), SafeEncoder.encodeMany(string)); } - public void lpush(final String key, final String string) { - lpush(SafeEncoder.encode(key), SafeEncoder.encode(string)); + public void lpush(final String key, final String... string) { + lpush(SafeEncoder.encode(key), SafeEncoder.encodeMany(string)); } public void llen(final String key) { @@ -233,16 +233,16 @@ public class Client extends BinaryClient implements Commands { rpoplpush(SafeEncoder.encode(srckey), SafeEncoder.encode(dstkey)); } - public void sadd(final String key, final String member) { - sadd(SafeEncoder.encode(key), SafeEncoder.encode(member)); + public void sadd(final String key, final String... members) { + sadd(SafeEncoder.encode(key), SafeEncoder.encodeMany(members)); } public void smembers(final String key) { smembers(SafeEncoder.encode(key)); } - public void srem(final String key, final String member) { - srem(SafeEncoder.encode(key), SafeEncoder.encode(member)); + public void srem(final String key, final String... members) { + srem(SafeEncoder.encode(key), SafeEncoder.encodeMany(members)); } public void spop(final String key) { @@ -323,8 +323,8 @@ public class Client extends BinaryClient implements Commands { zrange(SafeEncoder.encode(key), start, end); } - public void zrem(final String key, final String member) { - zrem(SafeEncoder.encode(key), SafeEncoder.encode(member)); + public void zrem(final String key, final String... members) { + zrem(SafeEncoder.encode(key), SafeEncoder.encodeMany(members)); } public void zincrby(final String key, final double score, @@ -595,4 +595,14 @@ public class Client extends BinaryClient implements Commands { public void configGet(String pattern) { configGet(SafeEncoder.encode(pattern)); } + + public void zadd(String key, Map scoreMembers) { + HashMap binaryScoreMembers = new HashMap(); + + for(Map.Entry entry : scoreMembers.entrySet()){ + binaryScoreMembers.put(entry.getKey(), SafeEncoder.encode(entry.getValue())); + } + + zaddBinary(SafeEncoder.encode(key), binaryScoreMembers); + } } diff --git a/src/main/java/redis/clients/jedis/Commands.java b/src/main/java/redis/clients/jedis/Commands.java index 235ee88..58be585 100644 --- a/src/main/java/redis/clients/jedis/Commands.java +++ b/src/main/java/redis/clients/jedis/Commands.java @@ -76,7 +76,7 @@ public interface Commands { public void hexists(final String key, final String field); - public void hdel(final String key, final String field); + public void hdel(final String key, final String... fields); public void hlen(final String key); @@ -86,9 +86,9 @@ public interface Commands { public void hgetAll(final String key); - public void rpush(final String key, final String string); + public void rpush(final String key, final String... strings); - public void lpush(final String key, final String string); + public void lpush(final String key, final String... strings); public void llen(final String key); @@ -108,11 +108,11 @@ public interface Commands { public void rpoplpush(final String srckey, final String dstkey); - public void sadd(final String key, final String member); + public void sadd(final String key, final String... members); public void smembers(final String key); - public void srem(final String key, final String member); + public void srem(final String key, final String... member); public void spop(final String key); @@ -139,9 +139,11 @@ public interface Commands { public void zadd(final String key, final double score, final String member); + public void zadd(final String key, final Map scoreMembers); + public void zrange(final String key, final int start, final int end); - public void zrem(final String key, final String member); + public void zrem(final String key, final String... members); public void zincrby(final String key, final double score, final String member); diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index c71d9aa..f4fdb99 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -779,13 +779,13 @@ public class Jedis extends BinaryJedis implements JedisCommands { * Time complexity: O(1) * * @param key - * @param field + * @param fields * @return If the field was present in the hash it is deleted and 1 is * returned, otherwise 0 is returned and no operation is performed. */ - public Long hdel(final String key, final String field) { + public Long hdel(final String key, final String... fields) { checkIsInMulti(); - client.hdel(key, field); + client.hdel(key, fields); return client.getIntegerReply(); } @@ -861,13 +861,13 @@ public class Jedis extends BinaryJedis implements JedisCommands { * @see Jedis#lpush(String, String) * * @param key - * @param string + * @param strings * @return Integer reply, specifically, the number of elements inside the * list after the push operation. */ - public Long rpush(final String key, final String string) { + public Long rpush(final String key, final String... strings) { checkIsInMulti(); - client.rpush(key, string); + client.rpush(key, strings); return client.getIntegerReply(); } @@ -882,13 +882,13 @@ public class Jedis extends BinaryJedis implements JedisCommands { * @see Jedis#rpush(String, String) * * @param key - * @param string + * @param strings * @return Integer reply, specifically, the number of elements inside the * list after the push operation. */ - public Long lpush(final String key, final String string) { + public Long lpush(final String key, final String... strings) { checkIsInMulti(); - client.lpush(key, string); + client.lpush(key, strings); return client.getIntegerReply(); } @@ -1139,13 +1139,13 @@ public class Jedis extends BinaryJedis implements JedisCommands { * Time complexity O(1) * * @param key - * @param member + * @param members * @return Integer reply, specifically: 1 if the new element was added 0 if * the element was already a member of the set */ - public Long sadd(final String key, final String member) { + public Long sadd(final String key, final String... members) { checkIsInMulti(); - client.sadd(key, member); + client.sadd(key, members); return client.getIntegerReply(); } @@ -1173,13 +1173,13 @@ public class Jedis extends BinaryJedis implements JedisCommands { * Time complexity O(1) * * @param key - * @param member + * @param members * @return Integer reply, specifically: 1 if the new element was removed 0 * if the new element was not a member of the set */ - public Long srem(final String key, final String member) { + public Long srem(final String key, final String... members) { checkIsInMulti(); - client.srem(key, member); + client.srem(key, members); return client.getIntegerReply(); } @@ -1435,6 +1435,12 @@ public class Jedis extends BinaryJedis implements JedisCommands { client.zadd(key, score, member); return client.getIntegerReply(); } + + public Long zadd(final String key, final Map scoreMembers) { + checkIsInMulti(); + client.zadd(key, scoreMembers); + return client.getIntegerReply(); + } public Set zrange(final String key, final int start, final int end) { checkIsInMulti(); @@ -1454,13 +1460,13 @@ public class Jedis extends BinaryJedis implements JedisCommands { * * * @param key - * @param member + * @param members * @return Integer reply, specifically: 1 if the new element was removed 0 * if the new element was not a member of the set */ - public Long zrem(final String key, final String member) { + public Long zrem(final String key, final String... members) { checkIsInMulti(); - client.zrem(key, member); + client.zrem(key, members); return client.getIntegerReply(); } diff --git a/src/main/java/redis/clients/jedis/JedisCommands.java b/src/main/java/redis/clients/jedis/JedisCommands.java index 603b60c..4e66e39 100644 --- a/src/main/java/redis/clients/jedis/JedisCommands.java +++ b/src/main/java/redis/clients/jedis/JedisCommands.java @@ -62,7 +62,7 @@ public interface JedisCommands { Boolean hexists(String key, String field); - Long hdel(String key, String field); + Long hdel(String key, String... field); Long hlen(String key); @@ -72,9 +72,9 @@ public interface JedisCommands { Map hgetAll(String key); - Long rpush(String key, String string); + Long rpush(String key, String... string); - Long lpush(String key, String string); + Long lpush(String key, String... string); Long llen(String key); @@ -92,11 +92,11 @@ public interface JedisCommands { String rpop(String key); - Long sadd(String key, String member); + Long sadd(String key, String... member); Set smembers(String key); - Long srem(String key, String member); + Long srem(String key, String... member); String spop(String key); @@ -107,10 +107,12 @@ public interface JedisCommands { String srandmember(String key); Long zadd(String key, double score, String member); + + Long zadd(String key, Map scoreMembers); Set zrange(String key, int start, int end); - Long zrem(String key, String member); + Long zrem(String key, String... member); Double zincrby(String key, double score, String member); diff --git a/src/main/java/redis/clients/jedis/ShardedJedis.java b/src/main/java/redis/clients/jedis/ShardedJedis.java index b294149..c646b29 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedis.java +++ b/src/main/java/redis/clients/jedis/ShardedJedis.java @@ -173,9 +173,9 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { return j.del(key); } - public Long hdel(String key, String field) { + public Long hdel(String key, String... fields) { Jedis j = getShard(key); - return j.hdel(key, field); + return j.hdel(key, fields); } public Long hlen(String key) { @@ -198,14 +198,14 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { return j.hgetAll(key); } - public Long rpush(String key, String string) { + public Long rpush(String key, String... strings) { Jedis j = getShard(key); - return j.rpush(key, string); + return j.rpush(key, strings); } - public Long lpush(String key, String string) { + public Long lpush(String key, String... strings) { Jedis j = getShard(key); - return j.lpush(key, string); + return j.lpush(key, strings); } public Long llen(String key) { @@ -248,9 +248,9 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { return j.rpop(key); } - public Long sadd(String key, String member) { + public Long sadd(String key, String... members) { Jedis j = getShard(key); - return j.sadd(key, member); + return j.sadd(key, members); } public Set smembers(String key) { @@ -258,9 +258,9 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { return j.smembers(key); } - public Long srem(String key, String member) { + public Long srem(String key, String... members) { Jedis j = getShard(key); - return j.srem(key, member); + return j.srem(key, members); } public String spop(String key) { @@ -287,15 +287,20 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { Jedis j = getShard(key); return j.zadd(key, score, member); } + + public Long zadd(String key, Map scoreMembers) { + Jedis j = getShard(key); + return j.zadd(key, scoreMembers); + } public Set zrange(String key, int start, int end) { Jedis j = getShard(key); return j.zrange(key, start, end); } - public Long zrem(String key, String member) { + public Long zrem(String key, String... members) { Jedis j = getShard(key); - return j.zrem(key, member); + return j.zrem(key, members); } public Double zincrby(String key, double score, String member) { diff --git a/src/main/java/redis/clients/util/SafeEncoder.java b/src/main/java/redis/clients/util/SafeEncoder.java index 8e88c40..d63fe0b 100644 --- a/src/main/java/redis/clients/util/SafeEncoder.java +++ b/src/main/java/redis/clients/util/SafeEncoder.java @@ -1,6 +1,8 @@ package redis.clients.util; import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.List; import redis.clients.jedis.Protocol; import redis.clients.jedis.exceptions.JedisDataException; @@ -11,6 +13,14 @@ import redis.clients.jedis.exceptions.JedisException; * */ public class SafeEncoder { + public static byte[][] encodeMany(final String... strs){ + byte[][] many = new byte[strs.length][]; + for(int i=0;i Date: Thu, 19 Apr 2012 00:32:23 -0400 Subject: [PATCH 052/112] Object commands are supported --- .../redis/clients/jedis/BinaryClient.java | 15 ++++++ .../java/redis/clients/jedis/BinaryJedis.java | 15 ++++++ .../clients/jedis/BinaryJedisCommands.java | 6 +++ .../clients/jedis/BinaryShardedJedis.java | 15 ++++++ src/main/java/redis/clients/jedis/Client.java | 12 +++++ .../java/redis/clients/jedis/Commands.java | 7 +++ src/main/java/redis/clients/jedis/Jedis.java | 17 ++++++- .../java/redis/clients/jedis/Protocol.java | 4 +- .../tests/commands/ObjectCommandsTest.java | 48 +++++++++++++++++++ 9 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 src/test/java/redis/clients/jedis/tests/commands/ObjectCommandsTest.java diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index 812defe..2534f25 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -6,6 +6,9 @@ import static redis.clients.jedis.Protocol.Keyword.LIMIT; import static redis.clients.jedis.Protocol.Keyword.NO; import static redis.clients.jedis.Protocol.Keyword.ONE; import static redis.clients.jedis.Protocol.Keyword.STORE; +import static redis.clients.jedis.Protocol.Keyword.REFCOUNT; +import static redis.clients.jedis.Protocol.Keyword.ENCODING; +import static redis.clients.jedis.Protocol.Keyword.IDLETIME; import static redis.clients.jedis.Protocol.Keyword.WITHSCORES; import java.util.ArrayList; @@ -718,4 +721,16 @@ public class BinaryClient extends Connection { db = 0; super.disconnect(); } + + public void objectRefcount(byte[] key) { + sendCommand(OBJECT, REFCOUNT.raw, key); + } + + public void objectIdletime(byte[] key) { + sendCommand(OBJECT, IDLETIME.raw, key); + } + + public void objectEncoding(byte[] key) { + sendCommand(OBJECT, ENCODING.raw, key); + } } diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 7b4cd30..136c21d 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -3006,4 +3006,19 @@ public class BinaryJedis implements BinaryJedisCommands { public Long getDB() { return client.getDB(); } + + public Long objectRefcount(byte[] key) { + client.objectRefcount(key); + return client.getIntegerReply(); + } + + public byte[] objectEncoding(byte[] key) { + client.objectEncoding(key); + return client.getBinaryBulkReply(); + } + + public Long objectIdletime(byte[] key) { + client.objectIdletime(key); + return client.getIntegerReply(); + } } diff --git a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java index ef8aebd..cfaefe7 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java +++ b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java @@ -154,4 +154,10 @@ public interface BinaryJedisCommands { Long zremrangeByScore(byte[] key, double start, double end); Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value); + + Long objectRefcount(byte[] key); + + Long objectIdletime(byte[] key); + + byte[] objectEncoding(byte[] key); } diff --git a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java index 9c1abd2..48a243d 100644 --- a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java @@ -407,4 +407,19 @@ public class BinaryShardedJedis extends Sharded pipeline.setShardedJedis(this); return pipeline; } + + public Long objectRefcount(byte[] key) { + Jedis j = getShard(key); + return j.objectRefcount(key); + } + + public byte[] objectEncoding(byte[] key) { + Jedis j = getShard(key); + return j.objectEncoding(key); + } + + public Long objectIdletime(byte[] key) { + Jedis j = getShard(key); + return j.objectIdletime(key); + } } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index 1f493e0..738bed2 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -595,4 +595,16 @@ public class Client extends BinaryClient implements Commands { public void configGet(String pattern) { configGet(SafeEncoder.encode(pattern)); } + + public void objectRefcount(String key) { + objectRefcount(SafeEncoder.encode(key)); + } + + public void objectIdletime(String key) { + objectIdletime(SafeEncoder.encode(key)); + } + + public void objectEncoding(String key) { + objectEncoding(SafeEncoder.encode(key)); + } } diff --git a/src/main/java/redis/clients/jedis/Commands.java b/src/main/java/redis/clients/jedis/Commands.java index 235ee88..0d17d25 100644 --- a/src/main/java/redis/clients/jedis/Commands.java +++ b/src/main/java/redis/clients/jedis/Commands.java @@ -3,6 +3,7 @@ package redis.clients.jedis; import java.util.Map; import redis.clients.jedis.BinaryClient.LIST_POSITION; +import redis.clients.util.SafeEncoder; public interface Commands { @@ -259,4 +260,10 @@ public interface Commands { public void exec(); public void discard(); + + public void objectRefcount(String key); + + public void objectIdletime(String key); + + public void objectEncoding(String key); } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index c71d9aa..081cb69 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -2688,5 +2688,20 @@ public class Jedis extends BinaryJedis implements JedisCommands { public String configSet(final String parameter, final String value) { client.configSet(parameter, value); return client.getStatusCodeReply(); - } + } + + public Long objectRefcount(String string) { + client.objectRefcount(string); + return client.getIntegerReply(); + } + + public String objectEncoding(String string) { + client.objectEncoding(string); + return client.getBulkReply(); + } + + public Long objectIdletime(String string) { + client.objectIdletime(string); + return client.getIntegerReply(); + } } diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index a4f1c7e..0baee7f 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -140,7 +140,7 @@ public final class Protocol { } public static enum Command { - PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE; + PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, OBJECT; public final byte[] raw; @@ -150,7 +150,7 @@ public final class Protocol { } public static enum Keyword { - AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT; + AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT, REFCOUNT, ENCODING, IDLETIME; public final byte[] raw; Keyword() { diff --git a/src/test/java/redis/clients/jedis/tests/commands/ObjectCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ObjectCommandsTest.java new file mode 100644 index 0000000..cbab817 --- /dev/null +++ b/src/test/java/redis/clients/jedis/tests/commands/ObjectCommandsTest.java @@ -0,0 +1,48 @@ +package redis.clients.jedis.tests.commands; + +import org.junit.Test; + +import redis.clients.util.SafeEncoder; + +public class ObjectCommandsTest extends JedisCommandTestBase { + + private String key = "key"; + private byte[] binaryKey = SafeEncoder.encode(key); + + @Test + public void objectRefcount() { + jedis.set(key, "test"); + Long refcount = jedis.objectRefcount(key); + assertEquals(new Long(1), refcount); + + //Binary + refcount = jedis.objectRefcount(binaryKey); + assertEquals(new Long(1), refcount); + + } + + @Test + public void objectEncoding() { + jedis.set(key, "test"); + String encoding = jedis.objectEncoding(key); + assertEquals("raw", encoding); + + //Binary + encoding = SafeEncoder.encode(jedis.objectEncoding(binaryKey)); + assertEquals("raw", encoding); + } + + @Test + public void objectIdletime() throws InterruptedException { + jedis.set(key, "test"); + + //Wait a little bit more than 10 seconds so the idle time is 10 seconds. + Thread.sleep(10001); + Long time = jedis.objectIdletime(key); + assertEquals(new Long(10), time); + + //Binary + time = jedis.objectIdletime(binaryKey); + assertEquals(new Long(10), time); + } +} \ No newline at end of file From dd88c51db8354036b4f9b761e6b076c0beabee50 Mon Sep 17 00:00:00 2001 From: ivowiblo Date: Thu, 19 Apr 2012 01:51:02 -0400 Subject: [PATCH 053/112] Tests for Variadic commands --- .../tests/commands/VariadicCommandsTest.java | 190 ++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 src/test/java/redis/clients/jedis/tests/commands/VariadicCommandsTest.java diff --git a/src/test/java/redis/clients/jedis/tests/commands/VariadicCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/VariadicCommandsTest.java new file mode 100644 index 0000000..fd63859 --- /dev/null +++ b/src/test/java/redis/clients/jedis/tests/commands/VariadicCommandsTest.java @@ -0,0 +1,190 @@ +package redis.clients.jedis.tests.commands; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.junit.Test; + +public class VariadicCommandsTest extends JedisCommandTestBase { + final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; + final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 }; + final byte[] bcar = { 0x09, 0x0A, 0x0B, 0x0C }; + final byte[] bfoo1 = { 0x01, 0x02, 0x03, 0x04, 0x0A }; + final byte[] bfoo2 = { 0x01, 0x02, 0x03, 0x04, 0x0B }; + + @Test + public void hdel() { + Map hash = new HashMap(); + hash.put("bar", "car"); + hash.put("car", "bar"); + hash.put("foo2", "bar"); + jedis.hmset("foo", hash); + + assertEquals(0, jedis.hdel("bar", "foo", "foo1").intValue()); + assertEquals(0, jedis.hdel("foo", "foo", "foo1").intValue()); + assertEquals(2, jedis.hdel("foo", "bar", "foo2").intValue()); + assertEquals(null, jedis.hget("foo", "bar")); + + // Binary + Map bhash = new HashMap(); + bhash.put(bbar, bcar); + bhash.put(bcar, bbar); + bhash.put(bfoo2, bbar); + jedis.hmset(bfoo, bhash); + + assertEquals(0, jedis.hdel(bbar, bfoo, bfoo1).intValue()); + assertEquals(0, jedis.hdel(bfoo, bfoo, bfoo1).intValue()); + assertEquals(2, jedis.hdel(bfoo, bbar, bfoo2).intValue()); + assertEquals(null, jedis.hget(bfoo, bbar)); + + } + + @Test + public void rpush() { + long size = jedis.rpush("foo", "bar", "foo"); + assertEquals(2, size); + + List expected = new ArrayList(); + expected.add("bar"); + expected.add("foo"); + + List values = jedis.lrange("foo",0,-1); + assertEquals(expected, values); + + // Binary + size = jedis.rpush(bfoo, bbar, bfoo); + assertEquals(2, size); + + List bexpected = new ArrayList(); + bexpected.add(bbar); + bexpected.add(bfoo); + + List bvalues = jedis.lrange(bfoo, 0, -1); + assertEquals(bexpected, bvalues); + + } + + @Test + public void lpush() { + long size = jedis.lpush("foo", "bar", "foo"); + assertEquals(2, size); + + List expected = new ArrayList(); + expected.add("foo"); + expected.add("bar"); + + List values = jedis.lrange("foo",0,-1); + assertEquals(expected, values); + + // Binary + size = jedis.lpush(bfoo, bbar, bfoo); + assertEquals(2, size); + + List bexpected = new ArrayList(); + bexpected.add(bfoo); + bexpected.add(bbar); + + List bvalues = jedis.lrange(bfoo, 0, -1); + assertEquals(bexpected, bvalues); + + } + + @Test + public void sadd() { + long status = jedis.sadd("foo", "bar", "foo1"); + assertEquals(2, status); + + status = jedis.sadd("foo", "bar", "car"); + assertEquals(1, status); + + status = jedis.sadd("foo", "bar", "foo1"); + assertEquals(0, status); + + status = jedis.sadd(bfoo, bbar, bfoo1); + assertEquals(2, status); + + status = jedis.sadd(bfoo, bbar, bcar); + assertEquals(1, status); + + status = jedis.sadd(bfoo, bbar, bfoo1); + assertEquals(0, status); + + } + + @Test + public void zadd() { + Map scoreMembers = new HashMap(); + scoreMembers.put(1d, "bar"); + scoreMembers.put(10d, "foo"); + + long status = jedis.zadd("foo", scoreMembers); + assertEquals(2, status); + + scoreMembers.clear(); + scoreMembers.put(0.1d, "car"); + scoreMembers.put(2d, "bar"); + + status = jedis.zadd("foo", scoreMembers); + assertEquals(1, status); + + Map bscoreMembers = new HashMap(); + bscoreMembers.put(1d, bbar); + bscoreMembers.put(10d, bfoo); + + status = jedis.zadd(bfoo, bscoreMembers); + assertEquals(2, status); + + bscoreMembers.clear(); + bscoreMembers.put(0.1d, bcar); + bscoreMembers.put(2d, bbar); + + status = jedis.zadd(bfoo, bscoreMembers); + assertEquals(1, status); + + } + + @Test + public void zrem() { + jedis.zadd("foo", 1d, "bar"); + jedis.zadd("foo", 2d, "car"); + jedis.zadd("foo", 3d, "foo1"); + + long status = jedis.zrem("foo", "bar", "car"); + + Set expected = new LinkedHashSet(); + expected.add("foo1"); + + assertEquals(2, status); + assertEquals(expected, jedis.zrange("foo", 0, 100)); + + status = jedis.zrem("foo", "bar", "car"); + assertEquals(0, status); + + status = jedis.zrem("foo", "bar", "foo1"); + assertEquals(1, status); + + //Binary + jedis.zadd(bfoo, 1d, bbar); + jedis.zadd(bfoo, 2d, bcar); + jedis.zadd(bfoo, 3d, bfoo1); + + status = jedis.zrem(bfoo, bbar, bcar); + + Set bexpected = new LinkedHashSet(); + bexpected.add(bfoo); + + assertEquals(2, status); + assertEquals(bexpected, jedis.zrange(bfoo, 0, 100)); + + status = jedis.zrem(bfoo, bbar, bcar); + assertEquals(0, status); + + status = jedis.zrem(bfoo, bbar, bfoo1); + assertEquals(1, status); + + } +} \ No newline at end of file From d5c2b9965c65c5ce50e436f979453ad682b61ad9 Mon Sep 17 00:00:00 2001 From: ivowiblo Date: Thu, 19 Apr 2012 02:53:26 -0400 Subject: [PATCH 054/112] Slowlog commands. The unit test is failing. --- .../redis/clients/jedis/BinaryClient.java | 18 +++++++ .../java/redis/clients/jedis/BinaryJedis.java | 19 +++++++ .../clients/jedis/BinaryJedisCommands.java | 1 + src/main/java/redis/clients/jedis/Jedis.java | 13 ++++- .../redis/clients/jedis/JedisCommands.java | 3 ++ .../java/redis/clients/jedis/Protocol.java | 4 +- src/main/java/redis/clients/util/Slowlog.java | 53 +++++++++++++++++++ .../tests/commands/SlowlogCommandsTest.java | 47 ++++++++++++++++ 8 files changed, 155 insertions(+), 3 deletions(-) create mode 100644 src/main/java/redis/clients/util/Slowlog.java create mode 100644 src/test/java/redis/clients/jedis/tests/commands/SlowlogCommandsTest.java diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index 812defe..34885fc 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -7,6 +7,8 @@ import static redis.clients.jedis.Protocol.Keyword.NO; import static redis.clients.jedis.Protocol.Keyword.ONE; import static redis.clients.jedis.Protocol.Keyword.STORE; import static redis.clients.jedis.Protocol.Keyword.WITHSCORES; +import static redis.clients.jedis.Protocol.Keyword.RESET; +import static redis.clients.jedis.Protocol.Keyword.LEN; import java.util.ArrayList; import java.util.List; @@ -718,4 +720,20 @@ public class BinaryClient extends Connection { db = 0; super.disconnect(); } + + public void slowlogGet() { + sendCommand(SLOWLOG, Keyword.GET.raw); + } + + public void slowlogGet(long entries) { + sendCommand(SLOWLOG, Keyword.GET.raw, toByteArray(entries)); + } + + public void slowlogReset() { + sendCommand(SLOWLOG, RESET.raw); + } + + public void slowlogLen() { + sendCommand(SLOWLOG, LEN.raw); + } } diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 7b4cd30..19c6314 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -3006,4 +3006,23 @@ public class BinaryJedis implements BinaryJedisCommands { public Long getDB() { return client.getDB(); } + + public void slowlogReset() { + client.slowlogReset(); + } + + public long slowlogLen() { + client.slowlogLen(); + return client.getIntegerReply(); + } + + public List slowlogGetBinary() { + client.slowlogGet(); + return client.getBinaryMultiBulkReply(); + } + + public List slowlogGetBinary(long entries) { + client.slowlogGet(entries); + return client.getBinaryMultiBulkReply(); + } } diff --git a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java index ef8aebd..c5ba5df 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java +++ b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java @@ -154,4 +154,5 @@ public interface BinaryJedisCommands { Long zremrangeByScore(byte[] key, double start, double end); Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value); + } diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index c71d9aa..e757fee 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -9,6 +9,7 @@ import java.util.Map; import java.util.Set; import redis.clients.jedis.BinaryClient.LIST_POSITION; +import redis.clients.util.Slowlog; public class Jedis extends BinaryJedis implements JedisCommands { public Jedis(final String host) { @@ -2688,5 +2689,15 @@ public class Jedis extends BinaryJedis implements JedisCommands { public String configSet(final String parameter, final String value) { client.configSet(parameter, value); return client.getStatusCodeReply(); - } + } + + public List slowlogGet() { + client.slowlogGet(); + return Slowlog.from(client.getObjectMultiBulkReply()); + } + + public List slowlogGet(long entries) { + client.slowlogGet(entries); + return Slowlog.from(client.getObjectMultiBulkReply()); + } } diff --git a/src/main/java/redis/clients/jedis/JedisCommands.java b/src/main/java/redis/clients/jedis/JedisCommands.java index 603b60c..374982b 100644 --- a/src/main/java/redis/clients/jedis/JedisCommands.java +++ b/src/main/java/redis/clients/jedis/JedisCommands.java @@ -4,6 +4,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import redis.clients.util.Slowlog; + /** * Common interface for sharded and non-sharded Jedis */ @@ -160,4 +162,5 @@ public interface JedisCommands { Long linsert(String key, Client.LIST_POSITION where, String pivot, String value); + } diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index a4f1c7e..e7613ec 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -140,7 +140,7 @@ public final class Protocol { } public static enum Command { - PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE; + PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, SLOWLOG; public final byte[] raw; @@ -150,7 +150,7 @@ public final class Protocol { } public static enum Keyword { - AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT; + AGGREGATE, ALPHA, ASC, BY, DESC, GET, LEN, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT, RESET; public final byte[] raw; Keyword() { diff --git a/src/main/java/redis/clients/util/Slowlog.java b/src/main/java/redis/clients/util/Slowlog.java new file mode 100644 index 0000000..0e805f7 --- /dev/null +++ b/src/main/java/redis/clients/util/Slowlog.java @@ -0,0 +1,53 @@ +package redis.clients.util; + +import java.util.ArrayList; +import java.util.List; + +public class Slowlog { + private final long id; + private final long timeStamp; + private final long executionTime; + private final List args; + + @SuppressWarnings("unchecked") + public static List from(List nestedMultiBulkReply){ + List logs = new ArrayList(nestedMultiBulkReply.size()); + for(Object obj:nestedMultiBulkReply){ + List list = (List)obj; + logs.add(new Slowlog(list)); + } + + return logs; + } + + @SuppressWarnings("unchecked") + private Slowlog(List properties) { + super(); + this.id = (Long)properties.get(0); + this.timeStamp = (Long)properties.get(1); + this.executionTime = (Long)properties.get(2); + + List bargs = (List)properties.get(3); + this.args = new ArrayList(bargs.size()); + + for(byte[] barg:bargs){ + this.args.add(SafeEncoder.encode(barg)); + } + } + + public long getId() { + return id; + } + + public long getTimeStamp() { + return timeStamp; + } + + public long getExecutionTime() { + return executionTime; + } + + public List getArgs() { + return args; + } +} diff --git a/src/test/java/redis/clients/jedis/tests/commands/SlowlogCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/SlowlogCommandsTest.java new file mode 100644 index 0000000..3e37d13 --- /dev/null +++ b/src/test/java/redis/clients/jedis/tests/commands/SlowlogCommandsTest.java @@ -0,0 +1,47 @@ +package redis.clients.jedis.tests.commands; + +import java.util.List; + +import org.junit.Test; + +import redis.clients.util.Slowlog; + +public class SlowlogCommandsTest extends JedisCommandTestBase { + + @Test + public void slowlog() { + //do something + jedis.set("foo", "bar"); + jedis.set("foo2", "bar2"); + + List reducedLog = jedis.slowlogGet(1); + assertEquals(1, reducedLog.size()); + + Slowlog log = reducedLog.get(0); + assertTrue(log.getId() > 0); + assertTrue(log.getTimeStamp() > 0); + assertTrue(log.getExecutionTime() > 0); + assertNotNull(log.getArgs()); + + List breducedLog = jedis.slowlogGetBinary(1); + assertEquals(1, breducedLog.size()); + + List log1 = jedis.slowlogGet(); + List blog1 = jedis.slowlogGetBinary(); + + assertNotNull(log1); + assertNotNull(blog1); + + long len1 = jedis.slowlogLen(); + + jedis.slowlogReset(); + + List log2 = jedis.slowlogGet(); + List blog2 = jedis.slowlogGetBinary(); + long len2 = jedis.slowlogLen(); + + assertTrue(len1 > len2); + assertTrue(log1.size() > log2.size()); + assertTrue(blog1.size() > blog2.size()); + } +} \ No newline at end of file From e008f403b1302106909d7ba912fbb81592a8ef64 Mon Sep 17 00:00:00 2001 From: ivowiblo Date: Thu, 19 Apr 2012 02:59:52 -0400 Subject: [PATCH 055/112] SLOWLOG RESET is fixed --- src/main/java/redis/clients/jedis/BinaryJedis.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 19c6314..2f43027 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -3007,8 +3007,9 @@ public class BinaryJedis implements BinaryJedisCommands { return client.getDB(); } - public void slowlogReset() { + public byte[] slowlogReset() { client.slowlogReset(); + return client.getBinaryBulkReply(); } public long slowlogLen() { From c765bc39105566f7af1c68d6b3897eeb5c85038e Mon Sep 17 00:00:00 2001 From: ivowiblo Date: Thu, 19 Apr 2012 03:04:06 -0400 Subject: [PATCH 056/112] Style refactor --- src/main/java/redis/clients/jedis/BinaryJedisCommands.java | 1 - src/main/java/redis/clients/jedis/JedisCommands.java | 3 --- src/main/java/redis/clients/util/Slowlog.java | 6 +++--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java index c5ba5df..ef8aebd 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java +++ b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java @@ -154,5 +154,4 @@ public interface BinaryJedisCommands { Long zremrangeByScore(byte[] key, double start, double end); Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value); - } diff --git a/src/main/java/redis/clients/jedis/JedisCommands.java b/src/main/java/redis/clients/jedis/JedisCommands.java index 374982b..603b60c 100644 --- a/src/main/java/redis/clients/jedis/JedisCommands.java +++ b/src/main/java/redis/clients/jedis/JedisCommands.java @@ -4,8 +4,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import redis.clients.util.Slowlog; - /** * Common interface for sharded and non-sharded Jedis */ @@ -162,5 +160,4 @@ public interface JedisCommands { Long linsert(String key, Client.LIST_POSITION where, String pivot, String value); - } diff --git a/src/main/java/redis/clients/util/Slowlog.java b/src/main/java/redis/clients/util/Slowlog.java index 0e805f7..0a0e7be 100644 --- a/src/main/java/redis/clients/util/Slowlog.java +++ b/src/main/java/redis/clients/util/Slowlog.java @@ -12,9 +12,9 @@ public class Slowlog { @SuppressWarnings("unchecked") public static List from(List nestedMultiBulkReply){ List logs = new ArrayList(nestedMultiBulkReply.size()); - for(Object obj:nestedMultiBulkReply){ - List list = (List)obj; - logs.add(new Slowlog(list)); + for(Object obj : nestedMultiBulkReply){ + List properties = (List)obj; + logs.add(new Slowlog(properties)); } return logs; From dbd7c8b53fedb4199390439fe5f211462bdaf500 Mon Sep 17 00:00:00 2001 From: Tom Martin Date: Thu, 19 Apr 2012 13:38:40 +0200 Subject: [PATCH 057/112] Fix NPE in BuilderFactory for Double. --- src/main/java/redis/clients/jedis/BuilderFactory.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/BuilderFactory.java b/src/main/java/redis/clients/jedis/BuilderFactory.java index ad94282..8a2320a 100644 --- a/src/main/java/redis/clients/jedis/BuilderFactory.java +++ b/src/main/java/redis/clients/jedis/BuilderFactory.java @@ -7,7 +7,8 @@ import java.util.*; public class BuilderFactory { public static final Builder DOUBLE = new Builder() { public Double build(Object data) { - return Double.valueOf(STRING.build(data)); + String asString = STRING.build(data); + return asString == null ? null : Double.valueOf(asString); } public String toString() { From 5a6d98ac56f8dec608c79c242c81389149fc3def Mon Sep 17 00:00:00 2001 From: Eric Hauser Date: Thu, 19 Apr 2012 16:48:18 -0400 Subject: [PATCH 058/112] fix broken instance reference to protocol --- src/main/java/redis/clients/jedis/Connection.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index 7aadc7f..5a168a7 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -209,7 +209,7 @@ public class Connection { public List getIntegerMultiBulkReply() { flush(); pipelinedCommands--; - return (List) protocol.read(inputStream); + return (List) Protocol.read(inputStream); } public List getAll() { @@ -235,4 +235,4 @@ public class Connection { pipelinedCommands--; return Protocol.read(inputStream); } -} \ No newline at end of file +} From 094023a7ceed5819aed237241449aae14555dbef Mon Sep 17 00:00:00 2001 From: Eric Hauser Date: Thu, 19 Apr 2012 16:53:06 -0400 Subject: [PATCH 059/112] make gradlew executable --- gradlew | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 gradlew diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 From 6bc2ac0a4fd7d8467d9b2f0c2266ede71fcc9e02 Mon Sep 17 00:00:00 2001 From: ivowiblo Date: Sun, 29 Apr 2012 02:43:39 -0400 Subject: [PATCH 060/112] Pipeline supports Multi. Issue #251 is fixed. --- .../java/redis/clients/jedis/Pipeline.java | 56 ++++++++++++++++++- .../clients/jedis/tests/PipeliningTest.java | 25 +++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index 520e975..05ee8d0 100644 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -9,8 +9,51 @@ import redis.clients.jedis.BinaryClient.LIST_POSITION; import redis.clients.jedis.exceptions.JedisDataException; public class Pipeline extends Queable { - private Client client; + + private MultiResponseBuilder currentMulti; + + private class MultiResponseBuilder extends Builder>{ + private List> responses = new ArrayList>(); + + @Override + public List build(Object data) { + @SuppressWarnings("unchecked") + List list = (List)data; + List values = new ArrayList(); + + if(list.size() != responses.size()){ + throw new JedisDataException("Expected data size " + responses.size() + " but was " + list.size()); + } + + for(int i=0;i response = responses.get(i); + response.set(list.get(i)); + values.add(response.get()); + } + return values; + } + public void addResponse(Response response){ + responses.add(response); + } + } + + @Override + protected Response getResponse(Builder builder) { + if(currentMulti != null){ + super.getResponse(BuilderFactory.STRING); //Expected QUEUED + + Response lr = new Response(builder); + currentMulti.addResponse(lr); + return lr; + } + else{ + return super.getResponse(builder); + } + } + + private Client client; + public void setClient(Client client) { this.client = client; } @@ -39,9 +82,11 @@ public class Pipeline extends Queable { public List syncAndReturnAll() { List unformatted = client.getAll(); List formatted = new ArrayList(); + for (Object o : unformatted) { try { - formatted.add(generateResponse(o).get()); + Response pr = generateResponse(o); + formatted.add(pr.get()); } catch (JedisDataException e) { formatted.add(e); } @@ -1176,10 +1221,14 @@ public class Pipeline extends Queable { public void exec() { client.exec(); + super.getResponse(currentMulti); + currentMulti = null; } public void multi() { client.multi(); + getResponse(BuilderFactory.STRING); //Expecting OK + currentMulti = new MultiResponseBuilder(); } public Response publish(String channel, String message) { @@ -1230,5 +1279,6 @@ public class Pipeline extends Queable { public Response select(int index){ client.select(index); return getResponse(BuilderFactory.STRING); - } + } + } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java index 0a2f7d4..93afb10 100644 --- a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java +++ b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java @@ -164,4 +164,29 @@ public class PipeliningTest extends Assert { } assertEquals(r.get(), "bar"); } + + @Test + public void multi(){ + Pipeline p = jedis.pipelined(); + p.multi(); + Response r1 = p.hincrBy("a", "f1", -1); + Response r2 = p.hincrBy("a", "f1", -2); + p.exec(); + List result = p.syncAndReturnAll(); + + assertEquals(new Long(-1), r1.get()); + assertEquals(new Long(-3), r2.get()); + + assertEquals(4, result.size()); + + assertEquals("OK", result.get(0)); + assertEquals("QUEUED", result.get(1)); + assertEquals("QUEUED", result.get(2)); + + //4th result is a list with the results from the multi + @SuppressWarnings("unchecked") + List multiResult = (List) result.get(3); + assertEquals(new Long(-1), multiResult.get(0)); + assertEquals(new Long(-3), multiResult.get(1)); + } } From d84ffdd8bc6c2f25c9a417291632516a44b77f08 Mon Sep 17 00:00:00 2001 From: ivowiblo Date: Sun, 29 Apr 2012 02:48:11 -0400 Subject: [PATCH 061/112] Format improved --- src/main/java/redis/clients/jedis/Pipeline.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index 05ee8d0..3f417a6 100644 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -85,8 +85,7 @@ public class Pipeline extends Queable { for (Object o : unformatted) { try { - Response pr = generateResponse(o); - formatted.add(pr.get()); + formatted.add(generateResponse(o).get()); } catch (JedisDataException e) { formatted.add(e); } From d526a32b12403609b9c7c68f17a8cfbc00c48f40 Mon Sep 17 00:00:00 2001 From: ivowiblo Date: Sun, 29 Apr 2012 02:55:22 -0400 Subject: [PATCH 062/112] Pipeline.exec() now returns a response --- src/main/java/redis/clients/jedis/Pipeline.java | 6 +++--- src/test/java/redis/clients/jedis/tests/PipeliningTest.java | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index 3f417a6..1e04deb 100644 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -1218,10 +1218,11 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING); } - public void exec() { + public Response> exec() { client.exec(); - super.getResponse(currentMulti); + Response> response = super.getResponse(currentMulti); currentMulti = null; + return response; } public void multi() { @@ -1279,5 +1280,4 @@ public class Pipeline extends Queable { client.select(index); return getResponse(BuilderFactory.STRING); } - } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java index 93afb10..568a2cd 100644 --- a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java +++ b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java @@ -171,7 +171,7 @@ public class PipeliningTest extends Assert { p.multi(); Response r1 = p.hincrBy("a", "f1", -1); Response r2 = p.hincrBy("a", "f1", -2); - p.exec(); + Response> r3 = p.exec(); List result = p.syncAndReturnAll(); assertEquals(new Long(-1), r1.get()); @@ -188,5 +188,9 @@ public class PipeliningTest extends Assert { List multiResult = (List) result.get(3); assertEquals(new Long(-1), multiResult.get(0)); assertEquals(new Long(-3), multiResult.get(1)); + + assertEquals(new Long(-1), r3.get().get(0)); + assertEquals(new Long(-3), r3.get().get(1)); + } } From 129e358c9dd8b35888708747d31dd31ca6cf7493 Mon Sep 17 00:00:00 2001 From: ivowiblo Date: Thu, 3 May 2012 23:30:44 -0400 Subject: [PATCH 063/112] Now methods accepting infinit and exclusions are supported as String and byte[] overloads --- .../redis/clients/jedis/BinaryClient.java | 56 +++++------ .../java/redis/clients/jedis/BinaryJedis.java | 97 +++++++++++++------ .../clients/jedis/BinaryJedisCommands.java | 19 ++++ .../clients/jedis/BinaryShardedJedis.java | 45 +++++++++ .../clients/jedis/BinaryTransaction.java | 42 ++++++-- src/main/java/redis/clients/jedis/Client.java | 61 ++++++++++-- .../java/redis/clients/jedis/Commands.java | 19 +++- src/main/java/redis/clients/jedis/Jedis.java | 61 ++++++++++++ .../redis/clients/jedis/JedisCommands.java | 24 +++++ .../java/redis/clients/jedis/Pipeline.java | 49 +++++++++- .../redis/clients/jedis/ShardedJedis.java | 55 +++++++++++ .../tests/commands/SortedSetCommandsTest.java | 9 +- 12 files changed, 448 insertions(+), 89 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index d12a845..3fecbd8 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -527,18 +527,8 @@ public class BinaryClient extends Connection { sendCommand(PUNSUBSCRIBE, patterns); } - public void zcount(final byte[] key, final double min, final double max) { - sendCommand(ZCOUNT, key, toByteArray(min), toByteArray(max)); - } - - public void zrangeByScore(final byte[] key, final double min, - final double max) { - sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max)); - } - - public void zrevrangeByScore(final byte[] key, final double max, - final double min) { - sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min)); + public void zcount(final byte[] key, final byte[] min, final byte[] max) { + sendCommand(ZCOUNT, key, min, max); } public void zrangeByScore(final byte[] key, final byte[] min, @@ -551,40 +541,40 @@ public class BinaryClient extends Connection { sendCommand(ZREVRANGEBYSCORE, key, max, min); } - public void zrangeByScore(final byte[] key, final double min, - final double max, final int offset, int count) { - sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max), + public void zrangeByScore(final byte[] key, final byte[] min, + final byte[] max, final int offset, int count) { + sendCommand(ZRANGEBYSCORE, key, min, max, LIMIT.raw, toByteArray(offset), toByteArray(count)); } - public void zrevrangeByScore(final byte[] key, final double max, - final double min, final int offset, int count) { - sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min), + public void zrevrangeByScore(final byte[] key, final byte[] max, + final byte[] min, final int offset, int count) { + sendCommand(ZREVRANGEBYSCORE, key, max, min, LIMIT.raw, toByteArray(offset), toByteArray(count)); } - public void zrangeByScoreWithScores(final byte[] key, final double min, - final double max) { - sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max), + public void zrangeByScoreWithScores(final byte[] key, final byte[] min, + final byte[] max) { + sendCommand(ZRANGEBYSCORE, key, min, max, WITHSCORES.raw); } - public void zrevrangeByScoreWithScores(final byte[] key, final double max, - final double min) { - sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min), + public void zrevrangeByScoreWithScores(final byte[] key, final byte[] max, + final byte[] min) { + sendCommand(ZREVRANGEBYSCORE, key, max, min, WITHSCORES.raw); } - public void zrangeByScoreWithScores(final byte[] key, final double min, - final double max, final int offset, final int count) { - sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max), + public void zrangeByScoreWithScores(final byte[] key, final byte[] min, + final byte[] max, final int offset, final int count) { + sendCommand(ZRANGEBYSCORE, key, min, max, LIMIT.raw, toByteArray(offset), toByteArray(count), WITHSCORES.raw); } - public void zrevrangeByScoreWithScores(final byte[] key, final double max, - final double min, final int offset, final int count) { - sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min), + public void zrevrangeByScoreWithScores(final byte[] key, final byte[] max, + final byte[] min, final int offset, final int count) { + sendCommand(ZREVRANGEBYSCORE, key, max, min, LIMIT.raw, toByteArray(offset), toByteArray(count), WITHSCORES.raw); } @@ -593,9 +583,9 @@ public class BinaryClient extends Connection { sendCommand(ZREMRANGEBYRANK, key, toByteArray(start), toByteArray(end)); } - public void zremrangeByScore(final byte[] key, final double start, - final double end) { - sendCommand(ZREMRANGEBYSCORE, key, toByteArray(start), toByteArray(end)); + public void zremrangeByScore(final byte[] key, final byte[] start, + final byte[] end) { + sendCommand(ZREMRANGEBYSCORE, key, start, end); } public void zunionstore(final byte[] dstkey, final byte[]... sets) { diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 1e38c35..6cc5f43 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -2064,11 +2064,15 @@ public class BinaryJedis implements BinaryJedisCommands { } public Long zcount(final byte[] key, final double min, final double max) { - checkIsInMulti(); - client.zcount(key, min, max); - return client.getIntegerReply(); + return zcount(key, toByteArray(min), toByteArray(max)); } - + + public Long zcount(final byte[] key, final byte[] min, final byte[] max) { + checkIsInMulti(); + client.zcount(key, min, max); + return client.getIntegerReply(); + } + /** * Return the all the elements in the sorted set at key with a score between * min and max (including elements with score equal to min or max). @@ -2127,10 +2131,8 @@ public class BinaryJedis implements BinaryJedisCommands { */ public Set zrangeByScore(final byte[] key, final double min, final double max) { - checkIsInMulti(); - client.zrangeByScore(key, min, max); - return new LinkedHashSet(client.getBinaryMultiBulkReply()); - } + return zrangeByScore(key, toByteArray(min), toByteArray(max)); + } public Set zrangeByScore(final byte[] key, final byte[] min, final byte[] max) { @@ -2197,10 +2199,15 @@ public class BinaryJedis implements BinaryJedisCommands { */ public Set zrangeByScore(final byte[] key, final double min, final double max, final int offset, final int count) { - checkIsInMulti(); - client.zrangeByScore(key, min, max, offset, count); - return new LinkedHashSet(client.getBinaryMultiBulkReply()); + return zrangeByScore(key, toByteArray(min),toByteArray(max),offset, count); } + + public Set zrangeByScore(final byte[] key, final byte[] min, + final byte[] max, final int offset, final int count) { + checkIsInMulti(); + client.zrangeByScore(key, min, max, offset, count); + return new LinkedHashSet(client.getBinaryMultiBulkReply()); + } /** * Return the all the elements in the sorted set at key with a score between @@ -2260,11 +2267,16 @@ public class BinaryJedis implements BinaryJedisCommands { */ public Set zrangeByScoreWithScores(final byte[] key, final double min, final double max) { - checkIsInMulti(); - client.zrangeByScoreWithScores(key, min, max); - Set set = getBinaryTupledSet(); - return set; + return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max)); } + + public Set zrangeByScoreWithScores(final byte[] key, + final byte[] min, final byte[] max) { + checkIsInMulti(); + client.zrangeByScoreWithScores(key, min, max); + Set set = getBinaryTupledSet(); + return set; + } /** * Return the all the elements in the sorted set at key with a score between @@ -2325,11 +2337,17 @@ public class BinaryJedis implements BinaryJedisCommands { public Set zrangeByScoreWithScores(final byte[] key, final double min, final double max, final int offset, final int count) { - checkIsInMulti(); - client.zrangeByScoreWithScores(key, min, max, offset, count); - Set set = getBinaryTupledSet(); - return set; + return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count); } + + public Set zrangeByScoreWithScores(final byte[] key, + final byte[] min, final byte[] max, final int offset, + final int count) { + checkIsInMulti(); + client.zrangeByScoreWithScores(key, min, max, offset, count); + Set set = getBinaryTupledSet(); + return set; + } private Set getBinaryTupledSet() { checkIsInMulti(); @@ -2345,9 +2363,7 @@ public class BinaryJedis implements BinaryJedisCommands { public Set zrevrangeByScore(final byte[] key, final double max, final double min) { - checkIsInMulti(); - client.zrevrangeByScore(key, max, min); - return new LinkedHashSet(client.getBinaryMultiBulkReply()); + return zrevrangeByScore(key, toByteArray(max), toByteArray(min)); } public Set zrevrangeByScore(final byte[] key, final byte[] max, @@ -2359,13 +2375,29 @@ public class BinaryJedis implements BinaryJedisCommands { public Set zrevrangeByScore(final byte[] key, final double max, final double min, final int offset, final int count) { - checkIsInMulti(); - client.zrevrangeByScore(key, max, min, offset, count); - return new LinkedHashSet(client.getBinaryMultiBulkReply()); + return zrevrangeByScore(key, toByteArray(max), toByteArray(min), offset, count); } + + public Set zrevrangeByScore(final byte[] key, final byte[] max, + final byte[] min, final int offset, final int count) { + checkIsInMulti(); + client.zrevrangeByScore(key, max, min, offset, count); + return new LinkedHashSet(client.getBinaryMultiBulkReply()); + } public Set zrevrangeByScoreWithScores(final byte[] key, final double max, final double min) { + return zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min)); + } + + public Set zrevrangeByScoreWithScores(final byte[] key, + final double max, final double min, final int offset, + final int count) { + return zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min), offset, count); + } + + public Set zrevrangeByScoreWithScores(final byte[] key, + final byte[] max, final byte[] min) { checkIsInMulti(); client.zrevrangeByScoreWithScores(key, max, min); Set set = getBinaryTupledSet(); @@ -2373,13 +2405,13 @@ public class BinaryJedis implements BinaryJedisCommands { } public Set zrevrangeByScoreWithScores(final byte[] key, - final double max, final double min, final int offset, + final byte[] max, final byte[] min, final int offset, final int count) { checkIsInMulti(); client.zrevrangeByScoreWithScores(key, max, min, offset, count); Set set = getBinaryTupledSet(); return set; - } + } /** * Remove all elements in the sorted set at key with rank between start and @@ -2416,10 +2448,15 @@ public class BinaryJedis implements BinaryJedisCommands { */ public Long zremrangeByScore(final byte[] key, final double start, final double end) { - checkIsInMulti(); - client.zremrangeByScore(key, start, end); - return client.getIntegerReply(); + return zremrangeByScore(key, toByteArray(start), toByteArray(end)); } + + public Long zremrangeByScore(final byte[] key, final byte[] start, + final byte[] end) { + checkIsInMulti(); + client.zremrangeByScore(key, start, end); + return client.getIntegerReply(); + } /** * Creates a union or intersection of N sorted sets given by keys k1 through diff --git a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java index c6ba248..922c00d 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java +++ b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java @@ -131,6 +131,8 @@ public interface BinaryJedisCommands { Long zcount(byte[] key, double min, double max); + Long zcount(byte[] key, byte[] min, byte[] max); + Set zrangeByScore(byte[] key, double min, double max); Set zrangeByScore(byte[] key, double min, double max, int offset, @@ -141,20 +143,37 @@ public interface BinaryJedisCommands { Set zrangeByScoreWithScores(byte[] key, double min, double max, int offset, int count); + Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max); + + Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max, + int offset, int count); + Set zrevrangeByScore(byte[] key, double max, double min); Set zrevrangeByScore(byte[] key, double max, double min, int offset, int count); + Set zrevrangeByScore(byte[] key, byte[] max, byte[] min); + + Set zrevrangeByScore(byte[] key, byte[] max, byte[] min, + int offset, int count); + Set zrevrangeByScoreWithScores(byte[] key, double max, double min); Set zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count); + Set zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min); + + Set zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min, + int offset, int count); + Long zremrangeByRank(byte[] key, int start, int end); Long zremrangeByScore(byte[] key, double start, double end); + Long zremrangeByScore(byte[] key, byte[] start, byte[] end); + Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value); Long objectRefcount(byte[] key); diff --git a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java index b887cc6..87eb1fc 100644 --- a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java @@ -339,6 +339,11 @@ public class BinaryShardedJedis extends Sharded Jedis j = getShard(key); return j.zcount(key, min, max); } + + public Long zcount(byte[] key, byte[] min, byte[] max) { + Jedis j = getShard(key); + return j.zcount(key, min, max); + } public Set zrangeByScore(byte[] key, double min, double max) { Jedis j = getShard(key); @@ -361,6 +366,18 @@ public class BinaryShardedJedis extends Sharded Jedis j = getShard(key); return j.zrangeByScoreWithScores(key, min, max, offset, count); } + + + public Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max) { + Jedis j = getShard(key); + return j.zrangeByScoreWithScores(key, min, max); + } + + public Set zrangeByScoreWithScores(byte[] key, byte[] min, + byte[] max, int offset, int count) { + Jedis j = getShard(key); + return j.zrangeByScoreWithScores(key, min, max, offset, count); + } public Set zrevrangeByScore(byte[] key, double max, double min) { Jedis j = getShard(key); @@ -384,6 +401,29 @@ public class BinaryShardedJedis extends Sharded Jedis j = getShard(key); return j.zrevrangeByScoreWithScores(key, max, min, offset, count); } + + public Set zrevrangeByScore(byte[] key, byte[] max, byte[] min) { + Jedis j = getShard(key); + return j.zrevrangeByScore(key, max, min); + } + + public Set zrevrangeByScore(byte[] key, byte[] max, byte[] min, + int offset, int count) { + Jedis j = getShard(key); + return j.zrevrangeByScore(key, max, min, offset, count); + } + + public Set zrevrangeByScoreWithScores(byte[] key, byte[] max, + byte[] min) { + Jedis j = getShard(key); + return j.zrevrangeByScoreWithScores(key, max, min); + } + + public Set zrevrangeByScoreWithScores(byte[] key, byte[] max, + byte[] min, int offset, int count) { + Jedis j = getShard(key); + return j.zrevrangeByScoreWithScores(key, max, min, offset, count); + } public Long zremrangeByRank(byte[] key, int start, int end) { Jedis j = getShard(key); @@ -395,6 +435,11 @@ public class BinaryShardedJedis extends Sharded return j.zremrangeByScore(key, start, end); } + public Long zremrangeByScore(byte[] key, byte[] start, byte[] end) { + Jedis j = getShard(key); + return j.zremrangeByScore(key, start, end); + } + public Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value) { Jedis j = getShard(key); diff --git a/src/main/java/redis/clients/jedis/BinaryTransaction.java b/src/main/java/redis/clients/jedis/BinaryTransaction.java index 3a6893d..96bdf2b 100644 --- a/src/main/java/redis/clients/jedis/BinaryTransaction.java +++ b/src/main/java/redis/clients/jedis/BinaryTransaction.java @@ -1,5 +1,7 @@ package redis.clients.jedis; +import static redis.clients.jedis.Protocol.toByteArray; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -446,6 +448,10 @@ public class BinaryTransaction extends Queable { } public Response zcount(byte[] key, double min, double max) { + return zcount(key, toByteArray(min), toByteArray(max)); + } + + public Response zcount(byte[] key, byte[] min, byte[] max) { client.zcount(key, min, max); return getResponse(BuilderFactory.LONG); } @@ -473,30 +479,44 @@ public class BinaryTransaction extends Queable { public Response> zrangeByScore(byte[] key, double min, double max) { + return zrangeByScore(key, toByteArray(min), toByteArray(max)); + } + + public Response> zrangeByScore(byte[] key, byte[] min, + byte[] max) { client.zrangeByScore(key, min, max); return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrangeByScore(byte[] key, byte[] min, - byte[] max) { - client.zrangeByScore(key, min, max); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrangeByScore(byte[] key, double min, - double max, int offset, int count) { + byte[] max, int offset, int count) { client.zrangeByScore(key, min, max, offset, count); return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } + + public Response> zrangeByScore(byte[] key, double min, + double max, int offset, int count) { + return zrangeByScore(key, toByteArray(min), toByteArray(max), offset, count); + } public Response> zrangeByScoreWithScores(byte[] key, double min, double max) { - client.zrangeByScoreWithScores(key, min, max); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); + return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max)); } public Response> zrangeByScoreWithScores(byte[] key, double min, double max, int offset, int count) { + return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count); + } + + public Response> zrangeByScoreWithScores(byte[] key, byte[] min, + byte[] max) { + client.zrangeByScoreWithScores(key, min, max); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); + } + + public Response> zrangeByScoreWithScores(byte[] key, byte[] min, + byte[] max, int offset, int count) { client.zrangeByScoreWithScores(key, min, max, offset, count); return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } @@ -522,6 +542,10 @@ public class BinaryTransaction extends Queable { } public Response zremrangeByScore(byte[] key, double start, double end) { + return zremrangeByScore(key, toByteArray(start), toByteArray(end)); + } + + public Response zremrangeByScore(byte[] key, byte[] start, byte[] end) { client.zremrangeByScore(key, start, end); return getResponse(BuilderFactory.LONG); } diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index dafc25f..8f7122c 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -405,12 +405,16 @@ public class Client extends BinaryClient implements Commands { } public void zcount(final String key, final double min, final double max) { - zcount(SafeEncoder.encode(key), min, max); + zcount(SafeEncoder.encode(key), toByteArray(min), toByteArray(max)); + } + + public void zcount(final String key, final String min, final String max) { + zcount(SafeEncoder.encode(key), SafeEncoder.encode(min), SafeEncoder.encode(max)); } public void zrangeByScore(final String key, final double min, final double max) { - zrangeByScore(SafeEncoder.encode(key), min, max); + zrangeByScore(SafeEncoder.encode(key), toByteArray(min), toByteArray(max)); } public void zrangeByScore(final String key, final String min, @@ -421,23 +425,39 @@ public class Client extends BinaryClient implements Commands { public void zrangeByScore(final String key, final double min, final double max, final int offset, int count) { - zrangeByScore(SafeEncoder.encode(key), min, max, offset, count); + zrangeByScore(SafeEncoder.encode(key), toByteArray(min), toByteArray(max), offset, count); } public void zrangeByScoreWithScores(final String key, final double min, final double max) { - zrangeByScoreWithScores(SafeEncoder.encode(key), min, max); + zrangeByScoreWithScores(SafeEncoder.encode(key), toByteArray(min), toByteArray(max)); } public void zrangeByScoreWithScores(final String key, final double min, final double max, final int offset, final int count) { - zrangeByScoreWithScores(SafeEncoder.encode(key), min, max, offset, + zrangeByScoreWithScores(SafeEncoder.encode(key), toByteArray(min), toByteArray(max), offset, count); } public void zrevrangeByScore(final String key, final double max, final double min) { - zrevrangeByScore(SafeEncoder.encode(key), max, min); + zrevrangeByScore(SafeEncoder.encode(key), toByteArray(max), toByteArray(min)); + } + + public void zrangeByScore(final String key, final String min, + final String max, final int offset, int count) { + zrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(min), SafeEncoder.encode(max), offset, count); + } + + public void zrangeByScoreWithScores(final String key, final String min, + final String max) { + zrangeByScoreWithScores(SafeEncoder.encode(key), SafeEncoder.encode(min), SafeEncoder.encode(max)); + } + + public void zrangeByScoreWithScores(final String key, final String min, + final String max, final int offset, final int count) { + zrangeByScoreWithScores(SafeEncoder.encode(key), SafeEncoder.encode(min), SafeEncoder.encode(max), offset, + count); } public void zrevrangeByScore(final String key, final String max, @@ -448,19 +468,35 @@ public class Client extends BinaryClient implements Commands { public void zrevrangeByScore(final String key, final double max, final double min, final int offset, int count) { - zrevrangeByScore(SafeEncoder.encode(key), max, min, offset, count); + zrevrangeByScore(SafeEncoder.encode(key), toByteArray(max), toByteArray(min), offset, count); + } + + public void zrevrangeByScore(final String key, final String max, + final String min, final int offset, int count) { + zrevrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(max), SafeEncoder.encode(min), offset, count); } public void zrevrangeByScoreWithScores(final String key, final double max, final double min) { - zrevrangeByScoreWithScores(SafeEncoder.encode(key), max, min); + zrevrangeByScoreWithScores(SafeEncoder.encode(key), toByteArray(max), toByteArray(min)); } + + public void zrevrangeByScoreWithScores(final String key, final String max, + final String min) { + zrevrangeByScoreWithScores(SafeEncoder.encode(key), SafeEncoder.encode(max), SafeEncoder.encode(min)); + } public void zrevrangeByScoreWithScores(final String key, final double max, final double min, final int offset, final int count) { - zrevrangeByScoreWithScores(SafeEncoder.encode(key), max, min, offset, + zrevrangeByScoreWithScores(SafeEncoder.encode(key), toByteArray(max), toByteArray(min), offset, count); } + + public void zrevrangeByScoreWithScores(final String key, final String max, + final String min, final int offset, final int count) { + zrevrangeByScoreWithScores(SafeEncoder.encode(key), SafeEncoder.encode(max), SafeEncoder.encode(min), offset, + count); + } public void zremrangeByRank(final String key, final int start, final int end) { zremrangeByRank(SafeEncoder.encode(key), start, end); @@ -468,8 +504,13 @@ public class Client extends BinaryClient implements Commands { public void zremrangeByScore(final String key, final double start, final double end) { - zremrangeByScore(SafeEncoder.encode(key), start, end); + zremrangeByScore(SafeEncoder.encode(key), toByteArray(start), toByteArray(end)); } + + public void zremrangeByScore(final String key, final String start, + final String end) { + zremrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(start), SafeEncoder.encode(end)); + } public void zunionstore(final String dstkey, final String... sets) { final byte[][] bsets = new byte[sets.length][]; diff --git a/src/main/java/redis/clients/jedis/Commands.java b/src/main/java/redis/clients/jedis/Commands.java index 3768157..c7d20d7 100644 --- a/src/main/java/redis/clients/jedis/Commands.java +++ b/src/main/java/redis/clients/jedis/Commands.java @@ -183,6 +183,8 @@ public interface Commands { final int timeout); public void zcount(final String key, final double min, final double max); + + public void zcount(final String key, final String min, final String max); public void zrangeByScore(final String key, final double min, final double max); @@ -199,7 +201,13 @@ public interface Commands { public void zrangeByScoreWithScores(final String key, final double min, final double max, final int offset, final int count); - public void zrevrangeByScore(final String key, final double max, + public void zrangeByScoreWithScores(final String key, final String min, + final String max); + + public void zrangeByScoreWithScores(final String key, final String min, + final String max, final int offset, final int count); + + public void zrevrangeByScore(final String key, final double max, final double min); public void zrevrangeByScore(final String key, final String max, @@ -213,12 +221,21 @@ public interface Commands { public void zrevrangeByScoreWithScores(final String key, final double max, final double min, final int offset, final int count); + + public void zrevrangeByScoreWithScores(final String key, final String max, + final String min); + + public void zrevrangeByScoreWithScores(final String key, final String max, + final String min, final int offset, final int count); public void zremrangeByRank(final String key, final int start, final int end); public void zremrangeByScore(final String key, final double start, final double end); + public void zremrangeByScore(final String key, final String start, + final String end); + public void zunionstore(final String dstkey, final String... sets); public void zunionstore(final String dstkey, final ZParams params, diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index c87690c..a345af7 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -1991,6 +1991,12 @@ public class Jedis extends BinaryJedis implements JedisCommands { client.zcount(key, min, max); return client.getIntegerReply(); } + + public Long zcount(final String key, final String min, final String max) { + checkIsInMulti(); + client.zcount(key, min, max); + return client.getIntegerReply(); + } /** * Return the all the elements in the sorted set at key with a score between @@ -2125,6 +2131,13 @@ public class Jedis extends BinaryJedis implements JedisCommands { client.zrangeByScore(key, min, max, offset, count); return new LinkedHashSet(client.getMultiBulkReply()); } + + public Set zrangeByScore(final String key, final String min, + final String max, final int offset, final int count) { + checkIsInMulti(); + client.zrangeByScore(key, min, max, offset, count); + return new LinkedHashSet(client.getMultiBulkReply()); + } /** * Return the all the elements in the sorted set at key with a score between @@ -2189,6 +2202,14 @@ public class Jedis extends BinaryJedis implements JedisCommands { Set set = getTupledSet(); return set; } + + public Set zrangeByScoreWithScores(final String key, + final String min, final String max) { + checkIsInMulti(); + client.zrangeByScoreWithScores(key, min, max); + Set set = getTupledSet(); + return set; + } /** * Return the all the elements in the sorted set at key with a score between @@ -2254,6 +2275,15 @@ public class Jedis extends BinaryJedis implements JedisCommands { Set set = getTupledSet(); return set; } + + public Set zrangeByScoreWithScores(final String key, + final String min, final String max, final int offset, + final int count) { + checkIsInMulti(); + client.zrangeByScoreWithScores(key, min, max, offset, count); + Set set = getTupledSet(); + return set; + } private Set getTupledSet() { checkIsInMulti(); @@ -2303,6 +2333,30 @@ public class Jedis extends BinaryJedis implements JedisCommands { Set set = getTupledSet(); return set; } + + public Set zrevrangeByScoreWithScores(final String key, + final String max, final String min, final int offset, + final int count) { + checkIsInMulti(); + client.zrevrangeByScoreWithScores(key, max, min, offset, count); + Set set = getTupledSet(); + return set; + } + + public Set zrevrangeByScore(final String key, final String max, + final String min, final int offset, final int count) { + checkIsInMulti(); + client.zrevrangeByScore(key, max, min, offset, count); + return new LinkedHashSet(client.getMultiBulkReply()); + } + + public Set zrevrangeByScoreWithScores(final String key, + final String max, final String min) { + checkIsInMulti(); + client.zrevrangeByScoreWithScores(key, max, min); + Set set = getTupledSet(); + return set; + } /** * Remove all elements in the sorted set at key with rank between start and @@ -2343,6 +2397,13 @@ public class Jedis extends BinaryJedis implements JedisCommands { client.zremrangeByScore(key, start, end); return client.getIntegerReply(); } + + public Long zremrangeByScore(final String key, final String start, + final String end) { + checkIsInMulti(); + client.zremrangeByScore(key, start, end); + return client.getIntegerReply(); + } /** * Creates a union or intersection of N sorted sets given by keys k1 through diff --git a/src/main/java/redis/clients/jedis/JedisCommands.java b/src/main/java/redis/clients/jedis/JedisCommands.java index 4e66e39..c6ddf1e 100644 --- a/src/main/java/redis/clients/jedis/JedisCommands.java +++ b/src/main/java/redis/clients/jedis/JedisCommands.java @@ -136,13 +136,22 @@ public interface JedisCommands { Long zcount(String key, double min, double max); + Long zcount(String key, String min, String max); + Set zrangeByScore(String key, double min, double max); + Set zrangeByScore(String key, String min, String max); + Set zrevrangeByScore(String key, double max, double min); Set zrangeByScore(String key, double min, double max, int offset, int count); + Set zrevrangeByScore(String key, String max, String min); + + Set zrangeByScore(String key, String min, String max, int offset, + int count); + Set zrevrangeByScore(String key, double max, double min, int offset, int count); @@ -152,13 +161,28 @@ public interface JedisCommands { Set zrangeByScoreWithScores(String key, double min, double max, int offset, int count); + + Set zrevrangeByScore(String key, String max, String min, + int offset, int count); + + Set zrangeByScoreWithScores(String key, String min, String max); + + Set zrevrangeByScoreWithScores(String key, String max, String min); + + Set zrangeByScoreWithScores(String key, String min, String max, + int offset, int count); Set zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count); + + Set zrevrangeByScoreWithScores(String key, String max, String min, + int offset, int count); Long zremrangeByRank(String key, int start, int end); Long zremrangeByScore(String key, double start, double end); + + Long zremrangeByScore(String key, String start, String end); Long linsert(String key, Client.LIST_POSITION where, String pivot, String value); diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index afb089a..f3564ca 100644 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -1,5 +1,6 @@ package redis.clients.jedis; +import static redis.clients.jedis.Protocol.toByteArray; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -842,7 +843,7 @@ public class Pipeline extends Queable { } public Response zcount(byte[] key, double min, double max) { - client.zcount(key, min, max); + client.zcount(key, toByteArray(min), toByteArray(max)); return getResponse(BuilderFactory.LONG); } @@ -896,10 +897,9 @@ public class Pipeline extends Queable { public Response> zrangeByScore(byte[] key, double min, double max) { - client.zrangeByScore(key, min, max); - return getResponse(BuilderFactory.STRING_ZSET); + return zrangeByScore(key, toByteArray(min), toByteArray(max)); } - + public Response> zrangeByScore(String key, String min, String max) { client.zrangeByScore(key, min, max); @@ -920,6 +920,11 @@ public class Pipeline extends Queable { public Response> zrangeByScore(byte[] key, double min, double max, int offset, int count) { + return zrangeByScore(key, toByteArray(min), toByteArray(max), offset, count); + } + + public Response> zrangeByScore(byte[] key, byte[] min, + byte[] max, int offset, int count) { client.zrangeByScore(key, min, max, offset, count); return getResponse(BuilderFactory.STRING_ZSET); } @@ -932,6 +937,11 @@ public class Pipeline extends Queable { public Response> zrangeByScoreWithScores(byte[] key, double min, double max) { + return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max)); + } + + public Response> zrangeByScoreWithScores(byte[] key, byte[] min, + byte[] max) { client.zrangeByScoreWithScores(key, min, max); return getResponse(BuilderFactory.TUPLE_ZSET); } @@ -944,6 +954,12 @@ public class Pipeline extends Queable { public Response> zrangeByScoreWithScores(byte[] key, double min, double max, int offset, int count) { + client.zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + + public Response> zrangeByScoreWithScores(byte[] key, byte[] min, + byte[] max, int offset, int count) { client.zrangeByScoreWithScores(key, min, max, offset, count); return getResponse(BuilderFactory.TUPLE_ZSET); } @@ -956,7 +972,7 @@ public class Pipeline extends Queable { public Response> zrevrangeByScore(byte[] key, double max, double min) { - client.zrevrangeByScore(key, max, min); + client.zrevrangeByScore(key, toByteArray(max), toByteArray(min)); return getResponse(BuilderFactory.STRING_ZSET); } @@ -980,6 +996,12 @@ public class Pipeline extends Queable { public Response> zrevrangeByScore(byte[] key, double max, double min, int offset, int count) { + client.zrevrangeByScore(key, toByteArray(max), toByteArray(min), offset, count); + return getResponse(BuilderFactory.STRING_ZSET); + } + + public Response> zrevrangeByScore(byte[] key, byte[] max, + byte[] min, int offset, int count) { client.zrevrangeByScore(key, max, min, offset, count); return getResponse(BuilderFactory.STRING_ZSET); } @@ -992,6 +1014,12 @@ public class Pipeline extends Queable { public Response> zrevrangeByScoreWithScores(byte[] key, double max, double min) { + client.zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min)); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + + public Response> zrevrangeByScoreWithScores(byte[] key, + byte[] max, byte[] min) { client.zrevrangeByScoreWithScores(key, max, min); return getResponse(BuilderFactory.TUPLE_ZSET); } @@ -1004,6 +1032,12 @@ public class Pipeline extends Queable { public Response> zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count) { + client.zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min), offset, count); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + + public Response> zrevrangeByScoreWithScores(byte[] key, + byte[] max, byte[] min, int offset, int count) { client.zrevrangeByScoreWithScores(key, max, min, offset, count); return getResponse(BuilderFactory.TUPLE_ZSET); } @@ -1054,6 +1088,11 @@ public class Pipeline extends Queable { } public Response zremrangeByScore(byte[] key, double start, double end) { + client.zremrangeByScore(key, toByteArray(start), toByteArray(end)); + return getResponse(BuilderFactory.LONG); + } + + public Response zremrangeByScore(byte[] key, byte[] start, byte[] end) { client.zremrangeByScore(key, start, end); return getResponse(BuilderFactory.LONG); } diff --git a/src/main/java/redis/clients/jedis/ShardedJedis.java b/src/main/java/redis/clients/jedis/ShardedJedis.java index d83ea45..507868c 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedis.java +++ b/src/main/java/redis/clients/jedis/ShardedJedis.java @@ -357,6 +357,11 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { Jedis j = getShard(key); return j.zcount(key, min, max); } + + public Long zcount(String key, String min, String max) { + Jedis j = getShard(key); + return j.zcount(key, min, max); + } public Set zrangeByScore(String key, double min, double max) { Jedis j = getShard(key); @@ -402,6 +407,51 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { Jedis j = getShard(key); return j.zrevrangeByScoreWithScores(key, max, min, offset, count); } + + public Set zrangeByScore(String key, String min, String max) { + Jedis j = getShard(key); + return j.zrangeByScore(key, min, max); + } + + public Set zrevrangeByScore(String key, String max, String min) { + Jedis j = getShard(key); + return j.zrevrangeByScore(key, max, min); + } + + public Set zrangeByScore(String key, String min, String max, + int offset, int count) { + Jedis j = getShard(key); + return j.zrangeByScore(key, min, max, offset, count); + } + + public Set zrevrangeByScore(String key, String max, String min, + int offset, int count) { + Jedis j = getShard(key); + return j.zrevrangeByScore(key, max, min, offset, count); + } + + public Set zrangeByScoreWithScores(String key, String min, String max) { + Jedis j = getShard(key); + return j.zrangeByScoreWithScores(key, min, max); + } + + public Set zrevrangeByScoreWithScores(String key, String max, + String min) { + Jedis j = getShard(key); + return j.zrevrangeByScoreWithScores(key, max, min); + } + + public Set zrangeByScoreWithScores(String key, String min, + String max, int offset, int count) { + Jedis j = getShard(key); + return j.zrangeByScoreWithScores(key, min, max, offset, count); + } + + public Set zrevrangeByScoreWithScores(String key, String max, + String min, int offset, int count) { + Jedis j = getShard(key); + return j.zrevrangeByScoreWithScores(key, max, min, offset, count); + } public Long zremrangeByRank(String key, int start, int end) { Jedis j = getShard(key); @@ -412,6 +462,11 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { Jedis j = getShard(key); return j.zremrangeByScore(key, start, end); } + + public Long zremrangeByScore(String key, String start, String end) { + Jedis j = getShard(key); + return j.zremrangeByScore(key, start, end); + } public Long linsert(String key, LIST_POSITION where, String pivot, String value) { diff --git a/src/test/java/redis/clients/jedis/tests/commands/SortedSetCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/SortedSetCommandsTest.java index 4135fba..65b8155 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/SortedSetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/SortedSetCommandsTest.java @@ -373,6 +373,10 @@ public class SortedSetCommandsTest extends JedisCommandTestBase { assertEquals(2, result); + result = jedis.zcount("foo", "(0.01", "+inf"); + + assertEquals(3, result); + // Binary jedis.zadd(bfoo, 1d, ba); jedis.zadd(bfoo, 10d, bb); @@ -383,6 +387,9 @@ public class SortedSetCommandsTest extends JedisCommandTestBase { assertEquals(2, bresult); + bresult = jedis.zcount(bfoo, SafeEncoder.encode("(0.01"), SafeEncoder.encode("+inf")); + + assertEquals(3, bresult); } @Test @@ -655,7 +662,7 @@ public class SortedSetCommandsTest extends JedisCommandTestBase { assertEquals(bexpected, brange); } - + @Test public void zremrangeByRank() { jedis.zadd("foo", 1d, "a"); From ea03bd46d06cc2f313c8ff5749a90e7d3784fc02 Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Thu, 10 May 2012 11:00:08 -0300 Subject: [PATCH 064/112] version bump --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ab999ec..c5290fd 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ jar redis.clients jedis - 2.0.1-SNAPSHOT + 2.1.0-SNAPSHOT Jedis Jedis is a blazingly small and sane Redis java client. http://code.google.com/p/jedis/ From ebbaa145a841dc0fc50731dfc258ba32254db052 Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Thu, 10 May 2012 11:06:41 -0300 Subject: [PATCH 065/112] Configuring POM for GitHub project --- pom.xml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index c5290fd..9931278 100644 --- a/pom.xml +++ b/pom.xml @@ -38,11 +38,11 @@ http://github.com/xetorthio/jedis/issues - - http://github.com/xetorthio/jedis - scm:git:git@github.com:xetorthio/jedis.git - scm:git:git@github.com:xetorthio/jedis.git - + + scm:git:git@github.com:xetorthio/jedis.git + scm:git:git@github.com:xetorthio/jedis.git + scm:git:git@github.com:xetorthio/jedis.git + localhost:6379,localhost:6380 @@ -102,6 +102,11 @@ true + + org.apache.maven.plugins + maven-release-plugin + 2.0-beta-9 + From f4b0c2c02cc774460d1e27e0c5861f94eef04c0e Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Thu, 10 May 2012 11:39:19 -0300 Subject: [PATCH 066/112] changes in pom --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9931278..c3fa679 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.sonatype.oss oss-parent - 5 + 4 4.0.0 From 78ad4cb51aa14263d15437aa7bd8d3b52683c1c2 Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Thu, 10 May 2012 11:59:31 -0300 Subject: [PATCH 067/112] update sonatype version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c3fa679..9387224 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.sonatype.oss oss-parent - 4 + 7 4.0.0 From 3a5f076371e698bfc0bac31175a905174797a5e2 Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Thu, 10 May 2012 12:28:03 -0300 Subject: [PATCH 068/112] [maven-release-plugin] prepare release jedis-2.1.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9387224..47a4ccf 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ jar redis.clients jedis - 2.1.0-SNAPSHOT + 2.1.0 Jedis Jedis is a blazingly small and sane Redis java client. http://code.google.com/p/jedis/ From 35a7677eb914d055d89c57b4c48cc912160f131f Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Thu, 10 May 2012 12:28:13 -0300 Subject: [PATCH 069/112] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 47a4ccf..0c75299 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ jar redis.clients jedis - 2.1.0 + 2.2.0-SNAPSHOT Jedis Jedis is a blazingly small and sane Redis java client. http://code.google.com/p/jedis/ From 8f9763a7e9f61d1cb92ffb0571c3de6fca356eff Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Wed, 1 Aug 2012 16:49:44 -0300 Subject: [PATCH 070/112] add url support --- .../java/redis/clients/jedis/BinaryJedis.java | 20 ++++- src/main/java/redis/clients/jedis/Jedis.java | 5 ++ .../java/redis/clients/jedis/JedisPool.java | 26 +++++- .../redis/clients/jedis/JedisShardInfo.java | 58 ++++++++----- src/main/java/redis/clients/util/Pool.java | 6 +- .../clients/jedis/tests/JedisPoolTest.java | 27 ++++++ .../redis/clients/jedis/tests/JedisTest.java | 84 ++++++++++++------- .../jedis/tests/ShardedJedisPoolTest.java | 58 +++++++++++++ 8 files changed, 231 insertions(+), 53 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 6cc5f43..5403e70 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -2,6 +2,7 @@ package redis.clients.jedis; import static redis.clients.jedis.Protocol.toByteArray; +import java.net.URI; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; @@ -20,7 +21,16 @@ public class BinaryJedis implements BinaryJedisCommands { protected Client client = null; public BinaryJedis(final String host) { - client = new Client(host); + URI uri = URI.create(host); + if (uri.getScheme() != null && uri.getScheme().equals("redis")) { + client = new Client(uri.getHost(), uri.getPort()); + client.auth(uri.getUserInfo().split(":", 2)[1]); + client.getStatusCodeReply(); + client.select(Integer.parseInt(uri.getPath().split("/", 2)[1])); + client.getStatusCodeReply(); + } else { + client = new Client(host); + } } public BinaryJedis(final String host, final int port) { @@ -38,6 +48,14 @@ public class BinaryJedis implements BinaryJedisCommands { client.setPassword(shardInfo.getPassword()); } + public BinaryJedis(URI uri) { + client = new Client(uri.getHost(), uri.getPort()); + client.auth(uri.getUserInfo().split(":", 2)[1]); + client.getStatusCodeReply(); + client.select(Integer.parseInt(uri.getPath().split("/", 2)[1])); + client.getStatusCodeReply(); + } + public String ping() { checkIsInMulti(); client.ping(); diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 8dff13d..f27c2bc 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -1,5 +1,6 @@ package redis.clients.jedis; +import java.net.URI; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; @@ -29,6 +30,10 @@ public class Jedis extends BinaryJedis implements JedisCommands { super(shardInfo); } + public Jedis(URI uri) { + super(uri); + } + public String ping() { checkIsInMulti(); client.ping(); diff --git a/src/main/java/redis/clients/jedis/JedisPool.java b/src/main/java/redis/clients/jedis/JedisPool.java index 9a73cc3..b996217 100644 --- a/src/main/java/redis/clients/jedis/JedisPool.java +++ b/src/main/java/redis/clients/jedis/JedisPool.java @@ -1,6 +1,9 @@ package redis.clients.jedis; +import java.net.URI; + import org.apache.commons.pool.BasePoolableObjectFactory; +import org.apache.commons.pool.impl.GenericObjectPool; import org.apache.commons.pool.impl.GenericObjectPool.Config; import redis.clients.util.Pool; @@ -16,9 +19,30 @@ public class JedisPool extends Pool { } public JedisPool(final String host) { - this(host, Protocol.DEFAULT_PORT); + URI uri = URI.create(host); + if (uri.getScheme() != null && uri.getScheme().equals("redis")) { + String h = uri.getHost(); + int port = uri.getPort(); + String password = uri.getUserInfo().split(":", 2)[1]; + int database = Integer.parseInt(uri.getPath().split("/", 2)[1]); + this.internalPool = new GenericObjectPool(new JedisFactory(h, port, + Protocol.DEFAULT_TIMEOUT, password, database), new Config()); + } else { + this.internalPool = new GenericObjectPool(new JedisFactory(host, + Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, null, + Protocol.DEFAULT_DATABASE), new Config()); + } } + public JedisPool(final URI uri) { + String h = uri.getHost(); + int port = uri.getPort(); + String password = uri.getUserInfo().split(":", 2)[1]; + int database = Integer.parseInt(uri.getPath().split("/", 2)[1]); + this.internalPool = new GenericObjectPool(new JedisFactory(h, port, + Protocol.DEFAULT_TIMEOUT, password, database), new Config()); + } + public JedisPool(final Config poolConfig, final String host, int port, int timeout, final String password) { this(poolConfig, host, port, timeout, password, Protocol.DEFAULT_DATABASE); diff --git a/src/main/java/redis/clients/jedis/JedisShardInfo.java b/src/main/java/redis/clients/jedis/JedisShardInfo.java index 75b71af..3c9f84d 100644 --- a/src/main/java/redis/clients/jedis/JedisShardInfo.java +++ b/src/main/java/redis/clients/jedis/JedisShardInfo.java @@ -1,11 +1,13 @@ package redis.clients.jedis; +import java.net.URI; + import redis.clients.util.ShardInfo; import redis.clients.util.Sharded; public class JedisShardInfo extends ShardInfo { public String toString() { - return host + ":" + port + "*" + getWeight(); + return host + ":" + port + "*" + getWeight(); } private int timeout; @@ -15,67 +17,83 @@ public class JedisShardInfo extends ShardInfo { private String name = null; public String getHost() { - return host; + return host; } public int getPort() { - return port; + return port; } public JedisShardInfo(String host) { - this(host, Protocol.DEFAULT_PORT); + super(Sharded.DEFAULT_WEIGHT); + URI uri = URI.create(host); + if (uri.getScheme() != null && uri.getScheme().equals("redis")) { + this.host = uri.getHost(); + this.port = uri.getPort(); + this.password = uri.getUserInfo().split(":", 2)[1]; + } else { + this.host = host; + this.port = Protocol.DEFAULT_PORT; + } } public JedisShardInfo(String host, String name) { - this(host, Protocol.DEFAULT_PORT, name); + this(host, Protocol.DEFAULT_PORT, name); } public JedisShardInfo(String host, int port) { - this(host, port, 2000); + this(host, port, 2000); } public JedisShardInfo(String host, int port, String name) { - this(host, port, 2000, name); + this(host, port, 2000, name); } public JedisShardInfo(String host, int port, int timeout) { - this(host, port, timeout, Sharded.DEFAULT_WEIGHT); + this(host, port, timeout, Sharded.DEFAULT_WEIGHT); } public JedisShardInfo(String host, int port, int timeout, String name) { - this(host, port, timeout, Sharded.DEFAULT_WEIGHT); - this.name = name; + this(host, port, timeout, Sharded.DEFAULT_WEIGHT); + this.name = name; } public JedisShardInfo(String host, int port, int timeout, int weight) { - super(weight); - this.host = host; - this.port = port; - this.timeout = timeout; + super(weight); + this.host = host; + this.port = port; + this.timeout = timeout; + } + + public JedisShardInfo(URI uri) { + super(Sharded.DEFAULT_WEIGHT); + this.host = uri.getHost(); + this.port = uri.getPort(); + this.password = uri.getUserInfo().split(":", 2)[1]; } public String getPassword() { - return password; + return password; } public void setPassword(String auth) { - this.password = auth; + this.password = auth; } public int getTimeout() { - return timeout; + return timeout; } public void setTimeout(int timeout) { - this.timeout = timeout; + this.timeout = timeout; } public String getName() { - return name; + return name; } @Override public Jedis createResource() { - return new Jedis(this); + return new Jedis(this); } } diff --git a/src/main/java/redis/clients/util/Pool.java b/src/main/java/redis/clients/util/Pool.java index 7f5e533..ab21d30 100644 --- a/src/main/java/redis/clients/util/Pool.java +++ b/src/main/java/redis/clients/util/Pool.java @@ -7,8 +7,12 @@ import redis.clients.jedis.exceptions.JedisConnectionException; import redis.clients.jedis.exceptions.JedisException; public abstract class Pool { - private final GenericObjectPool internalPool; + protected GenericObjectPool internalPool; + protected Pool() { + this.internalPool = null; + } + public Pool(final GenericObjectPool.Config poolConfig, PoolableObjectFactory factory) { this.internalPool = new GenericObjectPool(factory, poolConfig); diff --git a/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java b/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java index b0a489e..ba9db10 100644 --- a/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java +++ b/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java @@ -1,5 +1,8 @@ package redis.clients.jedis.tests; +import java.net.URI; +import java.net.URISyntaxException; + import org.apache.commons.pool.impl.GenericObjectPool; import org.apache.commons.pool.impl.GenericObjectPool.Config; import org.junit.Assert; @@ -123,4 +126,28 @@ public class JedisPoolTest extends Assert { pool.returnResource(jedis); pool.destroy(); } + + @Test + public void startWithUrlString() { + Jedis j = new Jedis("localhost", 6380); + j.auth("foobared"); + j.select(2); + j.set("foo", "bar"); + JedisPool pool = new JedisPool("redis://:foobared@localhost:6380/2"); + Jedis jedis = pool.getResource(); + assertEquals("PONG", jedis.ping()); + assertEquals("bar", jedis.get("foo")); + } + + @Test + public void startWithUrl() throws URISyntaxException { + Jedis j = new Jedis("localhost", 6380); + j.auth("foobared"); + j.select(2); + j.set("foo", "bar"); + JedisPool pool = new JedisPool(new URI("redis://:foobared@localhost:6380/2")); + Jedis jedis = pool.getResource(); + assertEquals("PONG", jedis.ping()); + assertEquals("bar", jedis.get("foo")); + } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/JedisTest.java b/src/test/java/redis/clients/jedis/tests/JedisTest.java index 4bd7b59..bfa71ea 100644 --- a/src/test/java/redis/clients/jedis/tests/JedisTest.java +++ b/src/test/java/redis/clients/jedis/tests/JedisTest.java @@ -1,6 +1,8 @@ package redis.clients.jedis.tests; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import java.util.HashMap; import java.util.Map; @@ -17,56 +19,78 @@ import redis.clients.util.SafeEncoder; public class JedisTest extends JedisCommandTestBase { @Test public void useWithoutConnecting() { - Jedis jedis = new Jedis("localhost"); - jedis.auth("foobared"); - jedis.dbSize(); + Jedis jedis = new Jedis("localhost"); + jedis.auth("foobared"); + jedis.dbSize(); } @Test public void checkBinaryData() { - byte[] bigdata = new byte[1777]; - for (int b = 0; b < bigdata.length; b++) { - bigdata[b] = (byte) ((byte) b % 255); - } - Map hash = new HashMap(); - hash.put("data", SafeEncoder.encode(bigdata)); + byte[] bigdata = new byte[1777]; + for (int b = 0; b < bigdata.length; b++) { + bigdata[b] = (byte) ((byte) b % 255); + } + Map hash = new HashMap(); + hash.put("data", SafeEncoder.encode(bigdata)); - String status = jedis.hmset("foo", hash); - assertEquals("OK", status); - assertEquals(hash, jedis.hgetAll("foo")); + String status = jedis.hmset("foo", hash); + assertEquals("OK", status); + assertEquals(hash, jedis.hgetAll("foo")); } @Test public void connectWithShardInfo() { - JedisShardInfo shardInfo = new JedisShardInfo("localhost", - Protocol.DEFAULT_PORT); - shardInfo.setPassword("foobared"); - Jedis jedis = new Jedis(shardInfo); - jedis.get("foo"); + JedisShardInfo shardInfo = new JedisShardInfo("localhost", + Protocol.DEFAULT_PORT); + shardInfo.setPassword("foobared"); + Jedis jedis = new Jedis(shardInfo); + jedis.get("foo"); } @Test(expected = JedisConnectionException.class) public void timeoutConnection() throws Exception { - jedis = new Jedis("localhost", 6379, 15000); - jedis.auth("foobared"); - jedis.configSet("timeout", "1"); - // we need to sleep a long time since redis check for idle connections - // every 10 seconds or so - Thread.sleep(20000); - jedis.hmget("foobar", "foo"); + jedis = new Jedis("localhost", 6379, 15000); + jedis.auth("foobared"); + jedis.configSet("timeout", "1"); + // we need to sleep a long time since redis check for idle connections + // every 10 seconds or so + Thread.sleep(20000); + jedis.hmget("foobar", "foo"); } @Test(expected = JedisDataException.class) public void failWhenSendingNullValues() { - jedis.set("foo", null); + jedis.set("foo", null); } @Test public void shouldReconnectToSameDB() throws IOException { - jedis.select(1); - jedis.set("foo", "bar"); - jedis.getClient().getSocket().shutdownInput(); - jedis.getClient().getSocket().shutdownOutput(); - assertEquals("bar", jedis.get("foo")); + jedis.select(1); + jedis.set("foo", "bar"); + jedis.getClient().getSocket().shutdownInput(); + jedis.getClient().getSocket().shutdownOutput(); + assertEquals("bar", jedis.get("foo")); + } + + @Test + public void startWithUrlString() { + Jedis j = new Jedis("localhost", 6380); + j.auth("foobared"); + j.select(2); + j.set("foo", "bar"); + Jedis jedis = new Jedis("redis://:foobared@localhost:6380/2"); + assertEquals("PONG", jedis.ping()); + assertEquals("bar", jedis.get("foo")); + } + + @Test + public void startWithUrl() throws URISyntaxException { + Jedis j = new Jedis("localhost", 6380); + j.auth("foobared"); + j.select(2); + j.set("foo", "bar"); + Jedis jedis = new Jedis(new URI("redis://:foobared@localhost:6380/2")); + assertEquals("PONG", jedis.ping()); + assertEquals("bar", jedis.get("foo")); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java b/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java index ce9b093..664e767 100644 --- a/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java +++ b/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java @@ -1,5 +1,7 @@ package redis.clients.jedis.tests; +import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; @@ -167,4 +169,60 @@ public class ShardedJedisPoolTest extends Assert { assertEquals(actual, c1); assertEquals(fails, c2); } + + @Test + public void startWithUrlString() { + Jedis j = new Jedis("localhost", 6380); + j.auth("foobared"); + j.set("foo", "bar"); + + j = new Jedis("localhost", 6379); + j.auth("foobared"); + j.set("foo", "bar"); + + List shards = new ArrayList(); + shards.add(new JedisShardInfo("redis://:foobared@localhost:6380")); + shards.add(new JedisShardInfo("redis://:foobared@localhost:6379")); + + Config redisConfig = new Config(); + ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards); + + Jedis[] jedises = pool.getResource().getAllShards().toArray(new Jedis[2]); + + Jedis jedis = jedises[0]; + assertEquals("PONG", jedis.ping()); + assertEquals("bar", jedis.get("foo")); + + jedis = jedises[1]; + assertEquals("PONG", jedis.ping()); + assertEquals("bar", jedis.get("foo")); + } + + @Test + public void startWithUrl() throws URISyntaxException { + Jedis j = new Jedis("localhost", 6380); + j.auth("foobared"); + j.set("foo", "bar"); + + j = new Jedis("localhost", 6379); + j.auth("foobared"); + j.set("foo", "bar"); + + List shards = new ArrayList(); + shards.add(new JedisShardInfo(new URI("redis://:foobared@localhost:6380"))); + shards.add(new JedisShardInfo(new URI("redis://:foobared@localhost:6379"))); + + Config redisConfig = new Config(); + ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards); + + Jedis[] jedises = pool.getResource().getAllShards().toArray(new Jedis[2]); + + Jedis jedis = jedises[0]; + assertEquals("PONG", jedis.ping()); + assertEquals("bar", jedis.get("foo")); + + jedis = jedises[1]; + assertEquals("PONG", jedis.ping()); + assertEquals("bar", jedis.get("foo")); + } } From beb999d50a0a2f6818c7d2a4e697073b979a49ad Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Thu, 2 Aug 2012 16:57:14 -0300 Subject: [PATCH 071/112] when setting timeout infinite, make sure it is connected first --- src/main/java/redis/clients/jedis/Connection.java | 3 +++ .../java/redis/clients/jedis/tests/ConnectionTest.java | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index 37e43e2..1c42b94 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -38,6 +38,9 @@ public class Connection { public void setTimeoutInfinite() { try { + if(!isConnected()) { + connect(); + } socket.setKeepAlive(true); socket.setSoTimeout(0); } catch (SocketException ex) { diff --git a/src/test/java/redis/clients/jedis/tests/ConnectionTest.java b/src/test/java/redis/clients/jedis/tests/ConnectionTest.java index 84d76b5..eee7ac9 100644 --- a/src/test/java/redis/clients/jedis/tests/ConnectionTest.java +++ b/src/test/java/redis/clients/jedis/tests/ConnectionTest.java @@ -33,4 +33,12 @@ public class ConnectionTest extends Assert { client.setPort(55665); client.connect(); } + + @Test + public void connectIfNotConnectedWhenSettingTimeoutInfinite() { + client.setHost("localhost"); + client.setPort(6379); + client.setTimeoutInfinite(); + } + } \ No newline at end of file From 63b40b71f749bcd015867e6c93fb82106a7fe956 Mon Sep 17 00:00:00 2001 From: panos Date: Mon, 13 Aug 2012 10:35:51 +0800 Subject: [PATCH 072/112] Sharded Performance improvement 'SortedMap.isEmpty()' performance is much higher than 'SortedMap.size()==0' --- src/main/java/redis/clients/util/Sharded.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/util/Sharded.java b/src/main/java/redis/clients/util/Sharded.java index f6065bc..5448fcd 100644 --- a/src/main/java/redis/clients/util/Sharded.java +++ b/src/main/java/redis/clients/util/Sharded.java @@ -77,7 +77,7 @@ public class Sharded> { public S getShardInfo(byte[] key) { SortedMap tail = nodes.tailMap(algo.hash(key)); - if (tail.size() == 0) { + if (tail.isEmpty()) { return nodes.get(nodes.firstKey()); } return tail.get(tail.firstKey()); From 4570329924d3d47626e05f8bf41337064519c668 Mon Sep 17 00:00:00 2001 From: MURAOKA Taro Date: Thu, 23 Aug 2012 10:29:36 +0900 Subject: [PATCH 073/112] implemented bitcount and bitop commands for Redis 2.6 --- .gitignore | 1 + .../redis/clients/jedis/BinaryClient.java | 37 +++++++++++ src/main/java/redis/clients/jedis/BitOP.java | 8 +++ src/main/java/redis/clients/jedis/Client.java | 12 ++++ .../java/redis/clients/jedis/Commands.java | 8 ++- src/main/java/redis/clients/jedis/Jedis.java | 16 +++++ .../redis/clients/jedis/JedisCommands.java | 7 +++ .../java/redis/clients/jedis/Protocol.java | 4 +- .../redis/clients/jedis/ShardedJedis.java | 15 +++++ .../jedis/tests/commands/BitCommandsTest.java | 63 ++++++++++++++++++- 10 files changed, 167 insertions(+), 4 deletions(-) create mode 100644 src/main/java/redis/clients/jedis/BitOP.java diff --git a/.gitignore b/.gitignore index d77754e..982e6b6 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ target/ build/ bin/ +tags diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index a5323d2..91f75b3 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -807,4 +807,41 @@ public class BinaryClient extends Connection { public void objectEncoding(byte[] key) { sendCommand(OBJECT, ENCODING.raw, key); } + + public void bitcount(byte[] key) { + sendCommand(BITCOUNT, key); + } + + public void bitcount(byte[] key, long start, long end) { + sendCommand(BITCOUNT, key, toByteArray(start), toByteArray(end)); + } + + public void bitop(BitOP op, byte[] destKey, String... srcKeys) { + Keyword kw = Keyword.AND; + int len = srcKeys.length; + switch (op) { + case AND: + kw = Keyword.AND; + break; + case OR: + kw = Keyword.OR; + break; + case XOR: + kw = Keyword.XOR; + break; + case NOT: + kw = Keyword.NOT; + len = Math.min(1, len); + break; + } + + byte[][] bargs = new byte[len + 2][]; + bargs[0] = kw.raw; + bargs[1] = destKey; + for (int i = 0; i < len; ++i) { + bargs[i + 2] = SafeEncoder.encode(srcKeys[i]); + } + + sendCommand(BITOP, bargs); + } } diff --git a/src/main/java/redis/clients/jedis/BitOP.java b/src/main/java/redis/clients/jedis/BitOP.java new file mode 100644 index 0000000..5e3ee89 --- /dev/null +++ b/src/main/java/redis/clients/jedis/BitOP.java @@ -0,0 +1,8 @@ +package redis.clients.jedis; + +public enum BitOP { + AND, + OR, + XOR, + NOT; +} diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index 39aae12..648d3ed 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -703,4 +703,16 @@ public class Client extends BinaryClient implements Commands { public void objectEncoding(String key) { objectEncoding(SafeEncoder.encode(key)); } + + public void bitcount(final String key) { + bitcount(SafeEncoder.encode(key)); + } + + public void bitcount(final String key, long start, long end) { + bitcount(SafeEncoder.encode(key), start, end); + } + + public void bitop(BitOP op, final String destKey, String... srcKeys) { + bitop(op, SafeEncoder.encode(destKey), srcKeys); + } } diff --git a/src/main/java/redis/clients/jedis/Commands.java b/src/main/java/redis/clients/jedis/Commands.java index 7881909..6227492 100644 --- a/src/main/java/redis/clients/jedis/Commands.java +++ b/src/main/java/redis/clients/jedis/Commands.java @@ -285,4 +285,10 @@ public interface Commands { public void objectIdletime(String key); public void objectEncoding(String key); -} \ No newline at end of file + + public void bitcount(final String key); + + public void bitcount(final String key, long start, long end); + + public void bitop(BitOP op, final String destKey, String... srcKeys); +} diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index f27c2bc..1f1ca8c 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -2873,4 +2873,20 @@ public class Jedis extends BinaryJedis implements JedisCommands { client.objectIdletime(string); return client.getIntegerReply(); } + + public Long bitcount(final String key) { + client.bitcount(key); + return client.getIntegerReply(); + } + + public Long bitcount(final String key, long start, long end) { + client.bitcount(key, start, end); + return client.getIntegerReply(); + } + + public Long bitop(BitOP op, final String destKey, String... srcKeys) { + client.bitop(op, destKey, srcKeys); + return client.getIntegerReply(); + } + } diff --git a/src/main/java/redis/clients/jedis/JedisCommands.java b/src/main/java/redis/clients/jedis/JedisCommands.java index d4c07f3..ee87aa2 100644 --- a/src/main/java/redis/clients/jedis/JedisCommands.java +++ b/src/main/java/redis/clients/jedis/JedisCommands.java @@ -190,4 +190,11 @@ public interface JedisCommands { Long lpushx(String key, String string); Long rpushx(String key, String string); + + Long bitcount(final String key); + + Long bitcount(final String key, long start, long end); + + Long bitop(BitOP op, final String destKey, String... srcKeys); + } diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index b1e391d..9c8f381 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -144,7 +144,7 @@ public final class Protocol { } public static enum Command { - PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT; + PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP; public final byte[] raw; @@ -154,7 +154,7 @@ public final class Protocol { } public static enum Keyword { - AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT, RESET, FLUSH, EXISTS, LOAD, KILL, LEN, REFCOUNT, ENCODING, IDLETIME; + AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT, RESET, FLUSH, EXISTS, LOAD, KILL, LEN, REFCOUNT, ENCODING, IDLETIME, AND, OR, XOR, NOT; public final byte[] raw; Keyword() { diff --git a/src/main/java/redis/clients/jedis/ShardedJedis.java b/src/main/java/redis/clients/jedis/ShardedJedis.java index ea2f11e..f4f5341 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedis.java +++ b/src/main/java/redis/clients/jedis/ShardedJedis.java @@ -483,4 +483,19 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { Jedis j = getShard(key); return j.linsert(key, where, pivot, value); } + + public Long bitcount(final String key) { + Jedis j = getShard(key); + return j.bitcount(key); + } + + public Long bitcount(final String key, long start, long end) { + Jedis j = getShard(key); + return j.bitcount(key, start, end); + } + + public Long bitop(BitOP op, final String destKey, String... srcKeys) { + Jedis j = getShard(destKey); + return j.bitop(op, destKey, srcKeys); + } } diff --git a/src/test/java/redis/clients/jedis/tests/commands/BitCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/BitCommandsTest.java index 047ca20..87b044f 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/BitCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/BitCommandsTest.java @@ -2,6 +2,8 @@ package redis.clients.jedis.tests.commands; import org.junit.Test; +import redis.clients.jedis.BitOP; + public class BitCommandsTest extends JedisCommandTestBase { @Test public void setAndgetbit() { @@ -29,4 +31,63 @@ public class BitCommandsTest extends JedisCommandTestBase { assertEquals("Hello", jedis.getrange("key1", 0, 4)); assertEquals("Jedis", jedis.getrange("key1", 6, 11)); } -} \ No newline at end of file + + @Test + public void bitCount() { + jedis.del("foo"); + + jedis.setbit("foo", 16, true); + jedis.setbit("foo", 24, true); + jedis.setbit("foo", 40, true); + jedis.setbit("foo", 56, true); + + long c4 = jedis.bitcount("foo"); + assertEquals(4, c4); + + long c3 = jedis.bitcount("foo", 2L, 5L); + assertEquals(3, c3); + + jedis.del("foo"); + } + + @Test + public void bitOp() + { + jedis.set("key1", "\u0060"); + jedis.set("key2", "\u0044"); + + jedis.bitop(BitOP.AND, "resultAnd", "key1", "key2"); + String resultAnd = jedis.get("resultAnd"); + assertEquals("\u0040", resultAnd); + + jedis.bitop(BitOP.OR, "resultOr", "key1", "key2"); + String resultOr = jedis.get("resultOr"); + assertEquals("\u0064", resultOr); + + jedis.bitop(BitOP.XOR, "resultXor", "key1", "key2"); + String resultXor = jedis.get("resultXor"); + assertEquals("\u0024", resultXor); + + jedis.del("resultAnd"); + jedis.del("resultOr"); + jedis.del("resultXor"); + jedis.del("key1"); + jedis.del("key2"); + } + + @Test + public void bitOpNot() + { + jedis.del("key"); + jedis.setbit("key", 0, true); + jedis.setbit("key", 4, true); + + jedis.bitop(BitOP.NOT, "resultNot", "key"); + + String resultNot = jedis.get("resultNot"); + assertEquals("\u0077", resultNot); + + jedis.del("key"); + jedis.del("resultNot"); + } +} From 909be715bcdbdaf846a990c0779f74e829dcf672 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Sun, 21 Oct 2012 17:17:26 +0100 Subject: [PATCH 074/112] adding del to sharded jedis pipeline --- .../java/redis/clients/jedis/ShardedJedisPipeline.java | 7 +++++++ .../clients/jedis/tests/ShardedJedisPipelineTest.java | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java index f58e5a7..af416c0 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java +++ b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java @@ -39,6 +39,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING); } + public Response del(String key) { + Client c = getClient(key); + c.del(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response exists(String key) { Client c = getClient(key); c.exists(key); diff --git a/src/test/java/redis/clients/jedis/tests/ShardedJedisPipelineTest.java b/src/test/java/redis/clients/jedis/tests/ShardedJedisPipelineTest.java index 05c5df4..7574f08 100644 --- a/src/test/java/redis/clients/jedis/tests/ShardedJedisPipelineTest.java +++ b/src/test/java/redis/clients/jedis/tests/ShardedJedisPipelineTest.java @@ -74,6 +74,8 @@ public class ShardedJedisPipelineTest { ShardedJedisPipeline p = jedis.pipelined(); Response string = p.get("string"); + Response del = p.del("string"); + Response emptyString = p.get("string"); Response list = p.lpop("list"); Response hash = p.hget("hash", "foo"); Response> zset = p.zrange("zset", 0, -1); @@ -91,6 +93,8 @@ public class ShardedJedisPipelineTest { p.sync(); assertEquals("foo", string.get()); + assertEquals(Long.valueOf(1), del.get()); + assertNull(emptyString.get()); assertEquals("foo", list.get()); assertEquals("bar", hash.get()); assertEquals("foo", zset.get().iterator().next()); From fe5e77773b00f752d253f448112ea1beea341a10 Mon Sep 17 00:00:00 2001 From: Eujern Lim Date: Fri, 26 Oct 2012 13:04:15 -0300 Subject: [PATCH 075/112] Update src/main/java/redis/clients/jedis/BinaryShardedJedis.java Added del(byte[] key) to BinaryShardedJedis. --- src/main/java/redis/clients/jedis/BinaryShardedJedis.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java index c15efb0..23fd6d6 100644 --- a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java @@ -100,6 +100,11 @@ public class BinaryShardedJedis extends Sharded return j.decr(key); } + public Long del(byte[] key) { + Jedis j = getShard(key); + return j.del(key); + } + public Long incrBy(byte[] key, long integer) { Jedis j = getShard(key); return j.incrBy(key, integer); From 69b5291f80762e737e2d30a5b3b87dbff1d81056 Mon Sep 17 00:00:00 2001 From: Maciej Lopacinski Date: Sun, 18 Nov 2012 19:58:13 +0100 Subject: [PATCH 076/112] SENTINEL commands --- .../redis/clients/jedis/BinaryClient.java | 5 + src/main/java/redis/clients/jedis/Client.java | 14 ++ src/main/java/redis/clients/jedis/Jedis.java | 139 ++++++++++++++++++ .../java/redis/clients/jedis/Protocol.java | 8 +- .../jedis/tests/JedisSentinelTest.java | 47 ++++++ 5 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 src/test/java/redis/clients/jedis/tests/JedisSentinelTest.java diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index a5323d2..8f29407 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -807,4 +807,9 @@ public class BinaryClient extends Connection { public void objectEncoding(byte[] key) { sendCommand(OBJECT, ENCODING.raw, key); } + + public void sentinel(final byte[]... args) { + sendCommand(SENTINEL, args); + } + } diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index 39aae12..bfabe2d 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -703,4 +703,18 @@ public class Client extends BinaryClient implements Commands { public void objectEncoding(String key) { objectEncoding(SafeEncoder.encode(key)); } + + + public void sentinel(final String... args) { + final byte[][] arg = new byte[args.length][]; + for (int i = 0; i < arg.length; i++) { + arg[i] = SafeEncoder.encode(args[i]); + } + sentinel(arg); + } + + public void sentinel(final String cmd, String arg1, int arg2) { + sentinel(SafeEncoder.encode(cmd), SafeEncoder.encode(arg1), toByteArray(arg2)); + } + } diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index f27c2bc..58925ea 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -2,6 +2,7 @@ package redis.clients.jedis; import java.net.URI; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; @@ -2873,4 +2874,142 @@ public class Jedis extends BinaryJedis implements JedisCommands { client.objectIdletime(string); return client.getIntegerReply(); } + + /** + *
+   * redis 127.0.0.1:26381> sentinel masters
+   * 1)  1) "name"
+   *     2) "mymaster"
+   *     3) "ip"
+   *     4) "127.0.0.1"
+   *     5) "port"
+   *     6) "6379"
+   *     7) "runid"
+   *     8) "93d4d4e6e9c06d0eea36e27f31924ac26576081d"
+   *     9) "flags"
+   *    10) "master"
+   *    11) "pending-commands"
+   *    12) "0"
+   *    13) "last-ok-ping-reply"
+   *    14) "423"
+   *    15) "last-ping-reply"
+   *    16) "423"
+   *    17) "info-refresh"
+   *    18) "6107"
+   *    19) "num-slaves"
+   *    20) "1"
+   *    21) "num-other-sentinels"
+   *    22) "2"
+   *    23) "quorum"
+   *    24) "2"
+   *
+   * 
+ * + * @return + */ + public List> sentinelMasters() { + client.sentinel(Protocol.SENTINEL_MASTERS); + final List reply = client.getObjectMultiBulkReply(); + + final List> masters = new ArrayList>(); + for (Object obj : reply) { + masters.add(BuilderFactory.STRING_MAP.build((List) obj)); + } + return masters; + } + + + /** + *
+   * redis 127.0.0.1:26381> sentinel get-master-addr-by-name mymaster
+   * 1) "127.0.0.1"
+   * 2) "6379"
+   * 
+ * + * @param masterName + * @return two elements list of strings : host and port. + */ + public List sentinelGetMasterAddrByName(String masterName) { + client.sentinel(Protocol.SENTINEL_GET_MASTER_ADDR_BY_NAME, masterName); + final List reply = client.getObjectMultiBulkReply(); + return BuilderFactory.STRING_LIST.build(reply); + } + + /** + *
+   * redis 127.0.0.1:26381> sentinel reset mymaster
+   * (integer) 1
+   * 
+ * + * @param pattern + * @return + */ + public Long sentinelReset(String pattern) { + client.sentinel(Protocol.SENTINEL_RESET, pattern); + return client.getIntegerReply(); + } + + /** + *
+   * redis 127.0.0.1:26381> sentinel slaves mymaster
+   * 1)  1) "name"
+   *     2) "127.0.0.1:6380"
+   *     3) "ip"
+   *     4) "127.0.0.1"
+   *     5) "port"
+   *     6) "6380"
+   *     7) "runid"
+   *     8) "d7f6c0ca7572df9d2f33713df0dbf8c72da7c039"
+   *     9) "flags"
+   *    10) "slave"
+   *    11) "pending-commands"
+   *    12) "0"
+   *    13) "last-ok-ping-reply"
+   *    14) "47"
+   *    15) "last-ping-reply"
+   *    16) "47"
+   *    17) "info-refresh"
+   *    18) "657"
+   *    19) "master-link-down-time"
+   *    20) "0"
+   *    21) "master-link-status"
+   *    22) "ok"
+   *    23) "master-host"
+   *    24) "localhost"
+   *    25) "master-port"
+   *    26) "6379"
+   *    27) "slave-priority"
+   *    28) "100"
+   * 
+ * + * @param masterName + * @return + */ + public List> sentinelSlaves(String masterName) { + client.sentinel(Protocol.SENTINEL_SLAVES, masterName); + final List reply = client.getObjectMultiBulkReply(); + + final List> slaves = new ArrayList>(); + for (Object obj : reply) { + slaves.add(BuilderFactory.STRING_MAP.build((List) obj)); + } + return slaves; + } + + /** + *
+   * redis 127.0.0.1:26381> SENTINEL is-master-down-by-addr 127.0.0.1 1
+   * 1) (integer) 0
+   * 2) "?"
+   * redis 127.0.0.1:26381> SENTINEL is-master-down-by-addr 127.0.0.1 6379
+   * 1) (integer) 0
+   * 2) "aaef11fbb2712346a386078c7f9834e72ed51e96"
+   * 
+ * @return Long followed by the String (runid) + */ + public List sentinelIsMasterDownByAddr(String host, int port) { + client.sentinel(Protocol.SENTINEL_IS_MASTER_DOWN_BY_ADDR, host, port); + final List reply = client.getObjectMultiBulkReply(); + return Arrays.asList(BuilderFactory.LONG.build(reply.get(0)), BuilderFactory.STRING.build(reply.get(1))); + } } diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index b1e391d..6e1d364 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -24,6 +24,12 @@ public final class Protocol { public static final byte MINUS_BYTE = '-'; public static final byte COLON_BYTE = ':'; + public static final String SENTINEL_MASTERS = "masters"; + public static final String SENTINEL_GET_MASTER_ADDR_BY_NAME = "get-master-addr-by-name"; + public static final String SENTINEL_RESET = "reset"; + public static final String SENTINEL_SLAVES = "slaves"; + public static final String SENTINEL_IS_MASTER_DOWN_BY_ADDR = "is-master-down-by-addr"; + private Protocol() { // this prevent the class from instantiation } @@ -144,7 +150,7 @@ public final class Protocol { } public static enum Command { - PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT; + PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, SENTINEL; public final byte[] raw; diff --git a/src/test/java/redis/clients/jedis/tests/JedisSentinelTest.java b/src/test/java/redis/clients/jedis/tests/JedisSentinelTest.java new file mode 100644 index 0000000..6ca62b9 --- /dev/null +++ b/src/test/java/redis/clients/jedis/tests/JedisSentinelTest.java @@ -0,0 +1,47 @@ +package redis.clients.jedis.tests; + +import static junit.framework.Assert.*; + +import java.util.List; +import java.util.Map; + +import org.junit.Test; + +import redis.clients.jedis.Jedis; + +public class JedisSentinelTest { + + private static final String MASTER_NAME = "mymaster"; + + /** + * Based on redis/master/slave/sentinel configs from + * https://github.com/noise/redis-sentinel-tests. + */ + @Test + public void sentinel() { + Jedis j = new Jedis("localhost", 26379); + List> masters = j.sentinelMasters(); + final String masterName = masters.get(0).get("name"); + + assertEquals(MASTER_NAME, masterName); + + List masterHostAndPort = j.sentinelGetMasterAddrByName(masterName); + assertEquals("127.0.0.1", masterHostAndPort.get(0)); + assertEquals("6379", masterHostAndPort.get(1)); + + List> slaves = j.sentinelSlaves(masterName); + assertEquals("6379", slaves.get(0).get("master-port")); + + List isMasterDownByAddr = j.sentinelIsMasterDownByAddr("127.0.0.1", 6379); + assertEquals(Long.valueOf(0), (Long) isMasterDownByAddr.get(0)); + assertFalse("?".equals(isMasterDownByAddr.get(1))); + + isMasterDownByAddr = j.sentinelIsMasterDownByAddr("127.0.0.1", 1); + assertEquals(Long.valueOf(0), (Long) isMasterDownByAddr.get(0)); + assertTrue("?".equals(isMasterDownByAddr.get(1))); + + // DO NOT RE-RUN TEST TOO FAST, RESET TAKES SOME TIME TO... RESET + assertEquals(Long.valueOf(1), j.sentinelReset(masterName)); + assertEquals(Long.valueOf(0), j.sentinelReset("woof" + masterName)); + } +} From 0340fddb3ae750c9deb119c7450618609fa0536a Mon Sep 17 00:00:00 2001 From: guycoleman Date: Mon, 3 Dec 2012 15:36:30 +0000 Subject: [PATCH 077/112] Add persist to ShardedJedis --- .../redis/clients/jedis/BinaryShardedJedis.java | 14 +++++++++----- .../java/redis/clients/jedis/ShardedJedis.java | 11 ++++++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java index 23fd6d6..a6bed45 100644 --- a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java @@ -1,5 +1,9 @@ package redis.clients.jedis; +import redis.clients.jedis.BinaryClient.LIST_POSITION; +import redis.clients.util.Hashing; +import redis.clients.util.Sharded; + import java.io.IOException; import java.util.Collection; import java.util.List; @@ -7,10 +11,6 @@ import java.util.Map; import java.util.Set; import java.util.regex.Pattern; -import redis.clients.jedis.BinaryClient.LIST_POSITION; -import redis.clients.util.Hashing; -import redis.clients.util.Sharded; - public class BinaryShardedJedis extends Sharded implements BinaryJedisCommands { public BinaryShardedJedis(List shards) { @@ -199,7 +199,11 @@ public class BinaryShardedJedis extends Sharded Jedis j = getShard(key); return j.lpushx(key, string); } - + + public Long persist(final byte[] key) { + Jedis j = getShard(key); + return j.persist(key); + } public Long rpushx(byte[] key, byte[] string) { Jedis j = getShard(key); diff --git a/src/main/java/redis/clients/jedis/ShardedJedis.java b/src/main/java/redis/clients/jedis/ShardedJedis.java index ea2f11e..dc82999 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedis.java +++ b/src/main/java/redis/clients/jedis/ShardedJedis.java @@ -1,13 +1,13 @@ package redis.clients.jedis; +import redis.clients.jedis.BinaryClient.LIST_POSITION; +import redis.clients.util.Hashing; + import java.util.List; import java.util.Map; import java.util.Set; import java.util.regex.Pattern; -import redis.clients.jedis.BinaryClient.LIST_POSITION; -import redis.clients.util.Hashing; - public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { public ShardedJedis(List shards) { super(shards); @@ -218,6 +218,11 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { return j.rpushx(key, string); } + public Long persist(final String key) { + Jedis j = getShard(key); + return j.persist(key); + } + public Long llen(String key) { Jedis j = getShard(key); return j.llen(key); From 6bede66493b49f27d21284f9f823b086e3683f10 Mon Sep 17 00:00:00 2001 From: guycoleman Date: Mon, 3 Dec 2012 15:42:15 +0000 Subject: [PATCH 078/112] Add strlen to ShardedJedis --- src/main/java/redis/clients/jedis/BinaryShardedJedis.java | 5 +++++ src/main/java/redis/clients/jedis/ShardedJedis.java | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java index a6bed45..54b0103 100644 --- a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java @@ -195,6 +195,11 @@ public class BinaryShardedJedis extends Sharded return j.lpush(key, strings); } + public Long strlen(final byte[] key) { + Jedis j = getShard(key); + return j.strlen(key); + } + public Long lpushx(byte[] key, byte[] string) { Jedis j = getShard(key); return j.lpushx(key, string); diff --git a/src/main/java/redis/clients/jedis/ShardedJedis.java b/src/main/java/redis/clients/jedis/ShardedJedis.java index dc82999..b14adac 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedis.java +++ b/src/main/java/redis/clients/jedis/ShardedJedis.java @@ -213,6 +213,11 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { return j.lpushx(key, string); } + public Long strlen(final String key) { + Jedis j = getShard(key); + return j.strlen(key); + } + public Long rpushx(String key, String string) { Jedis j = getShard(key); return j.rpushx(key, string); From 7e95b1500f3b6d1a9e6ba45a5bf037bdd1f2704a Mon Sep 17 00:00:00 2001 From: guycoleman Date: Mon, 3 Dec 2012 15:47:25 +0000 Subject: [PATCH 079/112] Add getbit,setbit, getrange, setrange to BinaryShardedJedis --- .../clients/jedis/BinaryShardedJedis.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java index 54b0103..68adb8d 100644 --- a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java @@ -498,4 +498,24 @@ public class BinaryShardedJedis extends Sharded Jedis j = getShard(key); return j.objectIdletime(key); } + + public Boolean setbit(byte[] key, long offset, byte[] value) { + Jedis j = getShard(key); + return j.setbit(key, offset, value); + } + + public Boolean getbit(byte[] key, long offset) { + Jedis j = getShard(key); + return j.getbit(key, offset); + } + + public Long setrange(byte[] key, long offset, byte[] value) { + Jedis j = getShard(key); + return j.setrange(key, offset, value); + } + + public String getrange(byte[] key, long startOffset, long endOffset) { + Jedis j = getShard(key); + return j.getrange(key, startOffset, endOffset); + } } \ No newline at end of file From bf9bba6ef221d5e9cb73232ac75576e18710becd Mon Sep 17 00:00:00 2001 From: guycoleman Date: Tue, 4 Dec 2012 17:21:43 +0000 Subject: [PATCH 080/112] Extract string and binary common interfaces for Pipline and ShardedJedisPipeline. While I'm here add missing binary methods for some bit operations and fix return types for some sharded operations (e.g. getType) --- .../clients/jedis/BinaryRedisPipeline.java | 205 +++++ .../java/redis/clients/jedis/Pipeline.java | 92 ++- .../redis/clients/jedis/RedisPipeline.java | 184 +++++ .../clients/jedis/ShardedJedisPipeline.java | 725 +++++++++++++++++- 4 files changed, 1153 insertions(+), 53 deletions(-) create mode 100644 src/main/java/redis/clients/jedis/BinaryRedisPipeline.java create mode 100644 src/main/java/redis/clients/jedis/RedisPipeline.java diff --git a/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java b/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java new file mode 100644 index 0000000..24b6089 --- /dev/null +++ b/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java @@ -0,0 +1,205 @@ +package redis.clients.jedis; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author guy + */ +public interface BinaryRedisPipeline { + Response append(byte[] key, byte[] value); + + Response decr(byte[] key); + + Response decrBy(byte[] key, long integer); + + Response exists(byte[] key); + + Response expire(byte[] key, int seconds); + + Response expireAt(byte[] key, long unixTime); + + Response get(byte[] key); + + Response getbit(byte[] key, long offset); + + Response getSet(byte[] key, byte[] value); + + Response getrange(byte[] key, long startOffset, long endOffset); + + Response hdel(byte[] key, byte[] field); + + Response hexists(byte[] key, byte[] field); + + Response hget(byte[] key, byte[] field); + + Response> hgetAll(byte[] key); + + Response hincrBy(byte[] key, byte[] field, long value); + + Response> hkeys(byte[] key); + + Response hlen(byte[] key); + + Response> hmget(byte[] key, byte[]... fields); + + Response hmset(byte[] key, Map hash); + + Response hset(byte[] key, byte[] field, byte[] value); + + Response hsetnx(byte[] key, byte[] field, byte[] value); + + Response> hvals(byte[] key); + + Response incr(byte[] key); + + Response incrBy(byte[] key, long integer); + + Response lindex(byte[] key, int index); + + Response linsert(byte[] key, BinaryClient.LIST_POSITION where, + byte[] pivot, byte[] value); + + Response llen(byte[] key); + + Response lpop(byte[] key); + + Response lpush(byte[] key, byte[] string); + + Response lpushx(byte[] key, byte[] bytes); + + Response> lrange(byte[] key, long start, long end); + + Response lrem(byte[] key, long count, byte[] value); + + Response lset(byte[] key, long index, byte[] value); + + Response ltrim(byte[] key, long start, long end); + + Response persist(byte[] key); + + Response rpop(byte[] key); + + Response rpush(byte[] key, byte[] string); + + Response rpushx(byte[] key, byte[] string); + + Response sadd(byte[] key, byte[] member); + + Response scard(byte[] key); + + Response set(byte[] key, byte[] value); + + Response setbit(byte[] key, long offset, byte[] value); + + Response setrange(byte[] key, long offset, byte[] value); + + Response setex(byte[] key, int seconds, byte[] value); + + Response setnx(byte[] key, byte[] value); + + Response setrange(String key, long offset, String value); + + Response> smembers(byte[] key); + + Response sismember(byte[] key, byte[] member); + + Response sort(byte[] key); + + Response> sort(byte[] key, + SortingParams sortingParameters); + + Response spop(byte[] key); + + Response srandmember(byte[] key); + + Response srem(byte[] key, byte[] member); + + Response strlen(byte[] key); + + Response substr(byte[] key, int start, int end); + + Response ttl(byte[] key); + + Response type(byte[] key); + + Response zadd(byte[] key, double score, byte[] member); + + Response zcard(byte[] key); + + Response zcount(byte[] key, double min, double max); + + Response zincrby(byte[] key, double score, byte[] member); + + Response> zrange(byte[] key, int start, int end); + + Response> zrangeByScore(byte[] key, double min, + double max); + + Response> zrangeByScore(byte[] key, byte[] min, + byte[] max); + + Response> zrangeByScore(byte[] key, double min, + double max, int offset, int count); + + Response> zrangeByScore(byte[] key, byte[] min, + byte[] max, int offset, int count); + + Response> zrangeByScoreWithScores(byte[] key, double min, + double max); + + Response> zrangeByScoreWithScores(byte[] key, byte[] min, + byte[] max); + + Response> zrangeByScoreWithScores(byte[] key, double min, + double max, int offset, int count); + + Response> zrangeByScoreWithScores(byte[] key, byte[] min, + byte[] max, int offset, int count); + + Response> zrevrangeByScore(byte[] key, double max, + double min); + + Response> zrevrangeByScore(byte[] key, byte[] max, + byte[] min); + + Response> zrevrangeByScore(byte[] key, double max, + double min, int offset, int count); + + Response> zrevrangeByScore(byte[] key, byte[] max, + byte[] min, int offset, int count); + + Response> zrevrangeByScoreWithScores(byte[] key, + double max, double min); + + Response> zrevrangeByScoreWithScores(byte[] key, + byte[] max, byte[] min); + + Response> zrevrangeByScoreWithScores(byte[] key, + double max, double min, int offset, int count); + + Response> zrevrangeByScoreWithScores(byte[] key, + byte[] max, byte[] min, int offset, int count); + + Response> zrangeWithScores(byte[] key, int start, int end); + + Response zrank(byte[] key, byte[] member); + + Response zrem(byte[] key, byte[] member); + + Response zremrangeByRank(byte[] key, int start, int end); + + Response zremrangeByScore(byte[] key, double start, double end); + + Response zremrangeByScore(byte[] key, byte[] start, byte[] end); + + Response> zrevrange(byte[] key, int start, int end); + + Response> zrevrangeWithScores(byte[] key, int start, + int end); + + Response zrevrank(byte[] key, byte[] member); + + Response zscore(byte[] key, byte[] member); +} diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index d89efea..a85fceb 100644 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -9,7 +9,7 @@ import java.util.Set; import redis.clients.jedis.BinaryClient.LIST_POSITION; import redis.clients.jedis.exceptions.JedisDataException; -public class Pipeline extends Queable { +public class Pipeline extends Queable implements BinaryRedisPipeline, RedisPipeline { private MultiResponseBuilder currentMulti; @@ -209,8 +209,13 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.BOOLEAN); } + public Response getbit(byte[] key, long offset) { + client.getbit(key, offset); + return getResponse(BuilderFactory.BOOLEAN); + } + public Response getrange(String key, long startOffset, - long endOffset) { + long endOffset) { client.getrange(key, startOffset, endOffset); return getResponse(BuilderFactory.STRING); } @@ -225,6 +230,11 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.BYTE_ARRAY); } + public Response getrange(byte[] key, long startOffset, long endOffset) { + client.getrange(key, startOffset, endOffset); + return getResponse(BuilderFactory.LONG); + } + public Response hdel(String key, String field) { client.hdel(key, field); return getResponse(BuilderFactory.LONG); @@ -386,13 +396,13 @@ public class Pipeline extends Queable { } public Response linsert(String key, LIST_POSITION where, - String pivot, String value) { + String pivot, String value) { client.linsert(key, where, pivot, value); return getResponse(BuilderFactory.LONG); } public Response linsert(byte[] key, LIST_POSITION where, - byte[] pivot, byte[] value) { + byte[] pivot, byte[] value) { client.linsert(key, where, pivot, value); return getResponse(BuilderFactory.LONG); } @@ -642,6 +652,11 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.BOOLEAN); } + public Response setbit(byte[] key, long offset, byte[] value) { + client.setbit(key, offset, value); + return getResponse(BuilderFactory.BOOLEAN); + } + public Response setex(String key, int seconds, String value) { client.setex(key, seconds, value); return getResponse(BuilderFactory.STRING); @@ -667,6 +682,11 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response setrange(byte[] key, long offset, byte[] value) { + client.setrange(key, offset, value); + return getResponse(BuilderFactory.LONG); + } + public Response> sinter(String... keys) { client.sinter(keys); return getResponse(BuilderFactory.STRING_SET); @@ -728,25 +748,25 @@ public class Pipeline extends Queable { } public Response> sort(String key, - SortingParams sortingParameters) { + SortingParams sortingParameters) { client.sort(key, sortingParameters); return getResponse(BuilderFactory.STRING_LIST); } public Response> sort(byte[] key, - SortingParams sortingParameters) { + SortingParams sortingParameters) { client.sort(key, sortingParameters); return getResponse(BuilderFactory.STRING_LIST); } public Response> sort(String key, - SortingParams sortingParameters, String dstkey) { + SortingParams sortingParameters, String dstkey) { client.sort(key, sortingParameters, dstkey); return getResponse(BuilderFactory.STRING_LIST); } public Response> sort(byte[] key, - SortingParams sortingParameters, byte[] dstkey) { + SortingParams sortingParameters, byte[] dstkey) { client.sort(key, sortingParameters, dstkey); return getResponse(BuilderFactory.STRING_LIST); } @@ -934,154 +954,154 @@ public class Pipeline extends Queable { } public Response> zrangeByScore(String key, double min, - double max) { + double max) { client.zrangeByScore(key, min, max); return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrangeByScore(byte[] key, double min, - double max) { + double max) { return zrangeByScore(key, toByteArray(min), toByteArray(max)); } public Response> zrangeByScore(String key, String min, - String max) { + String max) { client.zrangeByScore(key, min, max); return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrangeByScore(byte[] key, byte[] min, - byte[] max) { + byte[] max) { client.zrangeByScore(key, min, max); return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrangeByScore(String key, double min, - double max, int offset, int count) { + double max, int offset, int count) { client.zrangeByScore(key, min, max, offset, count); return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrangeByScore(byte[] key, double min, - double max, int offset, int count) { + double max, int offset, int count) { return zrangeByScore(key, toByteArray(min), toByteArray(max), offset, count); } public Response> zrangeByScore(byte[] key, byte[] min, - byte[] max, int offset, int count) { + byte[] max, int offset, int count) { client.zrangeByScore(key, min, max, offset, count); return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrangeByScoreWithScores(String key, double min, - double max) { + double max) { client.zrangeByScoreWithScores(key, min, max); return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrangeByScoreWithScores(byte[] key, double min, - double max) { + double max) { return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max)); } public Response> zrangeByScoreWithScores(byte[] key, byte[] min, - byte[] max) { + byte[] max) { client.zrangeByScoreWithScores(key, min, max); return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrangeByScoreWithScores(String key, double min, - double max, int offset, int count) { + double max, int offset, int count) { client.zrangeByScoreWithScores(key, min, max, offset, count); return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrangeByScoreWithScores(byte[] key, double min, - double max, int offset, int count) { + double max, int offset, int count) { client.zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count); return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrangeByScoreWithScores(byte[] key, byte[] min, - byte[] max, int offset, int count) { + byte[] max, int offset, int count) { client.zrangeByScoreWithScores(key, min, max, offset, count); return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrevrangeByScore(String key, double max, - double min) { + double min) { client.zrevrangeByScore(key, max, min); return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrevrangeByScore(byte[] key, double max, - double min) { + double min) { client.zrevrangeByScore(key, toByteArray(max), toByteArray(min)); return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrevrangeByScore(String key, String max, - String min) { + String min) { client.zrevrangeByScore(key, max, min); return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrevrangeByScore(byte[] key, byte[] max, - byte[] min) { + byte[] min) { client.zrevrangeByScore(key, max, min); return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrevrangeByScore(String key, double max, - double min, int offset, int count) { + double min, int offset, int count) { client.zrevrangeByScore(key, max, min, offset, count); return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrevrangeByScore(byte[] key, double max, - double min, int offset, int count) { + double min, int offset, int count) { client.zrevrangeByScore(key, toByteArray(max), toByteArray(min), offset, count); return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrevrangeByScore(byte[] key, byte[] max, - byte[] min, int offset, int count) { + byte[] min, int offset, int count) { client.zrevrangeByScore(key, max, min, offset, count); return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrevrangeByScoreWithScores(String key, - double max, double min) { + double max, double min) { client.zrevrangeByScoreWithScores(key, max, min); return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrevrangeByScoreWithScores(byte[] key, - double max, double min) { + double max, double min) { client.zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min)); return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrevrangeByScoreWithScores(byte[] key, - byte[] max, byte[] min) { + byte[] max, byte[] min) { client.zrevrangeByScoreWithScores(key, max, min); return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrevrangeByScoreWithScores(String key, - double max, double min, int offset, int count) { + double max, double min, int offset, int count) { client.zrevrangeByScoreWithScores(key, max, min, offset, count); return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrevrangeByScoreWithScores(byte[] key, - double max, double min, int offset, int count) { + double max, double min, int offset, int count) { client.zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min), offset, count); return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrevrangeByScoreWithScores(byte[] key, - byte[] max, byte[] min, int offset, int count) { + byte[] max, byte[] min, int offset, int count) { client.zrevrangeByScoreWithScores(key, max, min, offset, count); return getResponse(BuilderFactory.TUPLE_ZSET); } @@ -1152,13 +1172,13 @@ public class Pipeline extends Queable { } public Response> zrevrangeWithScores(String key, int start, - int end) { + int end) { client.zrevrangeWithScores(key, start, end); return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrevrangeWithScores(byte[] key, int start, - int end) { + int end) { client.zrevrangeWithScores(key, start, end); return getResponse(BuilderFactory.TUPLE_ZSET); } diff --git a/src/main/java/redis/clients/jedis/RedisPipeline.java b/src/main/java/redis/clients/jedis/RedisPipeline.java new file mode 100644 index 0000000..ca3370e --- /dev/null +++ b/src/main/java/redis/clients/jedis/RedisPipeline.java @@ -0,0 +1,184 @@ +package redis.clients.jedis; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author guy + */ +public interface RedisPipeline { + Response append(String key, String value); + + Response decr(String key); + + Response decrBy(String key, long integer); + + Response exists(String key); + + Response expire(String key, int seconds); + + Response expireAt(String key, long unixTime); + + Response get(String key); + + Response getbit(String key, long offset); + + + + Response getrange(String key, long startOffset, + long endOffset); + + Response getSet(String key, String value); + + Response hdel(String key, String field); + + Response hexists(String key, String field); + + Response hget(String key, String field); + + Response> hgetAll(String key); + + Response hincrBy(String key, String field, long value); + + Response> hkeys(String key); + + Response hlen(String key); + + Response> hmget(String key, String... fields); + + Response hmset(String key, Map hash); + + Response hset(String key, String field, String value); + + Response hsetnx(String key, String field, String value); + + Response> hvals(String key); + + Response incr(String key); + + Response incrBy(String key, long integer); + + Response lindex(String key, int index); + + Response linsert(String key, BinaryClient.LIST_POSITION where, + String pivot, String value); + + Response llen(String key); + + Response lpop(String key); + + Response lpush(String key, String string); + + Response lpushx(String key, String string); + + Response> lrange(String key, long start, long end); + + Response lrem(String key, long count, String value); + + Response lset(String key, long index, String value); + + Response ltrim(String key, long start, long end); + + Response persist(String key); + + Response rpop(String key); + + Response rpush(String key, String string); + + Response rpushx(String key, String string); + + Response sadd(String key, String member); + + Response scard(String key); + + Response sismember(String key, String member); + + Response set(String key, String value); + + Response setbit(String key, long offset, boolean value); + + Response setex(String key, int seconds, String value); + + Response setnx(String key, String value); + + Response> smembers(String key); + + Response sort(String key); + + Response> sort(String key, + SortingParams sortingParameters); + + Response spop(String key); + + Response srandmember(String key); + + Response srem(String key, String member); + + Response strlen(String key); + + Response substr(String key, int start, int end); + + Response ttl(String key); + + Response type(String key); + + Response zadd(String key, double score, String member); + + Response zcard(String key); + + Response zcount(String key, double min, double max); + + Response zincrby(String key, double score, String member); + + Response> zrange(String key, int start, int end); + + Response> zrangeByScore(String key, double min, + double max); + + Response> zrangeByScore(String key, String min, + String max); + + Response> zrangeByScore(String key, double min, + double max, int offset, int count); + + Response> zrangeByScoreWithScores(String key, double min, + double max); + + Response> zrangeByScoreWithScores(String key, double min, + double max, int offset, int count); + + Response> zrevrangeByScore(String key, double max, + double min); + + Response> zrevrangeByScore(String key, String max, + String min); + + Response> zrevrangeByScore(String key, double max, + double min, int offset, int count); + + Response> zrevrangeByScoreWithScores(String key, + double max, double min); + + Response> zrevrangeByScoreWithScores(String key, + double max, double min, int offset, int count); + + Response> zrangeWithScores(String key, int start, int end); + + Response zrank(String key, String member); + + Response zrem(String key, String member); + + Response zremrangeByRank(String key, int start, int end); + + Response zremrangeByScore(String key, double start, double end); + + Response> zrevrange(String key, int start, int end); + + Response> zrevrangeWithScores(String key, int start, + int end); + + Response zrevrank(String key, String member); + + Response zscore(String key, String member); +} diff --git a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java index af416c0..48371ac 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java +++ b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java @@ -4,7 +4,9 @@ import redis.clients.jedis.BinaryClient.LIST_POSITION; import java.util.*; -public class ShardedJedisPipeline extends Queable { +import static redis.clients.jedis.Protocol.toByteArray; + +public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline, RedisPipeline { private BinaryShardedJedis jedis; private List results = new ArrayList(); private Queue clients = new LinkedList(); @@ -32,6 +34,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING); } + public Response set(byte[] key, byte[] value) { + Client c = getClient(key); + c.set(key, value); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); + } + public Response get(String key) { Client c = getClient(key); c.get(key); @@ -39,6 +48,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING); } + public Response get(byte[] key) { + Client c = getClient(key); + c.get(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + public Response del(String key) { Client c = getClient(key); c.del(key); @@ -53,13 +69,27 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.BOOLEAN); } - public Response type(String key) { + public Response exists(byte[] key) { Client c = getClient(key); - c.type(key); + c.exists(key); results.add(new FutureResult(c)); return getResponse(BuilderFactory.BOOLEAN); } + public Response type(String key) { + Client c = getClient(key); + c.type(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); + } + + public Response type(byte[] key) { + Client c = getClient(key); + c.type(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); + } + public Response expire(String key, int seconds) { Client c = getClient(key); c.expire(key, seconds); @@ -67,6 +97,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response expire(byte[] key, int seconds) { + Client c = getClient(key); + c.expire(key, seconds); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response expireAt(String key, long unixTime) { Client c = getClient(key); c.expireAt(key, unixTime); @@ -74,6 +111,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response expireAt(byte[] key, long unixTime) { + Client c = getClient(key); + c.expireAt(key, unixTime); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response ttl(String key) { Client c = getClient(key); c.ttl(key); @@ -81,6 +125,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response ttl(byte[] key) { + Client c = getClient(key); + c.ttl(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response getSet(String key, String value) { Client c = getClient(key); c.getSet(key, value); @@ -88,6 +139,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING); } + public Response getSet(byte[] key, byte[] value) { + Client c = getClient(key); + c.getSet(key, value); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + public Response setnx(String key, String value) { Client c = getClient(key); c.setnx(key, value); @@ -95,11 +153,25 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } - public Response setex(String key, int seconds, String value) { + public Response setnx(byte[] key, byte[] value) { + Client c = getClient(key); + c.setnx(key, value); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + + public Response setex(String key, int seconds, String value) { Client c = getClient(key); c.setex(key, seconds, value); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); + return getResponse(BuilderFactory.STRING); + } + + public Response setex(byte[] key, int seconds, byte[] value) { + Client c = getClient(key); + c.setex(key, seconds, value); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); } public Response decrBy(String key, long integer) { @@ -109,6 +181,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response decrBy(byte[] key, long integer) { + Client c = getClient(key); + c.decrBy(key, integer); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response decr(String key) { Client c = getClient(key); c.decr(key); @@ -116,7 +195,21 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } - public Response incrBy(String key, int integer) { + public Response decr(byte[] key) { + Client c = getClient(key); + c.decr(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + + public Response incrBy(String key, long integer) { + Client c = getClient(key); + c.incrBy(key, integer); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + + public Response incrBy(byte[] key, long integer) { Client c = getClient(key); c.incrBy(key, integer); results.add(new FutureResult(c)); @@ -130,6 +223,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response incr(byte[] key) { + Client c = getClient(key); + c.incr(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response append(String key, String value) { Client c = getClient(key); c.append(key, value); @@ -137,6 +237,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response append(byte[] key, byte[] value) { + Client c = getClient(key); + c.append(key, value); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response substr(String key, int start, int end) { Client c = getClient(key); c.substr(key, start, end); @@ -144,6 +251,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING); } + public Response substr(byte[] key, int start, int end) { + Client c = getClient(key); + c.substr(key, start, end); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); + } + public Response hset(String key, String field, String value) { Client c = getClient(key); c.hset(key, field, value); @@ -151,6 +265,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response hset(byte[] key, byte[] field, byte[] value) { + Client c = getClient(key); + c.hset(key, field, value); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response hget(String key, String field) { Client c = getClient(key); c.hget(key, field); @@ -158,6 +279,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING); } + public Response hget(byte[] key, byte[] field) { + Client c = getClient(key); + c.hget(key, field); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); + } + public Response hsetnx(String key, String field, String value) { Client c = getClient(key); c.hsetnx(key, field, value); @@ -165,6 +293,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response hsetnx(byte[] key, byte[] field, byte[] value) { + Client c = getClient(key); + c.hsetnx(key, field, value); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response hmset(String key, Map hash) { Client c = getClient(key); c.hmset(key, hash); @@ -172,6 +307,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING); } + public Response hmset(byte[] key, Map hash) { + Client c = getClient(key); + c.hmset(key, hash); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); + } + public Response> hmget(String key, String... fields) { Client c = getClient(key); c.hmget(key, fields); @@ -179,7 +321,21 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING_LIST); } - public Response hincrBy(String key, String field, int value) { + public Response> hmget(byte[] key, byte[]... fields) { + Client c = getClient(key); + c.hmget(key, fields); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response hincrBy(String key, String field, long value) { + Client c = getClient(key); + c.hincrBy(key, field, value); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + + public Response hincrBy(byte[] key, byte[] field, long value) { Client c = getClient(key); c.hincrBy(key, field, value); results.add(new FutureResult(c)); @@ -193,6 +349,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.BOOLEAN); } + public Response hexists(byte[] key, byte[] field) { + Client c = getClient(key); + c.hexists(key, field); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.BOOLEAN); + } + public Response hdel(String key, String field) { Client c = getClient(key); c.hdel(key, field); @@ -200,6 +363,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response hdel(byte[] key, byte[] field) { + Client c = getClient(key); + c.hdel(key, field); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response hlen(String key) { Client c = getClient(key); c.hlen(key); @@ -207,6 +377,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response hlen(byte[] key) { + Client c = getClient(key); + c.hlen(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response> hkeys(String key) { Client c = getClient(key); c.hkeys(key); @@ -214,13 +391,27 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING_SET); } - public Response> hvals(String key) { + public Response> hkeys(byte[] key) { Client c = getClient(key); - c.hvals(key); + c.hkeys(key); results.add(new FutureResult(c)); return getResponse(BuilderFactory.STRING_SET); } + public Response> hvals(String key) { + Client c = getClient(key); + c.hvals(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> hvals(byte[] key) { + Client c = getClient(key); + c.hvals(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_LIST); + } + public Response> hgetAll(String key) { Client c = getClient(key); c.hgetAll(key); @@ -228,6 +419,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING_MAP); } + public Response> hgetAll(byte[] key) { + Client c = getClient(key); + c.hgetAll(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_MAP); + } + public Response rpush(String key, String string) { Client c = getClient(key); c.rpush(key, string); @@ -235,6 +433,27 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response rpush(byte[] key, byte[] string) { + Client c = getClient(key); + c.rpush(key, string); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + + public Response rpushx(String key, String string) { + Client c = getClient(key); + c.rpushx(key, string); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + + public Response rpushx(byte[] key, byte[] string) { + Client c = getClient(key); + c.rpushx(key, string); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response lpush(String key, String string) { Client c = getClient(key); c.lpush(key, string); @@ -242,6 +461,27 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response lpush(byte[] key, byte[] string) { + Client c = getClient(key); + c.lpush(key, string); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + + public Response lpushx(String key, String string) { + Client c = getClient(key); + c.lpushx(key, string); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + + public Response lpushx(byte[] key, byte[] bytes) { + Client c = getClient(key); + c.lpushx(key, bytes); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response llen(String key) { Client c = getClient(key); c.llen(key); @@ -249,20 +489,55 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } - public Response> lrange(String key, int start, int end) { + public Response llen(byte[] key) { + Client c = getClient(key); + c.llen(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + + public Response> lrange(String key, long start, long end) { Client c = getClient(key); c.lrange(key, start, end); results.add(new FutureResult(c)); return getResponse(BuilderFactory.STRING_LIST); } - public Response ltrim(String key, int start, int end) { + public Response> lrange(byte[] key, long start, long end) { + Client c = getClient(key); + c.lrange(key, start, end); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response ltrim(String key, long start, long end) { Client c = getClient(key); c.ltrim(key, start, end); results.add(new FutureResult(c)); return getResponse(BuilderFactory.STRING); } + public Response ltrim(byte[] key, long start, long end) { + Client c = getClient(key); + c.ltrim(key, start, end); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); + } + + public Response persist(String key) { + Client c = getClient(key); + c.persist(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + + public Response persist(byte[] key) { + Client c = getClient(key); + c.persist(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response lindex(String key, int index) { Client c = getClient(key); c.lindex(key, index); @@ -270,14 +545,35 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING); } - public Response lset(String key, int index, String value) { + public Response lindex(byte[] key, int index) { + Client c = getClient(key); + c.lindex(key, index); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); + } + + public Response lset(String key, long index, String value) { Client c = getClient(key); c.lset(key, index, value); results.add(new FutureResult(c)); return getResponse(BuilderFactory.STRING); } - public Response lrem(String key, int count, String value) { + public Response lset(byte[] key, long index, byte[] value) { + Client c = getClient(key); + c.lset(key, index, value); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); + } + + public Response lrem(String key, long count, String value) { + Client c = getClient(key); + c.lrem(key, count, value); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + + public Response lrem(byte[] key, long count, byte[] value) { Client c = getClient(key); c.lrem(key, count, value); results.add(new FutureResult(c)); @@ -291,6 +587,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING); } + public Response lpop(byte[] key) { + Client c = getClient(key); + c.lpop(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); + } + public Response rpop(String key) { Client c = getClient(key); c.rpop(key); @@ -298,6 +601,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING); } + public Response rpop(byte[] key) { + Client c = getClient(key); + c.rpop(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); + } + public Response sadd(String key, String member) { Client c = getClient(key); c.sadd(key, member); @@ -305,6 +615,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response sadd(byte[] key, byte[] member) { + Client c = getClient(key); + c.sadd(key, member); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response> smembers(String key) { Client c = getClient(key); c.smembers(key); @@ -312,6 +629,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING_SET); } + public Response> smembers(byte[] key) { + Client c = getClient(key); + c.smembers(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_SET); + } + public Response srem(String key, String member) { Client c = getClient(key); c.srem(key, member); @@ -319,6 +643,27 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response srem(byte[] key, byte[] member) { + Client c = getClient(key); + c.srem(key, member); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + + public Response strlen(String key) { + Client c = getClient(key); + c.strlen(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + + public Response strlen(byte[] key) { + Client c = getClient(key); + c.strlen(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response spop(String key) { Client c = getClient(key); c.spop(key); @@ -326,6 +671,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING); } + public Response spop(byte[] key) { + Client c = getClient(key); + c.spop(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); + } + public Response scard(String key) { Client c = getClient(key); c.scard(key); @@ -333,6 +685,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response scard(byte[] key) { + Client c = getClient(key); + c.scard(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response sismember(String key, String member) { Client c = getClient(key); c.sismember(key, member); @@ -340,6 +699,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.BOOLEAN); } + public Response sismember(byte[] key, byte[] member) { + Client c = getClient(key); + c.sismember(key, member); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.BOOLEAN); + } + public Response srandmember(String key) { Client c = getClient(key); c.srandmember(key); @@ -347,6 +713,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING); } + public Response srandmember(byte[] key) { + Client c = getClient(key); + c.srandmember(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); + } + public Response zadd(String key, double score, String member) { Client c = getClient(key); c.zadd(key, score, member); @@ -354,6 +727,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response zadd(byte[] key, double score, byte[] member) { + Client c = getClient(key); + c.zadd(key, score, member); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response> zrange(String key, int start, int end) { Client c = getClient(key); c.zrange(key, start, end); @@ -361,6 +741,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING_ZSET); } + public Response> zrange(byte[] key, int start, int end) { + Client c = getClient(key); + c.zrange(key, start, end); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_ZSET); + } + public Response zrem(String key, String member) { Client c = getClient(key); c.zrem(key, member); @@ -368,6 +755,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response zrem(byte[] key, byte[] member) { + Client c = getClient(key); + c.zrem(key, member); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response zincrby(String key, double score, String member) { Client c = getClient(key); c.zincrby(key, score, member); @@ -375,6 +769,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.DOUBLE); } + public Response zincrby(byte[] key, double score, byte[] member) { + Client c = getClient(key); + c.zincrby(key, score, member); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.DOUBLE); + } + public Response zrank(String key, String member) { Client c = getClient(key); c.zrank(key, member); @@ -382,6 +783,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response zrank(byte[] key, byte[] member) { + Client c = getClient(key); + c.zrank(key, member); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response zrevrank(String key, String member) { Client c = getClient(key); c.zrevrank(key, member); @@ -389,6 +797,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response zrevrank(byte[] key, byte[] member) { + Client c = getClient(key); + c.zrevrank(key, member); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response> zrevrange(String key, int start, int end) { Client c = getClient(key); c.zrevrange(key, start, end); @@ -396,6 +811,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING_ZSET); } + public Response> zrevrange(byte[] key, int start, int end) { + Client c = getClient(key); + c.zrevrange(key, start, end); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_ZSET); + } + public Response> zrangeWithScores(String key, int start, int end) { Client c = getClient(key); c.zrangeWithScores(key, start, end); @@ -403,6 +825,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.TUPLE_ZSET); } + public Response> zrangeWithScores(byte[] key, int start, int end) { + Client c = getClient(key); + c.zrangeWithScores(key, start, end); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + public Response> zrevrangeWithScores(String key, int start, int end) { Client c = getClient(key); c.zrevrangeWithScores(key, start, end); @@ -410,6 +839,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.TUPLE_ZSET); } + public Response> zrevrangeWithScores(byte[] key, int start, int end) { + Client c = getClient(key); + c.zrevrangeWithScores(key, start, end); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + public Response zcard(String key) { Client c = getClient(key); c.zcard(key); @@ -417,6 +853,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response zcard(byte[] key) { + Client c = getClient(key); + c.zcard(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response zscore(String key, String member) { Client c = getClient(key); c.zscore(key, member); @@ -424,13 +867,27 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.DOUBLE); } - public Response sort(String key) { + public Response zscore(byte[] key, byte[] member) { Client c = getClient(key); - c.sort(key); + c.zscore(key, member); results.add(new FutureResult(c)); return getResponse(BuilderFactory.DOUBLE); } + public Response sort(String key) { + Client c = getClient(key); + c.sort(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + + public Response sort(byte[] key) { + Client c = getClient(key); + c.sort(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response> sort(String key, SortingParams sortingParameters) { Client c = getClient(key); c.sort(key, sortingParameters); @@ -438,6 +895,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING_LIST); } + public Response> sort(byte[] key, SortingParams sortingParameters) { + Client c = getClient(key); + c.sort(key, sortingParameters); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_LIST); + } + public Response zcount(String key, double min, double max) { Client c = getClient(key); c.zcount(key, min, max); @@ -445,6 +909,69 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response zcount(byte[] key, double min, double max) { + Client c = getClient(key); + c.zcount(key, toByteArray(min), toByteArray(max)); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + + public Response> zrevrangeByScore(String key, String max, String min) { + Client c = getClient(key); + c.zrevrangeByScore(key, min, max); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_ZSET); + } + + public Response> zrevrangeByScore(String key, double max, double min) { + Client c = getClient(key); + c.zrevrangeByScore(key, min, max); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_ZSET); + } + + public Response> zrevrangeByScore(byte[] key, double max, double min) { + Client c = getClient(key); + c.zrevrangeByScore(key, toByteArray(min), toByteArray(max)); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_ZSET); + } + + public Response> zrevrangeByScore(byte[] key, byte[] max, byte[] min) { + Client c = getClient(key); + c.zrevrangeByScore(key, min, max); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_ZSET); + } + + public Response> zrevrangeByScore(String key, double max, double min, int offset, int count) { + Client c = getClient(key); + c.zrevrangeByScore(key, min, max, offset, count); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_ZSET); + } + + public Response> zrevrangeByScore(byte[] key, double max, double min, int offset, int count) { + Client c = getClient(key); + c.zrevrangeByScore(key, toByteArray(min), toByteArray(max), offset, count); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_ZSET); + } + + public Response> zrevrangeByScore(byte[] key, byte[] max, byte[] min, int offset, int count) { + Client c = getClient(key); + c.zrevrangeByScore(key, min, max, offset, count); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_ZSET); + } + + public Response> zrangeByScore(String key, String min, String max) { + Client c = getClient(key); + c.zrangeByScore(key, min, max); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_ZSET); + } + public Response> zrangeByScore(String key, double min, double max) { Client c = getClient(key); c.zrangeByScore(key, min, max); @@ -452,6 +979,20 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING_ZSET); } + public Response> zrangeByScore(byte[] key, double min, double max) { + Client c = getClient(key); + c.zrangeByScore(key, toByteArray(min), toByteArray(max)); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_ZSET); + } + + public Response> zrangeByScore(byte[] key, byte[] min, byte[] max) { + Client c = getClient(key); + c.zrangeByScore(key, min, max); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_ZSET); + } + public Response> zrangeByScore(String key, double min, double max, int offset, int count) { Client c = getClient(key); @@ -460,6 +1001,22 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.STRING_ZSET); } + public Response> zrangeByScore(byte[] key, double min, double max, + int offset, int count) { + Client c = getClient(key); + c.zrangeByScore(key, toByteArray(min), toByteArray(max), offset, count); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_ZSET); + } + + public Response> zrangeByScore(byte[] key, byte[] min, byte[] max, + int offset, int count) { + Client c = getClient(key); + c.zrangeByScore(key, min, max, offset, count); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_ZSET); + } + public Response> zrangeByScoreWithScores(String key, double min, double max) { Client c = getClient(key); c.zrangeByScoreWithScores(key, min, max); @@ -467,6 +1024,20 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.TUPLE_ZSET); } + public Response> zrangeByScoreWithScores(byte[] key, double min, double max) { + Client c = getClient(key); + c.zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max)); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + + public Response> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max) { + Client c = getClient(key); + c.zrangeByScoreWithScores(key, min, max); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + public Response> zrangeByScoreWithScores(String key, double min, double max, int offset, int count) { Client c = getClient(key); @@ -475,6 +1046,64 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.TUPLE_ZSET); } + public Response> zrangeByScoreWithScores(byte[] key, double min, double max, + int offset, int count) { + Client c = getClient(key); + c.zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + + public Response> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max, + int offset, int count) { + Client c = getClient(key); + c.zrangeByScoreWithScores(key, min, max, offset, count); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + + public Response> zrevrangeByScoreWithScores(String key, double max, double min) { + Client c = getClient(key); + c.zrevrangeByScoreWithScores(key, min, max); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + + public Response> zrevrangeByScoreWithScores(byte[] key, double max, double min) { + Client c = getClient(key); + c.zrevrangeByScoreWithScores(key, toByteArray(min), toByteArray(max)); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + + public Response> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min) { + Client c = getClient(key); + c.zrevrangeByScoreWithScores(key, min, max); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + + public Response> zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count) { + Client c = getClient(key); + c.zrevrangeByScoreWithScores(key, min, max, offset, count); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + + public Response> zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count) { + Client c = getClient(key); + c.zrevrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + + public Response> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min, int offset, int count) { + Client c = getClient(key); + c.zrevrangeByScoreWithScores(key, min, max, offset, count); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + public Response zremrangeByRank(String key, int start, int end) { Client c = getClient(key); c.zremrangeByRank(key, start, end); @@ -482,6 +1111,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response zremrangeByRank(byte[] key, int start, int end) { + Client c = getClient(key); + c.zremrangeByRank(key, start, end); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response zremrangeByScore(String key, double start, double end) { Client c = getClient(key); c.zremrangeByScore(key, start, end); @@ -489,6 +1125,20 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response zremrangeByScore(byte[] key, double start, double end) { + Client c = getClient(key); + c.zremrangeByScore(key, toByteArray(start), toByteArray(end)); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + + public Response zremrangeByScore(byte[] key, byte[] start, byte[] end) { + Client c = getClient(key); + c.zremrangeByScore(key, start, end); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response linsert(String key, LIST_POSITION where, String pivot, String value) { Client c = getClient(key); @@ -497,6 +1147,14 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.LONG); } + public Response linsert(byte[] key, LIST_POSITION where, byte[] pivot, + byte[] value) { + Client c = getClient(key); + c.linsert(key, where, pivot, value); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response getbit(String key, long offset) { Client c = getClient(key); c.getbit(key, offset); @@ -504,6 +1162,13 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.BOOLEAN); } + public Response getbit(byte[] key, long offset) { + Client c = getClient(key); + c.getbit(key, offset); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.BOOLEAN); + } + public Response setbit(String key, long offset, boolean value) { Client c = getClient(key); c.setbit(key, offset, value); @@ -511,15 +1176,35 @@ public class ShardedJedisPipeline extends Queable { return getResponse(BuilderFactory.BOOLEAN); } + public Response setbit(byte[] key, long offset, byte[] value) { + Client c = getClient(key); + c.setbit(key, offset, value); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.BOOLEAN); + } + public Response setrange(String key, long offset, String value) { Client c = getClient(key); c.setrange(key, offset, value); results.add(new FutureResult(c)); return getResponse(BuilderFactory.LONG); - } - public Response getrange(String key, long startOffset, long endOffset) { + public Response setrange(byte[] key, long offset, byte[] value) { + Client c = getClient(key); + c.setrange(key, offset, value); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + + public Response getrange(String key, long startOffset, long endOffset) { + Client c = getClient(key); + c.getrange(key, startOffset, endOffset); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); + } + + public Response getrange(byte[] key, long startOffset, long endOffset) { Client c = getClient(key); c.getrange(key, startOffset, endOffset); results.add(new FutureResult(c)); @@ -574,4 +1259,10 @@ public class ShardedJedisPipeline extends Queable { clients.add(client); return client; } + + private Client getClient(byte[] key) { + Client client = jedis.getShard(key).getClient(); + clients.add(client); + return client; + } } \ No newline at end of file From 45be143e23553395f7ee7f26fb86f77f39300689 Mon Sep 17 00:00:00 2001 From: shendley Date: Tue, 18 Dec 2012 10:26:56 -0500 Subject: [PATCH 081/112] Fixed binary safe pipeline commands and added tests for pipelined hash functions --- .../redis/clients/jedis/BuilderFactory.java | 25 +++++++ .../java/redis/clients/jedis/Pipeline.java | 67 +++++++++---------- .../clients/jedis/tests/PipeliningTest.java | 59 ++++++++++++++-- 3 files changed, 112 insertions(+), 39 deletions(-) mode change 100644 => 100755 src/main/java/redis/clients/jedis/BuilderFactory.java mode change 100644 => 100755 src/main/java/redis/clients/jedis/Pipeline.java mode change 100644 => 100755 src/test/java/redis/clients/jedis/tests/PipeliningTest.java diff --git a/src/main/java/redis/clients/jedis/BuilderFactory.java b/src/main/java/redis/clients/jedis/BuilderFactory.java old mode 100644 new mode 100755 index 8a2320a..bebd2d6 --- a/src/main/java/redis/clients/jedis/BuilderFactory.java +++ b/src/main/java/redis/clients/jedis/BuilderFactory.java @@ -144,6 +144,13 @@ public class BuilderFactory { } List l = (List) data; final Set result = new LinkedHashSet(l); + for (final byte[] barray : l) { + if (barray == null) { + result.add(null); + } else { + result.add(barray); + } + } return result; } @@ -151,6 +158,24 @@ public class BuilderFactory { return "ZSet"; } }; + public static final Builder> BYTE_ARRAY_MAP = new Builder>() { + @SuppressWarnings("unchecked") + public Map build(Object data) { + final List flatHash = (List) data; + final Map hash = new HashMap(); + final Iterator iterator = flatHash.iterator(); + while (iterator.hasNext()) { + hash.put(iterator.next(), iterator.next()); + } + + return hash; + } + + public String toString() { + return "Map"; + } + + }; public static final Builder> STRING_ZSET = new Builder>() { @SuppressWarnings("unchecked") diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java old mode 100644 new mode 100755 index d89efea..e032dbe --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -78,7 +78,6 @@ public class Pipeline extends Queable { * right response type (usually it is a waste of time). * * @return A list of all the responses in the order you executed them. - * @see sync */ public List syncAndReturnAll() { List unformatted = client.getAll(); @@ -109,9 +108,9 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING_LIST); } - public Response> blpop(byte[]... args) { + public Response> blpop(byte[]... args) { client.blpop(args); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response> brpop(String... args) { @@ -119,9 +118,9 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING_LIST); } - public Response> brpop(byte[]... args) { + public Response> brpop(byte[]... args) { client.brpop(args); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response decr(String key) { @@ -159,9 +158,9 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING); } - public Response echo(byte[] string) { + public Response echo(byte[] string) { client.echo(string); - return getResponse(BuilderFactory.STRING); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response exists(String key) { @@ -250,9 +249,9 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING); } - public Response hget(byte[] key, byte[] field) { + public Response hget(byte[] key, byte[] field) { client.hget(key, field); - return getResponse(BuilderFactory.STRING); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response> hgetAll(String key) { @@ -260,9 +259,9 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING_MAP); } - public Response> hgetAll(byte[] key) { + public Response> hgetAll(byte[] key) { client.hgetAll(key); - return getResponse(BuilderFactory.STRING_MAP); + return getResponse(BuilderFactory.BYTE_ARRAY_MAP); } public Response hincrBy(String key, String field, long value) { @@ -280,9 +279,9 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING_SET); } - public Response> hkeys(byte[] key) { + public Response> hkeys(byte[] key) { client.hkeys(key); - return getResponse(BuilderFactory.STRING_SET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response hlen(String key) { @@ -300,9 +299,9 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING_LIST); } - public Response> hmget(byte[] key, byte[]... fields) { + public Response> hmget(byte[] key, byte[]... fields) { client.hmget(key, fields); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response hmset(String key, Map hash) { @@ -340,9 +339,9 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING_LIST); } - public Response> hvals(byte[] key) { + public Response> hvals(byte[] key) { client.hvals(key); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response incr(String key) { @@ -370,9 +369,9 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING_SET); } - public Response> keys(byte[] pattern) { + public Response> keys(byte[] pattern) { client.keys(pattern); - return getResponse(BuilderFactory.STRING_SET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response lindex(String key, int index) { @@ -380,9 +379,9 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING); } - public Response lindex(byte[] key, int index) { + public Response lindex(byte[] key, int index) { client.lindex(key, index); - return getResponse(BuilderFactory.STRING); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response linsert(String key, LIST_POSITION where, @@ -412,9 +411,9 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING); } - public Response lpop(byte[] key) { + public Response lpop(byte[] key) { client.lpop(key); - return getResponse(BuilderFactory.STRING); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response lpush(String key, String string) { @@ -442,9 +441,9 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING_LIST); } - public Response> lrange(byte[] key, long start, long end) { + public Response> lrange(byte[] key, long start, long end) { client.lrange(key, start, end); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response lrem(String key, long count, String value) { @@ -482,9 +481,9 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING_LIST); } - public Response> mget(byte[]... keys) { + public Response> mget(byte[]... keys) { client.mget(keys); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response move(String key, int dbIndex) { @@ -552,9 +551,9 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING); } - public Response rpop(byte[] key) { + public Response rpop(byte[] key) { client.rpop(key); - return getResponse(BuilderFactory.STRING); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response rpoplpush(String srckey, String dstkey) { @@ -562,9 +561,9 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING); } - public Response rpoplpush(byte[] srckey, byte[] dstkey) { + public Response rpoplpush(byte[] srckey, byte[] dstkey) { client.rpoplpush(srckey, dstkey); - return getResponse(BuilderFactory.STRING); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response rpush(String key, String string) { @@ -612,9 +611,9 @@ public class Pipeline extends Queable { return getResponse(BuilderFactory.STRING_SET); } - public Response> sdiff(byte[]... keys) { + public Response> sdiff(byte[]... keys) { client.sdiff(keys); - return getResponse(BuilderFactory.STRING_SET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response sdiffstore(String dstkey, String... keys) { @@ -1319,4 +1318,4 @@ public class Pipeline extends Queable { client.select(index); return getResponse(BuilderFactory.STRING); } -} \ No newline at end of file +} diff --git a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java old mode 100644 new mode 100755 index 568a2cd..ffe2c9b --- a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java +++ b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java @@ -8,10 +8,7 @@ import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort; import java.io.UnsupportedEncodingException; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; +import java.util.*; public class PipeliningTest extends Assert { private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0); @@ -100,7 +97,59 @@ public class PipeliningTest extends Assert { assertNotNull(score.get()); } - + + @Test + public void pipelineBinarySafeHashCommands() { + jedis.hset("key".getBytes(), "f1".getBytes(), "v111".getBytes()); + jedis.hset("key".getBytes(), "f22".getBytes(), "v2222".getBytes()); + + Pipeline p = jedis.pipelined(); + Response> fmap = p.hgetAll("key".getBytes()); + Response> fkeys = p.hkeys("key".getBytes()); + Response> fordered = p.hmget("key".getBytes(), "f22".getBytes(), "f1".getBytes()); + Response> fvals = p.hvals("key".getBytes()); + p.sync(); + + assertNotNull(fmap.get()); + // we have to do these strange contortions because byte[] is not a very good key + // for a java Map. It only works with equality (you need the exact key object to retrieve + // the value) I recommend we switch to using ByteBuffer or something similar: + // http://stackoverflow.com/questions/1058149/using-a-byte-array-as-hashmap-key-java + Map map = fmap.get(); + Set mapKeys = map.keySet(); + Iterator iterMap = mapKeys.iterator(); + byte[] firstMapKey = iterMap.next(); + byte[] secondMapKey = iterMap.next(); + assertFalse(iterMap.hasNext()); + verifyHasBothValues(firstMapKey, secondMapKey, "f1".getBytes(), "f22".getBytes()); + byte[] firstMapValue = map.get(firstMapKey); + byte[] secondMapValue = map.get(secondMapKey); + verifyHasBothValues(firstMapValue, secondMapValue, "v111".getBytes(), "v2222".getBytes()); + + assertNotNull(fkeys.get()); + Iterator iter = fkeys.get().iterator(); + byte[] firstKey = iter.next(); + byte[] secondKey = iter.next(); + assertFalse(iter.hasNext()); + verifyHasBothValues(firstKey, secondKey, "f1".getBytes(), "f22".getBytes()); + + assertNotNull(fordered.get()); + assertArrayEquals("v2222".getBytes(), fordered.get().get(0)); + assertArrayEquals("v111".getBytes(), fordered.get().get(1)); + + assertNotNull(fvals.get()); + assertEquals(2, fvals.get().size()); + byte[] firstValue = fvals.get().get(0); + byte[] secondValue = fvals.get().get(1); + verifyHasBothValues(firstValue, secondValue, "v111".getBytes(), "v2222".getBytes()); + } + + private void verifyHasBothValues(byte[] firstKey, byte[] secondKey, byte[] value1, byte[] value2) { + assertFalse(Arrays.equals(firstKey, secondKey)); + 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(); From c0bda88e2c1637cc9d0a5ccfef8dbe7effe7f503 Mon Sep 17 00:00:00 2001 From: samhendley Date: Mon, 24 Dec 2012 10:45:19 -0500 Subject: [PATCH 082/112] Normalized Pipeline[] interfaces and extracted all of the non-shardable commands into the MultiKey* interfaces --- .../clients/jedis/BasicRedisPipeline.java | 44 +++++++++ .../clients/jedis/BinaryRedisPipeline.java | 26 ++++-- .../jedis/MultiKeyBinaryRedisPipeline.java | 63 +++++++++++++ .../jedis/MultiKeyCommandsPipeline.java | 65 +++++++++++++ .../java/redis/clients/jedis/Pipeline.java | 87 +++++++++++++---- .../redis/clients/jedis/RedisPipeline.java | 10 ++ .../clients/jedis/ShardedJedisPipeline.java | 93 +++++++++++++++---- 7 files changed, 343 insertions(+), 45 deletions(-) create mode 100644 src/main/java/redis/clients/jedis/BasicRedisPipeline.java create mode 100644 src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java create mode 100644 src/main/java/redis/clients/jedis/MultiKeyCommandsPipeline.java diff --git a/src/main/java/redis/clients/jedis/BasicRedisPipeline.java b/src/main/java/redis/clients/jedis/BasicRedisPipeline.java new file mode 100644 index 0000000..0b4ac36 --- /dev/null +++ b/src/main/java/redis/clients/jedis/BasicRedisPipeline.java @@ -0,0 +1,44 @@ +package redis.clients.jedis; + + +import java.util.List; + +/** + * Pipelined responses for all of the low level, non key related commands + */ +public interface BasicRedisPipeline { + + Response bgrewriteaof(); + + Response bgsave(); + + Response configGet(String pattern); + + Response configSet(String parameter, String value); + + Response configResetStat(); + + Response save(); + + Response lastsave(); + + Response discard(); + + Response> exec(); + + Response multi(); + + Response flushDB(); + + Response flushAll(); + + Response info(); + + Response dbSize(); + + Response shutdown(); + + Response ping(); + + Response select(int index); +} diff --git a/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java b/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java index 24b6089..959f915 100644 --- a/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java +++ b/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java @@ -10,10 +10,18 @@ import java.util.Set; public interface BinaryRedisPipeline { Response append(byte[] key, byte[] value); + Response> blpop(byte[] arg); + + Response> brpop(byte[] arg); + Response decr(byte[] key); Response decrBy(byte[] key, long integer); + Response del(byte[] keys); + + Response echo(byte[] string); + Response exists(byte[] key); Response expire(byte[] key, int seconds); @@ -32,17 +40,17 @@ public interface BinaryRedisPipeline { Response hexists(byte[] key, byte[] field); - Response hget(byte[] key, byte[] field); + Response hget(byte[] key, byte[] field); - Response> hgetAll(byte[] key); + Response> hgetAll(byte[] key); Response hincrBy(byte[] key, byte[] field, long value); - Response> hkeys(byte[] key); + Response> hkeys(byte[] key); Response hlen(byte[] key); - Response> hmget(byte[] key, byte[]... fields); + Response> hmget(byte[] key, byte[]... fields); Response hmset(byte[] key, Map hash); @@ -50,26 +58,26 @@ public interface BinaryRedisPipeline { Response hsetnx(byte[] key, byte[] field, byte[] value); - Response> hvals(byte[] key); + Response> hvals(byte[] key); Response incr(byte[] key); Response incrBy(byte[] key, long integer); - Response lindex(byte[] key, int index); + Response lindex(byte[] key, int index); Response linsert(byte[] key, BinaryClient.LIST_POSITION where, byte[] pivot, byte[] value); Response llen(byte[] key); - Response lpop(byte[] key); + Response lpop(byte[] key); Response lpush(byte[] key, byte[] string); Response lpushx(byte[] key, byte[] bytes); - Response> lrange(byte[] key, long start, long end); + Response> lrange(byte[] key, long start, long end); Response lrem(byte[] key, long count, byte[] value); @@ -79,7 +87,7 @@ public interface BinaryRedisPipeline { Response persist(byte[] key); - Response rpop(byte[] key); + Response rpop(byte[] key); Response rpush(byte[] key, byte[] string); diff --git a/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java b/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java new file mode 100644 index 0000000..12e2368 --- /dev/null +++ b/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java @@ -0,0 +1,63 @@ +package redis.clients.jedis; + + +import java.util.List; +import java.util.Set; + +/** + * Multikey related commands (these are split out because they are non-shardable) + */ +public interface MultiKeyBinaryRedisPipeline { + + Response del(byte[]... keys); + + Response> blpop(byte[]... args); + + Response> brpop(byte[]... args); + + Response> keys(byte[] pattern); + + Response> mget(byte[]... keys); + + Response mset(byte[]... keysvalues); + + Response msetnx(byte[]... keysvalues); + + Response rename(byte[] oldkey, byte[] newkey); + + Response renamenx(byte[] oldkey, byte[] newkey); + + Response rpoplpush(byte[] srckey, byte[] dstkey); + + Response> sdiff(byte[]... keys); + + Response sdiffstore(byte[] dstkey, byte[]... keys); + + Response> sinter(byte[]... keys); + + Response sinterstore(byte[] dstkey, byte[]... keys); + + Response smove(byte[] srckey, byte[] dstkey, byte[] member); + + Response> sort(byte[] key, SortingParams sortingParameters, byte[] dstkey); + + Response> sort(byte[] key, byte[] dstkey); + + Response> sunion(byte[]... keys); + + Response sunionstore(byte[] dstkey, byte[]... keys); + + Response watch(byte[]... keys); + + Response zinterstore(byte[] dstkey, byte[]... sets); + + Response zinterstore(byte[] dstkey, ZParams params, byte[]... sets); + + Response zunionstore(byte[] dstkey, byte[]... sets); + + Response zunionstore(byte[] dstkey, ZParams params, byte[]... sets); + + Response brpoplpush(byte[] source, byte[] destination, int timeout); + + Response publish(byte[] channel, byte[] message); +} diff --git a/src/main/java/redis/clients/jedis/MultiKeyCommandsPipeline.java b/src/main/java/redis/clients/jedis/MultiKeyCommandsPipeline.java new file mode 100644 index 0000000..9960537 --- /dev/null +++ b/src/main/java/redis/clients/jedis/MultiKeyCommandsPipeline.java @@ -0,0 +1,65 @@ +package redis.clients.jedis; + + +import java.util.List; +import java.util.Set; + + +/** + * Multikey related commands (these are split out because they are non-shardable) + */ +public interface MultiKeyCommandsPipeline { + Response del(String... keys); + + Response> blpop(String... args); + + Response> brpop(String... args); + + Response> keys(String pattern); + + Response> mget(String... keys); + + Response mset(String... keysvalues); + + Response msetnx(String... keysvalues); + + Response rename(String oldkey, String newkey); + + Response renamenx(String oldkey, String newkey); + + Response rpoplpush(String srckey, String dstkey); + + Response> sdiff(String... keys); + + Response sdiffstore(String dstkey, String... keys); + + Response> sinter(String... keys); + + Response sinterstore(String dstkey, String... keys); + + Response smove(String srckey, String dstkey, String member); + + Response> sort(String key, SortingParams sortingParameters, String dstkey); + + Response> sort(String key, String dstkey); + + Response> sunion(String... keys); + + Response sunionstore(String dstkey, String... keys); + + Response watch(String... keys); + + Response zinterstore(String dstkey, String... sets); + + Response zinterstore(String dstkey, ZParams params, String... sets); + + Response zunionstore(String dstkey, String... sets); + + Response zunionstore(String dstkey, ZParams params, String... sets); + + Response brpoplpush(String source, String destination, int timeout); + + Response publish(String channel, String message); + + Response randomKey(); +} diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index f93b95a..ae8518c 100755 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -9,7 +9,12 @@ import java.util.Set; import redis.clients.jedis.BinaryClient.LIST_POSITION; import redis.clients.jedis.exceptions.JedisDataException; -public class Pipeline extends Queable implements BinaryRedisPipeline, RedisPipeline { +public class Pipeline extends Queable implements + BasicRedisPipeline, + BinaryRedisPipeline, + RedisPipeline, + MultiKeyBinaryRedisPipeline, + MultiKeyCommandsPipeline { private MultiResponseBuilder currentMulti; @@ -59,6 +64,8 @@ public class Pipeline extends Queable implements BinaryRedisPipeline, RedisPipel this.client = client; } + + /** * Syncronize pipeline by reading all responses. This operation close the * pipeline. In order to get return values from pipelined commands, capture @@ -103,6 +110,34 @@ public class Pipeline extends Queable implements BinaryRedisPipeline, RedisPipel return getResponse(BuilderFactory.LONG); } + public Response> blpop(String arg) { + String[] temp = new String[1]; + temp[0] = arg; + client.blpop(temp); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> brpop(String arg) { + String[] temp = new String[1]; + temp[0] = arg; + client.brpop(temp); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> blpop(byte[] arg) { + byte[][] temp = new byte[1][]; + temp[0] = arg; + client.blpop(temp); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response> brpop(byte[] arg) { + byte[][] temp = new byte[1][]; + temp[0] = arg; + client.brpop(temp); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + public Response> blpop(String... args) { client.blpop(args); return getResponse(BuilderFactory.STRING_LIST); @@ -143,11 +178,21 @@ public class Pipeline extends Queable implements BinaryRedisPipeline, RedisPipel return getResponse(BuilderFactory.LONG); } + public Response del(String key) { + client.del(key); + return getResponse(BuilderFactory.LONG); + } + public Response del(String... keys) { client.del(keys); return getResponse(BuilderFactory.LONG); } + public Response del(byte[] key) { + client.del(key); + return getResponse(BuilderFactory.LONG); + } + public Response del(byte[]... keys) { client.del(keys); return getResponse(BuilderFactory.LONG); @@ -541,9 +586,9 @@ public class Pipeline extends Queable implements BinaryRedisPipeline, RedisPipel return getResponse(BuilderFactory.STRING); } - public Response rename(byte[] oldkey, byte[] newkey) { + public Response rename(byte[] oldkey, byte[] newkey) { client.rename(oldkey, newkey); - return getResponse(BuilderFactory.STRING); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response renamenx(String oldkey, String newkey) { @@ -691,9 +736,9 @@ public class Pipeline extends Queable implements BinaryRedisPipeline, RedisPipel return getResponse(BuilderFactory.STRING_SET); } - public Response> sinter(byte[]... keys) { + public Response> sinter(byte[]... keys) { client.sinter(keys); - return getResponse(BuilderFactory.STRING_SET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response sinterstore(String dstkey, String... keys) { @@ -764,10 +809,10 @@ public class Pipeline extends Queable implements BinaryRedisPipeline, RedisPipel return getResponse(BuilderFactory.STRING_LIST); } - public Response> sort(byte[] key, + public Response> sort(byte[] key, SortingParams sortingParameters, byte[] dstkey) { client.sort(key, sortingParameters, dstkey); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response> sort(String key, String dstkey) { @@ -775,9 +820,9 @@ public class Pipeline extends Queable implements BinaryRedisPipeline, RedisPipel return getResponse(BuilderFactory.STRING_LIST); } - public Response> sort(byte[] key, byte[] dstkey) { + public Response> sort(byte[] key, byte[] dstkey) { client.sort(key, dstkey); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response spop(String key) { @@ -1250,10 +1295,10 @@ public class Pipeline extends Queable implements BinaryRedisPipeline, RedisPipel return getResponse(BuilderFactory.STRING); } - public Response brpoplpush(byte[] source, byte[] destination, + public Response brpoplpush(byte[] source, byte[] destination, int timeout) { client.brpoplpush(source, destination, timeout); - return getResponse(BuilderFactory.STRING); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response configResetStat() { @@ -1283,10 +1328,11 @@ public class Pipeline extends Queable implements BinaryRedisPipeline, RedisPipel return response; } - public void multi() { + public Response multi() { client.multi(); - getResponse(BuilderFactory.STRING); //Expecting OK + Response response = getResponse(BuilderFactory.STRING); //Expecting OK currentMulti = new MultiResponseBuilder(); + return response; } public Response publish(String channel, String message) { @@ -1299,6 +1345,16 @@ public class Pipeline extends Queable implements BinaryRedisPipeline, RedisPipel return getResponse(BuilderFactory.LONG); } + public Response randomKey() { + client.randomKey(); + return getResponse(BuilderFactory.STRING); + } + + public Response randomKeyBinary() { + client.randomKey(); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + public Response flushDB() { client.flushDB(); return getResponse(BuilderFactory.STRING); @@ -1329,11 +1385,6 @@ public class Pipeline extends Queable implements BinaryRedisPipeline, RedisPipel return getResponse(BuilderFactory.STRING); } - public Response randomKey() { - client.randomKey(); - return getResponse(BuilderFactory.STRING); - } - public Response select(int index){ client.select(index); return getResponse(BuilderFactory.STRING); diff --git a/src/main/java/redis/clients/jedis/RedisPipeline.java b/src/main/java/redis/clients/jedis/RedisPipeline.java index ca3370e..570e620 100644 --- a/src/main/java/redis/clients/jedis/RedisPipeline.java +++ b/src/main/java/redis/clients/jedis/RedisPipeline.java @@ -10,10 +10,18 @@ import java.util.Set; public interface RedisPipeline { Response append(String key, String value); + Response> blpop(String arg); + + Response> brpop(String arg); + Response decr(String key); Response decrBy(String key, long integer); + Response del(String key); + + Response echo(String string); + Response exists(String key); Response expire(String key, int seconds); @@ -102,6 +110,8 @@ public interface RedisPipeline { Response setnx(String key, String value); + Response setrange(String key, long offset, String value); + Response> smembers(String key); Response sort(String key); diff --git a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java index 48371ac..771cdc9 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java +++ b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java @@ -55,6 +55,63 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.BYTE_ARRAY); } + public Response> blpop(byte[] arg) { + byte[][] temp = new byte[1][]; + temp[0] = arg; + Client c = getClient(arg); + c.blpop(temp); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response> brpop(byte[] arg) { + byte[][] temp = new byte[1][]; + temp[0] = arg; + Client c = getClient(arg); + c.blpop(temp); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response> blpop(String arg) { + String[] temp = new String[1]; + temp[0] = arg; + Client c = getClient(arg); + c.blpop(temp); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> brpop(String arg) { + String[] temp = new String[1]; + temp[0] = arg; + Client c = getClient(arg); + c.brpop(temp); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response echo(byte[] string) { + Client c = getClient(string); + c.echo(string); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response echo(String string) { + Client c = getClient(string); + c.echo(string); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.STRING); + } + + public Response del(byte[] key) { + Client c = getClient(key); + c.del(key); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response del(String key) { Client c = getClient(key); c.del(key); @@ -279,11 +336,11 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING); } - public Response hget(byte[] key, byte[] field) { + public Response hget(byte[] key, byte[] field) { Client c = getClient(key); c.hget(key, field); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response hsetnx(String key, String field, String value) { @@ -321,11 +378,11 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING_LIST); } - public Response> hmget(byte[] key, byte[]... fields) { + public Response> hmget(byte[] key, byte[]... fields) { Client c = getClient(key); c.hmget(key, fields); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response hincrBy(String key, String field, long value) { @@ -391,11 +448,11 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING_SET); } - public Response> hkeys(byte[] key) { + public Response> hkeys(byte[] key) { Client c = getClient(key); c.hkeys(key); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_SET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> hvals(String key) { @@ -405,11 +462,11 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING_LIST); } - public Response> hvals(byte[] key) { + public Response> hvals(byte[] key) { Client c = getClient(key); c.hvals(key); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response> hgetAll(String key) { @@ -419,11 +476,11 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING_MAP); } - public Response> hgetAll(byte[] key) { + public Response> hgetAll(byte[] key) { Client c = getClient(key); c.hgetAll(key); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_MAP); + return getResponse(BuilderFactory.BYTE_ARRAY_MAP); } public Response rpush(String key, String string) { @@ -503,11 +560,11 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING_LIST); } - public Response> lrange(byte[] key, long start, long end) { + public Response> lrange(byte[] key, long start, long end) { Client c = getClient(key); c.lrange(key, start, end); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response ltrim(String key, long start, long end) { @@ -545,11 +602,11 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING); } - public Response lindex(byte[] key, int index) { + public Response lindex(byte[] key, int index) { Client c = getClient(key); c.lindex(key, index); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response lset(String key, long index, String value) { @@ -587,11 +644,11 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING); } - public Response lpop(byte[] key) { + public Response lpop(byte[] key) { Client c = getClient(key); c.lpop(key); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response rpop(String key) { @@ -601,11 +658,11 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING); } - public Response rpop(byte[] key) { + public Response rpop(byte[] key) { Client c = getClient(key); c.rpop(key); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response sadd(String key, String member) { From 333ac221e189fa6988b9240b1b280863d1fac45c Mon Sep 17 00:00:00 2001 From: samhendley Date: Mon, 24 Dec 2012 11:41:53 -0500 Subject: [PATCH 083/112] extracted interfaces from Jedis --- src/main/java/redis/clients/jedis/Jedis.java | 43 +++++++++++- .../clients/jedis/JedisBasicCommands.java | 40 ++++++++++++ .../redis/clients/jedis/JedisCommands.java | 14 ++++ .../redis/clients/jedis/MultiKeyCommands.java | 65 +++++++++++++++++++ .../redis/clients/jedis/ShardedJedis.java | 20 ++++++ 5 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 src/main/java/redis/clients/jedis/JedisBasicCommands.java create mode 100644 src/main/java/redis/clients/jedis/MultiKeyCommands.java diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index f27c2bc..16b03f6 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -13,7 +13,7 @@ import redis.clients.jedis.BinaryClient.LIST_POSITION; import redis.clients.util.SafeEncoder; import redis.clients.util.Slowlog; -public class Jedis extends BinaryJedis implements JedisCommands { +public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommands, JedisBasicCommands { public Jedis(final String host) { super(host); } @@ -114,6 +114,11 @@ public class Jedis extends BinaryJedis implements JedisCommands { return client.getIntegerReply(); } + public Long del(String key) { + client.del(key); + return client.getIntegerReply(); + } + /** * Return the type of the value stored at key in form of a string. The type * can be one of "none", "string", "list", "set". "none" is returned if the @@ -1817,6 +1822,42 @@ public class Jedis extends BinaryJedis implements JedisCommands { return multiBulkReply; } + public List blpop(String... args) { + client.blpop(args); + client.setTimeoutInfinite(); + final List multiBulkReply = client.getMultiBulkReply(); + client.rollbackTimeout(); + return multiBulkReply; + } + + public List brpop(String... args) { + client.brpop(args); + client.setTimeoutInfinite(); + final List multiBulkReply = client.getMultiBulkReply(); + client.rollbackTimeout(); + return multiBulkReply; + } + + public List blpop(String arg) { + String[] args = new String[1]; + args[0] = arg; + client.blpop(args); + client.setTimeoutInfinite(); + final List multiBulkReply = client.getMultiBulkReply(); + client.rollbackTimeout(); + return multiBulkReply; + } + + public List brpop(String arg) { + String[] args = new String[1]; + args[0] = arg; + client.brpop(args); + client.setTimeoutInfinite(); + final List multiBulkReply = client.getMultiBulkReply(); + client.rollbackTimeout(); + return multiBulkReply; + } + /** * Sort a Set or a List accordingly to the specified parameters and store * the result at dstkey. diff --git a/src/main/java/redis/clients/jedis/JedisBasicCommands.java b/src/main/java/redis/clients/jedis/JedisBasicCommands.java new file mode 100644 index 0000000..2f89586 --- /dev/null +++ b/src/main/java/redis/clients/jedis/JedisBasicCommands.java @@ -0,0 +1,40 @@ +package redis.clients.jedis; + +import redis.clients.util.Slowlog; + +import java.util.List; + + +public interface JedisBasicCommands { + List configGet(String pattern); + + String configSet(String parameter, String value); + + Object eval(String script, int keyCount, String... params); + + Object eval(String script, List keys, List args); + + Object eval(String script); + + Object evalsha(String script); + + Object evalsha(String sha1, List keys, List args); + + Object evalsha(String sha1, int keyCount, String... params); + + Boolean scriptExists(String sha1); + + List scriptExists(String... sha1); + + String scriptLoad(String script); + + List slowlogGet(); + + List slowlogGet(long entries); + + Long objectRefcount(String string); + + String objectEncoding(String string); + + Long objectIdletime(String string); +} diff --git a/src/main/java/redis/clients/jedis/JedisCommands.java b/src/main/java/redis/clients/jedis/JedisCommands.java index d4c07f3..842e03f 100644 --- a/src/main/java/redis/clients/jedis/JedisCommands.java +++ b/src/main/java/redis/clients/jedis/JedisCommands.java @@ -14,6 +14,8 @@ public interface JedisCommands { Boolean exists(String key); + Long persist(String key); + String type(String key); Long expire(String key, int seconds); @@ -106,6 +108,8 @@ public interface JedisCommands { String srandmember(String key); + Long strlen(String key); + Long zadd(String key, double score, String member); Long zadd(String key, Map scoreMembers); @@ -190,4 +194,14 @@ public interface JedisCommands { Long lpushx(String key, String string); Long rpushx(String key, String string); + + List blpop(String arg); + + List brpop(String arg); + + Long del(String key); + + String echo(String string); + + Long move(String key, int dbIndex); } diff --git a/src/main/java/redis/clients/jedis/MultiKeyCommands.java b/src/main/java/redis/clients/jedis/MultiKeyCommands.java new file mode 100644 index 0000000..8a333a9 --- /dev/null +++ b/src/main/java/redis/clients/jedis/MultiKeyCommands.java @@ -0,0 +1,65 @@ +package redis.clients.jedis; + + +import java.util.List; +import java.util.Set; + +public interface MultiKeyCommands { + Long del(String... keys); + + List blpop(int timeout, String... keys); + + List brpop(int timeout, String... keys); + + List blpop(String... args); + + List brpop(String... args); + + Set keys(String pattern); + + List mget(String... keys); + + String mset(String... keysvalues); + + Long msetnx(String... keysvalues); + + String rename(String oldkey, String newkey); + + Long renamenx(String oldkey, String newkey); + + String rpoplpush(String srckey, String dstkey); + + Set sdiff(String... keys); + + Long sdiffstore(String dstkey, String... keys); + + Set sinter(String... keys); + + Long sinterstore(String dstkey, String... keys); + + Long smove(String srckey, String dstkey, String member); + + Long sort(String key, SortingParams sortingParameters, String dstkey); + + Long sort(String key, String dstkey); + + Set sunion(String... keys); + + Long sunionstore(String dstkey, String... keys); + + String watch(String... keys); + + Long zinterstore(String dstkey, String... sets); + + Long zinterstore(String dstkey, ZParams params, String... sets); + + Long zunionstore(String dstkey, String... sets); + + Long zunionstore(String dstkey, ZParams params, String... sets); + + String brpoplpush(String source, String destination, int timeout); + + Long publish(String channel, String message); + + String randomKey(); +} diff --git a/src/main/java/redis/clients/jedis/ShardedJedis.java b/src/main/java/redis/clients/jedis/ShardedJedis.java index b14adac..6df9157 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedis.java +++ b/src/main/java/redis/clients/jedis/ShardedJedis.java @@ -43,6 +43,11 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { return j.get(key); } + public String echo(String string) { + Jedis j = getShard(string); + return j.echo(string); + } + public Boolean exists(String key) { Jedis j = getShard(key); return j.exists(key); @@ -103,6 +108,16 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { return j.setex(key, seconds, value); } + public List blpop(String arg) { + Jedis j = getShard(arg); + return j.blpop(arg); + } + + public List brpop(String arg) { + Jedis j = getShard(arg); + return j.brpop(arg); + } + public Long decrBy(String key, long integer) { Jedis j = getShard(key); return j.decrBy(key, integer); @@ -218,6 +233,11 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { return j.strlen(key); } + public Long move(String key, int dbIndex) { + Jedis j = getShard(key); + return j.move(key, dbIndex); + } + public Long rpushx(String key, String string) { Jedis j = getShard(key); return j.rpushx(key, string); From 429e45081ec2d509b01a204e997f3872372630af Mon Sep 17 00:00:00 2001 From: samhendley Date: Tue, 25 Dec 2012 09:21:44 -0500 Subject: [PATCH 084/112] removed functions in Jedis that overrode BinaryJedis versions --- .../java/redis/clients/jedis/BinaryJedis.java | 4 + src/main/java/redis/clients/jedis/Jedis.java | 98 ------------------- 2 files changed, 4 insertions(+), 98 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 5403e70..fd537d3 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -2070,12 +2070,16 @@ public class BinaryJedis implements BinaryJedisCommands { } public Long publish(final String channel, final String message) { + checkIsInMulti(); + connect(); client.publish(channel, message); return client.getIntegerReply(); } public void psubscribe(final JedisPubSub jedisPubSub, final String... patterns) { + checkIsInMulti(); + connect(); client.setTimeoutInfinite(); jedisPubSub.proceedWithPatterns(client, patterns); client.rollbackTimeout(); diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 16b03f6..8c91669 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -34,12 +34,6 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand super(uri); } - public String ping() { - checkIsInMulti(); - client.ping(); - return client.getStatusCodeReply(); - } - /** * Set the string value as value of the key. The string can't be longer than * 1073741824 bytes (1 GB). @@ -72,16 +66,6 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand return client.getBulkReply(); } - /** - * Ask the server to silently close the connection. - */ - - public String quit() { - checkIsInMulti(); - client.quit(); - return client.getStatusCodeReply(); - } - /** * Test if the specified key exists. The command returns "1" if the key * exists, otherwise "0" is returned. Note that even keys set with an empty @@ -139,19 +123,6 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand return client.getStatusCodeReply(); } - /** - * Delete all the keys of the currently selected DB. This command never - * fails. - * - * @return Status code reply - */ - - public String flushDB() { - checkIsInMulti(); - client.flushDB(); - return client.getStatusCodeReply(); - } - /** * Returns all the keys matching the glob-style pattern as space separated * strings. For example if you have in the database the keys "foo" and @@ -325,20 +296,6 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand return client.getIntegerReply(); } - /** - * Select the DB with having the specified zero-based numeric index. For - * default every new client connection is automatically selected to DB 0. - * - * @param index - * @return Status code reply - */ - - public String select(final int index) { - checkIsInMulti(); - client.select(index); - return client.getStatusCodeReply(); - } - /** * Move the specified key from the currently selected DB to the specified * destination DB. Note that this command returns 1 only if the key was @@ -358,19 +315,6 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand return client.getIntegerReply(); } - /** - * Delete all the keys of all the existing databases, not just the currently - * selected one. This command never fails. - * - * @return Status code reply - */ - - public String flushAll() { - checkIsInMulti(); - client.flushAll(); - return client.getStatusCodeReply(); - } - /** * GETSET is an atomic set this value and return the old value command. Set * key to the string value and return the old value stored at key. The @@ -1988,49 +1932,7 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand return multiBulkReply; } - /** - * Request for authentication in a password protected Redis server. A Redis - * server can be instructed to require a password before to allow clients to - * issue commands. This is done using the requirepass directive in the Redis - * configuration file. If the password given by the client is correct the - * server replies with an OK status code reply and starts accepting commands - * from the client. Otherwise an error is returned and the clients needs to - * try a new password. Note that for the high performance nature of Redis it - * is possible to try a lot of passwords in parallel in very short time, so - * make sure to generate a strong and very long password so that this attack - * is infeasible. - * - * @param password - * @return Status code reply - */ - public String auth(final String password) { - checkIsInMulti(); - client.auth(password); - return client.getStatusCodeReply(); - } - - public void subscribe(JedisPubSub jedisPubSub, String... channels) { - checkIsInMulti(); - connect(); - client.setTimeoutInfinite(); - jedisPubSub.proceed(client, channels); - client.rollbackTimeout(); - } - - public Long publish(String channel, String message) { - checkIsInMulti(); - client.publish(channel, message); - return client.getIntegerReply(); - } - - public void psubscribe(JedisPubSub jedisPubSub, String... patterns) { - checkIsInMulti(); - connect(); - client.setTimeoutInfinite(); - jedisPubSub.proceedWithPatterns(client, patterns); - client.rollbackTimeout(); - } public Long zcount(final String key, final double min, final double max) { checkIsInMulti(); From 2006d80ac595bf909a86496d9f40fbe342e7faa1 Mon Sep 17 00:00:00 2001 From: samhendley Date: Tue, 25 Dec 2012 16:00:43 -0500 Subject: [PATCH 085/112] normalized BinaryJedisCommands to match JedisCommands (including setbit) --- .../redis/clients/jedis/BinaryClient.java | 4 + .../java/redis/clients/jedis/BinaryJedis.java | 65 ++++++++--- .../clients/jedis/BinaryJedisCommands.java | 104 +++++++++++------- .../clients/jedis/BinaryShardedJedis.java | 54 +++++++-- src/main/java/redis/clients/jedis/Client.java | 6 +- .../java/redis/clients/jedis/Commands.java | 2 + src/main/java/redis/clients/jedis/Jedis.java | 5 + .../redis/clients/jedis/JedisCommands.java | 2 + .../java/redis/clients/jedis/Protocol.java | 4 + .../redis/clients/jedis/ShardedJedis.java | 5 + 10 files changed, 182 insertions(+), 69 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index a5323d2..e87ca29 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -715,6 +715,10 @@ public class BinaryClient extends Connection { sendCommand(SETBIT, key, toByteArray(offset), value); } + public void setbit(byte[] key, long offset, boolean value) { + sendCommand(SETBIT, key, toByteArray(offset), toByteArray(value)); + } + public void getbit(byte[] key, long offset) { sendCommand(GETBIT, key, toByteArray(offset)); } diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index fd537d3..16c90f1 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -135,6 +135,12 @@ public class BinaryJedis implements BinaryJedisCommands { return client.getIntegerReply(); } + public Long del(final byte[] key) { + checkIsInMulti(); + client.del(key); + return client.getIntegerReply(); + } + /** * Return the type of the value stored at key in form of a string. The type * can be one of "none", "string", "list", "set". "none" is returned if the @@ -989,7 +995,7 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Multi bulk reply, specifically a list of elements in the * specified range. */ - public List lrange(final byte[] key, final int start, final int end) { + public List lrange(final byte[] key, final long start, final long end) { checkIsInMulti(); client.lrange(key, start, end); return client.getBinaryMultiBulkReply(); @@ -1029,7 +1035,7 @@ public class BinaryJedis implements BinaryJedisCommands { * @param end * @return Status code reply */ - public String ltrim(final byte[] key, final int start, final int end) { + public String ltrim(final byte[] key, final long start, final long end) { checkIsInMulti(); client.ltrim(key, start, end); return client.getStatusCodeReply(); @@ -1053,7 +1059,7 @@ public class BinaryJedis implements BinaryJedisCommands { * @param index * @return Bulk reply, specifically the requested element */ - public byte[] lindex(final byte[] key, final int index) { + public byte[] lindex(final byte[] key, final long index) { checkIsInMulti(); client.lindex(key, index); return client.getBinaryBulkReply(); @@ -1080,7 +1086,7 @@ public class BinaryJedis implements BinaryJedisCommands { * @param value * @return Status code reply */ - public String lset(final byte[] key, final int index, final byte[] value) { + public String lset(final byte[] key, final long index, final byte[] value) { checkIsInMulti(); client.lset(key, index, value); return client.getStatusCodeReply(); @@ -1105,7 +1111,7 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Integer Reply, specifically: The number of removed elements if * the operation succeeded */ - public Long lrem(final byte[] key, final int count, final byte[] value) { + public Long lrem(final byte[] key, final long count, final byte[] value) { checkIsInMulti(); client.lrem(key, count, value); return client.getIntegerReply(); @@ -1485,7 +1491,7 @@ public class BinaryJedis implements BinaryJedisCommands { return client.getIntegerReply(); } - public Set zrange(final byte[] key, final int start, final int end) { + public Set zrange(final byte[] key, final long start, final long end) { checkIsInMulti(); client.zrange(key, start, end); final List members = client.getBinaryMultiBulkReply(); @@ -1597,24 +1603,24 @@ public class BinaryJedis implements BinaryJedisCommands { return client.getIntegerReply(); } - public Set zrevrange(final byte[] key, final int start, - final int end) { + public Set zrevrange(final byte[] key, final long start, + final long end) { checkIsInMulti(); client.zrevrange(key, start, end); final List members = client.getBinaryMultiBulkReply(); return new LinkedHashSet(members); } - public Set zrangeWithScores(final byte[] key, final int start, - final int end) { + public Set zrangeWithScores(final byte[] key, final long start, + final long end) { checkIsInMulti(); client.zrangeWithScores(key, start, end); Set set = getBinaryTupledSet(); return set; } - public Set zrevrangeWithScores(final byte[] key, final int start, - final int end) { + public Set zrevrangeWithScores(final byte[] key, final long start, + final long end) { checkIsInMulti(); client.zrevrangeWithScores(key, start, end); Set set = getBinaryTupledSet(); @@ -2020,6 +2026,28 @@ public class BinaryJedis implements BinaryJedisCommands { return multiBulkReply; } + public List blpop(byte[] arg) { + checkIsInMulti(); + byte[][] args = new byte[1][]; + args[0] = arg; + client.blpop(args); + client.setTimeoutInfinite(); + final List multiBulkReply = client.getBinaryMultiBulkReply(); + client.rollbackTimeout(); + return multiBulkReply; + } + + public List brpop(byte[] arg) { + checkIsInMulti(); + byte[][] args = new byte[1][]; + args[0] = arg; + client.brpop(args); + client.setTimeoutInfinite(); + final List multiBulkReply = client.getBinaryMultiBulkReply(); + client.rollbackTimeout(); + return multiBulkReply; + } + /** * Request for authentication in a password protected Redis server. A Redis * server can be instructed to require a password before to allow clients to @@ -2448,7 +2476,7 @@ public class BinaryJedis implements BinaryJedisCommands { * operation * */ - public Long zremrangeByRank(final byte[] key, final int start, final int end) { + public Long zremrangeByRank(final byte[] key, final long start, final long end) { checkIsInMulti(); client.zremrangeByRank(key, start, end); return client.getIntegerReply(); @@ -3026,11 +3054,16 @@ public class BinaryJedis implements BinaryJedisCommands { * @param value * @return */ - public Boolean setbit(byte[] key, long offset, byte[] value) { + public Boolean setbit(byte[] key, long offset, boolean value) { client.setbit(key, offset, value); return client.getIntegerReply() == 1; } + public Boolean setbit(byte[] key, long offset, byte[] value) { + client.setbit(key, offset, value); + return client.getIntegerReply() == 1; + } + /** * Returns the bit value at offset in the string value stored at key * @@ -3048,9 +3081,9 @@ public class BinaryJedis implements BinaryJedisCommands { return client.getIntegerReply(); } - public String getrange(byte[] key, long startOffset, long endOffset) { + public byte[] getrange(byte[] key, long startOffset, long endOffset) { client.getrange(key, startOffset, endOffset); - return client.getBulkReply(); + return client.getBinaryBulkReply(); } public Long publish(byte[] channel, byte[] message) { diff --git a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java index 77189f7..237d584 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java +++ b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java @@ -17,6 +17,8 @@ public interface BinaryJedisCommands { Boolean exists(byte[] key); + Long persist(byte[] key); + String type(byte[] key); Long expire(byte[] key, int seconds); @@ -25,6 +27,16 @@ public interface BinaryJedisCommands { Long ttl(byte[] key); + Boolean setbit(byte[] key, long offset, boolean value); + + Boolean setbit(byte[] key, long offset, byte[] value); + + Boolean getbit(byte[] key, long offset); + + Long setrange(byte[] key, long offset, byte[] value); + + byte[] getrange(byte[] key, long startOffset, long endOffset); + byte[] getSet(byte[] key, byte[] value); Long setnx(byte[] key, byte[] value); @@ -67,21 +79,21 @@ public interface BinaryJedisCommands { Map hgetAll(byte[] key); - Long rpush(byte[] key, byte[]... string); + Long rpush(byte[] key, byte[]... args); - Long lpush(byte[] key, byte[]... string); + Long lpush(byte[] key, byte[]... args); Long llen(byte[] key); - List lrange(byte[] key, int start, int end); + List lrange(byte[] key, long start, long end); - String ltrim(byte[] key, int start, int end); + String ltrim(byte[] key, long start, long end); - byte[] lindex(byte[] key, int index); + byte[] lindex(byte[] key, long index); - String lset(byte[] key, int index, byte[] value); + String lset(byte[] key, long index, byte[] value); - Long lrem(byte[] key, int count, byte[] value); + Long lrem(byte[] key, long count, byte[] value); byte[] lpop(byte[] key); @@ -101,11 +113,13 @@ public interface BinaryJedisCommands { byte[] srandmember(byte[] key); - Long zadd(byte[] key, double score, byte[] member); + Long strlen(byte[] key); + Long zadd(byte[] key, double score, byte[] member); + Long zadd(byte[] key, Map scoreMembers); - Set zrange(byte[] key, int start, int end); + Set zrange(byte[] key, long start, long end); Long zrem(byte[] key, byte[]... member); @@ -115,11 +129,11 @@ public interface BinaryJedisCommands { Long zrevrank(byte[] key, byte[] member); - Set zrevrange(byte[] key, int start, int end); + Set zrevrange(byte[] key, long start, long end); - Set zrangeWithScores(byte[] key, int start, int end); + Set zrangeWithScores(byte[] key, long start, long end); - Set zrevrangeWithScores(byte[] key, int start, int end); + Set zrevrangeWithScores(byte[] key, long start, long end); Long zcard(byte[] key); @@ -135,54 +149,62 @@ public interface BinaryJedisCommands { Set zrangeByScore(byte[] key, double min, double max); + Set zrevrangeByScore(byte[] key, double max, double min); + Set zrangeByScore(byte[] key, double min, double max, int offset, int count); - Set zrangeByScoreWithScores(byte[] key, double min, double max); - - Set zrangeByScoreWithScores(byte[] key, double min, double max, - int offset, int count); - - Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max); - - Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max, - int offset, int count); - - Set zrevrangeByScore(byte[] key, double max, double min); - - Set zrevrangeByScore(byte[] key, double max, double min, - int offset, int count); - Set zrevrangeByScore(byte[] key, byte[] max, byte[] min); - Set zrevrangeByScore(byte[] key, byte[] max, byte[] min, - int offset, int count); + Set zrangeByScore(byte[] key, byte[] min, byte[] max, int offset, + int count); + + Set zrevrangeByScore(byte[] key, double max, double min, + int offset, int count); + + Set zrangeByScoreWithScores(byte[] key, double min, double max); Set zrevrangeByScoreWithScores(byte[] key, double max, double min); - Set zrevrangeByScoreWithScores(byte[] key, double max, double min, - int offset, int count); + Set zrangeByScoreWithScores(byte[] key, double min, double max, + int offset, int count); + + Set zrevrangeByScore(byte[] key, byte[] max, byte[] min, + int offset, int count); + Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max); + Set zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min); - Set zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min, - int offset, int count); + Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max, + int offset, int count); - Long zremrangeByRank(byte[] key, int start, int end); + Set zrevrangeByScoreWithScores(byte[] key, double max, double min, + int offset, int count); + + Set zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min, + int offset, int count); + + Long zremrangeByRank(byte[] key, long start, long end); Long zremrangeByScore(byte[] key, double start, double end); - + Long zremrangeByScore(byte[] key, byte[] start, byte[] end); - Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value); + Long linsert(byte[] key, Client.LIST_POSITION where, byte[] pivot, + byte[] value); + + Long lpushx(byte[] key, byte[] arg); + + Long rpushx(byte[] key, byte[] arg); - Long objectRefcount(byte[] key); + List blpop(byte[] arg); - Long objectIdletime(byte[] key); + List brpop(byte[] arg); - byte[] objectEncoding(byte[] key); + Long del(byte[] key); - Long lpushx(byte[] key, byte[] string); + byte[] echo(byte[] arg); - Long rpushx(byte[] key, byte[] string); + Long move(byte[] key, int dbIndex); } diff --git a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java index 68adb8d..9e9d72b 100644 --- a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java @@ -220,27 +220,27 @@ public class BinaryShardedJedis extends Sharded return j.llen(key); } - public List lrange(byte[] key, int start, int end) { + public List lrange(byte[] key, long start, long end) { Jedis j = getShard(key); return j.lrange(key, start, end); } - public String ltrim(byte[] key, int start, int end) { + public String ltrim(byte[] key, long start, long end) { Jedis j = getShard(key); return j.ltrim(key, start, end); } - public byte[] lindex(byte[] key, int index) { + public byte[] lindex(byte[] key, long index) { Jedis j = getShard(key); return j.lindex(key, index); } - public String lset(byte[] key, int index, byte[] value) { + public String lset(byte[] key, long index, byte[] value) { Jedis j = getShard(key); return j.lset(key, index, value); } - public Long lrem(byte[] key, int count, byte[] value) { + public Long lrem(byte[] key, long count, byte[] value) { Jedis j = getShard(key); return j.lrem(key, count, value); } @@ -300,7 +300,7 @@ public class BinaryShardedJedis extends Sharded return j.zadd(key, scoreMembers); } - public Set zrange(byte[] key, int start, int end) { + public Set zrange(byte[] key, long start, long end) { Jedis j = getShard(key); return j.zrange(key, start, end); } @@ -325,17 +325,17 @@ public class BinaryShardedJedis extends Sharded return j.zrevrank(key, member); } - public Set zrevrange(byte[] key, int start, int end) { + public Set zrevrange(byte[] key, long start, long end) { Jedis j = getShard(key); return j.zrevrange(key, start, end); } - public Set zrangeWithScores(byte[] key, int start, int end) { + public Set zrangeWithScores(byte[] key, long start, long end) { Jedis j = getShard(key); return j.zrangeWithScores(key, start, end); } - public Set zrevrangeWithScores(byte[] key, int start, int end) { + public Set zrevrangeWithScores(byte[] key, long start, long end) { Jedis j = getShard(key); return j.zrevrangeWithScores(key, start, end); } @@ -404,6 +404,11 @@ public class BinaryShardedJedis extends Sharded return j.zrangeByScoreWithScores(key, min, max, offset, count); } + public Set zrangeByScore(byte[] key, byte[] min, byte[] max, int offset, int count) { + Jedis j = getShard(key); + return j.zrangeByScore(key, min, max, offset, count); + } + public Set zrevrangeByScore(byte[] key, double max, double min) { Jedis j = getShard(key); return j.zrevrangeByScore(key, max, min); @@ -450,7 +455,7 @@ public class BinaryShardedJedis extends Sharded return j.zrevrangeByScoreWithScores(key, max, min, offset, count); } - public Long zremrangeByRank(byte[] key, int start, int end) { + public Long zremrangeByRank(byte[] key, long start, long end) { Jedis j = getShard(key); return j.zremrangeByRank(key, start, end); } @@ -499,6 +504,11 @@ public class BinaryShardedJedis extends Sharded return j.objectIdletime(key); } + public Boolean setbit(byte[] key, long offset, boolean value) { + Jedis j = getShard(key); + return j.setbit(key, offset, value); + } + public Boolean setbit(byte[] key, long offset, byte[] value) { Jedis j = getShard(key); return j.setbit(key, offset, value); @@ -514,8 +524,30 @@ public class BinaryShardedJedis extends Sharded return j.setrange(key, offset, value); } - public String getrange(byte[] key, long startOffset, long endOffset) { + public byte[] getrange(byte[] key, long startOffset, long endOffset) { Jedis j = getShard(key); return j.getrange(key, startOffset, endOffset); } + + public Long move(byte[] key, int dbIndex) { + Jedis j = getShard(key); + return j.move(key, dbIndex); + } + + public byte[] echo(byte[] arg) { + Jedis j = getShard(arg); + return j.echo(arg); + } + + public List brpop(byte[] arg) { + Jedis j = getShard(arg); + return j.brpop(arg); + } + + public List blpop(byte[] arg) { + Jedis j = getShard(arg); + return j.blpop(arg); + } + + } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index 39aae12..dd1b12b 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -592,7 +592,11 @@ public class Client extends BinaryClient implements Commands { } public void setbit(final String key, final long offset, final boolean value) { - setbit(SafeEncoder.encode(key), offset, toByteArray(value ? 1 : 0)); + setbit(SafeEncoder.encode(key), offset, value); + } + + public void setbit(final String key, final long offset, final String value) { + setbit(SafeEncoder.encode(key), offset, SafeEncoder.encode(value)); } public void getbit(String key, long offset) { diff --git a/src/main/java/redis/clients/jedis/Commands.java b/src/main/java/redis/clients/jedis/Commands.java index 7881909..0023158 100644 --- a/src/main/java/redis/clients/jedis/Commands.java +++ b/src/main/java/redis/clients/jedis/Commands.java @@ -30,6 +30,8 @@ public interface Commands { public void setbit(String key, long offset, boolean value); + public void setbit(String key, long offset, String value); + public void getbit(String key, long offset); public void setrange(String key, long offset, String value); diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 8c91669..d61656e 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -2605,6 +2605,11 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand return client.getIntegerReply() == 1; } + public Boolean setbit(String key, long offset, String value) { + client.setbit(key, offset, value); + return client.getIntegerReply() == 1; + } + /** * Returns the bit value at offset in the string value stored at key * diff --git a/src/main/java/redis/clients/jedis/JedisCommands.java b/src/main/java/redis/clients/jedis/JedisCommands.java index 842e03f..54fdb77 100644 --- a/src/main/java/redis/clients/jedis/JedisCommands.java +++ b/src/main/java/redis/clients/jedis/JedisCommands.java @@ -26,6 +26,8 @@ public interface JedisCommands { Boolean setbit(String key, long offset, boolean value); + Boolean setbit(String key, long offset, String value); + Boolean getbit(String key, long offset); Long setrange(String key, long offset, String value); diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index b1e391d..e3126db 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -131,6 +131,10 @@ public final class Protocol { return process(is); } + public static final byte[] toByteArray(final boolean value) { + return toByteArray(value ? 1 : 0); + } + public static final byte[] toByteArray(final int value) { return SafeEncoder.encode(String.valueOf(value)); } diff --git a/src/main/java/redis/clients/jedis/ShardedJedis.java b/src/main/java/redis/clients/jedis/ShardedJedis.java index 6df9157..cb5b122 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedis.java +++ b/src/main/java/redis/clients/jedis/ShardedJedis.java @@ -78,6 +78,11 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { return j.setbit(key, offset, value); } + public Boolean setbit(String key, long offset, String value) { + Jedis j = getShard(key); + return j.setbit(key, offset, value); + } + public Boolean getbit(String key, long offset) { Jedis j = getShard(key); return j.getbit(key, offset); From cc0ef89b7d5aa00769a8ed3d340b8eaf2fcf6167 Mon Sep 17 00:00:00 2001 From: samhendley Date: Wed, 26 Dec 2012 10:22:38 -0500 Subject: [PATCH 086/112] added binary version of MultiKey commands --- .../java/redis/clients/jedis/BinaryJedis.java | 20 +++++- .../clients/jedis/BinaryJedisCommands.java | 2 + .../clients/jedis/BinaryShardedJedis.java | 6 +- .../clients/jedis/MultiKeyBinaryCommands.java | 65 +++++++++++++++++++ 4 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 src/main/java/redis/clients/jedis/MultiKeyBinaryCommands.java diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 16c90f1..1b35263 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -17,7 +17,7 @@ import redis.clients.jedis.exceptions.JedisException; import redis.clients.util.JedisByteHashMap; import redis.clients.util.SafeEncoder; -public class BinaryJedis implements BinaryJedisCommands { +public class BinaryJedis implements BinaryJedisCommands, MultiKeyBinaryCommands { protected Client client = null; public BinaryJedis(final String host) { @@ -2048,6 +2048,24 @@ public class BinaryJedis implements BinaryJedisCommands { return multiBulkReply; } + public List blpop(byte[]... args) { + checkIsInMulti(); + client.blpop(args); + client.setTimeoutInfinite(); + final List multiBulkReply = client.getBinaryMultiBulkReply(); + client.rollbackTimeout(); + return multiBulkReply; + } + + public List brpop(byte[]... args) { + checkIsInMulti(); + client.brpop(args); + client.setTimeoutInfinite(); + final List multiBulkReply = client.getBinaryMultiBulkReply(); + client.rollbackTimeout(); + return multiBulkReply; + } + /** * Request for authentication in a password protected Redis server. A Redis * server can be instructed to require a password before to allow clients to diff --git a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java index 237d584..71b630e 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java +++ b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java @@ -149,6 +149,8 @@ public interface BinaryJedisCommands { Set zrangeByScore(byte[] key, double min, double max); + Set zrangeByScore(byte[] key, byte[] min, byte[] max); + Set zrevrangeByScore(byte[] key, double max, double min); Set zrangeByScore(byte[] key, double min, double max, int offset, diff --git a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java index 9e9d72b..686af12 100644 --- a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java @@ -391,7 +391,11 @@ public class BinaryShardedJedis extends Sharded Jedis j = getShard(key); return j.zrangeByScoreWithScores(key, min, max, offset, count); } - + + public Set zrangeByScore(byte[] key, byte[] min, byte[] max) { + Jedis j = getShard(key); + return j.zrangeByScore(key, min, max); + } public Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max) { Jedis j = getShard(key); diff --git a/src/main/java/redis/clients/jedis/MultiKeyBinaryCommands.java b/src/main/java/redis/clients/jedis/MultiKeyBinaryCommands.java new file mode 100644 index 0000000..b115173 --- /dev/null +++ b/src/main/java/redis/clients/jedis/MultiKeyBinaryCommands.java @@ -0,0 +1,65 @@ +package redis.clients.jedis; + + +import java.util.List; +import java.util.Set; + +public interface MultiKeyBinaryCommands { + Long del(byte[]... keys); + + List blpop(int timeout, byte[]... keys); + + List brpop(int timeout, byte[]... keys); + + List blpop(byte[]... args); + + List brpop(byte[]... args); + + Set keys(byte[] pattern); + + List mget(byte[]... keys); + + String mset(byte[]... keysvalues); + + Long msetnx(byte[]... keysvalues); + + String rename(byte[] oldkey, byte[] newkey); + + Long renamenx(byte[] oldkey, byte[] newkey); + + byte[] rpoplpush(byte[] srckey, byte[] dstkey); + + Set sdiff(byte[]... keys); + + Long sdiffstore(byte[] dstkey, byte[]... keys); + + Set sinter(byte[]... keys); + + Long sinterstore(byte[] dstkey, byte[]... keys); + + Long smove(byte[] srckey, byte[] dstkey, byte[] member); + + Long sort(byte[] key, SortingParams sortingParameters, byte[] dstkey); + + Long sort(byte[] key, byte[] dstkey); + + Set sunion(byte[]... keys); + + Long sunionstore(byte[] dstkey, byte[]... keys); + + String watch(byte[]... keys); + + Long zinterstore(byte[] dstkey, byte[]... sets); + + Long zinterstore(byte[] dstkey, ZParams params, byte[]... sets); + + Long zunionstore(byte[] dstkey, byte[]... sets); + + Long zunionstore(byte[] dstkey, ZParams params, byte[]... sets); + + byte[] brpoplpush(byte[] source, byte[] destination, int timeout); + + Long publish(byte[] channel, byte[] message); + + byte[] randomBinaryKey(); +} From 5bde3da7f23a599669bafa7f23858fff342234f6 Mon Sep 17 00:00:00 2001 From: samhendley Date: Wed, 26 Dec 2012 11:45:57 -0500 Subject: [PATCH 087/112] added interfaces for ScriptingCommands, AdvancedCommands most of jedis and binaryjedis are defined by interfaces --- .../jedis/AdvancedBinaryJedisCommands.java | 25 +++++++ .../clients/jedis/AdvancedJedisCommands.java | 26 +++++++ .../redis/clients/jedis/BasicCommands.java | 40 ++++++++++ .../redis/clients/jedis/BinaryClient.java | 10 ++- .../java/redis/clients/jedis/BinaryJedis.java | 73 ++++++++++--------- .../jedis/BinaryScriptingCommands.java | 30 ++++++++ src/main/java/redis/clients/jedis/Jedis.java | 25 ++++++- .../clients/jedis/MultiKeyBinaryCommands.java | 6 ++ .../redis/clients/jedis/MultiKeyCommands.java | 6 ++ ...icCommands.java => ScriptingCommands.java} | 19 +---- 10 files changed, 207 insertions(+), 53 deletions(-) create mode 100644 src/main/java/redis/clients/jedis/AdvancedBinaryJedisCommands.java create mode 100644 src/main/java/redis/clients/jedis/AdvancedJedisCommands.java create mode 100644 src/main/java/redis/clients/jedis/BasicCommands.java create mode 100644 src/main/java/redis/clients/jedis/BinaryScriptingCommands.java rename src/main/java/redis/clients/jedis/{JedisBasicCommands.java => ScriptingCommands.java} (58%) diff --git a/src/main/java/redis/clients/jedis/AdvancedBinaryJedisCommands.java b/src/main/java/redis/clients/jedis/AdvancedBinaryJedisCommands.java new file mode 100644 index 0000000..51b4879 --- /dev/null +++ b/src/main/java/redis/clients/jedis/AdvancedBinaryJedisCommands.java @@ -0,0 +1,25 @@ +package redis.clients.jedis; + + +import java.util.List; + +public interface AdvancedBinaryJedisCommands { + + List configGet(byte[] pattern); + + byte[] configSet(byte[] parameter, byte[] value); + + String slowlogReset(); + + Long slowlogLen(); + + List slowlogGetBinary(); + + List slowlogGetBinary(long entries); + + Long objectRefcount(byte[] key); + + byte[] objectEncoding(byte[] key); + + Long objectIdletime(byte[] key); +} diff --git a/src/main/java/redis/clients/jedis/AdvancedJedisCommands.java b/src/main/java/redis/clients/jedis/AdvancedJedisCommands.java new file mode 100644 index 0000000..5ed50eb --- /dev/null +++ b/src/main/java/redis/clients/jedis/AdvancedJedisCommands.java @@ -0,0 +1,26 @@ +package redis.clients.jedis; + +import redis.clients.util.Slowlog; + +import java.util.List; + + +public interface AdvancedJedisCommands { + List configGet(String pattern); + + String configSet(String parameter, String value); + + String slowlogReset(); + + Long slowlogLen(); + + List slowlogGet(); + + List slowlogGet(long entries); + + Long objectRefcount(String string); + + String objectEncoding(String string); + + Long objectIdletime(String string); +} diff --git a/src/main/java/redis/clients/jedis/BasicCommands.java b/src/main/java/redis/clients/jedis/BasicCommands.java new file mode 100644 index 0000000..fa4ee2d --- /dev/null +++ b/src/main/java/redis/clients/jedis/BasicCommands.java @@ -0,0 +1,40 @@ +package redis.clients.jedis; + +public interface BasicCommands { + + String ping(); + + String quit(); + + String flushDB(); + + Long dbSize(); + + String select(int index); + + String flushAll(); + + String auth(String password); + + String save(); + + String bgsave(); + + String bgrewriteaof(); + + Long lastsave(); + + String shutdown(); + + String info(); + + String slaveof(String host, int port); + + String slaveofNoOne(); + + Long getDB(); + + String debug(DebugParams params); + + String configResetStat(); +} diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index e87ca29..778e97e 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -759,10 +759,18 @@ public class BinaryClient extends Connection { sendEvalCommand(EVAL, script, keyCount, params); } - public void evalsha(byte[] sha1, byte[] keyCount, byte[][] params) { + public void eval(byte[] script, int keyCount, byte[]... params) { + eval(script, toByteArray(keyCount), params); + } + + public void evalsha(byte[] sha1, byte[] keyCount, byte[]... params) { sendEvalCommand(EVALSHA, sha1, keyCount, params); } + public void evalsha(byte[] sha1, int keyCount, byte[]... params) { + sendEvalCommand(EVALSHA, sha1, toByteArray(keyCount), params); + } + public void scriptFlush() { sendCommand(SCRIPT, Keyword.FLUSH.raw); } diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 1b35263..d26043d 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -17,7 +17,7 @@ import redis.clients.jedis.exceptions.JedisException; import redis.clients.util.JedisByteHashMap; import redis.clients.util.SafeEncoder; -public class BinaryJedis implements BinaryJedisCommands, MultiKeyBinaryCommands { +public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKeyBinaryCommands, AdvancedBinaryJedisCommands, BinaryScriptingCommands { protected Client client = null; public BinaryJedis(final String host) { @@ -2108,29 +2108,6 @@ public class BinaryJedis implements BinaryJedisCommands, MultiKeyBinaryCommands return pipeline; } - public void subscribe(final JedisPubSub jedisPubSub, - final String... channels) { - client.setTimeoutInfinite(); - jedisPubSub.proceed(client, channels); - client.rollbackTimeout(); - } - - public Long publish(final String channel, final String message) { - checkIsInMulti(); - connect(); - client.publish(channel, message); - return client.getIntegerReply(); - } - - public void psubscribe(final JedisPubSub jedisPubSub, - final String... patterns) { - checkIsInMulti(); - connect(); - client.setTimeoutInfinite(); - jedisPubSub.proceedWithPatterns(client, patterns); - client.rollbackTimeout(); - } - public Long zcount(final byte[] key, final double min, final double max) { return zcount(key, toByteArray(min), toByteArray(max)); } @@ -3151,20 +3128,50 @@ public class BinaryJedis implements BinaryJedisCommands, MultiKeyBinaryCommands return params; } - public Object eval(byte[] script, byte[] keyCount, byte[][] params) { + public Object eval(byte[] script, byte[] keyCount, byte[]... params) { client.setTimeoutInfinite(); client.eval(script, keyCount, params); return client.getOne(); } - public byte[] scriptFlush() { + public Object eval(byte[] script, int keyCount, byte[]... params) { + client.setTimeoutInfinite(); + client.eval(script, SafeEncoder.encode(Integer.toString(keyCount)), params); + return client.getOne(); + } + + public Object eval(byte[] script) { + client.setTimeoutInfinite(); + client.eval(script, 0); + return client.getOne(); + } + + public Object evalsha(byte[] sha1) { + client.setTimeoutInfinite(); + client.evalsha(sha1, 0); + return client.getOne(); + } + + public Object evalsha(byte[] sha1, List keys, List args) { + client.setTimeoutInfinite(); + client.evalsha(sha1, keys.size(), keys.toArray(new byte[0][])); + return client.getOne(); + } + + public Object evalsha(byte[] sha1, int keyCount, byte[]... params) { + client.setTimeoutInfinite(); + client.evalsha(sha1, keyCount, params); + return client.getOne(); + } + + public String scriptFlush() { client.scriptFlush(); - return client.getBinaryBulkReply(); + return client.getStatusCodeReply(); } public List scriptExists(byte[]... sha1) { client.scriptExists(sha1); - return client.getIntegerMultiBulkReply(); + return client.getIntegerMultiBulkReply(); } public byte[] scriptLoad(byte[] script) { @@ -3172,17 +3179,17 @@ public class BinaryJedis implements BinaryJedisCommands, MultiKeyBinaryCommands return client.getBinaryBulkReply(); } - public byte[] scriptKill() { + public String scriptKill() { client.scriptKill(); - return client.getBinaryBulkReply(); + return client.getStatusCodeReply(); } - public byte[] slowlogReset() { + public String slowlogReset() { client.slowlogReset(); - return client.getBinaryBulkReply(); + return client.getBulkReply(); } - public long slowlogLen() { + public Long slowlogLen() { client.slowlogLen(); return client.getIntegerReply(); } diff --git a/src/main/java/redis/clients/jedis/BinaryScriptingCommands.java b/src/main/java/redis/clients/jedis/BinaryScriptingCommands.java new file mode 100644 index 0000000..092ce7a --- /dev/null +++ b/src/main/java/redis/clients/jedis/BinaryScriptingCommands.java @@ -0,0 +1,30 @@ +package redis.clients.jedis; + + +import java.util.List; + +public interface BinaryScriptingCommands { + + Object eval(byte[] script, byte[] keyCount, byte[]... params); + + Object eval(byte[] script, int keyCount, byte[]... params); + + Object eval(byte[] script, List keys, List args); + + Object eval(byte[] script); + + Object evalsha(byte[] script); + + Object evalsha(byte[] sha1, List keys, List args); + + Object evalsha(byte[] sha1, int keyCount, byte[]... params); + + // TODO: should be Boolean, add singular version + List scriptExists(byte[]... sha1); + + byte[] scriptLoad(byte[] script); + + String scriptFlush(); + + String scriptKill(); +} diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index d61656e..e2c2c72 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -13,7 +13,7 @@ import redis.clients.jedis.BinaryClient.LIST_POSITION; import redis.clients.util.SafeEncoder; import redis.clients.util.Slowlog; -public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommands, JedisBasicCommands { +public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommands, AdvancedJedisCommands, ScriptingCommands { public Jedis(final String host) { super(host); } @@ -2719,6 +2719,29 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand return getEvalResult(); } + public void subscribe(final JedisPubSub jedisPubSub, + final String... channels) { + client.setTimeoutInfinite(); + jedisPubSub.proceed(client, channels); + client.rollbackTimeout(); + } + + public Long publish(final String channel, final String message) { + checkIsInMulti(); + connect(); + client.publish(channel, message); + return client.getIntegerReply(); + } + + public void psubscribe(final JedisPubSub jedisPubSub, + final String... patterns) { + checkIsInMulti(); + connect(); + client.setTimeoutInfinite(); + jedisPubSub.proceedWithPatterns(client, patterns); + client.rollbackTimeout(); + } + private String[] getParams(List keys, List args) { int keyCount = keys.size(); int argCount = args.size(); diff --git a/src/main/java/redis/clients/jedis/MultiKeyBinaryCommands.java b/src/main/java/redis/clients/jedis/MultiKeyBinaryCommands.java index b115173..277b70e 100644 --- a/src/main/java/redis/clients/jedis/MultiKeyBinaryCommands.java +++ b/src/main/java/redis/clients/jedis/MultiKeyBinaryCommands.java @@ -49,6 +49,8 @@ public interface MultiKeyBinaryCommands { String watch(byte[]... keys); + String unwatch(); + Long zinterstore(byte[] dstkey, byte[]... sets); Long zinterstore(byte[] dstkey, ZParams params, byte[]... sets); @@ -61,5 +63,9 @@ public interface MultiKeyBinaryCommands { Long publish(byte[] channel, byte[] message); + void subscribe(BinaryJedisPubSub jedisPubSub, byte[]... channels); + + void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns); + byte[] randomBinaryKey(); } diff --git a/src/main/java/redis/clients/jedis/MultiKeyCommands.java b/src/main/java/redis/clients/jedis/MultiKeyCommands.java index 8a333a9..d2386a6 100644 --- a/src/main/java/redis/clients/jedis/MultiKeyCommands.java +++ b/src/main/java/redis/clients/jedis/MultiKeyCommands.java @@ -49,6 +49,8 @@ public interface MultiKeyCommands { String watch(String... keys); + String unwatch(); + Long zinterstore(String dstkey, String... sets); Long zinterstore(String dstkey, ZParams params, String... sets); @@ -61,5 +63,9 @@ public interface MultiKeyCommands { Long publish(String channel, String message); + void subscribe(JedisPubSub jedisPubSub, String... channels); + + void psubscribe(JedisPubSub jedisPubSub, String... patterns); + String randomKey(); } diff --git a/src/main/java/redis/clients/jedis/JedisBasicCommands.java b/src/main/java/redis/clients/jedis/ScriptingCommands.java similarity index 58% rename from src/main/java/redis/clients/jedis/JedisBasicCommands.java rename to src/main/java/redis/clients/jedis/ScriptingCommands.java index 2f89586..ba693a4 100644 --- a/src/main/java/redis/clients/jedis/JedisBasicCommands.java +++ b/src/main/java/redis/clients/jedis/ScriptingCommands.java @@ -1,15 +1,8 @@ package redis.clients.jedis; -import redis.clients.util.Slowlog; - import java.util.List; - -public interface JedisBasicCommands { - List configGet(String pattern); - - String configSet(String parameter, String value); - +public interface ScriptingCommands { Object eval(String script, int keyCount, String... params); Object eval(String script, List keys, List args); @@ -27,14 +20,4 @@ public interface JedisBasicCommands { List scriptExists(String... sha1); String scriptLoad(String script); - - List slowlogGet(); - - List slowlogGet(long entries); - - Long objectRefcount(String string); - - String objectEncoding(String string); - - Long objectIdletime(String string); } From 7b7c6c9602f41b0b9f8a022aa16c6da9556cf64b Mon Sep 17 00:00:00 2001 From: samhendley Date: Wed, 26 Dec 2012 11:58:48 -0500 Subject: [PATCH 088/112] fixed up some missing pipelined methods --- .../redis/clients/jedis/BinaryRedisPipeline.java | 2 ++ .../redis/clients/jedis/BinaryShardedJedis.java | 9 +++++---- .../clients/jedis/MultiKeyBinaryRedisPipeline.java | 2 ++ .../java/redis/clients/jedis/RedisPipeline.java | 2 ++ .../java/redis/clients/jedis/ShardedJedis.java | 7 ------- .../redis/clients/jedis/ShardedJedisPipeline.java | 14 ++++++++++++++ 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java b/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java index 959f915..af57473 100644 --- a/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java +++ b/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java @@ -85,6 +85,8 @@ public interface BinaryRedisPipeline { Response ltrim(byte[] key, long start, long end); + Response move(byte[] key, int dbIndex); + Response persist(byte[] key); Response rpop(byte[] key); diff --git a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java index 686af12..e8a5dc5 100644 --- a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java @@ -30,10 +30,11 @@ public class BinaryShardedJedis extends Sharded super(shards, algo, keyTagPattern); } - public void disconnect() throws IOException { - for (Jedis jedis : getAllShards()) { - jedis.disconnect(); - } + public void disconnect() { + for (Jedis jedis : getAllShards()) { + jedis.quit(); + jedis.disconnect(); + } } protected Jedis create(JedisShardInfo shard) { diff --git a/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java b/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java index 12e2368..1413774 100644 --- a/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java +++ b/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java @@ -60,4 +60,6 @@ public interface MultiKeyBinaryRedisPipeline { Response brpoplpush(byte[] source, byte[] destination, int timeout); Response publish(byte[] channel, byte[] message); + + Response randomKeyBinary(); } diff --git a/src/main/java/redis/clients/jedis/RedisPipeline.java b/src/main/java/redis/clients/jedis/RedisPipeline.java index 570e620..3d79393 100644 --- a/src/main/java/redis/clients/jedis/RedisPipeline.java +++ b/src/main/java/redis/clients/jedis/RedisPipeline.java @@ -88,6 +88,8 @@ public interface RedisPipeline { Response ltrim(String key, long start, long end); + Response move(String key, int dbIndex); + Response persist(String key); Response rpop(String key); diff --git a/src/main/java/redis/clients/jedis/ShardedJedis.java b/src/main/java/redis/clients/jedis/ShardedJedis.java index cb5b122..142e754 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedis.java +++ b/src/main/java/redis/clients/jedis/ShardedJedis.java @@ -26,13 +26,6 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { super(shards, algo, keyTagPattern); } - public void disconnect() { - for (Jedis jedis : getAllShards()) { - jedis.quit(); - jedis.disconnect(); - } - } - public String set(String key, String value) { Jedis j = getShard(key); return j.set(key, value); diff --git a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java index 771cdc9..8725bf3 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java +++ b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java @@ -91,6 +91,20 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING_LIST); } + public Response move(byte[] key, int dbIndex) { + Client c = getClient(key); + c.move(key, dbIndex); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + + public Response move(String key, int dbIndex) { + Client c = getClient(key); + c.move(key, dbIndex); + results.add(new FutureResult(c)); + return getResponse(BuilderFactory.LONG); + } + public Response echo(byte[] string) { Client c = getClient(string); c.echo(string); From 1a967694817594e0c43f5ce6095eeec01f52e9e3 Mon Sep 17 00:00:00 2001 From: samhendley Date: Wed, 9 Jan 2013 22:52:38 -0500 Subject: [PATCH 089/112] updated scripting test to be more tolerant of changing error messages (changed since 2.6.0) --- .../clients/jedis/tests/commands/ScriptingCommandsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java index acee2cf..ed59799 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java @@ -132,7 +132,7 @@ public class ScriptingCommandsTest extends JedisCommandTestBase { jedis.scriptKill(); } catch(JedisDataException e) { - assertEquals("ERR No scripts in execution right now.", e.getMessage()); + assertTrue(e.getMessage().contains("No scripts in execution right now.")); } } } \ No newline at end of file From 4f9ddb3b5f1da4c4f60b0c07ba0f39e1c5ba8c6e Mon Sep 17 00:00:00 2001 From: samhendley Date: Thu, 10 Jan 2013 00:50:19 -0500 Subject: [PATCH 090/112] fixed many pipeline requests that were returning the wrong types --- .../clients/jedis/BasicRedisPipeline.java | 6 -- .../clients/jedis/BinaryRedisPipeline.java | 30 +++---- .../jedis/MultiKeyBinaryRedisPipeline.java | 4 +- .../java/redis/clients/jedis/Pipeline.java | 84 +++++++++---------- .../redis/clients/jedis/RedisPipeline.java | 2 +- .../clients/jedis/ShardedJedisPipeline.java | 64 +++++++------- 6 files changed, 92 insertions(+), 98 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BasicRedisPipeline.java b/src/main/java/redis/clients/jedis/BasicRedisPipeline.java index 0b4ac36..97658d8 100644 --- a/src/main/java/redis/clients/jedis/BasicRedisPipeline.java +++ b/src/main/java/redis/clients/jedis/BasicRedisPipeline.java @@ -22,12 +22,6 @@ public interface BasicRedisPipeline { Response lastsave(); - Response discard(); - - Response> exec(); - - Response multi(); - Response flushDB(); Response flushAll(); diff --git a/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java b/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java index 3722351..5c04491 100644 --- a/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java +++ b/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java @@ -111,18 +111,18 @@ public interface BinaryRedisPipeline { Response setrange(String key, long offset, String value); - Response> smembers(byte[] key); + Response> smembers(byte[] key); Response sismember(byte[] key, byte[] member); - Response sort(byte[] key); + Response> sort(byte[] key); - Response> sort(byte[] key, + Response> sort(byte[] key, SortingParams sortingParameters); - Response spop(byte[] key); + Response spop(byte[] key); - Response srandmember(byte[] key); + Response srandmember(byte[] key); Response srem(byte[] key, byte[] member); @@ -142,18 +142,18 @@ public interface BinaryRedisPipeline { Response zincrby(byte[] key, double score, byte[] member); - Response> zrange(byte[] key, int start, int end); + Response> zrange(byte[] key, int start, int end); - Response> zrangeByScore(byte[] key, double min, + Response> zrangeByScore(byte[] key, double min, double max); - Response> zrangeByScore(byte[] key, byte[] min, + Response> zrangeByScore(byte[] key, byte[] min, byte[] max); - Response> zrangeByScore(byte[] key, double min, + Response> zrangeByScore(byte[] key, double min, double max, int offset, int count); - Response> zrangeByScore(byte[] key, byte[] min, + Response> zrangeByScore(byte[] key, byte[] min, byte[] max, int offset, int count); Response> zrangeByScoreWithScores(byte[] key, double min, @@ -168,16 +168,16 @@ public interface BinaryRedisPipeline { Response> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max, int offset, int count); - Response> zrevrangeByScore(byte[] key, double max, + Response> zrevrangeByScore(byte[] key, double max, double min); - Response> zrevrangeByScore(byte[] key, byte[] max, + Response> zrevrangeByScore(byte[] key, byte[] max, byte[] min); - Response> zrevrangeByScore(byte[] key, double max, + Response> zrevrangeByScore(byte[] key, double max, double min, int offset, int count); - Response> zrevrangeByScore(byte[] key, byte[] max, + Response> zrevrangeByScore(byte[] key, byte[] max, byte[] min, int offset, int count); Response> zrevrangeByScoreWithScores(byte[] key, @@ -204,7 +204,7 @@ public interface BinaryRedisPipeline { Response zremrangeByScore(byte[] key, byte[] start, byte[] end); - Response> zrevrange(byte[] key, int start, int end); + Response> zrevrange(byte[] key, int start, int end); Response> zrevrangeWithScores(byte[] key, int start, int end); diff --git a/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java b/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java index 74f0e3d..85d004b 100644 --- a/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java +++ b/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java @@ -23,7 +23,7 @@ public interface MultiKeyBinaryRedisPipeline { Response msetnx(byte[]... keysvalues); - Response rename(byte[] oldkey, byte[] newkey); + Response rename(byte[] oldkey, byte[] newkey); Response renamenx(byte[] oldkey, byte[] newkey); @@ -43,7 +43,7 @@ public interface MultiKeyBinaryRedisPipeline { Response> sort(byte[] key, byte[] dstkey); - Response> sunion(byte[]... keys); + Response> sunion(byte[]... keys); Response sunionstore(byte[] dstkey, byte[]... keys); diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index afd98f5..d605f25 100755 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -586,9 +586,9 @@ public class Pipeline extends Queable implements return getResponse(BuilderFactory.STRING); } - public Response rename(byte[] oldkey, byte[] newkey) { + public Response rename(byte[] oldkey, byte[] newkey) { client.rename(oldkey, newkey); - return getResponse(BuilderFactory.BYTE_ARRAY); + return getResponse(BuilderFactory.STRING); } public Response renamenx(String oldkey, String newkey) { @@ -766,9 +766,9 @@ public class Pipeline extends Queable implements return getResponse(BuilderFactory.STRING_SET); } - public Response> smembers(byte[] key) { + public Response> smembers(byte[] key) { client.smembers(key); - return getResponse(BuilderFactory.STRING_SET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response smove(String srckey, String dstkey, String member) { @@ -781,14 +781,14 @@ public class Pipeline extends Queable implements return getResponse(BuilderFactory.LONG); } - public Response sort(String key) { + public Response> sort(String key) { client.sort(key); - return getResponse(BuilderFactory.LONG); + return getResponse(BuilderFactory.STRING_LIST); } - public Response sort(byte[] key) { + public Response> sort(byte[] key) { client.sort(key); - return getResponse(BuilderFactory.LONG); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response> sort(String key, @@ -797,10 +797,10 @@ public class Pipeline extends Queable implements return getResponse(BuilderFactory.STRING_LIST); } - public Response> sort(byte[] key, + public Response> sort(byte[] key, SortingParams sortingParameters) { client.sort(key, sortingParameters); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response> sort(String key, @@ -830,9 +830,9 @@ public class Pipeline extends Queable implements return getResponse(BuilderFactory.STRING); } - public Response spop(byte[] key) { + public Response spop(byte[] key) { client.spop(key); - return getResponse(BuilderFactory.STRING); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response srandmember(String key) { @@ -840,9 +840,9 @@ public class Pipeline extends Queable implements return getResponse(BuilderFactory.STRING); } - public Response srandmember(byte[] key) { + public Response srandmember(byte[] key) { client.srandmember(key); - return getResponse(BuilderFactory.STRING); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response srem(String key, String member) { @@ -880,9 +880,9 @@ public class Pipeline extends Queable implements return getResponse(BuilderFactory.STRING_SET); } - public Response> sunion(byte[]... keys) { + public Response> sunion(byte[]... keys) { client.sunion(keys); - return getResponse(BuilderFactory.STRING_SET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response sunionstore(String dstkey, String... keys) { @@ -992,9 +992,9 @@ public class Pipeline extends Queable implements return getResponse(BuilderFactory.STRING_ZSET); } - public Response> zrange(byte[] key, int start, int end) { + public Response> zrange(byte[] key, int start, int end) { client.zrange(key, start, end); - return getResponse(BuilderFactory.STRING_ZSET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrangeByScore(String key, double min, @@ -1003,7 +1003,7 @@ public class Pipeline extends Queable implements return getResponse(BuilderFactory.STRING_ZSET); } - public Response> zrangeByScore(byte[] key, double min, + public Response> zrangeByScore(byte[] key, double min, double max) { return zrangeByScore(key, toByteArray(min), toByteArray(max)); } @@ -1014,10 +1014,10 @@ public class Pipeline extends Queable implements return getResponse(BuilderFactory.STRING_ZSET); } - public Response> zrangeByScore(byte[] key, byte[] min, + public Response> zrangeByScore(byte[] key, byte[] min, byte[] max) { client.zrangeByScore(key, min, max); - return getResponse(BuilderFactory.STRING_ZSET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrangeByScore(String key, double min, @@ -1026,15 +1026,15 @@ public class Pipeline extends Queable implements return getResponse(BuilderFactory.STRING_ZSET); } - public Response> zrangeByScore(byte[] key, double min, + public Response> zrangeByScore(byte[] key, double min, double max, int offset, int count) { return zrangeByScore(key, toByteArray(min), toByteArray(max), offset, count); } - public Response> zrangeByScore(byte[] key, byte[] min, + public Response> zrangeByScore(byte[] key, byte[] min, byte[] max, int offset, int count) { client.zrangeByScore(key, min, max, offset, count); - return getResponse(BuilderFactory.STRING_ZSET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrangeByScoreWithScores(String key, double min, @@ -1051,7 +1051,7 @@ public class Pipeline extends Queable implements public Response> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max) { client.zrangeByScoreWithScores(key, min, max); - return getResponse(BuilderFactory.TUPLE_ZSET); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrangeByScoreWithScores(String key, double min, @@ -1063,13 +1063,13 @@ public class Pipeline extends Queable implements public Response> zrangeByScoreWithScores(byte[] key, double min, double max, int offset, int count) { client.zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max, int offset, int count) { client.zrangeByScoreWithScores(key, min, max, offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrevrangeByScore(String key, double max, @@ -1078,10 +1078,10 @@ public class Pipeline extends Queable implements return getResponse(BuilderFactory.STRING_ZSET); } - public Response> zrevrangeByScore(byte[] key, double max, + public Response> zrevrangeByScore(byte[] key, double max, double min) { client.zrevrangeByScore(key, toByteArray(max), toByteArray(min)); - return getResponse(BuilderFactory.STRING_ZSET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrevrangeByScore(String key, String max, @@ -1090,10 +1090,10 @@ public class Pipeline extends Queable implements return getResponse(BuilderFactory.STRING_ZSET); } - public Response> zrevrangeByScore(byte[] key, byte[] max, + public Response> zrevrangeByScore(byte[] key, byte[] max, byte[] min) { client.zrevrangeByScore(key, max, min); - return getResponse(BuilderFactory.STRING_ZSET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrevrangeByScore(String key, double max, @@ -1102,16 +1102,16 @@ public class Pipeline extends Queable implements return getResponse(BuilderFactory.STRING_ZSET); } - public Response> zrevrangeByScore(byte[] key, double max, + public Response> zrevrangeByScore(byte[] key, double max, double min, int offset, int count) { client.zrevrangeByScore(key, toByteArray(max), toByteArray(min), offset, count); - return getResponse(BuilderFactory.STRING_ZSET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } - public Response> zrevrangeByScore(byte[] key, byte[] max, + public Response> zrevrangeByScore(byte[] key, byte[] max, byte[] min, int offset, int count) { client.zrevrangeByScore(key, max, min, offset, count); - return getResponse(BuilderFactory.STRING_ZSET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrevrangeByScoreWithScores(String key, @@ -1123,13 +1123,13 @@ public class Pipeline extends Queable implements public Response> zrevrangeByScoreWithScores(byte[] key, double max, double min) { client.zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min)); - return getResponse(BuilderFactory.TUPLE_ZSET); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min) { client.zrevrangeByScoreWithScores(key, max, min); - return getResponse(BuilderFactory.TUPLE_ZSET); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrevrangeByScoreWithScores(String key, @@ -1141,13 +1141,13 @@ public class Pipeline extends Queable implements public Response> zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count) { client.zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min), offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min, int offset, int count) { client.zrevrangeByScoreWithScores(key, max, min, offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrangeWithScores(String key, int start, int end) { @@ -1157,7 +1157,7 @@ public class Pipeline extends Queable implements public Response> zrangeWithScores(byte[] key, int start, int end) { client.zrangeWithScores(key, start, end); - return getResponse(BuilderFactory.TUPLE_ZSET); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response zrank(String key, String member) { @@ -1210,9 +1210,9 @@ public class Pipeline extends Queable implements return getResponse(BuilderFactory.STRING_ZSET); } - public Response> zrevrange(byte[] key, int start, int end) { + public Response> zrevrange(byte[] key, int start, int end) { client.zrevrange(key, start, end); - return getResponse(BuilderFactory.STRING_ZSET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrevrangeWithScores(String key, int start, diff --git a/src/main/java/redis/clients/jedis/RedisPipeline.java b/src/main/java/redis/clients/jedis/RedisPipeline.java index 8d42aa2..b1c8461 100644 --- a/src/main/java/redis/clients/jedis/RedisPipeline.java +++ b/src/main/java/redis/clients/jedis/RedisPipeline.java @@ -116,7 +116,7 @@ public interface RedisPipeline { Response> smembers(String key); - Response sort(String key); + Response> sort(String key); Response> sort(String key, SortingParams sortingParameters); diff --git a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java index 1234b44..2601f9c 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java +++ b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java @@ -700,11 +700,11 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING_SET); } - public Response> smembers(byte[] key) { + public Response> smembers(byte[] key) { Client c = getClient(key); c.smembers(key); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_SET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response srem(String key, String member) { @@ -742,11 +742,11 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING); } - public Response spop(byte[] key) { + public Response spop(byte[] key) { Client c = getClient(key); c.spop(key); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response scard(String key) { @@ -784,11 +784,11 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING); } - public Response srandmember(byte[] key) { + public Response srandmember(byte[] key) { Client c = getClient(key); c.srandmember(key); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response zadd(String key, double score, String member) { @@ -812,11 +812,11 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING_ZSET); } - public Response> zrange(byte[] key, int start, int end) { + public Response> zrange(byte[] key, int start, int end) { Client c = getClient(key); c.zrange(key, start, end); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_ZSET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response zrem(String key, String member) { @@ -882,11 +882,11 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING_ZSET); } - public Response> zrevrange(byte[] key, int start, int end) { + public Response> zrevrange(byte[] key, int start, int end) { Client c = getClient(key); c.zrevrange(key, start, end); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_ZSET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrangeWithScores(String key, int start, int end) { @@ -945,18 +945,18 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.DOUBLE); } - public Response sort(String key) { + public Response> sort(String key) { Client c = getClient(key); c.sort(key); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); + return getResponse(BuilderFactory.STRING_LIST); } - public Response sort(byte[] key) { + public Response> sort(byte[] key) { Client c = getClient(key); c.sort(key); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response> sort(String key, SortingParams sortingParameters) { @@ -966,11 +966,11 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING_LIST); } - public Response> sort(byte[] key, SortingParams sortingParameters) { + public Response> sort(byte[] key, SortingParams sortingParameters) { Client c = getClient(key); c.sort(key, sortingParameters); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response zcount(String key, double min, double max) { @@ -1001,18 +1001,18 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING_ZSET); } - public Response> zrevrangeByScore(byte[] key, double max, double min) { + public Response> zrevrangeByScore(byte[] key, double max, double min) { Client c = getClient(key); c.zrevrangeByScore(key, toByteArray(min), toByteArray(max)); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_ZSET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } - public Response> zrevrangeByScore(byte[] key, byte[] max, byte[] min) { + public Response> zrevrangeByScore(byte[] key, byte[] max, byte[] min) { Client c = getClient(key); c.zrevrangeByScore(key, min, max); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_ZSET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrevrangeByScore(String key, double max, double min, int offset, int count) { @@ -1022,18 +1022,18 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING_ZSET); } - public Response> zrevrangeByScore(byte[] key, double max, double min, int offset, int count) { + public Response> zrevrangeByScore(byte[] key, double max, double min, int offset, int count) { Client c = getClient(key); c.zrevrangeByScore(key, toByteArray(min), toByteArray(max), offset, count); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_ZSET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } - public Response> zrevrangeByScore(byte[] key, byte[] max, byte[] min, int offset, int count) { + public Response> zrevrangeByScore(byte[] key, byte[] max, byte[] min, int offset, int count) { Client c = getClient(key); c.zrevrangeByScore(key, min, max, offset, count); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_ZSET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrangeByScore(String key, String min, String max) { @@ -1050,18 +1050,18 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING_ZSET); } - public Response> zrangeByScore(byte[] key, double min, double max) { + public Response> zrangeByScore(byte[] key, double min, double max) { Client c = getClient(key); c.zrangeByScore(key, toByteArray(min), toByteArray(max)); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_ZSET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } - public Response> zrangeByScore(byte[] key, byte[] min, byte[] max) { + public Response> zrangeByScore(byte[] key, byte[] min, byte[] max) { Client c = getClient(key); c.zrangeByScore(key, min, max); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_ZSET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrangeByScore(String key, double min, double max, @@ -1072,20 +1072,20 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline return getResponse(BuilderFactory.STRING_ZSET); } - public Response> zrangeByScore(byte[] key, double min, double max, + public Response> zrangeByScore(byte[] key, double min, double max, int offset, int count) { Client c = getClient(key); c.zrangeByScore(key, toByteArray(min), toByteArray(max), offset, count); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_ZSET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } - public Response> zrangeByScore(byte[] key, byte[] min, byte[] max, + public Response> zrangeByScore(byte[] key, byte[] min, byte[] max, int offset, int count) { Client c = getClient(key); c.zrangeByScore(key, min, max, offset, count); results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_ZSET); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrangeByScoreWithScores(String key, double min, double max) { From c8ddd237c3d86920e4fb16ceef0fa0204ef7197c Mon Sep 17 00:00:00 2001 From: samhendley Date: Thu, 10 Jan 2013 01:16:54 -0500 Subject: [PATCH 091/112] extracted common Pipeline operations into PipelineBase and used that to simplify BinaryTransaction/Transaction --- .../clients/jedis/BinaryTransaction.java | 675 --------- .../java/redis/clients/jedis/Pipeline.java | 1321 +--------------- .../redis/clients/jedis/PipelineBase.java | 1322 +++++++++++++++++ .../java/redis/clients/jedis/Transaction.java | 622 +------- .../commands/TransactionCommandsTest.java | 2 +- 5 files changed, 1382 insertions(+), 2560 deletions(-) delete mode 100644 src/main/java/redis/clients/jedis/BinaryTransaction.java create mode 100644 src/main/java/redis/clients/jedis/PipelineBase.java diff --git a/src/main/java/redis/clients/jedis/BinaryTransaction.java b/src/main/java/redis/clients/jedis/BinaryTransaction.java deleted file mode 100644 index 96bdf2b..0000000 --- a/src/main/java/redis/clients/jedis/BinaryTransaction.java +++ /dev/null @@ -1,675 +0,0 @@ -package redis.clients.jedis; - -import static redis.clients.jedis.Protocol.toByteArray; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import redis.clients.jedis.BinaryClient.LIST_POSITION; -import redis.clients.jedis.exceptions.JedisDataException; - -public class BinaryTransaction extends Queable { - protected Client client = null; - protected boolean inTransaction = true; - - public BinaryTransaction() { - } - - public BinaryTransaction(final Client client) { - this.client = client; - } - - public List exec() { - client.exec(); - client.getAll(1); // Discard all but the last reply - - List unformatted = client.getObjectMultiBulkReply(); - if (unformatted == null) { - return null; - } - List formatted = new ArrayList(); - for (Object o : unformatted) { - try{ - formatted.add(generateResponse(o).get()); - }catch(JedisDataException e){ - formatted.add(e); - } - } - return formatted; - } - - public List> execGetResponse() { - client.exec(); - client.getAll(1); // Discard all but the last reply - - List unformatted = client.getObjectMultiBulkReply(); - if (unformatted == null) { - return null; - } - List> response = new ArrayList>(); - for (Object o : unformatted) { - response.add(generateResponse(o)); - } - return response; - } - - public String discard() { - client.discard(); - client.getAll(1); // Discard all but the last reply - inTransaction = false; - clean(); - return client.getStatusCodeReply(); - } - - public Response append(byte[] key, byte[] value) { - client.append(key, value); - return getResponse(BuilderFactory.LONG); - } - - public Response> blpop(byte[]... args) { - client.blpop(args); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> brpop(byte[]... args) { - client.brpop(args); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response decr(byte[] key) { - client.decr(key); - return getResponse(BuilderFactory.LONG); - } - - public Response decrBy(byte[] key, long integer) { - client.decrBy(key, integer); - return getResponse(BuilderFactory.LONG); - } - - public Response del(byte[]... keys) { - client.del(keys); - return getResponse(BuilderFactory.LONG); - } - - public Response echo(byte[] string) { - client.echo(string); - return getResponse(BuilderFactory.STRING); - } - - public Response exists(byte[] key) { - client.exists(key); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response expire(byte[] key, int seconds) { - client.expire(key, seconds); - return getResponse(BuilderFactory.LONG); - } - - public Response expireAt(byte[] key, long unixTime) { - client.expireAt(key, unixTime); - return getResponse(BuilderFactory.LONG); - } - - public Response get(byte[] key) { - client.get(key); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response getSet(byte[] key, byte[] value) { - client.getSet(key, value); - return getResponse(BuilderFactory.STRING); - } - - public Response hdel(byte[] key, byte[] field) { - client.hdel(key, field); - return getResponse(BuilderFactory.LONG); - } - - public Response hexists(byte[] key, byte[] field) { - client.hexists(key, field); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response hget(byte[] key, byte[] field) { - client.hget(key, field); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response> hgetAll(byte[] key) { - client.hgetAll(key); - return getResponse(BuilderFactory.STRING_MAP); - } - - public Response hincrBy(byte[] key, byte[] field, long value) { - client.hincrBy(key, field, value); - return getResponse(BuilderFactory.LONG); - } - - public Response> hkeys(byte[] key) { - client.hkeys(key); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response hlen(byte[] key) { - client.hlen(key); - return getResponse(BuilderFactory.LONG); - } - - public Response> hmget(byte[] key, byte[]... fields) { - client.hmget(key, fields); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response hmset(byte[] key, Map hash) { - client.hmset(key, hash); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response hset(byte[] key, byte[] field, byte[] value) { - client.hset(key, field, value); - return getResponse(BuilderFactory.LONG); - } - - public Response hsetnx(byte[] key, byte[] field, byte[] value) { - client.hsetnx(key, field, value); - return getResponse(BuilderFactory.LONG); - } - - public Response> hvals(byte[] key) { - client.hvals(key); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response incr(byte[] key) { - client.incr(key); - return getResponse(BuilderFactory.LONG); - } - - public Response incrBy(byte[] key, long integer) { - client.incrBy(key, integer); - return getResponse(BuilderFactory.LONG); - } - - public Response> keys(byte[] pattern) { - client.keys(pattern); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response lindex(byte[] key, long index) { - client.lindex(key, index); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response linsert(byte[] key, LIST_POSITION where, - byte[] pivot, byte[] value) { - client.linsert(key, where, pivot, value); - return getResponse(BuilderFactory.LONG); - } - - public Response llen(byte[] key) { - client.llen(key); - return getResponse(BuilderFactory.LONG); - } - - public Response lpop(byte[] key) { - client.lpop(key); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response lpush(byte[] key, byte[] string) { - client.lpush(key, string); - return getResponse(BuilderFactory.LONG); - } - - public Response lpushx(byte[] key, byte[] bytes) { - client.lpushx(key, bytes); - return getResponse(BuilderFactory.LONG); - } - - public Response> lrange(byte[] key, long start, long end) { - client.lrange(key, start, end); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response lrem(byte[] key, long count, byte[] value) { - client.lrem(key, count, value); - return getResponse(BuilderFactory.LONG); - } - - public Response lset(byte[] key, long index, byte[] value) { - client.lset(key, index, value); - return getResponse(BuilderFactory.STRING); - } - - public Response ltrim(byte[] key, long start, long end) { - client.ltrim(key, start, end); - return getResponse(BuilderFactory.STRING); - } - - public Response> mget(byte[]... keys) { - client.mget(keys); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response move(byte[] key, int dbIndex) { - client.move(key, dbIndex); - return getResponse(BuilderFactory.LONG); - } - - public Response mset(byte[]... keysvalues) { - client.mset(keysvalues); - return getResponse(BuilderFactory.STRING); - } - - public Response msetnx(byte[]... keysvalues) { - client.msetnx(keysvalues); - return getResponse(BuilderFactory.LONG); - } - - public Response persist(byte[] key) { - client.persist(key); - return getResponse(BuilderFactory.LONG); - } - - public Response rename(byte[] oldkey, byte[] newkey) { - client.rename(oldkey, newkey); - return getResponse(BuilderFactory.STRING); - } - - public Response renamenx(byte[] oldkey, byte[] newkey) { - client.renamenx(oldkey, newkey); - return getResponse(BuilderFactory.LONG); - } - - public Response rpop(byte[] key) { - client.rpop(key); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response rpoplpush(byte[] srckey, byte[] dstkey) { - client.rpoplpush(srckey, dstkey); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response rpush(byte[] key, byte[] string) { - client.rpush(key, string); - return getResponse(BuilderFactory.LONG); - } - - public Response rpushx(byte[] key, byte[] string) { - client.rpushx(key, string); - return getResponse(BuilderFactory.LONG); - } - - public Response sadd(byte[] key, byte[] member) { - client.sadd(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response scard(byte[] key) { - client.scard(key); - return getResponse(BuilderFactory.LONG); - } - - public Response> sdiff(byte[]... keys) { - client.sdiff(keys); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response sdiffstore(byte[] dstkey, byte[]... keys) { - client.sdiffstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); - } - - public Response set(byte[] key, byte[] value) { - client.set(key, value); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response setbit(String key, long offset, boolean value) { - client.setbit(key, offset, value); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response setex(byte[] key, int seconds, byte[] value) { - client.setex(key, seconds, value); - return getResponse(BuilderFactory.STRING); - } - - public Response setnx(byte[] key, byte[] value) { - client.setnx(key, value); - return getResponse(BuilderFactory.LONG); - } - - public Response> sinter(byte[]... keys) { - client.sinter(keys); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response sinterstore(byte[] dstkey, byte[]... keys) { - client.sinterstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); - } - - public Response sismember(byte[] key, byte[] member) { - client.sismember(key, member); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response> smembers(byte[] key) { - client.smembers(key); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response smove(byte[] srckey, byte[] dstkey, byte[] member) { - client.smove(srckey, dstkey, member); - return getResponse(BuilderFactory.LONG); - } - - public Response> sort(byte[] key) { - client.sort(key); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response> sort(byte[] key, - SortingParams sortingParameters) { - client.sort(key, sortingParameters); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response> sort(byte[] key, - SortingParams sortingParameters, byte[] dstkey) { - client.sort(key, sortingParameters, dstkey); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response> sort(byte[] key, byte[] dstkey) { - client.sort(key, dstkey); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response spop(byte[] key) { - client.spop(key); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response srandmember(byte[] key) { - client.srandmember(key); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response srem(byte[] key, byte[] member) { - client.srem(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response strlen(byte[] key) { - client.strlen(key); - return getResponse(BuilderFactory.LONG); - } - - public Response substr(byte[] key, int start, int end) { // what's - // that? - client.substr(key, start, end); - return getResponse(BuilderFactory.STRING); - } - - public Response> sunion(byte[]... keys) { - client.sunion(keys); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response sunionstore(byte[] dstkey, byte[]... keys) { - client.sunionstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); - } - - public Response ttl(byte[] key) { - client.ttl(key); - return getResponse(BuilderFactory.LONG); - } - - public Response type(byte[] key) { - client.type(key); - return getResponse(BuilderFactory.STRING); - } - - public Response zadd(byte[] key, double score, byte[] member) { - client.zadd(key, score, member); - return getResponse(BuilderFactory.LONG); - } - - public Response zcard(byte[] key) { - client.zcard(key); - return getResponse(BuilderFactory.LONG); - } - - public Response zcount(byte[] key, double min, double max) { - return zcount(key, toByteArray(min), toByteArray(max)); - } - - public Response zcount(byte[] key, byte[] min, byte[] max) { - client.zcount(key, min, max); - return getResponse(BuilderFactory.LONG); - } - - public Response zincrby(byte[] key, double score, byte[] member) { - client.zincrby(key, score, member); - return getResponse(BuilderFactory.DOUBLE); - } - - public Response zinterstore(byte[] dstkey, byte[]... sets) { - client.zinterstore(dstkey, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response zinterstore(byte[] dstkey, ZParams params, - byte[]... sets) { - client.zinterstore(dstkey, params, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response> zrange(byte[] key, int start, int end) { - client.zrange(key, start, end); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrangeByScore(byte[] key, double min, - double max) { - return zrangeByScore(key, toByteArray(min), toByteArray(max)); - } - - public Response> zrangeByScore(byte[] key, byte[] min, - byte[] max) { - client.zrangeByScore(key, min, max); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrangeByScore(byte[] key, byte[] min, - byte[] max, int offset, int count) { - client.zrangeByScore(key, min, max, offset, count); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrangeByScore(byte[] key, double min, - double max, int offset, int count) { - return zrangeByScore(key, toByteArray(min), toByteArray(max), offset, count); - } - - public Response> zrangeByScoreWithScores(byte[] key, double min, - double max) { - return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max)); - } - - public Response> zrangeByScoreWithScores(byte[] key, double min, - double max, int offset, int count) { - return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count); - } - - public Response> zrangeByScoreWithScores(byte[] key, byte[] min, - byte[] max) { - client.zrangeByScoreWithScores(key, min, max); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); - } - - public Response> zrangeByScoreWithScores(byte[] key, byte[] min, - byte[] max, int offset, int count) { - client.zrangeByScoreWithScores(key, min, max, offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); - } - - public Response> zrangeWithScores(byte[] key, int start, int end) { - client.zrangeWithScores(key, start, end); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); - } - - public Response zrank(byte[] key, byte[] member) { - client.zrank(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response zrem(byte[] key, byte[] member) { - client.zrem(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response zremrangeByRank(byte[] key, int start, int end) { - client.zremrangeByRank(key, start, end); - return getResponse(BuilderFactory.LONG); - } - - public Response zremrangeByScore(byte[] key, double start, double end) { - return zremrangeByScore(key, toByteArray(start), toByteArray(end)); - } - - public Response zremrangeByScore(byte[] key, byte[] start, byte[] end) { - client.zremrangeByScore(key, start, end); - return getResponse(BuilderFactory.LONG); - } - - public Response> zrevrange(byte[] key, int start, int end) { - client.zrevrange(key, start, end); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrevrangeWithScores(byte[] key, int start, - int end) { - client.zrevrangeWithScores(key, start, end); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); - } - - public Response zrevrank(byte[] key, byte[] member) { - client.zrevrank(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response zscore(byte[] key, byte[] member) { - client.zscore(key, member); - return getResponse(BuilderFactory.DOUBLE); - } - - public Response zunionstore(byte[] dstkey, byte[]... sets) { - client.zunionstore(dstkey, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response zunionstore(byte[] dstkey, ZParams params, - byte[]... sets) { - client.zunionstore(dstkey, params, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response brpoplpush(byte[] source, byte[] destination, - int timeout) { - client.brpoplpush(source, destination, timeout); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response select(final int index) { - client.select(index); - return getResponse(BuilderFactory.STRING); - } - - public Response flushDB() { - client.flushDB(); - return getResponse(BuilderFactory.STRING); - } - - public Response flushAll() { - client.flushAll(); - return getResponse(BuilderFactory.STRING); - } - - public Response save() { - client.save(); - return getResponse(BuilderFactory.STRING); - } - - public Response info() { - client.info(); - return getResponse(BuilderFactory.STRING); - } - - public Response lastsave() { - client.lastsave(); - return getResponse(BuilderFactory.LONG); - } - - public Response dbSize() { - client.dbSize(); - return getResponse(BuilderFactory.LONG); - } - - public Response> configGet(final byte[] pattern) { - client.configGet(pattern); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response configSet(final byte[] parameter, final byte[] value) { - client.configSet(parameter, value); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response configResetStat() { - client.configResetStat(); - return getResponse(BuilderFactory.STRING); - } - - public Response shutdown() { - client.shutdown(); - return getResponse(BuilderFactory.STRING); - } - - public Response getbit(final byte[] key, final long offset) { - client.getbit(key, offset); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response setbit(final byte[] key, final long offset, final byte[] value) { - client.setbit(key, offset, value); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response ping() { - client.ping(); - return getResponse(BuilderFactory.STRING); - } - - public Response setrange(byte[] key, long offset, byte[] value) { - client.setrange(key, offset, value); - return getResponse(BuilderFactory.LONG); - } - - public Response randomKey() { - client.randomKey(); - return getResponse(BuilderFactory.STRING); - } - - public Response publish(byte[] channel, byte[] message) { - client.publish(channel, message); - return getResponse(BuilderFactory.LONG); - } -} \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index d605f25..cf61066 100755 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -1,20 +1,11 @@ package redis.clients.jedis; -import static redis.clients.jedis.Protocol.toByteArray; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import redis.clients.jedis.BinaryClient.LIST_POSITION; import redis.clients.jedis.exceptions.JedisDataException; -public class Pipeline extends Queable implements - BasicRedisPipeline, - BinaryRedisPipeline, - RedisPipeline, - MultiKeyBinaryRedisPipeline, - MultiKeyCommandsPipeline { +import java.util.ArrayList; +import java.util.List; + +public class Pipeline extends PipelineBase { private MultiResponseBuilder currentMulti; @@ -57,9 +48,7 @@ public class Pipeline extends Queable implements return super.getResponse(builder); } } - - private Client client; - + public void setClient(Client client) { this.client = client; } @@ -100,1222 +89,6 @@ public class Pipeline extends Queable implements return formatted; } - public Response append(String key, String value) { - client.append(key, value); - return getResponse(BuilderFactory.LONG); - } - - public Response append(byte[] key, byte[] value) { - client.append(key, value); - return getResponse(BuilderFactory.LONG); - } - - public Response> blpop(String arg) { - String[] temp = new String[1]; - temp[0] = arg; - client.blpop(temp); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> brpop(String arg) { - String[] temp = new String[1]; - temp[0] = arg; - client.brpop(temp); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> blpop(byte[] arg) { - byte[][] temp = new byte[1][]; - temp[0] = arg; - client.blpop(temp); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response> brpop(byte[] arg) { - byte[][] temp = new byte[1][]; - temp[0] = arg; - client.brpop(temp); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response> blpop(String... args) { - client.blpop(args); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> blpop(byte[]... args) { - client.blpop(args); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response> brpop(String... args) { - client.brpop(args); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> brpop(byte[]... args) { - client.brpop(args); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response decr(String key) { - client.decr(key); - return getResponse(BuilderFactory.LONG); - } - - public Response decr(byte[] key) { - client.decr(key); - return getResponse(BuilderFactory.LONG); - } - - public Response decrBy(String key, long integer) { - client.decrBy(key, integer); - return getResponse(BuilderFactory.LONG); - } - - public Response decrBy(byte[] key, long integer) { - client.decrBy(key, integer); - return getResponse(BuilderFactory.LONG); - } - - public Response del(String key) { - client.del(key); - return getResponse(BuilderFactory.LONG); - } - - public Response del(String... keys) { - client.del(keys); - return getResponse(BuilderFactory.LONG); - } - - public Response del(byte[] key) { - client.del(key); - return getResponse(BuilderFactory.LONG); - } - - public Response del(byte[]... keys) { - client.del(keys); - return getResponse(BuilderFactory.LONG); - } - - public Response echo(String string) { - client.echo(string); - return getResponse(BuilderFactory.STRING); - } - - public Response echo(byte[] string) { - client.echo(string); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response exists(String key) { - client.exists(key); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response exists(byte[] key) { - client.exists(key); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response expire(String key, int seconds) { - client.expire(key, seconds); - return getResponse(BuilderFactory.LONG); - } - - public Response expire(byte[] key, int seconds) { - client.expire(key, seconds); - return getResponse(BuilderFactory.LONG); - } - - public Response expireAt(String key, long unixTime) { - client.expireAt(key, unixTime); - return getResponse(BuilderFactory.LONG); - } - - public Response expireAt(byte[] key, long unixTime) { - client.expireAt(key, unixTime); - return getResponse(BuilderFactory.LONG); - } - - public Response get(String key) { - client.get(key); - return getResponse(BuilderFactory.STRING); - } - - public Response get(byte[] key) { - client.get(key); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response getbit(String key, long offset) { - client.getbit(key, offset); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response getbit(byte[] key, long offset) { - client.getbit(key, offset); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response getrange(String key, long startOffset, - long endOffset) { - client.getrange(key, startOffset, endOffset); - return getResponse(BuilderFactory.STRING); - } - - public Response getSet(String key, String value) { - client.getSet(key, value); - return getResponse(BuilderFactory.STRING); - } - - public Response getSet(byte[] key, byte[] value) { - client.getSet(key, value); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response getrange(byte[] key, long startOffset, long endOffset) { - client.getrange(key, startOffset, endOffset); - return getResponse(BuilderFactory.LONG); - } - - public Response hdel(String key, String field) { - client.hdel(key, field); - return getResponse(BuilderFactory.LONG); - } - - public Response hdel(byte[] key, byte[] field) { - client.hdel(key, field); - return getResponse(BuilderFactory.LONG); - } - - public Response hexists(String key, String field) { - client.hexists(key, field); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response hexists(byte[] key, byte[] field) { - client.hexists(key, field); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response hget(String key, String field) { - client.hget(key, field); - return getResponse(BuilderFactory.STRING); - } - - public Response hget(byte[] key, byte[] field) { - client.hget(key, field); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response> hgetAll(String key) { - client.hgetAll(key); - return getResponse(BuilderFactory.STRING_MAP); - } - - public Response> hgetAll(byte[] key) { - client.hgetAll(key); - return getResponse(BuilderFactory.BYTE_ARRAY_MAP); - } - - public Response hincrBy(String key, String field, long value) { - client.hincrBy(key, field, value); - return getResponse(BuilderFactory.LONG); - } - - public Response hincrBy(byte[] key, byte[] field, long value) { - client.hincrBy(key, field, value); - return getResponse(BuilderFactory.LONG); - } - - public Response> hkeys(String key) { - client.hkeys(key); - return getResponse(BuilderFactory.STRING_SET); - } - - public Response> hkeys(byte[] key) { - client.hkeys(key); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response hlen(String key) { - client.hlen(key); - return getResponse(BuilderFactory.LONG); - } - - public Response hlen(byte[] key) { - client.hlen(key); - return getResponse(BuilderFactory.LONG); - } - - public Response> hmget(String key, String... fields) { - client.hmget(key, fields); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> hmget(byte[] key, byte[]... fields) { - client.hmget(key, fields); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response hmset(String key, Map hash) { - client.hmset(key, hash); - return getResponse(BuilderFactory.STRING); - } - - public Response hmset(byte[] key, Map hash) { - client.hmset(key, hash); - return getResponse(BuilderFactory.STRING); - } - - public Response hset(String key, String field, String value) { - client.hset(key, field, value); - return getResponse(BuilderFactory.LONG); - } - - public Response hset(byte[] key, byte[] field, byte[] value) { - client.hset(key, field, value); - return getResponse(BuilderFactory.LONG); - } - - public Response hsetnx(String key, String field, String value) { - client.hsetnx(key, field, value); - return getResponse(BuilderFactory.LONG); - } - - public Response hsetnx(byte[] key, byte[] field, byte[] value) { - client.hsetnx(key, field, value); - return getResponse(BuilderFactory.LONG); - } - - public Response> hvals(String key) { - client.hvals(key); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> hvals(byte[] key) { - client.hvals(key); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response incr(String key) { - client.incr(key); - return getResponse(BuilderFactory.LONG); - } - - public Response incr(byte[] key) { - client.incr(key); - return getResponse(BuilderFactory.LONG); - } - - public Response incrBy(String key, long integer) { - client.incrBy(key, integer); - return getResponse(BuilderFactory.LONG); - } - - public Response incrBy(byte[] key, long integer) { - client.incrBy(key, integer); - return getResponse(BuilderFactory.LONG); - } - - public Response> keys(String pattern) { - client.keys(pattern); - return getResponse(BuilderFactory.STRING_SET); - } - - public Response> keys(byte[] pattern) { - client.keys(pattern); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response lindex(String key, int index) { - client.lindex(key, index); - return getResponse(BuilderFactory.STRING); - } - - public Response lindex(byte[] key, int index) { - client.lindex(key, index); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response linsert(String key, LIST_POSITION where, - String pivot, String value) { - client.linsert(key, where, pivot, value); - return getResponse(BuilderFactory.LONG); - } - - public Response linsert(byte[] key, LIST_POSITION where, - byte[] pivot, byte[] value) { - client.linsert(key, where, pivot, value); - return getResponse(BuilderFactory.LONG); - } - - public Response llen(String key) { - client.llen(key); - return getResponse(BuilderFactory.LONG); - } - - public Response llen(byte[] key) { - client.llen(key); - return getResponse(BuilderFactory.LONG); - } - - public Response lpop(String key) { - client.lpop(key); - return getResponse(BuilderFactory.STRING); - } - - public Response lpop(byte[] key) { - client.lpop(key); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response lpush(String key, String string) { - client.lpush(key, string); - return getResponse(BuilderFactory.LONG); - } - - public Response lpush(byte[] key, byte[] string) { - client.lpush(key, string); - return getResponse(BuilderFactory.LONG); - } - - public Response lpushx(String key, String string) { - client.lpushx(key, string); - return getResponse(BuilderFactory.LONG); - } - - public Response lpushx(byte[] key, byte[] bytes) { - client.lpushx(key, bytes); - return getResponse(BuilderFactory.LONG); - } - - public Response> lrange(String key, long start, long end) { - client.lrange(key, start, end); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> lrange(byte[] key, long start, long end) { - client.lrange(key, start, end); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response lrem(String key, long count, String value) { - client.lrem(key, count, value); - return getResponse(BuilderFactory.LONG); - } - - public Response lrem(byte[] key, long count, byte[] value) { - client.lrem(key, count, value); - return getResponse(BuilderFactory.LONG); - } - - public Response lset(String key, long index, String value) { - client.lset(key, index, value); - return getResponse(BuilderFactory.STRING); - } - - public Response lset(byte[] key, long index, byte[] value) { - client.lset(key, index, value); - return getResponse(BuilderFactory.STRING); - } - - public Response ltrim(String key, long start, long end) { - client.ltrim(key, start, end); - return getResponse(BuilderFactory.STRING); - } - - public Response ltrim(byte[] key, long start, long end) { - client.ltrim(key, start, end); - return getResponse(BuilderFactory.STRING); - } - - public Response> mget(String... keys) { - client.mget(keys); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> mget(byte[]... keys) { - client.mget(keys); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response move(String key, int dbIndex) { - client.move(key, dbIndex); - return getResponse(BuilderFactory.LONG); - } - - public Response move(byte[] key, int dbIndex) { - client.move(key, dbIndex); - return getResponse(BuilderFactory.LONG); - } - - public Response mset(String... keysvalues) { - client.mset(keysvalues); - return getResponse(BuilderFactory.STRING); - } - - public Response mset(byte[]... keysvalues) { - client.mset(keysvalues); - return getResponse(BuilderFactory.STRING); - } - - public Response msetnx(String... keysvalues) { - client.msetnx(keysvalues); - return getResponse(BuilderFactory.LONG); - } - - public Response msetnx(byte[]... keysvalues) { - client.msetnx(keysvalues); - return getResponse(BuilderFactory.LONG); - } - - public Response persist(String key) { - client.persist(key); - return getResponse(BuilderFactory.LONG); - } - - public Response persist(byte[] key) { - client.persist(key); - return getResponse(BuilderFactory.LONG); - } - - public Response rename(String oldkey, String newkey) { - client.rename(oldkey, newkey); - return getResponse(BuilderFactory.STRING); - } - - public Response rename(byte[] oldkey, byte[] newkey) { - client.rename(oldkey, newkey); - return getResponse(BuilderFactory.STRING); - } - - public Response renamenx(String oldkey, String newkey) { - client.renamenx(oldkey, newkey); - return getResponse(BuilderFactory.LONG); - } - - public Response renamenx(byte[] oldkey, byte[] newkey) { - client.renamenx(oldkey, newkey); - return getResponse(BuilderFactory.LONG); - } - - public Response rpop(String key) { - client.rpop(key); - return getResponse(BuilderFactory.STRING); - } - - public Response rpop(byte[] key) { - client.rpop(key); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response rpoplpush(String srckey, String dstkey) { - client.rpoplpush(srckey, dstkey); - return getResponse(BuilderFactory.STRING); - } - - public Response rpoplpush(byte[] srckey, byte[] dstkey) { - client.rpoplpush(srckey, dstkey); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response rpush(String key, String string) { - client.rpush(key, string); - return getResponse(BuilderFactory.LONG); - } - - public Response rpush(byte[] key, byte[] string) { - client.rpush(key, string); - return getResponse(BuilderFactory.LONG); - } - - public Response rpushx(String key, String string) { - client.rpushx(key, string); - return getResponse(BuilderFactory.LONG); - } - - public Response rpushx(byte[] key, byte[] string) { - client.rpushx(key, string); - return getResponse(BuilderFactory.LONG); - } - - public Response sadd(String key, String member) { - client.sadd(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response sadd(byte[] key, byte[] member) { - client.sadd(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response scard(String key) { - client.scard(key); - return getResponse(BuilderFactory.LONG); - } - - public Response scard(byte[] key) { - client.scard(key); - return getResponse(BuilderFactory.LONG); - } - - public Response> sdiff(String... keys) { - client.sdiff(keys); - return getResponse(BuilderFactory.STRING_SET); - } - - public Response> sdiff(byte[]... keys) { - client.sdiff(keys); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response sdiffstore(String dstkey, String... keys) { - client.sdiffstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); - } - - public Response sdiffstore(byte[] dstkey, byte[]... keys) { - client.sdiffstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); - } - - public Response set(String key, String value) { - client.set(key, value); - return getResponse(BuilderFactory.STRING); - } - - public Response set(byte[] key, byte[] value) { - client.set(key, value); - return getResponse(BuilderFactory.STRING); - } - - public Response setbit(String key, long offset, boolean value) { - client.setbit(key, offset, value); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response setbit(byte[] key, long offset, byte[] value) { - client.setbit(key, offset, value); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response setex(String key, int seconds, String value) { - client.setex(key, seconds, value); - return getResponse(BuilderFactory.STRING); - } - - public Response setex(byte[] key, int seconds, byte[] value) { - client.setex(key, seconds, value); - return getResponse(BuilderFactory.STRING); - } - - public Response setnx(String key, String value) { - client.setnx(key, value); - return getResponse(BuilderFactory.LONG); - } - - public Response setnx(byte[] key, byte[] value) { - client.setnx(key, value); - return getResponse(BuilderFactory.LONG); - } - - public Response setrange(String key, long offset, String value) { - client.setrange(key, offset, value); - return getResponse(BuilderFactory.LONG); - } - - public Response setrange(byte[] key, long offset, byte[] value) { - client.setrange(key, offset, value); - return getResponse(BuilderFactory.LONG); - } - - public Response> sinter(String... keys) { - client.sinter(keys); - return getResponse(BuilderFactory.STRING_SET); - } - - public Response> sinter(byte[]... keys) { - client.sinter(keys); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response sinterstore(String dstkey, String... keys) { - client.sinterstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); - } - - public Response sinterstore(byte[] dstkey, byte[]... keys) { - client.sinterstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); - } - - public Response sismember(String key, String member) { - client.sismember(key, member); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response sismember(byte[] key, byte[] member) { - client.sismember(key, member); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response> smembers(String key) { - client.smembers(key); - return getResponse(BuilderFactory.STRING_SET); - } - - public Response> smembers(byte[] key) { - client.smembers(key); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response smove(String srckey, String dstkey, String member) { - client.smove(srckey, dstkey, member); - return getResponse(BuilderFactory.LONG); - } - - public Response smove(byte[] srckey, byte[] dstkey, byte[] member) { - client.smove(srckey, dstkey, member); - return getResponse(BuilderFactory.LONG); - } - - public Response> sort(String key) { - client.sort(key); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> sort(byte[] key) { - client.sort(key); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response> sort(String key, - SortingParams sortingParameters) { - client.sort(key, sortingParameters); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> sort(byte[] key, - SortingParams sortingParameters) { - client.sort(key, sortingParameters); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response> sort(String key, - SortingParams sortingParameters, String dstkey) { - client.sort(key, sortingParameters, dstkey); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> sort(byte[] key, - SortingParams sortingParameters, byte[] dstkey) { - client.sort(key, sortingParameters, dstkey); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response> sort(String key, String dstkey) { - client.sort(key, dstkey); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> sort(byte[] key, byte[] dstkey) { - client.sort(key, dstkey); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response spop(String key) { - client.spop(key); - return getResponse(BuilderFactory.STRING); - } - - public Response spop(byte[] key) { - client.spop(key); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response srandmember(String key) { - client.srandmember(key); - return getResponse(BuilderFactory.STRING); - } - - public Response srandmember(byte[] key) { - client.srandmember(key); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response srem(String key, String member) { - client.srem(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response srem(byte[] key, byte[] member) { - client.srem(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response strlen(String key) { - client.strlen(key); - return getResponse(BuilderFactory.LONG); - } - - public Response strlen(byte[] key) { - client.strlen(key); - return getResponse(BuilderFactory.LONG); - } - - public Response substr(String key, int start, int end) { - client.substr(key, start, end); - return getResponse(BuilderFactory.STRING); - } - - public Response substr(byte[] key, int start, int end) { - client.substr(key, start, end); - return getResponse(BuilderFactory.STRING); - } - - public Response> sunion(String... keys) { - client.sunion(keys); - return getResponse(BuilderFactory.STRING_SET); - } - - public Response> sunion(byte[]... keys) { - client.sunion(keys); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response sunionstore(String dstkey, String... keys) { - client.sunionstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); - } - - public Response sunionstore(byte[] dstkey, byte[]... keys) { - client.sunionstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); - } - - public Response ttl(String key) { - client.ttl(key); - return getResponse(BuilderFactory.LONG); - } - - public Response ttl(byte[] key) { - client.ttl(key); - return getResponse(BuilderFactory.LONG); - } - - public Response type(String key) { - client.type(key); - return getResponse(BuilderFactory.STRING); - } - - public Response type(byte[] key) { - client.type(key); - return getResponse(BuilderFactory.STRING); - } - - public Response watch(String... keys) { - client.watch(keys); - return getResponse(BuilderFactory.STRING); - } - - public Response watch(byte[]... keys) { - client.watch(keys); - return getResponse(BuilderFactory.STRING); - } - - public Response zadd(String key, double score, String member) { - client.zadd(key, score, member); - return getResponse(BuilderFactory.LONG); - } - - public Response zadd(byte[] key, double score, byte[] member) { - client.zadd(key, score, member); - return getResponse(BuilderFactory.LONG); - } - - public Response zcard(String key) { - client.zcard(key); - return getResponse(BuilderFactory.LONG); - } - - public Response zcard(byte[] key) { - client.zcard(key); - return getResponse(BuilderFactory.LONG); - } - - public Response zcount(String key, double min, double max) { - client.zcount(key, min, max); - return getResponse(BuilderFactory.LONG); - } - - public Response zcount(byte[] key, double min, double max) { - client.zcount(key, toByteArray(min), toByteArray(max)); - return getResponse(BuilderFactory.LONG); - } - - public Response zincrby(String key, double score, String member) { - client.zincrby(key, score, member); - return getResponse(BuilderFactory.DOUBLE); - } - - public Response zincrby(byte[] key, double score, byte[] member) { - client.zincrby(key, score, member); - return getResponse(BuilderFactory.DOUBLE); - } - - public Response zinterstore(String dstkey, String... sets) { - client.zinterstore(dstkey, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response zinterstore(byte[] dstkey, byte[]... sets) { - client.zinterstore(dstkey, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response zinterstore(String dstkey, ZParams params, - String... sets) { - client.zinterstore(dstkey, params, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response zinterstore(byte[] dstkey, ZParams params, - byte[]... sets) { - client.zinterstore(dstkey, params, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response> zrange(String key, int start, int end) { - client.zrange(key, start, end); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrange(byte[] key, int start, int end) { - client.zrange(key, start, end); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrangeByScore(String key, double min, - double max) { - client.zrangeByScore(key, min, max); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrangeByScore(byte[] key, double min, - double max) { - return zrangeByScore(key, toByteArray(min), toByteArray(max)); - } - - public Response> zrangeByScore(String key, String min, - String max) { - client.zrangeByScore(key, min, max); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrangeByScore(byte[] key, byte[] min, - byte[] max) { - client.zrangeByScore(key, min, max); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrangeByScore(String key, double min, - double max, int offset, int count) { - client.zrangeByScore(key, min, max, offset, count); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrangeByScore(byte[] key, double min, - double max, int offset, int count) { - return zrangeByScore(key, toByteArray(min), toByteArray(max), offset, count); - } - - public Response> zrangeByScore(byte[] key, byte[] min, - byte[] max, int offset, int count) { - client.zrangeByScore(key, min, max, offset, count); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrangeByScoreWithScores(String key, double min, - double max) { - client.zrangeByScoreWithScores(key, min, max); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrangeByScoreWithScores(byte[] key, double min, - double max) { - return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max)); - } - - public Response> zrangeByScoreWithScores(byte[] key, byte[] min, - byte[] max) { - client.zrangeByScoreWithScores(key, min, max); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); - } - - public Response> zrangeByScoreWithScores(String key, double min, - double max, int offset, int count) { - client.zrangeByScoreWithScores(key, min, max, offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrangeByScoreWithScores(byte[] key, double min, - double max, int offset, int count) { - client.zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); - } - - public Response> zrangeByScoreWithScores(byte[] key, byte[] min, - byte[] max, int offset, int count) { - client.zrangeByScoreWithScores(key, min, max, offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); - } - - public Response> zrevrangeByScore(String key, double max, - double min) { - client.zrevrangeByScore(key, max, min); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrevrangeByScore(byte[] key, double max, - double min) { - client.zrevrangeByScore(key, toByteArray(max), toByteArray(min)); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrevrangeByScore(String key, String max, - String min) { - client.zrevrangeByScore(key, max, min); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrevrangeByScore(byte[] key, byte[] max, - byte[] min) { - client.zrevrangeByScore(key, max, min); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrevrangeByScore(String key, double max, - double min, int offset, int count) { - client.zrevrangeByScore(key, max, min, offset, count); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrevrangeByScore(byte[] key, double max, - double min, int offset, int count) { - client.zrevrangeByScore(key, toByteArray(max), toByteArray(min), offset, count); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrevrangeByScore(byte[] key, byte[] max, - byte[] min, int offset, int count) { - client.zrevrangeByScore(key, max, min, offset, count); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrevrangeByScoreWithScores(String key, - double max, double min) { - client.zrevrangeByScoreWithScores(key, max, min); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrevrangeByScoreWithScores(byte[] key, - double max, double min) { - client.zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min)); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); - } - - public Response> zrevrangeByScoreWithScores(byte[] key, - byte[] max, byte[] min) { - client.zrevrangeByScoreWithScores(key, max, min); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); - } - - public Response> zrevrangeByScoreWithScores(String key, - double max, double min, int offset, int count) { - client.zrevrangeByScoreWithScores(key, max, min, offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrevrangeByScoreWithScores(byte[] key, - double max, double min, int offset, int count) { - client.zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min), offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); - } - - public Response> zrevrangeByScoreWithScores(byte[] key, - byte[] max, byte[] min, int offset, int count) { - client.zrevrangeByScoreWithScores(key, max, min, offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); - } - - public Response> zrangeWithScores(String key, int start, int end) { - client.zrangeWithScores(key, start, end); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrangeWithScores(byte[] key, int start, int end) { - client.zrangeWithScores(key, start, end); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); - } - - public Response zrank(String key, String member) { - client.zrank(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response zrank(byte[] key, byte[] member) { - client.zrank(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response zrem(String key, String member) { - client.zrem(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response zrem(byte[] key, byte[] member) { - client.zrem(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response zremrangeByRank(String key, int start, int end) { - client.zremrangeByRank(key, start, end); - return getResponse(BuilderFactory.LONG); - } - - public Response zremrangeByRank(byte[] key, int start, int end) { - client.zremrangeByRank(key, start, end); - return getResponse(BuilderFactory.LONG); - } - - public Response zremrangeByScore(String key, double start, double end) { - client.zremrangeByScore(key, start, end); - return getResponse(BuilderFactory.LONG); - } - - public Response zremrangeByScore(byte[] key, double start, double end) { - client.zremrangeByScore(key, toByteArray(start), toByteArray(end)); - return getResponse(BuilderFactory.LONG); - } - - public Response zremrangeByScore(byte[] key, byte[] start, byte[] end) { - client.zremrangeByScore(key, start, end); - return getResponse(BuilderFactory.LONG); - } - - public Response> zrevrange(String key, int start, int end) { - client.zrevrange(key, start, end); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrevrange(byte[] key, int start, int end) { - client.zrevrange(key, start, end); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrevrangeWithScores(String key, int start, - int end) { - client.zrevrangeWithScores(key, start, end); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrevrangeWithScores(byte[] key, int start, - int end) { - client.zrevrangeWithScores(key, start, end); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response zrevrank(String key, String member) { - client.zrevrank(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response zrevrank(byte[] key, byte[] member) { - client.zrevrank(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response zscore(String key, String member) { - client.zscore(key, member); - return getResponse(BuilderFactory.DOUBLE); - } - - public Response zscore(byte[] key, byte[] member) { - client.zscore(key, member); - return getResponse(BuilderFactory.DOUBLE); - } - - public Response zunionstore(String dstkey, String... sets) { - client.zunionstore(dstkey, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response zunionstore(byte[] dstkey, byte[]... sets) { - client.zunionstore(dstkey, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response zunionstore(String dstkey, ZParams params, - String... sets) { - client.zunionstore(dstkey, params, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response zunionstore(byte[] dstkey, ZParams params, - byte[]... sets) { - client.zunionstore(dstkey, params, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response bgrewriteaof() { - client.bgrewriteaof(); - return getResponse(BuilderFactory.STRING); - } - - public Response bgsave() { - client.bgsave(); - return getResponse(BuilderFactory.STRING); - } - - public Response configGet(String pattern) { - client.configGet(pattern); - return getResponse(BuilderFactory.STRING); - } - - public Response configSet(String parameter, String value) { - client.configSet(parameter, value); - return getResponse(BuilderFactory.STRING); - } - - public Response brpoplpush(String source, String destination, - int timeout) { - client.brpoplpush(source, destination, timeout); - return getResponse(BuilderFactory.STRING); - } - - public Response brpoplpush(byte[] source, byte[] destination, - int timeout) { - client.brpoplpush(source, destination, timeout); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response configResetStat() { - client.configResetStat(); - return getResponse(BuilderFactory.STRING); - } - - public Response save() { - client.save(); - return getResponse(BuilderFactory.STRING); - } - - public Response lastsave() { - client.lastsave(); - return getResponse(BuilderFactory.LONG); - } - public Response discard() { client.discard(); return getResponse(BuilderFactory.STRING); @@ -1335,88 +108,4 @@ public class Pipeline extends Queable implements return response; } - public Response publish(String channel, String message) { - client.publish(channel, message); - return getResponse(BuilderFactory.LONG); - } - - public Response publish(byte[] channel, byte[] message) { - client.publish(channel, message); - return getResponse(BuilderFactory.LONG); - } - - public Response randomKey() { - client.randomKey(); - return getResponse(BuilderFactory.STRING); - } - - public Response randomKeyBinary() { - client.randomKey(); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response flushDB() { - client.flushDB(); - return getResponse(BuilderFactory.STRING); - } - - public Response flushAll() { - client.flushAll(); - return getResponse(BuilderFactory.STRING); - } - - public Response info() { - client.info(); - return getResponse(BuilderFactory.STRING); - } - - public Response dbSize() { - client.dbSize(); - return getResponse(BuilderFactory.LONG); - } - - public Response shutdown() { - client.shutdown(); - return getResponse(BuilderFactory.STRING); - } - - public Response ping() { - client.ping(); - return getResponse(BuilderFactory.STRING); - } - - public Response select(int index){ - client.select(index); - return getResponse(BuilderFactory.STRING); - } - - public Response bitcount(String key) { - client.bitcount(key); - return getResponse(BuilderFactory.LONG); - } - - public Response bitcount(String key, long start, long end) { - client.bitcount(key, start, end); - return getResponse(BuilderFactory.LONG); - } - - public Response bitcount(byte[] key) { - client.bitcount(key); - return getResponse(BuilderFactory.LONG); - } - - public Response bitcount(byte[] key, long start, long end) { - client.bitcount(key, start, end); - return getResponse(BuilderFactory.LONG); - } - - public Response bitop(BitOP op, byte[] destKey, byte[]... srcKeys) { - client.bitop(op, destKey, srcKeys); - return getResponse(BuilderFactory.LONG); - } - - public Response bitop(BitOP op, String destKey, String... srcKeys) { - client.bitop(op, destKey, srcKeys); - return getResponse(BuilderFactory.LONG); - } } diff --git a/src/main/java/redis/clients/jedis/PipelineBase.java b/src/main/java/redis/clients/jedis/PipelineBase.java new file mode 100644 index 0000000..b8fdefd --- /dev/null +++ b/src/main/java/redis/clients/jedis/PipelineBase.java @@ -0,0 +1,1322 @@ +package redis.clients.jedis; + +import static redis.clients.jedis.Protocol.toByteArray; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import redis.clients.jedis.BinaryClient.LIST_POSITION; +import redis.clients.jedis.exceptions.JedisDataException; + +abstract class PipelineBase extends Queable implements + BasicRedisPipeline, + BinaryRedisPipeline, + RedisPipeline, + MultiKeyBinaryRedisPipeline, + MultiKeyCommandsPipeline { + + protected Client client; + + public Response append(String key, String value) { + client.append(key, value); + return getResponse(BuilderFactory.LONG); + } + + public Response append(byte[] key, byte[] value) { + client.append(key, value); + return getResponse(BuilderFactory.LONG); + } + + public Response> blpop(String arg) { + String[] temp = new String[1]; + temp[0] = arg; + client.blpop(temp); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> brpop(String arg) { + String[] temp = new String[1]; + temp[0] = arg; + client.brpop(temp); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> blpop(byte[] arg) { + byte[][] temp = new byte[1][]; + temp[0] = arg; + client.blpop(temp); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response> brpop(byte[] arg) { + byte[][] temp = new byte[1][]; + temp[0] = arg; + client.brpop(temp); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response> blpop(String... args) { + client.blpop(args); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> blpop(byte[]... args) { + client.blpop(args); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response> brpop(String... args) { + client.brpop(args); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> brpop(byte[]... args) { + client.brpop(args); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response decr(String key) { + client.decr(key); + return getResponse(BuilderFactory.LONG); + } + + public Response decr(byte[] key) { + client.decr(key); + return getResponse(BuilderFactory.LONG); + } + + public Response decrBy(String key, long integer) { + client.decrBy(key, integer); + return getResponse(BuilderFactory.LONG); + } + + public Response decrBy(byte[] key, long integer) { + client.decrBy(key, integer); + return getResponse(BuilderFactory.LONG); + } + + public Response del(String key) { + client.del(key); + return getResponse(BuilderFactory.LONG); + } + + public Response del(String... keys) { + client.del(keys); + return getResponse(BuilderFactory.LONG); + } + + public Response del(byte[] key) { + client.del(key); + return getResponse(BuilderFactory.LONG); + } + + public Response del(byte[]... keys) { + client.del(keys); + return getResponse(BuilderFactory.LONG); + } + + public Response echo(String string) { + client.echo(string); + return getResponse(BuilderFactory.STRING); + } + + public Response echo(byte[] string) { + client.echo(string); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response exists(String key) { + client.exists(key); + return getResponse(BuilderFactory.BOOLEAN); + } + + public Response exists(byte[] key) { + client.exists(key); + return getResponse(BuilderFactory.BOOLEAN); + } + + public Response expire(String key, int seconds) { + client.expire(key, seconds); + return getResponse(BuilderFactory.LONG); + } + + public Response expire(byte[] key, int seconds) { + client.expire(key, seconds); + return getResponse(BuilderFactory.LONG); + } + + public Response expireAt(String key, long unixTime) { + client.expireAt(key, unixTime); + return getResponse(BuilderFactory.LONG); + } + + public Response expireAt(byte[] key, long unixTime) { + client.expireAt(key, unixTime); + return getResponse(BuilderFactory.LONG); + } + + public Response get(String key) { + client.get(key); + return getResponse(BuilderFactory.STRING); + } + + public Response get(byte[] key) { + client.get(key); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response getbit(String key, long offset) { + client.getbit(key, offset); + return getResponse(BuilderFactory.BOOLEAN); + } + + public Response getbit(byte[] key, long offset) { + client.getbit(key, offset); + return getResponse(BuilderFactory.BOOLEAN); + } + + public Response getrange(String key, long startOffset, + long endOffset) { + client.getrange(key, startOffset, endOffset); + return getResponse(BuilderFactory.STRING); + } + + public Response getSet(String key, String value) { + client.getSet(key, value); + return getResponse(BuilderFactory.STRING); + } + + public Response getSet(byte[] key, byte[] value) { + client.getSet(key, value); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response getrange(byte[] key, long startOffset, long endOffset) { + client.getrange(key, startOffset, endOffset); + return getResponse(BuilderFactory.LONG); + } + + public Response hdel(String key, String field) { + client.hdel(key, field); + return getResponse(BuilderFactory.LONG); + } + + public Response hdel(byte[] key, byte[] field) { + client.hdel(key, field); + return getResponse(BuilderFactory.LONG); + } + + public Response hexists(String key, String field) { + client.hexists(key, field); + return getResponse(BuilderFactory.BOOLEAN); + } + + public Response hexists(byte[] key, byte[] field) { + client.hexists(key, field); + return getResponse(BuilderFactory.BOOLEAN); + } + + public Response hget(String key, String field) { + client.hget(key, field); + return getResponse(BuilderFactory.STRING); + } + + public Response hget(byte[] key, byte[] field) { + client.hget(key, field); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response> hgetAll(String key) { + client.hgetAll(key); + return getResponse(BuilderFactory.STRING_MAP); + } + + public Response> hgetAll(byte[] key) { + client.hgetAll(key); + return getResponse(BuilderFactory.BYTE_ARRAY_MAP); + } + + public Response hincrBy(String key, String field, long value) { + client.hincrBy(key, field, value); + return getResponse(BuilderFactory.LONG); + } + + public Response hincrBy(byte[] key, byte[] field, long value) { + client.hincrBy(key, field, value); + return getResponse(BuilderFactory.LONG); + } + + public Response> hkeys(String key) { + client.hkeys(key); + return getResponse(BuilderFactory.STRING_SET); + } + + public Response> hkeys(byte[] key) { + client.hkeys(key); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + } + + public Response hlen(String key) { + client.hlen(key); + return getResponse(BuilderFactory.LONG); + } + + public Response hlen(byte[] key) { + client.hlen(key); + return getResponse(BuilderFactory.LONG); + } + + public Response> hmget(String key, String... fields) { + client.hmget(key, fields); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> hmget(byte[] key, byte[]... fields) { + client.hmget(key, fields); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response hmset(String key, Map hash) { + client.hmset(key, hash); + return getResponse(BuilderFactory.STRING); + } + + public Response hmset(byte[] key, Map hash) { + client.hmset(key, hash); + return getResponse(BuilderFactory.STRING); + } + + public Response hset(String key, String field, String value) { + client.hset(key, field, value); + return getResponse(BuilderFactory.LONG); + } + + public Response hset(byte[] key, byte[] field, byte[] value) { + client.hset(key, field, value); + return getResponse(BuilderFactory.LONG); + } + + public Response hsetnx(String key, String field, String value) { + client.hsetnx(key, field, value); + return getResponse(BuilderFactory.LONG); + } + + public Response hsetnx(byte[] key, byte[] field, byte[] value) { + client.hsetnx(key, field, value); + return getResponse(BuilderFactory.LONG); + } + + public Response> hvals(String key) { + client.hvals(key); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> hvals(byte[] key) { + client.hvals(key); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response incr(String key) { + client.incr(key); + return getResponse(BuilderFactory.LONG); + } + + public Response incr(byte[] key) { + client.incr(key); + return getResponse(BuilderFactory.LONG); + } + + public Response incrBy(String key, long integer) { + client.incrBy(key, integer); + return getResponse(BuilderFactory.LONG); + } + + public Response incrBy(byte[] key, long integer) { + client.incrBy(key, integer); + return getResponse(BuilderFactory.LONG); + } + + public Response> keys(String pattern) { + client.keys(pattern); + return getResponse(BuilderFactory.STRING_SET); + } + + public Response> keys(byte[] pattern) { + client.keys(pattern); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + } + + public Response lindex(String key, int index) { + client.lindex(key, index); + return getResponse(BuilderFactory.STRING); + } + + public Response lindex(byte[] key, int index) { + client.lindex(key, index); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response linsert(String key, LIST_POSITION where, + String pivot, String value) { + client.linsert(key, where, pivot, value); + return getResponse(BuilderFactory.LONG); + } + + public Response linsert(byte[] key, LIST_POSITION where, + byte[] pivot, byte[] value) { + client.linsert(key, where, pivot, value); + return getResponse(BuilderFactory.LONG); + } + + public Response llen(String key) { + client.llen(key); + return getResponse(BuilderFactory.LONG); + } + + public Response llen(byte[] key) { + client.llen(key); + return getResponse(BuilderFactory.LONG); + } + + public Response lpop(String key) { + client.lpop(key); + return getResponse(BuilderFactory.STRING); + } + + public Response lpop(byte[] key) { + client.lpop(key); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response lpush(String key, String string) { + client.lpush(key, string); + return getResponse(BuilderFactory.LONG); + } + + public Response lpush(byte[] key, byte[] string) { + client.lpush(key, string); + return getResponse(BuilderFactory.LONG); + } + + public Response lpushx(String key, String string) { + client.lpushx(key, string); + return getResponse(BuilderFactory.LONG); + } + + public Response lpushx(byte[] key, byte[] bytes) { + client.lpushx(key, bytes); + return getResponse(BuilderFactory.LONG); + } + + public Response> lrange(String key, long start, long end) { + client.lrange(key, start, end); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> lrange(byte[] key, long start, long end) { + client.lrange(key, start, end); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response lrem(String key, long count, String value) { + client.lrem(key, count, value); + return getResponse(BuilderFactory.LONG); + } + + public Response lrem(byte[] key, long count, byte[] value) { + client.lrem(key, count, value); + return getResponse(BuilderFactory.LONG); + } + + public Response lset(String key, long index, String value) { + client.lset(key, index, value); + return getResponse(BuilderFactory.STRING); + } + + public Response lset(byte[] key, long index, byte[] value) { + client.lset(key, index, value); + return getResponse(BuilderFactory.STRING); + } + + public Response ltrim(String key, long start, long end) { + client.ltrim(key, start, end); + return getResponse(BuilderFactory.STRING); + } + + public Response ltrim(byte[] key, long start, long end) { + client.ltrim(key, start, end); + return getResponse(BuilderFactory.STRING); + } + + public Response> mget(String... keys) { + client.mget(keys); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> mget(byte[]... keys) { + client.mget(keys); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response move(String key, int dbIndex) { + client.move(key, dbIndex); + return getResponse(BuilderFactory.LONG); + } + + public Response move(byte[] key, int dbIndex) { + client.move(key, dbIndex); + return getResponse(BuilderFactory.LONG); + } + + public Response mset(String... keysvalues) { + client.mset(keysvalues); + return getResponse(BuilderFactory.STRING); + } + + public Response mset(byte[]... keysvalues) { + client.mset(keysvalues); + return getResponse(BuilderFactory.STRING); + } + + public Response msetnx(String... keysvalues) { + client.msetnx(keysvalues); + return getResponse(BuilderFactory.LONG); + } + + public Response msetnx(byte[]... keysvalues) { + client.msetnx(keysvalues); + return getResponse(BuilderFactory.LONG); + } + + public Response persist(String key) { + client.persist(key); + return getResponse(BuilderFactory.LONG); + } + + public Response persist(byte[] key) { + client.persist(key); + return getResponse(BuilderFactory.LONG); + } + + public Response rename(String oldkey, String newkey) { + client.rename(oldkey, newkey); + return getResponse(BuilderFactory.STRING); + } + + public Response rename(byte[] oldkey, byte[] newkey) { + client.rename(oldkey, newkey); + return getResponse(BuilderFactory.STRING); + } + + public Response renamenx(String oldkey, String newkey) { + client.renamenx(oldkey, newkey); + return getResponse(BuilderFactory.LONG); + } + + public Response renamenx(byte[] oldkey, byte[] newkey) { + client.renamenx(oldkey, newkey); + return getResponse(BuilderFactory.LONG); + } + + public Response rpop(String key) { + client.rpop(key); + return getResponse(BuilderFactory.STRING); + } + + public Response rpop(byte[] key) { + client.rpop(key); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response rpoplpush(String srckey, String dstkey) { + client.rpoplpush(srckey, dstkey); + return getResponse(BuilderFactory.STRING); + } + + public Response rpoplpush(byte[] srckey, byte[] dstkey) { + client.rpoplpush(srckey, dstkey); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response rpush(String key, String string) { + client.rpush(key, string); + return getResponse(BuilderFactory.LONG); + } + + public Response rpush(byte[] key, byte[] string) { + client.rpush(key, string); + return getResponse(BuilderFactory.LONG); + } + + public Response rpushx(String key, String string) { + client.rpushx(key, string); + return getResponse(BuilderFactory.LONG); + } + + public Response rpushx(byte[] key, byte[] string) { + client.rpushx(key, string); + return getResponse(BuilderFactory.LONG); + } + + public Response sadd(String key, String member) { + client.sadd(key, member); + return getResponse(BuilderFactory.LONG); + } + + public Response sadd(byte[] key, byte[] member) { + client.sadd(key, member); + return getResponse(BuilderFactory.LONG); + } + + public Response scard(String key) { + client.scard(key); + return getResponse(BuilderFactory.LONG); + } + + public Response scard(byte[] key) { + client.scard(key); + return getResponse(BuilderFactory.LONG); + } + + public Response> sdiff(String... keys) { + client.sdiff(keys); + return getResponse(BuilderFactory.STRING_SET); + } + + public Response> sdiff(byte[]... keys) { + client.sdiff(keys); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + } + + public Response sdiffstore(String dstkey, String... keys) { + client.sdiffstore(dstkey, keys); + return getResponse(BuilderFactory.LONG); + } + + public Response sdiffstore(byte[] dstkey, byte[]... keys) { + client.sdiffstore(dstkey, keys); + return getResponse(BuilderFactory.LONG); + } + + public Response set(String key, String value) { + client.set(key, value); + return getResponse(BuilderFactory.STRING); + } + + public Response set(byte[] key, byte[] value) { + client.set(key, value); + return getResponse(BuilderFactory.STRING); + } + + public Response setbit(String key, long offset, boolean value) { + client.setbit(key, offset, value); + return getResponse(BuilderFactory.BOOLEAN); + } + + public Response setbit(byte[] key, long offset, byte[] value) { + client.setbit(key, offset, value); + return getResponse(BuilderFactory.BOOLEAN); + } + + public Response setex(String key, int seconds, String value) { + client.setex(key, seconds, value); + return getResponse(BuilderFactory.STRING); + } + + public Response setex(byte[] key, int seconds, byte[] value) { + client.setex(key, seconds, value); + return getResponse(BuilderFactory.STRING); + } + + public Response setnx(String key, String value) { + client.setnx(key, value); + return getResponse(BuilderFactory.LONG); + } + + public Response setnx(byte[] key, byte[] value) { + client.setnx(key, value); + return getResponse(BuilderFactory.LONG); + } + + public Response setrange(String key, long offset, String value) { + client.setrange(key, offset, value); + return getResponse(BuilderFactory.LONG); + } + + public Response setrange(byte[] key, long offset, byte[] value) { + client.setrange(key, offset, value); + return getResponse(BuilderFactory.LONG); + } + + public Response> sinter(String... keys) { + client.sinter(keys); + return getResponse(BuilderFactory.STRING_SET); + } + + public Response> sinter(byte[]... keys) { + client.sinter(keys); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + } + + public Response sinterstore(String dstkey, String... keys) { + client.sinterstore(dstkey, keys); + return getResponse(BuilderFactory.LONG); + } + + public Response sinterstore(byte[] dstkey, byte[]... keys) { + client.sinterstore(dstkey, keys); + return getResponse(BuilderFactory.LONG); + } + + public Response sismember(String key, String member) { + client.sismember(key, member); + return getResponse(BuilderFactory.BOOLEAN); + } + + public Response sismember(byte[] key, byte[] member) { + client.sismember(key, member); + return getResponse(BuilderFactory.BOOLEAN); + } + + public Response> smembers(String key) { + client.smembers(key); + return getResponse(BuilderFactory.STRING_SET); + } + + public Response> smembers(byte[] key) { + client.smembers(key); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + } + + public Response smove(String srckey, String dstkey, String member) { + client.smove(srckey, dstkey, member); + return getResponse(BuilderFactory.LONG); + } + + public Response smove(byte[] srckey, byte[] dstkey, byte[] member) { + client.smove(srckey, dstkey, member); + return getResponse(BuilderFactory.LONG); + } + + public Response> sort(String key) { + client.sort(key); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> sort(byte[] key) { + client.sort(key); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response> sort(String key, + SortingParams sortingParameters) { + client.sort(key, sortingParameters); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> sort(byte[] key, + SortingParams sortingParameters) { + client.sort(key, sortingParameters); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response> sort(String key, + SortingParams sortingParameters, String dstkey) { + client.sort(key, sortingParameters, dstkey); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> sort(byte[] key, + SortingParams sortingParameters, byte[] dstkey) { + client.sort(key, sortingParameters, dstkey); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response> sort(String key, String dstkey) { + client.sort(key, dstkey); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> sort(byte[] key, byte[] dstkey) { + client.sort(key, dstkey); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response spop(String key) { + client.spop(key); + return getResponse(BuilderFactory.STRING); + } + + public Response spop(byte[] key) { + client.spop(key); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response srandmember(String key) { + client.srandmember(key); + return getResponse(BuilderFactory.STRING); + } + + public Response srandmember(byte[] key) { + client.srandmember(key); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response srem(String key, String member) { + client.srem(key, member); + return getResponse(BuilderFactory.LONG); + } + + public Response srem(byte[] key, byte[] member) { + client.srem(key, member); + return getResponse(BuilderFactory.LONG); + } + + public Response strlen(String key) { + client.strlen(key); + return getResponse(BuilderFactory.LONG); + } + + public Response strlen(byte[] key) { + client.strlen(key); + return getResponse(BuilderFactory.LONG); + } + + public Response substr(String key, int start, int end) { + client.substr(key, start, end); + return getResponse(BuilderFactory.STRING); + } + + public Response substr(byte[] key, int start, int end) { + client.substr(key, start, end); + return getResponse(BuilderFactory.STRING); + } + + public Response> sunion(String... keys) { + client.sunion(keys); + return getResponse(BuilderFactory.STRING_SET); + } + + public Response> sunion(byte[]... keys) { + client.sunion(keys); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + } + + public Response sunionstore(String dstkey, String... keys) { + client.sunionstore(dstkey, keys); + return getResponse(BuilderFactory.LONG); + } + + public Response sunionstore(byte[] dstkey, byte[]... keys) { + client.sunionstore(dstkey, keys); + return getResponse(BuilderFactory.LONG); + } + + public Response ttl(String key) { + client.ttl(key); + return getResponse(BuilderFactory.LONG); + } + + public Response ttl(byte[] key) { + client.ttl(key); + return getResponse(BuilderFactory.LONG); + } + + public Response type(String key) { + client.type(key); + return getResponse(BuilderFactory.STRING); + } + + public Response type(byte[] key) { + client.type(key); + return getResponse(BuilderFactory.STRING); + } + + public Response watch(String... keys) { + client.watch(keys); + return getResponse(BuilderFactory.STRING); + } + + public Response watch(byte[]... keys) { + client.watch(keys); + return getResponse(BuilderFactory.STRING); + } + + public Response zadd(String key, double score, String member) { + client.zadd(key, score, member); + return getResponse(BuilderFactory.LONG); + } + + public Response zadd(byte[] key, double score, byte[] member) { + client.zadd(key, score, member); + return getResponse(BuilderFactory.LONG); + } + + public Response zcard(String key) { + client.zcard(key); + return getResponse(BuilderFactory.LONG); + } + + public Response zcard(byte[] key) { + client.zcard(key); + return getResponse(BuilderFactory.LONG); + } + + public Response zcount(String key, double min, double max) { + client.zcount(key, min, max); + return getResponse(BuilderFactory.LONG); + } + + public Response zcount(byte[] key, double min, double max) { + client.zcount(key, toByteArray(min), toByteArray(max)); + return getResponse(BuilderFactory.LONG); + } + + public Response zincrby(String key, double score, String member) { + client.zincrby(key, score, member); + return getResponse(BuilderFactory.DOUBLE); + } + + public Response zincrby(byte[] key, double score, byte[] member) { + client.zincrby(key, score, member); + return getResponse(BuilderFactory.DOUBLE); + } + + public Response zinterstore(String dstkey, String... sets) { + client.zinterstore(dstkey, sets); + return getResponse(BuilderFactory.LONG); + } + + public Response zinterstore(byte[] dstkey, byte[]... sets) { + client.zinterstore(dstkey, sets); + return getResponse(BuilderFactory.LONG); + } + + public Response zinterstore(String dstkey, ZParams params, + String... sets) { + client.zinterstore(dstkey, params, sets); + return getResponse(BuilderFactory.LONG); + } + + public Response zinterstore(byte[] dstkey, ZParams params, + byte[]... sets) { + client.zinterstore(dstkey, params, sets); + return getResponse(BuilderFactory.LONG); + } + + public Response> zrange(String key, int start, int end) { + client.zrange(key, start, end); + return getResponse(BuilderFactory.STRING_ZSET); + } + + public Response> zrange(byte[] key, int start, int end) { + client.zrange(key, start, end); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + } + + public Response> zrangeByScore(String key, double min, + double max) { + client.zrangeByScore(key, min, max); + return getResponse(BuilderFactory.STRING_ZSET); + } + + public Response> zrangeByScore(byte[] key, double min, + double max) { + return zrangeByScore(key, toByteArray(min), toByteArray(max)); + } + + public Response> zrangeByScore(String key, String min, + String max) { + client.zrangeByScore(key, min, max); + return getResponse(BuilderFactory.STRING_ZSET); + } + + public Response> zrangeByScore(byte[] key, byte[] min, + byte[] max) { + client.zrangeByScore(key, min, max); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + } + + public Response> zrangeByScore(String key, double min, + double max, int offset, int count) { + client.zrangeByScore(key, min, max, offset, count); + return getResponse(BuilderFactory.STRING_ZSET); + } + + public Response> zrangeByScore(byte[] key, double min, + double max, int offset, int count) { + return zrangeByScore(key, toByteArray(min), toByteArray(max), offset, count); + } + + public Response> zrangeByScore(byte[] key, byte[] min, + byte[] max, int offset, int count) { + client.zrangeByScore(key, min, max, offset, count); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + } + + public Response> zrangeByScoreWithScores(String key, double min, + double max) { + client.zrangeByScoreWithScores(key, min, max); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + + public Response> zrangeByScoreWithScores(byte[] key, double min, + double max) { + return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max)); + } + + public Response> zrangeByScoreWithScores(byte[] key, byte[] min, + byte[] max) { + client.zrangeByScoreWithScores(key, min, max); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); + } + + public Response> zrangeByScoreWithScores(String key, double min, + double max, int offset, int count) { + client.zrangeByScoreWithScores(key, min, max, offset, count); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + + public Response> zrangeByScoreWithScores(byte[] key, double min, + double max, int offset, int count) { + client.zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); + } + + public Response> zrangeByScoreWithScores(byte[] key, byte[] min, + byte[] max, int offset, int count) { + client.zrangeByScoreWithScores(key, min, max, offset, count); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); + } + + public Response> zrevrangeByScore(String key, double max, + double min) { + client.zrevrangeByScore(key, max, min); + return getResponse(BuilderFactory.STRING_ZSET); + } + + public Response> zrevrangeByScore(byte[] key, double max, + double min) { + client.zrevrangeByScore(key, toByteArray(max), toByteArray(min)); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + } + + public Response> zrevrangeByScore(String key, String max, + String min) { + client.zrevrangeByScore(key, max, min); + return getResponse(BuilderFactory.STRING_ZSET); + } + + public Response> zrevrangeByScore(byte[] key, byte[] max, + byte[] min) { + client.zrevrangeByScore(key, max, min); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + } + + public Response> zrevrangeByScore(String key, double max, + double min, int offset, int count) { + client.zrevrangeByScore(key, max, min, offset, count); + return getResponse(BuilderFactory.STRING_ZSET); + } + + public Response> zrevrangeByScore(byte[] key, double max, + double min, int offset, int count) { + client.zrevrangeByScore(key, toByteArray(max), toByteArray(min), offset, count); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + } + + public Response> zrevrangeByScore(byte[] key, byte[] max, + byte[] min, int offset, int count) { + client.zrevrangeByScore(key, max, min, offset, count); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + } + + public Response> zrevrangeByScoreWithScores(String key, + double max, double min) { + client.zrevrangeByScoreWithScores(key, max, min); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + + public Response> zrevrangeByScoreWithScores(byte[] key, + double max, double min) { + client.zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min)); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); + } + + public Response> zrevrangeByScoreWithScores(byte[] key, + byte[] max, byte[] min) { + client.zrevrangeByScoreWithScores(key, max, min); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); + } + + public Response> zrevrangeByScoreWithScores(String key, + double max, double min, int offset, int count) { + client.zrevrangeByScoreWithScores(key, max, min, offset, count); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + + public Response> zrevrangeByScoreWithScores(byte[] key, + double max, double min, int offset, int count) { + client.zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min), offset, count); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); + } + + public Response> zrevrangeByScoreWithScores(byte[] key, + byte[] max, byte[] min, int offset, int count) { + client.zrevrangeByScoreWithScores(key, max, min, offset, count); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); + } + + public Response> zrangeWithScores(String key, int start, int end) { + client.zrangeWithScores(key, start, end); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + + public Response> zrangeWithScores(byte[] key, int start, int end) { + client.zrangeWithScores(key, start, end); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); + } + + public Response zrank(String key, String member) { + client.zrank(key, member); + return getResponse(BuilderFactory.LONG); + } + + public Response zrank(byte[] key, byte[] member) { + client.zrank(key, member); + return getResponse(BuilderFactory.LONG); + } + + public Response zrem(String key, String member) { + client.zrem(key, member); + return getResponse(BuilderFactory.LONG); + } + + public Response zrem(byte[] key, byte[] member) { + client.zrem(key, member); + return getResponse(BuilderFactory.LONG); + } + + public Response zremrangeByRank(String key, int start, int end) { + client.zremrangeByRank(key, start, end); + return getResponse(BuilderFactory.LONG); + } + + public Response zremrangeByRank(byte[] key, int start, int end) { + client.zremrangeByRank(key, start, end); + return getResponse(BuilderFactory.LONG); + } + + public Response zremrangeByScore(String key, double start, double end) { + client.zremrangeByScore(key, start, end); + return getResponse(BuilderFactory.LONG); + } + + public Response zremrangeByScore(byte[] key, double start, double end) { + client.zremrangeByScore(key, toByteArray(start), toByteArray(end)); + return getResponse(BuilderFactory.LONG); + } + + public Response zremrangeByScore(byte[] key, byte[] start, byte[] end) { + client.zremrangeByScore(key, start, end); + return getResponse(BuilderFactory.LONG); + } + + public Response> zrevrange(String key, int start, int end) { + client.zrevrange(key, start, end); + return getResponse(BuilderFactory.STRING_ZSET); + } + + public Response> zrevrange(byte[] key, int start, int end) { + client.zrevrange(key, start, end); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + } + + public Response> zrevrangeWithScores(String key, int start, + int end) { + client.zrevrangeWithScores(key, start, end); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + + public Response> zrevrangeWithScores(byte[] key, int start, + int end) { + client.zrevrangeWithScores(key, start, end); + return getResponse(BuilderFactory.TUPLE_ZSET); + } + + public Response zrevrank(String key, String member) { + client.zrevrank(key, member); + return getResponse(BuilderFactory.LONG); + } + + public Response zrevrank(byte[] key, byte[] member) { + client.zrevrank(key, member); + return getResponse(BuilderFactory.LONG); + } + + public Response zscore(String key, String member) { + client.zscore(key, member); + return getResponse(BuilderFactory.DOUBLE); + } + + public Response zscore(byte[] key, byte[] member) { + client.zscore(key, member); + return getResponse(BuilderFactory.DOUBLE); + } + + public Response zunionstore(String dstkey, String... sets) { + client.zunionstore(dstkey, sets); + return getResponse(BuilderFactory.LONG); + } + + public Response zunionstore(byte[] dstkey, byte[]... sets) { + client.zunionstore(dstkey, sets); + return getResponse(BuilderFactory.LONG); + } + + public Response zunionstore(String dstkey, ZParams params, + String... sets) { + client.zunionstore(dstkey, params, sets); + return getResponse(BuilderFactory.LONG); + } + + public Response zunionstore(byte[] dstkey, ZParams params, + byte[]... sets) { + client.zunionstore(dstkey, params, sets); + return getResponse(BuilderFactory.LONG); + } + + public Response bgrewriteaof() { + client.bgrewriteaof(); + return getResponse(BuilderFactory.STRING); + } + + public Response bgsave() { + client.bgsave(); + return getResponse(BuilderFactory.STRING); + } + + public Response configGet(String pattern) { + client.configGet(pattern); + return getResponse(BuilderFactory.STRING); + } + + public Response configSet(String parameter, String value) { + client.configSet(parameter, value); + return getResponse(BuilderFactory.STRING); + } + + public Response brpoplpush(String source, String destination, + int timeout) { + client.brpoplpush(source, destination, timeout); + return getResponse(BuilderFactory.STRING); + } + + public Response brpoplpush(byte[] source, byte[] destination, + int timeout) { + client.brpoplpush(source, destination, timeout); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response configResetStat() { + client.configResetStat(); + return getResponse(BuilderFactory.STRING); + } + + public Response save() { + client.save(); + return getResponse(BuilderFactory.STRING); + } + + public Response lastsave() { + client.lastsave(); + return getResponse(BuilderFactory.LONG); + } + + public Response publish(String channel, String message) { + client.publish(channel, message); + return getResponse(BuilderFactory.LONG); + } + + public Response publish(byte[] channel, byte[] message) { + client.publish(channel, message); + return getResponse(BuilderFactory.LONG); + } + + public Response randomKey() { + client.randomKey(); + return getResponse(BuilderFactory.STRING); + } + + public Response randomKeyBinary() { + client.randomKey(); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response flushDB() { + client.flushDB(); + return getResponse(BuilderFactory.STRING); + } + + public Response flushAll() { + client.flushAll(); + return getResponse(BuilderFactory.STRING); + } + + public Response info() { + client.info(); + return getResponse(BuilderFactory.STRING); + } + + public Response dbSize() { + client.dbSize(); + return getResponse(BuilderFactory.LONG); + } + + public Response shutdown() { + client.shutdown(); + return getResponse(BuilderFactory.STRING); + } + + public Response ping() { + client.ping(); + return getResponse(BuilderFactory.STRING); + } + + public Response select(int index) { + client.select(index); + return getResponse(BuilderFactory.STRING); + } + + public Response bitcount(String key) { + client.bitcount(key); + return getResponse(BuilderFactory.LONG); + } + + public Response bitcount(String key, long start, long end) { + client.bitcount(key, start, end); + return getResponse(BuilderFactory.LONG); + } + + public Response bitcount(byte[] key) { + client.bitcount(key); + return getResponse(BuilderFactory.LONG); + } + + public Response bitcount(byte[] key, long start, long end) { + client.bitcount(key, start, end); + return getResponse(BuilderFactory.LONG); + } + + public Response bitop(BitOP op, byte[] destKey, byte[]... srcKeys) { + client.bitop(op, destKey, srcKeys); + return getResponse(BuilderFactory.LONG); + } + + public Response bitop(BitOP op, String destKey, String... srcKeys) { + client.bitop(op, destKey, srcKeys); + return getResponse(BuilderFactory.LONG); + } +} diff --git a/src/main/java/redis/clients/jedis/Transaction.java b/src/main/java/redis/clients/jedis/Transaction.java index 18c5f29..1629b59 100644 --- a/src/main/java/redis/clients/jedis/Transaction.java +++ b/src/main/java/redis/clients/jedis/Transaction.java @@ -1,579 +1,65 @@ package redis.clients.jedis; +import redis.clients.jedis.exceptions.JedisDataException; + +import java.util.ArrayList; import java.util.List; -import java.util.Map; -import java.util.Set; -import redis.clients.jedis.BinaryClient.LIST_POSITION; +/** + * Transaction is nearly identical to Pipeline, only differences are the multi/discard behaviors + */ +public class Transaction extends PipelineBase { -public class Transaction extends BinaryTransaction { - public Transaction() { + protected boolean inTransaction = true; + + protected Transaction(){ + // client will be set later in transaction block } public Transaction(final Client client) { - super(client); + this.client = client; + } + + public List exec() { + client.exec(); + client.getAll(1); // Discard all but the last reply + + List unformatted = client.getObjectMultiBulkReply(); + if (unformatted == null) { + return null; + } + List formatted = new ArrayList(); + for (Object o : unformatted) { + try { + formatted.add(generateResponse(o).get()); + } catch (JedisDataException e) { + formatted.add(e); + } + } + return formatted; + } + + public List> execGetResponse() { + client.exec(); + client.getAll(1); // Discard all but the last reply + + List unformatted = client.getObjectMultiBulkReply(); + if (unformatted == null) { + return null; + } + List> response = new ArrayList>(); + for (Object o : unformatted) { + response.add(generateResponse(o)); + } + return response; + } + + public String discard() { + client.discard(); + client.getAll(1); // Discard all but the last reply + inTransaction = false; + clean(); + return client.getStatusCodeReply(); } - public Response append(String key, String value) { - client.append(key, value); - return getResponse(BuilderFactory.LONG); - } - - public Response> blpop(String... args) { - client.blpop(args); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> brpop(String... args) { - client.brpop(args); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response decr(String key) { - client.decr(key); - return getResponse(BuilderFactory.LONG); - } - - public Response decrBy(String key, long integer) { - client.decrBy(key, integer); - return getResponse(BuilderFactory.LONG); - } - - public Response del(String... keys) { - client.del(keys); - return getResponse(BuilderFactory.LONG); - } - - public Response echo(String string) { - client.echo(string); - return getResponse(BuilderFactory.STRING); - } - - public Response exists(String key) { - client.exists(key); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response expire(String key, int seconds) { - client.expire(key, seconds); - return getResponse(BuilderFactory.LONG); - } - - public Response expireAt(String key, long unixTime) { - client.expireAt(key, unixTime); - return getResponse(BuilderFactory.LONG); - } - - public Response get(String key) { - client.get(key); - return getResponse(BuilderFactory.STRING); - } - - public Response getbit(String key, long offset) { - client.getbit(key, offset); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response getrange(String key, long startOffset, - long endOffset) { - client.getrange(key, startOffset, endOffset); - return getResponse(BuilderFactory.STRING); - } - - public Response getSet(String key, String value) { - client.getSet(key, value); - return getResponse(BuilderFactory.STRING); - } - - public Response hdel(String key, String field) { - client.hdel(key, field); - return getResponse(BuilderFactory.LONG); - } - - public Response hexists(String key, String field) { - client.hexists(key, field); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response hget(String key, String field) { - client.hget(key, field); - return getResponse(BuilderFactory.STRING); - } - - public Response> hgetAll(String key) { - client.hgetAll(key); - return getResponse(BuilderFactory.STRING_MAP); - } - - public Response hincrBy(String key, String field, long value) { - client.hincrBy(key, field, value); - return getResponse(BuilderFactory.LONG); - } - - public Response> hkeys(String key) { - client.hkeys(key); - return getResponse(BuilderFactory.STRING_SET); - } - - public Response hlen(String key) { - client.hlen(key); - return getResponse(BuilderFactory.LONG); - } - - public Response> hmget(String key, String... fields) { - client.hmget(key, fields); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response hmset(String key, Map hash) { - client.hmset(key, hash); - return getResponse(BuilderFactory.STRING); - } - - public Response hset(String key, String field, String value) { - client.hset(key, field, value); - return getResponse(BuilderFactory.LONG); - } - - public Response hsetnx(String key, String field, String value) { - client.hsetnx(key, field, value); - return getResponse(BuilderFactory.LONG); - } - - public Response> hvals(String key) { - client.hvals(key); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response incr(String key) { - client.incr(key); - return getResponse(BuilderFactory.LONG); - } - - public Response incrBy(String key, long integer) { - client.incrBy(key, integer); - return getResponse(BuilderFactory.LONG); - } - - public Response> keys(String pattern) { - client.keys(pattern); - return getResponse(BuilderFactory.STRING_SET); - } - - public Response lindex(String key, int index) { - client.lindex(key, index); - return getResponse(BuilderFactory.STRING); - } - - public Response linsert(String key, LIST_POSITION where, - String pivot, String value) { - client.linsert(key, where, pivot, value); - return getResponse(BuilderFactory.LONG); - } - - public Response llen(String key) { - client.llen(key); - return getResponse(BuilderFactory.LONG); - } - - public Response lpop(String key) { - client.lpop(key); - return getResponse(BuilderFactory.STRING); - } - - public Response lpush(String key, String string) { - client.lpush(key, string); - return getResponse(BuilderFactory.LONG); - } - - public Response lpushx(String key, String string) { - client.lpushx(key, string); - return getResponse(BuilderFactory.LONG); - } - - public Response> lrange(String key, long start, long end) { - client.lrange(key, start, end); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response lrem(String key, long count, String value) { - client.lrem(key, count, value); - return getResponse(BuilderFactory.LONG); - } - - public Response lset(String key, long index, String value) { - client.lset(key, index, value); - return getResponse(BuilderFactory.STRING); - } - - public Response ltrim(String key, long start, long end) { - client.ltrim(key, start, end); - return getResponse(BuilderFactory.STRING); - } - - public Response> mget(String... keys) { - client.mget(keys); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response move(String key, int dbIndex) { - client.move(key, dbIndex); - return getResponse(BuilderFactory.LONG); - } - - public Response mset(String... keysvalues) { - client.mset(keysvalues); - return getResponse(BuilderFactory.STRING); - } - - public Response msetnx(String... keysvalues) { - client.msetnx(keysvalues); - return getResponse(BuilderFactory.LONG); - } - - public Response persist(String key) { - client.persist(key); - return getResponse(BuilderFactory.LONG); - } - - public Response rename(String oldkey, String newkey) { - client.rename(oldkey, newkey); - return getResponse(BuilderFactory.STRING); - } - - public Response renamenx(String oldkey, String newkey) { - client.renamenx(oldkey, newkey); - return getResponse(BuilderFactory.LONG); - } - - public Response rpop(String key) { - client.rpop(key); - return getResponse(BuilderFactory.STRING); - } - - public Response rpoplpush(String srckey, String dstkey) { - client.rpoplpush(srckey, dstkey); - return getResponse(BuilderFactory.STRING); - } - - public Response rpush(String key, String string) { - client.rpush(key, string); - return getResponse(BuilderFactory.LONG); - } - - public Response rpushx(String key, String string) { - client.rpushx(key, string); - return getResponse(BuilderFactory.LONG); - } - - public Response sadd(String key, String member) { - client.sadd(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response scard(String key) { - client.scard(key); - return getResponse(BuilderFactory.LONG); - } - - public Response> sdiff(String... keys) { - client.sdiff(keys); - return getResponse(BuilderFactory.STRING_SET); - } - - public Response sdiffstore(String dstkey, String... keys) { - client.sdiffstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); - } - - public Response set(String key, String value) { - client.set(key, value); - return getResponse(BuilderFactory.STRING); - } - - public Response setbit(String key, long offset, boolean value) { - client.setbit(key, offset, value); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response setex(String key, int seconds, String value) { - client.setex(key, seconds, value); - return getResponse(BuilderFactory.STRING); - } - - public Response setnx(String key, String value) { - client.setnx(key, value); - return getResponse(BuilderFactory.LONG); - } - - public Response setrange(String key, long offset, String value) { - client.setrange(key, offset, value); - return getResponse(BuilderFactory.LONG); - } - - public Response> sinter(String... keys) { - client.sinter(keys); - return getResponse(BuilderFactory.STRING_SET); - } - - public Response sinterstore(String dstkey, String... keys) { - client.sinterstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); - } - - public Response sismember(String key, String member) { - client.sismember(key, member); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response> smembers(String key) { - client.smembers(key); - return getResponse(BuilderFactory.STRING_SET); - } - - public Response smove(String srckey, String dstkey, String member) { - client.smove(srckey, dstkey, member); - return getResponse(BuilderFactory.LONG); - } - - public Response> sort(String key) { - client.sort(key); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> sort(String key, - SortingParams sortingParameters) { - client.sort(key, sortingParameters); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> sort(String key, - SortingParams sortingParameters, String dstkey) { - client.sort(key, sortingParameters, dstkey); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> sort(String key, String dstkey) { - client.sort(key, dstkey); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response spop(String key) { - client.spop(key); - return getResponse(BuilderFactory.STRING); - } - - public Response srandmember(String key) { - client.srandmember(key); - return getResponse(BuilderFactory.STRING); - } - - public Response srem(String key, String member) { - client.srem(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response strlen(String key) { - client.strlen(key); - return getResponse(BuilderFactory.LONG); - } - - public Response substr(String key, int start, int end) { - client.substr(key, start, end); - return getResponse(BuilderFactory.STRING); - } - - public Response> sunion(String... keys) { - client.sunion(keys); - return getResponse(BuilderFactory.STRING_SET); - } - - public Response sunionstore(String dstkey, String... keys) { - client.sunionstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); - } - - public Response ttl(String key) { - client.ttl(key); - return getResponse(BuilderFactory.LONG); - } - - public Response type(String key) { - client.type(key); - return getResponse(BuilderFactory.STRING); - } - - public Response zadd(String key, double score, String member) { - client.zadd(key, score, member); - return getResponse(BuilderFactory.LONG); - } - - public Response zcard(String key) { - client.zcard(key); - return getResponse(BuilderFactory.LONG); - } - - public Response zcount(String key, double min, double max) { - client.zcount(key, min, max); - return getResponse(BuilderFactory.LONG); - } - - public Response zincrby(String key, double score, String member) { - client.zincrby(key, score, member); - return getResponse(BuilderFactory.DOUBLE); - } - - public Response zinterstore(String dstkey, String... sets) { - client.zinterstore(dstkey, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response zinterstore(String dstkey, ZParams params, - String... sets) { - client.zinterstore(dstkey, params, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response> zrange(String key, int start, int end) { - client.zrange(key, start, end); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrangeByScore(String key, double min, - double max) { - client.zrangeByScore(key, min, max); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrangeByScore(String key, String min, - String max) { - client.zrangeByScore(key, min, max); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrangeByScore(String key, double min, - double max, int offset, int count) { - client.zrangeByScore(key, min, max, offset, count); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrangeByScoreWithScores(String key, double min, - double max) { - client.zrangeByScoreWithScores(key, min, max); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrangeByScoreWithScores(String key, double min, - double max, int offset, int count) { - client.zrangeByScoreWithScores(key, min, max, offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrangeWithScores(String key, int start, int end) { - client.zrangeWithScores(key, start, end); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response zrank(String key, String member) { - client.zrank(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response zrem(String key, String member) { - client.zrem(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response zremrangeByRank(String key, int start, int end) { - client.zremrangeByRank(key, start, end); - return getResponse(BuilderFactory.LONG); - } - - public Response zremrangeByScore(String key, double start, double end) { - client.zremrangeByScore(key, start, end); - return getResponse(BuilderFactory.LONG); - } - - public Response> zrevrange(String key, int start, int end) { - client.zrevrange(key, start, end); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrevrangeWithScores(String key, int start, - int end) { - client.zrevrangeWithScores(key, start, end); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response zrevrank(String key, String member) { - client.zrevrank(key, member); - return getResponse(BuilderFactory.LONG); - } - - public Response zscore(String key, String member) { - client.zscore(key, member); - return getResponse(BuilderFactory.DOUBLE); - } - - public Response zunionstore(String dstkey, String... sets) { - client.zunionstore(dstkey, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response zunionstore(String dstkey, ZParams params, - String... sets) { - client.zunionstore(dstkey, params, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response bgrewriteaof() { - client.bgrewriteaof(); - return getResponse(BuilderFactory.STRING); - } - - public Response bgsave() { - client.bgsave(); - return getResponse(BuilderFactory.STRING); - } - - public Response configGet(String pattern) { - client.configGet(pattern); - return getResponse(BuilderFactory.STRING); - } - - public Response configSet(String parameter, String value) { - client.configSet(parameter, value); - return getResponse(BuilderFactory.STRING); - } - - public Response brpoplpush(String source, String destination, - int timeout) { - client.brpoplpush(source, destination, timeout); - return getResponse(BuilderFactory.STRING); - } - - public Response configResetStat() { - client.configResetStat(); - return getResponse(BuilderFactory.STRING); - } - - public Response save() { - client.save(); - return getResponse(BuilderFactory.STRING); - } - - public Response lastsave() { - client.lastsave(); - return getResponse(BuilderFactory.LONG); - } - - public Response publish(String channel, String message) { - client.publish(channel, message); - return getResponse(BuilderFactory.LONG); - } - - public Response publish(byte[] channel, byte[] message) { - client.publish(channel, message); - return getResponse(BuilderFactory.LONG); - } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java index 8167658..5e03270 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java @@ -171,7 +171,7 @@ public class TransactionCommandsTest extends JedisCommandTestBase { t.set(bmykey, bval); resp = t.exec(); assertEquals(1, resp.size()); - assertArrayEquals("OK".getBytes(), (byte[]) resp.get(0)); + assertEquals("OK", resp.get(0)); } @Test(expected = JedisDataException.class) From 6b5fccdc0ad69742b171d25515a0a9a630ac4635 Mon Sep 17 00:00:00 2001 From: samhendley Date: Thu, 10 Jan 2013 02:29:39 -0500 Subject: [PATCH 092/112] refactored pipelinebase so it is usable to implement SharedJedisPipeline as well. --- .../clients/jedis/MultiKeyPipelineBase.java | 370 +++++ .../java/redis/clients/jedis/Pipeline.java | 10 +- .../redis/clients/jedis/PipelineBase.java | 740 +++------- .../clients/jedis/ShardedJedisPipeline.java | 1302 +---------------- .../java/redis/clients/jedis/Transaction.java | 12 +- .../redis/clients/jedis/TransactionBlock.java | 2 +- 6 files changed, 597 insertions(+), 1839 deletions(-) create mode 100644 src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java diff --git a/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java b/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java new file mode 100644 index 0000000..ccf0dfd --- /dev/null +++ b/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java @@ -0,0 +1,370 @@ +package redis.clients.jedis; + +import java.util.List; +import java.util.Set; + +abstract class MultiKeyPipelineBase extends PipelineBase implements + BasicRedisPipeline, + MultiKeyBinaryRedisPipeline, + MultiKeyCommandsPipeline { + + protected Client client = null; + + public Response> brpop(String... args) { + client.brpop(args); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> blpop(String... args) { + client.blpop(args); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> brpop(byte[]... args) { + client.brpop(args); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response> blpop(byte[]... args) { + client.blpop(args); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response del(String... keys) { + client.del(keys); + return getResponse(BuilderFactory.LONG); + } + + public Response del(byte[]... keys) { + client.del(keys); + return getResponse(BuilderFactory.LONG); + } + + public Response> keys(String pattern) { + getClient(pattern).keys(pattern); + return getResponse(BuilderFactory.STRING_SET); + } + + public Response> keys(byte[] pattern) { + getClient(pattern).keys(pattern); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + } + + public Response> mget(String... keys) { + client.mget(keys); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> mget(byte[]... keys) { + client.mget(keys); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response mset(String... keysvalues) { + client.mset(keysvalues); + return getResponse(BuilderFactory.STRING); + } + + public Response mset(byte[]... keysvalues) { + client.mset(keysvalues); + return getResponse(BuilderFactory.STRING); + } + + public Response msetnx(String... keysvalues) { + client.msetnx(keysvalues); + return getResponse(BuilderFactory.LONG); + } + + public Response msetnx(byte[]... keysvalues) { + client.msetnx(keysvalues); + return getResponse(BuilderFactory.LONG); + } + + public Response rename(String oldkey, String newkey) { + client.rename(oldkey, newkey); + return getResponse(BuilderFactory.STRING); + } + + public Response rename(byte[] oldkey, byte[] newkey) { + client.rename(oldkey, newkey); + return getResponse(BuilderFactory.STRING); + } + + public Response renamenx(String oldkey, String newkey) { + client.renamenx(oldkey, newkey); + return getResponse(BuilderFactory.LONG); + } + + public Response renamenx(byte[] oldkey, byte[] newkey) { + client.renamenx(oldkey, newkey); + return getResponse(BuilderFactory.LONG); + } + + public Response rpoplpush(String srckey, String dstkey) { + client.rpoplpush(srckey, dstkey); + return getResponse(BuilderFactory.STRING); + } + + public Response rpoplpush(byte[] srckey, byte[] dstkey) { + client.rpoplpush(srckey, dstkey); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response> sdiff(String... keys) { + client.sdiff(keys); + return getResponse(BuilderFactory.STRING_SET); + } + + public Response> sdiff(byte[]... keys) { + client.sdiff(keys); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + } + + public Response sdiffstore(String dstkey, String... keys) { + client.sdiffstore(dstkey, keys); + return getResponse(BuilderFactory.LONG); + } + + public Response sdiffstore(byte[] dstkey, byte[]... keys) { + client.sdiffstore(dstkey, keys); + return getResponse(BuilderFactory.LONG); + } + + public Response> sinter(String... keys) { + client.sinter(keys); + return getResponse(BuilderFactory.STRING_SET); + } + + public Response> sinter(byte[]... keys) { + client.sinter(keys); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + } + + public Response sinterstore(String dstkey, String... keys) { + client.sinterstore(dstkey, keys); + return getResponse(BuilderFactory.LONG); + } + + public Response sinterstore(byte[] dstkey, byte[]... keys) { + client.sinterstore(dstkey, keys); + return getResponse(BuilderFactory.LONG); + } + + public Response smove(String srckey, String dstkey, String member) { + client.smove(srckey, dstkey, member); + return getResponse(BuilderFactory.LONG); + } + + public Response smove(byte[] srckey, byte[] dstkey, byte[] member) { + client.smove(srckey, dstkey, member); + return getResponse(BuilderFactory.LONG); + } + + public Response> sort(String key, + SortingParams sortingParameters, String dstkey) { + client.sort(key, sortingParameters, dstkey); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> sort(byte[] key, + SortingParams sortingParameters, byte[] dstkey) { + client.sort(key, sortingParameters, dstkey); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response> sort(String key, String dstkey) { + client.sort(key, dstkey); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> sort(byte[] key, byte[] dstkey) { + client.sort(key, dstkey); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } + + public Response> sunion(String... keys) { + client.sunion(keys); + return getResponse(BuilderFactory.STRING_SET); + } + + public Response> sunion(byte[]... keys) { + client.sunion(keys); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + } + + public Response sunionstore(String dstkey, String... keys) { + client.sunionstore(dstkey, keys); + return getResponse(BuilderFactory.LONG); + } + + public Response sunionstore(byte[] dstkey, byte[]... keys) { + client.sunionstore(dstkey, keys); + return getResponse(BuilderFactory.LONG); + } + + public Response watch(String... keys) { + client.watch(keys); + return getResponse(BuilderFactory.STRING); + } + + public Response watch(byte[]... keys) { + client.watch(keys); + return getResponse(BuilderFactory.STRING); + } + + public Response zinterstore(String dstkey, String... sets) { + client.zinterstore(dstkey, sets); + return getResponse(BuilderFactory.LONG); + } + + public Response zinterstore(byte[] dstkey, byte[]... sets) { + client.zinterstore(dstkey, sets); + return getResponse(BuilderFactory.LONG); + } + + public Response zinterstore(String dstkey, ZParams params, + String... sets) { + client.zinterstore(dstkey, params, sets); + return getResponse(BuilderFactory.LONG); + } + + public Response zinterstore(byte[] dstkey, ZParams params, + byte[]... sets) { + client.zinterstore(dstkey, params, sets); + return getResponse(BuilderFactory.LONG); + } + + public Response zunionstore(String dstkey, String... sets) { + client.zunionstore(dstkey, sets); + return getResponse(BuilderFactory.LONG); + } + + public Response zunionstore(byte[] dstkey, byte[]... sets) { + client.zunionstore(dstkey, sets); + return getResponse(BuilderFactory.LONG); + } + + public Response zunionstore(String dstkey, ZParams params, + String... sets) { + client.zunionstore(dstkey, params, sets); + return getResponse(BuilderFactory.LONG); + } + + public Response zunionstore(byte[] dstkey, ZParams params, + byte[]... sets) { + client.zunionstore(dstkey, params, sets); + return getResponse(BuilderFactory.LONG); + } + + public Response bgrewriteaof() { + client.bgrewriteaof(); + return getResponse(BuilderFactory.STRING); + } + + public Response bgsave() { + client.bgsave(); + return getResponse(BuilderFactory.STRING); + } + + public Response configGet(String pattern) { + client.configGet(pattern); + return getResponse(BuilderFactory.STRING); + } + + public Response configSet(String parameter, String value) { + client.configSet(parameter, value); + return getResponse(BuilderFactory.STRING); + } + + public Response brpoplpush(String source, String destination, + int timeout) { + client.brpoplpush(source, destination, timeout); + return getResponse(BuilderFactory.STRING); + } + + public Response brpoplpush(byte[] source, byte[] destination, + int timeout) { + client.brpoplpush(source, destination, timeout); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response configResetStat() { + client.configResetStat(); + return getResponse(BuilderFactory.STRING); + } + + public Response save() { + client.save(); + return getResponse(BuilderFactory.STRING); + } + + public Response lastsave() { + client.lastsave(); + return getResponse(BuilderFactory.LONG); + } + + public Response publish(String channel, String message) { + client.publish(channel, message); + return getResponse(BuilderFactory.LONG); + } + + public Response publish(byte[] channel, byte[] message) { + client.publish(channel, message); + return getResponse(BuilderFactory.LONG); + } + + public Response randomKey() { + client.randomKey(); + return getResponse(BuilderFactory.STRING); + } + + public Response randomKeyBinary() { + client.randomKey(); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response flushDB() { + client.flushDB(); + return getResponse(BuilderFactory.STRING); + } + + public Response flushAll() { + client.flushAll(); + return getResponse(BuilderFactory.STRING); + } + + public Response info() { + client.info(); + return getResponse(BuilderFactory.STRING); + } + + public Response dbSize() { + client.dbSize(); + return getResponse(BuilderFactory.LONG); + } + + public Response shutdown() { + client.shutdown(); + return getResponse(BuilderFactory.STRING); + } + + public Response ping() { + client.ping(); + return getResponse(BuilderFactory.STRING); + } + + public Response select(int index) { + client.select(index); + return getResponse(BuilderFactory.STRING); + } + + public Response bitop(BitOP op, byte[] destKey, byte[]... srcKeys) { + client.bitop(op, destKey, srcKeys); + return getResponse(BuilderFactory.LONG); + } + + public Response bitop(BitOP op, String destKey, String... srcKeys) { + client.bitop(op, destKey, srcKeys); + return getResponse(BuilderFactory.LONG); + } +} diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index cf61066..ee680eb 100755 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -5,7 +5,7 @@ import redis.clients.jedis.exceptions.JedisDataException; import java.util.ArrayList; import java.util.List; -public class Pipeline extends PipelineBase { +public class Pipeline extends MultiKeyPipelineBase { private MultiResponseBuilder currentMulti; @@ -53,7 +53,15 @@ public class Pipeline extends PipelineBase { this.client = client; } + @Override + protected Client getClient(byte[] key) { + return client; + } + @Override + protected Client getClient(String key) { + return client; + } /** * Syncronize pipeline by reading all responses. This operation close the diff --git a/src/main/java/redis/clients/jedis/PipelineBase.java b/src/main/java/redis/clients/jedis/PipelineBase.java index b8fdefd..2af0899 100644 --- a/src/main/java/redis/clients/jedis/PipelineBase.java +++ b/src/main/java/redis/clients/jedis/PipelineBase.java @@ -1,924 +1,707 @@ package redis.clients.jedis; -import static redis.clients.jedis.Protocol.toByteArray; +import redis.clients.jedis.BinaryClient.LIST_POSITION; -import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; -import redis.clients.jedis.BinaryClient.LIST_POSITION; -import redis.clients.jedis.exceptions.JedisDataException; +import static redis.clients.jedis.Protocol.toByteArray; abstract class PipelineBase extends Queable implements - BasicRedisPipeline, BinaryRedisPipeline, - RedisPipeline, - MultiKeyBinaryRedisPipeline, - MultiKeyCommandsPipeline { - - protected Client client; + RedisPipeline { + + protected abstract Client getClient(String key); + + protected abstract Client getClient(byte[] key); public Response append(String key, String value) { - client.append(key, value); + getClient(key).append(key, value); return getResponse(BuilderFactory.LONG); } public Response append(byte[] key, byte[] value) { - client.append(key, value); + getClient(key).append(key, value); return getResponse(BuilderFactory.LONG); } - public Response> blpop(String arg) { + public Response> blpop(String key) { String[] temp = new String[1]; - temp[0] = arg; - client.blpop(temp); + temp[0] = key; + getClient(key).blpop(temp); return getResponse(BuilderFactory.STRING_LIST); } - public Response> brpop(String arg) { + public Response> brpop(String key) { String[] temp = new String[1]; - temp[0] = arg; - client.brpop(temp); + temp[0] = key; + getClient(key).brpop(temp); return getResponse(BuilderFactory.STRING_LIST); } - public Response> blpop(byte[] arg) { + public Response> blpop(byte[] key) { byte[][] temp = new byte[1][]; - temp[0] = arg; - client.blpop(temp); + temp[0] = key; + getClient(key).blpop(temp); return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } - public Response> brpop(byte[] arg) { + public Response> brpop(byte[] key) { byte[][] temp = new byte[1][]; - temp[0] = arg; - client.brpop(temp); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response> blpop(String... args) { - client.blpop(args); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> blpop(byte[]... args) { - client.blpop(args); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response> brpop(String... args) { - client.brpop(args); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> brpop(byte[]... args) { - client.brpop(args); + temp[0] = key; + getClient(key).brpop(temp); return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response decr(String key) { - client.decr(key); + getClient(key).decr(key); return getResponse(BuilderFactory.LONG); } public Response decr(byte[] key) { - client.decr(key); + getClient(key).decr(key); return getResponse(BuilderFactory.LONG); } public Response decrBy(String key, long integer) { - client.decrBy(key, integer); + getClient(key).decrBy(key, integer); return getResponse(BuilderFactory.LONG); } public Response decrBy(byte[] key, long integer) { - client.decrBy(key, integer); + getClient(key).decrBy(key, integer); return getResponse(BuilderFactory.LONG); } public Response del(String key) { - client.del(key); - return getResponse(BuilderFactory.LONG); - } - - public Response del(String... keys) { - client.del(keys); + getClient(key).del(key); return getResponse(BuilderFactory.LONG); } public Response del(byte[] key) { - client.del(key); - return getResponse(BuilderFactory.LONG); - } - - public Response del(byte[]... keys) { - client.del(keys); + getClient(key).del(key); return getResponse(BuilderFactory.LONG); } public Response echo(String string) { - client.echo(string); + getClient(string).echo(string); return getResponse(BuilderFactory.STRING); } public Response echo(byte[] string) { - client.echo(string); + getClient(string).echo(string); return getResponse(BuilderFactory.BYTE_ARRAY); } public Response exists(String key) { - client.exists(key); + getClient(key).exists(key); return getResponse(BuilderFactory.BOOLEAN); } public Response exists(byte[] key) { - client.exists(key); + getClient(key).exists(key); return getResponse(BuilderFactory.BOOLEAN); } public Response expire(String key, int seconds) { - client.expire(key, seconds); + getClient(key).expire(key, seconds); return getResponse(BuilderFactory.LONG); } public Response expire(byte[] key, int seconds) { - client.expire(key, seconds); + getClient(key).expire(key, seconds); return getResponse(BuilderFactory.LONG); } public Response expireAt(String key, long unixTime) { - client.expireAt(key, unixTime); + getClient(key).expireAt(key, unixTime); return getResponse(BuilderFactory.LONG); } public Response expireAt(byte[] key, long unixTime) { - client.expireAt(key, unixTime); + getClient(key).expireAt(key, unixTime); return getResponse(BuilderFactory.LONG); } public Response get(String key) { - client.get(key); + getClient(key).get(key); return getResponse(BuilderFactory.STRING); } public Response get(byte[] key) { - client.get(key); + getClient(key).get(key); return getResponse(BuilderFactory.BYTE_ARRAY); } public Response getbit(String key, long offset) { - client.getbit(key, offset); + getClient(key).getbit(key, offset); return getResponse(BuilderFactory.BOOLEAN); } public Response getbit(byte[] key, long offset) { - client.getbit(key, offset); + getClient(key).getbit(key, offset); return getResponse(BuilderFactory.BOOLEAN); } public Response getrange(String key, long startOffset, long endOffset) { - client.getrange(key, startOffset, endOffset); + getClient(key).getrange(key, startOffset, endOffset); return getResponse(BuilderFactory.STRING); } public Response getSet(String key, String value) { - client.getSet(key, value); + getClient(key).getSet(key, value); return getResponse(BuilderFactory.STRING); } public Response getSet(byte[] key, byte[] value) { - client.getSet(key, value); + getClient(key).getSet(key, value); return getResponse(BuilderFactory.BYTE_ARRAY); } public Response getrange(byte[] key, long startOffset, long endOffset) { - client.getrange(key, startOffset, endOffset); + getClient(key).getrange(key, startOffset, endOffset); return getResponse(BuilderFactory.LONG); } public Response hdel(String key, String field) { - client.hdel(key, field); + getClient(key).hdel(key, field); return getResponse(BuilderFactory.LONG); } public Response hdel(byte[] key, byte[] field) { - client.hdel(key, field); + getClient(key).hdel(key, field); return getResponse(BuilderFactory.LONG); } public Response hexists(String key, String field) { - client.hexists(key, field); + getClient(key).hexists(key, field); return getResponse(BuilderFactory.BOOLEAN); } public Response hexists(byte[] key, byte[] field) { - client.hexists(key, field); + getClient(key).hexists(key, field); return getResponse(BuilderFactory.BOOLEAN); } public Response hget(String key, String field) { - client.hget(key, field); + getClient(key).hget(key, field); return getResponse(BuilderFactory.STRING); } public Response hget(byte[] key, byte[] field) { - client.hget(key, field); + getClient(key).hget(key, field); return getResponse(BuilderFactory.BYTE_ARRAY); } public Response> hgetAll(String key) { - client.hgetAll(key); + getClient(key).hgetAll(key); return getResponse(BuilderFactory.STRING_MAP); } public Response> hgetAll(byte[] key) { - client.hgetAll(key); + getClient(key).hgetAll(key); return getResponse(BuilderFactory.BYTE_ARRAY_MAP); } public Response hincrBy(String key, String field, long value) { - client.hincrBy(key, field, value); + getClient(key).hincrBy(key, field, value); return getResponse(BuilderFactory.LONG); } public Response hincrBy(byte[] key, byte[] field, long value) { - client.hincrBy(key, field, value); + getClient(key).hincrBy(key, field, value); return getResponse(BuilderFactory.LONG); } public Response> hkeys(String key) { - client.hkeys(key); + getClient(key).hkeys(key); return getResponse(BuilderFactory.STRING_SET); } public Response> hkeys(byte[] key) { - client.hkeys(key); + getClient(key).hkeys(key); return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response hlen(String key) { - client.hlen(key); + getClient(key).hlen(key); return getResponse(BuilderFactory.LONG); } public Response hlen(byte[] key) { - client.hlen(key); + getClient(key).hlen(key); return getResponse(BuilderFactory.LONG); } public Response> hmget(String key, String... fields) { - client.hmget(key, fields); + getClient(key).hmget(key, fields); return getResponse(BuilderFactory.STRING_LIST); } public Response> hmget(byte[] key, byte[]... fields) { - client.hmget(key, fields); + getClient(key).hmget(key, fields); return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response hmset(String key, Map hash) { - client.hmset(key, hash); + getClient(key).hmset(key, hash); return getResponse(BuilderFactory.STRING); } public Response hmset(byte[] key, Map hash) { - client.hmset(key, hash); + getClient(key).hmset(key, hash); return getResponse(BuilderFactory.STRING); } public Response hset(String key, String field, String value) { - client.hset(key, field, value); + getClient(key).hset(key, field, value); return getResponse(BuilderFactory.LONG); } public Response hset(byte[] key, byte[] field, byte[] value) { - client.hset(key, field, value); + getClient(key).hset(key, field, value); return getResponse(BuilderFactory.LONG); } public Response hsetnx(String key, String field, String value) { - client.hsetnx(key, field, value); + getClient(key).hsetnx(key, field, value); return getResponse(BuilderFactory.LONG); } public Response hsetnx(byte[] key, byte[] field, byte[] value) { - client.hsetnx(key, field, value); + getClient(key).hsetnx(key, field, value); return getResponse(BuilderFactory.LONG); } public Response> hvals(String key) { - client.hvals(key); + getClient(key).hvals(key); return getResponse(BuilderFactory.STRING_LIST); } public Response> hvals(byte[] key) { - client.hvals(key); + getClient(key).hvals(key); return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response incr(String key) { - client.incr(key); + getClient(key).incr(key); return getResponse(BuilderFactory.LONG); } public Response incr(byte[] key) { - client.incr(key); + getClient(key).incr(key); return getResponse(BuilderFactory.LONG); } public Response incrBy(String key, long integer) { - client.incrBy(key, integer); + getClient(key).incrBy(key, integer); return getResponse(BuilderFactory.LONG); } public Response incrBy(byte[] key, long integer) { - client.incrBy(key, integer); + getClient(key).incrBy(key, integer); return getResponse(BuilderFactory.LONG); } public Response> keys(String pattern) { - client.keys(pattern); + getClient(pattern).keys(pattern); return getResponse(BuilderFactory.STRING_SET); } public Response> keys(byte[] pattern) { - client.keys(pattern); + getClient(pattern).keys(pattern); return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response lindex(String key, int index) { - client.lindex(key, index); + getClient(key).lindex(key, index); return getResponse(BuilderFactory.STRING); } public Response lindex(byte[] key, int index) { - client.lindex(key, index); + getClient(key).lindex(key, index); return getResponse(BuilderFactory.BYTE_ARRAY); } public Response linsert(String key, LIST_POSITION where, String pivot, String value) { - client.linsert(key, where, pivot, value); + getClient(key).linsert(key, where, pivot, value); return getResponse(BuilderFactory.LONG); } public Response linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value) { - client.linsert(key, where, pivot, value); + getClient(key).linsert(key, where, pivot, value); return getResponse(BuilderFactory.LONG); } public Response llen(String key) { - client.llen(key); + getClient(key).llen(key); return getResponse(BuilderFactory.LONG); } public Response llen(byte[] key) { - client.llen(key); + getClient(key).llen(key); return getResponse(BuilderFactory.LONG); } public Response lpop(String key) { - client.lpop(key); + getClient(key).lpop(key); return getResponse(BuilderFactory.STRING); } public Response lpop(byte[] key) { - client.lpop(key); + getClient(key).lpop(key); return getResponse(BuilderFactory.BYTE_ARRAY); } public Response lpush(String key, String string) { - client.lpush(key, string); + getClient(key).lpush(key, string); return getResponse(BuilderFactory.LONG); } public Response lpush(byte[] key, byte[] string) { - client.lpush(key, string); + getClient(key).lpush(key, string); return getResponse(BuilderFactory.LONG); } public Response lpushx(String key, String string) { - client.lpushx(key, string); + getClient(key).lpushx(key, string); return getResponse(BuilderFactory.LONG); } public Response lpushx(byte[] key, byte[] bytes) { - client.lpushx(key, bytes); + getClient(key).lpushx(key, bytes); return getResponse(BuilderFactory.LONG); } public Response> lrange(String key, long start, long end) { - client.lrange(key, start, end); + getClient(key).lrange(key, start, end); return getResponse(BuilderFactory.STRING_LIST); } public Response> lrange(byte[] key, long start, long end) { - client.lrange(key, start, end); + getClient(key).lrange(key, start, end); return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response lrem(String key, long count, String value) { - client.lrem(key, count, value); + getClient(key).lrem(key, count, value); return getResponse(BuilderFactory.LONG); } public Response lrem(byte[] key, long count, byte[] value) { - client.lrem(key, count, value); + getClient(key).lrem(key, count, value); return getResponse(BuilderFactory.LONG); } public Response lset(String key, long index, String value) { - client.lset(key, index, value); + getClient(key).lset(key, index, value); return getResponse(BuilderFactory.STRING); } public Response lset(byte[] key, long index, byte[] value) { - client.lset(key, index, value); + getClient(key).lset(key, index, value); return getResponse(BuilderFactory.STRING); } public Response ltrim(String key, long start, long end) { - client.ltrim(key, start, end); + getClient(key).ltrim(key, start, end); return getResponse(BuilderFactory.STRING); } public Response ltrim(byte[] key, long start, long end) { - client.ltrim(key, start, end); + getClient(key).ltrim(key, start, end); return getResponse(BuilderFactory.STRING); } - public Response> mget(String... keys) { - client.mget(keys); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> mget(byte[]... keys) { - client.mget(keys); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - public Response move(String key, int dbIndex) { - client.move(key, dbIndex); + getClient(key).move(key, dbIndex); return getResponse(BuilderFactory.LONG); } public Response move(byte[] key, int dbIndex) { - client.move(key, dbIndex); - return getResponse(BuilderFactory.LONG); - } - - public Response mset(String... keysvalues) { - client.mset(keysvalues); - return getResponse(BuilderFactory.STRING); - } - - public Response mset(byte[]... keysvalues) { - client.mset(keysvalues); - return getResponse(BuilderFactory.STRING); - } - - public Response msetnx(String... keysvalues) { - client.msetnx(keysvalues); - return getResponse(BuilderFactory.LONG); - } - - public Response msetnx(byte[]... keysvalues) { - client.msetnx(keysvalues); + getClient(key).move(key, dbIndex); return getResponse(BuilderFactory.LONG); } public Response persist(String key) { - client.persist(key); + getClient(key).persist(key); return getResponse(BuilderFactory.LONG); } public Response persist(byte[] key) { - client.persist(key); - return getResponse(BuilderFactory.LONG); - } - - public Response rename(String oldkey, String newkey) { - client.rename(oldkey, newkey); - return getResponse(BuilderFactory.STRING); - } - - public Response rename(byte[] oldkey, byte[] newkey) { - client.rename(oldkey, newkey); - return getResponse(BuilderFactory.STRING); - } - - public Response renamenx(String oldkey, String newkey) { - client.renamenx(oldkey, newkey); - return getResponse(BuilderFactory.LONG); - } - - public Response renamenx(byte[] oldkey, byte[] newkey) { - client.renamenx(oldkey, newkey); + getClient(key).persist(key); return getResponse(BuilderFactory.LONG); } public Response rpop(String key) { - client.rpop(key); + getClient(key).rpop(key); return getResponse(BuilderFactory.STRING); } public Response rpop(byte[] key) { - client.rpop(key); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response rpoplpush(String srckey, String dstkey) { - client.rpoplpush(srckey, dstkey); - return getResponse(BuilderFactory.STRING); - } - - public Response rpoplpush(byte[] srckey, byte[] dstkey) { - client.rpoplpush(srckey, dstkey); + getClient(key).rpop(key); return getResponse(BuilderFactory.BYTE_ARRAY); } public Response rpush(String key, String string) { - client.rpush(key, string); + getClient(key).rpush(key, string); return getResponse(BuilderFactory.LONG); } public Response rpush(byte[] key, byte[] string) { - client.rpush(key, string); + getClient(key).rpush(key, string); return getResponse(BuilderFactory.LONG); } public Response rpushx(String key, String string) { - client.rpushx(key, string); + getClient(key).rpushx(key, string); return getResponse(BuilderFactory.LONG); } public Response rpushx(byte[] key, byte[] string) { - client.rpushx(key, string); + getClient(key).rpushx(key, string); return getResponse(BuilderFactory.LONG); } public Response sadd(String key, String member) { - client.sadd(key, member); + getClient(key).sadd(key, member); return getResponse(BuilderFactory.LONG); } public Response sadd(byte[] key, byte[] member) { - client.sadd(key, member); + getClient(key).sadd(key, member); return getResponse(BuilderFactory.LONG); } public Response scard(String key) { - client.scard(key); + getClient(key).scard(key); return getResponse(BuilderFactory.LONG); } public Response scard(byte[] key) { - client.scard(key); - return getResponse(BuilderFactory.LONG); - } - - public Response> sdiff(String... keys) { - client.sdiff(keys); - return getResponse(BuilderFactory.STRING_SET); - } - - public Response> sdiff(byte[]... keys) { - client.sdiff(keys); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response sdiffstore(String dstkey, String... keys) { - client.sdiffstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); - } - - public Response sdiffstore(byte[] dstkey, byte[]... keys) { - client.sdiffstore(dstkey, keys); + getClient(key).scard(key); return getResponse(BuilderFactory.LONG); } public Response set(String key, String value) { - client.set(key, value); + getClient(key).set(key, value); return getResponse(BuilderFactory.STRING); } public Response set(byte[] key, byte[] value) { - client.set(key, value); + getClient(key).set(key, value); return getResponse(BuilderFactory.STRING); } public Response setbit(String key, long offset, boolean value) { - client.setbit(key, offset, value); + getClient(key).setbit(key, offset, value); return getResponse(BuilderFactory.BOOLEAN); } public Response setbit(byte[] key, long offset, byte[] value) { - client.setbit(key, offset, value); + getClient(key).setbit(key, offset, value); return getResponse(BuilderFactory.BOOLEAN); } public Response setex(String key, int seconds, String value) { - client.setex(key, seconds, value); + getClient(key).setex(key, seconds, value); return getResponse(BuilderFactory.STRING); } public Response setex(byte[] key, int seconds, byte[] value) { - client.setex(key, seconds, value); + getClient(key).setex(key, seconds, value); return getResponse(BuilderFactory.STRING); } public Response setnx(String key, String value) { - client.setnx(key, value); + getClient(key).setnx(key, value); return getResponse(BuilderFactory.LONG); } public Response setnx(byte[] key, byte[] value) { - client.setnx(key, value); + getClient(key).setnx(key, value); return getResponse(BuilderFactory.LONG); } public Response setrange(String key, long offset, String value) { - client.setrange(key, offset, value); + getClient(key).setrange(key, offset, value); return getResponse(BuilderFactory.LONG); } public Response setrange(byte[] key, long offset, byte[] value) { - client.setrange(key, offset, value); - return getResponse(BuilderFactory.LONG); - } - - public Response> sinter(String... keys) { - client.sinter(keys); - return getResponse(BuilderFactory.STRING_SET); - } - - public Response> sinter(byte[]... keys) { - client.sinter(keys); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response sinterstore(String dstkey, String... keys) { - client.sinterstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); - } - - public Response sinterstore(byte[] dstkey, byte[]... keys) { - client.sinterstore(dstkey, keys); + getClient(key).setrange(key, offset, value); return getResponse(BuilderFactory.LONG); } public Response sismember(String key, String member) { - client.sismember(key, member); + getClient(key).sismember(key, member); return getResponse(BuilderFactory.BOOLEAN); } public Response sismember(byte[] key, byte[] member) { - client.sismember(key, member); + getClient(key).sismember(key, member); return getResponse(BuilderFactory.BOOLEAN); } public Response> smembers(String key) { - client.smembers(key); + getClient(key).smembers(key); return getResponse(BuilderFactory.STRING_SET); } public Response> smembers(byte[] key) { - client.smembers(key); + getClient(key).smembers(key); return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } - public Response smove(String srckey, String dstkey, String member) { - client.smove(srckey, dstkey, member); - return getResponse(BuilderFactory.LONG); - } - - public Response smove(byte[] srckey, byte[] dstkey, byte[] member) { - client.smove(srckey, dstkey, member); - return getResponse(BuilderFactory.LONG); - } - public Response> sort(String key) { - client.sort(key); + getClient(key).sort(key); return getResponse(BuilderFactory.STRING_LIST); } public Response> sort(byte[] key) { - client.sort(key); + getClient(key).sort(key); return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response> sort(String key, SortingParams sortingParameters) { - client.sort(key, sortingParameters); + getClient(key).sort(key, sortingParameters); return getResponse(BuilderFactory.STRING_LIST); } public Response> sort(byte[] key, SortingParams sortingParameters) { - client.sort(key, sortingParameters); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response> sort(String key, - SortingParams sortingParameters, String dstkey) { - client.sort(key, sortingParameters, dstkey); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> sort(byte[] key, - SortingParams sortingParameters, byte[] dstkey) { - client.sort(key, sortingParameters, dstkey); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response> sort(String key, String dstkey) { - client.sort(key, dstkey); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> sort(byte[] key, byte[] dstkey) { - client.sort(key, dstkey); + getClient(key).sort(key, sortingParameters); return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response spop(String key) { - client.spop(key); + getClient(key).spop(key); return getResponse(BuilderFactory.STRING); } public Response spop(byte[] key) { - client.spop(key); + getClient(key).spop(key); return getResponse(BuilderFactory.BYTE_ARRAY); } public Response srandmember(String key) { - client.srandmember(key); + getClient(key).srandmember(key); return getResponse(BuilderFactory.STRING); } public Response srandmember(byte[] key) { - client.srandmember(key); + getClient(key).srandmember(key); return getResponse(BuilderFactory.BYTE_ARRAY); } public Response srem(String key, String member) { - client.srem(key, member); + getClient(key).srem(key, member); return getResponse(BuilderFactory.LONG); } public Response srem(byte[] key, byte[] member) { - client.srem(key, member); + getClient(key).srem(key, member); return getResponse(BuilderFactory.LONG); } public Response strlen(String key) { - client.strlen(key); + getClient(key).strlen(key); return getResponse(BuilderFactory.LONG); } public Response strlen(byte[] key) { - client.strlen(key); + getClient(key).strlen(key); return getResponse(BuilderFactory.LONG); } public Response substr(String key, int start, int end) { - client.substr(key, start, end); + getClient(key).substr(key, start, end); return getResponse(BuilderFactory.STRING); } public Response substr(byte[] key, int start, int end) { - client.substr(key, start, end); + getClient(key).substr(key, start, end); return getResponse(BuilderFactory.STRING); } - public Response> sunion(String... keys) { - client.sunion(keys); - return getResponse(BuilderFactory.STRING_SET); - } - - public Response> sunion(byte[]... keys) { - client.sunion(keys); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response sunionstore(String dstkey, String... keys) { - client.sunionstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); - } - - public Response sunionstore(byte[] dstkey, byte[]... keys) { - client.sunionstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); - } - public Response ttl(String key) { - client.ttl(key); + getClient(key).ttl(key); return getResponse(BuilderFactory.LONG); } public Response ttl(byte[] key) { - client.ttl(key); + getClient(key).ttl(key); return getResponse(BuilderFactory.LONG); } public Response type(String key) { - client.type(key); + getClient(key).type(key); return getResponse(BuilderFactory.STRING); } public Response type(byte[] key) { - client.type(key); - return getResponse(BuilderFactory.STRING); - } - - public Response watch(String... keys) { - client.watch(keys); - return getResponse(BuilderFactory.STRING); - } - - public Response watch(byte[]... keys) { - client.watch(keys); + getClient(key).type(key); return getResponse(BuilderFactory.STRING); } public Response zadd(String key, double score, String member) { - client.zadd(key, score, member); + getClient(key).zadd(key, score, member); return getResponse(BuilderFactory.LONG); } public Response zadd(byte[] key, double score, byte[] member) { - client.zadd(key, score, member); + getClient(key).zadd(key, score, member); return getResponse(BuilderFactory.LONG); } public Response zcard(String key) { - client.zcard(key); + getClient(key).zcard(key); return getResponse(BuilderFactory.LONG); } public Response zcard(byte[] key) { - client.zcard(key); + getClient(key).zcard(key); return getResponse(BuilderFactory.LONG); } public Response zcount(String key, double min, double max) { - client.zcount(key, min, max); + getClient(key).zcount(key, min, max); return getResponse(BuilderFactory.LONG); } public Response zcount(byte[] key, double min, double max) { - client.zcount(key, toByteArray(min), toByteArray(max)); + getClient(key).zcount(key, toByteArray(min), toByteArray(max)); return getResponse(BuilderFactory.LONG); } public Response zincrby(String key, double score, String member) { - client.zincrby(key, score, member); + getClient(key).zincrby(key, score, member); return getResponse(BuilderFactory.DOUBLE); } public Response zincrby(byte[] key, double score, byte[] member) { - client.zincrby(key, score, member); + getClient(key).zincrby(key, score, member); return getResponse(BuilderFactory.DOUBLE); } - public Response zinterstore(String dstkey, String... sets) { - client.zinterstore(dstkey, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response zinterstore(byte[] dstkey, byte[]... sets) { - client.zinterstore(dstkey, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response zinterstore(String dstkey, ZParams params, - String... sets) { - client.zinterstore(dstkey, params, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response zinterstore(byte[] dstkey, ZParams params, - byte[]... sets) { - client.zinterstore(dstkey, params, sets); - return getResponse(BuilderFactory.LONG); - } - public Response> zrange(String key, int start, int end) { - client.zrange(key, start, end); + getClient(key).zrange(key, start, end); return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrange(byte[] key, int start, int end) { - client.zrange(key, start, end); + getClient(key).zrange(key, start, end); return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrangeByScore(String key, double min, double max) { - client.zrangeByScore(key, min, max); + getClient(key).zrangeByScore(key, min, max); return getResponse(BuilderFactory.STRING_ZSET); } @@ -929,19 +712,19 @@ abstract class PipelineBase extends Queable implements public Response> zrangeByScore(String key, String min, String max) { - client.zrangeByScore(key, min, max); + getClient(key).zrangeByScore(key, min, max); return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrangeByScore(byte[] key, byte[] min, byte[] max) { - client.zrangeByScore(key, min, max); + getClient(key).zrangeByScore(key, min, max); return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrangeByScore(String key, double min, double max, int offset, int count) { - client.zrangeByScore(key, min, max, offset, count); + getClient(key).zrangeByScore(key, min, max, offset, count); return getResponse(BuilderFactory.STRING_ZSET); } @@ -952,13 +735,13 @@ abstract class PipelineBase extends Queable implements public Response> zrangeByScore(byte[] key, byte[] min, byte[] max, int offset, int count) { - client.zrangeByScore(key, min, max, offset, count); + getClient(key).zrangeByScore(key, min, max, offset, count); return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrangeByScoreWithScores(String key, double min, double max) { - client.zrangeByScoreWithScores(key, min, max); + getClient(key).zrangeByScoreWithScores(key, min, max); return getResponse(BuilderFactory.TUPLE_ZSET); } @@ -969,354 +752,221 @@ abstract class PipelineBase extends Queable implements public Response> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max) { - client.zrangeByScoreWithScores(key, min, max); + getClient(key).zrangeByScoreWithScores(key, min, max); return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrangeByScoreWithScores(String key, double min, double max, int offset, int count) { - client.zrangeByScoreWithScores(key, min, max, offset, count); + getClient(key).zrangeByScoreWithScores(key, min, max, offset, count); return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrangeByScoreWithScores(byte[] key, double min, double max, int offset, int count) { - client.zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count); + getClient(key).zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count); return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max, int offset, int count) { - client.zrangeByScoreWithScores(key, min, max, offset, count); + getClient(key).zrangeByScoreWithScores(key, min, max, offset, count); return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrevrangeByScore(String key, double max, double min) { - client.zrevrangeByScore(key, max, min); + getClient(key).zrevrangeByScore(key, max, min); return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrevrangeByScore(byte[] key, double max, double min) { - client.zrevrangeByScore(key, toByteArray(max), toByteArray(min)); + getClient(key).zrevrangeByScore(key, toByteArray(max), toByteArray(min)); return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrevrangeByScore(String key, String max, String min) { - client.zrevrangeByScore(key, max, min); + getClient(key).zrevrangeByScore(key, max, min); return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrevrangeByScore(byte[] key, byte[] max, byte[] min) { - client.zrevrangeByScore(key, max, min); + getClient(key).zrevrangeByScore(key, max, min); return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrevrangeByScore(String key, double max, double min, int offset, int count) { - client.zrevrangeByScore(key, max, min, offset, count); + getClient(key).zrevrangeByScore(key, max, min, offset, count); return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrevrangeByScore(byte[] key, double max, double min, int offset, int count) { - client.zrevrangeByScore(key, toByteArray(max), toByteArray(min), offset, count); + getClient(key).zrevrangeByScore(key, toByteArray(max), toByteArray(min), offset, count); return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrevrangeByScore(byte[] key, byte[] max, byte[] min, int offset, int count) { - client.zrevrangeByScore(key, max, min, offset, count); + getClient(key).zrevrangeByScore(key, max, min, offset, count); return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrevrangeByScoreWithScores(String key, double max, double min) { - client.zrevrangeByScoreWithScores(key, max, min); + getClient(key).zrevrangeByScoreWithScores(key, max, min); return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrevrangeByScoreWithScores(byte[] key, double max, double min) { - client.zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min)); + getClient(key).zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min)); return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min) { - client.zrevrangeByScoreWithScores(key, max, min); + getClient(key).zrevrangeByScoreWithScores(key, max, min); return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count) { - client.zrevrangeByScoreWithScores(key, max, min, offset, count); + getClient(key).zrevrangeByScoreWithScores(key, max, min, offset, count); return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count) { - client.zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min), offset, count); + getClient(key).zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min), offset, count); return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min, int offset, int count) { - client.zrevrangeByScoreWithScores(key, max, min, offset, count); + getClient(key).zrevrangeByScoreWithScores(key, max, min, offset, count); return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrangeWithScores(String key, int start, int end) { - client.zrangeWithScores(key, start, end); + getClient(key).zrangeWithScores(key, start, end); return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrangeWithScores(byte[] key, int start, int end) { - client.zrangeWithScores(key, start, end); + getClient(key).zrangeWithScores(key, start, end); return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response zrank(String key, String member) { - client.zrank(key, member); + getClient(key).zrank(key, member); return getResponse(BuilderFactory.LONG); } public Response zrank(byte[] key, byte[] member) { - client.zrank(key, member); + getClient(key).zrank(key, member); return getResponse(BuilderFactory.LONG); } public Response zrem(String key, String member) { - client.zrem(key, member); + getClient(key).zrem(key, member); return getResponse(BuilderFactory.LONG); } public Response zrem(byte[] key, byte[] member) { - client.zrem(key, member); + getClient(key).zrem(key, member); return getResponse(BuilderFactory.LONG); } public Response zremrangeByRank(String key, int start, int end) { - client.zremrangeByRank(key, start, end); + getClient(key).zremrangeByRank(key, start, end); return getResponse(BuilderFactory.LONG); } public Response zremrangeByRank(byte[] key, int start, int end) { - client.zremrangeByRank(key, start, end); + getClient(key).zremrangeByRank(key, start, end); return getResponse(BuilderFactory.LONG); } public Response zremrangeByScore(String key, double start, double end) { - client.zremrangeByScore(key, start, end); + getClient(key).zremrangeByScore(key, start, end); return getResponse(BuilderFactory.LONG); } public Response zremrangeByScore(byte[] key, double start, double end) { - client.zremrangeByScore(key, toByteArray(start), toByteArray(end)); + getClient(key).zremrangeByScore(key, toByteArray(start), toByteArray(end)); return getResponse(BuilderFactory.LONG); } public Response zremrangeByScore(byte[] key, byte[] start, byte[] end) { - client.zremrangeByScore(key, start, end); + getClient(key).zremrangeByScore(key, start, end); return getResponse(BuilderFactory.LONG); } public Response> zrevrange(String key, int start, int end) { - client.zrevrange(key, start, end); + getClient(key).zrevrange(key, start, end); return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrevrange(byte[] key, int start, int end) { - client.zrevrange(key, start, end); + getClient(key).zrevrange(key, start, end); return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrevrangeWithScores(String key, int start, int end) { - client.zrevrangeWithScores(key, start, end); + getClient(key).zrevrangeWithScores(key, start, end); return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrevrangeWithScores(byte[] key, int start, int end) { - client.zrevrangeWithScores(key, start, end); + getClient(key).zrevrangeWithScores(key, start, end); return getResponse(BuilderFactory.TUPLE_ZSET); } public Response zrevrank(String key, String member) { - client.zrevrank(key, member); + getClient(key).zrevrank(key, member); return getResponse(BuilderFactory.LONG); } public Response zrevrank(byte[] key, byte[] member) { - client.zrevrank(key, member); + getClient(key).zrevrank(key, member); return getResponse(BuilderFactory.LONG); } public Response zscore(String key, String member) { - client.zscore(key, member); + getClient(key).zscore(key, member); return getResponse(BuilderFactory.DOUBLE); } public Response zscore(byte[] key, byte[] member) { - client.zscore(key, member); + getClient(key).zscore(key, member); return getResponse(BuilderFactory.DOUBLE); } - public Response zunionstore(String dstkey, String... sets) { - client.zunionstore(dstkey, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response zunionstore(byte[] dstkey, byte[]... sets) { - client.zunionstore(dstkey, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response zunionstore(String dstkey, ZParams params, - String... sets) { - client.zunionstore(dstkey, params, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response zunionstore(byte[] dstkey, ZParams params, - byte[]... sets) { - client.zunionstore(dstkey, params, sets); - return getResponse(BuilderFactory.LONG); - } - - public Response bgrewriteaof() { - client.bgrewriteaof(); - return getResponse(BuilderFactory.STRING); - } - - public Response bgsave() { - client.bgsave(); - return getResponse(BuilderFactory.STRING); - } - - public Response configGet(String pattern) { - client.configGet(pattern); - return getResponse(BuilderFactory.STRING); - } - - public Response configSet(String parameter, String value) { - client.configSet(parameter, value); - return getResponse(BuilderFactory.STRING); - } - - public Response brpoplpush(String source, String destination, - int timeout) { - client.brpoplpush(source, destination, timeout); - return getResponse(BuilderFactory.STRING); - } - - public Response brpoplpush(byte[] source, byte[] destination, - int timeout) { - client.brpoplpush(source, destination, timeout); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response configResetStat() { - client.configResetStat(); - return getResponse(BuilderFactory.STRING); - } - - public Response save() { - client.save(); - return getResponse(BuilderFactory.STRING); - } - - public Response lastsave() { - client.lastsave(); - return getResponse(BuilderFactory.LONG); - } - - public Response publish(String channel, String message) { - client.publish(channel, message); - return getResponse(BuilderFactory.LONG); - } - - public Response publish(byte[] channel, byte[] message) { - client.publish(channel, message); - return getResponse(BuilderFactory.LONG); - } - - public Response randomKey() { - client.randomKey(); - return getResponse(BuilderFactory.STRING); - } - - public Response randomKeyBinary() { - client.randomKey(); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response flushDB() { - client.flushDB(); - return getResponse(BuilderFactory.STRING); - } - - public Response flushAll() { - client.flushAll(); - return getResponse(BuilderFactory.STRING); - } - - public Response info() { - client.info(); - return getResponse(BuilderFactory.STRING); - } - - public Response dbSize() { - client.dbSize(); - return getResponse(BuilderFactory.LONG); - } - - public Response shutdown() { - client.shutdown(); - return getResponse(BuilderFactory.STRING); - } - - public Response ping() { - client.ping(); - return getResponse(BuilderFactory.STRING); - } - - public Response select(int index) { - client.select(index); - return getResponse(BuilderFactory.STRING); - } - public Response bitcount(String key) { - client.bitcount(key); + getClient(key).bitcount(key); return getResponse(BuilderFactory.LONG); } public Response bitcount(String key, long start, long end) { - client.bitcount(key, start, end); + getClient(key).bitcount(key, start, end); return getResponse(BuilderFactory.LONG); } public Response bitcount(byte[] key) { - client.bitcount(key); + getClient(key).bitcount(key); return getResponse(BuilderFactory.LONG); } public Response bitcount(byte[] key, long start, long end) { - client.bitcount(key, start, end); + getClient(key).bitcount(key, start, end); return getResponse(BuilderFactory.LONG); } - public Response bitop(BitOP op, byte[] destKey, byte[]... srcKeys) { - client.bitop(op, destKey, srcKeys); - return getResponse(BuilderFactory.LONG); - } - - public Response bitop(BitOP op, String destKey, String... srcKeys) { - client.bitop(op, destKey, srcKeys); - return getResponse(BuilderFactory.LONG); - } } diff --git a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java index 2601f9c..be6db92 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java +++ b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java @@ -1,12 +1,11 @@ package redis.clients.jedis; -import redis.clients.jedis.BinaryClient.LIST_POSITION; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; -import java.util.*; - -import static redis.clients.jedis.Protocol.toByteArray; - -public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline, RedisPipeline { +public class ShardedJedisPipeline extends PipelineBase { private BinaryShardedJedis jedis; private List results = new ArrayList(); private Queue clients = new LinkedList(); @@ -27,1289 +26,6 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline this.jedis = jedis; } - public Response set(String key, String value) { - Client c = getClient(key); - c.set(key, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response set(byte[] key, byte[] value) { - Client c = getClient(key); - c.set(key, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response get(String key) { - Client c = getClient(key); - c.get(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response get(byte[] key) { - Client c = getClient(key); - c.get(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response> blpop(byte[] arg) { - byte[][] temp = new byte[1][]; - temp[0] = arg; - Client c = getClient(arg); - c.blpop(temp); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response> brpop(byte[] arg) { - byte[][] temp = new byte[1][]; - temp[0] = arg; - Client c = getClient(arg); - c.blpop(temp); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response> blpop(String arg) { - String[] temp = new String[1]; - temp[0] = arg; - Client c = getClient(arg); - c.blpop(temp); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> brpop(String arg) { - String[] temp = new String[1]; - temp[0] = arg; - Client c = getClient(arg); - c.brpop(temp); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response move(byte[] key, int dbIndex) { - Client c = getClient(key); - c.move(key, dbIndex); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response move(String key, int dbIndex) { - Client c = getClient(key); - c.move(key, dbIndex); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response echo(byte[] string) { - Client c = getClient(string); - c.echo(string); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response echo(String string) { - Client c = getClient(string); - c.echo(string); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response del(byte[] key) { - Client c = getClient(key); - c.del(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response del(String key) { - Client c = getClient(key); - c.del(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response exists(String key) { - Client c = getClient(key); - c.exists(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response exists(byte[] key) { - Client c = getClient(key); - c.exists(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response type(String key) { - Client c = getClient(key); - c.type(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response type(byte[] key) { - Client c = getClient(key); - c.type(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response expire(String key, int seconds) { - Client c = getClient(key); - c.expire(key, seconds); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response expire(byte[] key, int seconds) { - Client c = getClient(key); - c.expire(key, seconds); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response expireAt(String key, long unixTime) { - Client c = getClient(key); - c.expireAt(key, unixTime); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response expireAt(byte[] key, long unixTime) { - Client c = getClient(key); - c.expireAt(key, unixTime); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response ttl(String key) { - Client c = getClient(key); - c.ttl(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response ttl(byte[] key) { - Client c = getClient(key); - c.ttl(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response getSet(String key, String value) { - Client c = getClient(key); - c.getSet(key, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response getSet(byte[] key, byte[] value) { - Client c = getClient(key); - c.getSet(key, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response setnx(String key, String value) { - Client c = getClient(key); - c.setnx(key, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response setnx(byte[] key, byte[] value) { - Client c = getClient(key); - c.setnx(key, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response setex(String key, int seconds, String value) { - Client c = getClient(key); - c.setex(key, seconds, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response setex(byte[] key, int seconds, byte[] value) { - Client c = getClient(key); - c.setex(key, seconds, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response decrBy(String key, long integer) { - Client c = getClient(key); - c.decrBy(key, integer); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response decrBy(byte[] key, long integer) { - Client c = getClient(key); - c.decrBy(key, integer); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response decr(String key) { - Client c = getClient(key); - c.decr(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response decr(byte[] key) { - Client c = getClient(key); - c.decr(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response incrBy(String key, long integer) { - Client c = getClient(key); - c.incrBy(key, integer); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response incrBy(byte[] key, long integer) { - Client c = getClient(key); - c.incrBy(key, integer); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response incr(String key) { - Client c = getClient(key); - c.incr(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response incr(byte[] key) { - Client c = getClient(key); - c.incr(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response append(String key, String value) { - Client c = getClient(key); - c.append(key, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response append(byte[] key, byte[] value) { - Client c = getClient(key); - c.append(key, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response substr(String key, int start, int end) { - Client c = getClient(key); - c.substr(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response substr(byte[] key, int start, int end) { - Client c = getClient(key); - c.substr(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response hset(String key, String field, String value) { - Client c = getClient(key); - c.hset(key, field, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response hset(byte[] key, byte[] field, byte[] value) { - Client c = getClient(key); - c.hset(key, field, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response hget(String key, String field) { - Client c = getClient(key); - c.hget(key, field); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response hget(byte[] key, byte[] field) { - Client c = getClient(key); - c.hget(key, field); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response hsetnx(String key, String field, String value) { - Client c = getClient(key); - c.hsetnx(key, field, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response hsetnx(byte[] key, byte[] field, byte[] value) { - Client c = getClient(key); - c.hsetnx(key, field, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response hmset(String key, Map hash) { - Client c = getClient(key); - c.hmset(key, hash); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response hmset(byte[] key, Map hash) { - Client c = getClient(key); - c.hmset(key, hash); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response> hmget(String key, String... fields) { - Client c = getClient(key); - c.hmget(key, fields); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> hmget(byte[] key, byte[]... fields) { - Client c = getClient(key); - c.hmget(key, fields); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response hincrBy(String key, String field, long value) { - Client c = getClient(key); - c.hincrBy(key, field, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response hincrBy(byte[] key, byte[] field, long value) { - Client c = getClient(key); - c.hincrBy(key, field, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response hexists(String key, String field) { - Client c = getClient(key); - c.hexists(key, field); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response hexists(byte[] key, byte[] field) { - Client c = getClient(key); - c.hexists(key, field); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response hdel(String key, String field) { - Client c = getClient(key); - c.hdel(key, field); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response hdel(byte[] key, byte[] field) { - Client c = getClient(key); - c.hdel(key, field); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response hlen(String key) { - Client c = getClient(key); - c.hlen(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response hlen(byte[] key) { - Client c = getClient(key); - c.hlen(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response> hkeys(String key) { - Client c = getClient(key); - c.hkeys(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_SET); - } - - public Response> hkeys(byte[] key) { - Client c = getClient(key); - c.hkeys(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> hvals(String key) { - Client c = getClient(key); - c.hvals(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> hvals(byte[] key) { - Client c = getClient(key); - c.hvals(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response> hgetAll(String key) { - Client c = getClient(key); - c.hgetAll(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_MAP); - } - - public Response> hgetAll(byte[] key) { - Client c = getClient(key); - c.hgetAll(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_MAP); - } - - public Response rpush(String key, String string) { - Client c = getClient(key); - c.rpush(key, string); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response rpush(byte[] key, byte[] string) { - Client c = getClient(key); - c.rpush(key, string); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response rpushx(String key, String string) { - Client c = getClient(key); - c.rpushx(key, string); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response rpushx(byte[] key, byte[] string) { - Client c = getClient(key); - c.rpushx(key, string); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response lpush(String key, String string) { - Client c = getClient(key); - c.lpush(key, string); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response lpush(byte[] key, byte[] string) { - Client c = getClient(key); - c.lpush(key, string); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response lpushx(String key, String string) { - Client c = getClient(key); - c.lpushx(key, string); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response lpushx(byte[] key, byte[] bytes) { - Client c = getClient(key); - c.lpushx(key, bytes); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response llen(String key) { - Client c = getClient(key); - c.llen(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response llen(byte[] key) { - Client c = getClient(key); - c.llen(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response> lrange(String key, long start, long end) { - Client c = getClient(key); - c.lrange(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> lrange(byte[] key, long start, long end) { - Client c = getClient(key); - c.lrange(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response ltrim(String key, long start, long end) { - Client c = getClient(key); - c.ltrim(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response ltrim(byte[] key, long start, long end) { - Client c = getClient(key); - c.ltrim(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response persist(String key) { - Client c = getClient(key); - c.persist(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response persist(byte[] key) { - Client c = getClient(key); - c.persist(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response lindex(String key, int index) { - Client c = getClient(key); - c.lindex(key, index); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response lindex(byte[] key, int index) { - Client c = getClient(key); - c.lindex(key, index); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response lset(String key, long index, String value) { - Client c = getClient(key); - c.lset(key, index, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response lset(byte[] key, long index, byte[] value) { - Client c = getClient(key); - c.lset(key, index, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response lrem(String key, long count, String value) { - Client c = getClient(key); - c.lrem(key, count, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response lrem(byte[] key, long count, byte[] value) { - Client c = getClient(key); - c.lrem(key, count, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response lpop(String key) { - Client c = getClient(key); - c.lpop(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response lpop(byte[] key) { - Client c = getClient(key); - c.lpop(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response rpop(String key) { - Client c = getClient(key); - c.rpop(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response rpop(byte[] key) { - Client c = getClient(key); - c.rpop(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response sadd(String key, String member) { - Client c = getClient(key); - c.sadd(key, member); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response sadd(byte[] key, byte[] member) { - Client c = getClient(key); - c.sadd(key, member); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response> smembers(String key) { - Client c = getClient(key); - c.smembers(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_SET); - } - - public Response> smembers(byte[] key) { - Client c = getClient(key); - c.smembers(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response srem(String key, String member) { - Client c = getClient(key); - c.srem(key, member); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response srem(byte[] key, byte[] member) { - Client c = getClient(key); - c.srem(key, member); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response strlen(String key) { - Client c = getClient(key); - c.strlen(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response strlen(byte[] key) { - Client c = getClient(key); - c.strlen(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response spop(String key) { - Client c = getClient(key); - c.spop(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response spop(byte[] key) { - Client c = getClient(key); - c.spop(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response scard(String key) { - Client c = getClient(key); - c.scard(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response scard(byte[] key) { - Client c = getClient(key); - c.scard(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response sismember(String key, String member) { - Client c = getClient(key); - c.sismember(key, member); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response sismember(byte[] key, byte[] member) { - Client c = getClient(key); - c.sismember(key, member); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response srandmember(String key) { - Client c = getClient(key); - c.srandmember(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response srandmember(byte[] key) { - Client c = getClient(key); - c.srandmember(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY); - } - - public Response zadd(String key, double score, String member) { - Client c = getClient(key); - c.zadd(key, score, member); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response zadd(byte[] key, double score, byte[] member) { - Client c = getClient(key); - c.zadd(key, score, member); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response> zrange(String key, int start, int end) { - Client c = getClient(key); - c.zrange(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrange(byte[] key, int start, int end) { - Client c = getClient(key); - c.zrange(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response zrem(String key, String member) { - Client c = getClient(key); - c.zrem(key, member); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response zrem(byte[] key, byte[] member) { - Client c = getClient(key); - c.zrem(key, member); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response zincrby(String key, double score, String member) { - Client c = getClient(key); - c.zincrby(key, score, member); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.DOUBLE); - } - - public Response zincrby(byte[] key, double score, byte[] member) { - Client c = getClient(key); - c.zincrby(key, score, member); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.DOUBLE); - } - - public Response zrank(String key, String member) { - Client c = getClient(key); - c.zrank(key, member); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response zrank(byte[] key, byte[] member) { - Client c = getClient(key); - c.zrank(key, member); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response zrevrank(String key, String member) { - Client c = getClient(key); - c.zrevrank(key, member); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response zrevrank(byte[] key, byte[] member) { - Client c = getClient(key); - c.zrevrank(key, member); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response> zrevrange(String key, int start, int end) { - Client c = getClient(key); - c.zrevrange(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrevrange(byte[] key, int start, int end) { - Client c = getClient(key); - c.zrevrange(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrangeWithScores(String key, int start, int end) { - Client c = getClient(key); - c.zrangeWithScores(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrangeWithScores(byte[] key, int start, int end) { - Client c = getClient(key); - c.zrangeWithScores(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrevrangeWithScores(String key, int start, int end) { - Client c = getClient(key); - c.zrevrangeWithScores(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrevrangeWithScores(byte[] key, int start, int end) { - Client c = getClient(key); - c.zrevrangeWithScores(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response zcard(String key) { - Client c = getClient(key); - c.zcard(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response zcard(byte[] key) { - Client c = getClient(key); - c.zcard(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response zscore(String key, String member) { - Client c = getClient(key); - c.zscore(key, member); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.DOUBLE); - } - - public Response zscore(byte[] key, byte[] member) { - Client c = getClient(key); - c.zscore(key, member); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.DOUBLE); - } - - public Response> sort(String key) { - Client c = getClient(key); - c.sort(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> sort(byte[] key) { - Client c = getClient(key); - c.sort(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response> sort(String key, SortingParams sortingParameters) { - Client c = getClient(key); - c.sort(key, sortingParameters); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_LIST); - } - - public Response> sort(byte[] key, SortingParams sortingParameters) { - Client c = getClient(key); - c.sort(key, sortingParameters); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); - } - - public Response zcount(String key, double min, double max) { - Client c = getClient(key); - c.zcount(key, min, max); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response zcount(byte[] key, double min, double max) { - Client c = getClient(key); - c.zcount(key, toByteArray(min), toByteArray(max)); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response> zrevrangeByScore(String key, String max, String min) { - Client c = getClient(key); - c.zrevrangeByScore(key, min, max); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrevrangeByScore(String key, double max, double min) { - Client c = getClient(key); - c.zrevrangeByScore(key, min, max); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrevrangeByScore(byte[] key, double max, double min) { - Client c = getClient(key); - c.zrevrangeByScore(key, toByteArray(min), toByteArray(max)); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrevrangeByScore(byte[] key, byte[] max, byte[] min) { - Client c = getClient(key); - c.zrevrangeByScore(key, min, max); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrevrangeByScore(String key, double max, double min, int offset, int count) { - Client c = getClient(key); - c.zrevrangeByScore(key, min, max, offset, count); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrevrangeByScore(byte[] key, double max, double min, int offset, int count) { - Client c = getClient(key); - c.zrevrangeByScore(key, toByteArray(min), toByteArray(max), offset, count); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrevrangeByScore(byte[] key, byte[] max, byte[] min, int offset, int count) { - Client c = getClient(key); - c.zrevrangeByScore(key, min, max, offset, count); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrangeByScore(String key, String min, String max) { - Client c = getClient(key); - c.zrangeByScore(key, min, max); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrangeByScore(String key, double min, double max) { - Client c = getClient(key); - c.zrangeByScore(key, min, max); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrangeByScore(byte[] key, double min, double max) { - Client c = getClient(key); - c.zrangeByScore(key, toByteArray(min), toByteArray(max)); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrangeByScore(byte[] key, byte[] min, byte[] max) { - Client c = getClient(key); - c.zrangeByScore(key, min, max); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrangeByScore(String key, double min, double max, - int offset, int count) { - Client c = getClient(key); - c.zrangeByScore(key, min, max, offset, count); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING_ZSET); - } - - public Response> zrangeByScore(byte[] key, double min, double max, - int offset, int count) { - Client c = getClient(key); - c.zrangeByScore(key, toByteArray(min), toByteArray(max), offset, count); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrangeByScore(byte[] key, byte[] min, byte[] max, - int offset, int count) { - Client c = getClient(key); - c.zrangeByScore(key, min, max, offset, count); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - - public Response> zrangeByScoreWithScores(String key, double min, double max) { - Client c = getClient(key); - c.zrangeByScoreWithScores(key, min, max); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrangeByScoreWithScores(byte[] key, double min, double max) { - Client c = getClient(key); - c.zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max)); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max) { - Client c = getClient(key); - c.zrangeByScoreWithScores(key, min, max); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrangeByScoreWithScores(String key, double min, double max, - int offset, int count) { - Client c = getClient(key); - c.zrangeByScoreWithScores(key, min, max, offset, count); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrangeByScoreWithScores(byte[] key, double min, double max, - int offset, int count) { - Client c = getClient(key); - c.zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max, - int offset, int count) { - Client c = getClient(key); - c.zrangeByScoreWithScores(key, min, max, offset, count); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrevrangeByScoreWithScores(String key, double max, double min) { - Client c = getClient(key); - c.zrevrangeByScoreWithScores(key, min, max); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrevrangeByScoreWithScores(byte[] key, double max, double min) { - Client c = getClient(key); - c.zrevrangeByScoreWithScores(key, toByteArray(min), toByteArray(max)); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min) { - Client c = getClient(key); - c.zrevrangeByScoreWithScores(key, min, max); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count) { - Client c = getClient(key); - c.zrevrangeByScoreWithScores(key, min, max, offset, count); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count) { - Client c = getClient(key); - c.zrevrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min, int offset, int count) { - Client c = getClient(key); - c.zrevrangeByScoreWithScores(key, min, max, offset, count); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.TUPLE_ZSET); - } - - public Response zremrangeByRank(String key, int start, int end) { - Client c = getClient(key); - c.zremrangeByRank(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response zremrangeByRank(byte[] key, int start, int end) { - Client c = getClient(key); - c.zremrangeByRank(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response zremrangeByScore(String key, double start, double end) { - Client c = getClient(key); - c.zremrangeByScore(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response zremrangeByScore(byte[] key, double start, double end) { - Client c = getClient(key); - c.zremrangeByScore(key, toByteArray(start), toByteArray(end)); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response zremrangeByScore(byte[] key, byte[] start, byte[] end) { - Client c = getClient(key); - c.zremrangeByScore(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response linsert(String key, LIST_POSITION where, String pivot, - String value) { - Client c = getClient(key); - c.linsert(key, where, pivot, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response linsert(byte[] key, LIST_POSITION where, byte[] pivot, - byte[] value) { - Client c = getClient(key); - c.linsert(key, where, pivot, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response getbit(String key, long offset) { - Client c = getClient(key); - c.getbit(key, offset); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response getbit(byte[] key, long offset) { - Client c = getClient(key); - c.getbit(key, offset); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response setbit(String key, long offset, boolean value) { - Client c = getClient(key); - c.setbit(key, offset, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response setbit(byte[] key, long offset, byte[] value) { - Client c = getClient(key); - c.setbit(key, offset, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.BOOLEAN); - } - - public Response setrange(String key, long offset, String value) { - Client c = getClient(key); - c.setrange(key, offset, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response setrange(byte[] key, long offset, byte[] value) { - Client c = getClient(key); - c.setrange(key, offset, value); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response getrange(String key, long startOffset, long endOffset) { - Client c = getClient(key); - c.getrange(key, startOffset, endOffset); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.STRING); - } - - public Response getrange(byte[] key, long startOffset, long endOffset) { - Client c = getClient(key); - c.getrange(key, startOffset, endOffset); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response bitcount(String key) { - Client c = getClient(key); - c.bitcount(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response bitcount(String key, long start, long end) { - Client c = getClient(key); - c.bitcount(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response bitcount(byte[] key) { - Client c = getClient(key); - c.bitcount(key); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - - public Response bitcount(byte[] key, long start, long end) { - Client c = getClient(key); - c.bitcount(key, start, end); - results.add(new FutureResult(c)); - return getResponse(BuilderFactory.LONG); - } - public List getResults() { List r = new ArrayList(); for (FutureResult fr : results) { @@ -1353,15 +69,19 @@ public class ShardedJedisPipeline extends Queable implements BinaryRedisPipeline public void execute() { } - private Client getClient(String key) { + @Override + protected Client getClient(String key) { Client client = jedis.getShard(key).getClient(); clients.add(client); + results.add(new FutureResult(client)); return client; } - private Client getClient(byte[] key) { + @Override + protected Client getClient(byte[] key) { Client client = jedis.getShard(key).getClient(); clients.add(client); + results.add(new FutureResult(client)); return client; } } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/Transaction.java b/src/main/java/redis/clients/jedis/Transaction.java index 1629b59..bca7157 100644 --- a/src/main/java/redis/clients/jedis/Transaction.java +++ b/src/main/java/redis/clients/jedis/Transaction.java @@ -8,7 +8,7 @@ import java.util.List; /** * Transaction is nearly identical to Pipeline, only differences are the multi/discard behaviors */ -public class Transaction extends PipelineBase { +public class Transaction extends MultiKeyPipelineBase { protected boolean inTransaction = true; @@ -20,6 +20,16 @@ public class Transaction extends PipelineBase { this.client = client; } + @Override + protected Client getClient(String key) { + return client; + } + + @Override + protected Client getClient(byte[] key) { + return client; + } + public List exec() { client.exec(); client.getAll(1); // Discard all but the last reply diff --git a/src/main/java/redis/clients/jedis/TransactionBlock.java b/src/main/java/redis/clients/jedis/TransactionBlock.java index 87df232..e784e19 100644 --- a/src/main/java/redis/clients/jedis/TransactionBlock.java +++ b/src/main/java/redis/clients/jedis/TransactionBlock.java @@ -13,6 +13,6 @@ public abstract class TransactionBlock extends Transaction { public abstract void execute() throws JedisException; public void setClient(Client client) { - this.client = client; + this.client = client; } } From 258ac300fce65be8caaf6a91eda2f5a5f2612b05 Mon Sep 17 00:00:00 2001 From: samhendley Date: Thu, 10 Jan 2013 02:39:48 -0500 Subject: [PATCH 093/112] added variadic versions of lpush/rpush(x) functions --- .../redis/clients/jedis/BinaryClient.java | 8 ++--- .../java/redis/clients/jedis/BinaryJedis.java | 4 +-- .../clients/jedis/BinaryJedisCommands.java | 4 +-- .../clients/jedis/BinaryRedisPipeline.java | 10 +++---- .../clients/jedis/BinaryShardedJedis.java | 4 +-- src/main/java/redis/clients/jedis/Client.java | 8 ++--- .../java/redis/clients/jedis/Commands.java | 4 +-- src/main/java/redis/clients/jedis/Jedis.java | 4 +-- .../redis/clients/jedis/JedisCommands.java | 4 +-- .../redis/clients/jedis/PipelineBase.java | 30 +++++++------------ .../redis/clients/jedis/RedisPipeline.java | 10 +++---- .../redis/clients/jedis/ShardedJedis.java | 4 +-- 12 files changed, 42 insertions(+), 52 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index 34fe202..032a2c1 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -677,16 +677,16 @@ public class BinaryClient extends Connection { sendCommand(SYNC); } - public void lpushx(final byte[] key, final byte[] string) { - sendCommand(LPUSHX, key, string); + public void lpushx(final byte[] key, final byte[]... string) { + sendCommand(LPUSHX, joinParameters(key, string)); } public void persist(final byte[] key) { sendCommand(PERSIST, key); } - public void rpushx(final byte[] key, final byte[] string) { - sendCommand(RPUSHX, key, string); + public void rpushx(final byte[] key, final byte[]... string) { + sendCommand(RPUSHX, joinParameters(key, string)); } public void echo(final byte[] string) { diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 06a83de..d4d0a08 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -2979,7 +2979,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey client.sync(); } - public Long lpushx(final byte[] key, final byte[] string) { + public Long lpushx(final byte[] key, final byte[]... string) { client.lpushx(key, string); return client.getIntegerReply(); } @@ -2999,7 +2999,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey return client.getIntegerReply(); } - public Long rpushx(final byte[] key, final byte[] string) { + public Long rpushx(final byte[] key, final byte[]... string) { client.rpushx(key, string); return client.getIntegerReply(); } diff --git a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java index a6da912..35e1879 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java +++ b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java @@ -196,9 +196,9 @@ public interface BinaryJedisCommands { Long linsert(byte[] key, Client.LIST_POSITION where, byte[] pivot, byte[] value); - Long lpushx(byte[] key, byte[] arg); + Long lpushx(byte[] key, byte[]... arg); - Long rpushx(byte[] key, byte[] arg); + Long rpushx(byte[] key, byte[]... arg); List blpop(byte[] arg); diff --git a/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java b/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java index 5c04491..6f4fd90 100644 --- a/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java +++ b/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java @@ -73,9 +73,9 @@ public interface BinaryRedisPipeline { Response lpop(byte[] key); - Response lpush(byte[] key, byte[] string); + Response lpush(byte[] key, byte[]... string); - Response lpushx(byte[] key, byte[] bytes); + Response lpushx(byte[] key, byte[]... bytes); Response> lrange(byte[] key, long start, long end); @@ -91,11 +91,11 @@ public interface BinaryRedisPipeline { Response rpop(byte[] key); - Response rpush(byte[] key, byte[] string); + Response rpush(byte[] key, byte[]... string); - Response rpushx(byte[] key, byte[] string); + Response rpushx(byte[] key, byte[]... string); - Response sadd(byte[] key, byte[] member); + Response sadd(byte[] key, byte[]... member); Response scard(byte[] key); diff --git a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java index 20065d7..2723aa1 100644 --- a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java @@ -201,7 +201,7 @@ public class BinaryShardedJedis extends Sharded return j.strlen(key); } - public Long lpushx(byte[] key, byte[] string) { + public Long lpushx(byte[] key, byte[]... string) { Jedis j = getShard(key); return j.lpushx(key, string); } @@ -211,7 +211,7 @@ public class BinaryShardedJedis extends Sharded return j.persist(key); } - public Long rpushx(byte[] key, byte[] string) { + public Long rpushx(byte[] key, byte[]... string) { Jedis j = getShard(key); return j.rpushx(key, string); } diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index 9e17202..f331f5e 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -564,16 +564,16 @@ public class Client extends BinaryClient implements Commands { strlen(SafeEncoder.encode(key)); } - public void lpushx(final String key, final String string) { - lpushx(SafeEncoder.encode(key), SafeEncoder.encode(string)); + public void lpushx(final String key, final String... string) { + lpushx(SafeEncoder.encode(key), getByteParams(string)); } public void persist(final String key) { persist(SafeEncoder.encode(key)); } - public void rpushx(final String key, final String string) { - rpushx(SafeEncoder.encode(key), SafeEncoder.encode(string)); + public void rpushx(final String key, final String... string) { + rpushx(SafeEncoder.encode(key), getByteParams(string)); } public void echo(final String string) { diff --git a/src/main/java/redis/clients/jedis/Commands.java b/src/main/java/redis/clients/jedis/Commands.java index a5df878..7d0e60d 100644 --- a/src/main/java/redis/clients/jedis/Commands.java +++ b/src/main/java/redis/clients/jedis/Commands.java @@ -251,11 +251,11 @@ public interface Commands { public void strlen(final String key); - public void lpushx(final String key, final String string); + public void lpushx(final String key, final String... string); public void persist(final String key); - public void rpushx(final String key, final String string); + public void rpushx(final String key, final String... string); public void echo(final String string); diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index d8dbb56..39f26d2 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -2535,7 +2535,7 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand return client.getIntegerReply(); } - public Long lpushx(final String key, final String string) { + public Long lpushx(final String key, final String... string) { client.lpushx(key, string); return client.getIntegerReply(); } @@ -2555,7 +2555,7 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand return client.getIntegerReply(); } - public Long rpushx(final String key, final String string) { + public Long rpushx(final String key, final String... string) { client.rpushx(key, string); return client.getIntegerReply(); } diff --git a/src/main/java/redis/clients/jedis/JedisCommands.java b/src/main/java/redis/clients/jedis/JedisCommands.java index 2dab095..ea5016b 100644 --- a/src/main/java/redis/clients/jedis/JedisCommands.java +++ b/src/main/java/redis/clients/jedis/JedisCommands.java @@ -193,9 +193,9 @@ public interface JedisCommands { Long linsert(String key, Client.LIST_POSITION where, String pivot, String value); - Long lpushx(String key, String string); + Long lpushx(String key, String... string); - Long rpushx(String key, String string); + Long rpushx(String key, String... string); List blpop(String arg); diff --git a/src/main/java/redis/clients/jedis/PipelineBase.java b/src/main/java/redis/clients/jedis/PipelineBase.java index 2af0899..2ceeeec 100644 --- a/src/main/java/redis/clients/jedis/PipelineBase.java +++ b/src/main/java/redis/clients/jedis/PipelineBase.java @@ -305,16 +305,6 @@ abstract class PipelineBase extends Queable implements return getResponse(BuilderFactory.LONG); } - public Response> keys(String pattern) { - getClient(pattern).keys(pattern); - return getResponse(BuilderFactory.STRING_SET); - } - - public Response> keys(byte[] pattern) { - getClient(pattern).keys(pattern); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); - } - public Response lindex(String key, int index) { getClient(key).lindex(key, index); return getResponse(BuilderFactory.STRING); @@ -357,22 +347,22 @@ abstract class PipelineBase extends Queable implements return getResponse(BuilderFactory.BYTE_ARRAY); } - public Response lpush(String key, String string) { + public Response lpush(String key, String... string) { getClient(key).lpush(key, string); return getResponse(BuilderFactory.LONG); } - public Response lpush(byte[] key, byte[] string) { + public Response lpush(byte[] key, byte[]... string) { getClient(key).lpush(key, string); return getResponse(BuilderFactory.LONG); } - public Response lpushx(String key, String string) { + public Response lpushx(String key, String... string) { getClient(key).lpushx(key, string); return getResponse(BuilderFactory.LONG); } - public Response lpushx(byte[] key, byte[] bytes) { + public Response lpushx(byte[] key, byte[]... bytes) { getClient(key).lpushx(key, bytes); return getResponse(BuilderFactory.LONG); } @@ -447,32 +437,32 @@ abstract class PipelineBase extends Queable implements return getResponse(BuilderFactory.BYTE_ARRAY); } - public Response rpush(String key, String string) { + public Response rpush(String key, String... string) { getClient(key).rpush(key, string); return getResponse(BuilderFactory.LONG); } - public Response rpush(byte[] key, byte[] string) { + public Response rpush(byte[] key, byte[]... string) { getClient(key).rpush(key, string); return getResponse(BuilderFactory.LONG); } - public Response rpushx(String key, String string) { + public Response rpushx(String key, String... string) { getClient(key).rpushx(key, string); return getResponse(BuilderFactory.LONG); } - public Response rpushx(byte[] key, byte[] string) { + public Response rpushx(byte[] key, byte[]... string) { getClient(key).rpushx(key, string); return getResponse(BuilderFactory.LONG); } - public Response sadd(String key, String member) { + public Response sadd(String key, String... member) { getClient(key).sadd(key, member); return getResponse(BuilderFactory.LONG); } - public Response sadd(byte[] key, byte[] member) { + public Response sadd(byte[] key, byte[]... member) { getClient(key).sadd(key, member); return getResponse(BuilderFactory.LONG); } diff --git a/src/main/java/redis/clients/jedis/RedisPipeline.java b/src/main/java/redis/clients/jedis/RedisPipeline.java index b1c8461..43b7516 100644 --- a/src/main/java/redis/clients/jedis/RedisPipeline.java +++ b/src/main/java/redis/clients/jedis/RedisPipeline.java @@ -76,9 +76,9 @@ public interface RedisPipeline { Response lpop(String key); - Response lpush(String key, String string); + Response lpush(String key, String... string); - Response lpushx(String key, String string); + Response lpushx(String key, String... string); Response> lrange(String key, long start, long end); @@ -94,11 +94,11 @@ public interface RedisPipeline { Response rpop(String key); - Response rpush(String key, String string); + Response rpush(String key, String... string); - Response rpushx(String key, String string); + Response rpushx(String key, String... string); - Response sadd(String key, String member); + Response sadd(String key, String... member); Response scard(String key); diff --git a/src/main/java/redis/clients/jedis/ShardedJedis.java b/src/main/java/redis/clients/jedis/ShardedJedis.java index 948718c..485f83a 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedis.java +++ b/src/main/java/redis/clients/jedis/ShardedJedis.java @@ -221,7 +221,7 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { return j.lpush(key, strings); } - public Long lpushx(String key, String string) { + public Long lpushx(String key, String... string) { Jedis j = getShard(key); return j.lpushx(key, string); } @@ -236,7 +236,7 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { return j.move(key, dbIndex); } - public Long rpushx(String key, String string) { + public Long rpushx(String key, String... string) { Jedis j = getShard(key); return j.rpushx(key, string); } From 406d52b271b8669c5461c97e88a17480cfd8a674 Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Wed, 30 Jan 2013 10:41:12 -0300 Subject: [PATCH 094/112] fix tests, since ttl now return -2 or -1 depending if the key exists already --- .../jedis/tests/commands/AllKindOfValuesCommandsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java index d7df713..855a35d 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java @@ -300,7 +300,7 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase { @Test public void ttl() { long ttl = jedis.ttl("foo"); - assertEquals(-1, ttl); + assertEquals(-2, ttl); jedis.set("foo", "bar"); ttl = jedis.ttl("foo"); @@ -312,7 +312,7 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase { // Binary long bttl = jedis.ttl(bfoo); - assertEquals(-1, bttl); + assertEquals(-2, bttl); jedis.set(bfoo, bbar); bttl = jedis.ttl(bfoo); From 23e50a363e621ef9b5996233c53445e9f8ed3e13 Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Wed, 30 Jan 2013 15:24:53 -0300 Subject: [PATCH 095/112] Change the way we test sentinel commands so it is automatic --- Makefile | 16 ++++++++++ .../jedis/tests/JedisSentinelTest.java | 31 +++++++++++++++---- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 0e31379..00f29bf 100644 --- a/Makefile +++ b/Makefile @@ -12,15 +12,31 @@ requirepass foobared pidfile /tmp/redis2.pid endef + +define REDIS_SENTINEL1 +port 26379 +daemonize yes +sentinel monitor mymaster 127.0.0.1 6379 2 +sentinel auth-pass mymaster foobared +sentinel down-after-milliseconds mymaster 5000 +sentinel failover-timeout mymaster 900000 +sentinel can-failover mymaster yes +sentinel parallel-syncs mymaster 1 +pidfile /tmp/sentinel1.pid +endef + export REDIS1_CONF export REDIS2_CONF +export REDIS_SENTINEL1 test: echo "$$REDIS1_CONF" | redis-server - echo "$$REDIS2_CONF" | redis-server - + echo "$$REDIS_SENTINEL1" | redis-sentinel - mvn clean compile test kill `cat /tmp/redis1.pid` kill `cat /tmp/redis2.pid` + kill `cat /tmp/sentinel1.pid` .PHONY: test diff --git a/src/test/java/redis/clients/jedis/tests/JedisSentinelTest.java b/src/test/java/redis/clients/jedis/tests/JedisSentinelTest.java index 0bca18c..7cd8188 100644 --- a/src/test/java/redis/clients/jedis/tests/JedisSentinelTest.java +++ b/src/test/java/redis/clients/jedis/tests/JedisSentinelTest.java @@ -1,22 +1,40 @@ package redis.clients.jedis.tests; -import static junit.framework.Assert.*; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertTrue; import java.util.List; import java.util.Map; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import redis.clients.jedis.Jedis; public class JedisSentinelTest { - private static final String MASTER_NAME = "mymaster"; - /** - * Based on redis/master/slave/sentinel configs from - * https://github.com/noise/redis-sentinel-tests. - */ + @Before + public void setup() throws InterruptedException { + Jedis j = new Jedis("localhost", 6380); + j.auth("foobared"); + j.configSet("masterauth", "foobared"); + j.slaveof("localhost", 6379); + // TODO: The sleep is to give time to the slave to synchronize with the + // master and also let know the sentinels about this new topology. We + // should find a better way to do this. + Thread.sleep(5000); + } + + @After + public void clear() { + Jedis j = new Jedis("localhost", 6380); + j.auth("foobared"); + j.slaveofNoOne(); + } + @Test public void sentinel() { Jedis j = new Jedis("localhost", 26379); @@ -45,5 +63,6 @@ public class JedisSentinelTest { // DO NOT RE-RUN TEST TOO FAST, RESET TAKES SOME TIME TO... RESET assertEquals(Long.valueOf(1), j.sentinelReset(masterName)); assertEquals(Long.valueOf(0), j.sentinelReset("woof" + masterName)); + } } From 9d538a06fd9145dcf6e44008c2a1648fadf4f5c0 Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Tue, 5 Feb 2013 15:44:35 -0300 Subject: [PATCH 096/112] when a script returns Null value, jedis throws NullPointerException --- src/main/java/redis/clients/jedis/Jedis.java | 8 +- .../tests/commands/ScriptingCommandsTest.java | 216 ++++++++++-------- 2 files changed, 120 insertions(+), 104 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index bca74d0..f30990d 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -2768,15 +2768,17 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand private Object getEvalResult() { Object result = client.getOne(); - + if (result instanceof byte[]) return SafeEncoder.encode((byte[]) result); if (result instanceof List) { List list = (List) result; List listResult = new ArrayList(list.size()); - for (Object bin : list) - listResult.add(SafeEncoder.encode((byte[]) bin)); + for (Object bin : list) { + listResult.add((bin == null ? null : SafeEncoder + .encode((byte[]) bin))); + } return listResult; } diff --git a/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java index ed59799..a3675d4 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java @@ -6,133 +6,147 @@ import java.util.List; import org.junit.Test; import redis.clients.jedis.exceptions.JedisDataException; -import redis.clients.jedis.exceptions.JedisException; import redis.clients.util.SafeEncoder; public class ScriptingCommandsTest extends JedisCommandTestBase { - + @SuppressWarnings("unchecked") - @Test + @Test public void evalMultiBulk() { - String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}"; - List keys = new ArrayList(); - keys.add("key1"); - keys.add("key2"); - - List args = new ArrayList(); - args.add("first"); - args.add("second"); - - List response = (List)jedis.eval(script, keys, args ); - - assertEquals(4, response.size()); - assertEquals("key1", response.get(0)); - assertEquals("key2", response.get(1)); - assertEquals("first", response.get(2)); - assertEquals("second", response.get(3)); + String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}"; + List keys = new ArrayList(); + keys.add("key1"); + keys.add("key2"); + + List args = new ArrayList(); + args.add("first"); + args.add("second"); + + List response = (List) jedis.eval(script, keys, args); + + assertEquals(4, response.size()); + assertEquals("key1", response.get(0)); + assertEquals("key2", response.get(1)); + assertEquals("first", response.get(2)); + assertEquals("second", response.get(3)); } - - @Test + + @Test public void evalBulk() { - String script = "return KEYS[1]"; - List keys = new ArrayList(); - keys.add("key1"); - - List args = new ArrayList(); - args.add("first"); - - String response = (String)jedis.eval(script, keys, args); - - assertEquals("key1", response); + String script = "return KEYS[1]"; + List keys = new ArrayList(); + keys.add("key1"); + + List args = new ArrayList(); + args.add("first"); + + String response = (String) jedis.eval(script, keys, args); + + assertEquals("key1", response); } - - @Test + + @Test public void evalInt() { - String script = "return 2"; - List keys = new ArrayList(); - keys.add("key1"); - - Long response = (Long)jedis.eval(script, keys, new ArrayList()); - - assertEquals(new Long(2), response); + String script = "return 2"; + List keys = new ArrayList(); + keys.add("key1"); + + Long response = (Long) jedis + .eval(script, keys, new ArrayList()); + + assertEquals(new Long(2), response); } - - @Test + + @Test public void evalNoArgs() { - String script = "return KEYS[1]"; - List keys = new ArrayList(); - keys.add("key1"); - String response = (String)jedis.eval(script, keys, new ArrayList()); - - assertEquals("key1", response); + String script = "return KEYS[1]"; + List keys = new ArrayList(); + keys.add("key1"); + String response = (String) jedis.eval(script, keys, + new ArrayList()); + + assertEquals("key1", response); } - - @SuppressWarnings("unchecked") - @Test + + @Test public void evalsha() { - jedis.set("foo", "bar"); - jedis.eval("return redis.call('get','foo')"); - String result = (String)jedis.evalsha("6b1bf486c81ceb7edf3c093f4c48582e38c0e791"); - - assertEquals("bar", result); + jedis.set("foo", "bar"); + jedis.eval("return redis.call('get','foo')"); + String result = (String) jedis + .evalsha("6b1bf486c81ceb7edf3c093f4c48582e38c0e791"); + + assertEquals("bar", result); } - - @SuppressWarnings("unchecked") - @Test(expected=JedisDataException.class) + + @Test(expected = JedisDataException.class) public void evalshaShaNotFound() { - jedis.evalsha("ffffffffffffffffffffffffffffffffffffffff"); + jedis.evalsha("ffffffffffffffffffffffffffffffffffffffff"); } - - @SuppressWarnings("unchecked") - @Test + + @Test public void scriptFlush() { - jedis.set("foo", "bar"); - jedis.eval("return redis.call('get','foo')"); - jedis.scriptFlush(); - assertFalse(jedis.scriptExists("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); + jedis.set("foo", "bar"); + jedis.eval("return redis.call('get','foo')"); + jedis.scriptFlush(); + assertFalse(jedis + .scriptExists("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); } - - @SuppressWarnings("unchecked") - @Test + + @Test public void scriptExists() { - jedis.scriptLoad("return redis.call('get','foo')"); - List exists = jedis.scriptExists("ffffffffffffffffffffffffffffffffffffffff","6b1bf486c81ceb7edf3c093f4c48582e38c0e791"); - assertFalse(exists.get(0)); - assertTrue(exists.get(1)); + jedis.scriptLoad("return redis.call('get','foo')"); + List exists = jedis.scriptExists( + "ffffffffffffffffffffffffffffffffffffffff", + "6b1bf486c81ceb7edf3c093f4c48582e38c0e791"); + assertFalse(exists.get(0)); + assertTrue(exists.get(1)); } - - @SuppressWarnings("unchecked") - @Test + + @Test public void scriptExistsBinary() { - jedis.scriptLoad(SafeEncoder.encode("return redis.call('get','foo')")); - List exists = jedis.scriptExists(SafeEncoder.encode("ffffffffffffffffffffffffffffffffffffffff"),SafeEncoder.encode("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); - assertEquals(new Long(0), exists.get(0)); - assertEquals(new Long(1), exists.get(1)); + jedis.scriptLoad(SafeEncoder.encode("return redis.call('get','foo')")); + List exists = jedis.scriptExists( + SafeEncoder.encode("ffffffffffffffffffffffffffffffffffffffff"), + SafeEncoder.encode("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); + assertEquals(new Long(0), exists.get(0)); + assertEquals(new Long(1), exists.get(1)); } - - @SuppressWarnings("unchecked") - @Test + + @Test public void scriptLoad() { - jedis.scriptLoad("return redis.call('get','foo')"); - assertTrue(jedis.scriptExists("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); + jedis.scriptLoad("return redis.call('get','foo')"); + assertTrue(jedis + .scriptExists("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); } - - @SuppressWarnings("unchecked") - @Test + + @Test public void scriptLoadBinary() { - jedis.scriptLoad(SafeEncoder.encode("return redis.call('get','foo')")); - List exists = jedis.scriptExists(SafeEncoder.encode("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); - assertEquals(new Long(1), exists.get(0)); + jedis.scriptLoad(SafeEncoder.encode("return redis.call('get','foo')")); + List exists = jedis.scriptExists(SafeEncoder + .encode("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); + assertEquals(new Long(1), exists.get(0)); } - - @SuppressWarnings("unchecked") - @Test + + @Test public void scriptKill() { - try { - jedis.scriptKill(); - } - catch(JedisDataException e) { - assertTrue(e.getMessage().contains("No scripts in execution right now.")); - } + try { + jedis.scriptKill(); + } catch (JedisDataException e) { + assertTrue(e.getMessage().contains( + "No scripts in execution right now.")); } + } + + @Test + public void scriptEvalReturnNullValues() { + String script = "return {redis.call('hget',KEYS[1],ARGV[1]),redis.call('hget',KEYS[2],ARGV[2])}"; + jedis.eval(script, 2, "key1", "key2", "1", "1"); + } + + @Test + public void scriptEvalShaReturnNullValues() { + String script = "return {redis.call('hget',KEYS[1],ARGV[1]),redis.call('hget',KEYS[2],ARGV[2])}"; + String sha = jedis.scriptLoad(script); + jedis.evalsha(sha, 2, "key1", "key2", "1", "1"); + } } \ No newline at end of file From 69f5340aa683a3d13aa2e8f9111cc560519c940c Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Tue, 5 Feb 2013 15:55:48 -0300 Subject: [PATCH 097/112] add info optional parameter --- src/main/java/redis/clients/jedis/BasicCommands.java | 2 ++ src/main/java/redis/clients/jedis/BinaryClient.java | 4 ++++ src/main/java/redis/clients/jedis/BinaryJedis.java | 5 +++++ .../clients/jedis/tests/commands/ControlCommandsTest.java | 2 ++ 4 files changed, 13 insertions(+) diff --git a/src/main/java/redis/clients/jedis/BasicCommands.java b/src/main/java/redis/clients/jedis/BasicCommands.java index fa4ee2d..482d43b 100644 --- a/src/main/java/redis/clients/jedis/BasicCommands.java +++ b/src/main/java/redis/clients/jedis/BasicCommands.java @@ -27,6 +27,8 @@ public interface BasicCommands { String shutdown(); String info(); + + String info(String section); String slaveof(String host, int port); diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index c6ac461..81c0c2f 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -648,6 +648,10 @@ public class BinaryClient extends Connection { public void info() { sendCommand(INFO); } + + public void info(final String section) { + sendCommand(INFO, section); + } public void monitor() { sendCommand(MONITOR); diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index d4d0a08..4c65974 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -2825,6 +2825,11 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey client.info(); return client.getBulkReply(); } + + public String info(final String section) { + client.info(section); + return client.getBulkReply(); + } /** * Dump all the received requests in real time. diff --git a/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java index 7e59335..fbc7d8e 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java @@ -58,6 +58,8 @@ public class ControlCommandsTest extends JedisCommandTestBase { public void info() { String info = jedis.info(); assertNotNull(info); + info = jedis.info("server"); + assertNotNull(info); } @Test From 62c30dfe8b84ebb0bc67b54d9f77ec1d292c4317 Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Thu, 2 May 2013 08:48:48 -0300 Subject: [PATCH 098/112] change licensing info --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 0c75299..54a2657 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ 2.2.0-SNAPSHOT Jedis Jedis is a blazingly small and sane Redis java client. - http://code.google.com/p/jedis/ + https://github.com/xetorthio/jedis @@ -27,7 +27,7 @@ - Jedis License + MIT http://github.com/xetorthio/jedis/raw/master/LICENSE.txt repo From 20a75417cd40ef7195bcc804383212d62a908a6c Mon Sep 17 00:00:00 2001 From: mindwind Date: Sat, 29 Jun 2013 12:58:25 +0800 Subject: [PATCH 099/112] fix - suppress warnings --- src/main/java/redis/clients/jedis/Jedis.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index f30990d..b717fb2 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -2891,7 +2891,8 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand * * @return */ - public List> sentinelMasters() { + @SuppressWarnings("rawtypes") + public List> sentinelMasters() { client.sentinel(Protocol.SENTINEL_MASTERS); final List reply = client.getObjectMultiBulkReply(); @@ -2968,7 +2969,8 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand * @param masterName * @return */ - public List> sentinelSlaves(String masterName) { + @SuppressWarnings("rawtypes") + public List> sentinelSlaves(String masterName) { client.sentinel(Protocol.SENTINEL_SLAVES, masterName); final List reply = client.getObjectMultiBulkReply(); @@ -2991,11 +2993,13 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand * * @return Long followed by the String (runid) */ - public List sentinelIsMasterDownByAddr(String host, + @SuppressWarnings("unchecked") + public List sentinelIsMasterDownByAddr(String host, int port) { client.sentinel(Protocol.SENTINEL_IS_MASTER_DOWN_BY_ADDR, host, port); final List reply = client.getObjectMultiBulkReply(); return Arrays.asList(BuilderFactory.LONG.build(reply.get(0)), BuilderFactory.STRING.build(reply.get(1))); } + } From f1db0b9cacf738bd40eb388f3eab088bd84c1402 Mon Sep 17 00:00:00 2001 From: mindwind Date: Sat, 29 Jun 2013 12:58:36 +0800 Subject: [PATCH 100/112] new - build.sh --- build.sh | 1 + 1 file changed, 1 insertion(+) create mode 100755 build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..53fdc96 --- /dev/null +++ b/build.sh @@ -0,0 +1 @@ +mvn -B install -Dmaven.test.skip=true \ No newline at end of file From 7b6006b66970d73742668e110247890ca1b878f1 Mon Sep 17 00:00:00 2001 From: mindwind Date: Sat, 29 Jun 2013 12:59:32 +0800 Subject: [PATCH 101/112] merge - jedis pull request #429 --- src/main/java/redis/clients/jedis/JedisPool.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/redis/clients/jedis/JedisPool.java b/src/main/java/redis/clients/jedis/JedisPool.java index b996217..1e0ead6 100644 --- a/src/main/java/redis/clients/jedis/JedisPool.java +++ b/src/main/java/redis/clients/jedis/JedisPool.java @@ -103,6 +103,16 @@ public class JedisPool extends Pool { return jedis; } + + @Override + public void activateObject(Object obj) throws Exception { + if (obj instanceof Jedis) { + final Jedis jedis = (Jedis)obj; + if (jedis.getDB() != database) { + jedis.select(database); + } + } + } public void destroyObject(final Object obj) throws Exception { if (obj instanceof Jedis) { From 8b3ea5f2de1e33229b0c08dd4180ae7ba578eeb6 Mon Sep 17 00:00:00 2001 From: mindwind Date: Sat, 29 Jun 2013 14:17:44 +0800 Subject: [PATCH 102/112] new - dump and restore command --- .../java/redis/clients/jedis/BinaryClient.java | 8 ++++++++ .../java/redis/clients/jedis/BinaryJedis.java | 12 ++++++++++++ src/main/java/redis/clients/jedis/Client.java | 9 +++++++++ src/main/java/redis/clients/jedis/Jedis.java | 15 +++++++++++++-- src/main/java/redis/clients/jedis/Protocol.java | 2 +- src/main/java/redis/clients/util/SafeEncoder.java | 2 -- .../commands/AllKindOfValuesCommandsTest.java | 8 ++++++++ .../tests/commands/JedisCommandTestBase.java | 4 ++++ 8 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index 81c0c2f..f545531 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -102,6 +102,14 @@ public class BinaryClient extends Connection { public void del(final byte[]... keys) { sendCommand(DEL, keys); } + + public void dump(final byte[] key) { + sendCommand(DUMP, key); + } + + public void restore(final byte[] key, final int ttl, final byte[] serializedValue) { + sendCommand(RESTORE, key, toByteArray(ttl), serializedValue); + } public void type(final byte[] key) { sendCommand(TYPE, key); diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 4c65974..b257a2a 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -3238,4 +3238,16 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey client.bitop(op, destKey, srcKeys); return client.getIntegerReply(); } + + public byte[] dump(final byte[] key) { + checkIsInMulti(); + client.dump(key); + return client.getBinaryBulkReply(); + } + + public String restore(final byte[] key, final int ttl, final byte[] serializedValue) { + checkIsInMulti(); + client.restore(key, ttl, serializedValue); + return client.getStatusCodeReply(); + } } diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index a647a20..c88d134 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -732,4 +732,13 @@ public class Client extends BinaryClient implements Commands { sentinel(SafeEncoder.encode(cmd), SafeEncoder.encode(arg1), toByteArray(arg2)); } + + public void dump(final String key) { + dump(SafeEncoder.encode(key)); + } + + public void restore(final String key, final int ttl, final byte[] serializedValue) { + restore(SafeEncoder.encode(key), ttl, serializedValue); + } + } diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index b717fb2..c9c6887 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -100,8 +100,8 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand } public Long del(String key) { - client.del(key); - return client.getIntegerReply(); + client.del(key); + return client.getIntegerReply(); } /** @@ -3002,4 +3002,15 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand BuilderFactory.STRING.build(reply.get(1))); } + public byte[] dump(final String key) { + checkIsInMulti(); + client.dump(key); + return client.getBinaryBulkReply(); + } + + public String restore(final String key, final int ttl, final byte[] serializedValue) { + checkIsInMulti(); + client.restore(key, ttl, serializedValue); + return client.getStatusCodeReply(); + } } diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index f0e5585..2ac77bc 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -154,7 +154,7 @@ public final class Protocol { } public static enum Command { - PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, SENTINEL; + PING, SET, GET, QUIT, EXISTS, DEL, DUMP, RESTORE, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, SENTINEL; public final byte[] raw; diff --git a/src/main/java/redis/clients/util/SafeEncoder.java b/src/main/java/redis/clients/util/SafeEncoder.java index d63fe0b..a00e6c4 100644 --- a/src/main/java/redis/clients/util/SafeEncoder.java +++ b/src/main/java/redis/clients/util/SafeEncoder.java @@ -1,8 +1,6 @@ package redis.clients.util; import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.List; import redis.clients.jedis.Protocol; import redis.clients.jedis.exceptions.JedisDataException; diff --git a/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java index 855a35d..03fb17e 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java @@ -103,6 +103,14 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase { reply = jedis.del(bfoo1, bfoo2); assertEquals(0, reply); } + + @Test + public void dumpAndRestore() { + jedis.set("foo1", "bar1"); + byte[] sv = jedis.dump("foo1"); + jedis.restore("foo2", 0, sv); + assertTrue(jedis.exists("foo2")); + } @Test public void type() { diff --git a/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java b/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java index c88b388..df10cb5 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java +++ b/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java @@ -27,7 +27,11 @@ public abstract class JedisCommandTestBase extends JedisTestBase { public void setUp() throws Exception { jedis = new Jedis(hnp.host, hnp.port, 500); jedis.connect(); + try { jedis.auth("foobared"); + } catch (Exception e) { + // ignore + } jedis.configSet("timeout", "300"); jedis.flushAll(); } From e7a88a49e9838fa6d47c5a7260e23195246a546e Mon Sep 17 00:00:00 2001 From: mindwind Date: Sat, 29 Jun 2013 15:13:21 +0800 Subject: [PATCH 103/112] new - pexpire, pexpireat and pttl command --- .../redis/clients/jedis/BinaryClient.java | 30 +++++++---- .../java/redis/clients/jedis/BinaryJedis.java | 30 ++++++++--- src/main/java/redis/clients/jedis/Client.java | 16 +++++- src/main/java/redis/clients/jedis/Jedis.java | 30 ++++++++--- .../java/redis/clients/jedis/Protocol.java | 3 +- .../commands/AllKindOfValuesCommandsTest.java | 53 ++++++++++++++++--- 6 files changed, 130 insertions(+), 32 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index f545531..3383848 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -102,14 +102,6 @@ public class BinaryClient extends Connection { public void del(final byte[]... keys) { sendCommand(DEL, keys); } - - public void dump(final byte[] key) { - sendCommand(DUMP, key); - } - - public void restore(final byte[] key, final int ttl, final byte[] serializedValue) { - sendCommand(RESTORE, key, toByteArray(ttl), serializedValue); - } public void type(final byte[] key) { sendCommand(TYPE, key); @@ -870,6 +862,26 @@ public class BinaryClient extends Connection { } public void sentinel(final byte[]... args) { - sendCommand(SENTINEL, args); + sendCommand(SENTINEL, args); + } + + public void dump(final byte[] key) { + sendCommand(DUMP, key); + } + + public void restore(final byte[] key, final int ttl, final byte[] serializedValue) { + sendCommand(RESTORE, key, toByteArray(ttl), serializedValue); + } + + public void pexpire(final byte[] key, final int milliseconds) { + sendCommand(PEXPIRE, key, toByteArray(milliseconds)); + } + + public void pexpireAt(final byte[] key, long millisecondsTimestamp) { + sendCommand(PEXPIREAT, key, toByteArray(millisecondsTimestamp)); + } + + public void pttl(final byte[] key) { + sendCommand(PTTL, key); } } diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index b257a2a..465f118 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -3240,14 +3240,32 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey } public byte[] dump(final byte[] key) { - checkIsInMulti(); - client.dump(key); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.dump(key); + return client.getBinaryBulkReply(); } public String restore(final byte[] key, final int ttl, final byte[] serializedValue) { - checkIsInMulti(); - client.restore(key, ttl, serializedValue); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.restore(key, ttl, serializedValue); + return client.getStatusCodeReply(); + } + + public Long pexpire(final byte[] key, final int milliseconds) { + checkIsInMulti(); + client.pexpire(key, milliseconds); + return client.getIntegerReply(); + } + + public Long pexpireAt(final byte[] key, final long millisecondsTimestamp) { + checkIsInMulti(); + client.pexpireAt(key, millisecondsTimestamp); + return client.getIntegerReply(); + } + + public Long pttl(final byte[] key) { + checkIsInMulti(); + client.pttl(key); + return client.getIntegerReply(); } } diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index c88d134..a268158 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -734,11 +734,23 @@ public class Client extends BinaryClient implements Commands { } public void dump(final String key) { - dump(SafeEncoder.encode(key)); + dump(SafeEncoder.encode(key)); } public void restore(final String key, final int ttl, final byte[] serializedValue) { - restore(SafeEncoder.encode(key), ttl, serializedValue); + restore(SafeEncoder.encode(key), ttl, serializedValue); + } + + public void pexpire(final String key, final int milliseconds) { + pexpire(SafeEncoder.encode(key), milliseconds); + } + + public void pexpireAt(final String key, final long millisecondsTimestamp) { + pexpireAt(SafeEncoder.encode(key), millisecondsTimestamp); + } + + public void pttl(final String key) { + pttl(SafeEncoder.encode(key)); } } diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index c9c6887..fe0f7ab 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -3003,14 +3003,32 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand } public byte[] dump(final String key) { - checkIsInMulti(); - client.dump(key); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.dump(key); + return client.getBinaryBulkReply(); } public String restore(final String key, final int ttl, final byte[] serializedValue) { - checkIsInMulti(); - client.restore(key, ttl, serializedValue); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.restore(key, ttl, serializedValue); + return client.getStatusCodeReply(); + } + + public Long pexpire(final String key, final int milliseconds) { + checkIsInMulti(); + client.pexpire(key, milliseconds); + return client.getIntegerReply(); + } + + public Long pexpireAt(final String key, final long millisecondsTimestamp) { + checkIsInMulti(); + client.pexpireAt(key, millisecondsTimestamp); + return client.getIntegerReply(); + } + + public Long pttl(final String key) { + checkIsInMulti(); + client.pttl(key); + return client.getIntegerReply(); } } diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index 2ac77bc..b074a33 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -154,7 +154,8 @@ public final class Protocol { } public static enum Command { - PING, SET, GET, QUIT, EXISTS, DEL, DUMP, RESTORE, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, SENTINEL; + PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, SENTINEL, + DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL; public final byte[] raw; diff --git a/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java index 03fb17e..390d7ff 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java @@ -103,14 +103,6 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase { reply = jedis.del(bfoo1, bfoo2); assertEquals(0, reply); } - - @Test - public void dumpAndRestore() { - jedis.set("foo1", "bar1"); - byte[] sv = jedis.dump("foo1"); - jedis.restore("foo2", 0, sv); - assertTrue(jedis.exists("foo2")); - } @Test public void type() { @@ -465,5 +457,50 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase { byte[] bresult = jedis.echo(SafeEncoder.encode("hello world")); assertArrayEquals(SafeEncoder.encode("hello world"), bresult); } + + @Test + public void dumpAndRestore() { + jedis.set("foo1", "bar1"); + byte[] sv = jedis.dump("foo1"); + jedis.restore("foo2", 0, sv); + assertTrue(jedis.exists("foo2")); + } + + @Test + public void pexpire() { + long status = jedis.pexpire("foo", 10000); + assertEquals(0, status); + + jedis.set("foo", "bar"); + status = jedis.pexpire("foo", 10000); + assertEquals(1, status); + } + + @Test + public void pexpireAt() { + long unixTime = (System.currentTimeMillis()) + 10000; + + long status = jedis.pexpireAt("foo", unixTime); + assertEquals(0, status); + + jedis.set("foo", "bar"); + unixTime = (System.currentTimeMillis()) + 10000; + status = jedis.pexpireAt("foo", unixTime); + assertEquals(1, status); + } + + @Test + public void pttl() { + long pttl = jedis.pttl("foo"); + assertEquals(-1, pttl); + + jedis.set("foo", "bar"); + pttl = jedis.pttl("foo"); + assertEquals(-1, pttl); + + jedis.pexpire("foo", 20000); + pttl = jedis.pttl("foo"); + assertTrue(pttl >= 0 && pttl <= 20000); + } } \ No newline at end of file From 1080d136ecfae0f35d58e44c71545623c3fdfea8 Mon Sep 17 00:00:00 2001 From: mindwind Date: Sat, 29 Jun 2013 23:15:56 +0800 Subject: [PATCH 104/112] new - command for redis 2.6 --- .../redis/clients/jedis/BinaryClient.java | 42 ++++++++++++- .../java/redis/clients/jedis/BinaryJedis.java | 62 +++++++++++++++++++ src/main/java/redis/clients/jedis/Client.java | 27 ++++++++ src/main/java/redis/clients/jedis/Jedis.java | 43 +++++++++++++ .../java/redis/clients/jedis/Protocol.java | 2 +- .../tests/commands/JedisCommandTestBase.java | 4 -- .../commands/StringValuesCommandsTest.java | 16 +++++ 7 files changed, 190 insertions(+), 6 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index 3383848..8af1981 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -877,11 +877,51 @@ public class BinaryClient extends Connection { sendCommand(PEXPIRE, key, toByteArray(milliseconds)); } - public void pexpireAt(final byte[] key, long millisecondsTimestamp) { + public void pexpireAt(final byte[] key, final long millisecondsTimestamp) { sendCommand(PEXPIREAT, key, toByteArray(millisecondsTimestamp)); } public void pttl(final byte[] key) { sendCommand(PTTL, key); } + + public void incrByFloat(final byte[] key, final double increment) { + sendCommand(INCRBYFLOAT, key, toByteArray(increment)); + } + + public void psetex(final byte[] key, final int milliseconds, final byte[] value) { + sendCommand(PSETEX, key, toByteArray(milliseconds), value); + } + + public void set(final byte[] key, final byte[] value, final byte[] nxxx) { + sendCommand(Command.SET, key, value, nxxx); + } + + public void set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final long time) { + sendCommand(Command.SET, key, value, nxxx, expx, toByteArray(time)); + } + + public void srandmember(final byte[] key, final int count) { + sendCommand(SRANDMEMBER, key, toByteArray(count)); + } + + public void clientKill(final byte[] client) { + sendCommand(CLIENT_KILL, client); + } + + public void clientGetname() { + sendCommand(CLIENT_GETNAME); + } + + public void clientList() { + sendCommand(CLIENT_LIST); + } + + public void clientSetname(final byte[] name) { + sendCommand(CLIENT_SETNAME); + } + + public void time() { + sendCommand(TIME); + } } diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 465f118..e0e8689 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -1457,6 +1457,12 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey client.srandmember(key); return client.getBinaryBulkReply(); } + + public List srandmember(final byte[] key, final int count) { + checkIsInMulti(); + client.srandmember(key, count); + return client.getBinaryMultiBulkReply(); + } /** * Add the specified member having the specifeid score to the sorted set @@ -3268,4 +3274,60 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey client.pttl(key); return client.getIntegerReply(); } + + public Double incrByFloat(final byte[] key, final double increment) { + checkIsInMulti(); + client.incrByFloat(key, increment); + String relpy = client.getBulkReply(); + return (relpy != null ? new Double(relpy) : null); + } + + public String psetex(final byte[] key, final int milliseconds, final byte[] value) { + checkIsInMulti(); + client.psetex(key, milliseconds, value); + return client.getStatusCodeReply(); + } + + public String set(final byte[] key, final byte[] value, final byte[] nxxx) { + checkIsInMulti(); + client.set(key, value, nxxx); + return client.getStatusCodeReply(); + } + + public String set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final long time) { + checkIsInMulti(); + client.set(key, value, nxxx, expx, time); + return client.getStatusCodeReply(); + } + + public String clientKill(final byte[] client) { + checkIsInMulti(); + this.client.clientKill(client); + return this.client.getStatusCodeReply(); + } + + public String clientGetname() { + checkIsInMulti(); + client.clientGetname(); + return client.getBulkReply(); + } + + public String clientList() { + checkIsInMulti(); + client.clientList(); + return client.getBulkReply(); + } + + public String clientSetname(final byte[] name) { + checkIsInMulti(); + client.clientSetname(name); + return client.getBulkReply(); + } + + public List time() { + checkIsInMulti(); + client.time(); + return client.getMultiBulkReply(); + } + } diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index a268158..b6bceed 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -752,5 +752,32 @@ public class Client extends BinaryClient implements Commands { public void pttl(final String key) { pttl(SafeEncoder.encode(key)); } + + public void incrByFloat(final String key, final double increment) { + incrByFloat(SafeEncoder.encode(key), increment); + } + + public void psetex(final String key, final int milliseconds, final String value) { + psetex(SafeEncoder.encode(key), milliseconds, SafeEncoder.encode(value)); + } + + public void set(final String key, final String value, final String nxxx) { + set(SafeEncoder.encode(key), SafeEncoder.encode(value), SafeEncoder.encode(nxxx)); + } + + public void set(final String key, final String value, final String nxxx, final String expx, final long time) { + set(SafeEncoder.encode(key), SafeEncoder.encode(value), SafeEncoder.encode(nxxx), SafeEncoder.encode(expx), time); + } + + public void srandmember(final String key, final int count) { + srandmember(SafeEncoder.encode(key), count); + } + public void clientKill(final String client) { + clientKill(SafeEncoder.encode(client)); + } + + public void clientSetname(final String name) { + clientSetname(SafeEncoder.encode(name)); + } } diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index fe0f7ab..22c02cc 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -1362,6 +1362,12 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand client.srandmember(key); return client.getBulkReply(); } + + public List srandmember(final String key, final int count) { + checkIsInMulti(); + client.srandmember(key); + return client.getMultiBulkReply(); + } /** * Add the specified member having the specifeid score to the sorted set @@ -3031,4 +3037,41 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand client.pttl(key); return client.getIntegerReply(); } + + public Double incrByFloat(final String key, final double increment) { + checkIsInMulti(); + client.incrByFloat(key, increment); + String relpy = client.getBulkReply(); + return (relpy != null ? new Double(relpy) : null); + } + + public String psetex(final String key, final int milliseconds, final String value) { + checkIsInMulti(); + client.psetex(key, milliseconds, value); + return client.getStatusCodeReply(); + } + + public String set(final String key, final String value, final String nxxx) { + checkIsInMulti(); + client.set(key, value, nxxx); + return client.getStatusCodeReply(); + } + + public String set(final String key, final String value, final String nxxx, final String expx, final long time) { + checkIsInMulti(); + client.set(key, value, nxxx, expx, time); + return client.getStatusCodeReply(); + } + + public String clientKill(final String client) { + checkIsInMulti(); + this.client.clientKill(client); + return this.client.getStatusCodeReply(); + } + + public String clientSetname(final String name) { + checkIsInMulti(); + client.clientSetname(name); + return client.getBulkReply(); + } } diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index b074a33..08b5193 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -155,7 +155,7 @@ public final class Protocol { public static enum Command { PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, SENTINEL, - DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL; + DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL, INCRBYFLOAT, PSETEX, CLIENT_KILL, CLIENT_GETNAME, CLIENT_SETNAME, CLIENT_LIST, TIME; public final byte[] raw; diff --git a/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java b/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java index df10cb5..c88b388 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java +++ b/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java @@ -27,11 +27,7 @@ public abstract class JedisCommandTestBase extends JedisTestBase { public void setUp() throws Exception { jedis = new Jedis(hnp.host, hnp.port, 500); jedis.connect(); - try { jedis.auth("foobared"); - } catch (Exception e) { - // ignore - } jedis.configSet("timeout", "300"); jedis.flushAll(); } diff --git a/src/test/java/redis/clients/jedis/tests/commands/StringValuesCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/StringValuesCommandsTest.java index fcf9f99..e34eb7b 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/StringValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/StringValuesCommandsTest.java @@ -190,4 +190,20 @@ public class StringValuesCommandsTest extends JedisCommandTestBase { long value = jedis.incr("foo"); assertEquals(Long.MIN_VALUE, value); } + + @Test + public void incrByFloat() { + double value = jedis.incrByFloat("foo", 10.5); + assertEquals(10.5, value, 0.0); + value = jedis.incrByFloat("foo", 0.1); + assertEquals(10.6, value, 0.0); + } + + @Test + public void psetex() { + String status = jedis.psetex("foo", 20000, "bar"); + assertEquals("OK", status); + long ttl = jedis.ttl("foo"); + assertTrue(ttl > 0 && ttl <= 20000); + } } \ No newline at end of file From 7655994933c2e708a8c0194abf533fd13579a3f9 Mon Sep 17 00:00:00 2001 From: mindwind Date: Mon, 1 Jul 2013 14:30:19 +0800 Subject: [PATCH 105/112] new - supplement transaction missing api and fix some args type definition which is inconsistent with jedis --- .../redis/clients/jedis/BinaryClient.java | 28 ++- .../java/redis/clients/jedis/BinaryJedis.java | 15 +- .../clients/jedis/BinaryRedisPipeline.java | 20 +- src/main/java/redis/clients/jedis/Client.java | 30 ++- src/main/java/redis/clients/jedis/Jedis.java | 15 +- .../clients/jedis/MultiKeyPipelineBase.java | 31 +++ .../redis/clients/jedis/PipelineBase.java | 230 ++++++++++++++++-- .../java/redis/clients/jedis/Protocol.java | 2 +- .../redis/clients/jedis/RedisPipeline.java | 20 +- .../java/redis/clients/jedis/Transaction.java | 4 +- 10 files changed, 348 insertions(+), 47 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index 8af1981..72ae2d5 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -475,6 +475,15 @@ public class BinaryClient extends Connection { public void blpop(final byte[][] args) { sendCommand(BLPOP, args); } + + public void blpop(final int timeout, final byte[]... keys) { + final List args = new ArrayList(); + for (final byte[] arg : keys) { + args.add(arg); + } + args.add(Protocol.toByteArray(timeout)); + blpop(args.toArray(new byte[args.size()][])); + } public void sort(final byte[] key, final SortingParams sortingParameters, final byte[] dstkey) { @@ -493,6 +502,15 @@ public class BinaryClient extends Connection { public void brpop(final byte[][] args) { sendCommand(BRPOP, args); } + + public void brpop(final int timeout, final byte[]... keys) { + final List args = new ArrayList(); + for (final byte[] arg : keys) { + args.add(arg); + } + args.add(Protocol.toByteArray(timeout)); + brpop(args.toArray(new byte[args.size()][])); + } public void auth(final String password) { setPassword(password); @@ -897,7 +915,7 @@ public class BinaryClient extends Connection { sendCommand(Command.SET, key, value, nxxx); } - public void set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final long time) { + public void set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final int time) { sendCommand(Command.SET, key, value, nxxx, expx, toByteArray(time)); } @@ -924,4 +942,12 @@ public class BinaryClient extends Connection { public void time() { sendCommand(TIME); } + + public void migrate(final byte[] host, final int port, final byte[] key, final int destinationDb, final int timeout) { + sendCommand(MIGRATE, host, toByteArray(port), key, toByteArray(destinationDb), toByteArray(timeout)); + } + + public void hincrByFloat(final byte[] key, final byte[] field, double increment) { + sendCommand(HINCRBYFLOAT, key, field, toByteArray(increment)); + } } diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index e0e8689..89b42ae 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -3294,7 +3294,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey return client.getStatusCodeReply(); } - public String set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final long time) { + public String set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final int time) { checkIsInMulti(); client.set(key, value, nxxx, expx, time); return client.getStatusCodeReply(); @@ -3329,5 +3329,18 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey client.time(); return client.getMultiBulkReply(); } + + public String migrate(final byte[] host, final int port, final byte[] key, final int destinationDb, final int timeout) { + checkIsInMulti(); + client.migrate(host, port, key, destinationDb, timeout); + return client.getStatusCodeReply(); + } + + public Double hincrByFloat(final byte[] key, final byte[] field, double increment) { + checkIsInMulti(); + client.hincrByFloat(key, field, increment); + String relpy = client.getBulkReply(); + return (relpy != null ? new Double(relpy) : null); + } } diff --git a/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java b/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java index 6f4fd90..d48800c 100644 --- a/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java +++ b/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java @@ -36,7 +36,7 @@ public interface BinaryRedisPipeline { Response getrange(byte[] key, long startOffset, long endOffset); - Response hdel(byte[] key, byte[] field); + Response hdel(byte[] key, byte[]... field); Response hexists(byte[] key, byte[] field); @@ -64,7 +64,7 @@ public interface BinaryRedisPipeline { Response incrBy(byte[] key, long integer); - Response lindex(byte[] key, int index); + Response lindex(byte[] key, long index); Response linsert(byte[] key, BinaryClient.LIST_POSITION where, byte[] pivot, byte[] value); @@ -124,7 +124,7 @@ public interface BinaryRedisPipeline { Response srandmember(byte[] key); - Response srem(byte[] key, byte[] member); + Response srem(byte[] key, byte[]... member); Response strlen(byte[] key); @@ -142,7 +142,7 @@ public interface BinaryRedisPipeline { Response zincrby(byte[] key, double score, byte[] member); - Response> zrange(byte[] key, int start, int end); + Response> zrange(byte[] key, long start, long end); Response> zrangeByScore(byte[] key, double min, double max); @@ -192,22 +192,22 @@ public interface BinaryRedisPipeline { Response> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min, int offset, int count); - Response> zrangeWithScores(byte[] key, int start, int end); + Response> zrangeWithScores(byte[] key, long start, long end); Response zrank(byte[] key, byte[] member); - Response zrem(byte[] key, byte[] member); + Response zrem(byte[] key, byte[]... member); - Response zremrangeByRank(byte[] key, int start, int end); + Response zremrangeByRank(byte[] key, long start, long end); Response zremrangeByScore(byte[] key, double start, double end); Response zremrangeByScore(byte[] key, byte[] start, byte[] end); - Response> zrevrange(byte[] key, int start, int end); + Response> zrevrange(byte[] key, long start, long end); - Response> zrevrangeWithScores(byte[] key, int start, - int end); + Response> zrevrangeWithScores(byte[] key, long start, + long end); Response zrevrank(byte[] key, byte[] member); diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index b6bceed..ce20fbc 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -2,7 +2,9 @@ package redis.clients.jedis; import static redis.clients.jedis.Protocol.toByteArray; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -385,6 +387,15 @@ public class Client extends BinaryClient implements Commands { } blpop(bargs); } + + public void blpop(final int timeout, final String... keys) { + List args = new ArrayList(); + for (String arg : keys) { + args.add(arg); + } + args.add(String.valueOf(timeout)); + blpop(args.toArray(new String[args.size()])); + } public void sort(final String key, final SortingParams sortingParameters, final String dstkey) { @@ -403,6 +414,15 @@ public class Client extends BinaryClient implements Commands { } brpop(bargs); } + + public void brpop(final int timeout, final String... keys) { + List args = new ArrayList(); + for (String arg : keys) { + args.add(arg); + } + args.add(String.valueOf(timeout)); + brpop(args.toArray(new String[args.size()])); + } public void zcount(final String key, final double min, final double max) { zcount(SafeEncoder.encode(key), toByteArray(min), toByteArray(max)); @@ -765,7 +785,7 @@ public class Client extends BinaryClient implements Commands { set(SafeEncoder.encode(key), SafeEncoder.encode(value), SafeEncoder.encode(nxxx)); } - public void set(final String key, final String value, final String nxxx, final String expx, final long time) { + public void set(final String key, final String value, final String nxxx, final String expx, final int time) { set(SafeEncoder.encode(key), SafeEncoder.encode(value), SafeEncoder.encode(nxxx), SafeEncoder.encode(expx), time); } @@ -780,4 +800,12 @@ public class Client extends BinaryClient implements Commands { public void clientSetname(final String name) { clientSetname(SafeEncoder.encode(name)); } + + public void migrate(final String host, final int port, final String key, final int destinationDb, final int timeout) { + migrate(SafeEncoder.encode(host), port, SafeEncoder.encode(key), destinationDb, timeout); + } + + public void hincrByFloat(final String key, final String field, double increment) { + hincrByFloat(SafeEncoder.encode(key), SafeEncoder.encode(field), increment); + } } diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 22c02cc..d5fd399 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -3057,7 +3057,7 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand return client.getStatusCodeReply(); } - public String set(final String key, final String value, final String nxxx, final String expx, final long time) { + public String set(final String key, final String value, final String nxxx, final String expx, final int time) { checkIsInMulti(); client.set(key, value, nxxx, expx, time); return client.getStatusCodeReply(); @@ -3074,4 +3074,17 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand client.clientSetname(name); return client.getBulkReply(); } + + public String migrate(final String host, final int port, final String key, final int destinationDb, final int timeout) { + checkIsInMulti(); + client.migrate(host, port, key, destinationDb, timeout); + return client.getStatusCodeReply(); + } + + public Double hincrByFloat(final String key, final String field, double increment) { + checkIsInMulti(); + client.hincrByFloat(key, field, increment); + String relpy = client.getBulkReply(); + return (relpy != null ? new Double(relpy) : null); + } } diff --git a/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java b/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java index ccf0dfd..46fede3 100644 --- a/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java +++ b/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java @@ -1,6 +1,7 @@ package redis.clients.jedis; import java.util.List; +import java.util.Map; import java.util.Set; abstract class MultiKeyPipelineBase extends PipelineBase implements @@ -14,21 +15,51 @@ abstract class MultiKeyPipelineBase extends PipelineBase implements client.brpop(args); return getResponse(BuilderFactory.STRING_LIST); } + + public Response> brpop(int timeout, String... keys) { + client.brpop(timeout, keys); + return getResponse(BuilderFactory.STRING_LIST); + } public Response> blpop(String... args) { client.blpop(args); return getResponse(BuilderFactory.STRING_LIST); } + + public Response> blpop(int timeout, String... keys) { + client.blpop(timeout, keys); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> blpopMap(int timeout, String... keys) { + client.blpop(timeout, keys); + return getResponse(BuilderFactory.STRING_MAP); + } public Response> brpop(byte[]... args) { client.brpop(args); return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } + + public Response> brpop(int timeout, byte[]... keys) { + client.brpop(timeout, keys); + return getResponse(BuilderFactory.STRING_LIST); + } + + public Response> brpopMap(int timeout, String... keys) { + client.blpop(timeout, keys); + return getResponse(BuilderFactory.STRING_MAP); + } public Response> blpop(byte[]... args) { client.blpop(args); return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } + + public Response> blpop(int timeout, byte[]... keys) { + client.blpop(timeout, keys); + return getResponse(BuilderFactory.STRING_LIST); + } public Response del(String... keys) { client.del(keys); diff --git a/src/main/java/redis/clients/jedis/PipelineBase.java b/src/main/java/redis/clients/jedis/PipelineBase.java index 2ceeeec..d09b0a6 100644 --- a/src/main/java/redis/clients/jedis/PipelineBase.java +++ b/src/main/java/redis/clients/jedis/PipelineBase.java @@ -165,12 +165,12 @@ abstract class PipelineBase extends Queable implements return getResponse(BuilderFactory.LONG); } - public Response hdel(String key, String field) { + public Response hdel(String key, String... field) { getClient(key).hdel(key, field); return getResponse(BuilderFactory.LONG); } - public Response hdel(byte[] key, byte[] field) { + public Response hdel(byte[] key, byte[]... field) { getClient(key).hdel(key, field); return getResponse(BuilderFactory.LONG); } @@ -305,12 +305,12 @@ abstract class PipelineBase extends Queable implements return getResponse(BuilderFactory.LONG); } - public Response lindex(String key, int index) { + public Response lindex(String key, long index) { getClient(key).lindex(key, index); return getResponse(BuilderFactory.STRING); } - public Response lindex(byte[] key, int index) { + public Response lindex(byte[] key, long index) { getClient(key).lindex(key, index); return getResponse(BuilderFactory.BYTE_ARRAY); } @@ -583,18 +583,28 @@ abstract class PipelineBase extends Queable implements getClient(key).srandmember(key); return getResponse(BuilderFactory.STRING); } + + public Response> srandmember(String key, int count) { + getClient(key).srandmember(key, count); + return getResponse(BuilderFactory.STRING_LIST); + } public Response srandmember(byte[] key) { getClient(key).srandmember(key); return getResponse(BuilderFactory.BYTE_ARRAY); } + + public Response> srandmember(byte[] key, int count) { + getClient(key).srandmember(key, count); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + } - public Response srem(String key, String member) { + public Response srem(String key, String... member) { getClient(key).srem(key, member); return getResponse(BuilderFactory.LONG); } - public Response srem(byte[] key, byte[] member) { + public Response srem(byte[] key, byte[]... member) { getClient(key).srem(key, member); return getResponse(BuilderFactory.LONG); } @@ -679,12 +689,12 @@ abstract class PipelineBase extends Queable implements return getResponse(BuilderFactory.DOUBLE); } - public Response> zrange(String key, int start, int end) { + public Response> zrange(String key, long start, long end) { getClient(key).zrange(key, start, end); return getResponse(BuilderFactory.STRING_ZSET); } - public Response> zrange(byte[] key, int start, int end) { + public Response> zrange(byte[] key, long start, long end) { getClient(key).zrange(key, start, end); return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } @@ -717,6 +727,11 @@ abstract class PipelineBase extends Queable implements getClient(key).zrangeByScore(key, min, max, offset, count); return getResponse(BuilderFactory.STRING_ZSET); } + + public Response> zrangeByScore(String key, String min, String max, int offset, int count) { + getClient(key).zrangeByScore(key, min, max, offset, count); + return getResponse(BuilderFactory.STRING_ZSET); + } public Response> zrangeByScore(byte[] key, double min, double max, int offset, int count) { @@ -734,6 +749,12 @@ abstract class PipelineBase extends Queable implements getClient(key).zrangeByScoreWithScores(key, min, max); return getResponse(BuilderFactory.TUPLE_ZSET); } + + public Response> zrangeByScoreWithScores(String key, String min, + String max) { + getClient(key).zrangeByScoreWithScores(key, min, max); + return getResponse(BuilderFactory.TUPLE_ZSET); + } public Response> zrangeByScoreWithScores(byte[] key, double min, double max) { @@ -751,6 +772,12 @@ abstract class PipelineBase extends Queable implements getClient(key).zrangeByScoreWithScores(key, min, max, offset, count); return getResponse(BuilderFactory.TUPLE_ZSET); } + + public Response> zrangeByScoreWithScores(String key, String min, + String max, int offset, int count) { + getClient(key).zrangeByScoreWithScores(key, min, max, offset, count); + return getResponse(BuilderFactory.TUPLE_ZSET); + } public Response> zrangeByScoreWithScores(byte[] key, double min, double max, int offset, int count) { @@ -793,6 +820,12 @@ abstract class PipelineBase extends Queable implements getClient(key).zrevrangeByScore(key, max, min, offset, count); return getResponse(BuilderFactory.STRING_ZSET); } + + public Response> zrevrangeByScore(String key, String max, + String min, int offset, int count) { + getClient(key).zrevrangeByScore(key, max, min, offset, count); + return getResponse(BuilderFactory.STRING_ZSET); + } public Response> zrevrangeByScore(byte[] key, double max, double min, int offset, int count) { @@ -811,6 +844,12 @@ abstract class PipelineBase extends Queable implements getClient(key).zrevrangeByScoreWithScores(key, max, min); return getResponse(BuilderFactory.TUPLE_ZSET); } + + public Response> zrevrangeByScoreWithScores(String key, + String max, String min) { + getClient(key).zrevrangeByScoreWithScores(key, max, min); + return getResponse(BuilderFactory.TUPLE_ZSET); + } public Response> zrevrangeByScoreWithScores(byte[] key, double max, double min) { @@ -829,6 +868,12 @@ abstract class PipelineBase extends Queable implements getClient(key).zrevrangeByScoreWithScores(key, max, min, offset, count); return getResponse(BuilderFactory.TUPLE_ZSET); } + + public Response> zrevrangeByScoreWithScores(String key, + String max, String min, int offset, int count) { + getClient(key).zrevrangeByScoreWithScores(key, max, min, offset, count); + return getResponse(BuilderFactory.TUPLE_ZSET); + } public Response> zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count) { @@ -842,12 +887,12 @@ abstract class PipelineBase extends Queable implements return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } - public Response> zrangeWithScores(String key, int start, int end) { + public Response> zrangeWithScores(String key, long start, long end) { getClient(key).zrangeWithScores(key, start, end); return getResponse(BuilderFactory.TUPLE_ZSET); } - public Response> zrangeWithScores(byte[] key, int start, int end) { + public Response> zrangeWithScores(byte[] key, long start, long end) { getClient(key).zrangeWithScores(key, start, end); return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } @@ -862,22 +907,22 @@ abstract class PipelineBase extends Queable implements return getResponse(BuilderFactory.LONG); } - public Response zrem(String key, String member) { + public Response zrem(String key, String... member) { getClient(key).zrem(key, member); return getResponse(BuilderFactory.LONG); } - public Response zrem(byte[] key, byte[] member) { + public Response zrem(byte[] key, byte[]... member) { getClient(key).zrem(key, member); return getResponse(BuilderFactory.LONG); } - public Response zremrangeByRank(String key, int start, int end) { + public Response zremrangeByRank(String key, long start, long end) { getClient(key).zremrangeByRank(key, start, end); return getResponse(BuilderFactory.LONG); } - public Response zremrangeByRank(byte[] key, int start, int end) { + public Response zremrangeByRank(byte[] key, long start, long end) { getClient(key).zremrangeByRank(key, start, end); return getResponse(BuilderFactory.LONG); } @@ -886,6 +931,11 @@ abstract class PipelineBase extends Queable implements getClient(key).zremrangeByScore(key, start, end); return getResponse(BuilderFactory.LONG); } + + public Response zremrangeByScore(String key, String start, String end) { + getClient(key).zremrangeByScore(key, start, end); + return getResponse(BuilderFactory.LONG); + } public Response zremrangeByScore(byte[] key, double start, double end) { getClient(key).zremrangeByScore(key, toByteArray(start), toByteArray(end)); @@ -897,24 +947,24 @@ abstract class PipelineBase extends Queable implements return getResponse(BuilderFactory.LONG); } - public Response> zrevrange(String key, int start, int end) { + public Response> zrevrange(String key, long start, long end) { getClient(key).zrevrange(key, start, end); return getResponse(BuilderFactory.STRING_ZSET); } - public Response> zrevrange(byte[] key, int start, int end) { + public Response> zrevrange(byte[] key, long start, long end) { getClient(key).zrevrange(key, start, end); return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } - public Response> zrevrangeWithScores(String key, int start, - int end) { + public Response> zrevrangeWithScores(String key, long start, + long end) { getClient(key).zrevrangeWithScores(key, start, end); return getResponse(BuilderFactory.TUPLE_ZSET); } - public Response> zrevrangeWithScores(byte[] key, int start, - int end) { + public Response> zrevrangeWithScores(byte[] key, long start, + long end) { getClient(key).zrevrangeWithScores(key, start, end); return getResponse(BuilderFactory.TUPLE_ZSET); } @@ -958,5 +1008,145 @@ abstract class PipelineBase extends Queable implements getClient(key).bitcount(key, start, end); return getResponse(BuilderFactory.LONG); } + + public Response dump(String key) { + getClient(key).dump(key); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response dump(byte[] key) { + getClient(key).dump(key); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response migrate(String host, int port, String key, int destinationDb, int timeout) { + getClient(key).migrate(host, port, key, destinationDb, timeout); + return getResponse(BuilderFactory.STRING); + } + + public Response migrate(byte[] host, int port, byte[] key, int destinationDb, int timeout) { + getClient(key).migrate(host, port, key, destinationDb, timeout); + return getResponse(BuilderFactory.STRING); + } + + public Response objectRefcount(String key) { + getClient(key).objectRefcount(key); + return getResponse(BuilderFactory.LONG); + } + + public Response objectRefcount(byte[] key) { + getClient(key).objectRefcount(key); + return getResponse(BuilderFactory.LONG); + } + + public Response objectEncoding(String key) { + getClient(key).objectEncoding(key); + return getResponse(BuilderFactory.STRING); + } + + public Response objectEncoding(byte[] key) { + getClient(key).objectEncoding(key); + return getResponse(BuilderFactory.BYTE_ARRAY); + } + + public Response objectIdletime(String key) { + getClient(key).objectIdletime(key); + return getResponse(BuilderFactory.LONG); + } + + public Response objectIdletime(byte[] key) { + getClient(key).objectIdletime(key); + return getResponse(BuilderFactory.LONG); + } + + public Response pexpire(String key, int milliseconds) { + getClient(key).pexpire(key, milliseconds); + return getResponse(BuilderFactory.LONG); + } + + public Response pexpire(byte[] key, int milliseconds) { + getClient(key).pexpire(key, milliseconds); + return getResponse(BuilderFactory.LONG); + } + + public Response pexpireAt(String key, long millisecondsTimestamp) { + getClient(key).pexpireAt(key, millisecondsTimestamp); + return getResponse(BuilderFactory.LONG); + } + + public Response pexpireAt(byte[] key, long millisecondsTimestamp) { + getClient(key).pexpireAt(key, millisecondsTimestamp); + return getResponse(BuilderFactory.LONG); + } + + public Response pttl(String key) { + getClient(key).pttl(key); + return getResponse(BuilderFactory.LONG); + } + + public Response pttl(byte[] key) { + getClient(key).pttl(key); + return getResponse(BuilderFactory.LONG); + } + + public Response restore(String key, int ttl, byte[] serializedValue) { + getClient(key).restore(key, ttl, serializedValue); + return getResponse(BuilderFactory.STRING); + } + + public Response restore(byte[] key, int ttl, byte[] serializedValue) { + getClient(key).restore(key, ttl, serializedValue); + return getResponse(BuilderFactory.STRING); + } + + public Response incrByFloat(String key, double increment) { + getClient(key).incrByFloat(key, increment); + return getResponse(BuilderFactory.DOUBLE); + } + + public Response incrByFloat(byte[] key, double increment) { + getClient(key).incrByFloat(key, increment); + return getResponse(BuilderFactory.DOUBLE); + } + + public Response psetex(String key, int milliseconds, String value) { + getClient(key).psetex(key, milliseconds, value); + return getResponse(BuilderFactory.STRING); + } + + public Response psetex(byte[] key, int milliseconds, byte[] value) { + getClient(key).psetex(key, milliseconds, value); + return getResponse(BuilderFactory.STRING); + } + + public Response set(String key, String value, String nxxx) { + getClient(key).set(key, value, nxxx); + return getResponse(BuilderFactory.STRING); + } + + public Response set(byte[] key, byte[] value, byte[] nxxx) { + getClient(key).set(key, value, nxxx); + return getResponse(BuilderFactory.STRING); + } + + public Response set(String key, String value, String nxxx, String expx, int time) { + getClient(key).set(key, value, nxxx, expx, time); + return getResponse(BuilderFactory.STRING); + } + + public Response set(byte[] key, byte[] value, byte[] nxxx, byte[] expx, int time) { + getClient(key).set(key, value, nxxx, expx, time); + return getResponse(BuilderFactory.STRING); + } + + public Response hincrByFloat(String key, String field, double increment) { + getClient(key).hincrByFloat(key, field, increment); + return getResponse(BuilderFactory.DOUBLE); + } + + public Response hincrByFloat(byte[] key, byte[] field, double increment) { + getClient(key).hincrByFloat(key, field, increment); + return getResponse(BuilderFactory.DOUBLE); + } } diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index 08b5193..0960c8e 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -155,7 +155,7 @@ public final class Protocol { public static enum Command { PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, SENTINEL, - DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL, INCRBYFLOAT, PSETEX, CLIENT_KILL, CLIENT_GETNAME, CLIENT_SETNAME, CLIENT_LIST, TIME; + DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL, INCRBYFLOAT, PSETEX, CLIENT_KILL, CLIENT_GETNAME, CLIENT_SETNAME, CLIENT_LIST, TIME, MIGRATE, HINCRBYFLOAT; public final byte[] raw; diff --git a/src/main/java/redis/clients/jedis/RedisPipeline.java b/src/main/java/redis/clients/jedis/RedisPipeline.java index 43b7516..ff9e862 100644 --- a/src/main/java/redis/clients/jedis/RedisPipeline.java +++ b/src/main/java/redis/clients/jedis/RedisPipeline.java @@ -39,7 +39,7 @@ public interface RedisPipeline { Response getSet(String key, String value); - Response hdel(String key, String field); + Response hdel(String key, String... field); Response hexists(String key, String field); @@ -67,7 +67,7 @@ public interface RedisPipeline { Response incrBy(String key, long integer); - Response lindex(String key, int index); + Response lindex(String key, long index); Response linsert(String key, BinaryClient.LIST_POSITION where, String pivot, String value); @@ -125,7 +125,7 @@ public interface RedisPipeline { Response srandmember(String key); - Response srem(String key, String member); + Response srem(String key, String... member); Response strlen(String key); @@ -143,7 +143,7 @@ public interface RedisPipeline { Response zincrby(String key, double score, String member); - Response> zrange(String key, int start, int end); + Response> zrange(String key, long start, long end); Response> zrangeByScore(String key, double min, double max); @@ -175,20 +175,20 @@ public interface RedisPipeline { Response> zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count); - Response> zrangeWithScores(String key, int start, int end); + Response> zrangeWithScores(String key, long start, long end); Response zrank(String key, String member); - Response zrem(String key, String member); + Response zrem(String key, String... member); - Response zremrangeByRank(String key, int start, int end); + Response zremrangeByRank(String key, long start, long end); Response zremrangeByScore(String key, double start, double end); - Response> zrevrange(String key, int start, int end); + Response> zrevrange(String key, long start, long end); - Response> zrevrangeWithScores(String key, int start, - int end); + Response> zrevrangeWithScores(String key, long start, + long end); Response zrevrank(String key, String member); diff --git a/src/main/java/redis/clients/jedis/Transaction.java b/src/main/java/redis/clients/jedis/Transaction.java index bca7157..949f541 100644 --- a/src/main/java/redis/clients/jedis/Transaction.java +++ b/src/main/java/redis/clients/jedis/Transaction.java @@ -1,10 +1,10 @@ package redis.clients.jedis; -import redis.clients.jedis.exceptions.JedisDataException; - import java.util.ArrayList; import java.util.List; +import redis.clients.jedis.exceptions.JedisDataException; + /** * Transaction is nearly identical to Pipeline, only differences are the multi/discard behaviors */ From 27b9eba0c037a28d6b7c4db6db026a6d50d6d171 Mon Sep 17 00:00:00 2001 From: mindwind Date: Wed, 3 Jul 2013 08:50:14 +0800 Subject: [PATCH 106/112] fix - srandmember missing parameter --- src/main/java/redis/clients/jedis/Jedis.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index d5fd399..4780e6c 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -1365,7 +1365,7 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand public List srandmember(final String key, final int count) { checkIsInMulti(); - client.srandmember(key); + client.srandmember(key, count); return client.getMultiBulkReply(); } From 96c789aaab40588f7831afb12162324b91c0c577 Mon Sep 17 00:00:00 2001 From: mindwind Date: Wed, 3 Jul 2013 16:20:31 +0800 Subject: [PATCH 107/112] new - zcount with string min and max --- src/main/java/redis/clients/jedis/PipelineBase.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/redis/clients/jedis/PipelineBase.java b/src/main/java/redis/clients/jedis/PipelineBase.java index d09b0a6..aaa6db3 100644 --- a/src/main/java/redis/clients/jedis/PipelineBase.java +++ b/src/main/java/redis/clients/jedis/PipelineBase.java @@ -673,6 +673,11 @@ abstract class PipelineBase extends Queable implements getClient(key).zcount(key, min, max); return getResponse(BuilderFactory.LONG); } + + public Response zcount(String key, String min, String max) { + getClient(key).zcount(key, min, max); + return getResponse(BuilderFactory.LONG); + } public Response zcount(byte[] key, double min, double max) { getClient(key).zcount(key, toByteArray(min), toByteArray(max)); From d57bfb94a942885fce3d93f7cfc8f49191762d5f Mon Sep 17 00:00:00 2001 From: mindwind Date: Fri, 5 Jul 2013 09:13:09 +0800 Subject: [PATCH 108/112] fix - CLIENT command --- src/main/java/redis/clients/jedis/BinaryClient.java | 8 ++++---- src/main/java/redis/clients/jedis/Jedis.java | 2 +- src/main/java/redis/clients/jedis/Protocol.java | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index 72ae2d5..c07f693 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -924,19 +924,19 @@ public class BinaryClient extends Connection { } public void clientKill(final byte[] client) { - sendCommand(CLIENT_KILL, client); + sendCommand(CLIENT, Keyword.KILL.raw, client); } public void clientGetname() { - sendCommand(CLIENT_GETNAME); + sendCommand(CLIENT, Keyword.GETNAME.raw); } public void clientList() { - sendCommand(CLIENT_LIST); + sendCommand(CLIENT, Keyword.LIST.raw); } public void clientSetname(final byte[] name) { - sendCommand(CLIENT_SETNAME); + sendCommand(CLIENT, Keyword.SETNAME.raw, name); } public void time() { diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 4780e6c..9aabda0 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -3072,7 +3072,7 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand public String clientSetname(final String name) { checkIsInMulti(); client.clientSetname(name); - return client.getBulkReply(); + return client.getStatusCodeReply(); } public String migrate(final String host, final int port, final String key, final int destinationDb, final int timeout) { diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index 0960c8e..d167b84 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -155,7 +155,7 @@ public final class Protocol { public static enum Command { PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, SENTINEL, - DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL, INCRBYFLOAT, PSETEX, CLIENT_KILL, CLIENT_GETNAME, CLIENT_SETNAME, CLIENT_LIST, TIME, MIGRATE, HINCRBYFLOAT; + DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL, INCRBYFLOAT, PSETEX, CLIENT, TIME, MIGRATE, HINCRBYFLOAT; public final byte[] raw; @@ -165,7 +165,8 @@ public final class Protocol { } public static enum Keyword { - AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT, RESET, FLUSH, EXISTS, LOAD, KILL, LEN, REFCOUNT, ENCODING, IDLETIME, AND, OR, XOR, NOT; + AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT, RESET, FLUSH, EXISTS, LOAD, KILL, LEN, REFCOUNT, ENCODING, IDLETIME, AND, OR, XOR, NOT, + GETNAME, SETNAME,LIST; public final byte[] raw; Keyword() { From fffd119c63db1554c24bd988273b0ea6c9c71bce Mon Sep 17 00:00:00 2001 From: mindwind Date: Mon, 8 Jul 2013 16:26:13 +0800 Subject: [PATCH 109/112] fix - pipeline sort --- .../jedis/MultiKeyBinaryRedisPipeline.java | 4 ++-- .../clients/jedis/MultiKeyCommandsPipeline.java | 4 ++-- .../clients/jedis/MultiKeyPipelineBase.java | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java b/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java index 85d004b..d77ddd9 100644 --- a/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java +++ b/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java @@ -39,9 +39,9 @@ public interface MultiKeyBinaryRedisPipeline { Response smove(byte[] srckey, byte[] dstkey, byte[] member); - Response> sort(byte[] key, SortingParams sortingParameters, byte[] dstkey); + Response sort(byte[] key, SortingParams sortingParameters, byte[] dstkey); - Response> sort(byte[] key, byte[] dstkey); + Response sort(byte[] key, byte[] dstkey); Response> sunion(byte[]... keys); diff --git a/src/main/java/redis/clients/jedis/MultiKeyCommandsPipeline.java b/src/main/java/redis/clients/jedis/MultiKeyCommandsPipeline.java index 1478e81..ee9af65 100644 --- a/src/main/java/redis/clients/jedis/MultiKeyCommandsPipeline.java +++ b/src/main/java/redis/clients/jedis/MultiKeyCommandsPipeline.java @@ -39,9 +39,9 @@ public interface MultiKeyCommandsPipeline { Response smove(String srckey, String dstkey, String member); - Response> sort(String key, SortingParams sortingParameters, String dstkey); + Response sort(String key, SortingParams sortingParameters, String dstkey); - Response> sort(String key, String dstkey); + Response sort(String key, String dstkey); Response> sunion(String... keys); diff --git a/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java b/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java index 46fede3..be9d89a 100644 --- a/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java +++ b/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java @@ -191,26 +191,26 @@ abstract class MultiKeyPipelineBase extends PipelineBase implements return getResponse(BuilderFactory.LONG); } - public Response> sort(String key, + public Response sort(String key, SortingParams sortingParameters, String dstkey) { client.sort(key, sortingParameters, dstkey); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.LONG); } - public Response> sort(byte[] key, + public Response sort(byte[] key, SortingParams sortingParameters, byte[] dstkey) { client.sort(key, sortingParameters, dstkey); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + return getResponse(BuilderFactory.LONG); } - public Response> sort(String key, String dstkey) { + public Response sort(String key, String dstkey) { client.sort(key, dstkey); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.LONG); } - public Response> sort(byte[] key, byte[] dstkey) { + public Response sort(byte[] key, byte[] dstkey) { client.sort(key, dstkey); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + return getResponse(BuilderFactory.LONG); } public Response> sunion(String... keys) { From 5f11954d31c7c657c527b4be4ac7dade2784f38b Mon Sep 17 00:00:00 2001 From: mindwind Date: Tue, 9 Jul 2013 16:42:01 +0800 Subject: [PATCH 110/112] fix - pipeline zadd method signature from: zadd(String key, double score, String member) to: zadd(String key, Map scoreMembers) --- src/main/java/redis/clients/jedis/PipelineBase.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/redis/clients/jedis/PipelineBase.java b/src/main/java/redis/clients/jedis/PipelineBase.java index aaa6db3..81f65f9 100644 --- a/src/main/java/redis/clients/jedis/PipelineBase.java +++ b/src/main/java/redis/clients/jedis/PipelineBase.java @@ -649,8 +649,8 @@ abstract class PipelineBase extends Queable implements return getResponse(BuilderFactory.STRING); } - public Response zadd(String key, double score, String member) { - getClient(key).zadd(key, score, member); + public Response zadd(String key, Map scoreMembers) { + getClient(key).zadd(key, scoreMembers); return getResponse(BuilderFactory.LONG); } From a1471e66e96b5ab3e99487ba692e886f29264e0b Mon Sep 17 00:00:00 2001 From: mindwind Date: Mon, 15 Jul 2013 15:56:34 +0800 Subject: [PATCH 111/112] del --- build.sh | 1 - 1 file changed, 1 deletion(-) delete mode 100755 build.sh diff --git a/build.sh b/build.sh deleted file mode 100755 index 53fdc96..0000000 --- a/build.sh +++ /dev/null @@ -1 +0,0 @@ -mvn -B install -Dmaven.test.skip=true \ No newline at end of file From 155aff09e05395abe2df49a3a38dcc969da41cf3 Mon Sep 17 00:00:00 2001 From: mindwind Date: Mon, 15 Jul 2013 15:57:03 +0800 Subject: [PATCH 112/112] fix - recover zadd with one score memeber --- src/main/java/redis/clients/jedis/PipelineBase.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/redis/clients/jedis/PipelineBase.java b/src/main/java/redis/clients/jedis/PipelineBase.java index 81f65f9..315716c 100644 --- a/src/main/java/redis/clients/jedis/PipelineBase.java +++ b/src/main/java/redis/clients/jedis/PipelineBase.java @@ -648,6 +648,11 @@ abstract class PipelineBase extends Queable implements getClient(key).type(key); return getResponse(BuilderFactory.STRING); } + + public Response zadd(String key, double score, String member) { + getClient(key).zadd(key, score, member); + return getResponse(BuilderFactory.LONG); + } public Response zadd(String key, Map scoreMembers) { getClient(key).zadd(key, scoreMembers);