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:
@@ -2,13 +2,13 @@ package redis.clients.jedis;
|
||||
|
||||
import static redis.clients.jedis.Protocol.toByteArray;
|
||||
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.NO;
|
||||
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.WITHSCORES;
|
||||
import static redis.clients.jedis.Protocol.Keyword.RESET;
|
||||
import static redis.clients.jedis.Protocol.Keyword.LEN;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -47,6 +47,15 @@ public class BinaryClient extends Connection {
|
||||
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) {
|
||||
this.password = password;
|
||||
}
|
||||
@@ -230,8 +239,8 @@ public class BinaryClient extends Connection {
|
||||
sendCommand(HEXISTS, key, field);
|
||||
}
|
||||
|
||||
public void hdel(final byte[] key, final byte[] field) {
|
||||
sendCommand(HDEL, key, field);
|
||||
public void hdel(final byte[] key, final byte[]... fields) {
|
||||
sendCommand(HDEL, joinParameters(key, fields));
|
||||
}
|
||||
|
||||
public void hlen(final byte[] key) {
|
||||
@@ -250,18 +259,12 @@ public class BinaryClient extends Connection {
|
||||
sendCommand(HGETALL, key);
|
||||
}
|
||||
|
||||
public void rpush(final byte[] key, final byte[]... vals) {
|
||||
byte[][] args = new byte[vals.length + 1][];
|
||||
args[0] = key;
|
||||
System.arraycopy(vals, 0, args, 1, vals.length);
|
||||
sendCommand(RPUSH, args);
|
||||
public void rpush(final byte[] key, final byte[]... strings) {
|
||||
sendCommand(RPUSH, joinParameters(key, strings));
|
||||
}
|
||||
|
||||
public void lpush(final byte[] key, final byte[]... vals) {
|
||||
byte[][] args = new byte[vals.length + 1][];
|
||||
args[0] = key;
|
||||
System.arraycopy(vals, 0, args, 1, vals.length);
|
||||
sendCommand(LPUSH, args);
|
||||
public void lpush(final byte[] key, final byte[]... strings) {
|
||||
sendCommand(LPUSH, joinParameters(key, strings));
|
||||
}
|
||||
|
||||
public void llen(final byte[] key) {
|
||||
@@ -300,16 +303,16 @@ public class BinaryClient extends Connection {
|
||||
sendCommand(RPOPLPUSH, srckey, dstkey);
|
||||
}
|
||||
|
||||
public void sadd(final byte[] key, final byte[] member) {
|
||||
sendCommand(SADD, key, member);
|
||||
public void sadd(final byte[] key, final byte[]... members) {
|
||||
sendCommand(SADD, joinParameters(key, members));
|
||||
}
|
||||
|
||||
public void smembers(final byte[] key) {
|
||||
sendCommand(SMEMBERS, key);
|
||||
}
|
||||
|
||||
public void srem(final byte[] key, final byte[] member) {
|
||||
sendCommand(SREM, key, member);
|
||||
public void srem(final byte[] key, final byte[]... members) {
|
||||
sendCommand(SREM, joinParameters(key, members));
|
||||
}
|
||||
|
||||
public void spop(final byte[] key) {
|
||||
@@ -370,12 +373,29 @@ public class BinaryClient extends Connection {
|
||||
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) {
|
||||
sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end));
|
||||
}
|
||||
|
||||
public void zrem(final byte[] key, final byte[] member) {
|
||||
sendCommand(ZREM, key, member);
|
||||
public void zrem(final byte[] key, final byte[]... members) {
|
||||
sendCommand(ZREM, joinParameters(key, members));
|
||||
}
|
||||
|
||||
public void zincrby(final byte[] key, final double score,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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.HashSet;
|
||||
@@ -11,12 +11,10 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.jedis.Protocol.Keyword;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
import redis.clients.util.JedisByteHashMap;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
import static redis.clients.jedis.Protocol.toByteArray;
|
||||
|
||||
public class BinaryJedis implements BinaryJedisCommands {
|
||||
protected Client client = null;
|
||||
@@ -800,13 +798,13 @@ public class BinaryJedis implements BinaryJedisCommands {
|
||||
* <b>Time complexity:</b> O(1)
|
||||
*
|
||||
* @param key
|
||||
* @param field
|
||||
* @param fields
|
||||
* @return If the field was present in the hash it is deleted and 1 is
|
||||
* returned, otherwise 0 is returned and no operation is performed.
|
||||
*/
|
||||
public Long hdel(final byte[] key, final byte[] field) {
|
||||
public Long hdel(final byte[] key, final byte[]... fields) {
|
||||
checkIsInMulti();
|
||||
client.hdel(key, field);
|
||||
client.hdel(key, fields);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
@@ -885,16 +883,16 @@ public class BinaryJedis implements BinaryJedisCommands {
|
||||
* <p>
|
||||
* Time complexity: O(1)
|
||||
*
|
||||
* @see BinaryJedis#lpush(byte[], byte[])
|
||||
* @see BinaryJedis#rpush(byte[], byte[]...)
|
||||
*
|
||||
* @param key
|
||||
* @param string
|
||||
* @param strings
|
||||
* @return Integer reply, specifically, the number of elements inside the
|
||||
* list after the push operation.
|
||||
*/
|
||||
public Long rpush(final byte[] key, final byte[]... string) {
|
||||
public Long rpush(final byte[] key, final byte[]... strings) {
|
||||
checkIsInMulti();
|
||||
client.rpush(key, string);
|
||||
client.rpush(key, strings);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
@@ -906,16 +904,16 @@ public class BinaryJedis implements BinaryJedisCommands {
|
||||
* <p>
|
||||
* Time complexity: O(1)
|
||||
*
|
||||
* @see BinaryJedis#rpush(byte[], byte[])
|
||||
* @see BinaryJedis#rpush(byte[], byte[]...)
|
||||
*
|
||||
* @param key
|
||||
* @param string
|
||||
* @param strings
|
||||
* @return Integer reply, specifically, the number of elements inside the
|
||||
* list after the push operation.
|
||||
*/
|
||||
public Long lpush(final byte[] key, final byte[]... string) {
|
||||
public Long lpush(final byte[] key, final byte[]... strings) {
|
||||
checkIsInMulti();
|
||||
client.lpush(key, string);
|
||||
client.lpush(key, strings);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
@@ -1166,13 +1164,13 @@ public class BinaryJedis implements BinaryJedisCommands {
|
||||
* Time complexity O(1)
|
||||
*
|
||||
* @param key
|
||||
* @param member
|
||||
* @param members
|
||||
* @return Integer reply, specifically: 1 if the new element was added 0 if
|
||||
* the element was already a member of the set
|
||||
*/
|
||||
public Long sadd(final byte[] key, final byte[] member) {
|
||||
public Long sadd(final byte[] key, final byte[]... members) {
|
||||
checkIsInMulti();
|
||||
client.sadd(key, member);
|
||||
client.sadd(key, members);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
@@ -1204,7 +1202,7 @@ public class BinaryJedis implements BinaryJedisCommands {
|
||||
* @return Integer reply, specifically: 1 if the new element was removed 0
|
||||
* if the new element was not a member of the set
|
||||
*/
|
||||
public Long srem(final byte[] key, final byte[] member) {
|
||||
public Long srem(final byte[] key, final byte[]... member) {
|
||||
checkIsInMulti();
|
||||
client.srem(key, member);
|
||||
return client.getIntegerReply();
|
||||
@@ -1463,6 +1461,12 @@ public class BinaryJedis implements BinaryJedisCommands {
|
||||
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) {
|
||||
checkIsInMulti();
|
||||
client.zrange(key, start, end);
|
||||
@@ -1481,13 +1485,13 @@ public class BinaryJedis implements BinaryJedisCommands {
|
||||
*
|
||||
*
|
||||
* @param key
|
||||
* @param member
|
||||
* @param members
|
||||
* @return Integer reply, specifically: 1 if the new element was removed 0
|
||||
* if the new element was not a member of the set
|
||||
*/
|
||||
public Long zrem(final byte[] key, final byte[] member) {
|
||||
public Long zrem(final byte[] key, final byte[]... members) {
|
||||
checkIsInMulti();
|
||||
client.zrem(key, member);
|
||||
client.zrem(key, members);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public interface BinaryJedisCommands {
|
||||
|
||||
Boolean hexists(byte[] key, byte[] field);
|
||||
|
||||
Long hdel(byte[] key, byte[] field);
|
||||
Long hdel(byte[] key, byte[]... field);
|
||||
|
||||
Long hlen(byte[] key);
|
||||
|
||||
@@ -87,11 +87,11 @@ public interface BinaryJedisCommands {
|
||||
|
||||
byte[] rpop(byte[] key);
|
||||
|
||||
Long sadd(byte[] key, byte[] member);
|
||||
Long sadd(byte[] key, byte[]... member);
|
||||
|
||||
Set<byte[]> smembers(byte[] key);
|
||||
|
||||
Long srem(byte[] key, byte[] member);
|
||||
Long srem(byte[] key, byte[]... member);
|
||||
|
||||
byte[] spop(byte[] key);
|
||||
|
||||
@@ -103,9 +103,11 @@ public interface BinaryJedisCommands {
|
||||
|
||||
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);
|
||||
|
||||
Long zrem(byte[] key, byte[] member);
|
||||
Long zrem(byte[] key, byte[]... member);
|
||||
|
||||
Double zincrby(byte[] key, double score, byte[] member);
|
||||
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.util.Hashing;
|
||||
import redis.clients.util.Sharded;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.util.Hashing;
|
||||
import redis.clients.util.Sharded;
|
||||
|
||||
public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
|
||||
implements BinaryJedisCommands {
|
||||
public BinaryShardedJedis(List<JedisShardInfo> shards) {
|
||||
@@ -156,9 +155,9 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
|
||||
return j.hexists(key, field);
|
||||
}
|
||||
|
||||
public Long hdel(byte[] key, byte[] field) {
|
||||
public Long hdel(byte[] key, byte[]... fields) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hdel(key, field);
|
||||
return j.hdel(key, fields);
|
||||
}
|
||||
|
||||
public Long hlen(byte[] key) {
|
||||
@@ -181,14 +180,14 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
|
||||
return j.hgetAll(key);
|
||||
}
|
||||
|
||||
public Long rpush(byte[] key, byte[]... string) {
|
||||
public Long rpush(byte[] key, byte[]... strings) {
|
||||
Jedis j = getShard(key);
|
||||
return j.rpush(key, string);
|
||||
return j.rpush(key, strings);
|
||||
}
|
||||
|
||||
public Long lpush(byte[] key, byte[]... string) {
|
||||
public Long lpush(byte[] key, byte[]... strings) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lpush(key, string);
|
||||
return j.lpush(key, strings);
|
||||
}
|
||||
|
||||
public Long llen(byte[] key) {
|
||||
@@ -231,9 +230,9 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
|
||||
return j.rpop(key);
|
||||
}
|
||||
|
||||
public Long sadd(byte[] key, byte[] member) {
|
||||
public Long sadd(byte[] key, byte[]... members) {
|
||||
Jedis j = getShard(key);
|
||||
return j.sadd(key, member);
|
||||
return j.sadd(key, members);
|
||||
}
|
||||
|
||||
public Set<byte[]> smembers(byte[] key) {
|
||||
@@ -241,9 +240,9 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
|
||||
return j.smembers(key);
|
||||
}
|
||||
|
||||
public Long srem(byte[] key, byte[] member) {
|
||||
public Long srem(byte[] key, byte[]... members) {
|
||||
Jedis j = getShard(key);
|
||||
return j.srem(key, member);
|
||||
return j.srem(key, members);
|
||||
}
|
||||
|
||||
public byte[] spop(byte[] key) {
|
||||
@@ -271,14 +270,19 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
|
||||
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) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrange(key, start, end);
|
||||
}
|
||||
|
||||
public Long zrem(byte[] key, byte[] member) {
|
||||
public Long zrem(byte[] key, byte[]... members) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrem(key, member);
|
||||
return j.zrem(key, members);
|
||||
}
|
||||
|
||||
public Double zincrby(byte[] key, double score, byte[] member) {
|
||||
@@ -369,7 +373,8 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
|
||||
return j.zrevrangeByScore(key, max, min, offset, count);
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min) {
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max,
|
||||
double min) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrevrangeByScoreWithScores(key, max, min);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import redis.clients.jedis.Protocol.Keyword;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
import static redis.clients.jedis.Protocol.toByteArray;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static redis.clients.jedis.Protocol.toByteArray;
|
||||
import static redis.clients.jedis.Protocol.Command.SCRIPT;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
public class Client extends BinaryClient implements Commands {
|
||||
public Client(final String host) {
|
||||
@@ -134,8 +130,8 @@ public class Client extends BinaryClient implements Commands {
|
||||
}
|
||||
|
||||
public void hset(final String key, final String field, final String value) {
|
||||
hset(SafeEncoder.encode(key), SafeEncoder.encode(field), SafeEncoder
|
||||
.encode(value));
|
||||
hset(SafeEncoder.encode(key), SafeEncoder.encode(field),
|
||||
SafeEncoder.encode(value));
|
||||
}
|
||||
|
||||
public void hget(final String key, final String field) {
|
||||
@@ -143,16 +139,16 @@ public class Client extends BinaryClient implements Commands {
|
||||
}
|
||||
|
||||
public void hsetnx(final String key, final String field, final String value) {
|
||||
hsetnx(SafeEncoder.encode(key), SafeEncoder.encode(field), SafeEncoder
|
||||
.encode(value));
|
||||
hsetnx(SafeEncoder.encode(key), SafeEncoder.encode(field),
|
||||
SafeEncoder.encode(value));
|
||||
}
|
||||
|
||||
public void hmset(final String key, final Map<String, String> hash) {
|
||||
final Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>(hash
|
||||
.size());
|
||||
final Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>(
|
||||
hash.size());
|
||||
for (final Entry<String, String> entry : hash.entrySet()) {
|
||||
bhash.put(SafeEncoder.encode(entry.getKey()), SafeEncoder
|
||||
.encode(entry.getValue()));
|
||||
bhash.put(SafeEncoder.encode(entry.getKey()),
|
||||
SafeEncoder.encode(entry.getValue()));
|
||||
}
|
||||
hmset(SafeEncoder.encode(key), bhash);
|
||||
}
|
||||
@@ -173,8 +169,8 @@ public class Client extends BinaryClient implements Commands {
|
||||
hexists(SafeEncoder.encode(key), SafeEncoder.encode(field));
|
||||
}
|
||||
|
||||
public void hdel(final String key, final String field) {
|
||||
hdel(SafeEncoder.encode(key), SafeEncoder.encode(field));
|
||||
public void hdel(final String key, final String... fields) {
|
||||
hdel(SafeEncoder.encode(key), SafeEncoder.encodeMany(fields));
|
||||
}
|
||||
|
||||
public void hlen(final String key) {
|
||||
@@ -193,22 +189,12 @@ public class Client extends BinaryClient implements Commands {
|
||||
hgetAll(SafeEncoder.encode(key));
|
||||
}
|
||||
|
||||
|
||||
public void rpush(final String key, final String... vals) {
|
||||
final byte[][] bvals = new byte[vals.length][];
|
||||
for (int i = 0; i < bvals.length; i++) {
|
||||
bvals[i] = SafeEncoder.encode(vals[i]);
|
||||
}
|
||||
rpush(SafeEncoder.encode(key), bvals);
|
||||
public void rpush(final String key, final String... string) {
|
||||
rpush(SafeEncoder.encode(key), SafeEncoder.encodeMany(string));
|
||||
}
|
||||
|
||||
|
||||
public void lpush(final String key, final String... vals) {
|
||||
final byte[][] bvals = new byte[vals.length][];
|
||||
for (int i = 0; i < bvals.length; i++) {
|
||||
bvals[i] = SafeEncoder.encode(vals[i]);
|
||||
}
|
||||
lpush(SafeEncoder.encode(key), bvals);
|
||||
public void lpush(final String key, final String... string) {
|
||||
lpush(SafeEncoder.encode(key), SafeEncoder.encodeMany(string));
|
||||
}
|
||||
|
||||
public void llen(final String key) {
|
||||
@@ -247,16 +233,16 @@ public class Client extends BinaryClient implements Commands {
|
||||
rpoplpush(SafeEncoder.encode(srckey), SafeEncoder.encode(dstkey));
|
||||
}
|
||||
|
||||
public void sadd(final String key, final String member) {
|
||||
sadd(SafeEncoder.encode(key), SafeEncoder.encode(member));
|
||||
public void sadd(final String key, final String... members) {
|
||||
sadd(SafeEncoder.encode(key), SafeEncoder.encodeMany(members));
|
||||
}
|
||||
|
||||
public void smembers(final String key) {
|
||||
smembers(SafeEncoder.encode(key));
|
||||
}
|
||||
|
||||
public void srem(final String key, final String member) {
|
||||
srem(SafeEncoder.encode(key), SafeEncoder.encode(member));
|
||||
public void srem(final String key, final String... members) {
|
||||
srem(SafeEncoder.encode(key), SafeEncoder.encodeMany(members));
|
||||
}
|
||||
|
||||
public void spop(final String key) {
|
||||
@@ -337,8 +323,8 @@ public class Client extends BinaryClient implements Commands {
|
||||
zrange(SafeEncoder.encode(key), start, end);
|
||||
}
|
||||
|
||||
public void zrem(final String key, final String member) {
|
||||
zrem(SafeEncoder.encode(key), SafeEncoder.encode(member));
|
||||
public void zrem(final String key, final String... members) {
|
||||
zrem(SafeEncoder.encode(key), SafeEncoder.encodeMany(members));
|
||||
}
|
||||
|
||||
public void zincrby(final String key, final double score,
|
||||
@@ -402,8 +388,8 @@ public class Client extends BinaryClient implements Commands {
|
||||
|
||||
public void sort(final String key, final SortingParams sortingParameters,
|
||||
final String dstkey) {
|
||||
sort(SafeEncoder.encode(key), sortingParameters, SafeEncoder
|
||||
.encode(dstkey));
|
||||
sort(SafeEncoder.encode(key), sortingParameters,
|
||||
SafeEncoder.encode(dstkey));
|
||||
}
|
||||
|
||||
public void sort(final String key, final String dstkey) {
|
||||
@@ -610,23 +596,25 @@ public class Client extends BinaryClient implements Commands {
|
||||
configGet(SafeEncoder.encode(pattern));
|
||||
}
|
||||
|
||||
private byte[][] getByteParams(String... params){
|
||||
private byte[][] getByteParams(String... params) {
|
||||
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]);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
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));
|
||||
evalsha(SafeEncoder.encode(sha1), toByteArray(keyCount),
|
||||
getByteParams(params));
|
||||
}
|
||||
|
||||
public void scriptExists(String... sha1){
|
||||
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]);
|
||||
@@ -634,7 +622,18 @@ public class Client extends BinaryClient implements Commands {
|
||||
scriptExists(bsha1);
|
||||
}
|
||||
|
||||
public void scriptLoad(String script){
|
||||
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()));
|
||||
}
|
||||
|
||||
zaddBinary(SafeEncoder.encode(key), binaryScoreMembers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public interface Commands {
|
||||
|
||||
public void hexists(final String key, final String field);
|
||||
|
||||
public void hdel(final String key, final String field);
|
||||
public void hdel(final String key, final String... fields);
|
||||
|
||||
public void hlen(final String key);
|
||||
|
||||
@@ -86,9 +86,9 @@ public interface Commands {
|
||||
|
||||
public void hgetAll(final String key);
|
||||
|
||||
public void rpush(final String key, final String... string);
|
||||
public void rpush(final String key, final String... strings);
|
||||
|
||||
public void lpush(final String key, final String... string);
|
||||
public void lpush(final String key, final String... strings);
|
||||
|
||||
public void llen(final String key);
|
||||
|
||||
@@ -108,11 +108,11 @@ public interface Commands {
|
||||
|
||||
public void rpoplpush(final String srckey, final String dstkey);
|
||||
|
||||
public void sadd(final String key, final String member);
|
||||
public void sadd(final String key, final String... members);
|
||||
|
||||
public void smembers(final String key);
|
||||
|
||||
public void srem(final String key, final String member);
|
||||
public void srem(final String key, final String... member);
|
||||
|
||||
public void spop(final String key);
|
||||
|
||||
@@ -139,9 +139,11 @@ public interface Commands {
|
||||
|
||||
public void zadd(final String key, final double score, final String member);
|
||||
|
||||
public void zadd(final String key, final Map<Double, String> scoreMembers);
|
||||
|
||||
public void zrange(final String key, final int start, final int end);
|
||||
|
||||
public void zrem(final String key, final String member);
|
||||
public void zrem(final String key, final String... members);
|
||||
|
||||
public void zincrby(final String key, final double score,
|
||||
final String member);
|
||||
|
||||
@@ -781,13 +781,13 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
* <b>Time complexity:</b> O(1)
|
||||
*
|
||||
* @param key
|
||||
* @param field
|
||||
* @param fields
|
||||
* @return If the field was present in the hash it is deleted and 1 is
|
||||
* returned, otherwise 0 is returned and no operation is performed.
|
||||
*/
|
||||
public Long hdel(final String key, final String field) {
|
||||
public Long hdel(final String key, final String... fields) {
|
||||
checkIsInMulti();
|
||||
client.hdel(key, field);
|
||||
client.hdel(key, fields);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
@@ -863,13 +863,13 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
* @see Jedis#lpush(String, String)
|
||||
*
|
||||
* @param key
|
||||
* @param string
|
||||
* @param strings
|
||||
* @return Integer reply, specifically, the number of elements inside the
|
||||
* list after the push operation.
|
||||
*/
|
||||
public Long rpush(final String key, final String... string) {
|
||||
public Long rpush(final String key, final String... strings) {
|
||||
checkIsInMulti();
|
||||
client.rpush(key, string);
|
||||
client.rpush(key, strings);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
@@ -884,13 +884,13 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
* @see Jedis#rpush(String, String)
|
||||
*
|
||||
* @param key
|
||||
* @param string
|
||||
* @param strings
|
||||
* @return Integer reply, specifically, the number of elements inside the
|
||||
* list after the push operation.
|
||||
*/
|
||||
public Long lpush(final String key, final String... string) {
|
||||
public Long lpush(final String key, final String... strings) {
|
||||
checkIsInMulti();
|
||||
client.lpush(key, string);
|
||||
client.lpush(key, strings);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
@@ -1142,13 +1142,13 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
* Time complexity O(1)
|
||||
*
|
||||
* @param key
|
||||
* @param member
|
||||
* @param members
|
||||
* @return Integer reply, specifically: 1 if the new element was added 0 if
|
||||
* the element was already a member of the set
|
||||
*/
|
||||
public Long sadd(final String key, final String member) {
|
||||
public Long sadd(final String key, final String... members) {
|
||||
checkIsInMulti();
|
||||
client.sadd(key, member);
|
||||
client.sadd(key, members);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
@@ -1176,13 +1176,13 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
* Time complexity O(1)
|
||||
*
|
||||
* @param key
|
||||
* @param member
|
||||
* @param members
|
||||
* @return Integer reply, specifically: 1 if the new element was removed 0
|
||||
* if the new element was not a member of the set
|
||||
*/
|
||||
public Long srem(final String key, final String member) {
|
||||
public Long srem(final String key, final String... members) {
|
||||
checkIsInMulti();
|
||||
client.srem(key, member);
|
||||
client.srem(key, members);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
@@ -1439,6 +1439,12 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
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) {
|
||||
checkIsInMulti();
|
||||
client.zrange(key, start, end);
|
||||
@@ -1457,13 +1463,13 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
*
|
||||
*
|
||||
* @param key
|
||||
* @param member
|
||||
* @param members
|
||||
* @return Integer reply, specifically: 1 if the new element was removed 0
|
||||
* if the new element was not a member of the set
|
||||
*/
|
||||
public Long zrem(final String key, final String member) {
|
||||
public Long zrem(final String key, final String... members) {
|
||||
checkIsInMulti();
|
||||
client.zrem(key, member);
|
||||
client.zrem(key, members);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public interface JedisCommands {
|
||||
|
||||
Boolean hexists(String key, String field);
|
||||
|
||||
Long hdel(String key, String field);
|
||||
Long hdel(String key, String... field);
|
||||
|
||||
Long hlen(String key);
|
||||
|
||||
@@ -92,11 +92,11 @@ public interface JedisCommands {
|
||||
|
||||
String rpop(String key);
|
||||
|
||||
Long sadd(String key, String member);
|
||||
Long sadd(String key, String... member);
|
||||
|
||||
Set<String> smembers(String key);
|
||||
|
||||
Long srem(String key, String member);
|
||||
Long srem(String key, String... member);
|
||||
|
||||
String spop(String key);
|
||||
|
||||
@@ -108,9 +108,11 @@ public interface JedisCommands {
|
||||
|
||||
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);
|
||||
|
||||
Long zrem(String key, String member);
|
||||
Long zrem(String key, String... member);
|
||||
|
||||
Double zincrby(String key, double score, String member);
|
||||
|
||||
|
||||
@@ -672,14 +672,14 @@ public class Pipeline extends Queable {
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<List<String>> sort(String key) {
|
||||
public Response<Long> sort(String 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);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<List<String>> sort(String key,
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.util.Hashing;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.util.Hashing;
|
||||
|
||||
public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||
public ShardedJedis(List<JedisShardInfo> shards) {
|
||||
super(shards);
|
||||
@@ -173,9 +173,9 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||
return j.del(key);
|
||||
}
|
||||
|
||||
public Long hdel(String key, String field) {
|
||||
public Long hdel(String key, String... fields) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hdel(key, field);
|
||||
return j.hdel(key, fields);
|
||||
}
|
||||
|
||||
public Long hlen(String key) {
|
||||
@@ -198,14 +198,14 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||
return j.hgetAll(key);
|
||||
}
|
||||
|
||||
public Long rpush(String key, String... string) {
|
||||
public Long rpush(String key, String... strings) {
|
||||
Jedis j = getShard(key);
|
||||
return j.rpush(key, string);
|
||||
return j.rpush(key, strings);
|
||||
}
|
||||
|
||||
public Long lpush(String key, String... string) {
|
||||
public Long lpush(String key, String... strings) {
|
||||
Jedis j = getShard(key);
|
||||
return j.lpush(key, string);
|
||||
return j.lpush(key, strings);
|
||||
}
|
||||
|
||||
public Long llen(String key) {
|
||||
@@ -248,9 +248,9 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||
return j.rpop(key);
|
||||
}
|
||||
|
||||
public Long sadd(String key, String member) {
|
||||
public Long sadd(String key, String... members) {
|
||||
Jedis j = getShard(key);
|
||||
return j.sadd(key, member);
|
||||
return j.sadd(key, members);
|
||||
}
|
||||
|
||||
public Set<String> smembers(String key) {
|
||||
@@ -258,9 +258,9 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||
return j.smembers(key);
|
||||
}
|
||||
|
||||
public Long srem(String key, String member) {
|
||||
public Long srem(String key, String... members) {
|
||||
Jedis j = getShard(key);
|
||||
return j.srem(key, member);
|
||||
return j.srem(key, members);
|
||||
}
|
||||
|
||||
public String spop(String key) {
|
||||
@@ -288,14 +288,19 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||
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) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrange(key, start, end);
|
||||
}
|
||||
|
||||
public Long zrem(String key, String member) {
|
||||
public Long zrem(String key, String... members) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrem(key, member);
|
||||
return j.zrem(key, members);
|
||||
}
|
||||
|
||||
public Double zincrby(String key, double score, String member) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package redis.clients.util;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import redis.clients.jedis.Protocol;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
@@ -11,6 +13,14 @@ import redis.clients.jedis.exceptions.JedisException;
|
||||
*
|
||||
*/
|
||||
public class SafeEncoder {
|
||||
public static byte[][] encodeMany(final String... strs){
|
||||
byte[][] many = new byte[strs.length][];
|
||||
for(int i=0;i<strs.length;i++){
|
||||
many[i] = encode(strs[i]);
|
||||
}
|
||||
return many;
|
||||
}
|
||||
|
||||
public static byte[] encode(final String str) {
|
||||
try {
|
||||
if (str == null) {
|
||||
|
||||
@@ -11,6 +11,7 @@ public class SlowlogCommandsTest extends JedisCommandTestBase {
|
||||
@Test
|
||||
public void slowlog() {
|
||||
//do something
|
||||
jedis.configSet("slowlog-log-slower-than", "0");
|
||||
jedis.set("foo", "bar");
|
||||
jedis.set("foo2", "bar2");
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user