Merge branch 'master' into introduce-new-sentinel-commands-added-to-Redis-2.8
Conflicts: Makefile src/main/java/redis/clients/jedis/Jedis.java
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AdvancedBinaryJedisCommands {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import redis.clients.util.Slowlog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import redis.clients.util.Slowlog;
|
||||
|
||||
public interface AdvancedJedisCommands {
|
||||
List<String> configGet(String pattern);
|
||||
|
||||
@@ -27,7 +27,7 @@ public interface BasicCommands {
|
||||
String shutdown();
|
||||
|
||||
String info();
|
||||
|
||||
|
||||
String info(String section);
|
||||
|
||||
String slaveof(String host, int port);
|
||||
@@ -39,6 +39,6 @@ public interface BasicCommands {
|
||||
String debug(DebugParams params);
|
||||
|
||||
String configResetStat();
|
||||
|
||||
|
||||
Long waitReplicas(int replicas, long timeout);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
|
||||
/**
|
||||
* Pipelined responses for all of the low level, non key related commands
|
||||
*/
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import redis.clients.jedis.Protocol.Command;
|
||||
import redis.clients.jedis.Protocol.Keyword;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
import static redis.clients.jedis.Protocol.toByteArray;
|
||||
import static redis.clients.jedis.Protocol.Command.*;
|
||||
import static redis.clients.jedis.Protocol.Keyword.ENCODING;
|
||||
import static redis.clients.jedis.Protocol.Keyword.IDLETIME;
|
||||
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.REFCOUNT;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static redis.clients.jedis.Protocol.Command.*;
|
||||
import static redis.clients.jedis.Protocol.Command.EXISTS;
|
||||
import static redis.clients.jedis.Protocol.Command.PSUBSCRIBE;
|
||||
import static redis.clients.jedis.Protocol.Command.PUNSUBSCRIBE;
|
||||
import static redis.clients.jedis.Protocol.Command.SUBSCRIBE;
|
||||
import static redis.clients.jedis.Protocol.Command.UNSUBSCRIBE;
|
||||
import static redis.clients.jedis.Protocol.Keyword.*;
|
||||
import static redis.clients.jedis.Protocol.toByteArray;
|
||||
import redis.clients.jedis.Protocol.Command;
|
||||
import redis.clients.jedis.Protocol.Keyword;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
public class BinaryClient extends Connection {
|
||||
public enum LIST_POSITION {
|
||||
@@ -34,10 +38,16 @@ public class BinaryClient extends Connection {
|
||||
|
||||
private long db;
|
||||
|
||||
private boolean isInWatch;
|
||||
|
||||
public boolean isInMulti() {
|
||||
return isInMulti;
|
||||
}
|
||||
|
||||
public boolean isInWatch() {
|
||||
return isInWatch;
|
||||
}
|
||||
|
||||
public BinaryClient(final String host) {
|
||||
super(host);
|
||||
}
|
||||
@@ -82,11 +92,11 @@ public class BinaryClient extends Connection {
|
||||
sendCommand(Command.SET, key, value);
|
||||
}
|
||||
|
||||
public void set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final long time) {
|
||||
sendCommand(Command.SET, key, value, nxxx, expx, toByteArray(time));
|
||||
public void set(final byte[] key, final byte[] value, final byte[] nxxx,
|
||||
final byte[] expx, final long time) {
|
||||
sendCommand(Command.SET, key, value, nxxx, expx, toByteArray(time));
|
||||
}
|
||||
|
||||
|
||||
public void get(final byte[] key) {
|
||||
sendCommand(Command.GET, key);
|
||||
}
|
||||
@@ -377,15 +387,16 @@ public class BinaryClient extends Connection {
|
||||
sendCommand(ZADD, key, toByteArray(score), member);
|
||||
}
|
||||
|
||||
public void zaddBinary(final byte[] key, Map<Double, byte[]> scoreMembers) {
|
||||
public void zaddBinary(final byte[] key,
|
||||
final Map<byte[], Double> 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());
|
||||
for (Map.Entry<byte[], Double> entry : scoreMembers.entrySet()) {
|
||||
args.add(toByteArray(entry.getValue()));
|
||||
args.add(entry.getKey());
|
||||
}
|
||||
|
||||
byte[][] argsArray = new byte[args.size()][];
|
||||
@@ -447,19 +458,23 @@ public class BinaryClient extends Connection {
|
||||
public void discard() {
|
||||
sendCommand(DISCARD);
|
||||
isInMulti = false;
|
||||
isInWatch = false;
|
||||
}
|
||||
|
||||
public void exec() {
|
||||
sendCommand(EXEC);
|
||||
isInMulti = false;
|
||||
isInWatch = false;
|
||||
}
|
||||
|
||||
public void watch(final byte[]... keys) {
|
||||
sendCommand(WATCH, keys);
|
||||
isInWatch = true;
|
||||
}
|
||||
|
||||
public void unwatch() {
|
||||
sendCommand(UNWATCH);
|
||||
isInWatch = false;
|
||||
}
|
||||
|
||||
public void sort(final byte[] key) {
|
||||
@@ -476,14 +491,14 @@ public class BinaryClient extends Connection {
|
||||
public void blpop(final byte[][] args) {
|
||||
sendCommand(BLPOP, args);
|
||||
}
|
||||
|
||||
|
||||
public void blpop(final int timeout, final byte[]... keys) {
|
||||
final List<byte[]> args = new ArrayList<byte[]>();
|
||||
for (final byte[] arg : keys) {
|
||||
args.add(arg);
|
||||
}
|
||||
args.add(Protocol.toByteArray(timeout));
|
||||
blpop(args.toArray(new byte[args.size()][]));
|
||||
final List<byte[]> args = new ArrayList<byte[]>();
|
||||
for (final byte[] arg : keys) {
|
||||
args.add(arg);
|
||||
}
|
||||
args.add(Protocol.toByteArray(timeout));
|
||||
blpop(args.toArray(new byte[args.size()][]));
|
||||
}
|
||||
|
||||
public void sort(final byte[] key, final SortingParams sortingParameters,
|
||||
@@ -503,14 +518,14 @@ public class BinaryClient extends Connection {
|
||||
public void brpop(final byte[][] args) {
|
||||
sendCommand(BRPOP, args);
|
||||
}
|
||||
|
||||
|
||||
public void brpop(final int timeout, final byte[]... keys) {
|
||||
final List<byte[]> args = new ArrayList<byte[]>();
|
||||
for (final byte[] arg : keys) {
|
||||
args.add(arg);
|
||||
}
|
||||
args.add(Protocol.toByteArray(timeout));
|
||||
brpop(args.toArray(new byte[args.size()][]));
|
||||
final List<byte[]> args = new ArrayList<byte[]>();
|
||||
for (final byte[] arg : keys) {
|
||||
args.add(arg);
|
||||
}
|
||||
args.add(Protocol.toByteArray(timeout));
|
||||
brpop(args.toArray(new byte[args.size()][]));
|
||||
}
|
||||
|
||||
public void auth(final String password) {
|
||||
@@ -543,32 +558,39 @@ public class BinaryClient extends Connection {
|
||||
}
|
||||
|
||||
public void punsubscribe(final byte[]... patterns) {
|
||||
sendCommand(PUNSUBSCRIBE, patterns);
|
||||
sendCommand(PUNSUBSCRIBE, patterns);
|
||||
}
|
||||
|
||||
public void pubsub(final byte[]... args) {
|
||||
sendCommand(PUBSUB, args);
|
||||
}
|
||||
|
||||
public void zcount(final byte[] key, final double min, final double max) {
|
||||
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf".getBytes() : toByteArray(min);
|
||||
byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf".getBytes() : toByteArray(max);
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
|
||||
.getBytes() : toByteArray(min);
|
||||
byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf"
|
||||
.getBytes() : toByteArray(max);
|
||||
|
||||
sendCommand(ZCOUNT, key, byteArrayMin, byteArrayMax);
|
||||
sendCommand(ZCOUNT, key, byteArrayMin, byteArrayMax);
|
||||
}
|
||||
|
||||
public void zcount(final byte[] key, final byte min[], final byte max[]) {
|
||||
sendCommand(ZCOUNT, key, min, max);
|
||||
sendCommand(ZCOUNT, key, min, max);
|
||||
}
|
||||
|
||||
public void zcount(final byte[] key, final String min, final String max) {
|
||||
sendCommand(ZCOUNT, key, min.getBytes(), max.getBytes());
|
||||
sendCommand(ZCOUNT, key, min.getBytes(), max.getBytes());
|
||||
}
|
||||
|
||||
public void zrangeByScore(final byte[] key, final double min,
|
||||
final double max) {
|
||||
final double max) {
|
||||
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf".getBytes() : toByteArray(min);
|
||||
byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf".getBytes() : toByteArray(max);
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
|
||||
.getBytes() : toByteArray(min);
|
||||
byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf"
|
||||
.getBytes() : toByteArray(max);
|
||||
|
||||
sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax);
|
||||
sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax);
|
||||
}
|
||||
|
||||
public void zrangeByScore(final byte[] key, final byte[] min,
|
||||
@@ -577,17 +599,19 @@ public class BinaryClient extends Connection {
|
||||
}
|
||||
|
||||
public void zrangeByScore(final byte[] key, final String min,
|
||||
final String max) {
|
||||
sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes());
|
||||
final String max) {
|
||||
sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes());
|
||||
}
|
||||
|
||||
public void zrevrangeByScore(final byte[] key, final double max,
|
||||
final double min) {
|
||||
final double min) {
|
||||
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf".getBytes() : toByteArray(min);
|
||||
byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf".getBytes() : toByteArray(max);
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
|
||||
.getBytes() : toByteArray(min);
|
||||
byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf"
|
||||
.getBytes() : toByteArray(max);
|
||||
|
||||
sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin);
|
||||
sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin);
|
||||
}
|
||||
|
||||
public void zrevrangeByScore(final byte[] key, final byte[] max,
|
||||
@@ -596,114 +620,125 @@ public class BinaryClient extends Connection {
|
||||
}
|
||||
|
||||
public void zrevrangeByScore(final byte[] key, final String max,
|
||||
final String min) {
|
||||
sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes());
|
||||
final String min) {
|
||||
sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes());
|
||||
}
|
||||
|
||||
public void zrangeByScore(final byte[] key, final double min,
|
||||
final double max, final int offset, int count) {
|
||||
final double max, final int offset, int count) {
|
||||
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf".getBytes() : toByteArray(min);
|
||||
byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf".getBytes() : toByteArray(max);
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
|
||||
.getBytes() : toByteArray(min);
|
||||
byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf"
|
||||
.getBytes() : toByteArray(max);
|
||||
|
||||
sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax,
|
||||
LIMIT.raw, toByteArray(offset), toByteArray(count));
|
||||
sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax, LIMIT.raw,
|
||||
toByteArray(offset), toByteArray(count));
|
||||
}
|
||||
|
||||
public void zrangeByScore(final byte[] key, final String min,
|
||||
final String max, final int offset, int count) {
|
||||
|
||||
sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes(),
|
||||
LIMIT.raw, toByteArray(offset), toByteArray(count));
|
||||
public void zrangeByScore(final byte[] key, final String min,
|
||||
final String max, final int offset, int count) {
|
||||
|
||||
sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes(),
|
||||
LIMIT.raw, toByteArray(offset), toByteArray(count));
|
||||
}
|
||||
|
||||
public void zrevrangeByScore(final byte[] key, final double max,
|
||||
final double min, final int offset, int count) {
|
||||
final double min, final int offset, int count) {
|
||||
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf".getBytes() : toByteArray(min);
|
||||
byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf".getBytes() : toByteArray(max);
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
|
||||
.getBytes() : toByteArray(min);
|
||||
byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf"
|
||||
.getBytes() : toByteArray(max);
|
||||
|
||||
sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin,
|
||||
LIMIT.raw, toByteArray(offset), toByteArray(count));
|
||||
}
|
||||
sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin,
|
||||
LIMIT.raw, toByteArray(offset), toByteArray(count));
|
||||
}
|
||||
|
||||
public void zrevrangeByScore(final byte[] key, final String max,
|
||||
final String min, final int offset, int count) {
|
||||
final String min, final int offset, int count) {
|
||||
|
||||
sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes(),
|
||||
LIMIT.raw, toByteArray(offset), toByteArray(count));
|
||||
sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes(),
|
||||
LIMIT.raw, toByteArray(offset), toByteArray(count));
|
||||
}
|
||||
|
||||
public void zrangeByScoreWithScores(final byte[] key, final double min,
|
||||
final double max) {
|
||||
final double max) {
|
||||
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf".getBytes() : toByteArray(min);
|
||||
byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf".getBytes() : toByteArray(max);
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
|
||||
.getBytes() : toByteArray(min);
|
||||
byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf"
|
||||
.getBytes() : toByteArray(max);
|
||||
|
||||
sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax,
|
||||
WITHSCORES.raw);
|
||||
sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax,
|
||||
WITHSCORES.raw);
|
||||
}
|
||||
|
||||
public void zrangeByScoreWithScores(final byte[] key, final String min,
|
||||
final String max) {
|
||||
final String max) {
|
||||
|
||||
sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes(),
|
||||
WITHSCORES.raw);
|
||||
sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes(),
|
||||
WITHSCORES.raw);
|
||||
}
|
||||
|
||||
public void zrevrangeByScoreWithScores(final byte[] key, final double max,
|
||||
final double min) {
|
||||
final double min) {
|
||||
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf".getBytes() : toByteArray(min);
|
||||
byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf".getBytes() : toByteArray(max);
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
|
||||
.getBytes() : toByteArray(min);
|
||||
byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf"
|
||||
.getBytes() : toByteArray(max);
|
||||
|
||||
sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin,
|
||||
WITHSCORES.raw);
|
||||
sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin,
|
||||
WITHSCORES.raw);
|
||||
}
|
||||
|
||||
public void zrevrangeByScoreWithScores(final byte[] key, final String max,
|
||||
final String min) {
|
||||
sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes(),
|
||||
WITHSCORES.raw);
|
||||
final String min) {
|
||||
sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes(),
|
||||
WITHSCORES.raw);
|
||||
}
|
||||
|
||||
public void zrangeByScoreWithScores(final byte[] key, final double min,
|
||||
final double max, final int offset, final int count) {
|
||||
final double max, final int offset, final int count) {
|
||||
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf".getBytes() : toByteArray(min);
|
||||
byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf".getBytes() : toByteArray(max);
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
|
||||
.getBytes() : toByteArray(min);
|
||||
byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf"
|
||||
.getBytes() : toByteArray(max);
|
||||
|
||||
sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax,
|
||||
LIMIT.raw, toByteArray(offset), toByteArray(count),
|
||||
WITHSCORES.raw);
|
||||
sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax, LIMIT.raw,
|
||||
toByteArray(offset), toByteArray(count), WITHSCORES.raw);
|
||||
}
|
||||
|
||||
public void zrangeByScoreWithScores(final byte[] key, final String min,
|
||||
final String max, final int offset, final int count) {
|
||||
sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes(),
|
||||
LIMIT.raw, toByteArray(offset), toByteArray(count),
|
||||
WITHSCORES.raw);
|
||||
final String max, final int offset, final int count) {
|
||||
sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes(),
|
||||
LIMIT.raw, toByteArray(offset), toByteArray(count),
|
||||
WITHSCORES.raw);
|
||||
}
|
||||
|
||||
public void zrevrangeByScoreWithScores(final byte[] key, final double max,
|
||||
final double min, final int offset, final int count) {
|
||||
final double min, final int offset, final int count) {
|
||||
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf".getBytes() : toByteArray(min);
|
||||
byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf".getBytes() : toByteArray(max);
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
|
||||
.getBytes() : toByteArray(min);
|
||||
byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf"
|
||||
.getBytes() : toByteArray(max);
|
||||
|
||||
sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin,
|
||||
LIMIT.raw, toByteArray(offset), toByteArray(count),
|
||||
WITHSCORES.raw);
|
||||
sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin,
|
||||
LIMIT.raw, toByteArray(offset), toByteArray(count),
|
||||
WITHSCORES.raw);
|
||||
}
|
||||
|
||||
public void zrevrangeByScoreWithScores(final byte[] key, final String max,
|
||||
final String min, final int offset, final int count) {
|
||||
final String min, final int offset, final int count) {
|
||||
|
||||
sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes(),
|
||||
LIMIT.raw, toByteArray(offset), toByteArray(count),
|
||||
WITHSCORES.raw);
|
||||
sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes(),
|
||||
LIMIT.raw, toByteArray(offset), toByteArray(count),
|
||||
WITHSCORES.raw);
|
||||
}
|
||||
|
||||
|
||||
public void zrangeByScore(final byte[] key, final byte[] min,
|
||||
final byte[] max, final int offset, int count) {
|
||||
sendCommand(ZRANGEBYSCORE, key, min, max, LIMIT.raw,
|
||||
@@ -746,11 +781,11 @@ public class BinaryClient extends Connection {
|
||||
public void zremrangeByScore(final byte[] key, final byte[] start,
|
||||
final byte[] end) {
|
||||
sendCommand(ZREMRANGEBYSCORE, key, start, end);
|
||||
}
|
||||
}
|
||||
|
||||
public void zremrangeByScore(final byte[] key, final String start,
|
||||
final String end) {
|
||||
sendCommand(ZREMRANGEBYSCORE, key, start.getBytes(), end.getBytes());
|
||||
final String end) {
|
||||
sendCommand(ZREMRANGEBYSCORE, key, start.getBytes(), end.getBytes());
|
||||
}
|
||||
|
||||
public void zunionstore(final byte[] dstkey, final byte[]... sets) {
|
||||
@@ -816,7 +851,7 @@ public class BinaryClient extends Connection {
|
||||
public void info() {
|
||||
sendCommand(INFO);
|
||||
}
|
||||
|
||||
|
||||
public void info(final String section) {
|
||||
sendCommand(INFO, section);
|
||||
}
|
||||
@@ -888,7 +923,7 @@ public class BinaryClient extends Connection {
|
||||
}
|
||||
|
||||
public void setbit(byte[] key, long offset, boolean value) {
|
||||
sendCommand(SETBIT, key, toByteArray(offset), toByteArray(value));
|
||||
sendCommand(SETBIT, key, toByteArray(offset), toByteArray(value));
|
||||
}
|
||||
|
||||
public void getbit(byte[] key, long offset) {
|
||||
@@ -913,6 +948,14 @@ public class BinaryClient extends Connection {
|
||||
super.disconnect();
|
||||
}
|
||||
|
||||
public void resetState() {
|
||||
if (isInMulti())
|
||||
discard();
|
||||
|
||||
if (isInWatch())
|
||||
unwatch();
|
||||
}
|
||||
|
||||
private void sendEvalCommand(Command command, byte[] script,
|
||||
byte[] keyCount, byte[][] params) {
|
||||
|
||||
@@ -932,7 +975,7 @@ public class BinaryClient extends Connection {
|
||||
}
|
||||
|
||||
public void eval(byte[] script, int keyCount, byte[]... params) {
|
||||
eval(script, toByteArray(keyCount), params);
|
||||
eval(script, toByteArray(keyCount), params);
|
||||
}
|
||||
|
||||
public void evalsha(byte[] sha1, byte[] keyCount, byte[]... params) {
|
||||
@@ -940,7 +983,7 @@ public class BinaryClient extends Connection {
|
||||
}
|
||||
|
||||
public void evalsha(byte[] sha1, int keyCount, byte[]... params) {
|
||||
sendEvalCommand(EVALSHA, sha1, toByteArray(keyCount), params);
|
||||
sendEvalCommand(EVALSHA, sha1, toByteArray(keyCount), params);
|
||||
}
|
||||
|
||||
public void scriptFlush() {
|
||||
@@ -993,153 +1036,160 @@ public class BinaryClient extends Connection {
|
||||
}
|
||||
|
||||
public void bitcount(byte[] key) {
|
||||
sendCommand(BITCOUNT, key);
|
||||
sendCommand(BITCOUNT, key);
|
||||
}
|
||||
|
||||
public void bitcount(byte[] key, long start, long end) {
|
||||
sendCommand(BITCOUNT, key, toByteArray(start), toByteArray(end));
|
||||
sendCommand(BITCOUNT, key, toByteArray(start), toByteArray(end));
|
||||
}
|
||||
|
||||
public void bitop(BitOP op, byte[] destKey, byte[]... srcKeys) {
|
||||
Keyword kw = Keyword.AND;
|
||||
int len = srcKeys.length;
|
||||
switch (op) {
|
||||
case AND:
|
||||
kw = Keyword.AND;
|
||||
break;
|
||||
case OR:
|
||||
kw = Keyword.OR;
|
||||
break;
|
||||
case XOR:
|
||||
kw = Keyword.XOR;
|
||||
break;
|
||||
case NOT:
|
||||
kw = Keyword.NOT;
|
||||
len = Math.min(1, len);
|
||||
break;
|
||||
}
|
||||
Keyword kw = Keyword.AND;
|
||||
int len = srcKeys.length;
|
||||
switch (op) {
|
||||
case AND:
|
||||
kw = Keyword.AND;
|
||||
break;
|
||||
case OR:
|
||||
kw = Keyword.OR;
|
||||
break;
|
||||
case XOR:
|
||||
kw = Keyword.XOR;
|
||||
break;
|
||||
case NOT:
|
||||
kw = Keyword.NOT;
|
||||
len = Math.min(1, len);
|
||||
break;
|
||||
}
|
||||
|
||||
byte[][] bargs = new byte[len + 2][];
|
||||
bargs[0] = kw.raw;
|
||||
bargs[1] = destKey;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
bargs[i + 2] = srcKeys[i];
|
||||
}
|
||||
byte[][] bargs = new byte[len + 2][];
|
||||
bargs[0] = kw.raw;
|
||||
bargs[1] = destKey;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
bargs[i + 2] = srcKeys[i];
|
||||
}
|
||||
|
||||
sendCommand(BITOP, bargs);
|
||||
sendCommand(BITOP, bargs);
|
||||
}
|
||||
|
||||
public void sentinel(final byte[]... args) {
|
||||
sendCommand(SENTINEL, args);
|
||||
sendCommand(SENTINEL, args);
|
||||
}
|
||||
|
||||
|
||||
public void dump(final byte[] key) {
|
||||
sendCommand(DUMP, key);
|
||||
sendCommand(DUMP, key);
|
||||
}
|
||||
|
||||
public void restore(final byte[] key, final int ttl, final byte[] serializedValue) {
|
||||
sendCommand(RESTORE, key, toByteArray(ttl), serializedValue);
|
||||
|
||||
public void restore(final byte[] key, final int ttl,
|
||||
final byte[] serializedValue) {
|
||||
sendCommand(RESTORE, key, toByteArray(ttl), serializedValue);
|
||||
}
|
||||
|
||||
|
||||
public void pexpire(final byte[] key, final int milliseconds) {
|
||||
sendCommand(PEXPIRE, key, toByteArray(milliseconds));
|
||||
sendCommand(PEXPIRE, key, toByteArray(milliseconds));
|
||||
}
|
||||
|
||||
|
||||
public void pexpireAt(final byte[] key, final long millisecondsTimestamp) {
|
||||
sendCommand(PEXPIREAT, key, toByteArray(millisecondsTimestamp));
|
||||
sendCommand(PEXPIREAT, key, toByteArray(millisecondsTimestamp));
|
||||
}
|
||||
|
||||
|
||||
public void pttl(final byte[] key) {
|
||||
sendCommand(PTTL, key);
|
||||
sendCommand(PTTL, key);
|
||||
}
|
||||
|
||||
|
||||
public void incrByFloat(final byte[] key, final double increment) {
|
||||
sendCommand(INCRBYFLOAT, key, toByteArray(increment));
|
||||
sendCommand(INCRBYFLOAT, key, toByteArray(increment));
|
||||
}
|
||||
|
||||
public void psetex(final byte[] key, final int milliseconds, final byte[] value) {
|
||||
sendCommand(PSETEX, key, toByteArray(milliseconds), value);
|
||||
|
||||
public void psetex(final byte[] key, final int milliseconds,
|
||||
final byte[] value) {
|
||||
sendCommand(PSETEX, key, toByteArray(milliseconds), value);
|
||||
}
|
||||
|
||||
|
||||
public void set(final byte[] key, final byte[] value, final byte[] nxxx) {
|
||||
sendCommand(Command.SET, key, value, nxxx);
|
||||
sendCommand(Command.SET, key, value, nxxx);
|
||||
}
|
||||
|
||||
public void set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final int time) {
|
||||
sendCommand(Command.SET, key, value, nxxx, expx, toByteArray(time));
|
||||
|
||||
public void set(final byte[] key, final byte[] value, final byte[] nxxx,
|
||||
final byte[] expx, final int time) {
|
||||
sendCommand(Command.SET, key, value, nxxx, expx, toByteArray(time));
|
||||
}
|
||||
|
||||
|
||||
public void srandmember(final byte[] key, final int count) {
|
||||
sendCommand(SRANDMEMBER, key, toByteArray(count));
|
||||
sendCommand(SRANDMEMBER, key, toByteArray(count));
|
||||
}
|
||||
|
||||
|
||||
public void clientKill(final byte[] client) {
|
||||
sendCommand(CLIENT, Keyword.KILL.raw, client);
|
||||
sendCommand(CLIENT, Keyword.KILL.raw, client);
|
||||
}
|
||||
|
||||
|
||||
public void clientGetname() {
|
||||
sendCommand(CLIENT, Keyword.GETNAME.raw);
|
||||
sendCommand(CLIENT, Keyword.GETNAME.raw);
|
||||
}
|
||||
|
||||
|
||||
public void clientList() {
|
||||
sendCommand(CLIENT, Keyword.LIST.raw);
|
||||
sendCommand(CLIENT, Keyword.LIST.raw);
|
||||
}
|
||||
|
||||
|
||||
public void clientSetname(final byte[] name) {
|
||||
sendCommand(CLIENT, Keyword.SETNAME.raw, name);
|
||||
sendCommand(CLIENT, Keyword.SETNAME.raw, name);
|
||||
}
|
||||
|
||||
|
||||
public void time() {
|
||||
sendCommand(TIME);
|
||||
sendCommand(TIME);
|
||||
}
|
||||
|
||||
public void migrate(final byte[] host, final int port, final byte[] key, final int destinationDb, final int timeout) {
|
||||
sendCommand(MIGRATE, host, toByteArray(port), key, toByteArray(destinationDb), toByteArray(timeout));
|
||||
|
||||
public void migrate(final byte[] host, final int port, final byte[] key,
|
||||
final int destinationDb, final int timeout) {
|
||||
sendCommand(MIGRATE, host, toByteArray(port), key,
|
||||
toByteArray(destinationDb), toByteArray(timeout));
|
||||
}
|
||||
|
||||
public void hincrByFloat(final byte[] key, final byte[] field, double increment) {
|
||||
sendCommand(HINCRBYFLOAT, key, field, toByteArray(increment));
|
||||
|
||||
public void hincrByFloat(final byte[] key, final byte[] field,
|
||||
double increment) {
|
||||
sendCommand(HINCRBYFLOAT, key, field, toByteArray(increment));
|
||||
}
|
||||
|
||||
|
||||
public void scan(int cursor, final ScanParams params) {
|
||||
final List<byte[]> args = new ArrayList<byte[]>();
|
||||
args.add(toByteArray(cursor));
|
||||
args.addAll(params.getParams());
|
||||
sendCommand(SCAN, args.toArray(new byte[args.size()][]));
|
||||
}
|
||||
|
||||
|
||||
public void hscan(final byte[] key, int cursor, final ScanParams params) {
|
||||
final List<byte[]> args = new ArrayList<byte[]>();
|
||||
args.add(key);
|
||||
args.add(toByteArray(cursor));
|
||||
args.addAll(params.getParams());
|
||||
sendCommand(HSCAN, args.toArray(new byte[args.size()][]));
|
||||
final List<byte[]> args = new ArrayList<byte[]>();
|
||||
args.add(key);
|
||||
args.add(toByteArray(cursor));
|
||||
args.addAll(params.getParams());
|
||||
sendCommand(HSCAN, args.toArray(new byte[args.size()][]));
|
||||
}
|
||||
|
||||
|
||||
public void sscan(final byte[] key, int cursor, final ScanParams params) {
|
||||
final List<byte[]> args = new ArrayList<byte[]>();
|
||||
args.add(key);
|
||||
args.add(toByteArray(cursor));
|
||||
args.addAll(params.getParams());
|
||||
sendCommand(SSCAN, args.toArray(new byte[args.size()][]));
|
||||
final List<byte[]> args = new ArrayList<byte[]>();
|
||||
args.add(key);
|
||||
args.add(toByteArray(cursor));
|
||||
args.addAll(params.getParams());
|
||||
sendCommand(SSCAN, args.toArray(new byte[args.size()][]));
|
||||
}
|
||||
|
||||
|
||||
public void zscan(final byte[] key, int cursor, final ScanParams params) {
|
||||
final List<byte[]> args = new ArrayList<byte[]>();
|
||||
args.add(key);
|
||||
args.add(toByteArray(cursor));
|
||||
args.addAll(params.getParams());
|
||||
sendCommand(ZSCAN, args.toArray(new byte[args.size()][]));
|
||||
final List<byte[]> args = new ArrayList<byte[]>();
|
||||
args.add(key);
|
||||
args.add(toByteArray(cursor));
|
||||
args.addAll(params.getParams());
|
||||
sendCommand(ZSCAN, args.toArray(new byte[args.size()][]));
|
||||
}
|
||||
|
||||
|
||||
public void waitReplicas(int replicas, long timeout) {
|
||||
sendCommand(WAIT, toByteArray(replicas), toByteArray(timeout));
|
||||
}
|
||||
|
||||
public void cluster(final byte[]... args) {
|
||||
sendCommand(CLUSTER, args);
|
||||
sendCommand(CLUSTER, args);
|
||||
}
|
||||
|
||||
public void asking() {
|
||||
sendCommand(Command.ASKING);
|
||||
sendCommand(Command.ASKING);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,25 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import static redis.clients.jedis.Protocol.toByteArray;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
import redis.clients.util.JedisByteHashMap;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
|
||||
import static redis.clients.jedis.Protocol.toByteArray;
|
||||
|
||||
public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKeyBinaryCommands, AdvancedBinaryJedisCommands, BinaryScriptingCommands {
|
||||
public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
|
||||
MultiKeyBinaryCommands, AdvancedBinaryJedisCommands,
|
||||
BinaryScriptingCommands {
|
||||
protected Client client = null;
|
||||
|
||||
public BinaryJedis(final String host) {
|
||||
@@ -75,18 +83,23 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
/**
|
||||
* Set the string value as value of the key. The string can't be longer than
|
||||
* 1073741824 bytes (1 GB).
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @param nxxx NX|XX, NX -- Only set the key if it does not already exist.
|
||||
* XX -- Only set the key if it already exist.
|
||||
* @param expx EX|PX, expire time units: EX = seconds; PX = milliseconds
|
||||
* @param time expire time in the units of {@param #expx}
|
||||
* @param nxxx
|
||||
* NX|XX, NX -- Only set the key if it does not already exist. XX
|
||||
* -- Only set the key if it already exist.
|
||||
* @param expx
|
||||
* EX|PX, expire time units: EX = seconds; PX = milliseconds
|
||||
* @param time
|
||||
* expire time in the units of {@param #expx}
|
||||
* @return Status code reply
|
||||
*/
|
||||
public String set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final long time) {
|
||||
checkIsInMulti();
|
||||
client.set(key, value, nxxx, expx, time);
|
||||
return client.getStatusCodeReply();
|
||||
public String set(final byte[] key, final byte[] value, final byte[] nxxx,
|
||||
final byte[] expx, final long time) {
|
||||
checkIsInMulti();
|
||||
client.set(key, value, nxxx, expx, time);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,9 +160,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
}
|
||||
|
||||
public Long del(final byte[] key) {
|
||||
checkIsInMulti();
|
||||
client.del(key);
|
||||
return client.getIntegerReply();
|
||||
checkIsInMulti();
|
||||
client.del(key);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1006,7 +1019,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
* @return Multi bulk reply, specifically a list of elements in the
|
||||
* specified range.
|
||||
*/
|
||||
public List<byte[]> lrange(final byte[] key, final long start, final long end) {
|
||||
public List<byte[]> lrange(final byte[] key, final long start,
|
||||
final long end) {
|
||||
checkIsInMulti();
|
||||
client.lrange(key, start, end);
|
||||
return client.getBinaryMultiBulkReply();
|
||||
@@ -1468,11 +1482,11 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
client.srandmember(key);
|
||||
return client.getBinaryBulkReply();
|
||||
}
|
||||
|
||||
|
||||
public List<byte[]> srandmember(final byte[] key, final int count) {
|
||||
checkIsInMulti();
|
||||
client.srandmember(key, count);
|
||||
return client.getBinaryMultiBulkReply();
|
||||
checkIsInMulti();
|
||||
client.srandmember(key, count);
|
||||
return client.getBinaryMultiBulkReply();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1502,7 +1516,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public Long zadd(final byte[] key, final Map<Double, byte[]> scoreMembers) {
|
||||
public Long zadd(final byte[] key, final Map<byte[], Double> scoreMembers) {
|
||||
checkIsInMulti();
|
||||
client.zaddBinary(key, scoreMembers);
|
||||
return client.getIntegerReply();
|
||||
@@ -1685,19 +1699,15 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
public List<Object> multi(final TransactionBlock jedisTransaction) {
|
||||
List<Object> results = null;
|
||||
jedisTransaction.setClient(client);
|
||||
try {
|
||||
client.multi();
|
||||
jedisTransaction.execute();
|
||||
results = jedisTransaction.exec();
|
||||
} catch (Exception ex) {
|
||||
jedisTransaction.discard();
|
||||
}
|
||||
client.multi();
|
||||
jedisTransaction.execute();
|
||||
results = jedisTransaction.exec();
|
||||
return results;
|
||||
}
|
||||
|
||||
protected void checkIsInMulti() {
|
||||
if (client.isInMulti()) {
|
||||
throw new JedisDataException(
|
||||
throw new JedisDataException(
|
||||
"Cannot use Jedis when in Multi. Please use JedisTransaction instead.");
|
||||
}
|
||||
}
|
||||
@@ -1710,6 +1720,11 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
client.disconnect();
|
||||
}
|
||||
|
||||
public void resetState() {
|
||||
client.resetState();
|
||||
client.getAll();
|
||||
}
|
||||
|
||||
public String watch(final byte[]... keys) {
|
||||
client.watch(keys);
|
||||
return client.getStatusCodeReply();
|
||||
@@ -2044,43 +2059,43 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
}
|
||||
|
||||
public List<byte[]> blpop(byte[] arg) {
|
||||
checkIsInMulti();
|
||||
byte[][] args = new byte[1][];
|
||||
args[0] = arg;
|
||||
client.blpop(args);
|
||||
client.setTimeoutInfinite();
|
||||
final List<byte[]> multiBulkReply = client.getBinaryMultiBulkReply();
|
||||
client.rollbackTimeout();
|
||||
return multiBulkReply;
|
||||
checkIsInMulti();
|
||||
byte[][] args = new byte[1][];
|
||||
args[0] = arg;
|
||||
client.blpop(args);
|
||||
client.setTimeoutInfinite();
|
||||
final List<byte[]> multiBulkReply = client.getBinaryMultiBulkReply();
|
||||
client.rollbackTimeout();
|
||||
return multiBulkReply;
|
||||
}
|
||||
|
||||
public List<byte[]> brpop(byte[] arg) {
|
||||
checkIsInMulti();
|
||||
byte[][] args = new byte[1][];
|
||||
args[0] = arg;
|
||||
client.brpop(args);
|
||||
client.setTimeoutInfinite();
|
||||
final List<byte[]> multiBulkReply = client.getBinaryMultiBulkReply();
|
||||
client.rollbackTimeout();
|
||||
return multiBulkReply;
|
||||
checkIsInMulti();
|
||||
byte[][] args = new byte[1][];
|
||||
args[0] = arg;
|
||||
client.brpop(args);
|
||||
client.setTimeoutInfinite();
|
||||
final List<byte[]> multiBulkReply = client.getBinaryMultiBulkReply();
|
||||
client.rollbackTimeout();
|
||||
return multiBulkReply;
|
||||
}
|
||||
|
||||
public List<byte[]> blpop(byte[]... args) {
|
||||
checkIsInMulti();
|
||||
client.blpop(args);
|
||||
client.setTimeoutInfinite();
|
||||
final List<byte[]> multiBulkReply = client.getBinaryMultiBulkReply();
|
||||
client.rollbackTimeout();
|
||||
return multiBulkReply;
|
||||
checkIsInMulti();
|
||||
client.blpop(args);
|
||||
client.setTimeoutInfinite();
|
||||
final List<byte[]> multiBulkReply = client.getBinaryMultiBulkReply();
|
||||
client.rollbackTimeout();
|
||||
return multiBulkReply;
|
||||
}
|
||||
|
||||
public List<byte[]> brpop(byte[]... args) {
|
||||
checkIsInMulti();
|
||||
client.brpop(args);
|
||||
client.setTimeoutInfinite();
|
||||
final List<byte[]> multiBulkReply = client.getBinaryMultiBulkReply();
|
||||
client.rollbackTimeout();
|
||||
return multiBulkReply;
|
||||
checkIsInMulti();
|
||||
client.brpop(args);
|
||||
client.setTimeoutInfinite();
|
||||
final List<byte[]> multiBulkReply = client.getBinaryMultiBulkReply();
|
||||
client.rollbackTimeout();
|
||||
return multiBulkReply;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2126,15 +2141,15 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
}
|
||||
|
||||
public Long zcount(final byte[] key, final double min, final double max) {
|
||||
return zcount(key, toByteArray(min), toByteArray(max));
|
||||
return zcount(key, toByteArray(min), toByteArray(max));
|
||||
}
|
||||
|
||||
|
||||
public Long zcount(final byte[] key, final byte[] min, final byte[] max) {
|
||||
checkIsInMulti();
|
||||
client.zcount(key, min, max);
|
||||
return client.getIntegerReply();
|
||||
checkIsInMulti();
|
||||
client.zcount(key, min, max);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the all the elements in the sorted set at key with a score between
|
||||
* min and max (including elements with score equal to min or max).
|
||||
@@ -2194,7 +2209,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
public Set<byte[]> zrangeByScore(final byte[] key, final double min,
|
||||
final double max) {
|
||||
return zrangeByScore(key, toByteArray(min), toByteArray(max));
|
||||
}
|
||||
}
|
||||
|
||||
public Set<byte[]> zrangeByScore(final byte[] key, final byte[] min,
|
||||
final byte[] max) {
|
||||
@@ -2261,15 +2276,16 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
*/
|
||||
public Set<byte[]> zrangeByScore(final byte[] key, final double min,
|
||||
final double max, final int offset, final int count) {
|
||||
return zrangeByScore(key, toByteArray(min),toByteArray(max),offset, count);
|
||||
return zrangeByScore(key, toByteArray(min), toByteArray(max), offset,
|
||||
count);
|
||||
}
|
||||
|
||||
|
||||
public Set<byte[]> zrangeByScore(final byte[] key, final byte[] min,
|
||||
final byte[] max, final int offset, final int count) {
|
||||
checkIsInMulti();
|
||||
client.zrangeByScore(key, min, max, offset, count);
|
||||
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
|
||||
}
|
||||
final byte[] max, final int offset, final int count) {
|
||||
checkIsInMulti();
|
||||
client.zrangeByScore(key, min, max, offset, count);
|
||||
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the all the elements in the sorted set at key with a score between
|
||||
@@ -2331,14 +2347,14 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
final double min, final double max) {
|
||||
return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max));
|
||||
}
|
||||
|
||||
|
||||
public Set<Tuple> zrangeByScoreWithScores(final byte[] key,
|
||||
final byte[] min, final byte[] max) {
|
||||
checkIsInMulti();
|
||||
client.zrangeByScoreWithScores(key, min, max);
|
||||
Set<Tuple> set = getBinaryTupledSet();
|
||||
return set;
|
||||
}
|
||||
final byte[] min, final byte[] max) {
|
||||
checkIsInMulti();
|
||||
client.zrangeByScoreWithScores(key, min, max);
|
||||
Set<Tuple> set = getBinaryTupledSet();
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the all the elements in the sorted set at key with a score between
|
||||
@@ -2399,17 +2415,18 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
public Set<Tuple> zrangeByScoreWithScores(final byte[] key,
|
||||
final double min, final double max, final int offset,
|
||||
final int count) {
|
||||
return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count);
|
||||
return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max),
|
||||
offset, count);
|
||||
}
|
||||
|
||||
|
||||
public Set<Tuple> zrangeByScoreWithScores(final byte[] key,
|
||||
final byte[] min, final byte[] max, final int offset,
|
||||
final int count) {
|
||||
checkIsInMulti();
|
||||
client.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||
Set<Tuple> set = getBinaryTupledSet();
|
||||
return set;
|
||||
}
|
||||
final byte[] min, final byte[] max, final int offset,
|
||||
final int count) {
|
||||
checkIsInMulti();
|
||||
client.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||
Set<Tuple> set = getBinaryTupledSet();
|
||||
return set;
|
||||
}
|
||||
|
||||
private Set<Tuple> getBinaryTupledSet() {
|
||||
checkIsInMulti();
|
||||
@@ -2437,29 +2454,32 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
|
||||
public Set<byte[]> zrevrangeByScore(final byte[] key, final double max,
|
||||
final double min, final int offset, final int count) {
|
||||
return zrevrangeByScore(key, toByteArray(max), toByteArray(min), offset, count);
|
||||
return zrevrangeByScore(key, toByteArray(max), toByteArray(min),
|
||||
offset, count);
|
||||
}
|
||||
|
||||
|
||||
public Set<byte[]> zrevrangeByScore(final byte[] key, final byte[] max,
|
||||
final byte[] min, final int offset, final int count) {
|
||||
checkIsInMulti();
|
||||
client.zrevrangeByScore(key, max, min, offset, count);
|
||||
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
|
||||
}
|
||||
final byte[] min, final int offset, final int count) {
|
||||
checkIsInMulti();
|
||||
client.zrevrangeByScore(key, max, min, offset, count);
|
||||
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(final byte[] key,
|
||||
final double max, final double min) {
|
||||
return zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min));
|
||||
return zrevrangeByScoreWithScores(key, toByteArray(max),
|
||||
toByteArray(min));
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(final byte[] key,
|
||||
final double max, final double min, final int offset,
|
||||
final int count) {
|
||||
return zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min), offset, count);
|
||||
return zrevrangeByScoreWithScores(key, toByteArray(max),
|
||||
toByteArray(min), offset, count);
|
||||
}
|
||||
|
||||
|
||||
public Set<Tuple> zrevrangeByScoreWithScores(final byte[] key,
|
||||
final byte[] max, final byte[] min) {
|
||||
final byte[] max, final byte[] min) {
|
||||
checkIsInMulti();
|
||||
client.zrevrangeByScoreWithScores(key, max, min);
|
||||
Set<Tuple> set = getBinaryTupledSet();
|
||||
@@ -2473,7 +2493,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
client.zrevrangeByScoreWithScores(key, max, min, offset, count);
|
||||
Set<Tuple> set = getBinaryTupledSet();
|
||||
return set;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all elements in the sorted set at key with rank between start and
|
||||
@@ -2488,7 +2508,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
* operation
|
||||
*
|
||||
*/
|
||||
public Long zremrangeByRank(final byte[] key, final long start, final long end) {
|
||||
public Long zremrangeByRank(final byte[] key, final long start,
|
||||
final long end) {
|
||||
checkIsInMulti();
|
||||
client.zremrangeByRank(key, start, end);
|
||||
return client.getIntegerReply();
|
||||
@@ -2512,13 +2533,13 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
final double end) {
|
||||
return zremrangeByScore(key, toByteArray(start), toByteArray(end));
|
||||
}
|
||||
|
||||
|
||||
public Long zremrangeByScore(final byte[] key, final byte[] start,
|
||||
final byte[] end) {
|
||||
checkIsInMulti();
|
||||
client.zremrangeByScore(key, start, end);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
final byte[] end) {
|
||||
checkIsInMulti();
|
||||
client.zremrangeByScore(key, start, end);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a union or intersection of N sorted sets given by keys k1 through
|
||||
@@ -2842,7 +2863,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
client.info();
|
||||
return client.getBulkReply();
|
||||
}
|
||||
|
||||
|
||||
public String info(final String section) {
|
||||
client.info(section);
|
||||
return client.getBulkReply();
|
||||
@@ -3078,8 +3099,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
}
|
||||
|
||||
public Boolean setbit(byte[] key, long offset, byte[] value) {
|
||||
client.setbit(key, offset, value);
|
||||
return client.getIntegerReply() == 1;
|
||||
client.setbit(key, offset, value);
|
||||
return client.getIntegerReply() == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3159,44 +3180,44 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
}
|
||||
|
||||
public Object eval(byte[] script, int keyCount, byte[]... params) {
|
||||
client.setTimeoutInfinite();
|
||||
client.eval(script, SafeEncoder.encode(Integer.toString(keyCount)), params);
|
||||
return client.getOne();
|
||||
client.setTimeoutInfinite();
|
||||
client.eval(script, SafeEncoder.encode(Integer.toString(keyCount)),
|
||||
params);
|
||||
return client.getOne();
|
||||
}
|
||||
|
||||
public Object eval(byte[] script) {
|
||||
client.setTimeoutInfinite();
|
||||
client.eval(script, 0);
|
||||
return client.getOne();
|
||||
client.setTimeoutInfinite();
|
||||
client.eval(script, 0);
|
||||
return client.getOne();
|
||||
}
|
||||
|
||||
public Object evalsha(byte[] sha1) {
|
||||
client.setTimeoutInfinite();
|
||||
client.evalsha(sha1, 0);
|
||||
return client.getOne();
|
||||
client.setTimeoutInfinite();
|
||||
client.evalsha(sha1, 0);
|
||||
return client.getOne();
|
||||
}
|
||||
|
||||
public Object evalsha(byte[] sha1, List<byte[]> keys, List<byte[]> args) {
|
||||
|
||||
int keyCount = keys == null ? 0 : keys.size();
|
||||
int argCount = args == null ? 0 : args.size();
|
||||
public Object evalsha(byte[] sha1, List<byte[]> keys, List<byte[]> args) {
|
||||
|
||||
byte[][] params = new byte[keyCount + argCount][];
|
||||
int keyCount = keys == null ? 0 : keys.size();
|
||||
int argCount = args == null ? 0 : args.size();
|
||||
|
||||
for (int i = 0; i < keyCount; i++)
|
||||
params[i] = keys.get(i);
|
||||
byte[][] params = new byte[keyCount + argCount][];
|
||||
|
||||
for (int i = 0; i < argCount; i++)
|
||||
params[keyCount + i] = args.get(i);
|
||||
for (int i = 0; i < keyCount; i++)
|
||||
params[i] = keys.get(i);
|
||||
|
||||
for (int i = 0; i < argCount; i++)
|
||||
params[keyCount + i] = args.get(i);
|
||||
|
||||
return evalsha(sha1, keyCount, params);
|
||||
}
|
||||
return evalsha(sha1, keyCount, params);
|
||||
}
|
||||
|
||||
public Object evalsha(byte[] sha1, int keyCount, byte[]... params) {
|
||||
client.setTimeoutInfinite();
|
||||
client.evalsha(sha1, keyCount, params);
|
||||
return client.getOne();
|
||||
client.setTimeoutInfinite();
|
||||
client.evalsha(sha1, keyCount, params);
|
||||
return client.getOne();
|
||||
}
|
||||
|
||||
public String scriptFlush() {
|
||||
@@ -3206,7 +3227,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
|
||||
public List<Long> scriptExists(byte[]... sha1) {
|
||||
client.scriptExists(sha1);
|
||||
return client.getIntegerMultiBulkReply();
|
||||
return client.getIntegerMultiBulkReply();
|
||||
}
|
||||
|
||||
public byte[] scriptLoad(byte[] script) {
|
||||
@@ -3238,133 +3259,138 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
client.slowlogGet(entries);
|
||||
return client.getBinaryMultiBulkReply();
|
||||
}
|
||||
|
||||
public Long objectRefcount(byte[] key) {
|
||||
client.objectRefcount(key);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public byte[] objectEncoding(byte[] key) {
|
||||
client.objectEncoding(key);
|
||||
return client.getBinaryBulkReply();
|
||||
}
|
||||
|
||||
public Long objectIdletime(byte[] key) {
|
||||
client.objectIdletime(key);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
public Long objectRefcount(byte[] key) {
|
||||
client.objectRefcount(key);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public byte[] objectEncoding(byte[] key) {
|
||||
client.objectEncoding(key);
|
||||
return client.getBinaryBulkReply();
|
||||
}
|
||||
|
||||
public Long objectIdletime(byte[] key) {
|
||||
client.objectIdletime(key);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public Long bitcount(final byte[] key) {
|
||||
client.bitcount(key);
|
||||
return client.getIntegerReply();
|
||||
client.bitcount(key);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public Long bitcount(final byte[] key, long start, long end) {
|
||||
client.bitcount(key, start, end);
|
||||
return client.getIntegerReply();
|
||||
client.bitcount(key, start, end);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public Long bitop(BitOP op, final byte[] destKey, byte[]... srcKeys) {
|
||||
client.bitop(op, destKey, srcKeys);
|
||||
return client.getIntegerReply();
|
||||
client.bitop(op, destKey, srcKeys);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
|
||||
public byte[] dump(final byte[] key) {
|
||||
checkIsInMulti();
|
||||
client.dump(key);
|
||||
return client.getBinaryBulkReply();
|
||||
checkIsInMulti();
|
||||
client.dump(key);
|
||||
return client.getBinaryBulkReply();
|
||||
}
|
||||
|
||||
public String restore(final byte[] key, final int ttl, final byte[] serializedValue) {
|
||||
checkIsInMulti();
|
||||
client.restore(key, ttl, serializedValue);
|
||||
return client.getStatusCodeReply();
|
||||
|
||||
public String restore(final byte[] key, final int ttl,
|
||||
final byte[] serializedValue) {
|
||||
checkIsInMulti();
|
||||
client.restore(key, ttl, serializedValue);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
|
||||
public Long pexpire(final byte[] key, final int milliseconds) {
|
||||
checkIsInMulti();
|
||||
client.pexpire(key, milliseconds);
|
||||
return client.getIntegerReply();
|
||||
checkIsInMulti();
|
||||
client.pexpire(key, milliseconds);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
|
||||
public Long pexpireAt(final byte[] key, final long millisecondsTimestamp) {
|
||||
checkIsInMulti();
|
||||
client.pexpireAt(key, millisecondsTimestamp);
|
||||
return client.getIntegerReply();
|
||||
checkIsInMulti();
|
||||
client.pexpireAt(key, millisecondsTimestamp);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
|
||||
public Long pttl(final byte[] key) {
|
||||
checkIsInMulti();
|
||||
client.pttl(key);
|
||||
return client.getIntegerReply();
|
||||
checkIsInMulti();
|
||||
client.pttl(key);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
|
||||
public Double incrByFloat(final byte[] key, final double increment) {
|
||||
checkIsInMulti();
|
||||
client.incrByFloat(key, increment);
|
||||
String relpy = client.getBulkReply();
|
||||
return (relpy != null ? new Double(relpy) : null);
|
||||
checkIsInMulti();
|
||||
client.incrByFloat(key, increment);
|
||||
String relpy = client.getBulkReply();
|
||||
return (relpy != null ? new Double(relpy) : null);
|
||||
}
|
||||
|
||||
public String psetex(final byte[] key, final int milliseconds, final byte[] value) {
|
||||
checkIsInMulti();
|
||||
client.psetex(key, milliseconds, value);
|
||||
return client.getStatusCodeReply();
|
||||
|
||||
public String psetex(final byte[] key, final int milliseconds,
|
||||
final byte[] value) {
|
||||
checkIsInMulti();
|
||||
client.psetex(key, milliseconds, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
|
||||
public String set(final byte[] key, final byte[] value, final byte[] nxxx) {
|
||||
checkIsInMulti();
|
||||
client.set(key, value, nxxx);
|
||||
return client.getStatusCodeReply();
|
||||
checkIsInMulti();
|
||||
client.set(key, value, nxxx);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final int time) {
|
||||
checkIsInMulti();
|
||||
client.set(key, value, nxxx, expx, time);
|
||||
return client.getStatusCodeReply();
|
||||
|
||||
public String set(final byte[] key, final byte[] value, final byte[] nxxx,
|
||||
final byte[] expx, final int time) {
|
||||
checkIsInMulti();
|
||||
client.set(key, value, nxxx, expx, time);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
|
||||
public String clientKill(final byte[] client) {
|
||||
checkIsInMulti();
|
||||
this.client.clientKill(client);
|
||||
return this.client.getStatusCodeReply();
|
||||
checkIsInMulti();
|
||||
this.client.clientKill(client);
|
||||
return this.client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
|
||||
public String clientGetname() {
|
||||
checkIsInMulti();
|
||||
client.clientGetname();
|
||||
return client.getBulkReply();
|
||||
checkIsInMulti();
|
||||
client.clientGetname();
|
||||
return client.getBulkReply();
|
||||
}
|
||||
|
||||
|
||||
public String clientList() {
|
||||
checkIsInMulti();
|
||||
client.clientList();
|
||||
return client.getBulkReply();
|
||||
checkIsInMulti();
|
||||
client.clientList();
|
||||
return client.getBulkReply();
|
||||
}
|
||||
|
||||
|
||||
public String clientSetname(final byte[] name) {
|
||||
checkIsInMulti();
|
||||
client.clientSetname(name);
|
||||
return client.getBulkReply();
|
||||
checkIsInMulti();
|
||||
client.clientSetname(name);
|
||||
return client.getBulkReply();
|
||||
}
|
||||
|
||||
|
||||
public List<String> time() {
|
||||
checkIsInMulti();
|
||||
client.time();
|
||||
return client.getMultiBulkReply();
|
||||
checkIsInMulti();
|
||||
client.time();
|
||||
return client.getMultiBulkReply();
|
||||
}
|
||||
|
||||
public String migrate(final byte[] host, final int port, final byte[] key, final int destinationDb, final int timeout) {
|
||||
checkIsInMulti();
|
||||
client.migrate(host, port, key, destinationDb, timeout);
|
||||
return client.getStatusCodeReply();
|
||||
|
||||
public String migrate(final byte[] host, final int port, final byte[] key,
|
||||
final int destinationDb, final int timeout) {
|
||||
checkIsInMulti();
|
||||
client.migrate(host, port, key, destinationDb, timeout);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public Double hincrByFloat(final byte[] key, final byte[] field, double increment) {
|
||||
checkIsInMulti();
|
||||
client.hincrByFloat(key, field, increment);
|
||||
String relpy = client.getBulkReply();
|
||||
return (relpy != null ? new Double(relpy) : null);
|
||||
|
||||
public Double hincrByFloat(final byte[] key, final byte[] field,
|
||||
double increment) {
|
||||
checkIsInMulti();
|
||||
client.hincrByFloat(key, field, increment);
|
||||
String relpy = client.getBulkReply();
|
||||
return (relpy != null ? new Double(relpy) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3375,9 +3401,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
* so I had to change the name of the method. Sorry :S
|
||||
*/
|
||||
public Long waitReplicas(int replicas, long timeout) {
|
||||
checkIsInMulti();
|
||||
client.waitReplicas(replicas, timeout);
|
||||
return client.getIntegerReply();
|
||||
checkIsInMulti();
|
||||
client.waitReplicas(replicas, timeout);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public interface BinaryJedisCommands {
|
||||
|
||||
Long zadd(byte[] key, double score, byte[] member);
|
||||
|
||||
Long zadd(byte[] key, Map<Double, byte[]> scoreMembers);
|
||||
Long zadd(byte[] key, Map<byte[], Double> scoreMembers);
|
||||
|
||||
Set<byte[]> zrange(byte[] key, long start, long end);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public abstract class BinaryJedisPubSub {
|
||||
public abstract void onMessage(byte[] channel, byte[] message);
|
||||
|
||||
public abstract void onPMessage(byte[] pattern, byte[] channel,
|
||||
byte[] message);
|
||||
byte[] message);
|
||||
|
||||
public abstract void onSubscribe(byte[] channel, int subscribedChannels);
|
||||
|
||||
@@ -30,91 +30,91 @@ public abstract class BinaryJedisPubSub {
|
||||
public abstract void onPSubscribe(byte[] pattern, int subscribedChannels);
|
||||
|
||||
public void unsubscribe() {
|
||||
client.unsubscribe();
|
||||
client.flush();
|
||||
client.unsubscribe();
|
||||
client.flush();
|
||||
}
|
||||
|
||||
public void unsubscribe(byte[]... channels) {
|
||||
client.unsubscribe(channels);
|
||||
client.flush();
|
||||
client.unsubscribe(channels);
|
||||
client.flush();
|
||||
}
|
||||
|
||||
public void subscribe(byte[]... channels) {
|
||||
client.subscribe(channels);
|
||||
client.flush();
|
||||
client.subscribe(channels);
|
||||
client.flush();
|
||||
}
|
||||
|
||||
public void psubscribe(byte[]... patterns) {
|
||||
client.psubscribe(patterns);
|
||||
client.flush();
|
||||
client.psubscribe(patterns);
|
||||
client.flush();
|
||||
}
|
||||
|
||||
public void punsubscribe() {
|
||||
client.punsubscribe();
|
||||
client.flush();
|
||||
client.punsubscribe();
|
||||
client.flush();
|
||||
}
|
||||
|
||||
public void punsubscribe(byte[]... patterns) {
|
||||
client.punsubscribe(patterns);
|
||||
client.flush();
|
||||
client.punsubscribe(patterns);
|
||||
client.flush();
|
||||
}
|
||||
|
||||
public boolean isSubscribed() {
|
||||
return subscribedChannels > 0;
|
||||
return subscribedChannels > 0;
|
||||
}
|
||||
|
||||
public void proceedWithPatterns(Client client, byte[]... patterns) {
|
||||
this.client = client;
|
||||
client.psubscribe(patterns);
|
||||
process(client);
|
||||
this.client = client;
|
||||
client.psubscribe(patterns);
|
||||
process(client);
|
||||
}
|
||||
|
||||
public void proceed(Client client, byte[]... channels) {
|
||||
this.client = client;
|
||||
client.subscribe(channels);
|
||||
process(client);
|
||||
this.client = client;
|
||||
client.subscribe(channels);
|
||||
process(client);
|
||||
}
|
||||
|
||||
private void process(Client client) {
|
||||
do {
|
||||
List<Object> reply = client.getObjectMultiBulkReply();
|
||||
final Object firstObj = reply.get(0);
|
||||
if (!(firstObj instanceof byte[])) {
|
||||
throw new JedisException("Unknown message type: " + firstObj);
|
||||
}
|
||||
final byte[] resp = (byte[]) firstObj;
|
||||
if (Arrays.equals(SUBSCRIBE.raw, resp)) {
|
||||
subscribedChannels = ((Long) reply.get(2)).intValue();
|
||||
final byte[] bchannel = (byte[]) reply.get(1);
|
||||
onSubscribe(bchannel, subscribedChannels);
|
||||
} else if (Arrays.equals(UNSUBSCRIBE.raw, resp)) {
|
||||
subscribedChannels = ((Long) reply.get(2)).intValue();
|
||||
final byte[] bchannel = (byte[]) reply.get(1);
|
||||
onUnsubscribe(bchannel, subscribedChannels);
|
||||
} else if (Arrays.equals(MESSAGE.raw, resp)) {
|
||||
final byte[] bchannel = (byte[]) reply.get(1);
|
||||
final byte[] bmesg = (byte[]) reply.get(2);
|
||||
onMessage(bchannel, bmesg);
|
||||
} else if (Arrays.equals(PMESSAGE.raw, resp)) {
|
||||
final byte[] bpattern = (byte[]) reply.get(1);
|
||||
final byte[] bchannel = (byte[]) reply.get(2);
|
||||
final byte[] bmesg = (byte[]) reply.get(3);
|
||||
onPMessage(bpattern, bchannel, bmesg);
|
||||
} else if (Arrays.equals(PSUBSCRIBE.raw, resp)) {
|
||||
subscribedChannels = ((Long) reply.get(2)).intValue();
|
||||
final byte[] bpattern = (byte[]) reply.get(1);
|
||||
onPSubscribe(bpattern, subscribedChannels);
|
||||
} else if (Arrays.equals(PUNSUBSCRIBE.raw, resp)) {
|
||||
subscribedChannels = ((Long) reply.get(2)).intValue();
|
||||
final byte[] bpattern = (byte[]) reply.get(1);
|
||||
onPUnsubscribe(bpattern, subscribedChannels);
|
||||
} else {
|
||||
throw new JedisException("Unknown message type: " + firstObj);
|
||||
}
|
||||
} while (isSubscribed());
|
||||
do {
|
||||
List<Object> reply = client.getObjectMultiBulkReply();
|
||||
final Object firstObj = reply.get(0);
|
||||
if (!(firstObj instanceof byte[])) {
|
||||
throw new JedisException("Unknown message type: " + firstObj);
|
||||
}
|
||||
final byte[] resp = (byte[]) firstObj;
|
||||
if (Arrays.equals(SUBSCRIBE.raw, resp)) {
|
||||
subscribedChannels = ((Long) reply.get(2)).intValue();
|
||||
final byte[] bchannel = (byte[]) reply.get(1);
|
||||
onSubscribe(bchannel, subscribedChannels);
|
||||
} else if (Arrays.equals(UNSUBSCRIBE.raw, resp)) {
|
||||
subscribedChannels = ((Long) reply.get(2)).intValue();
|
||||
final byte[] bchannel = (byte[]) reply.get(1);
|
||||
onUnsubscribe(bchannel, subscribedChannels);
|
||||
} else if (Arrays.equals(MESSAGE.raw, resp)) {
|
||||
final byte[] bchannel = (byte[]) reply.get(1);
|
||||
final byte[] bmesg = (byte[]) reply.get(2);
|
||||
onMessage(bchannel, bmesg);
|
||||
} else if (Arrays.equals(PMESSAGE.raw, resp)) {
|
||||
final byte[] bpattern = (byte[]) reply.get(1);
|
||||
final byte[] bchannel = (byte[]) reply.get(2);
|
||||
final byte[] bmesg = (byte[]) reply.get(3);
|
||||
onPMessage(bpattern, bchannel, bmesg);
|
||||
} else if (Arrays.equals(PSUBSCRIBE.raw, resp)) {
|
||||
subscribedChannels = ((Long) reply.get(2)).intValue();
|
||||
final byte[] bpattern = (byte[]) reply.get(1);
|
||||
onPSubscribe(bpattern, subscribedChannels);
|
||||
} else if (Arrays.equals(PUNSUBSCRIBE.raw, resp)) {
|
||||
subscribedChannels = ((Long) reply.get(2)).intValue();
|
||||
final byte[] bpattern = (byte[]) reply.get(1);
|
||||
onPUnsubscribe(bpattern, subscribedChannels);
|
||||
} else {
|
||||
throw new JedisException("Unknown message type: " + firstObj);
|
||||
}
|
||||
} while (isSubscribed());
|
||||
}
|
||||
|
||||
public int getSubscribedChannels() {
|
||||
return subscribedChannels;
|
||||
return subscribedChannels;
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public interface BinaryRedisPipeline {
|
||||
Response<byte[]> lindex(byte[] key, long index);
|
||||
|
||||
Response<Long> linsert(byte[] key, BinaryClient.LIST_POSITION where,
|
||||
byte[] pivot, byte[] value);
|
||||
byte[] pivot, byte[] value);
|
||||
|
||||
Response<Long> llen(byte[] key);
|
||||
|
||||
@@ -117,8 +117,7 @@ public interface BinaryRedisPipeline {
|
||||
|
||||
Response<List<byte[]>> sort(byte[] key);
|
||||
|
||||
Response<List<byte[]>> sort(byte[] key,
|
||||
SortingParams sortingParameters);
|
||||
Response<List<byte[]>> sort(byte[] key, SortingParams sortingParameters);
|
||||
|
||||
Response<byte[]> spop(byte[] key);
|
||||
|
||||
@@ -144,53 +143,49 @@ public interface BinaryRedisPipeline {
|
||||
|
||||
Response<Set<byte[]>> zrange(byte[] key, long start, long end);
|
||||
|
||||
Response<Set<byte[]>> zrangeByScore(byte[] key, double min,
|
||||
double max);
|
||||
Response<Set<byte[]>> zrangeByScore(byte[] key, double min, double max);
|
||||
|
||||
Response<Set<byte[]>> zrangeByScore(byte[] key, byte[] min,
|
||||
byte[] max);
|
||||
Response<Set<byte[]>> zrangeByScore(byte[] key, byte[] min, byte[] max);
|
||||
|
||||
Response<Set<byte[]>> zrangeByScore(byte[] key, double min,
|
||||
double max, int offset, int count);
|
||||
Response<Set<byte[]>> zrangeByScore(byte[] key, double min, double max,
|
||||
int offset, int count);
|
||||
|
||||
Response<Set<byte[]>> zrangeByScore(byte[] key, byte[] min,
|
||||
byte[] max, int offset, int count);
|
||||
Response<Set<byte[]>> zrangeByScore(byte[] key, byte[] min, byte[] max,
|
||||
int offset, int count);
|
||||
|
||||
Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, double min,
|
||||
double max);
|
||||
double max);
|
||||
|
||||
Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, byte[] min,
|
||||
byte[] max);
|
||||
byte[] max);
|
||||
|
||||
Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, double min,
|
||||
double max, int offset, int count);
|
||||
double max, int offset, int count);
|
||||
|
||||
Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, byte[] min,
|
||||
byte[] max, int offset, int count);
|
||||
byte[] max, int offset, int count);
|
||||
|
||||
Response<Set<byte[]>> zrevrangeByScore(byte[] key, double max,
|
||||
double min);
|
||||
Response<Set<byte[]>> zrevrangeByScore(byte[] key, double max, double min);
|
||||
|
||||
Response<Set<byte[]>> zrevrangeByScore(byte[] key, byte[] max,
|
||||
byte[] min);
|
||||
Response<Set<byte[]>> zrevrangeByScore(byte[] key, byte[] max, byte[] min);
|
||||
|
||||
Response<Set<byte[]>> zrevrangeByScore(byte[] key, double max,
|
||||
double min, int offset, int count);
|
||||
Response<Set<byte[]>> zrevrangeByScore(byte[] key, double max, double min,
|
||||
int offset, int count);
|
||||
|
||||
Response<Set<byte[]>> zrevrangeByScore(byte[] key, byte[] max,
|
||||
byte[] min, int offset, int count);
|
||||
Response<Set<byte[]>> zrevrangeByScore(byte[] key, byte[] max, byte[] min,
|
||||
int offset, int count);
|
||||
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key,
|
||||
double max, double min);
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key, double max,
|
||||
double min);
|
||||
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key,
|
||||
byte[] max, byte[] min);
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key, byte[] max,
|
||||
byte[] min);
|
||||
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key,
|
||||
double max, double min, int offset, int count);
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key, double max,
|
||||
double min, int offset, int count);
|
||||
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key,
|
||||
byte[] max, byte[] min, int offset, int count);
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key, byte[] max,
|
||||
byte[] min, int offset, int count);
|
||||
|
||||
Response<Set<Tuple>> zrangeWithScores(byte[] key, long start, long end);
|
||||
|
||||
@@ -206,8 +201,7 @@ public interface BinaryRedisPipeline {
|
||||
|
||||
Response<Set<byte[]>> zrevrange(byte[] key, long start, long end);
|
||||
|
||||
Response<Set<Tuple>> zrevrangeWithScores(byte[] key, long start,
|
||||
long end);
|
||||
Response<Set<Tuple>> zrevrangeWithScores(byte[] key, long start, long end);
|
||||
|
||||
Response<Long> zrevrank(byte[] key, byte[] member);
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BinaryScriptingCommands {
|
||||
@@ -8,7 +7,7 @@ public interface BinaryScriptingCommands {
|
||||
Object eval(byte[] script, byte[] keyCount, byte[]... params);
|
||||
|
||||
Object eval(byte[] script, int keyCount, byte[]... params);
|
||||
|
||||
|
||||
Object eval(byte[] script, List<byte[]> keys, List<byte[]> args);
|
||||
|
||||
Object eval(byte[] script);
|
||||
|
||||
@@ -295,7 +295,7 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
|
||||
return j.zadd(key, score, member);
|
||||
}
|
||||
|
||||
public Long zadd(byte[] key, Map<Double, byte[]> scoreMembers) {
|
||||
public Long zadd(byte[] key, Map<byte[], Double> scoreMembers) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zadd(key, scoreMembers);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
public enum BitOP {
|
||||
AND,
|
||||
OR,
|
||||
XOR,
|
||||
NOT;
|
||||
AND, OR, XOR, NOT;
|
||||
}
|
||||
|
||||
@@ -1,249 +1,257 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class BuilderFactory {
|
||||
public static final Builder<Double> DOUBLE = new Builder<Double>() {
|
||||
public Double build(Object data) {
|
||||
String asString = STRING.build(data);
|
||||
return asString == null ? null : Double.valueOf(asString);
|
||||
}
|
||||
public Double build(Object data) {
|
||||
String asString = STRING.build(data);
|
||||
return asString == null ? null : Double.valueOf(asString);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "double";
|
||||
}
|
||||
public String toString() {
|
||||
return "double";
|
||||
}
|
||||
};
|
||||
public static final Builder<Boolean> BOOLEAN = new Builder<Boolean>() {
|
||||
public Boolean build(Object data) {
|
||||
return ((Long) data) == 1;
|
||||
}
|
||||
public Boolean build(Object data) {
|
||||
return ((Long) data) == 1;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "boolean";
|
||||
}
|
||||
public String toString() {
|
||||
return "boolean";
|
||||
}
|
||||
};
|
||||
public static final Builder<byte[]> BYTE_ARRAY = new Builder<byte[]>() {
|
||||
public byte[] build(Object data) {
|
||||
return ((byte[]) data); // deleted == 1
|
||||
}
|
||||
public byte[] build(Object data) {
|
||||
return ((byte[]) data); // deleted == 1
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "byte[]";
|
||||
}
|
||||
public String toString() {
|
||||
return "byte[]";
|
||||
}
|
||||
};
|
||||
|
||||
public static final Builder<Long> LONG = new Builder<Long>() {
|
||||
public Long build(Object data) {
|
||||
return (Long) data;
|
||||
}
|
||||
public Long build(Object data) {
|
||||
return (Long) data;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "long";
|
||||
}
|
||||
public String toString() {
|
||||
return "long";
|
||||
}
|
||||
|
||||
};
|
||||
public static final Builder<String> STRING = new Builder<String>() {
|
||||
public String build(Object data) {
|
||||
return data == null ? null : SafeEncoder.encode((byte[]) data);
|
||||
}
|
||||
public String build(Object data) {
|
||||
return data == null ? null : SafeEncoder.encode((byte[]) data);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "string";
|
||||
}
|
||||
public String toString() {
|
||||
return "string";
|
||||
}
|
||||
|
||||
};
|
||||
public static final Builder<List<String>> STRING_LIST = new Builder<List<String>>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<String> build(Object data) {
|
||||
if (null == data) {
|
||||
return null;
|
||||
}
|
||||
List<byte[]> l = (List<byte[]>) data;
|
||||
final ArrayList<String> result = new ArrayList<String>(l.size());
|
||||
for (final byte[] barray : l) {
|
||||
if (barray == null) {
|
||||
result.add(null);
|
||||
} else {
|
||||
result.add(SafeEncoder.encode(barray));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<String> build(Object data) {
|
||||
if (null == data) {
|
||||
return null;
|
||||
}
|
||||
List<byte[]> l = (List<byte[]>) data;
|
||||
final ArrayList<String> result = new ArrayList<String>(l.size());
|
||||
for (final byte[] barray : l) {
|
||||
if (barray == null) {
|
||||
result.add(null);
|
||||
} else {
|
||||
result.add(SafeEncoder.encode(barray));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "List<String>";
|
||||
}
|
||||
public String toString() {
|
||||
return "List<String>";
|
||||
}
|
||||
|
||||
};
|
||||
public static final Builder<Map<String, String>> STRING_MAP = new Builder<Map<String, String>>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, String> build(Object data) {
|
||||
final List<byte[]> flatHash = (List<byte[]>) data;
|
||||
final Map<String, String> hash = new HashMap<String, String>();
|
||||
final Iterator<byte[]> iterator = flatHash.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
hash.put(SafeEncoder.encode(iterator.next()), SafeEncoder
|
||||
.encode(iterator.next()));
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, String> build(Object data) {
|
||||
final List<byte[]> flatHash = (List<byte[]>) data;
|
||||
final Map<String, String> hash = new HashMap<String, String>();
|
||||
final Iterator<byte[]> iterator = flatHash.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
hash.put(SafeEncoder.encode(iterator.next()),
|
||||
SafeEncoder.encode(iterator.next()));
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Map<String, String>";
|
||||
}
|
||||
public String toString() {
|
||||
return "Map<String, String>";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public static final Builder<Set<String>> STRING_SET = new Builder<Set<String>>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set<String> build(Object data) {
|
||||
if (null == data) {
|
||||
return null;
|
||||
}
|
||||
List<byte[]> l = (List<byte[]>) data;
|
||||
final Set<String> result = new HashSet<String>(l.size());
|
||||
for (final byte[] barray : l) {
|
||||
if (barray == null) {
|
||||
result.add(null);
|
||||
} else {
|
||||
result.add(SafeEncoder.encode(barray));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set<String> build(Object data) {
|
||||
if (null == data) {
|
||||
return null;
|
||||
}
|
||||
List<byte[]> l = (List<byte[]>) data;
|
||||
final Set<String> result = new HashSet<String>(l.size());
|
||||
for (final byte[] barray : l) {
|
||||
if (barray == null) {
|
||||
result.add(null);
|
||||
} else {
|
||||
result.add(SafeEncoder.encode(barray));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Set<String>";
|
||||
}
|
||||
public String toString() {
|
||||
return "Set<String>";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public static final Builder<List<byte[]>> BYTE_ARRAY_LIST = new Builder<List<byte[]>>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<byte[]> build(Object data) {
|
||||
if (null == data) {
|
||||
return null;
|
||||
}
|
||||
List<byte[]> l = (List<byte[]>) data;
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<byte[]> build(Object data) {
|
||||
if (null == data) {
|
||||
return null;
|
||||
}
|
||||
List<byte[]> l = (List<byte[]>) data;
|
||||
|
||||
return l;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "List<byte[]>";
|
||||
}
|
||||
public String toString() {
|
||||
return "List<byte[]>";
|
||||
}
|
||||
};
|
||||
|
||||
public static final Builder<Set<byte[]>> BYTE_ARRAY_ZSET = new Builder<Set<byte[]>>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set<byte[]> build(Object data) {
|
||||
if (null == data) {
|
||||
return null;
|
||||
}
|
||||
List<byte[]> l = (List<byte[]>) data;
|
||||
final Set<byte[]> result = new LinkedHashSet<byte[]>(l);
|
||||
for (final byte[] barray : l) {
|
||||
if (barray == null) {
|
||||
result.add(null);
|
||||
} else {
|
||||
result.add(barray);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set<byte[]> build(Object data) {
|
||||
if (null == data) {
|
||||
return null;
|
||||
}
|
||||
List<byte[]> l = (List<byte[]>) data;
|
||||
final Set<byte[]> result = new LinkedHashSet<byte[]>(l);
|
||||
for (final byte[] barray : l) {
|
||||
if (barray == null) {
|
||||
result.add(null);
|
||||
} else {
|
||||
result.add(barray);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ZSet<byte[]>";
|
||||
}
|
||||
public String toString() {
|
||||
return "ZSet<byte[]>";
|
||||
}
|
||||
};
|
||||
public static final Builder<Map<byte[], byte[]>> BYTE_ARRAY_MAP = new Builder<Map<byte[], byte[]>>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<byte[], byte[]> build(Object data) {
|
||||
final List<byte[]> flatHash = (List<byte[]>) data;
|
||||
final Map<byte[], byte[]> hash = new HashMap<byte[], byte[]>();
|
||||
final Iterator<byte[]> iterator = flatHash.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
hash.put(iterator.next(), iterator.next());
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<byte[], byte[]> build(Object data) {
|
||||
final List<byte[]> flatHash = (List<byte[]>) data;
|
||||
final Map<byte[], byte[]> hash = new HashMap<byte[], byte[]>();
|
||||
final Iterator<byte[]> iterator = flatHash.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
hash.put(iterator.next(), iterator.next());
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Map<byte[], byte[]>";
|
||||
}
|
||||
public String toString() {
|
||||
return "Map<byte[], byte[]>";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public static final Builder<Set<String>> STRING_ZSET = new Builder<Set<String>>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set<String> build(Object data) {
|
||||
if (null == data) {
|
||||
return null;
|
||||
}
|
||||
List<byte[]> l = (List<byte[]>) data;
|
||||
final Set<String> result = new LinkedHashSet<String>(l.size());
|
||||
for (final byte[] barray : l) {
|
||||
if (barray == null) {
|
||||
result.add(null);
|
||||
} else {
|
||||
result.add(SafeEncoder.encode(barray));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set<String> build(Object data) {
|
||||
if (null == data) {
|
||||
return null;
|
||||
}
|
||||
List<byte[]> l = (List<byte[]>) data;
|
||||
final Set<String> result = new LinkedHashSet<String>(l.size());
|
||||
for (final byte[] barray : l) {
|
||||
if (barray == null) {
|
||||
result.add(null);
|
||||
} else {
|
||||
result.add(SafeEncoder.encode(barray));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ZSet<String>";
|
||||
}
|
||||
public String toString() {
|
||||
return "ZSet<String>";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public static final Builder<Set<Tuple>> TUPLE_ZSET = new Builder<Set<Tuple>>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set<Tuple> build(Object data) {
|
||||
if (null == data) {
|
||||
return null;
|
||||
}
|
||||
List<byte[]> l = (List<byte[]>) data;
|
||||
final Set<Tuple> result = new LinkedHashSet<Tuple>(l.size());
|
||||
Iterator<byte[]> iterator = l.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
result.add(new Tuple(SafeEncoder.encode(iterator.next()),
|
||||
Double.valueOf(SafeEncoder.encode(iterator.next()))));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set<Tuple> build(Object data) {
|
||||
if (null == data) {
|
||||
return null;
|
||||
}
|
||||
List<byte[]> l = (List<byte[]>) data;
|
||||
final Set<Tuple> result = new LinkedHashSet<Tuple>(l.size());
|
||||
Iterator<byte[]> iterator = l.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
result.add(new Tuple(SafeEncoder.encode(iterator.next()),
|
||||
Double.valueOf(SafeEncoder.encode(iterator.next()))));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ZSet<Tuple>";
|
||||
}
|
||||
public String toString() {
|
||||
return "ZSet<Tuple>";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public static final Builder<Set<Tuple>> TUPLE_ZSET_BINARY = new Builder<Set<Tuple>>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set<Tuple> build(Object data) {
|
||||
if (null == data) {
|
||||
return null;
|
||||
}
|
||||
List<byte[]> l = (List<byte[]>) data;
|
||||
final Set<Tuple> result = new LinkedHashSet<Tuple>(l.size());
|
||||
Iterator<byte[]> iterator = l.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
result.add(new Tuple(iterator.next(), Double
|
||||
.valueOf(SafeEncoder.encode(iterator.next()))));
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set<Tuple> build(Object data) {
|
||||
if (null == data) {
|
||||
return null;
|
||||
}
|
||||
List<byte[]> l = (List<byte[]>) data;
|
||||
final Set<Tuple> result = new LinkedHashSet<Tuple>(l.size());
|
||||
Iterator<byte[]> iterator = l.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
result.add(new Tuple(iterator.next(), Double
|
||||
.valueOf(SafeEncoder.encode(iterator.next()))));
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ZSet<Tuple>";
|
||||
}
|
||||
public String toString() {
|
||||
return "ZSet<Tuple>";
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import redis.clients.util.SafeEncoder;
|
||||
import static redis.clients.jedis.Protocol.toByteArray;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -8,8 +8,7 @@ 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.HSCAN;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
public class Client extends BinaryClient implements Commands {
|
||||
public Client(final String host) {
|
||||
@@ -24,8 +23,10 @@ public class Client extends BinaryClient implements Commands {
|
||||
set(SafeEncoder.encode(key), SafeEncoder.encode(value));
|
||||
}
|
||||
|
||||
public void set(final String key, final String value, final String nxxx, final String expx, final long time) {
|
||||
set(SafeEncoder.encode(key), SafeEncoder.encode(value), SafeEncoder.encode(nxxx), SafeEncoder.encode(expx), time);
|
||||
public void set(final String key, final String value, final String nxxx,
|
||||
final String expx, final long time) {
|
||||
set(SafeEncoder.encode(key), SafeEncoder.encode(value),
|
||||
SafeEncoder.encode(nxxx), SafeEncoder.encode(expx), time);
|
||||
}
|
||||
|
||||
public void get(final String key) {
|
||||
@@ -392,14 +393,14 @@ public class Client extends BinaryClient implements Commands {
|
||||
}
|
||||
blpop(bargs);
|
||||
}
|
||||
|
||||
|
||||
public void blpop(final int timeout, final String... keys) {
|
||||
List<String> args = new ArrayList<String>();
|
||||
for (String arg : keys) {
|
||||
args.add(arg);
|
||||
}
|
||||
args.add(String.valueOf(timeout));
|
||||
blpop(args.toArray(new String[args.size()]));
|
||||
List<String> args = new ArrayList<String>();
|
||||
for (String arg : keys) {
|
||||
args.add(arg);
|
||||
}
|
||||
args.add(String.valueOf(timeout));
|
||||
blpop(args.toArray(new String[args.size()]));
|
||||
}
|
||||
|
||||
public void sort(final String key, final SortingParams sortingParameters,
|
||||
@@ -419,14 +420,14 @@ public class Client extends BinaryClient implements Commands {
|
||||
}
|
||||
brpop(bargs);
|
||||
}
|
||||
|
||||
|
||||
public void brpop(final int timeout, final String... keys) {
|
||||
List<String> args = new ArrayList<String>();
|
||||
for (String arg : keys) {
|
||||
args.add(arg);
|
||||
}
|
||||
args.add(String.valueOf(timeout));
|
||||
brpop(args.toArray(new String[args.size()]));
|
||||
List<String> args = new ArrayList<String>();
|
||||
for (String arg : keys) {
|
||||
args.add(arg);
|
||||
}
|
||||
args.add(String.valueOf(timeout));
|
||||
brpop(args.toArray(new String[args.size()]));
|
||||
}
|
||||
|
||||
public void zcount(final String key, final double min, final double max) {
|
||||
@@ -621,7 +622,7 @@ public class Client extends BinaryClient implements Commands {
|
||||
}
|
||||
|
||||
public void setbit(final String key, final long offset, final String value) {
|
||||
setbit(SafeEncoder.encode(key), offset, SafeEncoder.encode(value));
|
||||
setbit(SafeEncoder.encode(key), offset, SafeEncoder.encode(value));
|
||||
}
|
||||
|
||||
public void getbit(String key, long offset) {
|
||||
@@ -671,6 +672,18 @@ public class Client extends BinaryClient implements Commands {
|
||||
}
|
||||
subscribe(cs);
|
||||
}
|
||||
|
||||
public void pubsubChannels(String pattern) {
|
||||
pubsub(Protocol.PUBSUB_CHANNELS, pattern);
|
||||
}
|
||||
|
||||
public void pubsubNumPat() {
|
||||
pubsub(Protocol.PUBSUB_NUM_PAT);
|
||||
}
|
||||
|
||||
public void pubsubNumSub(String... channels) {
|
||||
pubsub(Protocol.PUBSUB_NUMSUB, channels);
|
||||
}
|
||||
|
||||
public void configSet(String parameter, String value) {
|
||||
configSet(SafeEncoder.encode(parameter), SafeEncoder.encode(value));
|
||||
@@ -710,12 +723,14 @@ public class Client extends BinaryClient implements Commands {
|
||||
scriptLoad(SafeEncoder.encode(script));
|
||||
}
|
||||
|
||||
public void zadd(String key, Map<Double, String> scoreMembers) {
|
||||
HashMap<Double, byte[]> binaryScoreMembers = new HashMap<Double, byte[]>();
|
||||
public void zadd(String key, Map<String, Double> scoreMembers) {
|
||||
|
||||
for (Map.Entry<Double, String> entry : scoreMembers.entrySet()) {
|
||||
binaryScoreMembers.put(entry.getKey(),
|
||||
SafeEncoder.encode(entry.getValue()));
|
||||
HashMap<byte[], Double> binaryScoreMembers = new HashMap<byte[], Double>();
|
||||
|
||||
for (Map.Entry<String, Double> entry : scoreMembers.entrySet()) {
|
||||
|
||||
binaryScoreMembers.put(SafeEncoder.encode(entry.getKey()),
|
||||
entry.getValue());
|
||||
}
|
||||
|
||||
zaddBinary(SafeEncoder.encode(key), binaryScoreMembers);
|
||||
@@ -734,15 +749,15 @@ public class Client extends BinaryClient implements Commands {
|
||||
}
|
||||
|
||||
public void bitcount(final String key) {
|
||||
bitcount(SafeEncoder.encode(key));
|
||||
bitcount(SafeEncoder.encode(key));
|
||||
}
|
||||
|
||||
public void bitcount(final String key, long start, long end) {
|
||||
bitcount(SafeEncoder.encode(key), start, end);
|
||||
bitcount(SafeEncoder.encode(key), start, end);
|
||||
}
|
||||
|
||||
public void bitop(BitOP op, final String destKey, String... srcKeys) {
|
||||
bitop(op, SafeEncoder.encode(destKey), getByteParams(srcKeys));
|
||||
bitop(op, SafeEncoder.encode(destKey), getByteParams(srcKeys));
|
||||
}
|
||||
|
||||
public void sentinel(final String... args) {
|
||||
@@ -753,132 +768,153 @@ public class Client extends BinaryClient implements Commands {
|
||||
sentinel(arg);
|
||||
}
|
||||
|
||||
public void dump(final String key) {
|
||||
dump(SafeEncoder.encode(key));
|
||||
public void dump(final String key) {
|
||||
dump(SafeEncoder.encode(key));
|
||||
}
|
||||
|
||||
public void restore(final String key, final int ttl, final byte[] serializedValue) {
|
||||
restore(SafeEncoder.encode(key), ttl, serializedValue);
|
||||
|
||||
public void restore(final String key, final int ttl,
|
||||
final byte[] serializedValue) {
|
||||
restore(SafeEncoder.encode(key), ttl, serializedValue);
|
||||
}
|
||||
|
||||
|
||||
public void pexpire(final String key, final int milliseconds) {
|
||||
pexpire(SafeEncoder.encode(key), milliseconds);
|
||||
pexpire(SafeEncoder.encode(key), milliseconds);
|
||||
}
|
||||
|
||||
|
||||
public void pexpireAt(final String key, final long millisecondsTimestamp) {
|
||||
pexpireAt(SafeEncoder.encode(key), millisecondsTimestamp);
|
||||
pexpireAt(SafeEncoder.encode(key), millisecondsTimestamp);
|
||||
}
|
||||
|
||||
|
||||
public void pttl(final String key) {
|
||||
pttl(SafeEncoder.encode(key));
|
||||
pttl(SafeEncoder.encode(key));
|
||||
}
|
||||
|
||||
|
||||
public void incrByFloat(final String key, final double increment) {
|
||||
incrByFloat(SafeEncoder.encode(key), increment);
|
||||
incrByFloat(SafeEncoder.encode(key), increment);
|
||||
}
|
||||
|
||||
public void psetex(final String key, final int milliseconds, final String value) {
|
||||
psetex(SafeEncoder.encode(key), milliseconds, SafeEncoder.encode(value));
|
||||
|
||||
public void psetex(final String key, final int milliseconds,
|
||||
final String value) {
|
||||
psetex(SafeEncoder.encode(key), milliseconds, SafeEncoder.encode(value));
|
||||
}
|
||||
|
||||
|
||||
public void set(final String key, final String value, final String nxxx) {
|
||||
set(SafeEncoder.encode(key), SafeEncoder.encode(value), SafeEncoder.encode(nxxx));
|
||||
set(SafeEncoder.encode(key), SafeEncoder.encode(value),
|
||||
SafeEncoder.encode(nxxx));
|
||||
}
|
||||
|
||||
public void set(final String key, final String value, final String nxxx, final String expx, final int time) {
|
||||
set(SafeEncoder.encode(key), SafeEncoder.encode(value), SafeEncoder.encode(nxxx), SafeEncoder.encode(expx), time);
|
||||
|
||||
public void set(final String key, final String value, final String nxxx,
|
||||
final String expx, final int time) {
|
||||
set(SafeEncoder.encode(key), SafeEncoder.encode(value),
|
||||
SafeEncoder.encode(nxxx), SafeEncoder.encode(expx), time);
|
||||
}
|
||||
|
||||
|
||||
public void srandmember(final String key, final int count) {
|
||||
srandmember(SafeEncoder.encode(key), count);
|
||||
srandmember(SafeEncoder.encode(key), count);
|
||||
}
|
||||
|
||||
public void clientKill(final String client) {
|
||||
clientKill(SafeEncoder.encode(client));
|
||||
clientKill(SafeEncoder.encode(client));
|
||||
}
|
||||
|
||||
|
||||
public void clientSetname(final String name) {
|
||||
clientSetname(SafeEncoder.encode(name));
|
||||
clientSetname(SafeEncoder.encode(name));
|
||||
}
|
||||
|
||||
public void migrate(final String host, final int port, final String key, final int destinationDb, final int timeout) {
|
||||
migrate(SafeEncoder.encode(host), port, SafeEncoder.encode(key), destinationDb, timeout);
|
||||
|
||||
public void migrate(final String host, final int port, final String key,
|
||||
final int destinationDb, final int timeout) {
|
||||
migrate(SafeEncoder.encode(host), port, SafeEncoder.encode(key),
|
||||
destinationDb, timeout);
|
||||
}
|
||||
|
||||
public void hincrByFloat(final String key, final String field, double increment) {
|
||||
hincrByFloat(SafeEncoder.encode(key), SafeEncoder.encode(field), increment);
|
||||
|
||||
public void hincrByFloat(final String key, final String field,
|
||||
double increment) {
|
||||
hincrByFloat(SafeEncoder.encode(key), SafeEncoder.encode(field),
|
||||
increment);
|
||||
}
|
||||
|
||||
|
||||
public void hscan(final String key, int cursor, final ScanParams params) {
|
||||
hscan(SafeEncoder.encode(key), cursor, params);
|
||||
hscan(SafeEncoder.encode(key), cursor, params);
|
||||
}
|
||||
|
||||
|
||||
public void sscan(final String key, int cursor, final ScanParams params) {
|
||||
sscan(SafeEncoder.encode(key), cursor, params);
|
||||
sscan(SafeEncoder.encode(key), cursor, params);
|
||||
}
|
||||
|
||||
|
||||
public void zscan(final String key, int cursor, final ScanParams params) {
|
||||
zscan(SafeEncoder.encode(key), cursor, params);
|
||||
zscan(SafeEncoder.encode(key), cursor, params);
|
||||
}
|
||||
|
||||
public void cluster(final String subcommand, final int... args) {
|
||||
final byte[][] arg = new byte[args.length+1][];
|
||||
final byte[][] arg = new byte[args.length + 1][];
|
||||
for (int i = 1; i < arg.length; i++) {
|
||||
arg[i] = toByteArray(args[i-1]);
|
||||
}
|
||||
arg[0] = SafeEncoder.encode(subcommand);
|
||||
cluster(arg);
|
||||
}
|
||||
|
||||
public void cluster(final String subcommand, final String... args) {
|
||||
final byte[][] arg = new byte[args.length+1][];
|
||||
for (int i = 1; i < arg.length; i++) {
|
||||
arg[i] = SafeEncoder.encode(args[i-1]);
|
||||
arg[i] = toByteArray(args[i - 1]);
|
||||
}
|
||||
arg[0] = SafeEncoder.encode(subcommand);
|
||||
cluster(arg);
|
||||
}
|
||||
|
||||
public void pubsub(final String subcommand, final String... args) {
|
||||
final byte[][] arg = new byte[args.length+1][];
|
||||
for (int i = 1; i < arg.length; i++) {
|
||||
arg[i] = SafeEncoder.encode(args[i-1]);
|
||||
}
|
||||
arg[0] = SafeEncoder.encode(subcommand);
|
||||
pubsub(arg);
|
||||
}
|
||||
|
||||
public void cluster(final String subcommand, final String... args) {
|
||||
final byte[][] arg = new byte[args.length + 1][];
|
||||
for (int i = 1; i < arg.length; i++) {
|
||||
arg[i] = SafeEncoder.encode(args[i - 1]);
|
||||
}
|
||||
arg[0] = SafeEncoder.encode(subcommand);
|
||||
cluster(arg);
|
||||
}
|
||||
|
||||
public void cluster(final String subcommand) {
|
||||
final byte[][] arg = new byte[1][];
|
||||
arg[0] = SafeEncoder.encode(subcommand);
|
||||
cluster(arg);
|
||||
}
|
||||
|
||||
|
||||
public void clusterNodes() {
|
||||
cluster(Protocol.CLUSTER_NODES);
|
||||
}
|
||||
|
||||
|
||||
public void clusterMeet(final String ip, final int port) {
|
||||
cluster(Protocol.CLUSTER_MEET, ip, String.valueOf(port));
|
||||
}
|
||||
|
||||
public void clusterAddSlots(final int ...slots) {
|
||||
|
||||
public void clusterAddSlots(final int... slots) {
|
||||
cluster(Protocol.CLUSTER_ADDSLOTS, slots);
|
||||
}
|
||||
|
||||
public void clusterDelSlots(final int ...slots) {
|
||||
|
||||
public void clusterDelSlots(final int... slots) {
|
||||
cluster(Protocol.CLUSTER_DELSLOTS, slots);
|
||||
}
|
||||
|
||||
|
||||
public void clusterInfo() {
|
||||
cluster(Protocol.CLUSTER_INFO);
|
||||
}
|
||||
|
||||
|
||||
public void clusterGetKeysInSlot(final int slot, final int count) {
|
||||
final int[] args = new int[]{ slot, count };
|
||||
cluster(Protocol.CLUSTER_GETKEYSINSLOT, args);
|
||||
final int[] args = new int[] { slot, count };
|
||||
cluster(Protocol.CLUSTER_GETKEYSINSLOT, args);
|
||||
}
|
||||
|
||||
|
||||
public void clusterSetSlotNode(final int slot, final String nodeId) {
|
||||
cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot), Protocol.CLUSTER_SETSLOT_NODE, nodeId);
|
||||
cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot),
|
||||
Protocol.CLUSTER_SETSLOT_NODE, nodeId);
|
||||
}
|
||||
|
||||
|
||||
public void clusterSetSlotMigrating(final int slot, final String nodeId) {
|
||||
cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot), Protocol.CLUSTER_SETSLOT_MIGRATING, nodeId);
|
||||
cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot),
|
||||
Protocol.CLUSTER_SETSLOT_MIGRATING, nodeId);
|
||||
}
|
||||
|
||||
|
||||
public void clusterSetSlotImporting(final int slot, final String nodeId) {
|
||||
cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot), Protocol.CLUSTER_SETSLOT_IMPORTING, nodeId);
|
||||
cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot),
|
||||
Protocol.CLUSTER_SETSLOT_IMPORTING, nodeId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ 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 zadd(final String key, final Map<String, Double> scoreMembers);
|
||||
|
||||
public void zrange(final String key, final long start, final long end);
|
||||
|
||||
|
||||
@@ -25,218 +25,230 @@ public class Connection {
|
||||
private int timeout = Protocol.DEFAULT_TIMEOUT;
|
||||
|
||||
public Socket getSocket() {
|
||||
return socket;
|
||||
return socket;
|
||||
}
|
||||
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(final int timeout) {
|
||||
this.timeout = timeout;
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public void setTimeoutInfinite() {
|
||||
try {
|
||||
if(!isConnected()) {
|
||||
connect();
|
||||
}
|
||||
socket.setKeepAlive(true);
|
||||
socket.setSoTimeout(0);
|
||||
} catch (SocketException ex) {
|
||||
throw new JedisException(ex);
|
||||
}
|
||||
try {
|
||||
if (!isConnected()) {
|
||||
connect();
|
||||
}
|
||||
socket.setKeepAlive(true);
|
||||
socket.setSoTimeout(0);
|
||||
} catch (SocketException ex) {
|
||||
throw new JedisException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void rollbackTimeout() {
|
||||
try {
|
||||
socket.setSoTimeout(timeout);
|
||||
socket.setKeepAlive(false);
|
||||
} catch (SocketException ex) {
|
||||
throw new JedisException(ex);
|
||||
}
|
||||
try {
|
||||
socket.setSoTimeout(timeout);
|
||||
socket.setKeepAlive(false);
|
||||
} catch (SocketException ex) {
|
||||
throw new JedisException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public Connection(final String host) {
|
||||
super();
|
||||
this.host = host;
|
||||
super();
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
protected void flush() {
|
||||
try {
|
||||
outputStream.flush();
|
||||
} catch (IOException e) {
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
try {
|
||||
outputStream.flush();
|
||||
} catch (IOException e) {
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected Connection sendCommand(final Command cmd, final String... args) {
|
||||
final byte[][] bargs = new byte[args.length][];
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
bargs[i] = SafeEncoder.encode(args[i]);
|
||||
}
|
||||
return sendCommand(cmd, bargs);
|
||||
final byte[][] bargs = new byte[args.length][];
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
bargs[i] = SafeEncoder.encode(args[i]);
|
||||
}
|
||||
return sendCommand(cmd, bargs);
|
||||
}
|
||||
|
||||
protected Connection sendCommand(final Command cmd, final byte[]... args) {
|
||||
connect();
|
||||
Protocol.sendCommand(outputStream, cmd, args);
|
||||
pipelinedCommands++;
|
||||
return this;
|
||||
connect();
|
||||
Protocol.sendCommand(outputStream, cmd, args);
|
||||
pipelinedCommands++;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
protected Connection sendCommand(final Command cmd) {
|
||||
connect();
|
||||
Protocol.sendCommand(outputStream, cmd, new byte[0][]);
|
||||
pipelinedCommands++;
|
||||
return this;
|
||||
connect();
|
||||
Protocol.sendCommand(outputStream, cmd, new byte[0][]);
|
||||
pipelinedCommands++;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Connection(final String host, final int port) {
|
||||
super();
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
super();
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(final String host) {
|
||||
this.host = host;
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(final int port) {
|
||||
this.port = port;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public Connection() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
if (!isConnected()) {
|
||||
try {
|
||||
socket = new Socket();
|
||||
//->@wjw_add
|
||||
socket.setReuseAddress(true);
|
||||
socket.setKeepAlive(true); //Will monitor the TCP connection is valid
|
||||
socket.setTcpNoDelay(true); //Socket buffer Whetherclosed, to ensure timely delivery of data
|
||||
socket.setSoLinger(true,0); //Control calls close () method, the underlying socket is closed immediately
|
||||
//<-@wjw_add
|
||||
if (!isConnected()) {
|
||||
try {
|
||||
socket = new Socket();
|
||||
// ->@wjw_add
|
||||
socket.setReuseAddress(true);
|
||||
socket.setKeepAlive(true); // Will monitor the TCP connection is
|
||||
// valid
|
||||
socket.setTcpNoDelay(true); // Socket buffer Whetherclosed, to
|
||||
// ensure timely delivery of data
|
||||
socket.setSoLinger(true, 0); // Control calls close () method,
|
||||
// the underlying socket is closed
|
||||
// immediately
|
||||
// <-@wjw_add
|
||||
|
||||
socket.connect(new InetSocketAddress(host, port), timeout);
|
||||
socket.setSoTimeout(timeout);
|
||||
outputStream = new RedisOutputStream(socket.getOutputStream());
|
||||
inputStream = new RedisInputStream(socket.getInputStream());
|
||||
} catch (IOException ex) {
|
||||
throw new JedisConnectionException(ex);
|
||||
}
|
||||
}
|
||||
socket.connect(new InetSocketAddress(host, port), timeout);
|
||||
socket.setSoTimeout(timeout);
|
||||
outputStream = new RedisOutputStream(socket.getOutputStream());
|
||||
inputStream = new RedisInputStream(socket.getInputStream());
|
||||
} catch (IOException ex) {
|
||||
throw new JedisConnectionException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
if (isConnected()) {
|
||||
try {
|
||||
inputStream.close();
|
||||
outputStream.close();
|
||||
if (!socket.isClosed()) {
|
||||
socket.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new JedisConnectionException(ex);
|
||||
}
|
||||
}
|
||||
if (isConnected()) {
|
||||
try {
|
||||
inputStream.close();
|
||||
outputStream.close();
|
||||
if (!socket.isClosed()) {
|
||||
socket.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new JedisConnectionException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return socket != null && socket.isBound() && !socket.isClosed()
|
||||
&& socket.isConnected() && !socket.isInputShutdown()
|
||||
&& !socket.isOutputShutdown();
|
||||
return socket != null && socket.isBound() && !socket.isClosed()
|
||||
&& socket.isConnected() && !socket.isInputShutdown()
|
||||
&& !socket.isOutputShutdown();
|
||||
}
|
||||
|
||||
protected String getStatusCodeReply() {
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
final byte[] resp = (byte[]) Protocol.read(inputStream);
|
||||
if (null == resp) {
|
||||
return null;
|
||||
} else {
|
||||
return SafeEncoder.encode(resp);
|
||||
}
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
final byte[] resp = (byte[]) Protocol.read(inputStream);
|
||||
if (null == resp) {
|
||||
return null;
|
||||
} else {
|
||||
return SafeEncoder.encode(resp);
|
||||
}
|
||||
}
|
||||
|
||||
public String getBulkReply() {
|
||||
final byte[] result = getBinaryBulkReply();
|
||||
if (null != result) {
|
||||
return SafeEncoder.encode(result);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
final byte[] result = getBinaryBulkReply();
|
||||
if (null != result) {
|
||||
return SafeEncoder.encode(result);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getBinaryBulkReply() {
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
return (byte[]) Protocol.read(inputStream);
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
return (byte[]) Protocol.read(inputStream);
|
||||
}
|
||||
|
||||
public Long getIntegerReply() {
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
return (Long) Protocol.read(inputStream);
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
return (Long) Protocol.read(inputStream);
|
||||
}
|
||||
|
||||
public List<String> getMultiBulkReply() {
|
||||
return BuilderFactory.STRING_LIST.build(getBinaryMultiBulkReply());
|
||||
return BuilderFactory.STRING_LIST.build(getBinaryMultiBulkReply());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<byte[]> getBinaryMultiBulkReply() {
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
return (List<byte[]>) Protocol.read(inputStream);
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
return (List<byte[]>) Protocol.read(inputStream);
|
||||
}
|
||||
|
||||
public void resetPipelinedCount() {
|
||||
pipelinedCommands = 0;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Object> getRawObjectMultiBulkReply() {
|
||||
return (List<Object>) Protocol.read(inputStream);
|
||||
}
|
||||
|
||||
public List<Object> getObjectMultiBulkReply() {
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
return (List<Object>) Protocol.read(inputStream);
|
||||
return getRawObjectMultiBulkReply();
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Long> getIntegerMultiBulkReply() {
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
return (List<Long>) Protocol.read(inputStream);
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
return (List<Long>) Protocol.read(inputStream);
|
||||
}
|
||||
|
||||
public List<Object> getAll() {
|
||||
return getAll(0);
|
||||
return getAll(0);
|
||||
}
|
||||
|
||||
public List<Object> getAll(int except) {
|
||||
List<Object> all = new ArrayList<Object>();
|
||||
flush();
|
||||
while (pipelinedCommands > except) {
|
||||
try{
|
||||
all.add(Protocol.read(inputStream));
|
||||
}catch(JedisDataException e){
|
||||
all.add(e);
|
||||
}
|
||||
pipelinedCommands--;
|
||||
}
|
||||
return all;
|
||||
List<Object> all = new ArrayList<Object>();
|
||||
flush();
|
||||
while (pipelinedCommands > except) {
|
||||
try {
|
||||
all.add(Protocol.read(inputStream));
|
||||
} catch (JedisDataException e) {
|
||||
all.add(e);
|
||||
}
|
||||
pipelinedCommands--;
|
||||
}
|
||||
return all;
|
||||
}
|
||||
|
||||
public Object getOne() {
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
return Protocol.read(inputStream);
|
||||
flush();
|
||||
pipelinedCommands--;
|
||||
return Protocol.read(inputStream);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +1,49 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
public class HostAndPort {
|
||||
public static final String LOCALHOST_STR = "localhost";
|
||||
|
||||
private String host;
|
||||
private int port;
|
||||
|
||||
public HostAndPort(String host, int port) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
public static final String LOCALHOST_STR = "localhost";
|
||||
|
||||
private String host;
|
||||
private int port;
|
||||
|
||||
public HostAndPort(String host, int port) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof HostAndPort) {
|
||||
HostAndPort hp = (HostAndPort) obj;
|
||||
|
||||
String thisHost = convertHost(host);
|
||||
String hpHost = convertHost(hp.host);
|
||||
return port == hp.port && thisHost.equals(hpHost);
|
||||
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return host + ":" + port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof HostAndPort) {
|
||||
HostAndPort hp = (HostAndPort) obj;
|
||||
|
||||
String thisHost = convertHost(host);
|
||||
String hpHost = convertHost(hp.host);
|
||||
return port == hp.port &&
|
||||
thisHost.equals(hpHost);
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return host + ":" + port;
|
||||
}
|
||||
|
||||
private String convertHost(String host) {
|
||||
if (host.equals("127.0.0.1"))
|
||||
return LOCALHOST_STR;
|
||||
else if (host.equals("::1"))
|
||||
return LOCALHOST_STR;
|
||||
if (host.equals("127.0.0.1"))
|
||||
return LOCALHOST_STR;
|
||||
else if (host.equals("::1"))
|
||||
return LOCALHOST_STR;
|
||||
|
||||
return host;
|
||||
return host;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
import redis.clients.util.Slowlog;
|
||||
|
||||
public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommands, AdvancedJedisCommands, ScriptingCommands, BasicCommands, ClusterCommands, SentinelCommands {
|
||||
public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
MultiKeyCommands, AdvancedJedisCommands, ScriptingCommands,
|
||||
BasicCommands, ClusterCommands {
|
||||
public Jedis(final String host) {
|
||||
super(host);
|
||||
}
|
||||
@@ -55,24 +57,29 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
/**
|
||||
* Set the string value as value of the key. The string can't be longer than
|
||||
* 1073741824 bytes (1 GB).
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @param nxxx NX|XX, NX -- Only set the key if it does not already exist.
|
||||
* XX -- Only set the key if it already exist.
|
||||
* @param expx EX|PX, expire time units: EX = seconds; PX = milliseconds
|
||||
* @param time expire time in the units of {@param #expx}
|
||||
* @param nxxx
|
||||
* NX|XX, NX -- Only set the key if it does not already exist. XX
|
||||
* -- Only set the key if it already exist.
|
||||
* @param expx
|
||||
* EX|PX, expire time units: EX = seconds; PX = milliseconds
|
||||
* @param time
|
||||
* expire time in the units of {@param #expx}
|
||||
* @return Status code reply
|
||||
*/
|
||||
public String set(final String key, final String value, final String nxxx, final String expx, final long time) {
|
||||
checkIsInMulti();
|
||||
client.set(key, value, nxxx, expx, time);
|
||||
return client.getStatusCodeReply();
|
||||
public String set(final String key, final String value, final String nxxx,
|
||||
final String expx, final long time) {
|
||||
checkIsInMulti();
|
||||
client.set(key, value, nxxx, expx, time);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the specified key. If the key does not exist the special
|
||||
* value 'nil' is returned. If the value stored at key is not a string an
|
||||
* error is returned because GET can only handle string values.
|
||||
* Get the value of the specified key. If the key does not exist null is
|
||||
* returned. If the value stored at key is not a string an error is returned
|
||||
* because GET can only handle string values.
|
||||
* <p>
|
||||
* Time complexity: O(1)
|
||||
*
|
||||
@@ -118,8 +125,8 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
}
|
||||
|
||||
public Long del(String key) {
|
||||
client.del(key);
|
||||
return client.getIntegerReply();
|
||||
client.del(key);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1380,7 +1387,7 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
client.srandmember(key);
|
||||
return client.getBulkReply();
|
||||
}
|
||||
|
||||
|
||||
public List<String> srandmember(final String key, final int count) {
|
||||
checkIsInMulti();
|
||||
client.srandmember(key, count);
|
||||
@@ -1414,7 +1421,7 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public Long zadd(final String key, final Map<Double, String> scoreMembers) {
|
||||
public Long zadd(final String key, final Map<String, Double> scoreMembers) {
|
||||
checkIsInMulti();
|
||||
client.zadd(key, scoreMembers);
|
||||
return client.getIntegerReply();
|
||||
@@ -1788,39 +1795,39 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
}
|
||||
|
||||
public List<String> blpop(String... args) {
|
||||
client.blpop(args);
|
||||
client.setTimeoutInfinite();
|
||||
final List<String> multiBulkReply = client.getMultiBulkReply();
|
||||
client.rollbackTimeout();
|
||||
return multiBulkReply;
|
||||
client.blpop(args);
|
||||
client.setTimeoutInfinite();
|
||||
final List<String> multiBulkReply = client.getMultiBulkReply();
|
||||
client.rollbackTimeout();
|
||||
return multiBulkReply;
|
||||
}
|
||||
|
||||
public List<String> brpop(String... args) {
|
||||
client.brpop(args);
|
||||
client.setTimeoutInfinite();
|
||||
final List<String> multiBulkReply = client.getMultiBulkReply();
|
||||
client.rollbackTimeout();
|
||||
return multiBulkReply;
|
||||
client.brpop(args);
|
||||
client.setTimeoutInfinite();
|
||||
final List<String> multiBulkReply = client.getMultiBulkReply();
|
||||
client.rollbackTimeout();
|
||||
return multiBulkReply;
|
||||
}
|
||||
|
||||
public List<String> blpop(String arg) {
|
||||
String[] args = new String[1];
|
||||
args[0] = arg;
|
||||
client.blpop(args);
|
||||
client.setTimeoutInfinite();
|
||||
final List<String> multiBulkReply = client.getMultiBulkReply();
|
||||
client.rollbackTimeout();
|
||||
return multiBulkReply;
|
||||
String[] args = new String[1];
|
||||
args[0] = arg;
|
||||
client.blpop(args);
|
||||
client.setTimeoutInfinite();
|
||||
final List<String> multiBulkReply = client.getMultiBulkReply();
|
||||
client.rollbackTimeout();
|
||||
return multiBulkReply;
|
||||
}
|
||||
|
||||
public List<String> brpop(String arg) {
|
||||
String[] args = new String[1];
|
||||
args[0] = arg;
|
||||
client.brpop(args);
|
||||
client.setTimeoutInfinite();
|
||||
final List<String> multiBulkReply = client.getMultiBulkReply();
|
||||
client.rollbackTimeout();
|
||||
return multiBulkReply;
|
||||
String[] args = new String[1];
|
||||
args[0] = arg;
|
||||
client.brpop(args);
|
||||
client.setTimeoutInfinite();
|
||||
final List<String> multiBulkReply = client.getMultiBulkReply();
|
||||
client.rollbackTimeout();
|
||||
return multiBulkReply;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1953,8 +1960,6 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
return multiBulkReply;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Long zcount(final String key, final double min, final double max) {
|
||||
checkIsInMulti();
|
||||
client.zcount(key, min, max);
|
||||
@@ -2019,8 +2024,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
* @see #zcount(String, double, double)
|
||||
*
|
||||
* @param key
|
||||
* @param min a double or Double.MIN_VALUE for "-inf"
|
||||
* @param max a double or Double.MAX_VALUE for "+inf"
|
||||
* @param min
|
||||
* a double or Double.MIN_VALUE for "-inf"
|
||||
* @param max
|
||||
* a double or Double.MAX_VALUE for "+inf"
|
||||
* @return Multi bulk reply specifically a list of elements in the specified
|
||||
* score range.
|
||||
*/
|
||||
@@ -2627,8 +2634,8 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
}
|
||||
|
||||
public Boolean setbit(String key, long offset, String value) {
|
||||
client.setbit(key, offset, value);
|
||||
return client.getIntegerReply() == 1;
|
||||
client.setbit(key, offset, value);
|
||||
return client.getIntegerReply() == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2741,26 +2748,26 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
}
|
||||
|
||||
public void subscribe(final JedisPubSub jedisPubSub,
|
||||
final String... channels) {
|
||||
client.setTimeoutInfinite();
|
||||
jedisPubSub.proceed(client, channels);
|
||||
client.rollbackTimeout();
|
||||
final String... channels) {
|
||||
client.setTimeoutInfinite();
|
||||
jedisPubSub.proceed(client, channels);
|
||||
client.rollbackTimeout();
|
||||
}
|
||||
|
||||
public Long publish(final String channel, final String message) {
|
||||
checkIsInMulti();
|
||||
connect();
|
||||
client.publish(channel, message);
|
||||
return client.getIntegerReply();
|
||||
checkIsInMulti();
|
||||
connect();
|
||||
client.publish(channel, message);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public void psubscribe(final JedisPubSub jedisPubSub,
|
||||
final String... patterns) {
|
||||
checkIsInMulti();
|
||||
connect();
|
||||
client.setTimeoutInfinite();
|
||||
jedisPubSub.proceedWithPatterns(client, patterns);
|
||||
client.rollbackTimeout();
|
||||
final String... patterns) {
|
||||
checkIsInMulti();
|
||||
connect();
|
||||
client.setTimeoutInfinite();
|
||||
jedisPubSub.proceedWithPatterns(client, patterns);
|
||||
client.rollbackTimeout();
|
||||
}
|
||||
|
||||
protected static String[] getParams(List<String> keys, List<String> args) {
|
||||
@@ -2792,7 +2799,7 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
|
||||
private Object getEvalResult() {
|
||||
Object result = client.getOne();
|
||||
|
||||
|
||||
if (result instanceof byte[])
|
||||
return SafeEncoder.encode((byte[]) result);
|
||||
|
||||
@@ -2869,18 +2876,18 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
}
|
||||
|
||||
public Long bitcount(final String key) {
|
||||
client.bitcount(key);
|
||||
return client.getIntegerReply();
|
||||
client.bitcount(key);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public Long bitcount(final String key, long start, long end) {
|
||||
client.bitcount(key, start, end);
|
||||
return client.getIntegerReply();
|
||||
client.bitcount(key, start, end);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public Long bitop(BitOP op, final String destKey, String... srcKeys) {
|
||||
client.bitop(op, destKey, srcKeys);
|
||||
return client.getIntegerReply();
|
||||
client.bitop(op, destKey, srcKeys);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2916,7 +2923,7 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<Map<String, String>> sentinelMasters() {
|
||||
public List<Map<String, String>> sentinelMasters() {
|
||||
client.sentinel(Protocol.SENTINEL_MASTERS);
|
||||
final List<Object> reply = client.getObjectMultiBulkReply();
|
||||
|
||||
@@ -2994,7 +3001,7 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<Map<String, String>> sentinelSlaves(String masterName) {
|
||||
public List<Map<String, String>> sentinelSlaves(String masterName) {
|
||||
client.sentinel(Protocol.SENTINEL_SLAVES, masterName);
|
||||
final List<Object> reply = client.getObjectMultiBulkReply();
|
||||
|
||||
@@ -3038,212 +3045,243 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
}
|
||||
|
||||
public byte[] dump(final String key) {
|
||||
checkIsInMulti();
|
||||
client.dump(key);
|
||||
return client.getBinaryBulkReply();
|
||||
checkIsInMulti();
|
||||
client.dump(key);
|
||||
return client.getBinaryBulkReply();
|
||||
}
|
||||
|
||||
public String restore(final String key, final int ttl, final byte[] serializedValue) {
|
||||
checkIsInMulti();
|
||||
client.restore(key, ttl, serializedValue);
|
||||
return client.getStatusCodeReply();
|
||||
|
||||
public String restore(final String key, final int ttl,
|
||||
final byte[] serializedValue) {
|
||||
checkIsInMulti();
|
||||
client.restore(key, ttl, serializedValue);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
|
||||
public Long pexpire(final String key, final int milliseconds) {
|
||||
checkIsInMulti();
|
||||
client.pexpire(key, milliseconds);
|
||||
return client.getIntegerReply();
|
||||
checkIsInMulti();
|
||||
client.pexpire(key, milliseconds);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
|
||||
public Long pexpireAt(final String key, final long millisecondsTimestamp) {
|
||||
checkIsInMulti();
|
||||
client.pexpireAt(key, millisecondsTimestamp);
|
||||
return client.getIntegerReply();
|
||||
checkIsInMulti();
|
||||
client.pexpireAt(key, millisecondsTimestamp);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
|
||||
public Long pttl(final String key) {
|
||||
checkIsInMulti();
|
||||
client.pttl(key);
|
||||
return client.getIntegerReply();
|
||||
checkIsInMulti();
|
||||
client.pttl(key);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
|
||||
public Double incrByFloat(final String key, final double increment) {
|
||||
checkIsInMulti();
|
||||
client.incrByFloat(key, increment);
|
||||
String relpy = client.getBulkReply();
|
||||
return (relpy != null ? new Double(relpy) : null);
|
||||
checkIsInMulti();
|
||||
client.incrByFloat(key, increment);
|
||||
String relpy = client.getBulkReply();
|
||||
return (relpy != null ? new Double(relpy) : null);
|
||||
}
|
||||
|
||||
public String psetex(final String key, final int milliseconds, final String value) {
|
||||
checkIsInMulti();
|
||||
client.psetex(key, milliseconds, value);
|
||||
return client.getStatusCodeReply();
|
||||
|
||||
public String psetex(final String key, final int milliseconds,
|
||||
final String value) {
|
||||
checkIsInMulti();
|
||||
client.psetex(key, milliseconds, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
|
||||
public String set(final String key, final String value, final String nxxx) {
|
||||
checkIsInMulti();
|
||||
client.set(key, value, nxxx);
|
||||
return client.getStatusCodeReply();
|
||||
checkIsInMulti();
|
||||
client.set(key, value, nxxx);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String set(final String key, final String value, final String nxxx, final String expx, final int time) {
|
||||
checkIsInMulti();
|
||||
client.set(key, value, nxxx, expx, time);
|
||||
return client.getStatusCodeReply();
|
||||
|
||||
public String set(final String key, final String value, final String nxxx,
|
||||
final String expx, final int time) {
|
||||
checkIsInMulti();
|
||||
client.set(key, value, nxxx, expx, time);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
|
||||
public String clientKill(final String client) {
|
||||
checkIsInMulti();
|
||||
this.client.clientKill(client);
|
||||
return this.client.getStatusCodeReply();
|
||||
checkIsInMulti();
|
||||
this.client.clientKill(client);
|
||||
return this.client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
|
||||
public String clientSetname(final String name) {
|
||||
checkIsInMulti();
|
||||
client.clientSetname(name);
|
||||
return client.getStatusCodeReply();
|
||||
checkIsInMulti();
|
||||
client.clientSetname(name);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String migrate(final String host, final int port, final String key, final int destinationDb, final int timeout) {
|
||||
checkIsInMulti();
|
||||
client.migrate(host, port, key, destinationDb, timeout);
|
||||
return client.getStatusCodeReply();
|
||||
|
||||
public String migrate(final String host, final int port, final String key,
|
||||
final int destinationDb, final int timeout) {
|
||||
checkIsInMulti();
|
||||
client.migrate(host, port, key, destinationDb, timeout);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public Double hincrByFloat(final String key, final String field, double increment) {
|
||||
checkIsInMulti();
|
||||
client.hincrByFloat(key, field, increment);
|
||||
String relpy = client.getBulkReply();
|
||||
return (relpy != null ? new Double(relpy) : null);
|
||||
|
||||
public Double hincrByFloat(final String key, final String field,
|
||||
double increment) {
|
||||
checkIsInMulti();
|
||||
client.hincrByFloat(key, field, increment);
|
||||
String relpy = client.getBulkReply();
|
||||
return (relpy != null ? new Double(relpy) : null);
|
||||
}
|
||||
|
||||
public ScanResult<String> scan(int cursor) {
|
||||
return scan(cursor, new ScanParams());
|
||||
}
|
||||
|
||||
|
||||
public ScanResult<String> scan(int cursor, final ScanParams params) {
|
||||
checkIsInMulti();
|
||||
client.scan(cursor, params);
|
||||
List<Object> result = client.getObjectMultiBulkReply();
|
||||
int newcursor = Integer.parseInt(new String((byte[])result.get(0)));
|
||||
int newcursor = Integer.parseInt(new String((byte[]) result.get(0)));
|
||||
List<String> results = new ArrayList<String>();
|
||||
List<byte[]> rawResults = (List<byte[]>)result.get(1);
|
||||
List<byte[]> rawResults = (List<byte[]>) result.get(1);
|
||||
for (byte[] bs : rawResults) {
|
||||
results.add(SafeEncoder.encode(bs));
|
||||
}
|
||||
return new ScanResult<String>(newcursor, results);
|
||||
}
|
||||
|
||||
public ScanResult<Map.Entry<String, String>> hscan(final String key, int cursor) {
|
||||
|
||||
public ScanResult<Map.Entry<String, String>> hscan(final String key,
|
||||
int cursor) {
|
||||
return hscan(key, cursor, new ScanParams());
|
||||
}
|
||||
|
||||
public ScanResult<Map.Entry<String, String>> hscan(final String key, int cursor, final ScanParams params) {
|
||||
|
||||
public ScanResult<Map.Entry<String, String>> hscan(final String key,
|
||||
int cursor, final ScanParams params) {
|
||||
checkIsInMulti();
|
||||
client.hscan(key, cursor, params);
|
||||
List<Object> result = client.getObjectMultiBulkReply();
|
||||
int newcursor = Integer.parseInt(new String((byte[])result.get(0)));
|
||||
int newcursor = Integer.parseInt(new String((byte[]) result.get(0)));
|
||||
List<Map.Entry<String, String>> results = new ArrayList<Map.Entry<String, String>>();
|
||||
List<byte[]> rawResults = (List<byte[]>)result.get(1);
|
||||
List<byte[]> rawResults = (List<byte[]>) result.get(1);
|
||||
Iterator<byte[]> iterator = rawResults.iterator();
|
||||
while(iterator.hasNext()) {
|
||||
results.add(new AbstractMap.SimpleEntry<String, String>(SafeEncoder.encode(iterator.next()), SafeEncoder.encode(iterator.next())));
|
||||
while (iterator.hasNext()) {
|
||||
results.add(new AbstractMap.SimpleEntry<String, String>(SafeEncoder
|
||||
.encode(iterator.next()), SafeEncoder.encode(iterator
|
||||
.next())));
|
||||
}
|
||||
return new ScanResult<Map.Entry<String, String>>(newcursor, results);
|
||||
}
|
||||
|
||||
|
||||
public ScanResult<String> sscan(final String key, int cursor) {
|
||||
return sscan(key, cursor, new ScanParams());
|
||||
}
|
||||
|
||||
public ScanResult<String> sscan(final String key, int cursor, final ScanParams params) {
|
||||
|
||||
public ScanResult<String> sscan(final String key, int cursor,
|
||||
final ScanParams params) {
|
||||
checkIsInMulti();
|
||||
client.sscan(key, cursor, params);
|
||||
List<Object> result = client.getObjectMultiBulkReply();
|
||||
int newcursor = Integer.parseInt(new String((byte[])result.get(0)));
|
||||
int newcursor = Integer.parseInt(new String((byte[]) result.get(0)));
|
||||
List<String> results = new ArrayList<String>();
|
||||
List<byte[]> rawResults = (List<byte[]>)result.get(1);
|
||||
List<byte[]> rawResults = (List<byte[]>) result.get(1);
|
||||
for (byte[] bs : rawResults) {
|
||||
results.add(SafeEncoder.encode(bs));
|
||||
}
|
||||
return new ScanResult<String>(newcursor, results);
|
||||
}
|
||||
|
||||
|
||||
public ScanResult<Tuple> zscan(final String key, int cursor) {
|
||||
return zscan(key, cursor, new ScanParams());
|
||||
}
|
||||
|
||||
public ScanResult<Tuple> zscan(final String key, int cursor, final ScanParams params) {
|
||||
|
||||
public ScanResult<Tuple> zscan(final String key, int cursor,
|
||||
final ScanParams params) {
|
||||
checkIsInMulti();
|
||||
client.zscan(key, cursor, params);
|
||||
List<Object> result = client.getObjectMultiBulkReply();
|
||||
int newcursor = Integer.parseInt(new String((byte[])result.get(0)));
|
||||
int newcursor = Integer.parseInt(new String((byte[]) result.get(0)));
|
||||
List<Tuple> results = new ArrayList<Tuple>();
|
||||
List<byte[]> rawResults = (List<byte[]>)result.get(1);
|
||||
List<byte[]> rawResults = (List<byte[]>) result.get(1);
|
||||
Iterator<byte[]> iterator = rawResults.iterator();
|
||||
while(iterator.hasNext()) {
|
||||
results.add(new Tuple(SafeEncoder.encode(iterator.next()), Double.valueOf(SafeEncoder.encode(iterator.next()))));
|
||||
while (iterator.hasNext()) {
|
||||
results.add(new Tuple(SafeEncoder.encode(iterator.next()), Double
|
||||
.valueOf(SafeEncoder.encode(iterator.next()))));
|
||||
}
|
||||
return new ScanResult<Tuple>(newcursor, results);
|
||||
}
|
||||
|
||||
public String clusterNodes() {
|
||||
checkIsInMulti();
|
||||
client.clusterNodes();
|
||||
return client.getBulkReply();
|
||||
checkIsInMulti();
|
||||
client.clusterNodes();
|
||||
return client.getBulkReply();
|
||||
}
|
||||
|
||||
|
||||
public String clusterMeet(final String ip, final int port) {
|
||||
checkIsInMulti();
|
||||
client.clusterMeet(ip, port);
|
||||
return client.getStatusCodeReply();
|
||||
checkIsInMulti();
|
||||
client.clusterMeet(ip, port);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String clusterAddSlots(final int ...slots) {
|
||||
checkIsInMulti();
|
||||
client.clusterAddSlots(slots);
|
||||
return client.getStatusCodeReply();
|
||||
|
||||
public String clusterAddSlots(final int... slots) {
|
||||
checkIsInMulti();
|
||||
client.clusterAddSlots(slots);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String clusterDelSlots(final int ...slots) {
|
||||
checkIsInMulti();
|
||||
client.clusterDelSlots(slots);
|
||||
return client.getStatusCodeReply();
|
||||
|
||||
public String clusterDelSlots(final int... slots) {
|
||||
checkIsInMulti();
|
||||
client.clusterDelSlots(slots);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
|
||||
public String clusterInfo() {
|
||||
checkIsInMulti();
|
||||
client.clusterInfo();
|
||||
return client.getStatusCodeReply();
|
||||
checkIsInMulti();
|
||||
client.clusterInfo();
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
|
||||
public List<String> clusterGetKeysInSlot(final int slot, final int count) {
|
||||
checkIsInMulti();
|
||||
client.clusterGetKeysInSlot(slot, count);
|
||||
return client.getMultiBulkReply();
|
||||
checkIsInMulti();
|
||||
client.clusterGetKeysInSlot(slot, count);
|
||||
return client.getMultiBulkReply();
|
||||
}
|
||||
|
||||
|
||||
public String clusterSetSlotNode(final int slot, final String nodeId) {
|
||||
checkIsInMulti();
|
||||
client.clusterSetSlotNode(slot, nodeId);
|
||||
return client.getStatusCodeReply();
|
||||
checkIsInMulti();
|
||||
client.clusterSetSlotNode(slot, nodeId);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
|
||||
public String clusterSetSlotMigrating(final int slot, final String nodeId) {
|
||||
checkIsInMulti();
|
||||
client.clusterSetSlotMigrating(slot, nodeId);
|
||||
return client.getStatusCodeReply();
|
||||
checkIsInMulti();
|
||||
client.clusterSetSlotMigrating(slot, nodeId);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
|
||||
public String clusterSetSlotImporting(final int slot, final String nodeId) {
|
||||
checkIsInMulti();
|
||||
client.clusterSetSlotImporting(slot, nodeId);
|
||||
return client.getStatusCodeReply();
|
||||
checkIsInMulti();
|
||||
client.clusterSetSlotImporting(slot, nodeId);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String asking() {
|
||||
checkIsInMulti();
|
||||
client.asking();
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
public String asking() {
|
||||
checkIsInMulti();
|
||||
client.asking();
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public List<String> pubsubChannels(String pattern) {
|
||||
checkIsInMulti();
|
||||
client.pubsubChannels(pattern);
|
||||
return client.getMultiBulkReply();
|
||||
}
|
||||
|
||||
public Long pubsubNumPat() {
|
||||
checkIsInMulti();
|
||||
client.pubsubNumPat();
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public Map<String, String> pubsubNumSub(String... channels) {
|
||||
checkIsInMulti();
|
||||
client.pubsubNumSub(channels);
|
||||
return BuilderFactory.STRING_MAP
|
||||
.build(client.getBinaryMultiBulkReply());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -635,7 +635,7 @@ public class JedisCluster implements JedisCommands, BasicCommands {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long zadd(final String key, final Map<Double, String> scoreMembers) {
|
||||
public Long zadd(final String key, final Map<String, Double> scoreMembers) {
|
||||
return new JedisClusterCommand<Long>(connectionHandler, timeout,
|
||||
maxRedirections) {
|
||||
@Override
|
||||
|
||||
@@ -7,47 +7,54 @@ import redis.clients.jedis.exceptions.JedisRedirectionException;
|
||||
import redis.clients.util.JedisClusterCRC16;
|
||||
|
||||
public abstract class JedisClusterCommand<T> {
|
||||
|
||||
private boolean asking = false;
|
||||
|
||||
private JedisClusterConnectionHandler connectionHandler;
|
||||
private int commandTimeout;
|
||||
private int redirections;
|
||||
// private boolean asking = false;
|
||||
|
||||
public JedisClusterCommand(JedisClusterConnectionHandler connectionHandler, int timeout, int maxRedirections) {
|
||||
this.connectionHandler = connectionHandler;
|
||||
this.commandTimeout = timeout;
|
||||
this.redirections = maxRedirections;
|
||||
}
|
||||
|
||||
public abstract T execute();
|
||||
|
||||
public T run(String key) {
|
||||
try {
|
||||
|
||||
if (key == null) {
|
||||
throw new JedisClusterException("No way to dispatch this command to Redis Cluster.");
|
||||
} else if (redirections == 0) {
|
||||
throw new JedisClusterMaxRedirectionsException("Too many Cluster redirections?");
|
||||
}
|
||||
connectionHandler.getConnectionFromSlot(JedisClusterCRC16.getSlot(key));
|
||||
if (asking) {
|
||||
//TODO: Pipeline asking with the original command to make it faster....
|
||||
connectionHandler.getConnection().asking();
|
||||
}
|
||||
return execute();
|
||||
} catch (JedisRedirectionException jre) {
|
||||
return handleRedirection(jre, key);
|
||||
}
|
||||
}
|
||||
private boolean asking = false;
|
||||
|
||||
private T handleRedirection(JedisRedirectionException jre, String key) {
|
||||
if (jre instanceof JedisAskDataException) {
|
||||
asking = true;
|
||||
}
|
||||
redirections--;
|
||||
this.connectionHandler.assignSlotToNode(jre.getSlot(), jre.getTargetNode());
|
||||
return run(key);
|
||||
private JedisClusterConnectionHandler connectionHandler;
|
||||
private int commandTimeout;
|
||||
private int redirections;
|
||||
|
||||
// private boolean asking = false;
|
||||
|
||||
public JedisClusterCommand(JedisClusterConnectionHandler connectionHandler,
|
||||
int timeout, int maxRedirections) {
|
||||
this.connectionHandler = connectionHandler;
|
||||
this.commandTimeout = timeout;
|
||||
this.redirections = maxRedirections;
|
||||
}
|
||||
|
||||
public abstract T execute();
|
||||
|
||||
public T run(String key) {
|
||||
try {
|
||||
|
||||
if (key == null) {
|
||||
throw new JedisClusterException(
|
||||
"No way to dispatch this command to Redis Cluster.");
|
||||
} else if (redirections == 0) {
|
||||
throw new JedisClusterMaxRedirectionsException(
|
||||
"Too many Cluster redirections?");
|
||||
}
|
||||
connectionHandler.getConnectionFromSlot(JedisClusterCRC16
|
||||
.getSlot(key));
|
||||
if (asking) {
|
||||
// TODO: Pipeline asking with the original command to make it
|
||||
// faster....
|
||||
connectionHandler.getConnection().asking();
|
||||
}
|
||||
return execute();
|
||||
} catch (JedisRedirectionException jre) {
|
||||
return handleRedirection(jre, key);
|
||||
}
|
||||
}
|
||||
|
||||
private T handleRedirection(JedisRedirectionException jre, String key) {
|
||||
if (jre instanceof JedisAskDataException) {
|
||||
asking = true;
|
||||
}
|
||||
redirections--;
|
||||
this.connectionHandler.assignSlotToNode(jre.getSlot(),
|
||||
jre.getTargetNode());
|
||||
return run(key);
|
||||
}
|
||||
}
|
||||
@@ -5,78 +5,80 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public abstract class JedisClusterConnectionHandler {
|
||||
|
||||
protected Map<String, JedisPool> nodes = new HashMap<String, JedisPool>();
|
||||
protected Map<Integer, JedisPool> slots = new HashMap<Integer, JedisPool>();
|
||||
|
||||
abstract Jedis getConnection();
|
||||
abstract Jedis getConnectionFromSlot(int slot);
|
||||
|
||||
public JedisClusterConnectionHandler(Set<HostAndPort> nodes) {
|
||||
initializeSlotsCache(nodes);
|
||||
}
|
||||
|
||||
public Map<String, JedisPool> getNodes() {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
private void initializeSlotsCache(Set<HostAndPort> nodes) {
|
||||
for (HostAndPort hostAndPort : nodes) {
|
||||
JedisPool jp = new JedisPool(hostAndPort.getHost(), hostAndPort.getPort());
|
||||
this.nodes.put(hostAndPort.getHost() + hostAndPort.getPort(), jp);
|
||||
discoverClusterNodesAndSlots(jp);
|
||||
}
|
||||
|
||||
protected Map<String, JedisPool> nodes = new HashMap<String, JedisPool>();
|
||||
protected Map<Integer, JedisPool> slots = new HashMap<Integer, JedisPool>();
|
||||
|
||||
abstract Jedis getConnection();
|
||||
|
||||
abstract Jedis getConnectionFromSlot(int slot);
|
||||
|
||||
public JedisClusterConnectionHandler(Set<HostAndPort> nodes) {
|
||||
initializeSlotsCache(nodes);
|
||||
}
|
||||
|
||||
public Map<String, JedisPool> getNodes() {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
private void initializeSlotsCache(Set<HostAndPort> nodes) {
|
||||
for (HostAndPort hostAndPort : nodes) {
|
||||
JedisPool jp = new JedisPool(hostAndPort.getHost(),
|
||||
hostAndPort.getPort());
|
||||
this.nodes.put(hostAndPort.getHost() + hostAndPort.getPort(), jp);
|
||||
discoverClusterNodesAndSlots(jp);
|
||||
}
|
||||
|
||||
private void discoverClusterNodesAndSlots(JedisPool jp) {
|
||||
String localNodes = jp.getResource().clusterNodes();
|
||||
for (String nodeInfo : localNodes.split("\n")) {
|
||||
HostAndPort node = getHostAndPortFromNodeLine(nodeInfo);
|
||||
JedisPool nodePool = new JedisPool(node.getHost(), node.getPort());
|
||||
this.nodes.put(node.getHost() + node.getPort(), nodePool);
|
||||
populateNodeSlots(nodeInfo, nodePool);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void populateNodeSlots(String nodeInfo, JedisPool nodePool) {
|
||||
String[] nodeInfoArray = nodeInfo.split(" ");
|
||||
if (nodeInfoArray.length > 7) {
|
||||
for (int i = 8; i < nodeInfoArray.length; i++) {
|
||||
processSlot(nodeInfoArray[i], nodePool);
|
||||
}
|
||||
}
|
||||
private void discoverClusterNodesAndSlots(JedisPool jp) {
|
||||
String localNodes = jp.getResource().clusterNodes();
|
||||
for (String nodeInfo : localNodes.split("\n")) {
|
||||
HostAndPort node = getHostAndPortFromNodeLine(nodeInfo);
|
||||
JedisPool nodePool = new JedisPool(node.getHost(), node.getPort());
|
||||
this.nodes.put(node.getHost() + node.getPort(), nodePool);
|
||||
populateNodeSlots(nodeInfo, nodePool);
|
||||
}
|
||||
}
|
||||
|
||||
private void processSlot(String slot, JedisPool nodePool) {
|
||||
if (slot.contains("-")) {
|
||||
String[] slotRange = slot.split("-");
|
||||
for (int i = Integer.valueOf(slotRange[0]); i <= Integer.valueOf(slotRange[1]); i++) {
|
||||
slots.put(i, nodePool);
|
||||
}
|
||||
} else {
|
||||
slots.put(Integer.valueOf(slot), nodePool);
|
||||
}
|
||||
private void populateNodeSlots(String nodeInfo, JedisPool nodePool) {
|
||||
String[] nodeInfoArray = nodeInfo.split(" ");
|
||||
if (nodeInfoArray.length > 7) {
|
||||
for (int i = 8; i < nodeInfoArray.length; i++) {
|
||||
processSlot(nodeInfoArray[i], nodePool);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private HostAndPort getHostAndPortFromNodeLine(String nodeInfo) {
|
||||
String stringHostAndPort = nodeInfo.split(" ",3)[1];
|
||||
String[] arrayHostAndPort = stringHostAndPort.split(":");
|
||||
return new HostAndPort(arrayHostAndPort[0], Integer.valueOf(arrayHostAndPort[1]));
|
||||
private void processSlot(String slot, JedisPool nodePool) {
|
||||
if (slot.contains("-")) {
|
||||
String[] slotRange = slot.split("-");
|
||||
for (int i = Integer.valueOf(slotRange[0]); i <= Integer
|
||||
.valueOf(slotRange[1]); i++) {
|
||||
slots.put(i, nodePool);
|
||||
}
|
||||
} else {
|
||||
slots.put(Integer.valueOf(slot), nodePool);
|
||||
}
|
||||
}
|
||||
|
||||
private HostAndPort getHostAndPortFromNodeLine(String nodeInfo) {
|
||||
String stringHostAndPort = nodeInfo.split(" ", 3)[1];
|
||||
String[] arrayHostAndPort = stringHostAndPort.split(":");
|
||||
return new HostAndPort(arrayHostAndPort[0],
|
||||
Integer.valueOf(arrayHostAndPort[1]));
|
||||
}
|
||||
|
||||
public void assignSlotToNode(int slot, HostAndPort targetNode) {
|
||||
JedisPool targetPool = nodes.get(targetNode.getHost()
|
||||
+ targetNode.getPort());
|
||||
slots.put(slot, targetPool);
|
||||
}
|
||||
|
||||
protected JedisPool getRandomConnection() {
|
||||
Object[] nodeArray = nodes.values().toArray();
|
||||
return (JedisPool) (nodeArray[new Random().nextInt(nodeArray.length)]);
|
||||
}
|
||||
|
||||
public void assignSlotToNode(int slot, HostAndPort targetNode) {
|
||||
JedisPool targetPool = nodes.get(targetNode.getHost() + targetNode.getPort());
|
||||
slots.put(slot, targetPool);
|
||||
}
|
||||
|
||||
|
||||
protected JedisPool getRandomConnection() {
|
||||
Object[] nodeArray = nodes.values().toArray();
|
||||
return (JedisPool) (nodeArray[new Random().nextInt(nodeArray.length)]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@ import java.util.Set;
|
||||
/**
|
||||
* Common interface for sharded and non-sharded Jedis
|
||||
*/
|
||||
public interface
|
||||
JedisCommands {
|
||||
public interface JedisCommands {
|
||||
String set(String key, String value);
|
||||
|
||||
String get(String key);
|
||||
@@ -114,8 +113,8 @@ public interface
|
||||
Long strlen(String key);
|
||||
|
||||
Long zadd(String key, double score, String member);
|
||||
|
||||
Long zadd(String key, Map<Double, String> scoreMembers);
|
||||
|
||||
Long zadd(String key, Map<String, Double> scoreMembers);
|
||||
|
||||
Set<String> zrange(String key, long start, long end);
|
||||
|
||||
@@ -152,50 +151,50 @@ public interface
|
||||
Set<String> zrevrangeByScore(String key, double max, double min);
|
||||
|
||||
Set<String> zrangeByScore(String key, double min, double max, int offset,
|
||||
int count);
|
||||
int count);
|
||||
|
||||
Set<String> zrevrangeByScore(String key, String max, String min);
|
||||
|
||||
Set<String> zrangeByScore(String key, String min, String max, int offset,
|
||||
int count);
|
||||
int count);
|
||||
|
||||
Set<String> zrevrangeByScore(String key, double max, double min,
|
||||
int offset, int count);
|
||||
int offset, int count);
|
||||
|
||||
Set<Tuple> zrangeByScoreWithScores(String key, double min, double max);
|
||||
|
||||
Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min);
|
||||
|
||||
Set<Tuple> zrangeByScoreWithScores(String key, double min, double max,
|
||||
int offset, int count);
|
||||
|
||||
int offset, int count);
|
||||
|
||||
Set<String> zrevrangeByScore(String key, String max, String min,
|
||||
int offset, int count);
|
||||
int offset, int count);
|
||||
|
||||
Set<Tuple> zrangeByScoreWithScores(String key, String min, String max);
|
||||
|
||||
|
||||
Set<Tuple> zrevrangeByScoreWithScores(String key, String max, String min);
|
||||
|
||||
Set<Tuple> zrangeByScoreWithScores(String key, String min, String max,
|
||||
int offset, int count);
|
||||
int offset, int count);
|
||||
|
||||
Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min,
|
||||
int offset, int count);
|
||||
|
||||
int offset, int count);
|
||||
|
||||
Set<Tuple> zrevrangeByScoreWithScores(String key, String max, String min,
|
||||
int offset, int count);
|
||||
int offset, int count);
|
||||
|
||||
Long zremrangeByRank(String key, long start, long end);
|
||||
|
||||
Long zremrangeByScore(String key, double start, double end);
|
||||
|
||||
|
||||
Long zremrangeByScore(String key, String start, String end);
|
||||
|
||||
Long linsert(String key, Client.LIST_POSITION where, String pivot,
|
||||
String value);
|
||||
|
||||
String value);
|
||||
|
||||
Long lpushx(String key, String... string);
|
||||
|
||||
|
||||
Long rpushx(String key, String... string);
|
||||
|
||||
List<String> blpop(String arg);
|
||||
@@ -211,10 +210,10 @@ public interface
|
||||
Long bitcount(final String key);
|
||||
|
||||
Long bitcount(final String key, long start, long end);
|
||||
|
||||
|
||||
ScanResult<Map.Entry<String, String>> hscan(final String key, int cursor);
|
||||
|
||||
|
||||
ScanResult<String> sscan(final String key, int cursor);
|
||||
|
||||
|
||||
ScanResult<Tuple> zscan(final String key, int cursor);
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@ public abstract class JedisMonitor {
|
||||
protected Client client;
|
||||
|
||||
public void proceed(Client client) {
|
||||
this.client = client;
|
||||
this.client.setTimeoutInfinite();
|
||||
do {
|
||||
String command = client.getBulkReply();
|
||||
onCommand(command);
|
||||
} while (client.isConnected());
|
||||
this.client = client;
|
||||
this.client.setTimeoutInfinite();
|
||||
do {
|
||||
String command = client.getBulkReply();
|
||||
onCommand(command);
|
||||
} while (client.isConnected());
|
||||
}
|
||||
|
||||
public abstract void onCommand(String command);
|
||||
|
||||
@@ -18,7 +18,7 @@ public class JedisPool extends Pool<Jedis> {
|
||||
this(new GenericObjectPoolConfig(), host, port,
|
||||
Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE, null);
|
||||
}
|
||||
|
||||
|
||||
public JedisPool(final String host) {
|
||||
URI uri = URI.create(host);
|
||||
if (uri.getScheme() != null && uri.getScheme().equals("redis")) {
|
||||
@@ -84,6 +84,7 @@ public class JedisPool extends Pool<Jedis> {
|
||||
}
|
||||
|
||||
public void returnResource(final Jedis resource) {
|
||||
resource.resetState();
|
||||
returnResourceObject(resource);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
|
||||
public class JedisPoolConfig extends GenericObjectPoolConfig {
|
||||
public JedisPoolConfig() {
|
||||
// defaults to make your life with connection pool easier :)
|
||||
setTestWhileIdle(true);
|
||||
setMinEvictableIdleTimeMillis(60000);
|
||||
setTimeBetweenEvictionRunsMillis(30000);
|
||||
setNumTestsPerEvictionRun(-1);
|
||||
// defaults to make your life with connection pool easier :)
|
||||
setTestWhileIdle(true);
|
||||
setMinEvictableIdleTimeMillis(60000);
|
||||
setTimeBetweenEvictionRunsMillis(30000);
|
||||
setNumTestsPerEvictionRun(-1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,12 @@ import redis.clients.util.SafeEncoder;
|
||||
|
||||
public abstract class JedisPubSub {
|
||||
private int subscribedChannels = 0;
|
||||
private Client client;
|
||||
private volatile Client client;
|
||||
|
||||
public abstract void onMessage(String channel, String message);
|
||||
|
||||
public abstract void onPMessage(String pattern, String channel,
|
||||
String message);
|
||||
String message);
|
||||
|
||||
public abstract void onSubscribe(String channel, int subscribedChannels);
|
||||
|
||||
@@ -32,115 +32,145 @@ public abstract class JedisPubSub {
|
||||
public abstract void onPSubscribe(String pattern, int subscribedChannels);
|
||||
|
||||
public void unsubscribe() {
|
||||
if (client == null) {
|
||||
throw new JedisConnectionException(
|
||||
"JedisPubSub was not subscribed to a Jedis instance.");
|
||||
}
|
||||
client.unsubscribe();
|
||||
client.flush();
|
||||
if (client == null) {
|
||||
throw new JedisConnectionException(
|
||||
"JedisPubSub was not subscribed to a Jedis instance.");
|
||||
}
|
||||
client.unsubscribe();
|
||||
client.flush();
|
||||
}
|
||||
|
||||
public void unsubscribe(String... channels) {
|
||||
client.unsubscribe(channels);
|
||||
client.flush();
|
||||
if (client == null) {
|
||||
throw new JedisConnectionException(
|
||||
"JedisPubSub is not subscribed to a Jedis instance.");
|
||||
}
|
||||
client.unsubscribe(channels);
|
||||
client.flush();
|
||||
}
|
||||
|
||||
public void subscribe(String... channels) {
|
||||
client.subscribe(channels);
|
||||
client.flush();
|
||||
if (client == null) {
|
||||
throw new JedisConnectionException(
|
||||
"JedisPubSub is not subscribed to a Jedis instance.");
|
||||
}
|
||||
client.subscribe(channels);
|
||||
client.flush();
|
||||
}
|
||||
|
||||
public void psubscribe(String... patterns) {
|
||||
client.psubscribe(patterns);
|
||||
client.flush();
|
||||
if (client == null) {
|
||||
throw new JedisConnectionException(
|
||||
"JedisPubSub is not subscribed to a Jedis instance.");
|
||||
}
|
||||
client.psubscribe(patterns);
|
||||
client.flush();
|
||||
}
|
||||
|
||||
public void punsubscribe() {
|
||||
client.punsubscribe();
|
||||
client.flush();
|
||||
if (client == null) {
|
||||
throw new JedisConnectionException(
|
||||
"JedisPubSub is not subscribed to a Jedis instance.");
|
||||
}
|
||||
client.punsubscribe();
|
||||
client.flush();
|
||||
}
|
||||
|
||||
public void punsubscribe(String... patterns) {
|
||||
client.punsubscribe(patterns);
|
||||
client.flush();
|
||||
if (client == null) {
|
||||
throw new JedisConnectionException(
|
||||
"JedisPubSub is not subscribed to a Jedis instance.");
|
||||
}
|
||||
client.punsubscribe(patterns);
|
||||
client.flush();
|
||||
}
|
||||
|
||||
public boolean isSubscribed() {
|
||||
return subscribedChannels > 0;
|
||||
return subscribedChannels > 0;
|
||||
}
|
||||
|
||||
public void proceedWithPatterns(Client client, String... patterns) {
|
||||
this.client = client;
|
||||
client.psubscribe(patterns);
|
||||
client.flush();
|
||||
process(client);
|
||||
this.client = client;
|
||||
client.psubscribe(patterns);
|
||||
client.flush();
|
||||
process(client);
|
||||
}
|
||||
|
||||
public void proceed(Client client, String... channels) {
|
||||
this.client = client;
|
||||
client.subscribe(channels);
|
||||
client.flush();
|
||||
process(client);
|
||||
this.client = client;
|
||||
client.subscribe(channels);
|
||||
client.flush();
|
||||
process(client);
|
||||
}
|
||||
|
||||
private void process(Client client) {
|
||||
do {
|
||||
List<Object> reply = client.getObjectMultiBulkReply();
|
||||
final Object firstObj = reply.get(0);
|
||||
if (!(firstObj instanceof byte[])) {
|
||||
throw new JedisException("Unknown message type: " + firstObj);
|
||||
}
|
||||
final byte[] resp = (byte[]) firstObj;
|
||||
if (Arrays.equals(SUBSCRIBE.raw, resp)) {
|
||||
subscribedChannels = ((Long) reply.get(2)).intValue();
|
||||
final byte[] bchannel = (byte[]) reply.get(1);
|
||||
final String strchannel = (bchannel == null) ? null
|
||||
: SafeEncoder.encode(bchannel);
|
||||
onSubscribe(strchannel, subscribedChannels);
|
||||
} else if (Arrays.equals(UNSUBSCRIBE.raw, resp)) {
|
||||
subscribedChannels = ((Long) reply.get(2)).intValue();
|
||||
final byte[] bchannel = (byte[]) reply.get(1);
|
||||
final String strchannel = (bchannel == null) ? null
|
||||
: SafeEncoder.encode(bchannel);
|
||||
onUnsubscribe(strchannel, subscribedChannels);
|
||||
} else if (Arrays.equals(MESSAGE.raw, resp)) {
|
||||
final byte[] bchannel = (byte[]) reply.get(1);
|
||||
final byte[] bmesg = (byte[]) reply.get(2);
|
||||
final String strchannel = (bchannel == null) ? null
|
||||
: SafeEncoder.encode(bchannel);
|
||||
final String strmesg = (bmesg == null) ? null : SafeEncoder
|
||||
.encode(bmesg);
|
||||
onMessage(strchannel, strmesg);
|
||||
} else if (Arrays.equals(PMESSAGE.raw, resp)) {
|
||||
final byte[] bpattern = (byte[]) reply.get(1);
|
||||
final byte[] bchannel = (byte[]) reply.get(2);
|
||||
final byte[] bmesg = (byte[]) reply.get(3);
|
||||
final String strpattern = (bpattern == null) ? null
|
||||
: SafeEncoder.encode(bpattern);
|
||||
final String strchannel = (bchannel == null) ? null
|
||||
: SafeEncoder.encode(bchannel);
|
||||
final String strmesg = (bmesg == null) ? null : SafeEncoder
|
||||
.encode(bmesg);
|
||||
onPMessage(strpattern, strchannel, strmesg);
|
||||
} else if (Arrays.equals(PSUBSCRIBE.raw, resp)) {
|
||||
subscribedChannels = ((Long) reply.get(2)).intValue();
|
||||
final byte[] bpattern = (byte[]) reply.get(1);
|
||||
final String strpattern = (bpattern == null) ? null
|
||||
: SafeEncoder.encode(bpattern);
|
||||
onPSubscribe(strpattern, subscribedChannels);
|
||||
} else if (Arrays.equals(PUNSUBSCRIBE.raw, resp)) {
|
||||
subscribedChannels = ((Long) reply.get(2)).intValue();
|
||||
final byte[] bpattern = (byte[]) reply.get(1);
|
||||
final String strpattern = (bpattern == null) ? null
|
||||
: SafeEncoder.encode(bpattern);
|
||||
onPUnsubscribe(strpattern, subscribedChannels);
|
||||
} else {
|
||||
throw new JedisException("Unknown message type: " + firstObj);
|
||||
}
|
||||
} while (isSubscribed());
|
||||
|
||||
do {
|
||||
List<Object> reply = client.getRawObjectMultiBulkReply();
|
||||
final Object firstObj = reply.get(0);
|
||||
if (!(firstObj instanceof byte[])) {
|
||||
throw new JedisException("Unknown message type: " + firstObj);
|
||||
}
|
||||
final byte[] resp = (byte[]) firstObj;
|
||||
if (Arrays.equals(SUBSCRIBE.raw, resp)) {
|
||||
subscribedChannels = ((Long) reply.get(2)).intValue();
|
||||
final byte[] bchannel = (byte[]) reply.get(1);
|
||||
final String strchannel = (bchannel == null) ? null
|
||||
: SafeEncoder.encode(bchannel);
|
||||
onSubscribe(strchannel, subscribedChannels);
|
||||
} else if (Arrays.equals(UNSUBSCRIBE.raw, resp)) {
|
||||
subscribedChannels = ((Long) reply.get(2)).intValue();
|
||||
final byte[] bchannel = (byte[]) reply.get(1);
|
||||
final String strchannel = (bchannel == null) ? null
|
||||
: SafeEncoder.encode(bchannel);
|
||||
onUnsubscribe(strchannel, subscribedChannels);
|
||||
} else if (Arrays.equals(MESSAGE.raw, resp)) {
|
||||
final byte[] bchannel = (byte[]) reply.get(1);
|
||||
final byte[] bmesg = (byte[]) reply.get(2);
|
||||
final String strchannel = (bchannel == null) ? null
|
||||
: SafeEncoder.encode(bchannel);
|
||||
final String strmesg = (bmesg == null) ? null : SafeEncoder
|
||||
.encode(bmesg);
|
||||
onMessage(strchannel, strmesg);
|
||||
} else if (Arrays.equals(PMESSAGE.raw, resp)) {
|
||||
final byte[] bpattern = (byte[]) reply.get(1);
|
||||
final byte[] bchannel = (byte[]) reply.get(2);
|
||||
final byte[] bmesg = (byte[]) reply.get(3);
|
||||
final String strpattern = (bpattern == null) ? null
|
||||
: SafeEncoder.encode(bpattern);
|
||||
final String strchannel = (bchannel == null) ? null
|
||||
: SafeEncoder.encode(bchannel);
|
||||
final String strmesg = (bmesg == null) ? null : SafeEncoder
|
||||
.encode(bmesg);
|
||||
onPMessage(strpattern, strchannel, strmesg);
|
||||
} else if (Arrays.equals(PSUBSCRIBE.raw, resp)) {
|
||||
subscribedChannels = ((Long) reply.get(2)).intValue();
|
||||
final byte[] bpattern = (byte[]) reply.get(1);
|
||||
final String strpattern = (bpattern == null) ? null
|
||||
: SafeEncoder.encode(bpattern);
|
||||
onPSubscribe(strpattern, subscribedChannels);
|
||||
} else if (Arrays.equals(PUNSUBSCRIBE.raw, resp)) {
|
||||
subscribedChannels = ((Long) reply.get(2)).intValue();
|
||||
final byte[] bpattern = (byte[]) reply.get(1);
|
||||
final String strpattern = (bpattern == null) ? null
|
||||
: SafeEncoder.encode(bpattern);
|
||||
onPUnsubscribe(strpattern, subscribedChannels);
|
||||
} else {
|
||||
throw new JedisException("Unknown message type: " + firstObj);
|
||||
}
|
||||
} while (isSubscribed());
|
||||
|
||||
/* Invalidate instance since this thread is no longer listening */
|
||||
this.client = null;
|
||||
|
||||
/*
|
||||
* Reset pipeline count because subscribe() calls would have increased
|
||||
* it but nothing decremented it.
|
||||
*/
|
||||
client.resetPipelinedCount();
|
||||
}
|
||||
|
||||
public int getSubscribedChannels() {
|
||||
return subscribedChannels;
|
||||
return subscribedChannels;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,17 +4,16 @@ import java.util.Set;
|
||||
|
||||
public class JedisRandomConnectionHandler extends JedisClusterConnectionHandler {
|
||||
|
||||
|
||||
public JedisRandomConnectionHandler(Set<HostAndPort> nodes) {
|
||||
super(nodes);
|
||||
}
|
||||
public JedisRandomConnectionHandler(Set<HostAndPort> nodes) {
|
||||
super(nodes);
|
||||
}
|
||||
|
||||
public Jedis getConnection() {
|
||||
return getRandomConnection().getResource();
|
||||
}
|
||||
public Jedis getConnection() {
|
||||
return getRandomConnection().getResource();
|
||||
}
|
||||
|
||||
@Override
|
||||
Jedis getConnectionFromSlot(int slot) {
|
||||
return getRandomConnection().getResource();
|
||||
}
|
||||
@Override
|
||||
Jedis getConnectionFromSlot(int slot) {
|
||||
return getRandomConnection().getResource();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ public class JedisSentinelPool extends Pool<Jedis> {
|
||||
}
|
||||
|
||||
public void returnResource(final Jedis resource) {
|
||||
resource.resetState();
|
||||
returnResourceObject(resource);
|
||||
}
|
||||
|
||||
@@ -100,8 +101,9 @@ public class JedisSentinelPool extends Pool<Jedis> {
|
||||
if (!master.equals(currentHostMaster)) {
|
||||
currentHostMaster = master;
|
||||
log.info("Created JedisPool to master at " + master);
|
||||
initPool(poolConfig, new JedisFactory(master.getHost(), master.getPort(),
|
||||
timeout, password, database));
|
||||
initPool(poolConfig,
|
||||
new JedisFactory(master.getHost(), master.getPort(),
|
||||
timeout, password, database));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,10 +165,10 @@ public class JedisSentinelPool extends Pool<Jedis> {
|
||||
}
|
||||
|
||||
private HostAndPort toHostAndPort(List<String> getMasterAddrByNameResult) {
|
||||
String host = getMasterAddrByNameResult.get(0);
|
||||
int port = Integer.parseInt(getMasterAddrByNameResult.get(1));
|
||||
|
||||
return new HostAndPort(host, port);
|
||||
String host = getMasterAddrByNameResult.get(0);
|
||||
int port = Integer.parseInt(getMasterAddrByNameResult.get(1));
|
||||
|
||||
return new HostAndPort(host, port);
|
||||
}
|
||||
|
||||
protected class JedisPubSubAdapter extends JedisPubSub {
|
||||
|
||||
@@ -2,47 +2,45 @@ package redis.clients.jedis;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class JedisSlotBasedConnectionHandler extends JedisClusterConnectionHandler {
|
||||
public class JedisSlotBasedConnectionHandler extends
|
||||
JedisClusterConnectionHandler {
|
||||
|
||||
private Jedis currentConnection;
|
||||
|
||||
public JedisSlotBasedConnectionHandler(Set<HostAndPort> nodes) {
|
||||
super(nodes);
|
||||
private Jedis currentConnection;
|
||||
|
||||
public JedisSlotBasedConnectionHandler(Set<HostAndPort> nodes) {
|
||||
super(nodes);
|
||||
}
|
||||
|
||||
public Jedis getConnection() {
|
||||
return currentConnection != null ? currentConnection
|
||||
: getRandomConnection().getResource();
|
||||
}
|
||||
|
||||
private void returnCurrentConnection() {
|
||||
if (currentConnection != null) {
|
||||
nodes.get(
|
||||
currentConnection.getClient().getHost()
|
||||
+ currentConnection.getClient().getPort())
|
||||
.returnResource(currentConnection);
|
||||
}
|
||||
|
||||
|
||||
public Jedis getConnection() {
|
||||
return currentConnection != null ? currentConnection : getRandomConnection().getResource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assignSlotToNode(int slot, HostAndPort targetNode) {
|
||||
super.assignSlotToNode(slot, targetNode);
|
||||
getConnectionFromSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Jedis getConnectionFromSlot(int slot) {
|
||||
returnCurrentConnection();
|
||||
JedisPool connectionPool = slots.get(slot);
|
||||
if (connectionPool == null) {
|
||||
connectionPool = getRandomConnection();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void returnCurrentConnection() {
|
||||
if (currentConnection != null) {
|
||||
nodes.get(currentConnection.getClient().getHost()+currentConnection.getClient().getPort()).returnResource(currentConnection);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void assignSlotToNode(int slot, HostAndPort targetNode) {
|
||||
super.assignSlotToNode(slot, targetNode);
|
||||
getConnectionFromSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Jedis getConnectionFromSlot(int slot) {
|
||||
returnCurrentConnection();
|
||||
JedisPool connectionPool = slots.get(slot);
|
||||
if (connectionPool == null) {
|
||||
connectionPool = getRandomConnection();
|
||||
}
|
||||
currentConnection = connectionPool.getResource();
|
||||
return connectionPool.getResource();
|
||||
}
|
||||
|
||||
|
||||
currentConnection = connectionPool.getResource();
|
||||
return connectionPool.getResource();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Multikey related commands (these are split out because they are non-shardable)
|
||||
* Multikey related commands (these are split out because they are
|
||||
* non-shardable)
|
||||
*/
|
||||
public interface MultiKeyBinaryRedisPipeline {
|
||||
|
||||
Response<Long> del(byte[]... keys);
|
||||
|
||||
|
||||
Response<List<byte[]>> blpop(byte[]... args);
|
||||
|
||||
Response<List<byte[]>> brpop(byte[]... args);
|
||||
@@ -39,7 +39,8 @@ public interface MultiKeyBinaryRedisPipeline {
|
||||
|
||||
Response<Long> smove(byte[] srckey, byte[] dstkey, byte[] member);
|
||||
|
||||
Response<Long> sort(byte[] key, SortingParams sortingParameters, byte[] dstkey);
|
||||
Response<Long> sort(byte[] key, SortingParams sortingParameters,
|
||||
byte[] dstkey);
|
||||
|
||||
Response<Long> sort(byte[] key, byte[] dstkey);
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public interface MultiKeyCommands {
|
||||
@@ -71,6 +69,6 @@ public interface MultiKeyCommands {
|
||||
String randomKey();
|
||||
|
||||
Long bitop(BitOP op, final String destKey, String... srcKeys);
|
||||
|
||||
|
||||
ScanResult<String> scan(int cursor);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* Multikey related commands (these are split out because they are non-shardable)
|
||||
* Multikey related commands (these are split out because they are
|
||||
* non-shardable)
|
||||
*/
|
||||
public interface MultiKeyCommandsPipeline {
|
||||
Response<Long> del(String... keys);
|
||||
@@ -39,7 +38,8 @@ public interface MultiKeyCommandsPipeline {
|
||||
|
||||
Response<Long> smove(String srckey, String dstkey, String member);
|
||||
|
||||
Response<Long> sort(String key, SortingParams sortingParameters, String dstkey);
|
||||
Response<Long> sort(String key, SortingParams sortingParameters,
|
||||
String dstkey);
|
||||
|
||||
Response<Long> sort(String key, String dstkey);
|
||||
|
||||
|
||||
@@ -5,401 +5,399 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
abstract class MultiKeyPipelineBase extends PipelineBase implements
|
||||
BasicRedisPipeline,
|
||||
MultiKeyBinaryRedisPipeline,
|
||||
MultiKeyCommandsPipeline,
|
||||
ClusterPipeline {
|
||||
BasicRedisPipeline, MultiKeyBinaryRedisPipeline,
|
||||
MultiKeyCommandsPipeline, ClusterPipeline {
|
||||
|
||||
protected Client client = null;
|
||||
|
||||
public Response<List<String>> brpop(String... args) {
|
||||
client.brpop(args);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
client.brpop(args);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
|
||||
public Response<List<String>> brpop(int timeout, String... keys) {
|
||||
client.brpop(timeout, keys);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
client.brpop(timeout, keys);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<List<String>> blpop(String... args) {
|
||||
client.blpop(args);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
client.blpop(args);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
|
||||
public Response<List<String>> blpop(int timeout, String... keys) {
|
||||
client.blpop(timeout, keys);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
client.blpop(timeout, keys);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
|
||||
public Response<Map<String, String>> blpopMap(int timeout, String... keys) {
|
||||
client.blpop(timeout, keys);
|
||||
return getResponse(BuilderFactory.STRING_MAP);
|
||||
client.blpop(timeout, keys);
|
||||
return getResponse(BuilderFactory.STRING_MAP);
|
||||
}
|
||||
|
||||
public Response<List<byte[]>> brpop(byte[]... args) {
|
||||
client.brpop(args);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
|
||||
client.brpop(args);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
|
||||
}
|
||||
|
||||
|
||||
public Response<List<String>> brpop(int timeout, byte[]... keys) {
|
||||
client.brpop(timeout, keys);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
client.brpop(timeout, keys);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
|
||||
public Response<Map<String, String>> brpopMap(int timeout, String... keys) {
|
||||
client.blpop(timeout, keys);
|
||||
return getResponse(BuilderFactory.STRING_MAP);
|
||||
client.blpop(timeout, keys);
|
||||
return getResponse(BuilderFactory.STRING_MAP);
|
||||
}
|
||||
|
||||
public Response<List<byte[]>> blpop(byte[]... args) {
|
||||
client.blpop(args);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
|
||||
client.blpop(args);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
|
||||
}
|
||||
|
||||
|
||||
public Response<List<String>> blpop(int timeout, byte[]... keys) {
|
||||
client.blpop(timeout, keys);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
client.blpop(timeout, keys);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<Long> del(String... keys) {
|
||||
client.del(keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.del(keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> del(byte[]... keys) {
|
||||
client.del(keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.del(keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Set<String>> keys(String pattern) {
|
||||
getClient(pattern).keys(pattern);
|
||||
return getResponse(BuilderFactory.STRING_SET);
|
||||
getClient(pattern).keys(pattern);
|
||||
return getResponse(BuilderFactory.STRING_SET);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> keys(byte[] pattern) {
|
||||
getClient(pattern).keys(pattern);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
getClient(pattern).keys(pattern);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<List<String>> mget(String... keys) {
|
||||
client.mget(keys);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
client.mget(keys);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<List<byte[]>> mget(byte[]... keys) {
|
||||
client.mget(keys);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
|
||||
client.mget(keys);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
|
||||
}
|
||||
|
||||
public Response<String> mset(String... keysvalues) {
|
||||
client.mset(keysvalues);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.mset(keysvalues);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> mset(byte[]... keysvalues) {
|
||||
client.mset(keysvalues);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.mset(keysvalues);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> msetnx(String... keysvalues) {
|
||||
client.msetnx(keysvalues);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.msetnx(keysvalues);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> msetnx(byte[]... keysvalues) {
|
||||
client.msetnx(keysvalues);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.msetnx(keysvalues);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> rename(String oldkey, String newkey) {
|
||||
client.rename(oldkey, newkey);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.rename(oldkey, newkey);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> rename(byte[] oldkey, byte[] newkey) {
|
||||
client.rename(oldkey, newkey);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.rename(oldkey, newkey);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> renamenx(String oldkey, String newkey) {
|
||||
client.renamenx(oldkey, newkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.renamenx(oldkey, newkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> renamenx(byte[] oldkey, byte[] newkey) {
|
||||
client.renamenx(oldkey, newkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.renamenx(oldkey, newkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> rpoplpush(String srckey, String dstkey) {
|
||||
client.rpoplpush(srckey, dstkey);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.rpoplpush(srckey, dstkey);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<byte[]> rpoplpush(byte[] srckey, byte[] dstkey) {
|
||||
client.rpoplpush(srckey, dstkey);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
client.rpoplpush(srckey, dstkey);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
|
||||
public Response<Set<String>> sdiff(String... keys) {
|
||||
client.sdiff(keys);
|
||||
return getResponse(BuilderFactory.STRING_SET);
|
||||
client.sdiff(keys);
|
||||
return getResponse(BuilderFactory.STRING_SET);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> sdiff(byte[]... keys) {
|
||||
client.sdiff(keys);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
client.sdiff(keys);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<Long> sdiffstore(String dstkey, String... keys) {
|
||||
client.sdiffstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.sdiffstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> sdiffstore(byte[] dstkey, byte[]... keys) {
|
||||
client.sdiffstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.sdiffstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Set<String>> sinter(String... keys) {
|
||||
client.sinter(keys);
|
||||
return getResponse(BuilderFactory.STRING_SET);
|
||||
client.sinter(keys);
|
||||
return getResponse(BuilderFactory.STRING_SET);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> sinter(byte[]... keys) {
|
||||
client.sinter(keys);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
client.sinter(keys);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<Long> sinterstore(String dstkey, String... keys) {
|
||||
client.sinterstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.sinterstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> sinterstore(byte[] dstkey, byte[]... keys) {
|
||||
client.sinterstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.sinterstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> smove(String srckey, String dstkey, String member) {
|
||||
client.smove(srckey, dstkey, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.smove(srckey, dstkey, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> smove(byte[] srckey, byte[] dstkey, byte[] member) {
|
||||
client.smove(srckey, dstkey, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.smove(srckey, dstkey, member);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> sort(String key,
|
||||
SortingParams sortingParameters, String dstkey) {
|
||||
client.sort(key, sortingParameters, dstkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
public Response<Long> sort(String key, SortingParams sortingParameters,
|
||||
String dstkey) {
|
||||
client.sort(key, sortingParameters, dstkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> sort(byte[] key,
|
||||
SortingParams sortingParameters, byte[] dstkey) {
|
||||
client.sort(key, sortingParameters, dstkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
public Response<Long> sort(byte[] key, SortingParams sortingParameters,
|
||||
byte[] dstkey) {
|
||||
client.sort(key, sortingParameters, dstkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> sort(String key, String dstkey) {
|
||||
client.sort(key, dstkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.sort(key, dstkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> sort(byte[] key, byte[] dstkey) {
|
||||
client.sort(key, dstkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.sort(key, dstkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Set<String>> sunion(String... keys) {
|
||||
client.sunion(keys);
|
||||
return getResponse(BuilderFactory.STRING_SET);
|
||||
client.sunion(keys);
|
||||
return getResponse(BuilderFactory.STRING_SET);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> sunion(byte[]... keys) {
|
||||
client.sunion(keys);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
client.sunion(keys);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
public Response<Long> sunionstore(String dstkey, String... keys) {
|
||||
client.sunionstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.sunionstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> sunionstore(byte[] dstkey, byte[]... keys) {
|
||||
client.sunionstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.sunionstore(dstkey, keys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> watch(String... keys) {
|
||||
client.watch(keys);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.watch(keys);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> watch(byte[]... keys) {
|
||||
client.watch(keys);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.watch(keys);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> zinterstore(String dstkey, String... sets) {
|
||||
client.zinterstore(dstkey, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.zinterstore(dstkey, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zinterstore(byte[] dstkey, byte[]... sets) {
|
||||
client.zinterstore(dstkey, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.zinterstore(dstkey, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zinterstore(String dstkey, ZParams params,
|
||||
String... sets) {
|
||||
client.zinterstore(dstkey, params, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
String... sets) {
|
||||
client.zinterstore(dstkey, params, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zinterstore(byte[] dstkey, ZParams params,
|
||||
byte[]... sets) {
|
||||
client.zinterstore(dstkey, params, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
byte[]... sets) {
|
||||
client.zinterstore(dstkey, params, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zunionstore(String dstkey, String... sets) {
|
||||
client.zunionstore(dstkey, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.zunionstore(dstkey, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zunionstore(byte[] dstkey, byte[]... sets) {
|
||||
client.zunionstore(dstkey, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.zunionstore(dstkey, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zunionstore(String dstkey, ZParams params,
|
||||
String... sets) {
|
||||
client.zunionstore(dstkey, params, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
String... sets) {
|
||||
client.zunionstore(dstkey, params, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> zunionstore(byte[] dstkey, ZParams params,
|
||||
byte[]... sets) {
|
||||
client.zunionstore(dstkey, params, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
byte[]... sets) {
|
||||
client.zunionstore(dstkey, params, sets);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> bgrewriteaof() {
|
||||
client.bgrewriteaof();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.bgrewriteaof();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> bgsave() {
|
||||
client.bgsave();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.bgsave();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> configGet(String pattern) {
|
||||
client.configGet(pattern);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.configGet(pattern);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> configSet(String parameter, String value) {
|
||||
client.configSet(parameter, value);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.configSet(parameter, value);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> brpoplpush(String source, String destination,
|
||||
int timeout) {
|
||||
client.brpoplpush(source, destination, timeout);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
int timeout) {
|
||||
client.brpoplpush(source, destination, timeout);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<byte[]> brpoplpush(byte[] source, byte[] destination,
|
||||
int timeout) {
|
||||
client.brpoplpush(source, destination, timeout);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
int timeout) {
|
||||
client.brpoplpush(source, destination, timeout);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
|
||||
public Response<String> configResetStat() {
|
||||
client.configResetStat();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.configResetStat();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> save() {
|
||||
client.save();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.save();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> lastsave() {
|
||||
client.lastsave();
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.lastsave();
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> publish(String channel, String message) {
|
||||
client.publish(channel, message);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.publish(channel, message);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> publish(byte[] channel, byte[] message) {
|
||||
client.publish(channel, message);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.publish(channel, message);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> randomKey() {
|
||||
client.randomKey();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.randomKey();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<byte[]> randomKeyBinary() {
|
||||
client.randomKey();
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
client.randomKey();
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
|
||||
public Response<String> flushDB() {
|
||||
client.flushDB();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.flushDB();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> flushAll() {
|
||||
client.flushAll();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.flushAll();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> info() {
|
||||
client.info();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.info();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> dbSize() {
|
||||
client.dbSize();
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.dbSize();
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<String> shutdown() {
|
||||
client.shutdown();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.shutdown();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> ping() {
|
||||
client.ping();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.ping();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> select(int index) {
|
||||
client.select(index);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.select(index);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Long> bitop(BitOP op, byte[] destKey, byte[]... srcKeys) {
|
||||
client.bitop(op, destKey, srcKeys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.bitop(op, destKey, srcKeys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> bitop(BitOP op, String destKey, String... srcKeys) {
|
||||
client.bitop(op, destKey, srcKeys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
client.bitop(op, destKey, srcKeys);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
|
||||
public Response<String> clusterNodes() {
|
||||
client.clusterNodes();
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
@@ -425,22 +423,26 @@ abstract class MultiKeyPipelineBase extends PipelineBase implements
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<List<String>> clusterGetKeysInSlot(final int slot, final int count) {
|
||||
public Response<List<String>> clusterGetKeysInSlot(final int slot,
|
||||
final int count) {
|
||||
client.clusterGetKeysInSlot(slot, count);
|
||||
return getResponse(BuilderFactory.STRING_LIST);
|
||||
}
|
||||
|
||||
public Response<String> clusterSetSlotNode(final int slot, final String nodeId) {
|
||||
public Response<String> clusterSetSlotNode(final int slot,
|
||||
final String nodeId) {
|
||||
client.clusterSetSlotNode(slot, nodeId);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> clusterSetSlotMigrating(final int slot, final String nodeId) {
|
||||
public Response<String> clusterSetSlotMigrating(final int slot,
|
||||
final String nodeId) {
|
||||
client.clusterSetSlotMigrating(slot, nodeId);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> clusterSetSlotImporting(final int slot, final String nodeId) {
|
||||
public Response<String> clusterSetSlotImporting(final int slot,
|
||||
final String nodeId) {
|
||||
client.clusterSetSlotImporting(slot, nodeId);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
@@ -1,66 +1,66 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Pipeline extends MultiKeyPipelineBase {
|
||||
|
||||
private MultiResponseBuilder currentMulti;
|
||||
|
||||
private class MultiResponseBuilder extends Builder<List<Object>>{
|
||||
private List<Response<?>> responses = new ArrayList<Response<?>>();
|
||||
|
||||
@Override
|
||||
public List<Object> build(Object data) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> list = (List<Object>)data;
|
||||
List<Object> values = new ArrayList<Object>();
|
||||
|
||||
if(list.size() != responses.size()){
|
||||
throw new JedisDataException("Expected data size " + responses.size() + " but was " + list.size());
|
||||
}
|
||||
|
||||
for(int i=0;i<list.size();i++){
|
||||
Response<?> response = responses.get(i);
|
||||
response.set(list.get(i));
|
||||
values.add(response.get());
|
||||
}
|
||||
return values;
|
||||
}
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
|
||||
public void addResponse(Response<?> response){
|
||||
responses.add(response);
|
||||
}
|
||||
public class Pipeline extends MultiKeyPipelineBase {
|
||||
|
||||
private MultiResponseBuilder currentMulti;
|
||||
|
||||
private class MultiResponseBuilder extends Builder<List<Object>> {
|
||||
private List<Response<?>> responses = new ArrayList<Response<?>>();
|
||||
|
||||
@Override
|
||||
public List<Object> build(Object data) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> list = (List<Object>) data;
|
||||
List<Object> values = new ArrayList<Object>();
|
||||
|
||||
if (list.size() != responses.size()) {
|
||||
throw new JedisDataException("Expected data size "
|
||||
+ responses.size() + " but was " + list.size());
|
||||
}
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Response<?> response = responses.get(i);
|
||||
response.set(list.get(i));
|
||||
values.add(response.get());
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public void addResponse(Response<?> response) {
|
||||
responses.add(response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> Response<T> getResponse(Builder<T> builder) {
|
||||
if(currentMulti != null){
|
||||
super.getResponse(BuilderFactory.STRING); //Expected QUEUED
|
||||
|
||||
Response<T> lr = new Response<T>(builder);
|
||||
currentMulti.addResponse(lr);
|
||||
return lr;
|
||||
}
|
||||
else{
|
||||
return super.getResponse(builder);
|
||||
}
|
||||
if (currentMulti != null) {
|
||||
super.getResponse(BuilderFactory.STRING); // Expected QUEUED
|
||||
|
||||
Response<T> lr = new Response<T>(builder);
|
||||
currentMulti.addResponse(lr);
|
||||
return lr;
|
||||
} else {
|
||||
return super.getResponse(builder);
|
||||
}
|
||||
}
|
||||
|
||||
public void setClient(Client client) {
|
||||
this.client = client;
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Client getClient(byte[] key) {
|
||||
return client;
|
||||
return client;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Client getClient(String key) {
|
||||
return client;
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,10 +69,10 @@ public class Pipeline extends MultiKeyPipelineBase {
|
||||
* the different Response<?> of the commands you execute.
|
||||
*/
|
||||
public void sync() {
|
||||
List<Object> unformatted = client.getAll();
|
||||
for (Object o : unformatted) {
|
||||
generateResponse(o);
|
||||
}
|
||||
List<Object> unformatted = client.getAll();
|
||||
for (Object o : unformatted) {
|
||||
generateResponse(o);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,37 +84,38 @@ public class Pipeline extends MultiKeyPipelineBase {
|
||||
* @return A list of all the responses in the order you executed them.
|
||||
*/
|
||||
public List<Object> syncAndReturnAll() {
|
||||
List<Object> unformatted = client.getAll();
|
||||
List<Object> formatted = new ArrayList<Object>();
|
||||
|
||||
for (Object o : unformatted) {
|
||||
try {
|
||||
formatted.add(generateResponse(o).get());
|
||||
} catch (JedisDataException e) {
|
||||
formatted.add(e);
|
||||
}
|
||||
}
|
||||
return formatted;
|
||||
List<Object> unformatted = client.getAll();
|
||||
List<Object> formatted = new ArrayList<Object>();
|
||||
|
||||
for (Object o : unformatted) {
|
||||
try {
|
||||
formatted.add(generateResponse(o).get());
|
||||
} catch (JedisDataException e) {
|
||||
formatted.add(e);
|
||||
}
|
||||
}
|
||||
return formatted;
|
||||
}
|
||||
|
||||
public Response<String> discard() {
|
||||
client.discard();
|
||||
currentMulti = null;
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
client.discard();
|
||||
currentMulti = null;
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<List<Object>> exec() {
|
||||
client.exec();
|
||||
Response<List<Object>> response = super.getResponse(currentMulti);
|
||||
currentMulti = null;
|
||||
return response;
|
||||
client.exec();
|
||||
Response<List<Object>> response = super.getResponse(currentMulti);
|
||||
currentMulti = null;
|
||||
return response;
|
||||
}
|
||||
|
||||
public Response<String> multi() {
|
||||
client.multi();
|
||||
Response<String> response = getResponse(BuilderFactory.STRING); //Expecting OK
|
||||
currentMulti = new MultiResponseBuilder();
|
||||
return response;
|
||||
client.multi();
|
||||
Response<String> response = getResponse(BuilderFactory.STRING); // Expecting
|
||||
// OK
|
||||
currentMulti = new MultiResponseBuilder();
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,5 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
|
||||
public abstract class PipelineBlock extends Pipeline {
|
||||
public abstract void execute();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public final class Protocol {
|
||||
|
||||
private static final String ASK_RESPONSE = "ASK";
|
||||
private static final String MOVED_RESPONSE = "MOVED";
|
||||
public static final int DEFAULT_PORT = 6379;
|
||||
public static final int DEFAULT_PORT = 6379;
|
||||
public static final int DEFAULT_SENTINEL_PORT = 26379;
|
||||
public static final int DEFAULT_TIMEOUT = 2000;
|
||||
public static final int DEFAULT_DATABASE = 0;
|
||||
@@ -48,7 +48,10 @@ public final class Protocol {
|
||||
public static final String CLUSTER_SETSLOT_NODE = "node";
|
||||
public static final String CLUSTER_SETSLOT_MIGRATING = "migrating";
|
||||
public static final String CLUSTER_SETSLOT_IMPORTING = "importing";
|
||||
|
||||
public static final String PUBSUB_CHANNELS= "channels";
|
||||
public static final String PUBSUB_NUMSUB = "numsub";
|
||||
public static final String PUBSUB_NUM_PAT = "numpat";
|
||||
|
||||
private Protocol() {
|
||||
// this prevent the class from instantiation
|
||||
}
|
||||
@@ -80,27 +83,32 @@ public final class Protocol {
|
||||
}
|
||||
|
||||
private static void processError(final RedisInputStream is) {
|
||||
String message = is.readLine();
|
||||
//TODO: I'm not sure if this is the best way to do this.
|
||||
//Maybe Read only first 5 bytes instead?
|
||||
if (message.startsWith(MOVED_RESPONSE)) {
|
||||
String[] movedInfo = parseTargetHostAndSlot(message);
|
||||
throw new JedisMovedDataException(message, new HostAndPort(movedInfo[1], Integer.valueOf(movedInfo[2])), Integer.valueOf(movedInfo[0]));
|
||||
} else if (message.startsWith(ASK_RESPONSE)) {
|
||||
String[] askInfo = parseTargetHostAndSlot(message);
|
||||
throw new JedisAskDataException(message, new HostAndPort(askInfo[1], Integer.valueOf(askInfo[2])), Integer.valueOf(askInfo[0]));
|
||||
}
|
||||
throw new JedisDataException(message);
|
||||
String message = is.readLine();
|
||||
// TODO: I'm not sure if this is the best way to do this.
|
||||
// Maybe Read only first 5 bytes instead?
|
||||
if (message.startsWith(MOVED_RESPONSE)) {
|
||||
String[] movedInfo = parseTargetHostAndSlot(message);
|
||||
throw new JedisMovedDataException(message, new HostAndPort(
|
||||
movedInfo[1], Integer.valueOf(movedInfo[2])),
|
||||
Integer.valueOf(movedInfo[0]));
|
||||
} else if (message.startsWith(ASK_RESPONSE)) {
|
||||
String[] askInfo = parseTargetHostAndSlot(message);
|
||||
throw new JedisAskDataException(message, new HostAndPort(
|
||||
askInfo[1], Integer.valueOf(askInfo[2])),
|
||||
Integer.valueOf(askInfo[0]));
|
||||
}
|
||||
throw new JedisDataException(message);
|
||||
}
|
||||
|
||||
private static String[] parseTargetHostAndSlot(String clusterRedirectResponse) {
|
||||
String[] response = new String[3];
|
||||
String[] messageInfo = clusterRedirectResponse.split(" ");
|
||||
String[] targetHostAndPort = messageInfo[2].split(":");
|
||||
response[0] = messageInfo[1];
|
||||
response[1] = targetHostAndPort[0];
|
||||
response[2] = targetHostAndPort[1];
|
||||
return response;
|
||||
|
||||
private static String[] parseTargetHostAndSlot(
|
||||
String clusterRedirectResponse) {
|
||||
String[] response = new String[3];
|
||||
String[] messageInfo = clusterRedirectResponse.split(" ");
|
||||
String[] targetHostAndPort = messageInfo[2].split(":");
|
||||
response[0] = messageInfo[1];
|
||||
response[1] = targetHostAndPort[0];
|
||||
response[2] = targetHostAndPort[1];
|
||||
return response;
|
||||
}
|
||||
|
||||
private static Object process(final RedisInputStream is) {
|
||||
@@ -138,10 +146,11 @@ public final class Protocol {
|
||||
int offset = 0;
|
||||
try {
|
||||
while (offset < len) {
|
||||
int size = is.read(read, offset, (len - offset));
|
||||
if (size == -1)
|
||||
throw new JedisConnectionException("It seems like server has closed the connection.");
|
||||
offset += size;
|
||||
int size = is.read(read, offset, (len - offset));
|
||||
if (size == -1)
|
||||
throw new JedisConnectionException(
|
||||
"It seems like server has closed the connection.");
|
||||
offset += size;
|
||||
}
|
||||
// read 2 more bytes for the command delimiter
|
||||
is.readByte();
|
||||
@@ -195,7 +204,7 @@ public final class Protocol {
|
||||
}
|
||||
|
||||
public static enum Command {
|
||||
PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, SENTINEL, DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL, INCRBYFLOAT, PSETEX, CLIENT, TIME, MIGRATE, HINCRBYFLOAT, SCAN, HSCAN, SSCAN, ZSCAN, WAIT, CLUSTER, ASKING;
|
||||
PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, PUBSUB, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, SENTINEL, DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL, INCRBYFLOAT, PSETEX, CLIENT, TIME, MIGRATE, HINCRBYFLOAT, SCAN, HSCAN, SSCAN, ZSCAN, WAIT, CLUSTER, ASKING;
|
||||
|
||||
public final byte[] raw;
|
||||
|
||||
@@ -205,8 +214,7 @@ public final class Protocol {
|
||||
}
|
||||
|
||||
public static enum Keyword {
|
||||
AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT, RESET, FLUSH, EXISTS, LOAD, KILL, LEN, REFCOUNT, ENCODING, IDLETIME, AND, OR, XOR, NOT,
|
||||
GETNAME, SETNAME,LIST, MATCH, COUNT;
|
||||
AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT, RESET, FLUSH, EXISTS, LOAD, KILL, LEN, REFCOUNT, ENCODING, IDLETIME, AND, OR, XOR, NOT, GETNAME, SETNAME, LIST, MATCH, COUNT;
|
||||
public final byte[] raw;
|
||||
|
||||
Keyword() {
|
||||
|
||||
@@ -7,21 +7,21 @@ public class Queable {
|
||||
private Queue<Response<?>> pipelinedResponses = new LinkedList<Response<?>>();
|
||||
|
||||
protected void clean() {
|
||||
pipelinedResponses.clear();
|
||||
pipelinedResponses.clear();
|
||||
}
|
||||
|
||||
protected Response<?> generateResponse(Object data) {
|
||||
Response<?> response = pipelinedResponses.poll();
|
||||
if (response != null) {
|
||||
response.set(data);
|
||||
}
|
||||
return response;
|
||||
Response<?> response = pipelinedResponses.poll();
|
||||
if (response != null) {
|
||||
response.set(data);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
protected <T> Response<T> getResponse(Builder<T> builder) {
|
||||
Response<T> lr = new Response<T>(builder);
|
||||
pipelinedResponses.add(lr);
|
||||
return lr;
|
||||
Response<T> lr = new Response<T>(builder);
|
||||
pipelinedResponses.add(lr);
|
||||
return lr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,10 +32,7 @@ public interface RedisPipeline {
|
||||
|
||||
Response<Boolean> getbit(String key, long offset);
|
||||
|
||||
|
||||
|
||||
Response<String> getrange(String key, long startOffset,
|
||||
long endOffset);
|
||||
Response<String> getrange(String key, long startOffset, long endOffset);
|
||||
|
||||
Response<String> getSet(String key, String value);
|
||||
|
||||
@@ -70,7 +67,7 @@ public interface RedisPipeline {
|
||||
Response<String> lindex(String key, long index);
|
||||
|
||||
Response<Long> linsert(String key, BinaryClient.LIST_POSITION where,
|
||||
String pivot, String value);
|
||||
String pivot, String value);
|
||||
|
||||
Response<Long> llen(String key);
|
||||
|
||||
@@ -118,8 +115,7 @@ public interface RedisPipeline {
|
||||
|
||||
Response<List<String>> sort(String key);
|
||||
|
||||
Response<List<String>> sort(String key,
|
||||
SortingParams sortingParameters);
|
||||
Response<List<String>> sort(String key, SortingParams sortingParameters);
|
||||
|
||||
Response<String> spop(String key);
|
||||
|
||||
@@ -145,35 +141,31 @@ public interface RedisPipeline {
|
||||
|
||||
Response<Set<String>> zrange(String key, long start, long end);
|
||||
|
||||
Response<Set<String>> zrangeByScore(String key, double min,
|
||||
double max);
|
||||
Response<Set<String>> zrangeByScore(String key, double min, double max);
|
||||
|
||||
Response<Set<String>> zrangeByScore(String key, String min,
|
||||
String max);
|
||||
Response<Set<String>> zrangeByScore(String key, String min, String max);
|
||||
|
||||
Response<Set<String>> zrangeByScore(String key, double min,
|
||||
double max, int offset, int count);
|
||||
Response<Set<String>> zrangeByScore(String key, double min, double max,
|
||||
int offset, int count);
|
||||
|
||||
Response<Set<Tuple>> zrangeByScoreWithScores(String key, double min,
|
||||
double max);
|
||||
double max);
|
||||
|
||||
Response<Set<Tuple>> zrangeByScoreWithScores(String key, double min,
|
||||
double max, int offset, int count);
|
||||
double max, int offset, int count);
|
||||
|
||||
Response<Set<String>> zrevrangeByScore(String key, double max,
|
||||
double min);
|
||||
Response<Set<String>> zrevrangeByScore(String key, double max, double min);
|
||||
|
||||
Response<Set<String>> zrevrangeByScore(String key, String max,
|
||||
String min);
|
||||
Response<Set<String>> zrevrangeByScore(String key, String max, String min);
|
||||
|
||||
Response<Set<String>> zrevrangeByScore(String key, double max,
|
||||
double min, int offset, int count);
|
||||
Response<Set<String>> zrevrangeByScore(String key, double max, double min,
|
||||
int offset, int count);
|
||||
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(String key,
|
||||
double max, double min);
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(String key, double max,
|
||||
double min);
|
||||
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(String key,
|
||||
double max, double min, int offset, int count);
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(String key, double max,
|
||||
double min, int offset, int count);
|
||||
|
||||
Response<Set<Tuple>> zrangeWithScores(String key, long start, long end);
|
||||
|
||||
@@ -187,8 +179,7 @@ public interface RedisPipeline {
|
||||
|
||||
Response<Set<String>> zrevrange(String key, long start, long end);
|
||||
|
||||
Response<Set<Tuple>> zrevrangeWithScores(String key, long start,
|
||||
long end);
|
||||
Response<Set<Tuple>> zrevrangeWithScores(String key, long start, long end);
|
||||
|
||||
Response<Long> zrevrank(String key, String member);
|
||||
|
||||
|
||||
@@ -10,34 +10,34 @@ public class Response<T> {
|
||||
private Object data;
|
||||
|
||||
public Response(Builder<T> b) {
|
||||
this.builder = b;
|
||||
this.builder = b;
|
||||
}
|
||||
|
||||
public void set(Object data) {
|
||||
this.data = data;
|
||||
set = true;
|
||||
this.data = data;
|
||||
set = true;
|
||||
}
|
||||
|
||||
public T get() {
|
||||
if (!set) {
|
||||
throw new JedisDataException(
|
||||
"Please close pipeline or multi block before calling this method.");
|
||||
}
|
||||
if (!built) {
|
||||
if(data != null ){
|
||||
if (data instanceof JedisDataException){
|
||||
throw new JedisDataException((JedisDataException)data);
|
||||
}
|
||||
response = builder.build(data);
|
||||
}
|
||||
this.data = null;
|
||||
built = true;
|
||||
}
|
||||
return response;
|
||||
if (!set) {
|
||||
throw new JedisDataException(
|
||||
"Please close pipeline or multi block before calling this method.");
|
||||
}
|
||||
if (!built) {
|
||||
if (data != null) {
|
||||
if (data instanceof JedisDataException) {
|
||||
throw new JedisDataException((JedisDataException) data);
|
||||
}
|
||||
response = builder.build(data);
|
||||
}
|
||||
this.data = null;
|
||||
built = true;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Response " + builder.toString();
|
||||
return "Response " + builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
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.Map.Entry;
|
||||
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);
|
||||
@@ -38,8 +38,8 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||
}
|
||||
|
||||
public String echo(String string) {
|
||||
Jedis j = getShard(string);
|
||||
return j.echo(string);
|
||||
Jedis j = getShard(string);
|
||||
return j.echo(string);
|
||||
}
|
||||
|
||||
public Boolean exists(String key) {
|
||||
@@ -73,8 +73,8 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||
}
|
||||
|
||||
public Boolean setbit(String key, long offset, String value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.setbit(key, offset, value);
|
||||
Jedis j = getShard(key);
|
||||
return j.setbit(key, offset, value);
|
||||
}
|
||||
|
||||
public Boolean getbit(String key, long offset) {
|
||||
@@ -108,13 +108,13 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||
}
|
||||
|
||||
public List<String> blpop(String arg) {
|
||||
Jedis j = getShard(arg);
|
||||
return j.blpop(arg);
|
||||
Jedis j = getShard(arg);
|
||||
return j.blpop(arg);
|
||||
}
|
||||
|
||||
public List<String> brpop(String arg) {
|
||||
Jedis j = getShard(arg);
|
||||
return j.brpop(arg);
|
||||
Jedis j = getShard(arg);
|
||||
return j.brpop(arg);
|
||||
}
|
||||
|
||||
public Long decrBy(String key, long integer) {
|
||||
@@ -228,13 +228,13 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||
}
|
||||
|
||||
public Long strlen(final String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.strlen(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.strlen(key);
|
||||
}
|
||||
|
||||
public Long move(String key, int dbIndex) {
|
||||
Jedis j = getShard(key);
|
||||
return j.move(key, dbIndex);
|
||||
Jedis j = getShard(key);
|
||||
return j.move(key, dbIndex);
|
||||
}
|
||||
|
||||
public Long rpushx(String key, String... string) {
|
||||
@@ -243,8 +243,8 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||
}
|
||||
|
||||
public Long persist(final String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.persist(key);
|
||||
Jedis j = getShard(key);
|
||||
return j.persist(key);
|
||||
}
|
||||
|
||||
public Long llen(String key) {
|
||||
@@ -327,7 +327,7 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||
return j.zadd(key, score, member);
|
||||
}
|
||||
|
||||
public Long zadd(String key, Map<Double, String> scoreMembers) {
|
||||
public Long zadd(String key, Map<String, Double> scoreMembers) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zadd(key, scoreMembers);
|
||||
}
|
||||
@@ -527,12 +527,12 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||
Jedis j = getShard(key);
|
||||
return j.hscan(key, cursor);
|
||||
}
|
||||
|
||||
|
||||
public ScanResult<String> sscan(String key, int cursor) {
|
||||
Jedis j = getShard(key);
|
||||
return j.sscan(key, cursor);
|
||||
}
|
||||
|
||||
|
||||
public ScanResult<Tuple> zscan(String key, int cursor) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zscan(key, cursor);
|
||||
|
||||
@@ -11,27 +11,27 @@ public class ShardedJedisPipeline extends PipelineBase {
|
||||
private Queue<Client> clients = new LinkedList<Client>();
|
||||
|
||||
private static class FutureResult {
|
||||
private Client client;
|
||||
private Client client;
|
||||
|
||||
public FutureResult(Client client) {
|
||||
this.client = client;
|
||||
}
|
||||
public FutureResult(Client client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public Object get() {
|
||||
return client.getOne();
|
||||
}
|
||||
public Object get() {
|
||||
return client.getOne();
|
||||
}
|
||||
}
|
||||
|
||||
public void setShardedJedis(BinaryShardedJedis jedis) {
|
||||
this.jedis = jedis;
|
||||
this.jedis = jedis;
|
||||
}
|
||||
|
||||
public List<Object> getResults() {
|
||||
List<Object> r = new ArrayList<Object>();
|
||||
for (FutureResult fr : results) {
|
||||
r.add(fr.get());
|
||||
}
|
||||
return r;
|
||||
List<Object> r = new ArrayList<Object>();
|
||||
for (FutureResult fr : results) {
|
||||
r.add(fr.get());
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,30 +40,30 @@ public class ShardedJedisPipeline extends PipelineBase {
|
||||
* the different Response<?> of the commands you execute.
|
||||
*/
|
||||
public void sync() {
|
||||
for (Client client : clients) {
|
||||
generateResponse(client.getOne());
|
||||
}
|
||||
for (Client client : clients) {
|
||||
generateResponse(client.getOne());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncronize pipeline by reading all responses. This operation closes the
|
||||
* pipeline. Whenever possible try to avoid using this version and use
|
||||
* ShardedJedisPipeline.sync() as it won't go through all the responses and generate the
|
||||
* right response type (usually it is a waste of time).
|
||||
*
|
||||
* ShardedJedisPipeline.sync() as it won't go through all the responses and
|
||||
* generate the right response type (usually it is a waste of time).
|
||||
*
|
||||
* @return A list of all the responses in the order you executed them.
|
||||
*/
|
||||
public List<Object> syncAndReturnAll() {
|
||||
List<Object> formatted = new ArrayList<Object>();
|
||||
for (Client client : clients) {
|
||||
formatted.add(generateResponse(client.getOne()).get());
|
||||
}
|
||||
return formatted;
|
||||
List<Object> formatted = new ArrayList<Object>();
|
||||
for (Client client : clients) {
|
||||
formatted.add(generateResponse(client.getOne()).get());
|
||||
}
|
||||
return formatted;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be removed in Jedis 3.0. Use the methods that return Response's and call
|
||||
* sync().
|
||||
* This method will be removed in Jedis 3.0. Use the methods that return
|
||||
* Response's and call sync().
|
||||
*/
|
||||
@Deprecated
|
||||
public void execute() {
|
||||
@@ -71,17 +71,17 @@ public class ShardedJedisPipeline extends PipelineBase {
|
||||
|
||||
@Override
|
||||
protected Client getClient(String key) {
|
||||
Client client = jedis.getShard(key).getClient();
|
||||
clients.add(client);
|
||||
results.add(new FutureResult(client));
|
||||
return client;
|
||||
Client client = jedis.getShard(key).getClient();
|
||||
clients.add(client);
|
||||
results.add(new FutureResult(client));
|
||||
return client;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Client getClient(byte[] key) {
|
||||
Client client = jedis.getShard(key).getClient();
|
||||
clients.add(client);
|
||||
results.add(new FutureResult(client));
|
||||
return client;
|
||||
Client client = jedis.getShard(key).getClient();
|
||||
clients.add(client);
|
||||
results.add(new FutureResult(client));
|
||||
return client;
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public class SortingParams {
|
||||
* @return the SortingParams Object
|
||||
*/
|
||||
public SortingParams by(final String pattern) {
|
||||
return by(SafeEncoder.encode(pattern));
|
||||
return by(SafeEncoder.encode(pattern));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,9 +53,9 @@ public class SortingParams {
|
||||
* @return the SortingParams Object
|
||||
*/
|
||||
public SortingParams by(final byte[] pattern) {
|
||||
params.add(BY.raw);
|
||||
params.add(pattern);
|
||||
return this;
|
||||
params.add(BY.raw);
|
||||
params.add(pattern);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,13 +67,13 @@ public class SortingParams {
|
||||
* @return the SortingParams Object
|
||||
*/
|
||||
public SortingParams nosort() {
|
||||
params.add(BY.raw);
|
||||
params.add(NOSORT.raw);
|
||||
return this;
|
||||
params.add(BY.raw);
|
||||
params.add(NOSORT.raw);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Collection<byte[]> getParams() {
|
||||
return Collections.unmodifiableCollection(params);
|
||||
return Collections.unmodifiableCollection(params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,8 +82,8 @@ public class SortingParams {
|
||||
* @return the sortingParams Object
|
||||
*/
|
||||
public SortingParams desc() {
|
||||
params.add(DESC.raw);
|
||||
return this;
|
||||
params.add(DESC.raw);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,8 +92,8 @@ public class SortingParams {
|
||||
* @return the SortingParams Object
|
||||
*/
|
||||
public SortingParams asc() {
|
||||
params.add(ASC.raw);
|
||||
return this;
|
||||
params.add(ASC.raw);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,10 +105,10 @@ public class SortingParams {
|
||||
* @return the SortingParams Object
|
||||
*/
|
||||
public SortingParams limit(final int start, final int count) {
|
||||
params.add(LIMIT.raw);
|
||||
params.add(Protocol.toByteArray(start));
|
||||
params.add(Protocol.toByteArray(count));
|
||||
return this;
|
||||
params.add(LIMIT.raw);
|
||||
params.add(Protocol.toByteArray(start));
|
||||
params.add(Protocol.toByteArray(count));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,8 +118,8 @@ public class SortingParams {
|
||||
* @return the SortingParams Object
|
||||
*/
|
||||
public SortingParams alpha() {
|
||||
params.add(ALPHA.raw);
|
||||
return this;
|
||||
params.add(ALPHA.raw);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,11 +138,11 @@ public class SortingParams {
|
||||
* @return the SortingParams Object
|
||||
*/
|
||||
public SortingParams get(String... patterns) {
|
||||
for (final String pattern : patterns) {
|
||||
params.add(GET.raw);
|
||||
params.add(SafeEncoder.encode(pattern));
|
||||
}
|
||||
return this;
|
||||
for (final String pattern : patterns) {
|
||||
params.add(GET.raw);
|
||||
params.add(SafeEncoder.encode(pattern));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,10 +161,10 @@ public class SortingParams {
|
||||
* @return the SortingParams Object
|
||||
*/
|
||||
public SortingParams get(byte[]... patterns) {
|
||||
for (final byte[] pattern : patterns) {
|
||||
params.add(GET.raw);
|
||||
params.add(pattern);
|
||||
}
|
||||
return this;
|
||||
for (final byte[] pattern : patterns) {
|
||||
params.add(GET.raw);
|
||||
params.add(pattern);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -6,70 +6,71 @@ import java.util.List;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
|
||||
/**
|
||||
* Transaction is nearly identical to Pipeline, only differences are the multi/discard behaviors
|
||||
* Transaction is nearly identical to Pipeline, only differences are the
|
||||
* multi/discard behaviors
|
||||
*/
|
||||
public class Transaction extends MultiKeyPipelineBase {
|
||||
|
||||
protected boolean inTransaction = true;
|
||||
|
||||
protected Transaction(){
|
||||
// client will be set later in transaction block
|
||||
protected Transaction() {
|
||||
// client will be set later in transaction block
|
||||
}
|
||||
|
||||
public Transaction(final Client client) {
|
||||
this.client = client;
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Client getClient(String key) {
|
||||
return client;
|
||||
return client;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Client getClient(byte[] key) {
|
||||
return client;
|
||||
return client;
|
||||
}
|
||||
|
||||
public List<Object> exec() {
|
||||
client.exec();
|
||||
client.getAll(1); // Discard all but the last reply
|
||||
client.exec();
|
||||
client.getAll(1); // Discard all but the last reply
|
||||
|
||||
List<Object> unformatted = client.getObjectMultiBulkReply();
|
||||
if (unformatted == null) {
|
||||
return null;
|
||||
}
|
||||
List<Object> formatted = new ArrayList<Object>();
|
||||
for (Object o : unformatted) {
|
||||
try {
|
||||
formatted.add(generateResponse(o).get());
|
||||
} catch (JedisDataException e) {
|
||||
formatted.add(e);
|
||||
}
|
||||
}
|
||||
return formatted;
|
||||
List<Object> unformatted = client.getObjectMultiBulkReply();
|
||||
if (unformatted == null) {
|
||||
return null;
|
||||
}
|
||||
List<Object> formatted = new ArrayList<Object>();
|
||||
for (Object o : unformatted) {
|
||||
try {
|
||||
formatted.add(generateResponse(o).get());
|
||||
} catch (JedisDataException e) {
|
||||
formatted.add(e);
|
||||
}
|
||||
}
|
||||
return formatted;
|
||||
}
|
||||
|
||||
public List<Response<?>> execGetResponse() {
|
||||
client.exec();
|
||||
client.getAll(1); // Discard all but the last reply
|
||||
client.exec();
|
||||
client.getAll(1); // Discard all but the last reply
|
||||
|
||||
List<Object> unformatted = client.getObjectMultiBulkReply();
|
||||
if (unformatted == null) {
|
||||
return null;
|
||||
}
|
||||
List<Response<?>> response = new ArrayList<Response<?>>();
|
||||
for (Object o : unformatted) {
|
||||
response.add(generateResponse(o));
|
||||
}
|
||||
return response;
|
||||
List<Object> unformatted = client.getObjectMultiBulkReply();
|
||||
if (unformatted == null) {
|
||||
return null;
|
||||
}
|
||||
List<Response<?>> response = new ArrayList<Response<?>>();
|
||||
for (Object o : unformatted) {
|
||||
response.add(generateResponse(o));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
public String discard() {
|
||||
client.discard();
|
||||
client.getAll(1); // Discard all but the last reply
|
||||
inTransaction = false;
|
||||
clean();
|
||||
return client.getStatusCodeReply();
|
||||
client.discard();
|
||||
client.getAll(1); // Discard all but the last reply
|
||||
inTransaction = false;
|
||||
clean();
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,6 +13,6 @@ public abstract class TransactionBlock extends Transaction {
|
||||
public abstract void execute() throws JedisException;
|
||||
|
||||
public void setClient(Client client) {
|
||||
this.client = client;
|
||||
this.client = client;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,72 +9,72 @@ public class Tuple implements Comparable<Tuple> {
|
||||
private Double score;
|
||||
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result;
|
||||
if (null != element) {
|
||||
for (final byte b : element) {
|
||||
result = prime * result + b;
|
||||
}
|
||||
}
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(score);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result;
|
||||
if (null != element) {
|
||||
for (final byte b : element) {
|
||||
result = prime * result + b;
|
||||
}
|
||||
}
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(score);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Tuple other = (Tuple) obj;
|
||||
if (element == null) {
|
||||
if (other.element != null)
|
||||
return false;
|
||||
} else if (!Arrays.equals(element, other.element))
|
||||
return false;
|
||||
return true;
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Tuple other = (Tuple) obj;
|
||||
if (element == null) {
|
||||
if (other.element != null)
|
||||
return false;
|
||||
} else if (!Arrays.equals(element, other.element))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int compareTo(Tuple other) {
|
||||
if (Arrays.equals(this.element, other.element))
|
||||
return 0;
|
||||
else
|
||||
return this.score < other.getScore() ? -1 : 1;
|
||||
if (Arrays.equals(this.element, other.element))
|
||||
return 0;
|
||||
else
|
||||
return this.score < other.getScore() ? -1 : 1;
|
||||
}
|
||||
|
||||
public Tuple(String element, Double score) {
|
||||
super();
|
||||
this.element = SafeEncoder.encode(element);
|
||||
this.score = score;
|
||||
super();
|
||||
this.element = SafeEncoder.encode(element);
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public Tuple(byte[] element, Double score) {
|
||||
super();
|
||||
this.element = element;
|
||||
this.score = score;
|
||||
super();
|
||||
this.element = element;
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public String getElement() {
|
||||
if (null != element) {
|
||||
return SafeEncoder.encode(element);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
if (null != element) {
|
||||
return SafeEncoder.encode(element);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getBinaryElement() {
|
||||
return element;
|
||||
return element;
|
||||
}
|
||||
|
||||
public double getScore() {
|
||||
return score;
|
||||
return score;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return '[' + Arrays.toString(element) + ',' + score + ']';
|
||||
return '[' + Arrays.toString(element) + ',' + score + ']';
|
||||
}
|
||||
}
|
||||
@@ -12,33 +12,33 @@ import redis.clients.util.SafeEncoder;
|
||||
|
||||
public class ZParams {
|
||||
public enum Aggregate {
|
||||
SUM, MIN, MAX;
|
||||
SUM, MIN, MAX;
|
||||
|
||||
public final byte[] raw;
|
||||
public final byte[] raw;
|
||||
|
||||
Aggregate() {
|
||||
raw = SafeEncoder.encode(name());
|
||||
}
|
||||
Aggregate() {
|
||||
raw = SafeEncoder.encode(name());
|
||||
}
|
||||
}
|
||||
|
||||
private List<byte[]> params = new ArrayList<byte[]>();
|
||||
|
||||
public ZParams weights(final int... weights) {
|
||||
params.add(WEIGHTS.raw);
|
||||
for (final int weight : weights) {
|
||||
params.add(Protocol.toByteArray(weight));
|
||||
}
|
||||
params.add(WEIGHTS.raw);
|
||||
for (final int weight : weights) {
|
||||
params.add(Protocol.toByteArray(weight));
|
||||
}
|
||||
|
||||
return this;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Collection<byte[]> getParams() {
|
||||
return Collections.unmodifiableCollection(params);
|
||||
return Collections.unmodifiableCollection(params);
|
||||
}
|
||||
|
||||
public ZParams aggregate(final Aggregate aggregate) {
|
||||
params.add(AGGREGATE.raw);
|
||||
params.add(aggregate.raw);
|
||||
return this;
|
||||
params.add(AGGREGATE.raw);
|
||||
params.add(aggregate.raw);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,17 +4,20 @@ import redis.clients.jedis.HostAndPort;
|
||||
|
||||
public class JedisAskDataException extends JedisRedirectionException {
|
||||
private static final long serialVersionUID = 3878126572474819403L;
|
||||
|
||||
public JedisAskDataException(Throwable cause, HostAndPort targetHost, int slot) {
|
||||
super(cause, targetHost, slot);
|
||||
|
||||
public JedisAskDataException(Throwable cause, HostAndPort targetHost,
|
||||
int slot) {
|
||||
super(cause, targetHost, slot);
|
||||
}
|
||||
|
||||
public JedisAskDataException(String message, Throwable cause, HostAndPort targetHost, int slot) {
|
||||
super(message, cause, targetHost, slot);
|
||||
public JedisAskDataException(String message, Throwable cause,
|
||||
HostAndPort targetHost, int slot) {
|
||||
super(message, cause, targetHost, slot);
|
||||
}
|
||||
|
||||
public JedisAskDataException(String message, HostAndPort targetHost, int slot) {
|
||||
super(message, targetHost, slot);
|
||||
}
|
||||
public JedisAskDataException(String message, HostAndPort targetHost,
|
||||
int slot) {
|
||||
super(message, targetHost, slot);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
package redis.clients.jedis.exceptions;
|
||||
|
||||
|
||||
public class JedisClusterException extends JedisDataException {
|
||||
private static final long serialVersionUID = 3878126572474819403L;
|
||||
|
||||
|
||||
public JedisClusterException(Throwable cause) {
|
||||
super(cause);
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public JedisClusterException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public JedisClusterException(String message) {
|
||||
super(message);
|
||||
}
|
||||
public JedisClusterException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
package redis.clients.jedis.exceptions;
|
||||
|
||||
|
||||
public class JedisClusterMaxRedirectionsException extends JedisDataException {
|
||||
private static final long serialVersionUID = 3878126572474819403L;
|
||||
|
||||
|
||||
public JedisClusterMaxRedirectionsException(Throwable cause) {
|
||||
super(cause);
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public JedisClusterMaxRedirectionsException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public JedisClusterMaxRedirectionsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
public JedisClusterMaxRedirectionsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@ public class JedisConnectionException extends JedisException {
|
||||
private static final long serialVersionUID = 3878126572474819403L;
|
||||
|
||||
public JedisConnectionException(String message) {
|
||||
super(message);
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JedisConnectionException(Throwable cause) {
|
||||
super(cause);
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public JedisConnectionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@ public class JedisDataException extends JedisException {
|
||||
private static final long serialVersionUID = 3878126572474819403L;
|
||||
|
||||
public JedisDataException(String message) {
|
||||
super(message);
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JedisDataException(Throwable cause) {
|
||||
super(cause);
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public JedisDataException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
package redis.clients.jedis.exceptions;
|
||||
|
||||
|
||||
public class JedisException extends RuntimeException {
|
||||
private static final long serialVersionUID = -2946266495682282677L;
|
||||
|
||||
public JedisException(String message) {
|
||||
super(message);
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JedisException(Throwable e) {
|
||||
super(e);
|
||||
super(e);
|
||||
}
|
||||
|
||||
public JedisException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,20 +2,21 @@ package redis.clients.jedis.exceptions;
|
||||
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
|
||||
|
||||
public class JedisMovedDataException extends JedisRedirectionException {
|
||||
private static final long serialVersionUID = 3878126572474819403L;
|
||||
|
||||
|
||||
public JedisMovedDataException(String message, HostAndPort targetNode, int slot) {
|
||||
super(message, targetNode, slot);
|
||||
public JedisMovedDataException(String message, HostAndPort targetNode,
|
||||
int slot) {
|
||||
super(message, targetNode, slot);
|
||||
}
|
||||
|
||||
public JedisMovedDataException(Throwable cause, HostAndPort targetNode, int slot) {
|
||||
super(cause, targetNode, slot);
|
||||
public JedisMovedDataException(Throwable cause, HostAndPort targetNode,
|
||||
int slot) {
|
||||
super(cause, targetNode, slot);
|
||||
}
|
||||
|
||||
public JedisMovedDataException(String message, Throwable cause, HostAndPort targetNode, int slot) {
|
||||
super(message, cause, targetNode, slot);
|
||||
public JedisMovedDataException(String message, Throwable cause,
|
||||
HostAndPort targetNode, int slot) {
|
||||
super(message, cause, targetNode, slot);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,36 +2,38 @@ package redis.clients.jedis.exceptions;
|
||||
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
|
||||
|
||||
public class JedisRedirectionException extends JedisDataException {
|
||||
private static final long serialVersionUID = 3878126572474819403L;
|
||||
|
||||
|
||||
private HostAndPort targetNode;
|
||||
private int slot;
|
||||
|
||||
public JedisRedirectionException(String message, HostAndPort targetNode, int slot) {
|
||||
super(message);
|
||||
this.targetNode = targetNode;
|
||||
this.slot = slot;
|
||||
public JedisRedirectionException(String message, HostAndPort targetNode,
|
||||
int slot) {
|
||||
super(message);
|
||||
this.targetNode = targetNode;
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
public JedisRedirectionException(Throwable cause, HostAndPort targetNode, int slot) {
|
||||
super(cause);
|
||||
this.targetNode = targetNode;
|
||||
this.slot = slot;
|
||||
public JedisRedirectionException(Throwable cause, HostAndPort targetNode,
|
||||
int slot) {
|
||||
super(cause);
|
||||
this.targetNode = targetNode;
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
public JedisRedirectionException(String message, Throwable cause, HostAndPort targetNode, int slot) {
|
||||
super(message, cause);
|
||||
this.targetNode = targetNode;
|
||||
this.slot = slot;
|
||||
public JedisRedirectionException(String message, Throwable cause,
|
||||
HostAndPort targetNode, int slot) {
|
||||
super(message, cause);
|
||||
this.targetNode = targetNode;
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
public HostAndPort getTargetNode() {
|
||||
return targetNode;
|
||||
}
|
||||
public HostAndPort getTargetNode() {
|
||||
return targetNode;
|
||||
}
|
||||
|
||||
public int getSlot() {
|
||||
return slot;
|
||||
}
|
||||
public int getSlot() {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,28 +8,28 @@ public interface Hashing {
|
||||
public ThreadLocal<MessageDigest> md5Holder = new ThreadLocal<MessageDigest>();
|
||||
|
||||
public static final Hashing MD5 = new Hashing() {
|
||||
public long hash(String key) {
|
||||
return hash(SafeEncoder.encode(key));
|
||||
}
|
||||
public long hash(String key) {
|
||||
return hash(SafeEncoder.encode(key));
|
||||
}
|
||||
|
||||
public long hash(byte[] key) {
|
||||
try {
|
||||
if (md5Holder.get() == null) {
|
||||
md5Holder.set(MessageDigest.getInstance("MD5"));
|
||||
}
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new IllegalStateException("++++ no md5 algorythm found");
|
||||
}
|
||||
MessageDigest md5 = md5Holder.get();
|
||||
public long hash(byte[] key) {
|
||||
try {
|
||||
if (md5Holder.get() == null) {
|
||||
md5Holder.set(MessageDigest.getInstance("MD5"));
|
||||
}
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new IllegalStateException("++++ no md5 algorythm found");
|
||||
}
|
||||
MessageDigest md5 = md5Holder.get();
|
||||
|
||||
md5.reset();
|
||||
md5.update(key);
|
||||
byte[] bKey = md5.digest();
|
||||
long res = ((long) (bKey[3] & 0xFF) << 24)
|
||||
| ((long) (bKey[2] & 0xFF) << 16)
|
||||
| ((long) (bKey[1] & 0xFF) << 8) | (long) (bKey[0] & 0xFF);
|
||||
return res;
|
||||
}
|
||||
md5.reset();
|
||||
md5.update(key);
|
||||
byte[] bKey = md5.digest();
|
||||
long res = ((long) (bKey[3] & 0xFF) << 24)
|
||||
| ((long) (bKey[2] & 0xFF) << 16)
|
||||
| ((long) (bKey[1] & 0xFF) << 8) | (long) (bKey[0] & 0xFF);
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
public long hash(String key);
|
||||
|
||||
@@ -10,127 +10,127 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class JedisByteHashMap implements Map<byte[], byte[]>, Cloneable,
|
||||
Serializable {
|
||||
Serializable {
|
||||
private static final long serialVersionUID = -6971431362627219416L;
|
||||
private Map<ByteArrayWrapper, byte[]> internalMap = new HashMap<ByteArrayWrapper, byte[]>();
|
||||
|
||||
public void clear() {
|
||||
internalMap.clear();
|
||||
internalMap.clear();
|
||||
}
|
||||
|
||||
public boolean containsKey(Object key) {
|
||||
if (key instanceof byte[])
|
||||
return internalMap.containsKey(new ByteArrayWrapper((byte[]) key));
|
||||
return internalMap.containsKey(key);
|
||||
if (key instanceof byte[])
|
||||
return internalMap.containsKey(new ByteArrayWrapper((byte[]) key));
|
||||
return internalMap.containsKey(key);
|
||||
}
|
||||
|
||||
public boolean containsValue(Object value) {
|
||||
return internalMap.containsValue(value);
|
||||
return internalMap.containsValue(value);
|
||||
}
|
||||
|
||||
public Set<java.util.Map.Entry<byte[], byte[]>> entrySet() {
|
||||
Iterator<java.util.Map.Entry<ByteArrayWrapper, byte[]>> iterator = internalMap
|
||||
.entrySet().iterator();
|
||||
HashSet<Entry<byte[], byte[]>> hashSet = new HashSet<java.util.Map.Entry<byte[], byte[]>>();
|
||||
while (iterator.hasNext()) {
|
||||
Entry<ByteArrayWrapper, byte[]> entry = iterator.next();
|
||||
hashSet.add(new JedisByteEntry(entry.getKey().data, entry
|
||||
.getValue()));
|
||||
}
|
||||
return hashSet;
|
||||
Iterator<java.util.Map.Entry<ByteArrayWrapper, byte[]>> iterator = internalMap
|
||||
.entrySet().iterator();
|
||||
HashSet<Entry<byte[], byte[]>> hashSet = new HashSet<java.util.Map.Entry<byte[], byte[]>>();
|
||||
while (iterator.hasNext()) {
|
||||
Entry<ByteArrayWrapper, byte[]> entry = iterator.next();
|
||||
hashSet.add(new JedisByteEntry(entry.getKey().data, entry
|
||||
.getValue()));
|
||||
}
|
||||
return hashSet;
|
||||
}
|
||||
|
||||
public byte[] get(Object key) {
|
||||
if (key instanceof byte[])
|
||||
return internalMap.get(new ByteArrayWrapper((byte[]) key));
|
||||
return internalMap.get(key);
|
||||
if (key instanceof byte[])
|
||||
return internalMap.get(new ByteArrayWrapper((byte[]) key));
|
||||
return internalMap.get(key);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return internalMap.isEmpty();
|
||||
return internalMap.isEmpty();
|
||||
}
|
||||
|
||||
public Set<byte[]> keySet() {
|
||||
Set<byte[]> keySet = new HashSet<byte[]>();
|
||||
Iterator<ByteArrayWrapper> iterator = internalMap.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
keySet.add(iterator.next().data);
|
||||
}
|
||||
return keySet;
|
||||
Set<byte[]> keySet = new HashSet<byte[]>();
|
||||
Iterator<ByteArrayWrapper> iterator = internalMap.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
keySet.add(iterator.next().data);
|
||||
}
|
||||
return keySet;
|
||||
}
|
||||
|
||||
public byte[] put(byte[] key, byte[] value) {
|
||||
return internalMap.put(new ByteArrayWrapper(key), value);
|
||||
return internalMap.put(new ByteArrayWrapper(key), value);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void putAll(Map<? extends byte[], ? extends byte[]> m) {
|
||||
Iterator<?> iterator = m.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Entry<? extends byte[], ? extends byte[]> next = (Entry<? extends byte[], ? extends byte[]>) iterator
|
||||
.next();
|
||||
internalMap.put(new ByteArrayWrapper(next.getKey()), next
|
||||
.getValue());
|
||||
}
|
||||
Iterator<?> iterator = m.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Entry<? extends byte[], ? extends byte[]> next = (Entry<? extends byte[], ? extends byte[]>) iterator
|
||||
.next();
|
||||
internalMap.put(new ByteArrayWrapper(next.getKey()),
|
||||
next.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] remove(Object key) {
|
||||
if (key instanceof byte[])
|
||||
return internalMap.remove(new ByteArrayWrapper((byte[]) key));
|
||||
return internalMap.remove(key);
|
||||
if (key instanceof byte[])
|
||||
return internalMap.remove(new ByteArrayWrapper((byte[]) key));
|
||||
return internalMap.remove(key);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return internalMap.size();
|
||||
return internalMap.size();
|
||||
}
|
||||
|
||||
public Collection<byte[]> values() {
|
||||
return internalMap.values();
|
||||
return internalMap.values();
|
||||
}
|
||||
|
||||
private static final class ByteArrayWrapper {
|
||||
private final byte[] data;
|
||||
private final byte[] data;
|
||||
|
||||
public ByteArrayWrapper(byte[] data) {
|
||||
if (data == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
this.data = data;
|
||||
}
|
||||
public ByteArrayWrapper(byte[] data) {
|
||||
if (data == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof ByteArrayWrapper)) {
|
||||
return false;
|
||||
}
|
||||
return Arrays.equals(data, ((ByteArrayWrapper) other).data);
|
||||
}
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof ByteArrayWrapper)) {
|
||||
return false;
|
||||
}
|
||||
return Arrays.equals(data, ((ByteArrayWrapper) other).data);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(data);
|
||||
}
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(data);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class JedisByteEntry implements Entry<byte[], byte[]> {
|
||||
private byte[] value;
|
||||
private byte[] key;
|
||||
private byte[] value;
|
||||
private byte[] key;
|
||||
|
||||
public JedisByteEntry(byte[] key, byte[] value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
public JedisByteEntry(byte[] key, byte[] value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public byte[] getKey() {
|
||||
return this.key;
|
||||
}
|
||||
public byte[] getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public byte[] getValue() {
|
||||
return this.value;
|
||||
}
|
||||
public byte[] getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public byte[] setValue(byte[] value) {
|
||||
this.value = value;
|
||||
return value;
|
||||
}
|
||||
public byte[] setValue(byte[] value) {
|
||||
this.value = value;
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,23 @@
|
||||
package redis.clients.util;
|
||||
|
||||
public class JedisClusterCRC16 {
|
||||
public final static int polynomial = 0x1021; // Represents x^16+x^12+x^5+1
|
||||
static int crc;
|
||||
|
||||
public static int getSlot(String key) {
|
||||
crc = 0x0000;
|
||||
for (byte b : key.getBytes()) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
boolean bit = ((b >> (7-i) & 1) == 1);
|
||||
boolean c15 = ((crc >> 15 & 1) == 1);
|
||||
crc <<= 1;
|
||||
// If coefficient of bit and remainder polynomial = 1 xor crc with polynomial
|
||||
if (c15 ^ bit) crc ^= polynomial;
|
||||
}
|
||||
}
|
||||
public final static int polynomial = 0x1021; // Represents x^16+x^12+x^5+1
|
||||
static int crc;
|
||||
|
||||
return crc &= 0xffff % 16384;
|
||||
}
|
||||
public static int getSlot(String key) {
|
||||
crc = 0x0000;
|
||||
for (byte b : key.getBytes()) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
boolean bit = ((b >> (7 - i) & 1) == 1);
|
||||
boolean c15 = ((crc >> 15 & 1) == 1);
|
||||
crc <<= 1;
|
||||
// If coefficient of bit and remainder polynomial = 1 xor crc
|
||||
// with polynomial
|
||||
if (c15 ^ bit)
|
||||
crc ^= polynomial;
|
||||
}
|
||||
}
|
||||
|
||||
return crc &= 0xffff % 16384;
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class MurmurHash implements Hashing {
|
||||
* @return The 32 bit hash of the bytes in question.
|
||||
*/
|
||||
public static int hash(byte[] data, int seed) {
|
||||
return hash(ByteBuffer.wrap(data), seed);
|
||||
return hash(ByteBuffer.wrap(data), seed);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,7 +57,7 @@ public class MurmurHash implements Hashing {
|
||||
* @return The 32-bit hash of the data in question.
|
||||
*/
|
||||
public static int hash(byte[] data, int offset, int length, int seed) {
|
||||
return hash(ByteBuffer.wrap(data, offset, length), seed);
|
||||
return hash(ByteBuffer.wrap(data, offset, length), seed);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,97 +70,97 @@ public class MurmurHash implements Hashing {
|
||||
* @return The 32 bit murmur hash of the bytes in the buffer.
|
||||
*/
|
||||
public static int hash(ByteBuffer buf, int seed) {
|
||||
// save byte order for later restoration
|
||||
ByteOrder byteOrder = buf.order();
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
// save byte order for later restoration
|
||||
ByteOrder byteOrder = buf.order();
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
int m = 0x5bd1e995;
|
||||
int r = 24;
|
||||
int m = 0x5bd1e995;
|
||||
int r = 24;
|
||||
|
||||
int h = seed ^ buf.remaining();
|
||||
int h = seed ^ buf.remaining();
|
||||
|
||||
int k;
|
||||
while (buf.remaining() >= 4) {
|
||||
k = buf.getInt();
|
||||
int k;
|
||||
while (buf.remaining() >= 4) {
|
||||
k = buf.getInt();
|
||||
|
||||
k *= m;
|
||||
k ^= k >>> r;
|
||||
k *= m;
|
||||
k *= m;
|
||||
k ^= k >>> r;
|
||||
k *= m;
|
||||
|
||||
h *= m;
|
||||
h ^= k;
|
||||
}
|
||||
h *= m;
|
||||
h ^= k;
|
||||
}
|
||||
|
||||
if (buf.remaining() > 0) {
|
||||
ByteBuffer finish = ByteBuffer.allocate(4).order(
|
||||
ByteOrder.LITTLE_ENDIAN);
|
||||
// for big-endian version, use this first:
|
||||
// finish.position(4-buf.remaining());
|
||||
finish.put(buf).rewind();
|
||||
h ^= finish.getInt();
|
||||
h *= m;
|
||||
}
|
||||
if (buf.remaining() > 0) {
|
||||
ByteBuffer finish = ByteBuffer.allocate(4).order(
|
||||
ByteOrder.LITTLE_ENDIAN);
|
||||
// for big-endian version, use this first:
|
||||
// finish.position(4-buf.remaining());
|
||||
finish.put(buf).rewind();
|
||||
h ^= finish.getInt();
|
||||
h *= m;
|
||||
}
|
||||
|
||||
h ^= h >>> 13;
|
||||
h *= m;
|
||||
h ^= h >>> 15;
|
||||
h ^= h >>> 13;
|
||||
h *= m;
|
||||
h ^= h >>> 15;
|
||||
|
||||
buf.order(byteOrder);
|
||||
return h;
|
||||
buf.order(byteOrder);
|
||||
return h;
|
||||
}
|
||||
|
||||
public static long hash64A(byte[] data, int seed) {
|
||||
return hash64A(ByteBuffer.wrap(data), seed);
|
||||
return hash64A(ByteBuffer.wrap(data), seed);
|
||||
}
|
||||
|
||||
public static long hash64A(byte[] data, int offset, int length, int seed) {
|
||||
return hash64A(ByteBuffer.wrap(data, offset, length), seed);
|
||||
return hash64A(ByteBuffer.wrap(data, offset, length), seed);
|
||||
}
|
||||
|
||||
public static long hash64A(ByteBuffer buf, int seed) {
|
||||
ByteOrder byteOrder = buf.order();
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
ByteOrder byteOrder = buf.order();
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
long m = 0xc6a4a7935bd1e995L;
|
||||
int r = 47;
|
||||
long m = 0xc6a4a7935bd1e995L;
|
||||
int r = 47;
|
||||
|
||||
long h = seed ^ (buf.remaining() * m);
|
||||
long h = seed ^ (buf.remaining() * m);
|
||||
|
||||
long k;
|
||||
while (buf.remaining() >= 8) {
|
||||
k = buf.getLong();
|
||||
long k;
|
||||
while (buf.remaining() >= 8) {
|
||||
k = buf.getLong();
|
||||
|
||||
k *= m;
|
||||
k ^= k >>> r;
|
||||
k *= m;
|
||||
k *= m;
|
||||
k ^= k >>> r;
|
||||
k *= m;
|
||||
|
||||
h ^= k;
|
||||
h *= m;
|
||||
}
|
||||
h ^= k;
|
||||
h *= m;
|
||||
}
|
||||
|
||||
if (buf.remaining() > 0) {
|
||||
ByteBuffer finish = ByteBuffer.allocate(8).order(
|
||||
ByteOrder.LITTLE_ENDIAN);
|
||||
// for big-endian version, do this first:
|
||||
// finish.position(8-buf.remaining());
|
||||
finish.put(buf).rewind();
|
||||
h ^= finish.getLong();
|
||||
h *= m;
|
||||
}
|
||||
if (buf.remaining() > 0) {
|
||||
ByteBuffer finish = ByteBuffer.allocate(8).order(
|
||||
ByteOrder.LITTLE_ENDIAN);
|
||||
// for big-endian version, do this first:
|
||||
// finish.position(8-buf.remaining());
|
||||
finish.put(buf).rewind();
|
||||
h ^= finish.getLong();
|
||||
h *= m;
|
||||
}
|
||||
|
||||
h ^= h >>> r;
|
||||
h *= m;
|
||||
h ^= h >>> r;
|
||||
h ^= h >>> r;
|
||||
h *= m;
|
||||
h ^= h >>> r;
|
||||
|
||||
buf.order(byteOrder);
|
||||
return h;
|
||||
buf.order(byteOrder);
|
||||
return h;
|
||||
}
|
||||
|
||||
public long hash(byte[] key) {
|
||||
return hash64A(key, 0x1234ABCD);
|
||||
return hash64A(key, 0x1234ABCD);
|
||||
}
|
||||
|
||||
public long hash(String key) {
|
||||
return hash(SafeEncoder.encode(key));
|
||||
return hash(SafeEncoder.encode(key));
|
||||
}
|
||||
}
|
||||
@@ -29,84 +29,84 @@ public class RedisInputStream extends FilterInputStream {
|
||||
protected int count, limit;
|
||||
|
||||
public RedisInputStream(InputStream in, int size) {
|
||||
super(in);
|
||||
if (size <= 0) {
|
||||
throw new IllegalArgumentException("Buffer size <= 0");
|
||||
}
|
||||
buf = new byte[size];
|
||||
super(in);
|
||||
if (size <= 0) {
|
||||
throw new IllegalArgumentException("Buffer size <= 0");
|
||||
}
|
||||
buf = new byte[size];
|
||||
}
|
||||
|
||||
public RedisInputStream(InputStream in) {
|
||||
this(in, 8192);
|
||||
this(in, 8192);
|
||||
}
|
||||
|
||||
public byte readByte() throws IOException {
|
||||
if (count == limit) {
|
||||
fill();
|
||||
}
|
||||
if (count == limit) {
|
||||
fill();
|
||||
}
|
||||
|
||||
return buf[count++];
|
||||
return buf[count++];
|
||||
}
|
||||
|
||||
public String readLine() {
|
||||
int b;
|
||||
byte c;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int b;
|
||||
byte c;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
if (count == limit) {
|
||||
fill();
|
||||
}
|
||||
if (limit == -1)
|
||||
break;
|
||||
try {
|
||||
while (true) {
|
||||
if (count == limit) {
|
||||
fill();
|
||||
}
|
||||
if (limit == -1)
|
||||
break;
|
||||
|
||||
b = buf[count++];
|
||||
if (b == '\r') {
|
||||
if (count == limit) {
|
||||
fill();
|
||||
}
|
||||
b = buf[count++];
|
||||
if (b == '\r') {
|
||||
if (count == limit) {
|
||||
fill();
|
||||
}
|
||||
|
||||
if (limit == -1) {
|
||||
sb.append((char) b);
|
||||
break;
|
||||
}
|
||||
if (limit == -1) {
|
||||
sb.append((char) b);
|
||||
break;
|
||||
}
|
||||
|
||||
c = buf[count++];
|
||||
if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
sb.append((char) b);
|
||||
sb.append((char) c);
|
||||
} else {
|
||||
sb.append((char) b);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
String reply = sb.toString();
|
||||
if (reply.length() == 0) {
|
||||
throw new JedisConnectionException(
|
||||
"It seems like server has closed the connection.");
|
||||
}
|
||||
return reply;
|
||||
c = buf[count++];
|
||||
if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
sb.append((char) b);
|
||||
sb.append((char) c);
|
||||
} else {
|
||||
sb.append((char) b);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
String reply = sb.toString();
|
||||
if (reply.length() == 0) {
|
||||
throw new JedisConnectionException(
|
||||
"It seems like server has closed the connection.");
|
||||
}
|
||||
return reply;
|
||||
}
|
||||
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
if (count == limit) {
|
||||
fill();
|
||||
if (limit == -1)
|
||||
return -1;
|
||||
}
|
||||
final int length = Math.min(limit - count, len);
|
||||
System.arraycopy(buf, count, b, off, length);
|
||||
count += length;
|
||||
return length;
|
||||
if (count == limit) {
|
||||
fill();
|
||||
if (limit == -1)
|
||||
return -1;
|
||||
}
|
||||
final int length = Math.min(limit - count, len);
|
||||
System.arraycopy(buf, count, b, off, length);
|
||||
count += length;
|
||||
return length;
|
||||
}
|
||||
|
||||
private void fill() throws IOException {
|
||||
limit = in.read(buf);
|
||||
count = 0;
|
||||
limit = in.read(buf);
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package redis.clients.util;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* The class implements a buffered output stream without synchronization
|
||||
* There are also special operations like in-place string encoding.
|
||||
* This stream fully ignore mark/reset and should not be used outside Jedis
|
||||
* The class implements a buffered output stream without synchronization There
|
||||
* are also special operations like in-place string encoding. This stream fully
|
||||
* ignore mark/reset and should not be used outside Jedis
|
||||
*/
|
||||
public final class RedisOutputStream extends FilterOutputStream {
|
||||
protected final byte buf[];
|
||||
@@ -13,218 +15,212 @@ public final class RedisOutputStream extends FilterOutputStream {
|
||||
protected int count;
|
||||
|
||||
public RedisOutputStream(final OutputStream out) {
|
||||
this(out, 8192);
|
||||
this(out, 8192);
|
||||
}
|
||||
|
||||
public RedisOutputStream(final OutputStream out, final int size) {
|
||||
super(out);
|
||||
if (size <= 0) {
|
||||
throw new IllegalArgumentException("Buffer size <= 0");
|
||||
}
|
||||
buf = new byte[size];
|
||||
super(out);
|
||||
if (size <= 0) {
|
||||
throw new IllegalArgumentException("Buffer size <= 0");
|
||||
}
|
||||
buf = new byte[size];
|
||||
}
|
||||
|
||||
private void flushBuffer() throws IOException {
|
||||
if (count > 0) {
|
||||
out.write(buf, 0, count);
|
||||
count = 0;
|
||||
}
|
||||
if (count > 0) {
|
||||
out.write(buf, 0, count);
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void write(final byte b) throws IOException {
|
||||
buf[count++] = b;
|
||||
if (count == buf.length) {
|
||||
flushBuffer();
|
||||
}
|
||||
buf[count++] = b;
|
||||
if (count == buf.length) {
|
||||
flushBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void write(final byte[] b) throws IOException {
|
||||
write(b, 0, b.length);
|
||||
write(b, 0, b.length);
|
||||
}
|
||||
|
||||
public void write(final byte b[], final int off, final int len) throws IOException {
|
||||
if (len >= buf.length) {
|
||||
flushBuffer();
|
||||
out.write(b, off, len);
|
||||
} else {
|
||||
if (len >= buf.length - count) {
|
||||
flushBuffer();
|
||||
}
|
||||
public void write(final byte b[], final int off, final int len)
|
||||
throws IOException {
|
||||
if (len >= buf.length) {
|
||||
flushBuffer();
|
||||
out.write(b, off, len);
|
||||
} else {
|
||||
if (len >= buf.length - count) {
|
||||
flushBuffer();
|
||||
}
|
||||
|
||||
System.arraycopy(b, off, buf, count, len);
|
||||
count += len;
|
||||
}
|
||||
System.arraycopy(b, off, buf, count, len);
|
||||
count += len;
|
||||
}
|
||||
}
|
||||
|
||||
public void writeAsciiCrLf(final String in) throws IOException {
|
||||
final int size = in.length();
|
||||
final int size = in.length();
|
||||
|
||||
for (int i = 0; i != size; ++i) {
|
||||
buf[count++] = (byte) in.charAt(i);
|
||||
if (count == buf.length) {
|
||||
flushBuffer();
|
||||
}
|
||||
}
|
||||
for (int i = 0; i != size; ++i) {
|
||||
buf[count++] = (byte) in.charAt(i);
|
||||
if (count == buf.length) {
|
||||
flushBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
writeCrLf();
|
||||
writeCrLf();
|
||||
}
|
||||
|
||||
public static boolean isSurrogate(final char ch) {
|
||||
return ch >= Character.MIN_SURROGATE && ch <= Character.MAX_SURROGATE;
|
||||
return ch >= Character.MIN_SURROGATE && ch <= Character.MAX_SURROGATE;
|
||||
}
|
||||
|
||||
public static int utf8Length (final String str) {
|
||||
int strLen = str.length(), utfLen = 0;
|
||||
for(int i = 0; i != strLen; ++i) {
|
||||
char c = str.charAt(i);
|
||||
if (c < 0x80) {
|
||||
utfLen++;
|
||||
} else if (c < 0x800) {
|
||||
utfLen += 2;
|
||||
} else if (isSurrogate(c)) {
|
||||
i++;
|
||||
utfLen += 4;
|
||||
} else {
|
||||
utfLen += 3;
|
||||
}
|
||||
}
|
||||
return utfLen;
|
||||
public static int utf8Length(final String str) {
|
||||
int strLen = str.length(), utfLen = 0;
|
||||
for (int i = 0; i != strLen; ++i) {
|
||||
char c = str.charAt(i);
|
||||
if (c < 0x80) {
|
||||
utfLen++;
|
||||
} else if (c < 0x800) {
|
||||
utfLen += 2;
|
||||
} else if (isSurrogate(c)) {
|
||||
i++;
|
||||
utfLen += 4;
|
||||
} else {
|
||||
utfLen += 3;
|
||||
}
|
||||
}
|
||||
return utfLen;
|
||||
}
|
||||
|
||||
public void writeCrLf() throws IOException {
|
||||
if (2 >= buf.length - count) {
|
||||
flushBuffer();
|
||||
}
|
||||
if (2 >= buf.length - count) {
|
||||
flushBuffer();
|
||||
}
|
||||
|
||||
buf[count++] = '\r';
|
||||
buf[count++] = '\n';
|
||||
buf[count++] = '\r';
|
||||
buf[count++] = '\n';
|
||||
}
|
||||
|
||||
public void writeUtf8CrLf(final String str) throws IOException {
|
||||
int strLen = str.length();
|
||||
int strLen = str.length();
|
||||
|
||||
int i;
|
||||
for (i = 0; i < strLen; i++) {
|
||||
char c = str.charAt(i);
|
||||
if (!(c < 0x80)) break;
|
||||
buf[count++] = (byte) c;
|
||||
if(count == buf.length) {
|
||||
flushBuffer();
|
||||
}
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < strLen; i++) {
|
||||
char c = str.charAt(i);
|
||||
if (!(c < 0x80))
|
||||
break;
|
||||
buf[count++] = (byte) c;
|
||||
if (count == buf.length) {
|
||||
flushBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
for (; i < strLen; i++) {
|
||||
char c = str.charAt(i);
|
||||
if (c < 0x80) {
|
||||
buf[count++] = (byte) c;
|
||||
if(count == buf.length) {
|
||||
flushBuffer();
|
||||
}
|
||||
} else if (c < 0x800) {
|
||||
if(2 >= buf.length - count) {
|
||||
flushBuffer();
|
||||
}
|
||||
buf[count++] = (byte)(0xc0 | (c >> 6));
|
||||
buf[count++] = (byte)(0x80 | (c & 0x3f));
|
||||
} else if (isSurrogate(c)) {
|
||||
if(4 >= buf.length - count) {
|
||||
flushBuffer();
|
||||
}
|
||||
int uc = Character.toCodePoint(c, str.charAt(i++));
|
||||
buf[count++] = ((byte)(0xf0 | ((uc >> 18))));
|
||||
buf[count++] = ((byte)(0x80 | ((uc >> 12) & 0x3f)));
|
||||
buf[count++] = ((byte)(0x80 | ((uc >> 6) & 0x3f)));
|
||||
buf[count++] = ((byte)(0x80 | (uc & 0x3f)));
|
||||
} else {
|
||||
if(3 >= buf.length - count) {
|
||||
flushBuffer();
|
||||
}
|
||||
buf[count++] =((byte)(0xe0 | ((c >> 12))));
|
||||
buf[count++] =((byte)(0x80 | ((c >> 6) & 0x3f)));
|
||||
buf[count++] =((byte)(0x80 | (c & 0x3f)));
|
||||
}
|
||||
}
|
||||
for (; i < strLen; i++) {
|
||||
char c = str.charAt(i);
|
||||
if (c < 0x80) {
|
||||
buf[count++] = (byte) c;
|
||||
if (count == buf.length) {
|
||||
flushBuffer();
|
||||
}
|
||||
} else if (c < 0x800) {
|
||||
if (2 >= buf.length - count) {
|
||||
flushBuffer();
|
||||
}
|
||||
buf[count++] = (byte) (0xc0 | (c >> 6));
|
||||
buf[count++] = (byte) (0x80 | (c & 0x3f));
|
||||
} else if (isSurrogate(c)) {
|
||||
if (4 >= buf.length - count) {
|
||||
flushBuffer();
|
||||
}
|
||||
int uc = Character.toCodePoint(c, str.charAt(i++));
|
||||
buf[count++] = ((byte) (0xf0 | ((uc >> 18))));
|
||||
buf[count++] = ((byte) (0x80 | ((uc >> 12) & 0x3f)));
|
||||
buf[count++] = ((byte) (0x80 | ((uc >> 6) & 0x3f)));
|
||||
buf[count++] = ((byte) (0x80 | (uc & 0x3f)));
|
||||
} else {
|
||||
if (3 >= buf.length - count) {
|
||||
flushBuffer();
|
||||
}
|
||||
buf[count++] = ((byte) (0xe0 | ((c >> 12))));
|
||||
buf[count++] = ((byte) (0x80 | ((c >> 6) & 0x3f)));
|
||||
buf[count++] = ((byte) (0x80 | (c & 0x3f)));
|
||||
}
|
||||
}
|
||||
|
||||
writeCrLf();
|
||||
writeCrLf();
|
||||
}
|
||||
|
||||
private final static int[] sizeTable = {9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, Integer.MAX_VALUE};
|
||||
private final static int[] sizeTable = { 9, 99, 999, 9999, 99999, 999999,
|
||||
9999999, 99999999, 999999999, Integer.MAX_VALUE };
|
||||
|
||||
private final static byte[] DigitTens = {
|
||||
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
|
||||
'1', '1', '1', '1', '1', '1', '1', '1', '1', '1',
|
||||
'2', '2', '2', '2', '2', '2', '2', '2', '2', '2',
|
||||
'3', '3', '3', '3', '3', '3', '3', '3', '3', '3',
|
||||
'4', '4', '4', '4', '4', '4', '4', '4', '4', '4',
|
||||
'5', '5', '5', '5', '5', '5', '5', '5', '5', '5',
|
||||
'6', '6', '6', '6', '6', '6', '6', '6', '6', '6',
|
||||
'7', '7', '7', '7', '7', '7', '7', '7', '7', '7',
|
||||
'8', '8', '8', '8', '8', '8', '8', '8', '8', '8',
|
||||
'9', '9', '9', '9', '9', '9', '9', '9', '9', '9',
|
||||
};
|
||||
private final static byte[] DigitTens = { '0', '0', '0', '0', '0', '0',
|
||||
'0', '0', '0', '0', '1', '1', '1', '1', '1', '1', '1', '1', '1',
|
||||
'1', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '3', '3',
|
||||
'3', '3', '3', '3', '3', '3', '3', '3', '4', '4', '4', '4', '4',
|
||||
'4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '5', '5', '5',
|
||||
'5', '5', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '7',
|
||||
'7', '7', '7', '7', '7', '7', '7', '7', '7', '8', '8', '8', '8',
|
||||
'8', '8', '8', '8', '8', '8', '9', '9', '9', '9', '9', '9', '9',
|
||||
'9', '9', '9', };
|
||||
|
||||
private final static byte[] DigitOnes = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
};
|
||||
private final static byte[] DigitOnes = { '0', '1', '2', '3', '4', '5',
|
||||
'6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8',
|
||||
'9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1',
|
||||
'2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4',
|
||||
'5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
|
||||
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3',
|
||||
'4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6',
|
||||
'7', '8', '9', };
|
||||
|
||||
private final static byte[] digits = {
|
||||
'0', '1', '2', '3', '4', '5',
|
||||
'6', '7', '8', '9', 'a', 'b',
|
||||
'c', 'd', 'e', 'f', 'g', 'h',
|
||||
'i', 'j', 'k', 'l', 'm', 'n',
|
||||
'o', 'p', 'q', 'r', 's', 't',
|
||||
'u', 'v', 'w', 'x', 'y', 'z'
|
||||
};
|
||||
private final static byte[] digits = { '0', '1', '2', '3', '4', '5', '6',
|
||||
'7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
|
||||
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
|
||||
'x', 'y', 'z' };
|
||||
|
||||
public void writeIntCrLf(int value) throws IOException {
|
||||
if (value < 0) {
|
||||
write('-');
|
||||
value = -value;
|
||||
}
|
||||
if (value < 0) {
|
||||
write((byte) '-');
|
||||
value = -value;
|
||||
}
|
||||
|
||||
int size = 0;
|
||||
while (value > sizeTable[size])
|
||||
size++;
|
||||
int size = 0;
|
||||
while (value > sizeTable[size])
|
||||
size++;
|
||||
|
||||
size++;
|
||||
if (size >= buf.length - count) {
|
||||
flushBuffer();
|
||||
}
|
||||
size++;
|
||||
if (size >= buf.length - count) {
|
||||
flushBuffer();
|
||||
}
|
||||
|
||||
int q, r;
|
||||
int charPos = count + size;
|
||||
int q, r;
|
||||
int charPos = count + size;
|
||||
|
||||
while (value >= 65536) {
|
||||
q = value / 100;
|
||||
r = value - ((q << 6) + (q << 5) + (q << 2));
|
||||
value = q;
|
||||
buf[--charPos] = DigitOnes[r];
|
||||
buf[--charPos] = DigitTens[r];
|
||||
}
|
||||
while (value >= 65536) {
|
||||
q = value / 100;
|
||||
r = value - ((q << 6) + (q << 5) + (q << 2));
|
||||
value = q;
|
||||
buf[--charPos] = DigitOnes[r];
|
||||
buf[--charPos] = DigitTens[r];
|
||||
}
|
||||
|
||||
for (; ;) {
|
||||
q = (value * 52429) >>> (16 + 3);
|
||||
r = value - ((q << 3) + (q << 1));
|
||||
buf[--charPos] = digits[r];
|
||||
value = q;
|
||||
if (value == 0) break;
|
||||
}
|
||||
count += size;
|
||||
for (;;) {
|
||||
q = (value * 52429) >>> (16 + 3);
|
||||
r = value - ((q << 3) + (q << 1));
|
||||
buf[--charPos] = digits[r];
|
||||
value = q;
|
||||
if (value == 0)
|
||||
break;
|
||||
}
|
||||
count += size;
|
||||
|
||||
writeCrLf();
|
||||
writeCrLf();
|
||||
}
|
||||
|
||||
public void flush() throws IOException {
|
||||
flushBuffer();
|
||||
out.flush();
|
||||
flushBuffer();
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,31 +11,31 @@ 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[][] 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) {
|
||||
throw new JedisDataException(
|
||||
"value sent to redis cannot be null");
|
||||
}
|
||||
return str.getBytes(Protocol.CHARSET);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new JedisException(e);
|
||||
}
|
||||
try {
|
||||
if (str == null) {
|
||||
throw new JedisDataException(
|
||||
"value sent to redis cannot be null");
|
||||
}
|
||||
return str.getBytes(Protocol.CHARSET);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new JedisException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String encode(final byte[] data) {
|
||||
try {
|
||||
return new String(data, Protocol.CHARSET);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new JedisException(e);
|
||||
}
|
||||
try {
|
||||
return new String(data, Protocol.CHARSET);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new JedisException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,14 @@ public abstract class ShardInfo<T> {
|
||||
}
|
||||
|
||||
public ShardInfo(int weight) {
|
||||
this.weight = weight;
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public int getWeight() {
|
||||
return this.weight;
|
||||
return this.weight;
|
||||
}
|
||||
|
||||
protected abstract T createResource();
|
||||
|
||||
|
||||
public abstract String getName();
|
||||
}
|
||||
|
||||
@@ -26,91 +26,93 @@ public class Sharded<R, S extends ShardInfo<R>> {
|
||||
private Pattern tagPattern = null;
|
||||
// the tag is anything between {}
|
||||
public static final Pattern DEFAULT_KEY_TAG_PATTERN = Pattern
|
||||
.compile("\\{(.+?)\\}");
|
||||
.compile("\\{(.+?)\\}");
|
||||
|
||||
public Sharded(List<S> shards) {
|
||||
this(shards, Hashing.MURMUR_HASH); // MD5 is really not good as we works
|
||||
// with 64-bits not 128
|
||||
this(shards, Hashing.MURMUR_HASH); // MD5 is really not good as we works
|
||||
// with 64-bits not 128
|
||||
}
|
||||
|
||||
public Sharded(List<S> shards, Hashing algo) {
|
||||
this.algo = algo;
|
||||
initialize(shards);
|
||||
this.algo = algo;
|
||||
initialize(shards);
|
||||
}
|
||||
|
||||
public Sharded(List<S> shards, Pattern tagPattern) {
|
||||
this(shards, Hashing.MURMUR_HASH, tagPattern); // MD5 is really not good
|
||||
// as we works with
|
||||
// 64-bits not 128
|
||||
this(shards, Hashing.MURMUR_HASH, tagPattern); // MD5 is really not good
|
||||
// as we works with
|
||||
// 64-bits not 128
|
||||
}
|
||||
|
||||
public Sharded(List<S> shards, Hashing algo, Pattern tagPattern) {
|
||||
this.algo = algo;
|
||||
this.tagPattern = tagPattern;
|
||||
initialize(shards);
|
||||
this.algo = algo;
|
||||
this.tagPattern = tagPattern;
|
||||
initialize(shards);
|
||||
}
|
||||
|
||||
private void initialize(List<S> shards) {
|
||||
nodes = new TreeMap<Long, S>();
|
||||
nodes = new TreeMap<Long, S>();
|
||||
|
||||
for (int i = 0; i != shards.size(); ++i) {
|
||||
final S shardInfo = shards.get(i);
|
||||
if (shardInfo.getName() == null)
|
||||
for (int n = 0; n < 160 * shardInfo.getWeight(); n++) {
|
||||
nodes.put(this.algo.hash("SHARD-" + i + "-NODE-" + n), shardInfo);
|
||||
}
|
||||
else
|
||||
for (int n = 0; n < 160 * shardInfo.getWeight(); n++) {
|
||||
nodes.put(this.algo.hash(shardInfo.getName() + "*" + shardInfo.getWeight() + n), shardInfo);
|
||||
}
|
||||
resources.put(shardInfo, shardInfo.createResource());
|
||||
}
|
||||
for (int i = 0; i != shards.size(); ++i) {
|
||||
final S shardInfo = shards.get(i);
|
||||
if (shardInfo.getName() == null)
|
||||
for (int n = 0; n < 160 * shardInfo.getWeight(); n++) {
|
||||
nodes.put(this.algo.hash("SHARD-" + i + "-NODE-" + n),
|
||||
shardInfo);
|
||||
}
|
||||
else
|
||||
for (int n = 0; n < 160 * shardInfo.getWeight(); n++) {
|
||||
nodes.put(
|
||||
this.algo.hash(shardInfo.getName() + "*"
|
||||
+ shardInfo.getWeight() + n), shardInfo);
|
||||
}
|
||||
resources.put(shardInfo, shardInfo.createResource());
|
||||
}
|
||||
}
|
||||
|
||||
public R getShard(byte[] key) {
|
||||
return resources.get(getShardInfo(key));
|
||||
return resources.get(getShardInfo(key));
|
||||
}
|
||||
|
||||
public R getShard(String key) {
|
||||
return resources.get(getShardInfo(key));
|
||||
return resources.get(getShardInfo(key));
|
||||
}
|
||||
|
||||
public S getShardInfo(byte[] key) {
|
||||
SortedMap<Long, S> tail = nodes.tailMap(algo.hash(key));
|
||||
if (tail.isEmpty()) {
|
||||
return nodes.get(nodes.firstKey());
|
||||
}
|
||||
return tail.get(tail.firstKey());
|
||||
SortedMap<Long, S> tail = nodes.tailMap(algo.hash(key));
|
||||
if (tail.isEmpty()) {
|
||||
return nodes.get(nodes.firstKey());
|
||||
}
|
||||
return tail.get(tail.firstKey());
|
||||
}
|
||||
|
||||
public S getShardInfo(String key) {
|
||||
return getShardInfo(SafeEncoder.encode(getKeyTag(key)));
|
||||
return getShardInfo(SafeEncoder.encode(getKeyTag(key)));
|
||||
}
|
||||
|
||||
/**
|
||||
* A key tag is a special pattern inside a key that, if preset, is the only
|
||||
* part of the key hashed in order to select the server for this key.
|
||||
*
|
||||
*
|
||||
* @see http://code.google.com/p/redis/wiki/FAQ#I
|
||||
* 'm_using_some_form_of_key_hashing_for_partitioning,_but_wh
|
||||
* @param key
|
||||
* @return The tag if it exists, or the original key
|
||||
*/
|
||||
public String getKeyTag(String key) {
|
||||
if (tagPattern != null) {
|
||||
Matcher m = tagPattern.matcher(key);
|
||||
if (m.find())
|
||||
return m.group(1);
|
||||
}
|
||||
return key;
|
||||
if (tagPattern != null) {
|
||||
Matcher m = tagPattern.matcher(key);
|
||||
if (m.find())
|
||||
return m.group(1);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
public Collection<S> getAllShardInfo() {
|
||||
return Collections.unmodifiableCollection(nodes.values());
|
||||
return Collections.unmodifiableCollection(nodes.values());
|
||||
}
|
||||
|
||||
public Collection<R> getAllShards() {
|
||||
return Collections.unmodifiableCollection(resources.values());
|
||||
return Collections.unmodifiableCollection(resources.values());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,50 +4,50 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Slowlog {
|
||||
private final long id;
|
||||
private final long timeStamp;
|
||||
private final long executionTime;
|
||||
private final List<String> args;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Slowlog> from(List<Object> nestedMultiBulkReply){
|
||||
List<Slowlog> logs = new ArrayList<Slowlog>(nestedMultiBulkReply.size());
|
||||
for(Object obj : nestedMultiBulkReply){
|
||||
List<Object> properties = (List<Object>)obj;
|
||||
logs.add(new Slowlog(properties));
|
||||
}
|
||||
|
||||
return logs;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Slowlog(List<Object> properties) {
|
||||
super();
|
||||
this.id = (Long)properties.get(0);
|
||||
this.timeStamp = (Long)properties.get(1);
|
||||
this.executionTime = (Long)properties.get(2);
|
||||
|
||||
List<byte[]> bargs = (List<byte[]>)properties.get(3);
|
||||
this.args = new ArrayList<String>(bargs.size());
|
||||
|
||||
for(byte[] barg:bargs){
|
||||
this.args.add(SafeEncoder.encode(barg));
|
||||
}
|
||||
private final long id;
|
||||
private final long timeStamp;
|
||||
private final long executionTime;
|
||||
private final List<String> args;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Slowlog> from(List<Object> nestedMultiBulkReply) {
|
||||
List<Slowlog> logs = new ArrayList<Slowlog>(nestedMultiBulkReply.size());
|
||||
for (Object obj : nestedMultiBulkReply) {
|
||||
List<Object> properties = (List<Object>) obj;
|
||||
logs.add(new Slowlog(properties));
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
return logs;
|
||||
}
|
||||
|
||||
public long getTimeStamp() {
|
||||
return timeStamp;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
private Slowlog(List<Object> properties) {
|
||||
super();
|
||||
this.id = (Long) properties.get(0);
|
||||
this.timeStamp = (Long) properties.get(1);
|
||||
this.executionTime = (Long) properties.get(2);
|
||||
|
||||
public long getExecutionTime() {
|
||||
return executionTime;
|
||||
}
|
||||
List<byte[]> bargs = (List<byte[]>) properties.get(3);
|
||||
this.args = new ArrayList<String>(bargs.size());
|
||||
|
||||
public List<String> getArgs() {
|
||||
return args;
|
||||
for (byte[] barg : bargs) {
|
||||
this.args.add(SafeEncoder.encode(barg));
|
||||
}
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public long getTimeStamp() {
|
||||
return timeStamp;
|
||||
}
|
||||
|
||||
public long getExecutionTime() {
|
||||
return executionTime;
|
||||
}
|
||||
|
||||
public List<String> getArgs() {
|
||||
return args;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user