Merge branch 'variadic' of git://github.com/ivowiblo/jedis into variadic

Conflicts:
	src/main/java/redis/clients/jedis/BinaryClient.java
	src/main/java/redis/clients/jedis/BinaryJedis.java
	src/main/java/redis/clients/jedis/BinaryShardedJedis.java
	src/main/java/redis/clients/jedis/Client.java
	src/main/java/redis/clients/jedis/Commands.java
	src/main/java/redis/clients/jedis/Jedis.java
	src/main/java/redis/clients/jedis/ShardedJedis.java
This commit is contained in:
Jonathan Leibiusky
2012-04-23 21:00:29 -03:00
13 changed files with 976 additions and 730 deletions

View File

@@ -2,13 +2,13 @@ package redis.clients.jedis;
import static redis.clients.jedis.Protocol.toByteArray; import static redis.clients.jedis.Protocol.toByteArray;
import static redis.clients.jedis.Protocol.Command.*; import static redis.clients.jedis.Protocol.Command.*;
import static redis.clients.jedis.Protocol.Keyword.LEN;
import static redis.clients.jedis.Protocol.Keyword.LIMIT; import static redis.clients.jedis.Protocol.Keyword.LIMIT;
import static redis.clients.jedis.Protocol.Keyword.NO; import static redis.clients.jedis.Protocol.Keyword.NO;
import static redis.clients.jedis.Protocol.Keyword.ONE; import static redis.clients.jedis.Protocol.Keyword.ONE;
import static redis.clients.jedis.Protocol.Keyword.RESET;
import static redis.clients.jedis.Protocol.Keyword.STORE; import static redis.clients.jedis.Protocol.Keyword.STORE;
import static redis.clients.jedis.Protocol.Keyword.WITHSCORES; 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.ArrayList;
import java.util.List; import java.util.List;
@@ -47,6 +47,15 @@ public class BinaryClient extends Connection {
super(host, 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 < rest.length; i++) {
result[i + 1] = rest[i];
}
return result;
}
public void setPassword(final String password) { public void setPassword(final String password) {
this.password = password; this.password = password;
} }
@@ -230,8 +239,8 @@ public class BinaryClient extends Connection {
sendCommand(HEXISTS, key, field); sendCommand(HEXISTS, key, field);
} }
public void hdel(final byte[] key, final byte[] field) { public void hdel(final byte[] key, final byte[]... fields) {
sendCommand(HDEL, key, field); sendCommand(HDEL, joinParameters(key, fields));
} }
public void hlen(final byte[] key) { public void hlen(final byte[] key) {
@@ -250,18 +259,12 @@ public class BinaryClient extends Connection {
sendCommand(HGETALL, key); sendCommand(HGETALL, key);
} }
public void rpush(final byte[] key, final byte[]... vals) { public void rpush(final byte[] key, final byte[]... strings) {
byte[][] args = new byte[vals.length + 1][]; sendCommand(RPUSH, joinParameters(key, strings));
args[0] = key;
System.arraycopy(vals, 0, args, 1, vals.length);
sendCommand(RPUSH, args);
} }
public void lpush(final byte[] key, final byte[]... vals) { public void lpush(final byte[] key, final byte[]... strings) {
byte[][] args = new byte[vals.length + 1][]; sendCommand(LPUSH, joinParameters(key, strings));
args[0] = key;
System.arraycopy(vals, 0, args, 1, vals.length);
sendCommand(LPUSH, args);
} }
public void llen(final byte[] key) { public void llen(final byte[] key) {
@@ -300,16 +303,16 @@ public class BinaryClient extends Connection {
sendCommand(RPOPLPUSH, srckey, dstkey); sendCommand(RPOPLPUSH, srckey, dstkey);
} }
public void sadd(final byte[] key, final byte[] member) { public void sadd(final byte[] key, final byte[]... members) {
sendCommand(SADD, key, member); sendCommand(SADD, joinParameters(key, members));
} }
public void smembers(final byte[] key) { public void smembers(final byte[] key) {
sendCommand(SMEMBERS, key); sendCommand(SMEMBERS, key);
} }
public void srem(final byte[] key, final byte[] member) { public void srem(final byte[] key, final byte[]... members) {
sendCommand(SREM, key, member); sendCommand(SREM, joinParameters(key, members));
} }
public void spop(final byte[] key) { public void spop(final byte[] key) {
@@ -370,12 +373,29 @@ public class BinaryClient extends Connection {
sendCommand(ZADD, key, toByteArray(score), member); sendCommand(ZADD, key, toByteArray(score), member);
} }
public void zaddBinary(final byte[] key, Map<Double, byte[]> scoreMembers) {
ArrayList<byte[]> args = new ArrayList<byte[]>(
scoreMembers.size() * 2 + 1);
args.add(key);
for (Map.Entry<Double, byte[]> 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) { public void zrange(final byte[] key, final int start, final int end) {
sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end)); sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end));
} }
public void zrem(final byte[] key, final byte[] member) { public void zrem(final byte[] key, final byte[]... members) {
sendCommand(ZREM, key, member); sendCommand(ZREM, joinParameters(key, members));
} }
public void zincrby(final byte[] key, final double score, public void zincrby(final byte[] key, final double score,
@@ -785,4 +805,4 @@ public class BinaryClient extends Connection {
public void slowlogLen() { public void slowlogLen() {
sendCommand(SLOWLOG, LEN.raw); sendCommand(SLOWLOG, LEN.raw);
} }
} }

View File

@@ -1,6 +1,6 @@
package redis.clients.jedis; package redis.clients.jedis;
import static redis.clients.jedis.Protocol.Command.SCRIPT; import static redis.clients.jedis.Protocol.toByteArray;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@@ -11,12 +11,10 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import redis.clients.jedis.BinaryClient.LIST_POSITION; import redis.clients.jedis.BinaryClient.LIST_POSITION;
import redis.clients.jedis.Protocol.Keyword;
import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.exceptions.JedisException; import redis.clients.jedis.exceptions.JedisException;
import redis.clients.util.JedisByteHashMap; import redis.clients.util.JedisByteHashMap;
import redis.clients.util.SafeEncoder; import redis.clients.util.SafeEncoder;
import static redis.clients.jedis.Protocol.toByteArray;
public class BinaryJedis implements BinaryJedisCommands { public class BinaryJedis implements BinaryJedisCommands {
protected Client client = null; protected Client client = null;
@@ -800,13 +798,13 @@ public class BinaryJedis implements BinaryJedisCommands {
* <b>Time complexity:</b> O(1) * <b>Time complexity:</b> O(1)
* *
* @param key * @param key
* @param field * @param fields
* @return If the field was present in the hash it is deleted and 1 is * @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. * 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(); checkIsInMulti();
client.hdel(key, field); client.hdel(key, fields);
return client.getIntegerReply(); return client.getIntegerReply();
} }
@@ -885,16 +883,16 @@ public class BinaryJedis implements BinaryJedisCommands {
* <p> * <p>
* Time complexity: O(1) * Time complexity: O(1)
* *
* @see BinaryJedis#lpush(byte[], byte[]) * @see BinaryJedis#rpush(byte[], byte[]...)
* *
* @param key * @param key
* @param string * @param strings
* @return Integer reply, specifically, the number of elements inside the * @return Integer reply, specifically, the number of elements inside the
* list after the push operation. * list after the push operation.
*/ */
public Long rpush(final byte[] key, final byte[]... string) { public Long rpush(final byte[] key, final byte[]... strings) {
checkIsInMulti(); checkIsInMulti();
client.rpush(key, string); client.rpush(key, strings);
return client.getIntegerReply(); return client.getIntegerReply();
} }
@@ -906,16 +904,16 @@ public class BinaryJedis implements BinaryJedisCommands {
* <p> * <p>
* Time complexity: O(1) * Time complexity: O(1)
* *
* @see BinaryJedis#rpush(byte[], byte[]) * @see BinaryJedis#rpush(byte[], byte[]...)
* *
* @param key * @param key
* @param string * @param strings
* @return Integer reply, specifically, the number of elements inside the * @return Integer reply, specifically, the number of elements inside the
* list after the push operation. * list after the push operation.
*/ */
public Long lpush(final byte[] key, final byte[]... string) { public Long lpush(final byte[] key, final byte[]... strings) {
checkIsInMulti(); checkIsInMulti();
client.lpush(key, string); client.lpush(key, strings);
return client.getIntegerReply(); return client.getIntegerReply();
} }
@@ -1166,13 +1164,13 @@ public class BinaryJedis implements BinaryJedisCommands {
* Time complexity O(1) * Time complexity O(1)
* *
* @param key * @param key
* @param member * @param members
* @return Integer reply, specifically: 1 if the new element was added 0 if * @return Integer reply, specifically: 1 if the new element was added 0 if
* the element was already a member of the set * 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(); checkIsInMulti();
client.sadd(key, member); client.sadd(key, members);
return client.getIntegerReply(); return client.getIntegerReply();
} }
@@ -1204,7 +1202,7 @@ public class BinaryJedis implements BinaryJedisCommands {
* @return Integer reply, specifically: 1 if the new element was removed 0 * @return Integer reply, specifically: 1 if the new element was removed 0
* if the new element was not a member of the set * 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(); checkIsInMulti();
client.srem(key, member); client.srem(key, member);
return client.getIntegerReply(); return client.getIntegerReply();
@@ -1463,6 +1461,12 @@ public class BinaryJedis implements BinaryJedisCommands {
return client.getIntegerReply(); return client.getIntegerReply();
} }
public Long zadd(final byte[] key, final Map<Double, byte[]> scoreMembers) {
checkIsInMulti();
client.zaddBinary(key, scoreMembers);
return client.getIntegerReply();
}
public Set<byte[]> zrange(final byte[] key, final int start, final int end) { public Set<byte[]> zrange(final byte[] key, final int start, final int end) {
checkIsInMulti(); checkIsInMulti();
client.zrange(key, start, end); client.zrange(key, start, end);
@@ -1481,13 +1485,13 @@ public class BinaryJedis implements BinaryJedisCommands {
* *
* *
* @param key * @param key
* @param member * @param members
* @return Integer reply, specifically: 1 if the new element was removed 0 * @return Integer reply, specifically: 1 if the new element was removed 0
* if the new element was not a member of the set * 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(); checkIsInMulti();
client.zrem(key, member); client.zrem(key, members);
return client.getIntegerReply(); return client.getIntegerReply();
} }

View File

@@ -57,7 +57,7 @@ public interface BinaryJedisCommands {
Boolean hexists(byte[] key, byte[] field); Boolean hexists(byte[] key, byte[] field);
Long hdel(byte[] key, byte[] field); Long hdel(byte[] key, byte[]... field);
Long hlen(byte[] key); Long hlen(byte[] key);
@@ -87,11 +87,11 @@ public interface BinaryJedisCommands {
byte[] rpop(byte[] key); byte[] rpop(byte[] key);
Long sadd(byte[] key, byte[] member); Long sadd(byte[] key, byte[]... member);
Set<byte[]> smembers(byte[] key); Set<byte[]> smembers(byte[] key);
Long srem(byte[] key, byte[] member); Long srem(byte[] key, byte[]... member);
byte[] spop(byte[] key); byte[] spop(byte[] key);
@@ -102,10 +102,12 @@ public interface BinaryJedisCommands {
byte[] srandmember(byte[] key); byte[] srandmember(byte[] key);
Long zadd(byte[] key, double score, byte[] member); Long zadd(byte[] key, double score, byte[] member);
Long zadd(byte[] key, Map<Double, byte[]> scoreMembers);
Set<byte[]> zrange(byte[] key, int start, int end); Set<byte[]> 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); Double zincrby(byte[] key, double score, byte[] member);

View File

@@ -1,411 +1,416 @@
package redis.clients.jedis; 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.io.IOException;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern; 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<Jedis, JedisShardInfo> public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
implements BinaryJedisCommands { implements BinaryJedisCommands {
public BinaryShardedJedis(List<JedisShardInfo> shards) { public BinaryShardedJedis(List<JedisShardInfo> shards) {
super(shards); super(shards);
} }
public BinaryShardedJedis(List<JedisShardInfo> shards, Hashing algo) { public BinaryShardedJedis(List<JedisShardInfo> shards, Hashing algo) {
super(shards, algo); super(shards, algo);
} }
public BinaryShardedJedis(List<JedisShardInfo> shards, Pattern keyTagPattern) { public BinaryShardedJedis(List<JedisShardInfo> shards, Pattern keyTagPattern) {
super(shards, keyTagPattern); super(shards, keyTagPattern);
} }
public BinaryShardedJedis(List<JedisShardInfo> shards, Hashing algo, public BinaryShardedJedis(List<JedisShardInfo> shards, Hashing algo,
Pattern keyTagPattern) { Pattern keyTagPattern) {
super(shards, algo, keyTagPattern); super(shards, algo, keyTagPattern);
} }
public void disconnect() throws IOException { public void disconnect() throws IOException {
for (Jedis jedis : getAllShards()) { for (Jedis jedis : getAllShards()) {
jedis.disconnect(); jedis.disconnect();
} }
} }
protected Jedis create(JedisShardInfo shard) { protected Jedis create(JedisShardInfo shard) {
return new Jedis(shard); return new Jedis(shard);
} }
public String set(byte[] key, byte[] value) { public String set(byte[] key, byte[] value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.set(key, value); return j.set(key, value);
} }
public byte[] get(byte[] key) { public byte[] get(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.get(key); return j.get(key);
} }
public Boolean exists(byte[] key) { public Boolean exists(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.exists(key); return j.exists(key);
} }
public String type(byte[] key) { public String type(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.type(key); return j.type(key);
} }
public Long expire(byte[] key, int seconds) { public Long expire(byte[] key, int seconds) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.expire(key, seconds); return j.expire(key, seconds);
} }
public Long expireAt(byte[] key, long unixTime) { public Long expireAt(byte[] key, long unixTime) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.expireAt(key, unixTime); return j.expireAt(key, unixTime);
} }
public Long ttl(byte[] key) { public Long ttl(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.ttl(key); return j.ttl(key);
} }
public byte[] getSet(byte[] key, byte[] value) { public byte[] getSet(byte[] key, byte[] value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.getSet(key, value); return j.getSet(key, value);
} }
public Long setnx(byte[] key, byte[] value) { public Long setnx(byte[] key, byte[] value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.setnx(key, value); return j.setnx(key, value);
} }
public String setex(byte[] key, int seconds, byte[] value) { public String setex(byte[] key, int seconds, byte[] value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.setex(key, seconds, value); return j.setex(key, seconds, value);
} }
public Long decrBy(byte[] key, long integer) { public Long decrBy(byte[] key, long integer) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.decrBy(key, integer); return j.decrBy(key, integer);
} }
public Long decr(byte[] key) { public Long decr(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.decr(key); return j.decr(key);
} }
public Long incrBy(byte[] key, long integer) { public Long incrBy(byte[] key, long integer) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.incrBy(key, integer); return j.incrBy(key, integer);
} }
public Long incr(byte[] key) { public Long incr(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.incr(key); return j.incr(key);
} }
public Long append(byte[] key, byte[] value) { public Long append(byte[] key, byte[] value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.append(key, value); return j.append(key, value);
} }
public byte[] substr(byte[] key, int start, int end) { public byte[] substr(byte[] key, int start, int end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.substr(key, start, end); return j.substr(key, start, end);
} }
public Long hset(byte[] key, byte[] field, byte[] value) { public Long hset(byte[] key, byte[] field, byte[] value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hset(key, field, value); return j.hset(key, field, value);
} }
public byte[] hget(byte[] key, byte[] field) { public byte[] hget(byte[] key, byte[] field) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hget(key, field); return j.hget(key, field);
} }
public Long hsetnx(byte[] key, byte[] field, byte[] value) { public Long hsetnx(byte[] key, byte[] field, byte[] value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hsetnx(key, field, value); return j.hsetnx(key, field, value);
} }
public String hmset(byte[] key, Map<byte[], byte[]> hash) { public String hmset(byte[] key, Map<byte[], byte[]> hash) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hmset(key, hash); return j.hmset(key, hash);
} }
public List<byte[]> hmget(byte[] key, byte[]... fields) { public List<byte[]> hmget(byte[] key, byte[]... fields) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hmget(key, fields); return j.hmget(key, fields);
} }
public Long hincrBy(byte[] key, byte[] field, long value) { public Long hincrBy(byte[] key, byte[] field, long value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hincrBy(key, field, value); return j.hincrBy(key, field, value);
} }
public Boolean hexists(byte[] key, byte[] field) { public Boolean hexists(byte[] key, byte[] field) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hexists(key, field); return j.hexists(key, field);
} }
public Long hdel(byte[] key, byte[] field) { public Long hdel(byte[] key, byte[]... fields) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hdel(key, field); return j.hdel(key, fields);
} }
public Long hlen(byte[] key) { public Long hlen(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hlen(key); return j.hlen(key);
} }
public Set<byte[]> hkeys(byte[] key) { public Set<byte[]> hkeys(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hkeys(key); return j.hkeys(key);
} }
public Collection<byte[]> hvals(byte[] key) { public Collection<byte[]> hvals(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hvals(key); return j.hvals(key);
} }
public Map<byte[], byte[]> hgetAll(byte[] key) { public Map<byte[], byte[]> hgetAll(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hgetAll(key); return j.hgetAll(key);
} }
public Long rpush(byte[] key, byte[]... string) { public Long rpush(byte[] key, byte[]... strings) {
Jedis j = getShard(key); 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); Jedis j = getShard(key);
return j.lpush(key, string); return j.lpush(key, strings);
} }
public Long llen(byte[] key) { public Long llen(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.llen(key); return j.llen(key);
} }
public List<byte[]> lrange(byte[] key, int start, int end) { public List<byte[]> lrange(byte[] key, int start, int end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.lrange(key, start, end); return j.lrange(key, start, end);
} }
public String ltrim(byte[] key, int start, int end) { public String ltrim(byte[] key, int start, int end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.ltrim(key, start, end); return j.ltrim(key, start, end);
} }
public byte[] lindex(byte[] key, int index) { public byte[] lindex(byte[] key, int index) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.lindex(key, index); return j.lindex(key, index);
} }
public String lset(byte[] key, int index, byte[] value) { public String lset(byte[] key, int index, byte[] value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.lset(key, index, value); return j.lset(key, index, value);
} }
public Long lrem(byte[] key, int count, byte[] value) { public Long lrem(byte[] key, int count, byte[] value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.lrem(key, count, value); return j.lrem(key, count, value);
} }
public byte[] lpop(byte[] key) { public byte[] lpop(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.lpop(key); return j.lpop(key);
} }
public byte[] rpop(byte[] key) { public byte[] rpop(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.rpop(key); return j.rpop(key);
} }
public Long sadd(byte[] key, byte[] member) { public Long sadd(byte[] key, byte[]... members) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.sadd(key, member); return j.sadd(key, members);
} }
public Set<byte[]> smembers(byte[] key) { public Set<byte[]> smembers(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.smembers(key); return j.smembers(key);
} }
public Long srem(byte[] key, byte[] member) { public Long srem(byte[] key, byte[]... members) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.srem(key, member); return j.srem(key, members);
} }
public byte[] spop(byte[] key) { public byte[] spop(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.spop(key); return j.spop(key);
} }
public Long scard(byte[] key) { public Long scard(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.scard(key); return j.scard(key);
} }
public Boolean sismember(byte[] key, byte[] member) { public Boolean sismember(byte[] key, byte[] member) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.sismember(key, member); return j.sismember(key, member);
} }
public byte[] srandmember(byte[] key) { public byte[] srandmember(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.srandmember(key); return j.srandmember(key);
} }
public Long zadd(byte[] key, double score, byte[] member) { public Long zadd(byte[] key, double score, byte[] member) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zadd(key, score, member); return j.zadd(key, score, member);
}
public Long zadd(byte[] key, Map<Double, byte[]> scoreMembers) {
Jedis j = getShard(key);
return j.zadd(key, scoreMembers);
} }
public Set<byte[]> zrange(byte[] key, int start, int end) { public Set<byte[]> zrange(byte[] key, int start, int end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrange(key, start, end); return j.zrange(key, start, end);
} }
public Long zrem(byte[] key, byte[] member) { public Long zrem(byte[] key, byte[]... members) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrem(key, member); return j.zrem(key, members);
} }
public Double zincrby(byte[] key, double score, byte[] member) { public Double zincrby(byte[] key, double score, byte[] member) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zincrby(key, score, member); return j.zincrby(key, score, member);
} }
public Long zrank(byte[] key, byte[] member) { public Long zrank(byte[] key, byte[] member) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrank(key, member); return j.zrank(key, member);
} }
public Long zrevrank(byte[] key, byte[] member) { public Long zrevrank(byte[] key, byte[] member) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrevrank(key, member); return j.zrevrank(key, member);
} }
public Set<byte[]> zrevrange(byte[] key, int start, int end) { public Set<byte[]> zrevrange(byte[] key, int start, int end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrevrange(key, start, end); return j.zrevrange(key, start, end);
} }
public Set<Tuple> zrangeWithScores(byte[] key, int start, int end) { public Set<Tuple> zrangeWithScores(byte[] key, int start, int end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrangeWithScores(key, start, end); return j.zrangeWithScores(key, start, end);
} }
public Set<Tuple> zrevrangeWithScores(byte[] key, int start, int end) { public Set<Tuple> zrevrangeWithScores(byte[] key, int start, int end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrevrangeWithScores(key, start, end); return j.zrevrangeWithScores(key, start, end);
} }
public Long zcard(byte[] key) { public Long zcard(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zcard(key); return j.zcard(key);
} }
public Double zscore(byte[] key, byte[] member) { public Double zscore(byte[] key, byte[] member) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zscore(key, member); return j.zscore(key, member);
} }
public List<byte[]> sort(byte[] key) { public List<byte[]> sort(byte[] key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.sort(key); return j.sort(key);
} }
public List<byte[]> sort(byte[] key, SortingParams sortingParameters) { public List<byte[]> sort(byte[] key, SortingParams sortingParameters) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.sort(key, sortingParameters); return j.sort(key, sortingParameters);
} }
public Long zcount(byte[] key, double min, double max) { public Long zcount(byte[] key, double min, double max) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zcount(key, min, max); return j.zcount(key, min, max);
} }
public Set<byte[]> zrangeByScore(byte[] key, double min, double max) { public Set<byte[]> zrangeByScore(byte[] key, double min, double max) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrangeByScore(key, min, max); return j.zrangeByScore(key, min, max);
} }
public Set<byte[]> zrangeByScore(byte[] key, double min, double max, public Set<byte[]> zrangeByScore(byte[] key, double min, double max,
int offset, int count) { int offset, int count) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrangeByScore(key, min, max, offset, count); return j.zrangeByScore(key, min, max, offset, count);
} }
public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max) { public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrangeByScoreWithScores(key, min, max); return j.zrangeByScoreWithScores(key, min, max);
} }
public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min,
double max, int offset, int count) { double max, int offset, int count) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrangeByScoreWithScores(key, min, max, offset, count); return j.zrangeByScoreWithScores(key, min, max, offset, count);
} }
public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min) { public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrevrangeByScore(key, max, min); return j.zrevrangeByScore(key, max, min);
} }
public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min, public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min,
int offset, int count) { int offset, int count) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrevrangeByScore(key, max, min, offset, count); return j.zrevrangeByScore(key, max, min, offset, count);
}
public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min) {
Jedis j = getShard(key);
return j.zrevrangeByScoreWithScores(key, max, min);
} }
public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max,
double min, int offset, int count) { double min) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrevrangeByScoreWithScores(key, max, min, offset, count); return j.zrevrangeByScoreWithScores(key, max, min);
}
public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max,
double 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) { public Long zremrangeByRank(byte[] key, int start, int end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zremrangeByRank(key, start, end); return j.zremrangeByRank(key, start, end);
} }
public Long zremrangeByScore(byte[] key, double start, double end) { public Long zremrangeByScore(byte[] key, double start, double end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zremrangeByScore(key, start, end); return j.zremrangeByScore(key, start, end);
} }
public Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, public Long linsert(byte[] key, LIST_POSITION where, byte[] pivot,
byte[] value) { byte[] value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.linsert(key, where, pivot, value); return j.linsert(key, where, pivot, value);
} }
@Deprecated @Deprecated
public List<Object> pipelined(ShardedJedisPipeline shardedJedisPipeline) { public List<Object> pipelined(ShardedJedisPipeline shardedJedisPipeline) {
shardedJedisPipeline.setShardedJedis(this); shardedJedisPipeline.setShardedJedis(this);
shardedJedisPipeline.execute(); shardedJedisPipeline.execute();
return shardedJedisPipeline.getResults(); return shardedJedisPipeline.getResults();
} }
public ShardedJedisPipeline pipelined() { public ShardedJedisPipeline pipelined() {
ShardedJedisPipeline pipeline = new ShardedJedisPipeline(); ShardedJedisPipeline pipeline = new ShardedJedisPipeline();
pipeline.setShardedJedis(this); pipeline.setShardedJedis(this);
return pipeline; return pipeline;
} }
} }

