Reformat all files in the project according to java conventions.
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);
|
||||
|
||||
@@ -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 {
|
||||
@@ -88,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) {
|
||||
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);
|
||||
}
|
||||
@@ -383,12 +387,14 @@ public class BinaryClient extends Connection {
|
||||
sendCommand(ZADD, key, toByteArray(score), member);
|
||||
}
|
||||
|
||||
public void zaddBinary(final byte[] key, final Map< byte[], Double> scoreMembers) {
|
||||
public void zaddBinary(final byte[] key,
|
||||
final Map<byte[], Double> scoreMembers) {
|
||||
|
||||
ArrayList<byte[]> args = new ArrayList<byte[]>(scoreMembers.size() * 2 + 1);
|
||||
ArrayList<byte[]> args = new ArrayList<byte[]>(
|
||||
scoreMembers.size() * 2 + 1);
|
||||
args.add(key);
|
||||
|
||||
for (Map.Entry<byte[],Double > entry : scoreMembers.entrySet()) {
|
||||
for (Map.Entry<byte[], Double> entry : scoreMembers.entrySet()) {
|
||||
args.add(toByteArray(entry.getValue()));
|
||||
args.add(entry.getKey());
|
||||
}
|
||||
@@ -557,8 +563,10 @@ public class BinaryClient extends Connection {
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -574,8 +582,10 @@ public class BinaryClient extends Connection {
|
||||
public void zrangeByScore(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(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax);
|
||||
}
|
||||
@@ -593,8 +603,10 @@ public class BinaryClient extends Connection {
|
||||
public void zrevrangeByScore(final byte[] key, final double max,
|
||||
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);
|
||||
}
|
||||
@@ -612,11 +624,13 @@ public class BinaryClient extends Connection {
|
||||
public void zrangeByScore(final byte[] key, final double min,
|
||||
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,
|
||||
@@ -629,8 +643,10 @@ public class BinaryClient extends Connection {
|
||||
public void zrevrangeByScore(final byte[] key, final double max,
|
||||
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));
|
||||
@@ -646,8 +662,10 @@ public class BinaryClient extends Connection {
|
||||
public void zrangeByScoreWithScores(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(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax,
|
||||
WITHSCORES.raw);
|
||||
@@ -663,8 +681,10 @@ public class BinaryClient extends Connection {
|
||||
public void zrevrangeByScoreWithScores(final byte[] key, final double max,
|
||||
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);
|
||||
@@ -679,12 +699,13 @@ public class BinaryClient extends Connection {
|
||||
public void zrangeByScoreWithScores(final byte[] key, final double min,
|
||||
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,
|
||||
@@ -697,8 +718,10 @@ public class BinaryClient extends Connection {
|
||||
public void zrevrangeByScoreWithScores(final byte[] key, final double max,
|
||||
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),
|
||||
@@ -1054,7 +1077,8 @@ public class BinaryClient extends Connection {
|
||||
sendCommand(DUMP, key);
|
||||
}
|
||||
|
||||
public void restore(final byte[] key, final int ttl, final byte[] serializedValue) {
|
||||
public void restore(final byte[] key, final int ttl,
|
||||
final byte[] serializedValue) {
|
||||
sendCommand(RESTORE, key, toByteArray(ttl), serializedValue);
|
||||
}
|
||||
|
||||
@@ -1074,7 +1098,8 @@ public class BinaryClient extends Connection {
|
||||
sendCommand(INCRBYFLOAT, key, toByteArray(increment));
|
||||
}
|
||||
|
||||
public void psetex(final byte[] key, final int milliseconds, final byte[] value) {
|
||||
public void psetex(final byte[] key, final int milliseconds,
|
||||
final byte[] value) {
|
||||
sendCommand(PSETEX, key, toByteArray(milliseconds), value);
|
||||
}
|
||||
|
||||
@@ -1082,7 +1107,8 @@ public class BinaryClient extends Connection {
|
||||
sendCommand(Command.SET, key, value, nxxx);
|
||||
}
|
||||
|
||||
public void set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final int 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));
|
||||
}
|
||||
|
||||
@@ -1110,11 +1136,14 @@ public class BinaryClient extends Connection {
|
||||
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) {
|
||||
public void hincrByFloat(final byte[] key, final byte[] field,
|
||||
double increment) {
|
||||
sendCommand(HINCRBYFLOAT, key, field, toByteArray(increment));
|
||||
}
|
||||
|
||||
@@ -1156,6 +1185,7 @@ public class BinaryClient extends Connection {
|
||||
public void cluster(final byte[]... args) {
|
||||
sendCommand(CLUSTER, args);
|
||||
}
|
||||
|
||||
public void 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,15 +83,20 @@ 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) {
|
||||
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();
|
||||
@@ -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();
|
||||
@@ -2266,7 +2280,8 @@ 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,
|
||||
@@ -2404,7 +2419,8 @@ 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,
|
||||
@@ -2442,7 +2458,8 @@ 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,
|
||||
@@ -2454,13 +2471,15 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
|
||||
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,
|
||||
@@ -2493,7 +2512,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();
|
||||
@@ -3165,7 +3185,8 @@ 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);
|
||||
client.eval(script, SafeEncoder.encode(Integer.toString(keyCount)),
|
||||
params);
|
||||
return client.getOne();
|
||||
}
|
||||
|
||||
@@ -3194,7 +3215,6 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
for (int i = 0; i < argCount; i++)
|
||||
params[keyCount + i] = args.get(i);
|
||||
|
||||
|
||||
return evalsha(sha1, keyCount, params);
|
||||
}
|
||||
|
||||
@@ -3280,7 +3300,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
return client.getBinaryBulkReply();
|
||||
}
|
||||
|
||||
public String restore(final byte[] key, final int ttl, final byte[] serializedValue) {
|
||||
public String restore(final byte[] key, final int ttl,
|
||||
final byte[] serializedValue) {
|
||||
checkIsInMulti();
|
||||
client.restore(key, ttl, serializedValue);
|
||||
return client.getStatusCodeReply();
|
||||
@@ -3311,7 +3332,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
return (relpy != null ? new Double(relpy) : null);
|
||||
}
|
||||
|
||||
public String psetex(final byte[] key, final int milliseconds, final byte[] value) {
|
||||
public String psetex(final byte[] key, final int milliseconds,
|
||||
final byte[] value) {
|
||||
checkIsInMulti();
|
||||
client.psetex(key, milliseconds, value);
|
||||
return client.getStatusCodeReply();
|
||||
@@ -3323,7 +3345,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final int time) {
|
||||
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();
|
||||
@@ -3359,13 +3382,15 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
||||
return client.getMultiBulkReply();
|
||||
}
|
||||
|
||||
public String migrate(final byte[] host, final int port, final byte[] key, final int destinationDb, final int timeout) {
|
||||
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) {
|
||||
public Double hincrByFloat(final byte[] key, final byte[] field,
|
||||
double increment) {
|
||||
checkIsInMulti();
|
||||
client.hincrByFloat(key, field, increment);
|
||||
String relpy = client.getBulkReply();
|
||||
|
||||
@@ -5,8 +5,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
|
||||
/**
|
||||
* Common interface for sharded and non-sharded BinaryJedis
|
||||
*/
|
||||
|
||||
@@ -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,17 +143,15 @@ 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);
|
||||
@@ -168,30 +165,28 @@ public interface BinaryRedisPipeline {
|
||||
Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, byte[] min,
|
||||
byte[] max, int offset, int count);
|
||||
|
||||
Response<Set<byte[]>> zrevrangeByScore(byte[] key, double max,
|
||||
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, double max, double 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<byte[]>> zrevrangeByScore(byte[] key, byte[] max,
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key, byte[] max,
|
||||
byte[] min);
|
||||
|
||||
Response<Set<byte[]>> zrevrangeByScore(byte[] key, double max,
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key, double max,
|
||||
double min, int offset, int count);
|
||||
|
||||
Response<Set<byte[]>> zrevrangeByScore(byte[] key, byte[] max,
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(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,
|
||||
byte[] max, byte[] min);
|
||||
|
||||
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>> zrangeWithScores(byte[] key, long start, long end);
|
||||
|
||||
Response<Long> zrank(byte[] key, byte[] member);
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
public enum BitOP {
|
||||
AND,
|
||||
OR,
|
||||
XOR,
|
||||
NOT;
|
||||
AND, OR, XOR, NOT;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import redis.clients.util.SafeEncoder;
|
||||
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 java.util.*;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
public class BuilderFactory {
|
||||
public static final Builder<Double> DOUBLE = new Builder<Double>() {
|
||||
@@ -84,8 +91,8 @@ public class BuilderFactory {
|
||||
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()));
|
||||
hash.put(SafeEncoder.encode(iterator.next()),
|
||||
SafeEncoder.encode(iterator.next()));
|
||||
}
|
||||
|
||||
return hash;
|
||||
|
||||
@@ -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) {
|
||||
@@ -716,13 +717,13 @@ public class Client extends BinaryClient implements Commands {
|
||||
|
||||
for (Map.Entry<String, Double> entry : scoreMembers.entrySet()) {
|
||||
|
||||
binaryScoreMembers.put(SafeEncoder.encode(entry.getKey()), entry.getValue());
|
||||
binaryScoreMembers.put(SafeEncoder.encode(entry.getKey()),
|
||||
entry.getValue());
|
||||
}
|
||||
|
||||
zaddBinary(SafeEncoder.encode(key), binaryScoreMembers);
|
||||
}
|
||||
|
||||
|
||||
public void objectRefcount(String key) {
|
||||
objectRefcount(SafeEncoder.encode(key));
|
||||
}
|
||||
@@ -759,7 +760,8 @@ public class Client extends BinaryClient implements Commands {
|
||||
dump(SafeEncoder.encode(key));
|
||||
}
|
||||
|
||||
public void restore(final String key, final int ttl, final byte[] serializedValue) {
|
||||
public void restore(final String key, final int ttl,
|
||||
final byte[] serializedValue) {
|
||||
restore(SafeEncoder.encode(key), ttl, serializedValue);
|
||||
}
|
||||
|
||||
@@ -779,16 +781,20 @@ public class Client extends BinaryClient implements Commands {
|
||||
incrByFloat(SafeEncoder.encode(key), increment);
|
||||
}
|
||||
|
||||
public void psetex(final String key, final int milliseconds, final String 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) {
|
||||
@@ -803,12 +809,16 @@ public class Client extends BinaryClient implements Commands {
|
||||
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) {
|
||||
@@ -824,18 +834,18 @@ public class Client extends BinaryClient implements Commands {
|
||||
}
|
||||
|
||||
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[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][];
|
||||
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] = SafeEncoder.encode(args[i - 1]);
|
||||
}
|
||||
arg[0] = SafeEncoder.encode(subcommand);
|
||||
cluster(arg);
|
||||
@@ -855,11 +865,11 @@ public class Client extends BinaryClient implements Commands {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -868,19 +878,22 @@ public class Client extends BinaryClient implements Commands {
|
||||
}
|
||||
|
||||
public void clusterGetKeysInSlot(final int slot, final int count) {
|
||||
final int[] args = new int[]{ slot, count };
|
||||
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<String, Double > scoreMembers);
|
||||
public void zadd(final String key, final Map<String, Double> scoreMembers);
|
||||
|
||||
public void zrange(final String key, final long start, final long end);
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public class Connection {
|
||||
|
||||
public void setTimeoutInfinite() {
|
||||
try {
|
||||
if(!isConnected()) {
|
||||
if (!isConnected()) {
|
||||
connect();
|
||||
}
|
||||
socket.setKeepAlive(true);
|
||||
@@ -122,12 +122,16 @@ public class Connection {
|
||||
if (!isConnected()) {
|
||||
try {
|
||||
socket = new Socket();
|
||||
//->@wjw_add
|
||||
// ->@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.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);
|
||||
@@ -224,9 +228,9 @@ public class Connection {
|
||||
List<Object> all = new ArrayList<Object>();
|
||||
flush();
|
||||
while (pipelinedCommands > except) {
|
||||
try{
|
||||
try {
|
||||
all.add(Protocol.read(inputStream));
|
||||
}catch(JedisDataException e){
|
||||
} catch (JedisDataException e) {
|
||||
all.add(e);
|
||||
}
|
||||
pipelinedCommands--;
|
||||
|
||||
@@ -26,8 +26,7 @@ public class HostAndPort {
|
||||
|
||||
String thisHost = convertHost(host);
|
||||
String hpHost = convertHost(hp.host);
|
||||
return port == hp.port &&
|
||||
thisHost.equals(hpHost);
|
||||
return port == hp.port && thisHost.equals(hpHost);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -13,10 +13,10 @@ import java.util.Set;
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
import redis.clients.util.Slowlog;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
|
||||
public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommands, AdvancedJedisCommands, ScriptingCommands, BasicCommands, ClusterCommands {
|
||||
public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
MultiKeyCommands, AdvancedJedisCommands, ScriptingCommands,
|
||||
BasicCommands, ClusterCommands {
|
||||
public Jedis(final String host) {
|
||||
super(host);
|
||||
}
|
||||
@@ -56,24 +56,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) {
|
||||
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 null
|
||||
* 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)
|
||||
*
|
||||
@@ -1954,8 +1959,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);
|
||||
@@ -2020,8 +2023,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.
|
||||
*/
|
||||
@@ -3012,7 +3017,8 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
return client.getBinaryBulkReply();
|
||||
}
|
||||
|
||||
public String restore(final String key, final int ttl, final byte[] serializedValue) {
|
||||
public String restore(final String key, final int ttl,
|
||||
final byte[] serializedValue) {
|
||||
checkIsInMulti();
|
||||
client.restore(key, ttl, serializedValue);
|
||||
return client.getStatusCodeReply();
|
||||
@@ -3043,7 +3049,8 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
return (relpy != null ? new Double(relpy) : null);
|
||||
}
|
||||
|
||||
public String psetex(final String key, final int milliseconds, final String value) {
|
||||
public String psetex(final String key, final int milliseconds,
|
||||
final String value) {
|
||||
checkIsInMulti();
|
||||
client.psetex(key, milliseconds, value);
|
||||
return client.getStatusCodeReply();
|
||||
@@ -3055,7 +3062,8 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String set(final String key, final String value, final String nxxx, final String expx, final int time) {
|
||||
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();
|
||||
@@ -3073,13 +3081,15 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String migrate(final String host, final int port, final String key, final int destinationDb, final int timeout) {
|
||||
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) {
|
||||
public Double hincrByFloat(final String key, final String field,
|
||||
double increment) {
|
||||
checkIsInMulti();
|
||||
client.hincrByFloat(key, field, increment);
|
||||
String relpy = client.getBulkReply();
|
||||
@@ -3094,29 +3104,33 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
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);
|
||||
}
|
||||
@@ -3125,13 +3139,14 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
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));
|
||||
}
|
||||
@@ -3142,19 +3157,22 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
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();
|
||||
@@ -3167,13 +3185,13 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String clusterAddSlots(final int ...slots) {
|
||||
public String clusterAddSlots(final int... slots) {
|
||||
checkIsInMulti();
|
||||
client.clusterAddSlots(slots);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String clusterDelSlots(final int ...slots) {
|
||||
public String clusterDelSlots(final int... slots) {
|
||||
checkIsInMulti();
|
||||
client.clusterDelSlots(slots);
|
||||
return client.getStatusCodeReply();
|
||||
|
||||
@@ -13,9 +13,11 @@ public abstract class JedisClusterCommand<T> {
|
||||
private JedisClusterConnectionHandler connectionHandler;
|
||||
private int commandTimeout;
|
||||
private int redirections;
|
||||
// private boolean asking = false;
|
||||
|
||||
public JedisClusterCommand(JedisClusterConnectionHandler connectionHandler, int timeout, int maxRedirections) {
|
||||
// private boolean asking = false;
|
||||
|
||||
public JedisClusterCommand(JedisClusterConnectionHandler connectionHandler,
|
||||
int timeout, int maxRedirections) {
|
||||
this.connectionHandler = connectionHandler;
|
||||
this.commandTimeout = timeout;
|
||||
this.redirections = maxRedirections;
|
||||
@@ -27,13 +29,17 @@ public abstract class JedisClusterCommand<T> {
|
||||
try {
|
||||
|
||||
if (key == null) {
|
||||
throw new JedisClusterException("No way to dispatch this command to Redis Cluster.");
|
||||
throw new JedisClusterException(
|
||||
"No way to dispatch this command to Redis Cluster.");
|
||||
} else if (redirections == 0) {
|
||||
throw new JedisClusterMaxRedirectionsException("Too many Cluster redirections?");
|
||||
throw new JedisClusterMaxRedirectionsException(
|
||||
"Too many Cluster redirections?");
|
||||
}
|
||||
connectionHandler.getConnectionFromSlot(JedisClusterCRC16.getSlot(key));
|
||||
connectionHandler.getConnectionFromSlot(JedisClusterCRC16
|
||||
.getSlot(key));
|
||||
if (asking) {
|
||||
//TODO: Pipeline asking with the original command to make it faster....
|
||||
// TODO: Pipeline asking with the original command to make it
|
||||
// faster....
|
||||
connectionHandler.getConnection().asking();
|
||||
}
|
||||
return execute();
|
||||
@@ -47,7 +53,8 @@ public abstract class JedisClusterCommand<T> {
|
||||
asking = true;
|
||||
}
|
||||
redirections--;
|
||||
this.connectionHandler.assignSlotToNode(jre.getSlot(), jre.getTargetNode());
|
||||
this.connectionHandler.assignSlotToNode(jre.getSlot(),
|
||||
jre.getTargetNode());
|
||||
return run(key);
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,13 @@ 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) {
|
||||
@@ -24,7 +24,8 @@ public abstract class JedisClusterConnectionHandler {
|
||||
|
||||
private void initializeSlotsCache(Set<HostAndPort> nodes) {
|
||||
for (HostAndPort hostAndPort : nodes) {
|
||||
JedisPool jp = new JedisPool(hostAndPort.getHost(), hostAndPort.getPort());
|
||||
JedisPool jp = new JedisPool(hostAndPort.getHost(),
|
||||
hostAndPort.getPort());
|
||||
this.nodes.put(hostAndPort.getHost() + hostAndPort.getPort(), jp);
|
||||
discoverClusterNodesAndSlots(jp);
|
||||
}
|
||||
@@ -53,7 +54,8 @@ public abstract class JedisClusterConnectionHandler {
|
||||
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++) {
|
||||
for (int i = Integer.valueOf(slotRange[0]); i <= Integer
|
||||
.valueOf(slotRange[1]); i++) {
|
||||
slots.put(i, nodePool);
|
||||
}
|
||||
} else {
|
||||
@@ -62,21 +64,21 @@ public abstract class JedisClusterConnectionHandler {
|
||||
}
|
||||
|
||||
private HostAndPort getHostAndPortFromNodeLine(String nodeInfo) {
|
||||
String stringHostAndPort = nodeInfo.split(" ",3)[1];
|
||||
String stringHostAndPort = nodeInfo.split(" ", 3)[1];
|
||||
String[] arrayHostAndPort = stringHostAndPort.split(":");
|
||||
return new HostAndPort(arrayHostAndPort[0], Integer.valueOf(arrayHostAndPort[1]));
|
||||
return new HostAndPort(arrayHostAndPort[0],
|
||||
Integer.valueOf(arrayHostAndPort[1]));
|
||||
}
|
||||
|
||||
public void assignSlotToNode(int slot, HostAndPort targetNode) {
|
||||
JedisPool targetPool = nodes.get(targetNode.getHost() + targetNode.getPort());
|
||||
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);
|
||||
@@ -115,7 +114,7 @@ public interface
|
||||
|
||||
Long zadd(String key, double score, String member);
|
||||
|
||||
Long zadd(String key, Map<String, Double > scoreMembers);
|
||||
Long zadd(String key, Map<String, Double> scoreMembers);
|
||||
|
||||
Set<String> zrange(String key, long start, long end);
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.util.Set;
|
||||
|
||||
public class JedisRandomConnectionHandler extends JedisClusterConnectionHandler {
|
||||
|
||||
|
||||
public JedisRandomConnectionHandler(Set<HostAndPort> nodes) {
|
||||
super(nodes);
|
||||
}
|
||||
|
||||
@@ -101,7 +101,8 @@ 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(),
|
||||
initPool(poolConfig,
|
||||
new JedisFactory(master.getHost(), master.getPort(),
|
||||
timeout, password, database));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ package redis.clients.jedis;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class JedisSlotBasedConnectionHandler extends JedisClusterConnectionHandler {
|
||||
public class JedisSlotBasedConnectionHandler extends
|
||||
JedisClusterConnectionHandler {
|
||||
|
||||
private Jedis currentConnection;
|
||||
|
||||
@@ -10,22 +11,21 @@ public class JedisSlotBasedConnectionHandler extends JedisClusterConnectionHandl
|
||||
super(nodes);
|
||||
}
|
||||
|
||||
|
||||
public Jedis getConnection() {
|
||||
return currentConnection != null ? currentConnection : getRandomConnection().getResource();
|
||||
return currentConnection != null ? currentConnection
|
||||
: getRandomConnection().getResource();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void returnCurrentConnection() {
|
||||
if (currentConnection != null) {
|
||||
nodes.get(currentConnection.getClient().getHost()+currentConnection.getClient().getPort()).returnResource(currentConnection);
|
||||
nodes.get(
|
||||
currentConnection.getClient().getHost()
|
||||
+ currentConnection.getClient().getPort())
|
||||
.returnResource(currentConnection);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void assignSlotToNode(int slot, HostAndPort targetNode) {
|
||||
super.assignSlotToNode(slot, targetNode);
|
||||
@@ -43,6 +43,4 @@ public class JedisSlotBasedConnectionHandler extends JedisClusterConnectionHandl
|
||||
return connectionPool.getResource();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@@ -1,11 +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 MultiKeyBinaryRedisPipeline {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,10 +5,8 @@ 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;
|
||||
|
||||
@@ -192,14 +190,14 @@ abstract class MultiKeyPipelineBase extends PipelineBase implements
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
public Response<Long> sort(String key,
|
||||
SortingParams sortingParameters, String dstkey) {
|
||||
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) {
|
||||
public Response<Long> sort(byte[] key, SortingParams sortingParameters,
|
||||
byte[] dstkey) {
|
||||
client.sort(key, sortingParameters, dstkey);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
@@ -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,28 +1,29 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
|
||||
public class Pipeline extends MultiKeyPipelineBase {
|
||||
|
||||
private MultiResponseBuilder currentMulti;
|
||||
|
||||
private class MultiResponseBuilder extends Builder<List<Object>>{
|
||||
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> 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());
|
||||
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++){
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Response<?> response = responses.get(i);
|
||||
response.set(list.get(i));
|
||||
values.add(response.get());
|
||||
@@ -30,21 +31,20 @@ public class Pipeline extends MultiKeyPipelineBase {
|
||||
return values;
|
||||
}
|
||||
|
||||
public void addResponse(Response<?> response){
|
||||
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
|
||||
if (currentMulti != null) {
|
||||
super.getResponse(BuilderFactory.STRING); // Expected QUEUED
|
||||
|
||||
Response<T> lr = new Response<T>(builder);
|
||||
currentMulti.addResponse(lr);
|
||||
return lr;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
return super.getResponse(builder);
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,8 @@ public class Pipeline extends MultiKeyPipelineBase {
|
||||
|
||||
public Response<String> multi() {
|
||||
client.multi();
|
||||
Response<String> response = getResponse(BuilderFactory.STRING); //Expecting OK
|
||||
Response<String> response = getResponse(BuilderFactory.STRING); // Expecting
|
||||
// OK
|
||||
currentMulti = new MultiResponseBuilder();
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import static redis.clients.jedis.Protocol.toByteArray;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static redis.clients.jedis.Protocol.toByteArray;
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
|
||||
abstract class PipelineBase extends Queable implements
|
||||
BinaryRedisPipeline,
|
||||
abstract class PipelineBase extends Queable implements BinaryRedisPipeline,
|
||||
RedisPipeline {
|
||||
|
||||
protected abstract Client getClient(String key);
|
||||
@@ -738,14 +737,16 @@ abstract class PipelineBase extends Queable implements
|
||||
return getResponse(BuilderFactory.STRING_ZSET);
|
||||
}
|
||||
|
||||
public Response<Set<String>> zrangeByScore(String key, String min, String max, int offset, int count) {
|
||||
public Response<Set<String>> zrangeByScore(String key, String min,
|
||||
String max, int offset, int count) {
|
||||
getClient(key).zrangeByScore(key, min, max, offset, count);
|
||||
return getResponse(BuilderFactory.STRING_ZSET);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> zrangeByScore(byte[] key, double min,
|
||||
double max, int offset, int count) {
|
||||
return zrangeByScore(key, toByteArray(min), toByteArray(max), offset, count);
|
||||
return zrangeByScore(key, toByteArray(min), toByteArray(max), offset,
|
||||
count);
|
||||
}
|
||||
|
||||
public Response<Set<byte[]>> zrangeByScore(byte[] key, byte[] min,
|
||||
@@ -791,7 +792,8 @@ abstract class PipelineBase extends Queable implements
|
||||
|
||||
public Response<Set<Tuple>> zrangeByScoreWithScores(byte[] key, double min,
|
||||
double max, int offset, int count) {
|
||||
getClient(key).zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), offset, count);
|
||||
getClient(key).zrangeByScoreWithScores(key, toByteArray(min),
|
||||
toByteArray(max), offset, count);
|
||||
return getResponse(BuilderFactory.TUPLE_ZSET_BINARY);
|
||||
}
|
||||
|
||||
@@ -809,7 +811,8 @@ abstract class PipelineBase extends Queable implements
|
||||
|
||||
public Response<Set<byte[]>> zrevrangeByScore(byte[] key, double max,
|
||||
double min) {
|
||||
getClient(key).zrevrangeByScore(key, toByteArray(max), toByteArray(min));
|
||||
getClient(key)
|
||||
.zrevrangeByScore(key, toByteArray(max), toByteArray(min));
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
@@ -839,7 +842,8 @@ abstract class PipelineBase extends Queable implements
|
||||
|
||||
public Response<Set<byte[]>> zrevrangeByScore(byte[] key, double max,
|
||||
double min, int offset, int count) {
|
||||
getClient(key).zrevrangeByScore(key, toByteArray(max), toByteArray(min), offset, count);
|
||||
getClient(key).zrevrangeByScore(key, toByteArray(max),
|
||||
toByteArray(min), offset, count);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
@@ -863,7 +867,8 @@ abstract class PipelineBase extends Queable implements
|
||||
|
||||
public Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key,
|
||||
double max, double min) {
|
||||
getClient(key).zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min));
|
||||
getClient(key).zrevrangeByScoreWithScores(key, toByteArray(max),
|
||||
toByteArray(min));
|
||||
return getResponse(BuilderFactory.TUPLE_ZSET_BINARY);
|
||||
}
|
||||
|
||||
@@ -887,7 +892,8 @@ abstract class PipelineBase extends Queable implements
|
||||
|
||||
public Response<Set<Tuple>> zrevrangeByScoreWithScores(byte[] key,
|
||||
double max, double min, int offset, int count) {
|
||||
getClient(key).zrevrangeByScoreWithScores(key, toByteArray(max), toByteArray(min), offset, count);
|
||||
getClient(key).zrevrangeByScoreWithScores(key, toByteArray(max),
|
||||
toByteArray(min), offset, count);
|
||||
return getResponse(BuilderFactory.TUPLE_ZSET_BINARY);
|
||||
}
|
||||
|
||||
@@ -897,12 +903,14 @@ abstract class PipelineBase extends Queable implements
|
||||
return getResponse(BuilderFactory.TUPLE_ZSET_BINARY);
|
||||
}
|
||||
|
||||
public Response<Set<Tuple>> zrangeWithScores(String key, long start, long end) {
|
||||
public Response<Set<Tuple>> zrangeWithScores(String key, long start,
|
||||
long end) {
|
||||
getClient(key).zrangeWithScores(key, start, end);
|
||||
return getResponse(BuilderFactory.TUPLE_ZSET);
|
||||
}
|
||||
|
||||
public Response<Set<Tuple>> zrangeWithScores(byte[] key, long start, long end) {
|
||||
public Response<Set<Tuple>> zrangeWithScores(byte[] key, long start,
|
||||
long end) {
|
||||
getClient(key).zrangeWithScores(key, start, end);
|
||||
return getResponse(BuilderFactory.TUPLE_ZSET_BINARY);
|
||||
}
|
||||
@@ -948,7 +956,8 @@ abstract class PipelineBase extends Queable implements
|
||||
}
|
||||
|
||||
public Response<Long> zremrangeByScore(byte[] key, double start, double end) {
|
||||
getClient(key).zremrangeByScore(key, toByteArray(start), toByteArray(end));
|
||||
getClient(key).zremrangeByScore(key, toByteArray(start),
|
||||
toByteArray(end));
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
@@ -1029,12 +1038,14 @@ abstract class PipelineBase extends Queable implements
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
|
||||
public Response<String> migrate(String host, int port, String key, int destinationDb, int timeout) {
|
||||
public Response<String> migrate(String host, int port, String key,
|
||||
int destinationDb, int timeout) {
|
||||
getClient(key).migrate(host, port, key, destinationDb, timeout);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> migrate(byte[] host, int port, byte[] key, int destinationDb, int timeout) {
|
||||
public Response<String> migrate(byte[] host, int port, byte[] key,
|
||||
int destinationDb, int timeout) {
|
||||
getClient(key).migrate(host, port, key, destinationDb, timeout);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
@@ -1139,22 +1150,26 @@ abstract class PipelineBase extends Queable implements
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> set(String key, String value, String nxxx, String expx, int time) {
|
||||
public Response<String> set(String key, String value, String nxxx,
|
||||
String expx, int time) {
|
||||
getClient(key).set(key, value, nxxx, expx, time);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<String> set(byte[] key, byte[] value, byte[] nxxx, byte[] expx, int time) {
|
||||
public Response<String> set(byte[] key, byte[] value, byte[] nxxx,
|
||||
byte[] expx, int time) {
|
||||
getClient(key).set(key, value, nxxx, expx, time);
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
public Response<Double> hincrByFloat(String key, String field, double increment) {
|
||||
public Response<Double> hincrByFloat(String key, String field,
|
||||
double increment) {
|
||||
getClient(key).hincrByFloat(key, field, increment);
|
||||
return getResponse(BuilderFactory.DOUBLE);
|
||||
}
|
||||
|
||||
public Response<Double> hincrByFloat(byte[] key, byte[] field, double increment) {
|
||||
public Response<Double> hincrByFloat(byte[] key, byte[] field,
|
||||
double increment) {
|
||||
getClient(key).hincrByFloat(key, field, increment);
|
||||
return getResponse(BuilderFactory.DOUBLE);
|
||||
}
|
||||
@@ -1163,7 +1178,8 @@ abstract class PipelineBase extends Queable implements
|
||||
return this.eval(script, 0, new String[0]);
|
||||
}
|
||||
|
||||
public Response<String> eval(String script, List<String> keys, List<String> args) {
|
||||
public Response<String> eval(String script, List<String> keys,
|
||||
List<String> args) {
|
||||
String[] argv = Jedis.getParams(keys, args);
|
||||
return this.eval(script, keys.size(), argv);
|
||||
}
|
||||
@@ -1177,7 +1193,8 @@ abstract class PipelineBase extends Queable implements
|
||||
return this.evalsha(script, 0, new String[0]);
|
||||
}
|
||||
|
||||
public Response<String> evalsha(String sha1, List<String> keys, List<String> args) {
|
||||
public Response<String> evalsha(String sha1, List<String> keys,
|
||||
List<String> args) {
|
||||
String[] argv = Jedis.getParams(keys, args);
|
||||
return this.evalsha(sha1, keys.size(), argv);
|
||||
}
|
||||
@@ -1187,5 +1204,4 @@ abstract class PipelineBase extends Queable implements
|
||||
return getResponse(BuilderFactory.STRING);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
|
||||
public abstract class PipelineBlock extends Pipeline {
|
||||
public abstract void execute();
|
||||
}
|
||||
|
||||
@@ -77,19 +77,24 @@ 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?
|
||||
// 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]));
|
||||
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 JedisAskDataException(message, new HostAndPort(
|
||||
askInfo[1], Integer.valueOf(askInfo[2])),
|
||||
Integer.valueOf(askInfo[0]));
|
||||
}
|
||||
throw new JedisDataException(message);
|
||||
}
|
||||
|
||||
private static String[] parseTargetHostAndSlot(String clusterRedirectResponse) {
|
||||
private static String[] parseTargetHostAndSlot(
|
||||
String clusterRedirectResponse) {
|
||||
String[] response = new String[3];
|
||||
String[] messageInfo = clusterRedirectResponse.split(" ");
|
||||
String[] targetHostAndPort = messageInfo[2].split(":");
|
||||
@@ -136,7 +141,8 @@ public final class Protocol {
|
||||
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.");
|
||||
throw new JedisConnectionException(
|
||||
"It seems like server has closed the connection.");
|
||||
offset += size;
|
||||
}
|
||||
// read 2 more bytes for the command delimiter
|
||||
@@ -201,8 +207,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() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,14 +141,12 @@ 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);
|
||||
@@ -160,21 +154,19 @@ public interface RedisPipeline {
|
||||
Response<Set<Tuple>> zrangeByScoreWithScores(String key, double min,
|
||||
double max, int offset, int count);
|
||||
|
||||
Response<Set<String>> zrevrangeByScore(String key, double max,
|
||||
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, double max, double min,
|
||||
int offset, int count);
|
||||
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(String key, double max,
|
||||
double min);
|
||||
|
||||
Response<Set<String>> zrevrangeByScore(String key, String max,
|
||||
String min);
|
||||
|
||||
Response<Set<String>> zrevrangeByScore(String key, double max,
|
||||
Response<Set<Tuple>> zrevrangeByScoreWithScores(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, int offset, int count);
|
||||
|
||||
Response<Set<Tuple>> zrangeWithScores(String key, long start, long end);
|
||||
|
||||
Response<Long> zrank(String key, String member);
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ public class Response<T> {
|
||||
"Please close pipeline or multi block before calling this method.");
|
||||
}
|
||||
if (!built) {
|
||||
if(data != null ){
|
||||
if (data instanceof JedisDataException){
|
||||
throw new JedisDataException((JedisDataException)data);
|
||||
if (data != null) {
|
||||
if (data instanceof JedisDataException) {
|
||||
throw new JedisDataException((JedisDataException) data);
|
||||
}
|
||||
response = builder.build(data);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -48,8 +48,8 @@ public class ShardedJedisPipeline extends PipelineBase {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -62,8 +62,8 @@ public class ShardedJedisPipeline extends PipelineBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
@@ -6,13 +6,14 @@ 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(){
|
||||
protected Transaction() {
|
||||
// client will be set later in transaction block
|
||||
}
|
||||
|
||||
|
||||
@@ -5,15 +5,18 @@ import redis.clients.jedis.HostAndPort;
|
||||
public class JedisAskDataException extends JedisRedirectionException {
|
||||
private static final long serialVersionUID = 3878126572474819403L;
|
||||
|
||||
public JedisAskDataException(Throwable cause, HostAndPort targetHost, int slot) {
|
||||
public JedisAskDataException(Throwable cause, HostAndPort targetHost,
|
||||
int slot) {
|
||||
super(cause, targetHost, slot);
|
||||
}
|
||||
|
||||
public JedisAskDataException(String message, Throwable cause, HostAndPort targetHost, int slot) {
|
||||
public JedisAskDataException(String message, Throwable cause,
|
||||
HostAndPort targetHost, int slot) {
|
||||
super(message, cause, targetHost, slot);
|
||||
}
|
||||
|
||||
public JedisAskDataException(String message, HostAndPort targetHost, int slot) {
|
||||
public JedisAskDataException(String message, HostAndPort targetHost,
|
||||
int slot) {
|
||||
super(message, targetHost, slot);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package redis.clients.jedis.exceptions;
|
||||
|
||||
|
||||
public class JedisClusterException extends JedisDataException {
|
||||
private static final long serialVersionUID = 3878126572474819403L;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package redis.clients.jedis.exceptions;
|
||||
|
||||
|
||||
public class JedisClusterMaxRedirectionsException extends JedisDataException {
|
||||
private static final long serialVersionUID = 3878126572474819403L;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package redis.clients.jedis.exceptions;
|
||||
|
||||
|
||||
public class JedisException extends RuntimeException {
|
||||
private static final long serialVersionUID = -2946266495682282677L;
|
||||
|
||||
|
||||
@@ -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) {
|
||||
public JedisMovedDataException(String message, HostAndPort targetNode,
|
||||
int slot) {
|
||||
super(message, targetNode, slot);
|
||||
}
|
||||
|
||||
public JedisMovedDataException(Throwable cause, HostAndPort targetNode, int slot) {
|
||||
public JedisMovedDataException(Throwable cause, HostAndPort targetNode,
|
||||
int slot) {
|
||||
super(cause, targetNode, slot);
|
||||
}
|
||||
|
||||
public JedisMovedDataException(String message, Throwable cause, HostAndPort targetNode, int slot) {
|
||||
public JedisMovedDataException(String message, Throwable cause,
|
||||
HostAndPort targetNode, int slot) {
|
||||
super(message, cause, targetNode, slot);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,26 +2,28 @@ 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) {
|
||||
public JedisRedirectionException(String message, HostAndPort targetNode,
|
||||
int slot) {
|
||||
super(message);
|
||||
this.targetNode = targetNode;
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
public JedisRedirectionException(Throwable cause, HostAndPort targetNode, int 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) {
|
||||
public JedisRedirectionException(String message, Throwable cause,
|
||||
HostAndPort targetNode, int slot) {
|
||||
super(message, cause);
|
||||
this.targetNode = targetNode;
|
||||
this.slot = slot;
|
||||
|
||||
@@ -69,8 +69,8 @@ public class JedisByteHashMap implements Map<byte[], byte[]>, Cloneable,
|
||||
while (iterator.hasNext()) {
|
||||
Entry<? extends byte[], ? extends byte[]> next = (Entry<? extends byte[], ? extends byte[]>) iterator
|
||||
.next();
|
||||
internalMap.put(new ByteArrayWrapper(next.getKey()), next
|
||||
.getValue());
|
||||
internalMap.put(new ByteArrayWrapper(next.getKey()),
|
||||
next.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,11 +8,13 @@ public class JedisClusterCRC16 {
|
||||
crc = 0x0000;
|
||||
for (byte b : key.getBytes()) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
boolean bit = ((b >> (7-i) & 1) == 1);
|
||||
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;
|
||||
// If coefficient of bit and remainder polynomial = 1 xor crc
|
||||
// with polynomial
|
||||
if (c15 ^ bit)
|
||||
crc ^= polynomial;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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[];
|
||||
@@ -42,7 +44,8 @@ public final class RedisOutputStream extends FilterOutputStream {
|
||||
write(b, 0, b.length);
|
||||
}
|
||||
|
||||
public void write(final byte b[], final int off, final int len) throws IOException {
|
||||
public void write(final byte b[], final int off, final int len)
|
||||
throws IOException {
|
||||
if (len >= buf.length) {
|
||||
flushBuffer();
|
||||
out.write(b, off, len);
|
||||
@@ -73,9 +76,9 @@ public final class RedisOutputStream extends FilterOutputStream {
|
||||
return ch >= Character.MIN_SURROGATE && ch <= Character.MAX_SURROGATE;
|
||||
}
|
||||
|
||||
public static int utf8Length (final String str) {
|
||||
public static int utf8Length(final String str) {
|
||||
int strLen = str.length(), utfLen = 0;
|
||||
for(int i = 0; i != strLen; ++i) {
|
||||
for (int i = 0; i != strLen; ++i) {
|
||||
char c = str.charAt(i);
|
||||
if (c < 0x80) {
|
||||
utfLen++;
|
||||
@@ -106,9 +109,10 @@ public final class RedisOutputStream extends FilterOutputStream {
|
||||
int i;
|
||||
for (i = 0; i < strLen; i++) {
|
||||
char c = str.charAt(i);
|
||||
if (!(c < 0x80)) break;
|
||||
if (!(c < 0x80))
|
||||
break;
|
||||
buf[count++] = (byte) c;
|
||||
if(count == buf.length) {
|
||||
if (count == buf.length) {
|
||||
flushBuffer();
|
||||
}
|
||||
}
|
||||
@@ -117,77 +121,68 @@ public final class RedisOutputStream extends FilterOutputStream {
|
||||
char c = str.charAt(i);
|
||||
if (c < 0x80) {
|
||||
buf[count++] = (byte) c;
|
||||
if(count == buf.length) {
|
||||
if (count == buf.length) {
|
||||
flushBuffer();
|
||||
}
|
||||
} else if (c < 0x800) {
|
||||
if(2 >= buf.length - count) {
|
||||
if (2 >= buf.length - count) {
|
||||
flushBuffer();
|
||||
}
|
||||
buf[count++] = (byte)(0xc0 | (c >> 6));
|
||||
buf[count++] = (byte)(0x80 | (c & 0x3f));
|
||||
buf[count++] = (byte) (0xc0 | (c >> 6));
|
||||
buf[count++] = (byte) (0x80 | (c & 0x3f));
|
||||
} else if (isSurrogate(c)) {
|
||||
if(4 >= buf.length - count) {
|
||||
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)));
|
||||
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) {
|
||||
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)));
|
||||
buf[count++] = ((byte) (0xe0 | ((c >> 12))));
|
||||
buf[count++] = ((byte) (0x80 | ((c >> 6) & 0x3f)));
|
||||
buf[count++] = ((byte) (0x80 | (c & 0x3f)));
|
||||
}
|
||||
}
|
||||
|
||||
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((byte)'-');
|
||||
write((byte) '-');
|
||||
value = -value;
|
||||
}
|
||||
|
||||
@@ -211,12 +206,13 @@ public final class RedisOutputStream extends FilterOutputStream {
|
||||
buf[--charPos] = DigitTens[r];
|
||||
}
|
||||
|
||||
for (; ;) {
|
||||
for (;;) {
|
||||
q = (value * 52429) >>> (16 + 3);
|
||||
r = value - ((q << 3) + (q << 1));
|
||||
buf[--charPos] = digits[r];
|
||||
value = q;
|
||||
if (value == 0) break;
|
||||
if (value == 0)
|
||||
break;
|
||||
}
|
||||
count += size;
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ import redis.clients.jedis.exceptions.JedisException;
|
||||
*
|
||||
*/
|
||||
public class SafeEncoder {
|
||||
public static byte[][] encodeMany(final String... strs){
|
||||
public static byte[][] encodeMany(final String... strs) {
|
||||
byte[][] many = new byte[strs.length][];
|
||||
for(int i=0;i<strs.length;i++){
|
||||
for (int i = 0; i < strs.length; i++) {
|
||||
many[i] = encode(strs[i]);
|
||||
}
|
||||
return many;
|
||||
|
||||
@@ -57,11 +57,14 @@ public class Sharded<R, S extends ShardInfo<R>> {
|
||||
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);
|
||||
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);
|
||||
nodes.put(
|
||||
this.algo.hash(shardInfo.getName() + "*"
|
||||
+ shardInfo.getWeight() + n), shardInfo);
|
||||
}
|
||||
resources.put(shardInfo, shardInfo.createResource());
|
||||
}
|
||||
@@ -113,4 +116,3 @@ public class Sharded<R, S extends ShardInfo<R>> {
|
||||
return Collections.unmodifiableCollection(resources.values());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ public class Slowlog {
|
||||
private final List<String> args;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Slowlog> from(List<Object> nestedMultiBulkReply){
|
||||
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;
|
||||
for (Object obj : nestedMultiBulkReply) {
|
||||
List<Object> properties = (List<Object>) obj;
|
||||
logs.add(new Slowlog(properties));
|
||||
}
|
||||
|
||||
@@ -23,14 +23,14 @@ public class Slowlog {
|
||||
@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);
|
||||
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);
|
||||
List<byte[]> bargs = (List<byte[]>) properties.get(3);
|
||||
this.args = new ArrayList<String>(bargs.size());
|
||||
|
||||
for(byte[] barg:bargs){
|
||||
for (byte[] barg : bargs) {
|
||||
this.args.add(SafeEncoder.encode(barg));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,8 +93,8 @@ public class JedisPoolTest extends Assert {
|
||||
public void securePool() {
|
||||
JedisPoolConfig config = new JedisPoolConfig();
|
||||
config.setTestOnBorrow(true);
|
||||
JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), 2000,
|
||||
"foobared");
|
||||
JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(),
|
||||
2000, "foobared");
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.set("foo", "bar");
|
||||
pool.returnResource(jedis);
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.junit.Test;
|
||||
import redis.clients.jedis.DebugParams;
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPubSub;
|
||||
import redis.clients.jedis.JedisSentinelPool;
|
||||
import redis.clients.jedis.Transaction;
|
||||
|
||||
@@ -114,34 +114,41 @@ public class PipeliningTest extends Assert {
|
||||
jedis.hset("key".getBytes(), "f22".getBytes(), "v2222".getBytes());
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<Map<byte[],byte[]>> fmap = p.hgetAll("key".getBytes());
|
||||
Response<Map<byte[], byte[]>> fmap = p.hgetAll("key".getBytes());
|
||||
Response<Set<byte[]>> fkeys = p.hkeys("key".getBytes());
|
||||
Response<List<byte[]>> fordered = p.hmget("key".getBytes(), "f22".getBytes(), "f1".getBytes());
|
||||
Response<List<byte[]>> fordered = p.hmget("key".getBytes(),
|
||||
"f22".getBytes(), "f1".getBytes());
|
||||
Response<List<byte[]>> fvals = p.hvals("key".getBytes());
|
||||
p.sync();
|
||||
|
||||
assertNotNull(fmap.get());
|
||||
// we have to do these strange contortions because byte[] is not a very good key
|
||||
// for a java Map. It only works with equality (you need the exact key object to retrieve
|
||||
// the value) I recommend we switch to using ByteBuffer or something similar:
|
||||
// we have to do these strange contortions because byte[] is not a very
|
||||
// good key
|
||||
// for a java Map. It only works with equality (you need the exact key
|
||||
// object to retrieve
|
||||
// the value) I recommend we switch to using ByteBuffer or something
|
||||
// similar:
|
||||
// http://stackoverflow.com/questions/1058149/using-a-byte-array-as-hashmap-key-java
|
||||
Map<byte[],byte[]> map = fmap.get();
|
||||
Map<byte[], byte[]> map = fmap.get();
|
||||
Set<byte[]> mapKeys = map.keySet();
|
||||
Iterator<byte[]> iterMap = mapKeys.iterator();
|
||||
byte[] firstMapKey = iterMap.next();
|
||||
byte[] secondMapKey = iterMap.next();
|
||||
assertFalse(iterMap.hasNext());
|
||||
verifyHasBothValues(firstMapKey, secondMapKey, "f1".getBytes(), "f22".getBytes());
|
||||
verifyHasBothValues(firstMapKey, secondMapKey, "f1".getBytes(),
|
||||
"f22".getBytes());
|
||||
byte[] firstMapValue = map.get(firstMapKey);
|
||||
byte[] secondMapValue = map.get(secondMapKey);
|
||||
verifyHasBothValues(firstMapValue, secondMapValue, "v111".getBytes(), "v2222".getBytes());
|
||||
verifyHasBothValues(firstMapValue, secondMapValue, "v111".getBytes(),
|
||||
"v2222".getBytes());
|
||||
|
||||
assertNotNull(fkeys.get());
|
||||
Iterator<byte[]> iter = fkeys.get().iterator();
|
||||
byte[] firstKey = iter.next();
|
||||
byte[] secondKey = iter.next();
|
||||
assertFalse(iter.hasNext());
|
||||
verifyHasBothValues(firstKey, secondKey, "f1".getBytes(), "f22".getBytes());
|
||||
verifyHasBothValues(firstKey, secondKey, "f1".getBytes(),
|
||||
"f22".getBytes());
|
||||
|
||||
assertNotNull(fordered.get());
|
||||
assertArrayEquals("v2222".getBytes(), fordered.get().get(0));
|
||||
@@ -151,13 +158,17 @@ public class PipeliningTest extends Assert {
|
||||
assertEquals(2, fvals.get().size());
|
||||
byte[] firstValue = fvals.get().get(0);
|
||||
byte[] secondValue = fvals.get().get(1);
|
||||
verifyHasBothValues(firstValue, secondValue, "v111".getBytes(), "v2222".getBytes());
|
||||
verifyHasBothValues(firstValue, secondValue, "v111".getBytes(),
|
||||
"v2222".getBytes());
|
||||
}
|
||||
|
||||
private void verifyHasBothValues(byte[] firstKey, byte[] secondKey, byte[] value1, byte[] value2) {
|
||||
private void verifyHasBothValues(byte[] firstKey, byte[] secondKey,
|
||||
byte[] value1, byte[] value2) {
|
||||
assertFalse(Arrays.equals(firstKey, secondKey));
|
||||
assertTrue(Arrays.equals(firstKey, value1) || Arrays.equals(firstKey, value2));
|
||||
assertTrue(Arrays.equals(secondKey, value1) || Arrays.equals(secondKey, value2));
|
||||
assertTrue(Arrays.equals(firstKey, value1)
|
||||
|| Arrays.equals(firstKey, value2));
|
||||
assertTrue(Arrays.equals(secondKey, value1)
|
||||
|| Arrays.equals(secondKey, value2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -178,7 +189,6 @@ public class PipeliningTest extends Assert {
|
||||
assertNull(score.get());
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void pipelineResponseWithinPipeline() {
|
||||
jedis.set("string", "foo");
|
||||
@@ -193,8 +203,8 @@ public class PipeliningTest extends Assert {
|
||||
public void pipelineWithPubSub() {
|
||||
Pipeline pipelined = jedis.pipelined();
|
||||
Response<Long> p1 = pipelined.publish("foo", "bar");
|
||||
Response<Long> p2 = pipelined.publish("foo".getBytes(), "bar"
|
||||
.getBytes());
|
||||
Response<Long> p2 = pipelined.publish("foo".getBytes(),
|
||||
"bar".getBytes());
|
||||
pipelined.sync();
|
||||
assertEquals(0, p1.get().longValue());
|
||||
assertEquals(0, p2.get().longValue());
|
||||
@@ -209,23 +219,23 @@ public class PipeliningTest extends Assert {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void piplineWithError(){
|
||||
public void piplineWithError() {
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.set("foo", "bar");
|
||||
Response<Set<String>> error = p.smembers("foo");
|
||||
Response<String> r = p.get("foo");
|
||||
p.sync();
|
||||
try{
|
||||
try {
|
||||
error.get();
|
||||
fail();
|
||||
}catch(JedisDataException e){
|
||||
//that is fine we should be here
|
||||
} catch (JedisDataException e) {
|
||||
// that is fine we should be here
|
||||
}
|
||||
assertEquals(r.get(), "bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multi(){
|
||||
public void multi() {
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.multi();
|
||||
Response<Long> r1 = p.hincrBy("a", "f1", -1);
|
||||
@@ -242,7 +252,7 @@ public class PipeliningTest extends Assert {
|
||||
assertEquals("QUEUED", result.get(1));
|
||||
assertEquals("QUEUED", result.get(2));
|
||||
|
||||
//4th result is a list with the results from the multi
|
||||
// 4th result is a list with the results from the multi
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> multiResult = (List<Object>) result.get(3);
|
||||
assertEquals(new Long(-1), multiResult.get(0));
|
||||
@@ -284,9 +294,11 @@ public class PipeliningTest extends Assert {
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.set(key, "0");
|
||||
Response<String> result0 = p.eval(script, Arrays.asList(key), Arrays.asList(arg));
|
||||
Response<String> result0 = p.eval(script, Arrays.asList(key),
|
||||
Arrays.asList(arg));
|
||||
p.incr(key);
|
||||
Response<String> result1 = p.eval(script, Arrays.asList(key), Arrays.asList(arg));
|
||||
Response<String> result1 = p.eval(script, Arrays.asList(key),
|
||||
Arrays.asList(arg));
|
||||
Response<String> result2 = p.get(key);
|
||||
p.sync();
|
||||
|
||||
@@ -320,9 +332,11 @@ public class PipeliningTest extends Assert {
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.set(key, "0");
|
||||
Response<String> result0 = p.evalsha(sha1, Arrays.asList(key), Arrays.asList(arg));
|
||||
Response<String> result0 = p.evalsha(sha1, Arrays.asList(key),
|
||||
Arrays.asList(arg));
|
||||
p.incr(key);
|
||||
Response<String> result1 = p.evalsha(sha1, Arrays.asList(key), Arrays.asList(arg));
|
||||
Response<String> result1 = p.evalsha(sha1, Arrays.asList(key),
|
||||
Arrays.asList(arg));
|
||||
Response<String> result2 = p.get(key);
|
||||
p.sync();
|
||||
|
||||
|
||||
@@ -53,7 +53,8 @@ public class ShardedJedisTest extends Assert {
|
||||
@Test
|
||||
public void trySharding() {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
JedisShardInfo si = new JedisShardInfo(redis1.getHost(), redis1.getPort());
|
||||
JedisShardInfo si = new JedisShardInfo(redis1.getHost(),
|
||||
redis1.getPort());
|
||||
si.setPassword("foobared");
|
||||
shards.add(si);
|
||||
si = new JedisShardInfo(redis2.getHost(), redis2.getPort());
|
||||
@@ -80,7 +81,8 @@ public class ShardedJedisTest extends Assert {
|
||||
@Test
|
||||
public void tryShardingWithMurmure() {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
JedisShardInfo si = new JedisShardInfo(redis1.getHost(), redis1.getPort());
|
||||
JedisShardInfo si = new JedisShardInfo(redis1.getHost(),
|
||||
redis1.getPort());
|
||||
si.setPassword("foobared");
|
||||
shards.add(si);
|
||||
si = new JedisShardInfo(redis2.getHost(), redis2.getPort());
|
||||
@@ -264,8 +266,8 @@ public class ShardedJedisTest extends Assert {
|
||||
.toString(i));
|
||||
JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer
|
||||
.toString(i));
|
||||
assertEquals(shards.indexOf(jedisShardInfo), otherShards
|
||||
.indexOf(jedisShardInfo2));
|
||||
assertEquals(shards.indexOf(jedisShardInfo),
|
||||
otherShards.indexOf(jedisShardInfo2));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@ public class HashingBenchmark {
|
||||
public static void main(String[] args) throws UnknownHostException,
|
||||
IOException {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
JedisShardInfo shard = new JedisShardInfo(hnp1.getHost(), hnp1.getPort());
|
||||
JedisShardInfo shard = new JedisShardInfo(hnp1.getHost(),
|
||||
hnp1.getPort());
|
||||
shard.setPassword("foobared");
|
||||
shards.add(shard);
|
||||
shard = new JedisShardInfo(hnp2.getHost(), hnp2.getPort());
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import redis.clients.jedis.Protocol.Keyword;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.Protocol.Keyword;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
|
||||
public class BinaryValuesCommandsTest extends JedisCommandTestBase {
|
||||
byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
|
||||
@@ -54,10 +55,11 @@ public class BinaryValuesCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void setIfNotExistAndGet() {
|
||||
String status= jedis.set(bfoo, binaryValue);
|
||||
String status = jedis.set(bfoo, binaryValue);
|
||||
assertTrue(Keyword.OK.name().equalsIgnoreCase(status));
|
||||
// nx should fail if value exists
|
||||
String statusFail = jedis.set(bfoo, binaryValue, bnx, bex, expireSeconds);
|
||||
String statusFail = jedis.set(bfoo, binaryValue, bnx, bex,
|
||||
expireSeconds);
|
||||
assertNull(statusFail);
|
||||
|
||||
byte[] value = jedis.get(bfoo);
|
||||
@@ -68,10 +70,11 @@ public class BinaryValuesCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void setIfExistAndGet() {
|
||||
String status= jedis.set(bfoo, binaryValue);
|
||||
String status = jedis.set(bfoo, binaryValue);
|
||||
assertTrue(Keyword.OK.name().equalsIgnoreCase(status));
|
||||
// nx should fail if value exists
|
||||
String statusSuccess = jedis.set(bfoo, binaryValue, bxx, bex, expireSeconds);
|
||||
String statusSuccess = jedis.set(bfoo, binaryValue, bxx, bex,
|
||||
expireSeconds);
|
||||
assertTrue(Keyword.OK.name().equalsIgnoreCase(statusSuccess));
|
||||
|
||||
byte[] value = jedis.get(bfoo);
|
||||
@@ -83,7 +86,8 @@ public class BinaryValuesCommandsTest extends JedisCommandTestBase {
|
||||
@Test
|
||||
public void setFailIfNotExistAndGet() {
|
||||
// xx should fail if value does NOT exists
|
||||
String statusFail = jedis.set(bfoo, binaryValue, bxx, bex, expireSeconds);
|
||||
String statusFail = jedis.set(bfoo, binaryValue, bxx, bex,
|
||||
expireSeconds);
|
||||
assertNull(statusFail);
|
||||
}
|
||||
|
||||
@@ -95,7 +99,6 @@ public class BinaryValuesCommandsTest extends JedisCommandTestBase {
|
||||
assertTrue(ttl > 0 && ttl <= expireSeconds);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setAndExpire() {
|
||||
String status = jedis.set(bfoo, binaryValue, bnx, bex, expireSeconds);
|
||||
@@ -104,7 +107,6 @@ public class BinaryValuesCommandsTest extends JedisCommandTestBase {
|
||||
assertTrue(ttl > 0 && ttl <= expireSeconds);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getSet() {
|
||||
byte[] value = jedis.getSet(bfoo, binaryValue);
|
||||
@@ -263,15 +265,13 @@ public class BinaryValuesCommandsTest extends JedisCommandTestBase {
|
||||
assertTrue(Arrays.equals(first512, rfirst512));
|
||||
|
||||
byte[] last512 = new byte[512];
|
||||
System
|
||||
.arraycopy(binaryValue, binaryValue.length - 512, last512, 0,
|
||||
512);
|
||||
System.arraycopy(binaryValue, binaryValue.length - 512, last512, 0, 512);
|
||||
assertTrue(Arrays.equals(last512, jedis.substr(bfoo, -512, -1)));
|
||||
|
||||
assertTrue(Arrays.equals(binaryValue, jedis.substr(bfoo, 0, -1)));
|
||||
|
||||
assertTrue(Arrays.equals(last512, jedis.substr(bfoo,
|
||||
binaryValue.length - 512, 100000)));
|
||||
assertTrue(Arrays.equals(last512,
|
||||
jedis.substr(bfoo, binaryValue.length - 512, 100000)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -51,8 +51,7 @@ public class BitCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bitOp()
|
||||
{
|
||||
public void bitOp() {
|
||||
jedis.set("key1", "\u0060");
|
||||
jedis.set("key2", "\u0044");
|
||||
|
||||
@@ -76,8 +75,7 @@ public class BitCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bitOpNot()
|
||||
{
|
||||
public void bitOpNot() {
|
||||
jedis.del("key");
|
||||
jedis.setbit("key", 0, true);
|
||||
jedis.setbit("key", 4, true);
|
||||
|
||||
@@ -40,31 +40,34 @@ public class ClusterCommandsTest extends JedisTestBase {
|
||||
|
||||
@AfterClass
|
||||
public static void removeSlots() throws InterruptedException {
|
||||
//This is to wait for gossip to replicate data.
|
||||
// This is to wait for gossip to replicate data.
|
||||
waitForEqualClusterSize();
|
||||
String[] nodes = node1.clusterNodes().split("\n");
|
||||
String node1Id = nodes[0].split(" ")[0];
|
||||
node1.clusterDelSlots(1,2,3,4,5,500);
|
||||
node1.clusterDelSlots(1, 2, 3, 4, 5, 500);
|
||||
node1.clusterSetSlotNode(5000, node1Id);
|
||||
node1.clusterDelSlots(5000, 10000);
|
||||
node1.clusterDelSlots(6000);
|
||||
node2.clusterDelSlots(6000,1,2,3,4,5,500,5000);
|
||||
node2.clusterDelSlots(6000, 1, 2, 3, 4, 5, 500, 5000);
|
||||
try {
|
||||
node2.clusterDelSlots(10000);
|
||||
} catch (JedisDataException jde) {
|
||||
//Do nothing, slot may or may not be assigned depending on gossip
|
||||
// Do nothing, slot may or may not be assigned depending on gossip
|
||||
}
|
||||
}
|
||||
|
||||
private static void waitForEqualClusterSize() throws InterruptedException {
|
||||
boolean notEqualSize = true;
|
||||
while (notEqualSize) {
|
||||
notEqualSize = getClusterAttribute(node1.clusterInfo(), "cluster_known_nodes") == getClusterAttribute(node2.clusterInfo(), "cluster_size") ? false : true;
|
||||
notEqualSize = getClusterAttribute(node1.clusterInfo(),
|
||||
"cluster_known_nodes") == getClusterAttribute(
|
||||
node2.clusterInfo(), "cluster_size") ? false : true;
|
||||
}
|
||||
}
|
||||
|
||||
private static int getClusterAttribute(String clusterInfo, String attributeName) {
|
||||
for (String infoElement: clusterInfo.split("\n")) {
|
||||
private static int getClusterAttribute(String clusterInfo,
|
||||
String attributeName) {
|
||||
for (String infoElement : clusterInfo.split("\n")) {
|
||||
if (infoElement.contains(attributeName)) {
|
||||
return Integer.valueOf(infoElement.split(":")[1].trim());
|
||||
}
|
||||
|
||||
@@ -309,7 +309,8 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
jedis.hset("foo", "b", "b");
|
||||
jedis.hset("foo", "a", "a");
|
||||
jedis.hset("foo", "aa", "aa");
|
||||
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo", 0, params);
|
||||
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo", 0,
|
||||
params);
|
||||
|
||||
assertEquals(0, result.getCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
@@ -324,7 +325,8 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
jedis.hset("foo", "a" + i, "a" + i);
|
||||
}
|
||||
|
||||
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo", 0, params);
|
||||
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo", 0,
|
||||
params);
|
||||
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
||||
size = jedis.rpush("foo", "bar", "foo");
|
||||
assertEquals(4, size);
|
||||
|
||||
|
||||
// Binary
|
||||
long bsize = jedis.rpush(bfoo, bbar);
|
||||
assertEquals(1, bsize);
|
||||
@@ -445,7 +444,6 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
||||
List<String> result = jedis.brpop(1, "foo");
|
||||
assertNull(result);
|
||||
|
||||
|
||||
jedis.lpush("foo", "bar");
|
||||
result = jedis.brpop(1, "foo");
|
||||
assertNotNull(result);
|
||||
|
||||
@@ -5,14 +5,12 @@ import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.BinaryJedisPubSub;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPubSub;
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
@@ -43,7 +41,7 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
assertEquals("foo", channel);
|
||||
assertEquals(1, subscribedChannels);
|
||||
|
||||
//now that I'm subscribed... publish
|
||||
// now that I'm subscribed... publish
|
||||
publishOne("foo", "exit");
|
||||
}
|
||||
|
||||
@@ -264,7 +262,8 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
public void onPSubscribe(byte[] pattern, int subscribedChannels) {
|
||||
assertTrue(Arrays.equals(SafeEncoder.encode("foo.*"), pattern));
|
||||
assertEquals(1, subscribedChannels);
|
||||
publishOne(SafeEncoder.encode(pattern).replace("*", "bar"), "exit");
|
||||
publishOne(SafeEncoder.encode(pattern).replace("*", "bar"),
|
||||
"exit");
|
||||
}
|
||||
|
||||
public void onPUnsubscribe(byte[] pattern, int subscribedChannels) {
|
||||
@@ -297,7 +296,8 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
|
||||
public void onPSubscribe(byte[] pattern, int subscribedChannels) {
|
||||
publishOne(SafeEncoder.encode(pattern).replace("*", "123"), "exit");
|
||||
publishOne(SafeEncoder.encode(pattern).replace("*", "123"),
|
||||
"exit");
|
||||
}
|
||||
|
||||
public void onPUnsubscribe(byte[] pattern, int subscribedChannels) {
|
||||
@@ -321,7 +321,7 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
public void onSubscribe(byte[] channel, int subscribedChannels) {
|
||||
publishOne(SafeEncoder.encode(channel), "exit");
|
||||
|
||||
if(!SafeEncoder.encode(channel).equals("bar")) {
|
||||
if (!SafeEncoder.encode(channel).equals("bar")) {
|
||||
this.subscribe(SafeEncoder.encode("bar"));
|
||||
this.psubscribe(SafeEncoder.encode("bar.*"));
|
||||
}
|
||||
@@ -331,7 +331,8 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
|
||||
public void onPSubscribe(byte[] pattern, int subscribedChannels) {
|
||||
publishOne(SafeEncoder.encode(pattern).replace("*", "123"), "exit");
|
||||
publishOne(SafeEncoder.encode(pattern).replace("*", "123"),
|
||||
"exit");
|
||||
}
|
||||
|
||||
public void onPUnsubscribe(byte[] pattern, int subscribedChannels) {
|
||||
|
||||
@@ -47,11 +47,13 @@ public class ScriptingCommandsTest extends JedisCommandTestBase {
|
||||
args.add("second".getBytes());
|
||||
args.add("third".getBytes());
|
||||
|
||||
BinaryJedis binaryJedis = new BinaryJedis(hnp.getHost(), hnp.getPort(), 500);
|
||||
BinaryJedis binaryJedis = new BinaryJedis(hnp.getHost(), hnp.getPort(),
|
||||
500);
|
||||
binaryJedis.connect();
|
||||
binaryJedis.auth("foobared");
|
||||
|
||||
List<byte[]> responses = (List<byte[]>) binaryJedis.eval(script.getBytes(), keys, args);
|
||||
List<byte[]> responses = (List<byte[]>) binaryJedis.eval(
|
||||
script.getBytes(), keys, args);
|
||||
assertEquals(5, responses.size());
|
||||
assertEquals("key1", new String(responses.get(0)));
|
||||
assertEquals("key2", new String(responses.get(1)));
|
||||
@@ -169,7 +171,8 @@ public class ScriptingCommandsTest extends JedisCommandTestBase {
|
||||
@Test
|
||||
public void scriptEvalReturnNullValues() {
|
||||
String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}";
|
||||
List<String> results = (List<String>) jedis.eval(script, 2, "key1", "key2", "1", "2");
|
||||
List<String> results = (List<String>) jedis.eval(script, 2, "key1",
|
||||
"key2", "1", "2");
|
||||
assertEquals(results.get(0), "key1");
|
||||
assertEquals(results.get(1), "key2");
|
||||
assertEquals(results.get(2), "1");
|
||||
@@ -180,7 +183,8 @@ public class ScriptingCommandsTest extends JedisCommandTestBase {
|
||||
public void scriptEvalShaReturnNullValues() {
|
||||
String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}";
|
||||
String sha = jedis.scriptLoad(script);
|
||||
List<String> results = (List<String>) jedis.evalsha(sha, 2, "key1", "key2", "1", "2");
|
||||
List<String> results = (List<String>) jedis.evalsha(sha, 2, "key1",
|
||||
"key2", "1", "2");
|
||||
assertEquals(results.get(0), "key1");
|
||||
assertEquals(results.get(1), "key2");
|
||||
assertEquals(results.get(2), "1");
|
||||
@@ -188,4 +192,3 @@ public class ScriptingCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package redis.clients.jedis.tests.commands;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -454,7 +453,6 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
||||
assertNull(bmember);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void sscan() {
|
||||
jedis.sadd("foo", "a", "b");
|
||||
|
||||
@@ -10,7 +10,7 @@ public class SlowlogCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void slowlog() {
|
||||
//do something
|
||||
// do something
|
||||
jedis.configSet("slowlog-log-slower-than", "0");
|
||||
jedis.set("foo", "bar");
|
||||
jedis.set("foo2", "bar2");
|
||||
|
||||
@@ -389,7 +389,8 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(2, bresult);
|
||||
|
||||
bresult = jedis.zcount(bfoo, SafeEncoder.encode("(0.01"), SafeEncoder.encode("+inf"));
|
||||
bresult = jedis.zcount(bfoo, SafeEncoder.encode("(0.01"),
|
||||
SafeEncoder.encode("+inf"));
|
||||
|
||||
assertEquals(3, bresult);
|
||||
}
|
||||
@@ -447,8 +448,8 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
assertEquals(bexpected, brange);
|
||||
|
||||
brange = jedis.zrangeByScore(bfoo, 0d, 2d, 1, 1);
|
||||
Set<byte[]> brange2 = jedis.zrangeByScore(bfoo, SafeEncoder
|
||||
.encode("-inf"), SafeEncoder.encode("(2"));
|
||||
Set<byte[]> brange2 = jedis.zrangeByScore(bfoo,
|
||||
SafeEncoder.encode("-inf"), SafeEncoder.encode("(2"));
|
||||
assertEquals(bexpected, brange2);
|
||||
|
||||
bexpected = new LinkedHashSet<byte[]>();
|
||||
@@ -523,8 +524,8 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(bexpected, brange);
|
||||
|
||||
Set<byte[]> brange2 = jedis.zrevrangeByScore(bfoo, SafeEncoder
|
||||
.encode("+inf"), SafeEncoder.encode("(2"));
|
||||
Set<byte[]> brange2 = jedis.zrevrangeByScore(bfoo,
|
||||
SafeEncoder.encode("+inf"), SafeEncoder.encode("(2"));
|
||||
|
||||
bexpected = new LinkedHashSet<byte[]>();
|
||||
bexpected.add(bb);
|
||||
@@ -763,8 +764,8 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
bexpected.add(new Tuple(bb, new Double(4)));
|
||||
bexpected.add(new Tuple(ba, new Double(3)));
|
||||
|
||||
assertEquals(bexpected, jedis.zrangeWithScores(SafeEncoder
|
||||
.encode("dst"), 0, 100));
|
||||
assertEquals(bexpected,
|
||||
jedis.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -805,8 +806,8 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
bexpected.add(new Tuple(bb, new Double(8)));
|
||||
bexpected.add(new Tuple(ba, new Double(6)));
|
||||
|
||||
assertEquals(bexpected, jedis.zrangeWithScores(SafeEncoder
|
||||
.encode("dst"), 0, 100));
|
||||
assertEquals(bexpected,
|
||||
jedis.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -836,8 +837,8 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
Set<Tuple> bexpected = new LinkedHashSet<Tuple>();
|
||||
bexpected.add(new Tuple(ba, new Double(3)));
|
||||
|
||||
assertEquals(bexpected, jedis.zrangeWithScores(SafeEncoder
|
||||
.encode("dst"), 0, 100));
|
||||
assertEquals(bexpected,
|
||||
jedis.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -874,8 +875,8 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
Set<Tuple> bexpected = new LinkedHashSet<Tuple>();
|
||||
bexpected.add(new Tuple(ba, new Double(6)));
|
||||
|
||||
assertEquals(bexpected, jedis.zrangeWithScores(SafeEncoder
|
||||
.encode("dst"), 0, 100));
|
||||
assertEquals(bexpected,
|
||||
jedis.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -888,7 +889,6 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
assertEquals(0, t2.compareTo(t2));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void zscan() {
|
||||
jedis.zadd("foo", 1, "a");
|
||||
|
||||
@@ -180,8 +180,8 @@ public class StringValuesCommandsTest extends JedisCommandTestBase {
|
||||
public void incrLargeNumbers() {
|
||||
long value = jedis.incr("foo");
|
||||
assertEquals(1, value);
|
||||
assertEquals(1L + Integer.MAX_VALUE, (long) jedis.incrBy("foo",
|
||||
Integer.MAX_VALUE));
|
||||
assertEquals(1L + Integer.MAX_VALUE,
|
||||
(long) jedis.incrBy("foo", Integer.MAX_VALUE));
|
||||
}
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
|
||||
@@ -11,13 +11,12 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.Protocol.Keyword;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
import redis.clients.jedis.Protocol.Keyword;
|
||||
import redis.clients.jedis.Response;
|
||||
import redis.clients.jedis.Transaction;
|
||||
import redis.clients.jedis.TransactionBlock;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
|
||||
public class TransactionCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
|
||||
@@ -52,7 +52,7 @@ public class VariadicCommandsTest extends JedisCommandTestBase {
|
||||
expected.add("bar");
|
||||
expected.add("foo");
|
||||
|
||||
List<String> values = jedis.lrange("foo",0,-1);
|
||||
List<String> values = jedis.lrange("foo", 0, -1);
|
||||
assertEquals(expected, values);
|
||||
|
||||
// Binary
|
||||
@@ -77,7 +77,7 @@ public class VariadicCommandsTest extends JedisCommandTestBase {
|
||||
expected.add("foo");
|
||||
expected.add("bar");
|
||||
|
||||
List<String> values = jedis.lrange("foo",0,-1);
|
||||
List<String> values = jedis.lrange("foo", 0, -1);
|
||||
assertEquals(expected, values);
|
||||
|
||||
// Binary
|
||||
@@ -167,7 +167,7 @@ public class VariadicCommandsTest extends JedisCommandTestBase {
|
||||
status = jedis.zrem("foo", "bar", "foo1");
|
||||
assertEquals(1, status);
|
||||
|
||||
//Binary
|
||||
// Binary
|
||||
jedis.zadd(bfoo, 1d, bbar);
|
||||
jedis.zadd(bfoo, 2d, bcar);
|
||||
jedis.zadd(bfoo, 3d, bfoo1);
|
||||
|
||||
Reference in New Issue
Block a user