Variadic commands

This commit is contained in:
ivowiblo
2012-04-18 15:22:43 -04:00
parent e4f7f61d00
commit 8aca0b77f9
10 changed files with 176 additions and 102 deletions

View File

@@ -9,6 +9,7 @@ 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 java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@@ -45,6 +46,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;
} }
@@ -228,8 +238,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) {
@@ -248,12 +258,12 @@ public class BinaryClient extends Connection {
sendCommand(HGETALL, key); sendCommand(HGETALL, key);
} }
public void rpush(final byte[] key, final byte[] string) { public void rpush(final byte[] key, final byte[]... strings) {
sendCommand(RPUSH, key, string); sendCommand(RPUSH, joinParameters(key, strings));
} }
public void lpush(final byte[] key, final byte[] string) { public void lpush(final byte[] key, final byte[]... strings) {
sendCommand(LPUSH, key, string); sendCommand(LPUSH, joinParameters(key, strings));
} }
public void llen(final byte[] key) { public void llen(final byte[] key) {
@@ -292,16 +302,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) {
@@ -362,12 +372,28 @@ 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,

View File

@@ -796,13 +796,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();
} }
@@ -881,16 +881,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();
} }
@@ -902,16 +902,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();
} }
@@ -1162,13 +1162,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();
} }
@@ -1200,7 +1200,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();
@@ -1459,6 +1459,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);
@@ -1477,13 +1483,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);
@@ -67,9 +67,9 @@ public interface BinaryJedisCommands {
Map<byte[], byte[]> hgetAll(byte[] key); Map<byte[], byte[]> hgetAll(byte[] key);
Long rpush(byte[] key, byte[] string); Long rpush(byte[] key, byte[]... string);
Long lpush(byte[] key, byte[] string); Long lpush(byte[] key, byte[]... string);
Long llen(byte[] key); Long llen(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);
@@ -103,9 +103,11 @@ public interface BinaryJedisCommands {
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

@@ -155,9 +155,9 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
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) {
@@ -180,14 +180,14 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
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) {
@@ -230,9 +230,9 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
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) {
@@ -240,9 +240,9 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
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) {
@@ -270,14 +270,19 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
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) {

View File

@@ -169,8 +169,8 @@ public class Client extends BinaryClient implements Commands {
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) {
@@ -189,12 +189,12 @@ public class Client extends BinaryClient implements Commands {
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... string) {
rpush(SafeEncoder.encode(key), SafeEncoder.encode(string)); rpush(SafeEncoder.encode(key), SafeEncoder.encodeMany(string));
} }
public void lpush(final String key, final String string) { public void lpush(final String key, final String... string) {
lpush(SafeEncoder.encode(key), SafeEncoder.encode(string)); lpush(SafeEncoder.encode(key), SafeEncoder.encodeMany(string));
} }
public void llen(final String key) { public void llen(final String key) {
@@ -233,16 +233,16 @@ public class Client extends BinaryClient implements Commands {
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) {
@@ -323,8 +323,8 @@ public class Client extends BinaryClient implements Commands {
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,
@@ -595,4 +595,14 @@ public class Client extends BinaryClient implements Commands {
public void configGet(String pattern) { public void configGet(String pattern) {
configGet(SafeEncoder.encode(pattern)); configGet(SafeEncoder.encode(pattern));
} }
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()));
}
zaddBinary(SafeEncoder.encode(key), binaryScoreMembers);
}
} }

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,11 +108,11 @@ 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);
@@ -139,9 +139,11 @@ public interface Commands {
public void zadd(final String key, final double score, final String member); public void zadd(final String key, final 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);

View File

@@ -779,13 +779,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();
} }
@@ -861,13 +861,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();
} }
@@ -882,13 +882,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();
} }
@@ -1139,13 +1139,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();
} }
@@ -1173,13 +1173,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();
} }
@@ -1436,6 +1436,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);
@@ -1454,13 +1460,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);
@@ -72,9 +72,9 @@ public interface JedisCommands {
Map<String, String> hgetAll(String key); Map<String, String> hgetAll(String key);
Long rpush(String key, String string); Long rpush(String key, String... string);
Long lpush(String key, String string); Long lpush(String key, String... string);
Long llen(String key); Long llen(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);
@@ -108,9 +108,11 @@ public interface JedisCommands {
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

@@ -173,9 +173,9 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
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) {
@@ -198,14 +198,14 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
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) {
@@ -248,9 +248,9 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
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) {
@@ -258,9 +258,9 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
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) {
@@ -288,14 +288,19 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
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) {

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) {