View File

@@ -1,640 +1,639 @@
package redis.clients.jedis; package redis.clients.jedis;
import redis.clients.jedis.Protocol.Keyword; import static redis.clients.jedis.Protocol.toByteArray;
import redis.clients.util.SafeEncoder;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import static redis.clients.jedis.Protocol.toByteArray; import redis.clients.util.SafeEncoder;
import static redis.clients.jedis.Protocol.Command.SCRIPT;
public class Client extends BinaryClient implements Commands { public class Client extends BinaryClient implements Commands {
public Client(final String host) { public Client(final String host) {
super(host); super(host);
} }
public Client(final String host, final int port) { public Client(final String host, final int port) {
super(host, port); super(host, port);
} }
public void set(final String key, final String value) { public void set(final String key, final String value) {
set(SafeEncoder.encode(key), SafeEncoder.encode(value)); set(SafeEncoder.encode(key), SafeEncoder.encode(value));
} }
public void get(final String key) { public void get(final String key) {
get(SafeEncoder.encode(key)); get(SafeEncoder.encode(key));
} }
public void exists(final String key) { public void exists(final String key) {
exists(SafeEncoder.encode(key)); exists(SafeEncoder.encode(key));
} }
public void del(final String... keys) { public void del(final String... keys) {
final byte[][] bkeys = new byte[keys.length][]; final byte[][] bkeys = new byte[keys.length][];
for (int i = 0; i < keys.length; i++) { for (int i = 0; i < keys.length; i++) {
bkeys[i] = SafeEncoder.encode(keys[i]); bkeys[i] = SafeEncoder.encode(keys[i]);
} }
del(bkeys); del(bkeys);
} }
public void type(final String key) { public void type(final String key) {
type(SafeEncoder.encode(key)); type(SafeEncoder.encode(key));
} }
public void keys(final String pattern) { public void keys(final String pattern) {
keys(SafeEncoder.encode(pattern)); keys(SafeEncoder.encode(pattern));
} }
public void rename(final String oldkey, final String newkey) { public void rename(final String oldkey, final String newkey) {
rename(SafeEncoder.encode(oldkey), SafeEncoder.encode(newkey)); rename(SafeEncoder.encode(oldkey), SafeEncoder.encode(newkey));
} }
public void renamenx(final String oldkey, final String newkey) { public void renamenx(final String oldkey, final String newkey) {
renamenx(SafeEncoder.encode(oldkey), SafeEncoder.encode(newkey)); renamenx(SafeEncoder.encode(oldkey), SafeEncoder.encode(newkey));
} }
public void expire(final String key, final int seconds) { public void expire(final String key, final int seconds) {
expire(SafeEncoder.encode(key), seconds); expire(SafeEncoder.encode(key), seconds);
} }
public void expireAt(final String key, final long unixTime) { public void expireAt(final String key, final long unixTime) {
expireAt(SafeEncoder.encode(key), unixTime); expireAt(SafeEncoder.encode(key), unixTime);
} }
public void ttl(final String key) { public void ttl(final String key) {
ttl(SafeEncoder.encode(key)); ttl(SafeEncoder.encode(key));
} }
public void move(final String key, final int dbIndex) { public void move(final String key, final int dbIndex) {
move(SafeEncoder.encode(key), dbIndex); move(SafeEncoder.encode(key), dbIndex);
} }
public void getSet(final String key, final String value) { public void getSet(final String key, final String value) {
getSet(SafeEncoder.encode(key), SafeEncoder.encode(value)); getSet(SafeEncoder.encode(key), SafeEncoder.encode(value));
} }
public void mget(final String... keys) { public void mget(final String... keys) {
final byte[][] bkeys = new byte[keys.length][]; final byte[][] bkeys = new byte[keys.length][];
for (int i = 0; i < bkeys.length; i++) { for (int i = 0; i < bkeys.length; i++) {
bkeys[i] = SafeEncoder.encode(keys[i]); bkeys[i] = SafeEncoder.encode(keys[i]);
} }
mget(bkeys); mget(bkeys);
} }
public void setnx(final String key, final String value) { public void setnx(final String key, final String value) {
setnx(SafeEncoder.encode(key), SafeEncoder.encode(value)); setnx(SafeEncoder.encode(key), SafeEncoder.encode(value));
} }
public void setex(final String key, final int seconds, final String value) { public void setex(final String key, final int seconds, final String value) {
setex(SafeEncoder.encode(key), seconds, SafeEncoder.encode(value)); setex(SafeEncoder.encode(key), seconds, SafeEncoder.encode(value));
} }
public void mset(final String... keysvalues) { public void mset(final String... keysvalues) {
final byte[][] bkeysvalues = new byte[keysvalues.length][]; final byte[][] bkeysvalues = new byte[keysvalues.length][];
for (int i = 0; i < keysvalues.length; i++) { for (int i = 0; i < keysvalues.length; i++) {
bkeysvalues[i] = SafeEncoder.encode(keysvalues[i]); bkeysvalues[i] = SafeEncoder.encode(keysvalues[i]);
} }
mset(bkeysvalues); mset(bkeysvalues);
} }
public void msetnx(final String... keysvalues) { public void msetnx(final String... keysvalues) {
final byte[][] bkeysvalues = new byte[keysvalues.length][]; final byte[][] bkeysvalues = new byte[keysvalues.length][];
for (int i = 0; i < keysvalues.length; i++) { for (int i = 0; i < keysvalues.length; i++) {
bkeysvalues[i] = SafeEncoder.encode(keysvalues[i]); bkeysvalues[i] = SafeEncoder.encode(keysvalues[i]);
} }
msetnx(bkeysvalues); msetnx(bkeysvalues);
} }
public void decrBy(final String key, final long integer) { public void decrBy(final String key, final long integer) {
decrBy(SafeEncoder.encode(key), integer); decrBy(SafeEncoder.encode(key), integer);
} }
public void decr(final String key) { public void decr(final String key) {
decr(SafeEncoder.encode(key)); decr(SafeEncoder.encode(key));
} }
public void incrBy(final String key, final long integer) { public void incrBy(final String key, final long integer) {
incrBy(SafeEncoder.encode(key), integer); incrBy(SafeEncoder.encode(key), integer);
} }
public void incr(final String key) { public void incr(final String key) {
incr(SafeEncoder.encode(key)); incr(SafeEncoder.encode(key));
} }
public void append(final String key, final String value) { public void append(final String key, final String value) {
append(SafeEncoder.encode(key), SafeEncoder.encode(value)); append(SafeEncoder.encode(key), SafeEncoder.encode(value));
} }
public void substr(final String key, final int start, final int end) { public void substr(final String key, final int start, final int end) {
substr(SafeEncoder.encode(key), start, end); substr(SafeEncoder.encode(key), start, end);
} }
public void hset(final String key, final String field, final String value) { public void hset(final String key, final String field, final String value) {
hset(SafeEncoder.encode(key), SafeEncoder.encode(field), SafeEncoder hset(SafeEncoder.encode(key), SafeEncoder.encode(field),
.encode(value)); SafeEncoder.encode(value));
} }
public void hget(final String key, final String field) { public void hget(final String key, final String field) {
hget(SafeEncoder.encode(key), SafeEncoder.encode(field)); hget(SafeEncoder.encode(key), SafeEncoder.encode(field));
} }
public void hsetnx(final String key, final String field, final String value) { public void hsetnx(final String key, final String field, final String value) {
hsetnx(SafeEncoder.encode(key), SafeEncoder.encode(field), SafeEncoder hsetnx(SafeEncoder.encode(key), SafeEncoder.encode(field),
.encode(value)); SafeEncoder.encode(value));
} }
public void hmset(final String key, final Map<String, String> hash) { public void hmset(final String key, final Map<String, String> hash) {
final Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>(hash final Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>(
.size()); hash.size());
for (final Entry<String, String> entry : hash.entrySet()) { for (final Entry<String, String> entry : hash.entrySet()) {
bhash.put(SafeEncoder.encode(entry.getKey()), SafeEncoder bhash.put(SafeEncoder.encode(entry.getKey()),
.encode(entry.getValue())); SafeEncoder.encode(entry.getValue()));
} }
hmset(SafeEncoder.encode(key), bhash); hmset(SafeEncoder.encode(key), bhash);
} }
public void hmget(final String key, final String... fields) { public void hmget(final String key, final String... fields) {
final byte[][] bfields = new byte[fields.length][]; final byte[][] bfields = new byte[fields.length][];
for (int i = 0; i < bfields.length; i++) { for (int i = 0; i < bfields.length; i++) {
bfields[i] = SafeEncoder.encode(fields[i]); bfields[i] = SafeEncoder.encode(fields[i]);
} }
hmget(SafeEncoder.encode(key), bfields); hmget(SafeEncoder.encode(key), bfields);
} }
public void hincrBy(final String key, final String field, final long value) { public void hincrBy(final String key, final String field, final long value) {
hincrBy(SafeEncoder.encode(key), SafeEncoder.encode(field), value); hincrBy(SafeEncoder.encode(key), SafeEncoder.encode(field), value);
} }
public void hexists(final String key, final String field) { public void hexists(final String key, final String field) {
hexists(SafeEncoder.encode(key), SafeEncoder.encode(field)); hexists(SafeEncoder.encode(key), SafeEncoder.encode(field));
} }
public void hdel(final String key, final String field) { public void hdel(final String key, final String... fields) {
hdel(SafeEncoder.encode(key), SafeEncoder.encode(field)); hdel(SafeEncoder.encode(key), SafeEncoder.encodeMany(fields));
} }
public void hlen(final String key) { public void hlen(final String key) {
hlen(SafeEncoder.encode(key)); hlen(SafeEncoder.encode(key));
} }
public void hkeys(final String key) { public void hkeys(final String key) {
hkeys(SafeEncoder.encode(key)); hkeys(SafeEncoder.encode(key));
} }
public void hvals(final String key) { public void hvals(final String key) {
hvals(SafeEncoder.encode(key)); hvals(SafeEncoder.encode(key));
} }
public void hgetAll(final String key) { public void hgetAll(final String key) {
hgetAll(SafeEncoder.encode(key)); hgetAll(SafeEncoder.encode(key));
} }
public void rpush(final String key, final String... string) {
public void rpush(final String key, final String... vals) { rpush(SafeEncoder.encode(key), SafeEncoder.encodeMany(string));
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) {
public void lpush(final String key, final String... vals) { lpush(SafeEncoder.encode(key), SafeEncoder.encodeMany(string));
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) { public void llen(final String key) {
llen(SafeEncoder.encode(key)); llen(SafeEncoder.encode(key));
} }
public void lrange(final String key, final long start, final long end) { public void lrange(final String key, final long start, final long end) {
lrange(SafeEncoder.encode(key), start, end); lrange(SafeEncoder.encode(key), start, end);
} }
public void ltrim(final String key, final long start, final long end) { public void ltrim(final String key, final long start, final long end) {
ltrim(SafeEncoder.encode(key), start, end); ltrim(SafeEncoder.encode(key), start, end);
} }
public void lindex(final String key, final long index) { public void lindex(final String key, final long index) {
lindex(SafeEncoder.encode(key), index); lindex(SafeEncoder.encode(key), index);
} }
public void lset(final String key, final long index, final String value) { public void lset(final String key, final long index, final String value) {
lset(SafeEncoder.encode(key), index, SafeEncoder.encode(value)); lset(SafeEncoder.encode(key), index, SafeEncoder.encode(value));
} }
public void lrem(final String key, long count, final String value) { public void lrem(final String key, long count, final String value) {
lrem(SafeEncoder.encode(key), count, SafeEncoder.encode(value)); lrem(SafeEncoder.encode(key), count, SafeEncoder.encode(value));
} }
public void lpop(final String key) { public void lpop(final String key) {
lpop(SafeEncoder.encode(key)); lpop(SafeEncoder.encode(key));
} }
public void rpop(final String key) { public void rpop(final String key) {
rpop(SafeEncoder.encode(key)); rpop(SafeEncoder.encode(key));
} }
public void rpoplpush(final String srckey, final String dstkey) { public void rpoplpush(final String srckey, final String dstkey) {
rpoplpush(SafeEncoder.encode(srckey), SafeEncoder.encode(dstkey)); rpoplpush(SafeEncoder.encode(srckey), SafeEncoder.encode(dstkey));
} }
public void sadd(final String key, final String member) { public void sadd(final String key, final String... members) {
sadd(SafeEncoder.encode(key), SafeEncoder.encode(member)); sadd(SafeEncoder.encode(key), SafeEncoder.encodeMany(members));
} }
public void smembers(final String key) { public void smembers(final String key) {
smembers(SafeEncoder.encode(key)); smembers(SafeEncoder.encode(key));
} }
public void srem(final String key, final String member) { public void srem(final String key, final String... members) {
srem(SafeEncoder.encode(key), SafeEncoder.encode(member)); srem(SafeEncoder.encode(key), SafeEncoder.encodeMany(members));
} }
public void spop(final String key) { public void spop(final String key) {
spop(SafeEncoder.encode(key)); spop(SafeEncoder.encode(key));
} }
public void smove(final String srckey, final String dstkey, public void smove(final String srckey, final String dstkey,
final String member) { final String member) {
smove(SafeEncoder.encode(srckey), SafeEncoder.encode(dstkey), smove(SafeEncoder.encode(srckey), SafeEncoder.encode(dstkey),
SafeEncoder.encode(member)); SafeEncoder.encode(member));
} }
public void scard(final String key) { public void scard(final String key) {
scard(SafeEncoder.encode(key)); scard(SafeEncoder.encode(key));
} }
public void sismember(final String key, final String member) { public void sismember(final String key, final String member) {
sismember(SafeEncoder.encode(key), SafeEncoder.encode(member)); sismember(SafeEncoder.encode(key), SafeEncoder.encode(member));
} }
public void sinter(final String... keys) { public void sinter(final String... keys) {
final byte[][] bkeys = new byte[keys.length][]; final byte[][] bkeys = new byte[keys.length][];
for (int i = 0; i < bkeys.length; i++) { for (int i = 0; i < bkeys.length; i++) {
bkeys[i] = SafeEncoder.encode(keys[i]); bkeys[i] = SafeEncoder.encode(keys[i]);
} }
sinter(bkeys); sinter(bkeys);
} }
public void sinterstore(final String dstkey, final String... keys) { public void sinterstore(final String dstkey, final String... keys) {
final byte[][] bkeys = new byte[keys.length][]; final byte[][] bkeys = new byte[keys.length][];
for (int i = 0; i < bkeys.length; i++) { for (int i = 0; i < bkeys.length; i++) {
bkeys[i] = SafeEncoder.encode(keys[i]); bkeys[i] = SafeEncoder.encode(keys[i]);
} }
sinterstore(SafeEncoder.encode(dstkey), bkeys); sinterstore(SafeEncoder.encode(dstkey), bkeys);
} }
public void sunion(final String... keys) { public void sunion(final String... keys) {
final byte[][] bkeys = new byte[keys.length][]; final byte[][] bkeys = new byte[keys.length][];
for (int i = 0; i < bkeys.length; i++) { for (int i = 0; i < bkeys.length; i++) {
bkeys[i] = SafeEncoder.encode(keys[i]); bkeys[i] = SafeEncoder.encode(keys[i]);
} }
sunion(bkeys); sunion(bkeys);
} }
public void sunionstore(final String dstkey, final String... keys) { public void sunionstore(final String dstkey, final String... keys) {
final byte[][] bkeys = new byte[keys.length][]; final byte[][] bkeys = new byte[keys.length][];
for (int i = 0; i < bkeys.length; i++) { for (int i = 0; i < bkeys.length; i++) {
bkeys[i] = SafeEncoder.encode(keys[i]); bkeys[i] = SafeEncoder.encode(keys[i]);
} }
sunionstore(SafeEncoder.encode(dstkey), bkeys); sunionstore(SafeEncoder.encode(dstkey), bkeys);
} }
public void sdiff(final String... keys) { public void sdiff(final String... keys) {
final byte[][] bkeys = new byte[keys.length][]; final byte[][] bkeys = new byte[keys.length][];
for (int i = 0; i < bkeys.length; i++) { for (int i = 0; i < bkeys.length; i++) {
bkeys[i] = SafeEncoder.encode(keys[i]); bkeys[i] = SafeEncoder.encode(keys[i]);
} }
sdiff(bkeys); sdiff(bkeys);
} }
public void sdiffstore(final String dstkey, final String... keys) { public void sdiffstore(final String dstkey, final String... keys) {
final byte[][] bkeys = new byte[keys.length][]; final byte[][] bkeys = new byte[keys.length][];
for (int i = 0; i < bkeys.length; i++) { for (int i = 0; i < bkeys.length; i++) {
bkeys[i] = SafeEncoder.encode(keys[i]); bkeys[i] = SafeEncoder.encode(keys[i]);
} }
sdiffstore(SafeEncoder.encode(dstkey), bkeys); sdiffstore(SafeEncoder.encode(dstkey), bkeys);
} }
public void srandmember(final String key) { public void srandmember(final String key) {
srandmember(SafeEncoder.encode(key)); srandmember(SafeEncoder.encode(key));
} }
public void zadd(final String key, final double score, final String member) { public void zadd(final String key, final double score, final String member) {
zadd(SafeEncoder.encode(key), score, SafeEncoder.encode(member)); 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 int start, final int end) {
zrange(SafeEncoder.encode(key), start, end); zrange(SafeEncoder.encode(key), start, end);
} }
public void zrem(final String key, final String member) { public void zrem(final String key, final String... members) {
zrem(SafeEncoder.encode(key), SafeEncoder.encode(member)); zrem(SafeEncoder.encode(key), SafeEncoder.encodeMany(members));
} }
public void zincrby(final String key, final double score, public void zincrby(final String key, final double score,
final String member) { final String member) {
zincrby(SafeEncoder.encode(key), score, SafeEncoder.encode(member)); zincrby(SafeEncoder.encode(key), score, SafeEncoder.encode(member));
} }
public void zrank(final String key, final String member) { public void zrank(final String key, final String member) {
zrank(SafeEncoder.encode(key), SafeEncoder.encode(member)); zrank(SafeEncoder.encode(key), SafeEncoder.encode(member));
} }
public void zrevrank(final String key, final String member) { public void zrevrank(final String key, final String member) {
zrevrank(SafeEncoder.encode(key), SafeEncoder.encode(member)); 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 int start, final int end) {
zrevrange(SafeEncoder.encode(key), start, end); zrevrange(SafeEncoder.encode(key), start, end);
} }
public void zrangeWithScores(final String key, final int start, public void zrangeWithScores(final String key, final int start,
final int end) { final int end) {
zrangeWithScores(SafeEncoder.encode(key), start, end); zrangeWithScores(SafeEncoder.encode(key), start, end);
} }
public void zrevrangeWithScores(final String key, final int start, public void zrevrangeWithScores(final String key, final int start,
final int end) { final int end) {
zrevrangeWithScores(SafeEncoder.encode(key), start, end); zrevrangeWithScores(SafeEncoder.encode(key), start, end);
} }
public void zcard(final String key) { public void zcard(final String key) {
zcard(SafeEncoder.encode(key)); zcard(SafeEncoder.encode(key));
} }
public void zscore(final String key, final String member) { public void zscore(final String key, final String member) {
zscore(SafeEncoder.encode(key), SafeEncoder.encode(member)); zscore(SafeEncoder.encode(key), SafeEncoder.encode(member));
} }
public void watch(final String... keys) { public void watch(final String... keys) {
final byte[][] bargs = new byte[keys.length][]; final byte[][] bargs = new byte[keys.length][];
for (int i = 0; i < bargs.length; i++) { for (int i = 0; i < bargs.length; i++) {
bargs[i] = SafeEncoder.encode(keys[i]); bargs[i] = SafeEncoder.encode(keys[i]);
} }
watch(bargs); watch(bargs);
} }
public void sort(final String key) { public void sort(final String key) {
sort(SafeEncoder.encode(key)); sort(SafeEncoder.encode(key));
} }
public void sort(final String key, final SortingParams sortingParameters) { public void sort(final String key, final SortingParams sortingParameters) {
sort(SafeEncoder.encode(key), sortingParameters); sort(SafeEncoder.encode(key), sortingParameters);
} }
public void blpop(final String[] args) { public void blpop(final String[] args) {
final byte[][] bargs = new byte[args.length][]; final byte[][] bargs = new byte[args.length][];
for (int i = 0; i < bargs.length; i++) { for (int i = 0; i < bargs.length; i++) {
bargs[i] = SafeEncoder.encode(args[i]); bargs[i] = SafeEncoder.encode(args[i]);
} }
blpop(bargs); blpop(bargs);
} }
public void sort(final String key, final SortingParams sortingParameters, public void sort(final String key, final SortingParams sortingParameters,
final String dstkey) { final String dstkey) {
sort(SafeEncoder.encode(key), sortingParameters, SafeEncoder sort(SafeEncoder.encode(key), sortingParameters,
.encode(dstkey)); SafeEncoder.encode(dstkey));
} }
public void sort(final String key, final String dstkey) { public void sort(final String key, final String dstkey) {
sort(SafeEncoder.encode(key), SafeEncoder.encode(dstkey)); sort(SafeEncoder.encode(key), SafeEncoder.encode(dstkey));
} }
public void brpop(final String[] args) { public void brpop(final String[] args) {
final byte[][] bargs = new byte[args.length][]; final byte[][] bargs = new byte[args.length][];
for (int i = 0; i < bargs.length; i++) { for (int i = 0; i < bargs.length; i++) {
bargs[i] = SafeEncoder.encode(args[i]); bargs[i] = SafeEncoder.encode(args[i]);
} }
brpop(bargs); brpop(bargs);
} }
public void zcount(final String key, final double min, final double max) { public void zcount(final String key, final double min, final double max) {
zcount(SafeEncoder.encode(key), min, max); zcount(SafeEncoder.encode(key), min, max);
} }
public void zrangeByScore(final String key, final double min, public void zrangeByScore(final String key, final double min,
final double max) { final double max) {
zrangeByScore(SafeEncoder.encode(key), min, max); zrangeByScore(SafeEncoder.encode(key), min, max);
} }
public void zrangeByScore(final String key, final String min, public void zrangeByScore(final String key, final String min,
final String max) { final String max) {
zrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(min), zrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(min),
SafeEncoder.encode(max)); SafeEncoder.encode(max));
} }
public void zrangeByScore(final String key, final double min, public void zrangeByScore(final String key, final double min,
final double max, final int offset, int count) { final double max, final int offset, int count) {
zrangeByScore(SafeEncoder.encode(key), min, max, offset, count); zrangeByScore(SafeEncoder.encode(key), min, max, offset, count);
} }
public void zrangeByScoreWithScores(final String key, final double min, public void zrangeByScoreWithScores(final String key, final double min,
final double max) { final double max) {
zrangeByScoreWithScores(SafeEncoder.encode(key), min, max); zrangeByScoreWithScores(SafeEncoder.encode(key), min, max);
} }
public void zrangeByScoreWithScores(final String key, final double min, public void zrangeByScoreWithScores(final String key, final double min,
final double max, final int offset, final int count) { final double max, final int offset, final int count) {
zrangeByScoreWithScores(SafeEncoder.encode(key), min, max, offset, zrangeByScoreWithScores(SafeEncoder.encode(key), min, max, offset,
count); count);
} }
public void zrevrangeByScore(final String key, final double max, public void zrevrangeByScore(final String key, final double max,
final double min) { final double min) {
zrevrangeByScore(SafeEncoder.encode(key), max, min); zrevrangeByScore(SafeEncoder.encode(key), max, min);
} }
public void zrevrangeByScore(final String key, final String max, public void zrevrangeByScore(final String key, final String max,
final String min) { final String min) {
zrevrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(max), zrevrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(max),
SafeEncoder.encode(min)); SafeEncoder.encode(min));
} }
public void zrevrangeByScore(final String key, final double max, public void zrevrangeByScore(final String key, final double max,
final double min, final int offset, int count) { final double min, final int offset, int count) {
zrevrangeByScore(SafeEncoder.encode(key), max, min, offset, count); zrevrangeByScore(SafeEncoder.encode(key), max, min, offset, count);
} }
public void zrevrangeByScoreWithScores(final String key, final double max, public void zrevrangeByScoreWithScores(final String key, final double max,
final double min) { final double min) {
zrevrangeByScoreWithScores(SafeEncoder.encode(key), max, min); zrevrangeByScoreWithScores(SafeEncoder.encode(key), max, min);
} }
public void zrevrangeByScoreWithScores(final String key, final double max, public void zrevrangeByScoreWithScores(final String key, final double max,
final double min, final int offset, final int count) { final double min, final int offset, final int count) {
zrevrangeByScoreWithScores(SafeEncoder.encode(key), max, min, offset, zrevrangeByScoreWithScores(SafeEncoder.encode(key), max, min, offset,
count); count);
} }
public void zremrangeByRank(final String key, final int start, final int end) { public void zremrangeByRank(final String key, final int start, final int end) {
zremrangeByRank(SafeEncoder.encode(key), start, end); zremrangeByRank(SafeEncoder.encode(key), start, end);
} }
public void zremrangeByScore(final String key, final double start, public void zremrangeByScore(final String key, final double start,
final double end) { final double end) {
zremrangeByScore(SafeEncoder.encode(key), start, end); zremrangeByScore(SafeEncoder.encode(key), start, end);
} }
public void zunionstore(final String dstkey, final String... sets) { public void zunionstore(final String dstkey, final String... sets) {
final byte[][] bsets = new byte[sets.length][]; final byte[][] bsets = new byte[sets.length][];
for (int i = 0; i < bsets.length; i++) { for (int i = 0; i < bsets.length; i++) {
bsets[i] = SafeEncoder.encode(sets[i]); bsets[i] = SafeEncoder.encode(sets[i]);
} }
zunionstore(SafeEncoder.encode(dstkey), bsets); zunionstore(SafeEncoder.encode(dstkey), bsets);
} }
public void zunionstore(final String dstkey, final ZParams params, public void zunionstore(final String dstkey, final ZParams params,
final String... sets) { final String... sets) {
final byte[][] bsets = new byte[sets.length][]; final byte[][] bsets = new byte[sets.length][];
for (int i = 0; i < bsets.length; i++) { for (int i = 0; i < bsets.length; i++) {
bsets[i] = SafeEncoder.encode(sets[i]); bsets[i] = SafeEncoder.encode(sets[i]);
} }
zunionstore(SafeEncoder.encode(dstkey), params, bsets); zunionstore(SafeEncoder.encode(dstkey), params, bsets);
} }
public void zinterstore(final String dstkey, final String... sets) { public void zinterstore(final String dstkey, final String... sets) {
final byte[][] bsets = new byte[sets.length][]; final byte[][] bsets = new byte[sets.length][];
for (int i = 0; i < bsets.length; i++) { for (int i = 0; i < bsets.length; i++) {
bsets[i] = SafeEncoder.encode(sets[i]); bsets[i] = SafeEncoder.encode(sets[i]);
} }
zinterstore(SafeEncoder.encode(dstkey), bsets); zinterstore(SafeEncoder.encode(dstkey), bsets);
} }
public void zinterstore(final String dstkey, final ZParams params, public void zinterstore(final String dstkey, final ZParams params,
final String... sets) { final String... sets) {
final byte[][] bsets = new byte[sets.length][]; final byte[][] bsets = new byte[sets.length][];
for (int i = 0; i < bsets.length; i++) { for (int i = 0; i < bsets.length; i++) {
bsets[i] = SafeEncoder.encode(sets[i]); bsets[i] = SafeEncoder.encode(sets[i]);
} }
zinterstore(SafeEncoder.encode(dstkey), params, bsets); zinterstore(SafeEncoder.encode(dstkey), params, bsets);
} }
public void strlen(final String key) { public void strlen(final String key) {
strlen(SafeEncoder.encode(key)); strlen(SafeEncoder.encode(key));
} }
public void lpushx(final String key, final String string) { public void lpushx(final String key, final String string) {
lpushx(SafeEncoder.encode(key), SafeEncoder.encode(string)); lpushx(SafeEncoder.encode(key), SafeEncoder.encode(string));
} }
public void persist(final String key) { public void persist(final String key) {
persist(SafeEncoder.encode(key)); persist(SafeEncoder.encode(key));
} }
public void rpushx(final String key, final String string) { public void rpushx(final String key, final String string) {
rpushx(SafeEncoder.encode(key), SafeEncoder.encode(string)); rpushx(SafeEncoder.encode(key), SafeEncoder.encode(string));
} }
public void echo(final String string) { public void echo(final String string) {
echo(SafeEncoder.encode(string)); echo(SafeEncoder.encode(string));
} }
public void linsert(final String key, final LIST_POSITION where, public void linsert(final String key, final LIST_POSITION where,
final String pivot, final String value) { final String pivot, final String value) {
linsert(SafeEncoder.encode(key), where, SafeEncoder.encode(pivot), linsert(SafeEncoder.encode(key), where, SafeEncoder.encode(pivot),
SafeEncoder.encode(value)); SafeEncoder.encode(value));
} }
public void brpoplpush(String source, String destination, int timeout) { public void brpoplpush(String source, String destination, int timeout) {
brpoplpush(SafeEncoder.encode(source), SafeEncoder.encode(destination), brpoplpush(SafeEncoder.encode(source), SafeEncoder.encode(destination),
timeout); timeout);
} }
public void setbit(final String key, final long offset, final boolean value) { 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, toByteArray(value ? 1 : 0));
} }
public void getbit(String key, long offset) { public void getbit(String key, long offset) {
getbit(SafeEncoder.encode(key), offset); getbit(SafeEncoder.encode(key), offset);
} }
public void setrange(String key, long offset, String value) { public void setrange(String key, long offset, String value) {
setrange(SafeEncoder.encode(key), offset, SafeEncoder.encode(value)); setrange(SafeEncoder.encode(key), offset, SafeEncoder.encode(value));
} }
public void getrange(String key, long startOffset, long endOffset) { public void getrange(String key, long startOffset, long endOffset) {
getrange(SafeEncoder.encode(key), startOffset, endOffset); getrange(SafeEncoder.encode(key), startOffset, endOffset);
} }
public void publish(final String channel, final String message) { public void publish(final String channel, final String message) {
publish(SafeEncoder.encode(channel), SafeEncoder.encode(message)); publish(SafeEncoder.encode(channel), SafeEncoder.encode(message));
} }
public void unsubscribe(final String... channels) { public void unsubscribe(final String... channels) {
final byte[][] cs = new byte[channels.length][]; final byte[][] cs = new byte[channels.length][];
for (int i = 0; i < cs.length; i++) { for (int i = 0; i < cs.length; i++) {
cs[i] = SafeEncoder.encode(channels[i]); cs[i] = SafeEncoder.encode(channels[i]);
} }
unsubscribe(cs); unsubscribe(cs);
} }
public void psubscribe(final String... patterns) { public void psubscribe(final String... patterns) {
final byte[][] ps = new byte[patterns.length][]; final byte[][] ps = new byte[patterns.length][];
for (int i = 0; i < ps.length; i++) { for (int i = 0; i < ps.length; i++) {
ps[i] = SafeEncoder.encode(patterns[i]); ps[i] = SafeEncoder.encode(patterns[i]);
} }
psubscribe(ps); psubscribe(ps);
} }
public void punsubscribe(final String... patterns) { public void punsubscribe(final String... patterns) {
final byte[][] ps = new byte[patterns.length][]; final byte[][] ps = new byte[patterns.length][];
for (int i = 0; i < ps.length; i++) { for (int i = 0; i < ps.length; i++) {
ps[i] = SafeEncoder.encode(patterns[i]); ps[i] = SafeEncoder.encode(patterns[i]);
} }
punsubscribe(ps); punsubscribe(ps);
} }
public void subscribe(final String... channels) { public void subscribe(final String... channels) {
final byte[][] cs = new byte[channels.length][]; final byte[][] cs = new byte[channels.length][];
for (int i = 0; i < cs.length; i++) { for (int i = 0; i < cs.length; i++) {
cs[i] = SafeEncoder.encode(channels[i]); cs[i] = SafeEncoder.encode(channels[i]);
} }
subscribe(cs); subscribe(cs);
} }
public void configSet(String parameter, String value) { public void configSet(String parameter, String value) {
configSet(SafeEncoder.encode(parameter), SafeEncoder.encode(value)); configSet(SafeEncoder.encode(parameter), SafeEncoder.encode(value));
} }
public void configGet(String pattern) { public void configGet(String pattern) {
configGet(SafeEncoder.encode(pattern)); configGet(SafeEncoder.encode(pattern));
} }
private byte[][] getByteParams(String... params){ private byte[][] getByteParams(String... params) {
byte[][] p = new byte[params.length][]; byte[][] p = new byte[params.length][];
for(int i=0;i<params.length;i++) for (int i = 0; i < params.length; i++)
p[i] = SafeEncoder.encode(params[i]); p[i] = SafeEncoder.encode(params[i]);
return p; return p;
} }
public void eval(String script, int keyCount, String... params) { public void eval(String script, int keyCount, String... params) {
eval(SafeEncoder.encode(script),toByteArray(keyCount), getByteParams(params)); eval(SafeEncoder.encode(script), toByteArray(keyCount),
getByteParams(params));
}
public void evalsha(String sha1, int keyCount, String... params) {
evalsha(SafeEncoder.encode(sha1), toByteArray(keyCount),
getByteParams(params));
}
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));
}
public void zadd(String key, Map<Double, String> scoreMembers) {
HashMap<Double, byte[]> binaryScoreMembers = new HashMap<Double, byte[]>();
for (Map.Entry<Double, String> entry : scoreMembers.entrySet()) {
binaryScoreMembers.put(entry.getKey(),
SafeEncoder.encode(entry.getValue()));
} }
public void evalsha(String sha1, int keyCount, String... params) { zaddBinary(SafeEncoder.encode(key), binaryScoreMembers);
evalsha(SafeEncoder.encode(sha1),toByteArray(keyCount), getByteParams(params));
}
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));
} }
} }

