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,
|
||||
@@ -785,4 +805,4 @@ public class BinaryClient extends Connection {
|
||||
public void slowlogLen() {
|
||||
sendCommand(SLOWLOG, LEN.raw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user