View File

@@ -76,7 +76,7 @@ public interface Commands {
public void hexists(final String key, final String field); 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); public void hlen(final String key);
@@ -86,9 +86,9 @@ public interface Commands {
public void hgetAll(final String key); 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); public void llen(final String key);
@@ -108,16 +108,16 @@ public interface Commands {
public void rpoplpush(final String srckey, final String dstkey); 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 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); public void spop(final String key);
public void smove(final String srckey, final String dstkey, public void smove(final String srckey, final String dstkey,
final String member); final String member);
public void scard(final String key); public void scard(final String key);
@@ -139,12 +139,14 @@ public interface Commands {
public void zadd(final String key, final double score, final String member); public void zadd(final String key, final double score, final String member);
public void zadd(final String key, final Map<Double, String> scoreMembers);
public void zrange(final String key, final int start, final int end); 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, public void zincrby(final String key, final double score,
final String member); final String member);
public void zrank(final String key, final String member); public void zrank(final String key, final String member);
@@ -153,10 +155,10 @@ public interface Commands {
public void zrevrange(final String key, final int start, final int end); public void zrevrange(final String key, final int start, final int end);
public void zrangeWithScores(final String key, final int start, public void zrangeWithScores(final String key, final int start,
final int end); final int end);
public void zrevrangeWithScores(final String key, final int start, public void zrevrangeWithScores(final String key, final int start,
final int end); final int end);
public void zcard(final String key); public void zcard(final String key);
@@ -171,61 +173,61 @@ public interface Commands {
public void blpop(final String[] args); public void blpop(final String[] args);
public void sort(final String key, final SortingParams sortingParameters, public void sort(final String key, final SortingParams sortingParameters,
final String dstkey); final String dstkey);
public void sort(final String key, final String dstkey); public void sort(final String key, final String dstkey);
public void brpop(final String[] args); public void brpop(final String[] args);
public void brpoplpush(final String source, final String destination, public void brpoplpush(final String source, final String destination,
final int timeout); final int timeout);
public void zcount(final String key, final double min, final double max); public void zcount(final String key, final double min, final double max);
public void zrangeByScore(final String key, final double min, public void zrangeByScore(final String key, final double min,
final double max); final double max);
public void zrangeByScore(final String key, final String min, public void zrangeByScore(final String key, final String min,
final String max); final String max);
public void zrangeByScore(final String key, final double min, public void zrangeByScore(final String key, final double min,
final double max, final int offset, int count); final double max, final int offset, int count);
public void zrangeByScoreWithScores(final String key, final double min, public void zrangeByScoreWithScores(final String key, final double min,
final double max); final double max);
public void zrangeByScoreWithScores(final String key, final double min, public void zrangeByScoreWithScores(final String key, final double min,
final double max, final int offset, final int count); final double max, final int offset, final int count);
public void zrevrangeByScore(final String key, final double max, public void zrevrangeByScore(final String key, final double max,
final double min); final double min);
public void zrevrangeByScore(final String key, final String max, public void zrevrangeByScore(final String key, final String max,
final String min); final String min);
public void zrevrangeByScore(final String key, final double max, public void zrevrangeByScore(final String key, final double max,
final double min, final int offset, int count); final double min, final int offset, int count);
public void zrevrangeByScoreWithScores(final String key, final double max, public void zrevrangeByScoreWithScores(final String key, final double max,
final double min); final double min);
public void zrevrangeByScoreWithScores(final String key, final double max, public void zrevrangeByScoreWithScores(final String key, final double max,
final double min, final int offset, final int count); 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 int start, final int end);
public void zremrangeByScore(final String key, final double start, public void zremrangeByScore(final String key, final double start,
final double end); final double end);
public void zunionstore(final String dstkey, final String... sets); public void zunionstore(final String dstkey, final String... sets);
public void zunionstore(final String dstkey, final ZParams params, public void zunionstore(final String dstkey, final ZParams params,
final String... sets); final String... sets);
public void zinterstore(final String dstkey, final String... sets); public void zinterstore(final String dstkey, final String... sets);
public void zinterstore(final String dstkey, final ZParams params, public void zinterstore(final String dstkey, final ZParams params,
final String... sets); final String... sets);
public void strlen(final String key); public void strlen(final String key);
@@ -238,7 +240,7 @@ public interface Commands {
public void echo(final String string); public void echo(final String string);
public void linsert(final String key, final LIST_POSITION where, public void linsert(final String key, final LIST_POSITION where,
final String pivot, final String value); final String pivot, final String value);
public void bgrewriteaof(); public void bgrewriteaof();

View File

@@ -781,13 +781,13 @@ public class Jedis extends BinaryJedis implements JedisCommands {
* <b>Time complexity:</b> O(1) * <b>Time complexity:</b> O(1)
* *
* @param key * @param key
* @param field * @param fields
* @return If the field was present in the hash it is deleted and 1 is * @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. * 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(); checkIsInMulti();
client.hdel(key, field); client.hdel(key, fields);
return client.getIntegerReply(); return client.getIntegerReply();
} }
@@ -863,13 +863,13 @@ public class Jedis extends BinaryJedis implements JedisCommands {
* @see Jedis#lpush(String, String) * @see Jedis#lpush(String, String)
* *
* @param key * @param key
* @param string * @param strings
* @return Integer reply, specifically, the number of elements inside the * @return Integer reply, specifically, the number of elements inside the
* list after the push operation. * list after the push operation.
*/ */
public Long rpush(final String key, final String... string) { public Long rpush(final String key, final String... strings) {
checkIsInMulti(); checkIsInMulti();
client.rpush(key, string); client.rpush(key, strings);
return client.getIntegerReply(); return client.getIntegerReply();
} }
@@ -884,13 +884,13 @@ public class Jedis extends BinaryJedis implements JedisCommands {
* @see Jedis#rpush(String, String) * @see Jedis#rpush(String, String)
* *
* @param key * @param key
* @param string * @param strings
* @return Integer reply, specifically, the number of elements inside the * @return Integer reply, specifically, the number of elements inside the
* list after the push operation. * list after the push operation.
*/ */
public Long lpush(final String key, final String... string) { public Long lpush(final String key, final String... strings) {
checkIsInMulti(); checkIsInMulti();
client.lpush(key, string); client.lpush(key, strings);
return client.getIntegerReply(); return client.getIntegerReply();
} }
@@ -1142,13 +1142,13 @@ public class Jedis extends BinaryJedis implements JedisCommands {
* Time complexity O(1) * Time complexity O(1)
* *
* @param key * @param key
* @param member * @param members
* @return Integer reply, specifically: 1 if the new element was added 0 if * @return Integer reply, specifically: 1 if the new element was added 0 if
* the element was already a member of the set * 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(); checkIsInMulti();
client.sadd(key, member); client.sadd(key, members);
return client.getIntegerReply(); return client.getIntegerReply();
} }
@@ -1176,13 +1176,13 @@ public class Jedis extends BinaryJedis implements JedisCommands {
* Time complexity O(1) * Time complexity O(1)
* *
* @param key * @param key
* @param member * @param members
* @return Integer reply, specifically: 1 if the new element was removed 0 * @return Integer reply, specifically: 1 if the new element was removed 0
* if the new element was not a member of the set * 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(); checkIsInMulti();
client.srem(key, member); client.srem(key, members);
return client.getIntegerReply(); return client.getIntegerReply();
} }
@@ -1439,6 +1439,12 @@ public class Jedis extends BinaryJedis implements JedisCommands {
return client.getIntegerReply(); return client.getIntegerReply();
} }
public Long zadd(final String key, final Map<Double, String> scoreMembers) {
checkIsInMulti();
client.zadd(key, scoreMembers);
return client.getIntegerReply();
}
public Set<String> zrange(final String key, final int start, final int end) { public Set<String> zrange(final String key, final int start, final int end) {
checkIsInMulti(); checkIsInMulti();
client.zrange(key, start, end); client.zrange(key, start, end);
@@ -1457,13 +1463,13 @@ public class Jedis extends BinaryJedis implements JedisCommands {
* *
* *
* @param key * @param key
* @param member * @param members
* @return Integer reply, specifically: 1 if the new element was removed 0 * @return Integer reply, specifically: 1 if the new element was removed 0
* if the new element was not a member of the set * 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(); checkIsInMulti();
client.zrem(key, member); client.zrem(key, members);
return client.getIntegerReply(); return client.getIntegerReply();
} }

View File

@@ -62,7 +62,7 @@ public interface JedisCommands {
Boolean hexists(String key, String field); Boolean hexists(String key, String field);
Long hdel(String key, String field); Long hdel(String key, String... field);
Long hlen(String key); Long hlen(String key);
@@ -92,11 +92,11 @@ public interface JedisCommands {
String rpop(String key); String rpop(String key);
Long sadd(String key, String member); Long sadd(String key, String... member);
Set<String> smembers(String key); Set<String> smembers(String key);
Long srem(String key, String member); Long srem(String key, String... member);
String spop(String key); String spop(String key);
@@ -107,10 +107,12 @@ public interface JedisCommands {
String srandmember(String key); String srandmember(String key);
Long zadd(String key, double score, String member); Long zadd(String key, double score, String member);
Long zadd(String key, Map<Double, String> scoreMembers);
Set<String> zrange(String key, int start, int end); Set<String> 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); Double zincrby(String key, double score, String member);

View File

@@ -672,14 +672,14 @@ public class Pipeline extends Queable {
return getResponse(BuilderFactory.LONG); return getResponse(BuilderFactory.LONG);
} }
public Response<List<String>> sort(String key) { public Response<Long> sort(String key) {
client.sort(key); client.sort(key);
return getResponse(BuilderFactory.STRING_LIST); return getResponse(BuilderFactory.LONG);
} }
public Response<List<String>> sort(byte[] key) { public Response<Long> sort(byte[] key) {
client.sort(key); client.sort(key);
return getResponse(BuilderFactory.STRING_LIST); return getResponse(BuilderFactory.LONG);
} }
public Response<List<String>> sort(String key, public Response<List<String>> sort(String key,

View File

@@ -1,416 +1,421 @@
package redis.clients.jedis; package redis.clients.jedis;
import redis.clients.jedis.BinaryClient.LIST_POSITION;
import redis.clients.util.Hashing;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern; 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 class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
public ShardedJedis(List<JedisShardInfo> shards) { public ShardedJedis(List<JedisShardInfo> shards) {
super(shards); super(shards);
} }
public ShardedJedis(List<JedisShardInfo> shards, Hashing algo) { public ShardedJedis(List<JedisShardInfo> shards, Hashing algo) {
super(shards, algo); super(shards, algo);
} }
public ShardedJedis(List<JedisShardInfo> shards, Pattern keyTagPattern) { public ShardedJedis(List<JedisShardInfo> shards, Pattern keyTagPattern) {
super(shards, keyTagPattern); super(shards, keyTagPattern);
} }
public ShardedJedis(List<JedisShardInfo> shards, Hashing algo, public ShardedJedis(List<JedisShardInfo> shards, Hashing algo,
Pattern keyTagPattern) { Pattern keyTagPattern) {
super(shards, algo, keyTagPattern); super(shards, algo, keyTagPattern);
} }
public void disconnect() { public void disconnect() {
for (Jedis jedis : getAllShards()) { for (Jedis jedis : getAllShards()) {
jedis.quit(); jedis.quit();
jedis.disconnect(); jedis.disconnect();
} }
} }
public String set(String key, String value) { public String set(String key, String value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.set(key, value); return j.set(key, value);
} }
public String get(String key) { public String get(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.get(key); return j.get(key);
} }
public Boolean exists(String key) { public Boolean exists(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.exists(key); return j.exists(key);
} }
public String type(String key) { public String type(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.type(key); return j.type(key);
} }
public Long expire(String key, int seconds) { public Long expire(String key, int seconds) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.expire(key, seconds); return j.expire(key, seconds);
} }
public Long expireAt(String key, long unixTime) { public Long expireAt(String key, long unixTime) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.expireAt(key, unixTime); return j.expireAt(key, unixTime);
} }
public Long ttl(String key) { public Long ttl(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.ttl(key); 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); Jedis j = getShard(key);
return j.setbit(key, offset, value); return j.setbit(key, offset, value);
} }
public Boolean getbit(String key, long offset) { public Boolean getbit(String key, long offset) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.getbit(key, offset); 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); Jedis j = getShard(key);
return j.setrange(key, offset, value); return j.setrange(key, offset, value);
} }
public String getrange(String key, long startOffset, long endOffset) { public String getrange(String key, long startOffset, long endOffset) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.getrange(key, startOffset, endOffset); return j.getrange(key, startOffset, endOffset);
} }
public String getSet(String key, String value) { public String getSet(String key, String value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.getSet(key, value); return j.getSet(key, value);
} }
public Long setnx(String key, String value) { public Long setnx(String key, String value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.setnx(key, value); return j.setnx(key, value);
} }
public String setex(String key, int seconds, String value) { public String setex(String key, int seconds, String value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.setex(key, seconds, value); return j.setex(key, seconds, value);
} }
public Long decrBy(String key, long integer) { public Long decrBy(String key, long integer) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.decrBy(key, integer); return j.decrBy(key, integer);
} }
public Long decr(String key) { public Long decr(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.decr(key); return j.decr(key);
} }
public Long incrBy(String key, long integer) { public Long incrBy(String key, long integer) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.incrBy(key, integer); return j.incrBy(key, integer);
} }
public Long incr(String key) { public Long incr(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.incr(key); return j.incr(key);
} }
public Long append(String key, String value) { public Long append(String key, String value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.append(key, value); return j.append(key, value);
} }
public String substr(String key, int start, int end) { public String substr(String key, int start, int end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.substr(key, start, end); return j.substr(key, start, end);
} }
public Long hset(String key, String field, String value) { public Long hset(String key, String field, String value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hset(key, field, value); return j.hset(key, field, value);
} }
public String hget(String key, String field) { public String hget(String key, String field) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hget(key, field); return j.hget(key, field);
} }
public Long hsetnx(String key, String field, String value) { public Long hsetnx(String key, String field, String value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hsetnx(key, field, value); return j.hsetnx(key, field, value);
} }
public String hmset(String key, Map<String, String> hash) { public String hmset(String key, Map<String, String> hash) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hmset(key, hash); return j.hmset(key, hash);
} }
public List<String> hmget(String key, String... fields) { public List<String> hmget(String key, String... fields) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hmget(key, fields); return j.hmget(key, fields);
} }
public Long hincrBy(String key, String field, long value) { public Long hincrBy(String key, String field, long value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hincrBy(key, field, value); return j.hincrBy(key, field, value);
} }
public Boolean hexists(String key, String field) { public Boolean hexists(String key, String field) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hexists(key, field); return j.hexists(key, field);
} }
public Long del(String key) { public Long del(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.del(key); return j.del(key);
} }
public Long hdel(String key, String field) { public Long hdel(String key, String... fields) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hdel(key, field); return j.hdel(key, fields);
} }
public Long hlen(String key) { public Long hlen(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hlen(key); return j.hlen(key);
} }
public Set<String> hkeys(String key) { public Set<String> hkeys(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hkeys(key); return j.hkeys(key);
} }
public List<String> hvals(String key) { public List<String> hvals(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hvals(key); return j.hvals(key);
} }
public Map<String, String> hgetAll(String key) { public Map<String, String> hgetAll(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.hgetAll(key); return j.hgetAll(key);
} }
public Long rpush(String key, String... string) { public Long rpush(String key, String... strings) {
Jedis j = getShard(key); 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); Jedis j = getShard(key);
return j.lpush(key, string); return j.lpush(key, strings);
} }
public Long llen(String key) { public Long llen(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.llen(key); return j.llen(key);
} }
public List<String> lrange(String key, long start, long end) { public List<String> lrange(String key, long start, long end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.lrange(key, start, end); return j.lrange(key, start, end);
} }
public String ltrim(String key, long start, long end) { public String ltrim(String key, long start, long end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.ltrim(key, start, end); return j.ltrim(key, start, end);
} }
public String lindex(String key, long index) { public String lindex(String key, long index) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.lindex(key, index); return j.lindex(key, index);
} }
public String lset(String key, long index, String value) { public String lset(String key, long index, String value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.lset(key, index, value); return j.lset(key, index, value);
} }
public Long lrem(String key, long count, String value) { public Long lrem(String key, long count, String value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.lrem(key, count, value); return j.lrem(key, count, value);
} }
public String lpop(String key) { public String lpop(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.lpop(key); return j.lpop(key);
} }
public String rpop(String key) { public String rpop(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.rpop(key); return j.rpop(key);
} }
public Long sadd(String key, String member) { public Long sadd(String key, String... members) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.sadd(key, member); return j.sadd(key, members);
} }
public Set<String> smembers(String key) { public Set<String> smembers(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.smembers(key); return j.smembers(key);
} }
public Long srem(String key, String member) { public Long srem(String key, String... members) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.srem(key, member); return j.srem(key, members);
} }
public String spop(String key) { public String spop(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.spop(key); return j.spop(key);
} }
public Long scard(String key) { public Long scard(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.scard(key); return j.scard(key);
} }
public Boolean sismember(String key, String member) { public Boolean sismember(String key, String member) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.sismember(key, member); return j.sismember(key, member);
} }
public String srandmember(String key) { public String srandmember(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.srandmember(key); return j.srandmember(key);
} }
public Long zadd(String key, double score, String member) { public Long zadd(String key, double score, String member) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zadd(key, score, member); return j.zadd(key, score, member);
}
public Long zadd(String key, Map<Double, String> scoreMembers) {
Jedis j = getShard(key);
return j.zadd(key, scoreMembers);
} }
public Set<String> zrange(String key, int start, int end) { public Set<String> zrange(String key, int start, int end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrange(key, start, end); return j.zrange(key, start, end);
} }
public Long zrem(String key, String member) { public Long zrem(String key, String... members) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrem(key, member); return j.zrem(key, members);
} }
public Double zincrby(String key, double score, String member) { public Double zincrby(String key, double score, String member) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zincrby(key, score, member); return j.zincrby(key, score, member);
} }
public Long zrank(String key, String member) { public Long zrank(String key, String member) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrank(key, member); return j.zrank(key, member);
} }
public Long zrevrank(String key, String member) { public Long zrevrank(String key, String member) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrevrank(key, member); return j.zrevrank(key, member);
} }
public Set<String> zrevrange(String key, int start, int end) { public Set<String> zrevrange(String key, int start, int end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrevrange(key, start, end); return j.zrevrange(key, start, end);
} }
public Set<Tuple> zrangeWithScores(String key, int start, int end) { public Set<Tuple> zrangeWithScores(String key, int start, int end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrangeWithScores(key, start, end); return j.zrangeWithScores(key, start, end);
} }
public Set<Tuple> zrevrangeWithScores(String key, int start, int end) { public Set<Tuple> zrevrangeWithScores(String key, int start, int end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrevrangeWithScores(key, start, end); return j.zrevrangeWithScores(key, start, end);
} }
public Long zcard(String key) { public Long zcard(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zcard(key); return j.zcard(key);
} }
public Double zscore(String key, String member) { public Double zscore(String key, String member) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zscore(key, member); return j.zscore(key, member);
} }
public List<String> sort(String key) { public List<String> sort(String key) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.sort(key); return j.sort(key);
} }
public List<String> sort(String key, SortingParams sortingParameters) { public List<String> sort(String key, SortingParams sortingParameters) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.sort(key, sortingParameters); return j.sort(key, sortingParameters);
} }
public Long zcount(String key, double min, double max) { public Long zcount(String key, double min, double max) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zcount(key, min, max); return j.zcount(key, min, max);
} }
public Set<String> zrangeByScore(String key, double min, double max) { public Set<String> zrangeByScore(String key, double min, double max) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrangeByScore(key, min, max); return j.zrangeByScore(key, min, max);
} }
public Set<String> zrevrangeByScore(String key, double max, double min) { public Set<String> zrevrangeByScore(String key, double max, double min) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrevrangeByScore(key, max, min); return j.zrevrangeByScore(key, max, min);
} }
public Set<String> zrangeByScore(String key, double min, double max, public Set<String> zrangeByScore(String key, double min, double max,
int offset, int count) { int offset, int count) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrangeByScore(key, min, max, offset, count); return j.zrangeByScore(key, min, max, offset, count);
} }
public Set<String> zrevrangeByScore(String key, double max, double min, public Set<String> zrevrangeByScore(String key, double max, double min,
int offset, int count) { int offset, int count) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrevrangeByScore(key, max, min, offset, count); return j.zrevrangeByScore(key, max, min, offset, count);
} }
public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max) { public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrangeByScoreWithScores(key, min, max); return j.zrangeByScoreWithScores(key, min, max);
} }
public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, public Set<Tuple> zrevrangeByScoreWithScores(String key, double max,
double min) { double min) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrevrangeByScoreWithScores(key, max, min); return j.zrevrangeByScoreWithScores(key, max, min);
} }
public Set<Tuple> zrangeByScoreWithScores(String key, double min, public Set<Tuple> zrangeByScoreWithScores(String key, double min,
double max, int offset, int count) { double max, int offset, int count) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrangeByScoreWithScores(key, min, max, offset, count); return j.zrangeByScoreWithScores(key, min, max, offset, count);
} }
public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, public Set<Tuple> zrevrangeByScoreWithScores(String key, double max,
double min, int offset, int count) { double min, int offset, int count) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zrevrangeByScoreWithScores(key, max, min, offset, count); return j.zrevrangeByScoreWithScores(key, max, min, offset, count);
} }
public Long zremrangeByRank(String key, int start, int end) { public Long zremrangeByRank(String key, int start, int end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zremrangeByRank(key, start, end); return j.zremrangeByRank(key, start, end);
} }
public Long zremrangeByScore(String key, double start, double end) { public Long zremrangeByScore(String key, double start, double end) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.zremrangeByScore(key, start, end); return j.zremrangeByScore(key, start, end);
} }
public Long linsert(String key, LIST_POSITION where, String pivot, public Long linsert(String key, LIST_POSITION where, String pivot,
String value) { String value) {
Jedis j = getShard(key); Jedis j = getShard(key);
return j.linsert(key, where, pivot, value); return j.linsert(key, where, pivot, value);
} }
} }

View File

@@ -1,6 +1,8 @@
package redis.clients.util; package redis.clients.util;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import redis.clients.jedis.Protocol; import redis.clients.jedis.Protocol;
import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.exceptions.JedisDataException;
@@ -11,6 +13,14 @@ import redis.clients.jedis.exceptions.JedisException;
* *
*/ */
public class SafeEncoder { public class SafeEncoder {
public static byte[][] encodeMany(final String... strs){
byte[][] many = new byte[strs.length][];
for(int i=0;i<strs.length;i++){
many[i] = encode(strs[i]);
}
return many;
}
public static byte[] encode(final String str) { public static byte[] encode(final String str) {
try { try {
if (str == null) { if (str == null) {

View File

@@ -11,6 +11,7 @@ public class SlowlogCommandsTest extends JedisCommandTestBase {
@Test @Test
public void slowlog() { public void slowlog() {
//do something //do something
jedis.configSet("slowlog-log-slower-than", "0");
jedis.set("foo", "bar"); jedis.set("foo", "bar");
jedis.set("foo2", "bar2"); jedis.set("foo2", "bar2");

View File

@@ -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<String, String> hash = new HashMap<String, String>();
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<byte[], byte[]> bhash = new HashMap<byte[], byte[]>();
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<String> expected = new ArrayList<String>();
expected.add("bar");
expected.add("foo");
List<String> values = jedis.lrange("foo",0,-1);
assertEquals(expected, values);
// Binary
size = jedis.rpush(bfoo, bbar, bfoo);
assertEquals(2, size);
List<byte[]> bexpected = new ArrayList<byte[]>();
bexpected.add(bbar);
bexpected.add(bfoo);
List<byte[]> bvalues = jedis.lrange(bfoo, 0, -1);
assertEquals(bexpected, bvalues);
}
@Test
public void lpush() {
long size = jedis.lpush("foo", "bar", "foo");
assertEquals(2, size);
List<String> expected = new ArrayList<String>();
expected.add("foo");
expected.add("bar");
List<String> values = jedis.lrange("foo",0,-1);
assertEquals(expected, values);
// Binary
size = jedis.lpush(bfoo, bbar, bfoo);
assertEquals(2, size);
List<byte[]> bexpected = new ArrayList<byte[]>();
bexpected.add(bfoo);
bexpected.add(bbar);
List<byte[]> 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<Double, String> scoreMembers = new HashMap<Double, String>();
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<Double, byte[]> bscoreMembers = new HashMap<Double, byte[]>();
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<String> expected = new LinkedHashSet<String>();
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<byte[]> bexpected = new LinkedHashSet<byte[]>();
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);
}
}