Apply "Format" to all files, Closes #765
This commit is contained in:
@@ -572,6 +572,7 @@ public class BinaryClient extends Connection {
|
||||
public void pubsub(final byte[]... args) {
|
||||
sendCommand(PUBSUB, args);
|
||||
}
|
||||
|
||||
public void zcount(final byte[] key, final double min, final double max) {
|
||||
|
||||
byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
|
||||
@@ -844,18 +845,19 @@ public class BinaryClient extends Connection {
|
||||
sendCommand(ZRANGEBYLEX, key, min, max);
|
||||
}
|
||||
|
||||
public void zrangeByLex(final byte[] key, final byte[] min, final byte[] max,
|
||||
final int offset, final int count) {
|
||||
sendCommand(ZRANGEBYLEX, key, min, max, LIMIT.raw,
|
||||
toByteArray(offset), toByteArray(count));
|
||||
public void zrangeByLex(final byte[] key, final byte[] min,
|
||||
final byte[] max, final int offset, final int count) {
|
||||
sendCommand(ZRANGEBYLEX, key, min, max, LIMIT.raw, toByteArray(offset),
|
||||
toByteArray(count));
|
||||
}
|
||||
|
||||
public void zrevrangeByLex(final byte[] key, final byte[] max, final byte[] min) {
|
||||
public void zrevrangeByLex(final byte[] key, final byte[] max,
|
||||
final byte[] min) {
|
||||
sendCommand(ZREVRANGEBYLEX, key, max, min);
|
||||
}
|
||||
|
||||
public void zrevrangeByLex(final byte[] key, final byte[] max, final byte[] min,
|
||||
final int offset, final int count) {
|
||||
public void zrevrangeByLex(final byte[] key, final byte[] max,
|
||||
final byte[] min, final int offset, final int count) {
|
||||
sendCommand(ZREVRANGEBYLEX, key, max, min, LIMIT.raw,
|
||||
toByteArray(offset), toByteArray(count));
|
||||
}
|
||||
@@ -966,7 +968,8 @@ public class BinaryClient extends Connection {
|
||||
sendCommand(GETBIT, key, toByteArray(offset));
|
||||
}
|
||||
|
||||
public void bitpos(final byte[] key, final boolean value, final BitPosParams params) {
|
||||
public void bitpos(final byte[] key, final boolean value,
|
||||
final BitPosParams params) {
|
||||
final List<byte[]> args = new ArrayList<byte[]>();
|
||||
args.add(key);
|
||||
args.add(toByteArray(value));
|
||||
@@ -1200,7 +1203,8 @@ public class BinaryClient extends Connection {
|
||||
sendCommand(SCAN, args.toArray(new byte[args.size()][]));
|
||||
}
|
||||
|
||||
public void hscan(final byte[] key, final byte[] cursor, final ScanParams params) {
|
||||
public void hscan(final byte[] key, final byte[] cursor,
|
||||
final ScanParams params) {
|
||||
final List<byte[]> args = new ArrayList<byte[]>();
|
||||
args.add(key);
|
||||
args.add(cursor);
|
||||
@@ -1208,7 +1212,8 @@ public class BinaryClient extends Connection {
|
||||
sendCommand(HSCAN, args.toArray(new byte[args.size()][]));
|
||||
}
|
||||
|
||||
public void sscan(final byte[] key, final byte[] cursor, final ScanParams params) {
|
||||
public void sscan(final byte[] key, final byte[] cursor,
|
||||
final ScanParams params) {
|
||||
final List<byte[]> args = new ArrayList<byte[]>();
|
||||
args.add(key);
|
||||
args.add(cursor);
|
||||
@@ -1216,7 +1221,8 @@ public class BinaryClient extends Connection {
|
||||
sendCommand(SSCAN, args.toArray(new byte[args.size()][]));
|
||||
}
|
||||
|
||||
public void zscan(final byte[] key, final byte[] cursor, final ScanParams params) {
|
||||
public void zscan(final byte[] key, final byte[] cursor,
|
||||
final ScanParams params) {
|
||||
final List<byte[]> args = new ArrayList<byte[]>();
|
||||
args.add(key);
|
||||
args.add(cursor);
|
||||
|
||||
@@ -2838,15 +2838,16 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zrangeByLex(final byte[] key, final byte[] min, final byte[] max) {
|
||||
public Set<byte[]> zrangeByLex(final byte[] key, final byte[] min,
|
||||
final byte[] max) {
|
||||
checkIsInMulti();
|
||||
client.zrangeByLex(key, min, max);
|
||||
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zrangeByLex(final byte[] key, final byte[] min, final byte[] max,
|
||||
final int offset, final int count) {
|
||||
public Set<byte[]> zrangeByLex(final byte[] key, final byte[] min,
|
||||
final byte[] max, final int offset, final int count) {
|
||||
checkIsInMulti();
|
||||
client.zrangeByLex(key, min, max, offset, count);
|
||||
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
|
||||
@@ -2868,7 +2869,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long zremrangeByLex(final byte[] key, final byte[] min, final byte[] max) {
|
||||
public Long zremrangeByLex(final byte[] key, final byte[] min,
|
||||
final byte[] max) {
|
||||
checkIsInMulti();
|
||||
client.zremrangeByLex(key, min, max);
|
||||
return client.getIntegerReply();
|
||||
|
||||
@@ -201,13 +201,14 @@ public interface BinaryJedisCommands {
|
||||
|
||||
Set<byte[]> zrangeByLex(final byte[] key, final byte[] min, final byte[] max);
|
||||
|
||||
Set<byte[]> zrangeByLex(final byte[] key, final byte[] min, final byte[] max,
|
||||
int offset, int count);
|
||||
Set<byte[]> zrangeByLex(final byte[] key, final byte[] min,
|
||||
final byte[] max, int offset, int count);
|
||||
|
||||
Set<byte[]> zrevrangeByLex(final byte[] key, final byte[] max, final byte[] min);
|
||||
Set<byte[]> zrevrangeByLex(final byte[] key, final byte[] max,
|
||||
final byte[] min);
|
||||
|
||||
Set<byte[]> zrevrangeByLex(final byte[] key, final byte[] max, final byte[] min,
|
||||
int offset, int count);
|
||||
Set<byte[]> zrevrangeByLex(final byte[] key, final byte[] max,
|
||||
final byte[] min, int offset, int count);
|
||||
|
||||
Long zremrangeByLex(final byte[] key, final byte[] min, final byte[] max);
|
||||
|
||||
|
||||
@@ -207,19 +207,23 @@ public interface BinaryRedisPipeline {
|
||||
|
||||
Response<Double> zscore(byte[] key, byte[] member);
|
||||
|
||||
Response<Long> zlexcount(final byte[] key, final byte[] min, final byte[] max);
|
||||
Response<Long> zlexcount(final byte[] key, final byte[] min,
|
||||
final byte[] max);
|
||||
|
||||
Response<Set<byte[]>> zrangeByLex(final byte[] key, final byte[] min, final byte[] max);
|
||||
Response<Set<byte[]>> zrangeByLex(final byte[] key, final byte[] min,
|
||||
final byte[] max);
|
||||
|
||||
Response<Set<byte[]>> zrangeByLex(final byte[] key, final byte[] min, final byte[] max,
|
||||
int offset, int count);
|
||||
Response<Set<byte[]>> zrangeByLex(final byte[] key, final byte[] min,
|
||||
final byte[] max, int offset, int count);
|
||||
|
||||
Response<Set<byte[]>> zrevrangeByLex(final byte[] key, final byte[] max, final byte[] min);
|
||||
Response<Set<byte[]>> zrevrangeByLex(final byte[] key, final byte[] max,
|
||||
final byte[] min);
|
||||
|
||||
Response<Set<byte[]>> zrevrangeByLex(final byte[] key, final byte[] max, final byte[] min,
|
||||
int offset, int count);
|
||||
Response<Set<byte[]>> zrevrangeByLex(final byte[] key, final byte[] max,
|
||||
final byte[] min, int offset, int count);
|
||||
|
||||
Response<Long> zremrangeByLex(final byte[] key, final byte[] min, final byte[] max);
|
||||
Response<Long> zremrangeByLex(final byte[] key, final byte[] min,
|
||||
final byte[] max);
|
||||
|
||||
Response<Long> bitcount(byte[] key);
|
||||
|
||||
|
||||
@@ -498,14 +498,15 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zrangeByLex(final byte[] key, final byte[] min, final byte[] max) {
|
||||
public Set<byte[]> zrangeByLex(final byte[] key, final byte[] min,
|
||||
final byte[] max) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByLex(key, min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zrangeByLex(final byte[] key, final byte[] min, final byte[] max,
|
||||
final int offset, final int count) {
|
||||
public Set<byte[]> zrangeByLex(final byte[] key, final byte[] min,
|
||||
final byte[] max, final int offset, final int count) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zrangeByLex(key, min, max, offset, count);
|
||||
}
|
||||
@@ -524,7 +525,8 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long zremrangeByLex(final byte[] key, final byte[] min, final byte[] max) {
|
||||
public Long zremrangeByLex(final byte[] key, final byte[] min,
|
||||
final byte[] max) {
|
||||
Jedis j = getShard(key);
|
||||
return j.zremrangeByLex(key, min, max);
|
||||
}
|
||||
|
||||
@@ -593,31 +593,36 @@ public class Client extends BinaryClient implements Commands {
|
||||
}
|
||||
|
||||
public void zlexcount(final String key, final String min, final String max) {
|
||||
zlexcount(SafeEncoder.encode(key), SafeEncoder.encode(min), SafeEncoder.encode(max));
|
||||
zlexcount(SafeEncoder.encode(key), SafeEncoder.encode(min),
|
||||
SafeEncoder.encode(max));
|
||||
}
|
||||
|
||||
public void zrangeByLex(final String key, final String min, final String max) {
|
||||
zrangeByLex(SafeEncoder.encode(key), SafeEncoder.encode(min), SafeEncoder.encode(max));
|
||||
zrangeByLex(SafeEncoder.encode(key), SafeEncoder.encode(min),
|
||||
SafeEncoder.encode(max));
|
||||
}
|
||||
|
||||
public void zrangeByLex(final String key, final String min, final String max,
|
||||
final int offset, final int count) {
|
||||
zrangeByLex(SafeEncoder.encode(key), SafeEncoder.encode(min), SafeEncoder.encode(max),
|
||||
offset, count);
|
||||
public void zrangeByLex(final String key, final String min,
|
||||
final String max, final int offset, final int count) {
|
||||
zrangeByLex(SafeEncoder.encode(key), SafeEncoder.encode(min),
|
||||
SafeEncoder.encode(max), offset, count);
|
||||
}
|
||||
|
||||
public void zrevrangeByLex(String key, String max, String min) {
|
||||
zrevrangeByLex(SafeEncoder.encode(key), SafeEncoder.encode(max), SafeEncoder.encode(min));
|
||||
zrevrangeByLex(SafeEncoder.encode(key), SafeEncoder.encode(max),
|
||||
SafeEncoder.encode(min));
|
||||
}
|
||||
|
||||
public void zrevrangeByLex(String key, String max, String min, int offset,
|
||||
int count) {
|
||||
zrevrangeByLex(SafeEncoder.encode(key), SafeEncoder.encode(max), SafeEncoder.encode(min),
|
||||
offset, count);
|
||||
zrevrangeByLex(SafeEncoder.encode(key), SafeEncoder.encode(max),
|
||||
SafeEncoder.encode(min), offset, count);
|
||||
}
|
||||
|
||||
public void zremrangeByLex(final String key, final String min, final String max) {
|
||||
zremrangeByLex(SafeEncoder.encode(key), SafeEncoder.encode(min), SafeEncoder.encode(max));
|
||||
public void zremrangeByLex(final String key, final String min,
|
||||
final String max) {
|
||||
zremrangeByLex(SafeEncoder.encode(key), SafeEncoder.encode(min),
|
||||
SafeEncoder.encode(max));
|
||||
}
|
||||
|
||||
public void strlen(final String key) {
|
||||
@@ -663,9 +668,11 @@ public class Client extends BinaryClient implements Commands {
|
||||
getbit(SafeEncoder.encode(key), offset);
|
||||
}
|
||||
|
||||
public void bitpos(final String key, final boolean value, final BitPosParams params) {
|
||||
public void bitpos(final String key, final boolean value,
|
||||
final BitPosParams params) {
|
||||
bitpos(SafeEncoder.encode(key), value, params);
|
||||
}
|
||||
|
||||
public void setrange(String key, long offset, String value) {
|
||||
setrange(SafeEncoder.encode(key), offset, SafeEncoder.encode(value));
|
||||
}
|
||||
@@ -874,15 +881,18 @@ public class Client extends BinaryClient implements Commands {
|
||||
scan(SafeEncoder.encode(cursor), params);
|
||||
}
|
||||
|
||||
public void hscan(final String key, final String cursor, final ScanParams params) {
|
||||
public void hscan(final String key, final String cursor,
|
||||
final ScanParams params) {
|
||||
hscan(SafeEncoder.encode(key), SafeEncoder.encode(cursor), params);
|
||||
}
|
||||
|
||||
public void sscan(final String key, final String cursor, final ScanParams params) {
|
||||
public void sscan(final String key, final String cursor,
|
||||
final ScanParams params) {
|
||||
sscan(SafeEncoder.encode(key), SafeEncoder.encode(cursor), params);
|
||||
}
|
||||
|
||||
public void zscan(final String key, final String cursor, final ScanParams params) {
|
||||
public void zscan(final String key, final String cursor,
|
||||
final ScanParams params) {
|
||||
zscan(SafeEncoder.encode(key), SafeEncoder.encode(cursor), params);
|
||||
}
|
||||
|
||||
@@ -978,6 +988,7 @@ public class Client extends BinaryClient implements Commands {
|
||||
public void pfmerge(final String destkey, final String... sourcekeys) {
|
||||
pfmerge(SafeEncoder.encode(destkey), SafeEncoder.encodeMany(sourcekeys));
|
||||
}
|
||||
|
||||
public void clusterSetSlotStable(final int slot) {
|
||||
cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot),
|
||||
Protocol.CLUSTER_SETSLOT_STABLE);
|
||||
|
||||
@@ -81,7 +81,8 @@ public interface Commands {
|
||||
|
||||
public void hincrBy(final String key, final String field, final long value);
|
||||
|
||||
public void hincrByFloat(final String key, final String field, final double value);
|
||||
public void hincrByFloat(final String key, final String field,
|
||||
final double value);
|
||||
|
||||
public void hexists(final String key, final String field);
|
||||
|
||||
@@ -303,11 +304,14 @@ public interface Commands {
|
||||
|
||||
public void scan(final String cursor, final ScanParams params);
|
||||
|
||||
public void hscan(final String key, final String cursor, final ScanParams params);
|
||||
public void hscan(final String key, final String cursor,
|
||||
final ScanParams params);
|
||||
|
||||
public void sscan(final String key, final String cursor, final ScanParams params);
|
||||
public void sscan(final String key, final String cursor,
|
||||
final ScanParams params);
|
||||
|
||||
public void zscan(final String key, final String cursor, final ScanParams params);
|
||||
public void zscan(final String key, final String cursor,
|
||||
final ScanParams params);
|
||||
|
||||
public void waitReplicas(int replicas, long timeout);
|
||||
}
|
||||
|
||||
@@ -326,11 +326,11 @@ public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
*
|
||||
* @param key
|
||||
* @return Integer reply, returns the remaining time to live in seconds of a
|
||||
* key that has an EXPIRE.
|
||||
* In Redis 2.6 or older, if the Key does not exists or does not
|
||||
* have an associated expire, -1 is returned.
|
||||
* In Redis 2.8 or newer, if the Key does not have an associated expire, -1 is returned
|
||||
* or if the Key does not exists, -2 is returned.
|
||||
* key that has an EXPIRE. In Redis 2.6 or older, if the Key does
|
||||
* not exists or does not have an associated expire, -1 is returned.
|
||||
* In Redis 2.8 or newer, if the Key does not have an associated
|
||||
* expire, -1 is returned or if the Key does not exists, -2 is
|
||||
* returned.
|
||||
*/
|
||||
public Long ttl(final String key) {
|
||||
checkIsInMulti();
|
||||
@@ -2639,15 +2639,16 @@ public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> zrangeByLex(final String key, final String min, final String max) {
|
||||
public Set<String> zrangeByLex(final String key, final String min,
|
||||
final String max) {
|
||||
checkIsInMulti();
|
||||
client.zrangeByLex(key, min, max);
|
||||
return new LinkedHashSet<String>(client.getMultiBulkReply());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> zrangeByLex(final String key, final String min, final String max,
|
||||
final int offset, final int count) {
|
||||
public Set<String> zrangeByLex(final String key, final String min,
|
||||
final String max, final int offset, final int count) {
|
||||
checkIsInMulti();
|
||||
client.zrangeByLex(key, min, max, offset, count);
|
||||
return new LinkedHashSet<String>(client.getMultiBulkReply());
|
||||
@@ -2669,7 +2670,8 @@ public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long zremrangeByLex(final String key, final String min, final String max) {
|
||||
public Long zremrangeByLex(final String key, final String min,
|
||||
final String max) {
|
||||
checkIsInMulti();
|
||||
client.zremrangeByLex(key, min, max);
|
||||
return client.getIntegerReply();
|
||||
@@ -3459,8 +3461,8 @@ public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
public Map<String, String> pubsubNumSub(String... channels) {
|
||||
checkIsInMulti();
|
||||
client.pubsubNumSub(channels);
|
||||
return BuilderFactory.PUBSUB_NUMSUB_MAP
|
||||
.build(client.getBinaryMultiBulkReply());
|
||||
return BuilderFactory.PUBSUB_NUMSUB_MAP.build(client
|
||||
.getBinaryMultiBulkReply());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -10,12 +8,16 @@ import java.util.Set;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
|
||||
public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
public static final short HASHSLOTS = 16384;
|
||||
private static final int DEFAULT_TIMEOUT = 1;
|
||||
private static final int DEFAULT_MAX_REDIRECTIONS = 5;
|
||||
|
||||
public static enum Reset {SOFT, HARD}
|
||||
public static enum Reset {
|
||||
SOFT, HARD
|
||||
}
|
||||
|
||||
private int timeout;
|
||||
private int maxRedirections;
|
||||
@@ -30,10 +32,8 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
this(nodes, DEFAULT_TIMEOUT);
|
||||
}
|
||||
|
||||
public JedisCluster(Set<HostAndPort> nodes, int timeout,
|
||||
int maxRedirections) {
|
||||
this(nodes, timeout, maxRedirections,
|
||||
new GenericObjectPoolConfig());
|
||||
public JedisCluster(Set<HostAndPort> nodes, int timeout, int maxRedirections) {
|
||||
this(nodes, timeout, maxRedirections, new GenericObjectPoolConfig());
|
||||
}
|
||||
|
||||
public JedisCluster(Set<HostAndPort> nodes,
|
||||
@@ -153,8 +153,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Long execute(Jedis connection) {
|
||||
return connection
|
||||
.expireAt(key, unixTime);
|
||||
return connection.expireAt(key, unixTime);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -177,8 +176,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Boolean execute(Jedis connection) {
|
||||
return connection.setbit(key, offset,
|
||||
value);
|
||||
return connection.setbit(key, offset, value);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -190,8 +188,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Boolean execute(Jedis connection) {
|
||||
return connection.setbit(key, offset,
|
||||
value);
|
||||
return connection.setbit(key, offset, value);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -213,8 +210,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Long execute(Jedis connection) {
|
||||
return connection.setrange(key, offset,
|
||||
value);
|
||||
return connection.setrange(key, offset, value);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -226,8 +222,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public String execute(Jedis connection) {
|
||||
return connection.getrange(key,
|
||||
startOffset, endOffset);
|
||||
return connection.getrange(key, startOffset, endOffset);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -260,8 +255,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public String execute(Jedis connection) {
|
||||
return connection.setex(key, seconds,
|
||||
value);
|
||||
return connection.setex(key, seconds, value);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -327,8 +321,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public String execute(Jedis connection) {
|
||||
return connection
|
||||
.substr(key, start, end);
|
||||
return connection.substr(key, start, end);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -339,8 +332,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Long execute(Jedis connection) {
|
||||
return connection
|
||||
.hset(key, field, value);
|
||||
return connection.hset(key, field, value);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -362,8 +354,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Long execute(Jedis connection) {
|
||||
return connection.hsetnx(key, field,
|
||||
value);
|
||||
return connection.hsetnx(key, field, value);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -396,8 +387,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Long execute(Jedis connection) {
|
||||
return connection.hincrBy(key, field,
|
||||
value);
|
||||
return connection.hincrBy(key, field, value);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -508,8 +498,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
timeout, maxRedirections) {
|
||||
@Override
|
||||
public List<String> execute(Jedis connection) {
|
||||
return connection
|
||||
.lrange(key, start, end);
|
||||
return connection.lrange(key, start, end);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -542,8 +531,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public String execute(Jedis connection) {
|
||||
return connection
|
||||
.lset(key, index, value);
|
||||
return connection.lset(key, index, value);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -554,8 +542,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Long execute(Jedis connection) {
|
||||
return connection
|
||||
.lrem(key, count, value);
|
||||
return connection.lrem(key, count, value);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -661,8 +648,8 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
|
||||
@Override
|
||||
public List<String> srandmember(final String key, final int count) {
|
||||
return new JedisClusterCommand<List<String>>(connectionHandler, timeout,
|
||||
maxRedirections) {
|
||||
return new JedisClusterCommand<List<String>>(connectionHandler,
|
||||
timeout, maxRedirections) {
|
||||
@Override
|
||||
public List<String> execute(Jedis connection) {
|
||||
return connection.srandmember(key, count);
|
||||
@@ -687,8 +674,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Long execute(Jedis connection) {
|
||||
return connection.zadd(key, score,
|
||||
member);
|
||||
return connection.zadd(key, score, member);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -699,8 +685,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Long execute(Jedis connection) {
|
||||
return connection
|
||||
.zadd(key, scoreMembers);
|
||||
return connection.zadd(key, scoreMembers);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -711,8 +696,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<String> execute(Jedis connection) {
|
||||
return connection
|
||||
.zrange(key, start, end);
|
||||
return connection.zrange(key, start, end);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -735,8 +719,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Double execute(Jedis connection) {
|
||||
return connection.zincrby(key, score,
|
||||
member);
|
||||
return connection.zincrby(key, score, member);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -770,8 +753,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<String> execute(Jedis connection) {
|
||||
return connection.zrevrange(key, start,
|
||||
end);
|
||||
return connection.zrevrange(key, start, end);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -783,8 +765,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<Tuple> execute(Jedis connection) {
|
||||
return connection.zrangeWithScores(key,
|
||||
start, end);
|
||||
return connection.zrangeWithScores(key, start, end);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -796,8 +777,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<Tuple> execute(Jedis connection) {
|
||||
return connection.zrevrangeWithScores(
|
||||
key, start, end);
|
||||
return connection.zrevrangeWithScores(key, start, end);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -842,8 +822,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
timeout, maxRedirections) {
|
||||
@Override
|
||||
public List<String> execute(Jedis connection) {
|
||||
return connection.sort(key,
|
||||
sortingParameters);
|
||||
return connection.sort(key, sortingParameters);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -877,8 +856,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<String> execute(Jedis connection) {
|
||||
return connection.zrangeByScore(key,
|
||||
min, max);
|
||||
return connection.zrangeByScore(key, min, max);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -890,8 +868,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<String> execute(Jedis connection) {
|
||||
return connection.zrangeByScore(key,
|
||||
min, max);
|
||||
return connection.zrangeByScore(key, min, max);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -903,8 +880,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<String> execute(Jedis connection) {
|
||||
return connection.zrevrangeByScore(key,
|
||||
min, max);
|
||||
return connection.zrevrangeByScore(key, min, max);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -916,8 +892,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<String> execute(Jedis connection) {
|
||||
return connection.zrangeByScore(key,
|
||||
min, max, offset, count);
|
||||
return connection.zrangeByScore(key, min, max, offset, count);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -929,8 +904,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<String> execute(Jedis connection) {
|
||||
return connection.zrevrangeByScore(key,
|
||||
min, max);
|
||||
return connection.zrevrangeByScore(key, min, max);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -942,8 +916,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<String> execute(Jedis connection) {
|
||||
return connection.zrangeByScore(key,
|
||||
min, max, offset, count);
|
||||
return connection.zrangeByScore(key, min, max, offset, count);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -955,8 +928,8 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<String> execute(Jedis connection) {
|
||||
return connection.zrevrangeByScore(key,
|
||||
min, max, offset, count);
|
||||
return connection
|
||||
.zrevrangeByScore(key, min, max, offset, count);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -968,8 +941,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<Tuple> execute(Jedis connection) {
|
||||
return connection
|
||||
.zrangeByScoreWithScores(key, min, max);
|
||||
return connection.zrangeByScoreWithScores(key, min, max);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -981,8 +953,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<Tuple> execute(Jedis connection) {
|
||||
return connection
|
||||
.zrevrangeByScoreWithScores(key, min, max);
|
||||
return connection.zrevrangeByScoreWithScores(key, min, max);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -995,8 +966,8 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<Tuple> execute(Jedis connection) {
|
||||
return connection
|
||||
.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||
return connection.zrangeByScoreWithScores(key, min, max,
|
||||
offset, count);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -1008,8 +979,8 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<String> execute(Jedis connection) {
|
||||
return connection.zrevrangeByScore(key,
|
||||
min, max, offset, count);
|
||||
return connection
|
||||
.zrevrangeByScore(key, min, max, offset, count);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -1021,8 +992,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<Tuple> execute(Jedis connection) {
|
||||
return connection
|
||||
.zrangeByScoreWithScores(key, min, max);
|
||||
return connection.zrangeByScoreWithScores(key, min, max);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -1034,8 +1004,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<Tuple> execute(Jedis connection) {
|
||||
return connection
|
||||
.zrevrangeByScoreWithScores(key, min, max);
|
||||
return connection.zrevrangeByScoreWithScores(key, min, max);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -1048,8 +1017,8 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<Tuple> execute(Jedis connection) {
|
||||
return connection
|
||||
.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||
return connection.zrangeByScoreWithScores(key, min, max,
|
||||
offset, count);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -1062,9 +1031,8 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<Tuple> execute(Jedis connection) {
|
||||
return connection
|
||||
.zrevrangeByScoreWithScores(key, max, min, offset,
|
||||
count);
|
||||
return connection.zrevrangeByScoreWithScores(key, max, min,
|
||||
offset, count);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -1077,9 +1045,8 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Set<Tuple> execute(Jedis connection) {
|
||||
return connection
|
||||
.zrevrangeByScoreWithScores(key, max, min, offset,
|
||||
count);
|
||||
return connection.zrevrangeByScoreWithScores(key, max, min,
|
||||
offset, count);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -1091,8 +1058,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Long execute(Jedis connection) {
|
||||
return connection.zremrangeByRank(key,
|
||||
start, end);
|
||||
return connection.zremrangeByRank(key, start, end);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -1104,8 +1070,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Long execute(Jedis connection) {
|
||||
return connection.zremrangeByScore(key,
|
||||
start, end);
|
||||
return connection.zremrangeByScore(key, start, end);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -1117,8 +1082,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Long execute(Jedis connection) {
|
||||
return connection.zremrangeByScore(key,
|
||||
start, end);
|
||||
return connection.zremrangeByScore(key, start, end);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -1135,7 +1099,8 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> zrangeByLex(final String key, final String min, final String max) {
|
||||
public Set<String> zrangeByLex(final String key, final String min,
|
||||
final String max) {
|
||||
return new JedisClusterCommand<Set<String>>(connectionHandler, timeout,
|
||||
maxRedirections) {
|
||||
@Override
|
||||
@@ -1146,8 +1111,8 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> zrangeByLex(final String key, final String min, final String max,
|
||||
final int offset, final int count) {
|
||||
public Set<String> zrangeByLex(final String key, final String min,
|
||||
final String max, final int offset, final int count) {
|
||||
return new JedisClusterCommand<Set<String>>(connectionHandler, timeout,
|
||||
maxRedirections) {
|
||||
@Override
|
||||
@@ -1158,7 +1123,8 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> zrevrangeByLex(final String key, final String max, final String min) {
|
||||
public Set<String> zrevrangeByLex(final String key, final String max,
|
||||
final String min) {
|
||||
return new JedisClusterCommand<Set<String>>(connectionHandler, timeout,
|
||||
maxRedirections) {
|
||||
@Override
|
||||
@@ -1169,8 +1135,8 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> zrevrangeByLex(final String key, final String max, final String min,
|
||||
final int offset, final int count) {
|
||||
public Set<String> zrevrangeByLex(final String key, final String max,
|
||||
final String min, final int offset, final int count) {
|
||||
return new JedisClusterCommand<Set<String>>(connectionHandler, timeout,
|
||||
maxRedirections) {
|
||||
@Override
|
||||
@@ -1181,7 +1147,8 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long zremrangeByLex(final String key, final String min, final String max) {
|
||||
public Long zremrangeByLex(final String key, final String min,
|
||||
final String max) {
|
||||
return new JedisClusterCommand<Long>(connectionHandler, timeout,
|
||||
maxRedirections) {
|
||||
@Override
|
||||
@@ -1198,8 +1165,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Long execute(Jedis connection) {
|
||||
return connection.linsert(key, where,
|
||||
pivot, value);
|
||||
return connection.linsert(key, where, pivot, value);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -1298,8 +1264,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Long execute(Jedis connection) {
|
||||
return connection.bitcount(key, start,
|
||||
end);
|
||||
return connection.bitcount(key, start, end);
|
||||
}
|
||||
}.run(key);
|
||||
}
|
||||
@@ -1559,8 +1524,8 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
|
||||
@Override
|
||||
public Long pfadd(final String key, final String... elements) {
|
||||
return new JedisClusterCommand<Long>(connectionHandler,
|
||||
timeout, maxRedirections) {
|
||||
return new JedisClusterCommand<Long>(connectionHandler, timeout,
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Long execute(Jedis connection) {
|
||||
return connection.pfadd(key, elements);
|
||||
@@ -1570,8 +1535,8 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable {
|
||||
|
||||
@Override
|
||||
public long pfcount(final String key) {
|
||||
return new JedisClusterCommand<Long>(connectionHandler,
|
||||
timeout, maxRedirections) {
|
||||
return new JedisClusterCommand<Long>(connectionHandler, timeout,
|
||||
maxRedirections) {
|
||||
@Override
|
||||
public Long execute(Jedis connection) {
|
||||
return connection.pfcount(key);
|
||||
|
||||
@@ -43,7 +43,6 @@ public abstract class JedisClusterCommand<T> {
|
||||
Jedis connection = null;
|
||||
try {
|
||||
|
||||
|
||||
if (asking) {
|
||||
// TODO: Pipeline asking with the original command to make it
|
||||
// faster....
|
||||
@@ -57,7 +56,8 @@ public abstract class JedisClusterCommand<T> {
|
||||
connection = connectionHandler.getConnection();
|
||||
} else {
|
||||
connection = connectionHandler
|
||||
.getConnectionFromSlot(JedisClusterCRC16.getSlot(key));
|
||||
.getConnectionFromSlot(JedisClusterCRC16
|
||||
.getSlot(key));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,8 @@ public abstract class JedisClusterCommand<T> {
|
||||
} catch (JedisRedirectionException jre) {
|
||||
if (jre instanceof JedisAskDataException) {
|
||||
asking = true;
|
||||
askConnection.set(this.connectionHandler.getConnectionFromNode(jre.getTargetNode()));
|
||||
askConnection.set(this.connectionHandler
|
||||
.getConnectionFromNode(jre.getTargetNode()));
|
||||
} else if (jre instanceof JedisMovedDataException) {
|
||||
// it rebuilds cluster's slot cache
|
||||
// recommended by Redis cluster specification
|
||||
|
||||
@@ -32,7 +32,8 @@ public abstract class JedisClusterConnectionHandler {
|
||||
.getResource();
|
||||
}
|
||||
|
||||
public JedisClusterConnectionHandler(Set<HostAndPort> nodes, final GenericObjectPoolConfig poolConfig) {
|
||||
public JedisClusterConnectionHandler(Set<HostAndPort> nodes,
|
||||
final GenericObjectPoolConfig poolConfig) {
|
||||
this.cache = new JedisClusterInfoCache(poolConfig);
|
||||
initializeSlotsCache(nodes, poolConfig);
|
||||
}
|
||||
@@ -45,7 +46,8 @@ public abstract class JedisClusterConnectionHandler {
|
||||
cache.assignSlotToNode(slot, targetNode);
|
||||
}
|
||||
|
||||
private void initializeSlotsCache(Set<HostAndPort> startNodes, GenericObjectPoolConfig poolConfig) {
|
||||
private void initializeSlotsCache(Set<HostAndPort> startNodes,
|
||||
GenericObjectPoolConfig poolConfig) {
|
||||
for (HostAndPort hostAndPort : startNodes) {
|
||||
JedisPool jp = new JedisPool(poolConfig, hostAndPort.getHost(),
|
||||
hostAndPort.getPort());
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import redis.clients.util.ClusterNodeInformation;
|
||||
import redis.clients.util.ClusterNodeInformationParser;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -12,6 +7,12 @@ import java.util.Map;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
|
||||
import redis.clients.util.ClusterNodeInformation;
|
||||
import redis.clients.util.ClusterNodeInformationParser;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
public class JedisClusterInfoCache {
|
||||
public static final ClusterNodeInformationParser nodeInfoParser = new ClusterNodeInformationParser();
|
||||
|
||||
@@ -96,7 +97,8 @@ public class JedisClusterInfoCache {
|
||||
if (nodes.containsKey(nodeKey))
|
||||
return;
|
||||
|
||||
JedisPool nodePool = new JedisPool(poolConfig, node.getHost(), node.getPort());
|
||||
JedisPool nodePool = new JedisPool(poolConfig, node.getHost(),
|
||||
node.getPort());
|
||||
nodes.put(nodeKey, nodePool);
|
||||
} finally {
|
||||
w.unlock();
|
||||
|
||||
@@ -10,8 +10,7 @@ import java.util.Set;
|
||||
public interface JedisCommands {
|
||||
String set(String key, String value);
|
||||
|
||||
String set(String key, String value, String nxxx,
|
||||
String expx, long time);
|
||||
String set(String key, String value, String nxxx, String expx, long time);
|
||||
|
||||
String get(String key);
|
||||
|
||||
@@ -199,13 +198,14 @@ public interface JedisCommands {
|
||||
|
||||
Set<String> zrangeByLex(final String key, final String min, final String max);
|
||||
|
||||
Set<String> zrangeByLex(final String key, final String min, final String max,
|
||||
final int offset, final int count);
|
||||
Set<String> zrangeByLex(final String key, final String min,
|
||||
final String max, final int offset, final int count);
|
||||
|
||||
Set<String> zrevrangeByLex(final String key, final String max, final String min);
|
||||
Set<String> zrevrangeByLex(final String key, final String max,
|
||||
final String min);
|
||||
|
||||
Set<String> zrevrangeByLex(final String key, final String max, final String min,
|
||||
final int offset, final int count);
|
||||
Set<String> zrevrangeByLex(final String key, final String max,
|
||||
final String min, final int offset, final int count);
|
||||
|
||||
Long zremrangeByLex(final String key, final String min, final String max);
|
||||
|
||||
@@ -234,7 +234,8 @@ public interface JedisCommands {
|
||||
|
||||
Long bitcount(final String key, long start, long end);
|
||||
|
||||
ScanResult<Map.Entry<String, String>> hscan(final String key, final String cursor);
|
||||
ScanResult<Map.Entry<String, String>> hscan(final String key,
|
||||
final String cursor);
|
||||
|
||||
ScanResult<String> sscan(final String key, final String cursor);
|
||||
|
||||
|
||||
@@ -65,7 +65,8 @@ class JedisFactory implements PooledObjectFactory<Jedis> {
|
||||
@Override
|
||||
public PooledObject<Jedis> makeObject() throws Exception {
|
||||
final HostAndPort hostAndPort = this.hostAndPort.get();
|
||||
final Jedis jedis = new Jedis(hostAndPort.getHost(), hostAndPort.getPort(), this.timeout);
|
||||
final Jedis jedis = new Jedis(hostAndPort.getHost(),
|
||||
hostAndPort.getPort(), this.timeout);
|
||||
|
||||
jedis.connect();
|
||||
if (null != this.password) {
|
||||
@@ -96,8 +97,9 @@ class JedisFactory implements PooledObjectFactory<Jedis> {
|
||||
String connectionHost = jedis.getClient().getHost();
|
||||
int connectionPort = jedis.getClient().getPort();
|
||||
|
||||
return hostAndPort.getHost().equals(connectionHost) && hostAndPort.getPort() == connectionPort &&
|
||||
jedis.isConnected() && jedis.ping().equals("PONG");
|
||||
return hostAndPort.getHost().equals(connectionHost)
|
||||
&& hostAndPort.getPort() == connectionPort
|
||||
&& jedis.isConnected() && jedis.ping().equals("PONG");
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -100,8 +100,10 @@ public class JedisSentinelPool extends Pool<Jedis> {
|
||||
initPool(poolConfig, factory);
|
||||
} else {
|
||||
factory.setHostAndPort(currentHostMaster);
|
||||
// although we clear the pool, we still have to check the returned object
|
||||
// in getResource, this call only clears idle instances, not borrowed instances
|
||||
// although we clear the pool, we still have to check the
|
||||
// returned object
|
||||
// in getResource, this call only clears idle instances, not
|
||||
// borrowed instances
|
||||
internalPool.clear();
|
||||
}
|
||||
|
||||
@@ -154,11 +156,13 @@ public class JedisSentinelPool extends Pool<Jedis> {
|
||||
|
||||
if (master == null) {
|
||||
if (sentinelAvailable) {
|
||||
// can connect to sentinel, but master name seems to not monitored
|
||||
throw new JedisException("Can connect to sentinel, but " + masterName
|
||||
+ " seems to be not monitored...");
|
||||
// can connect to sentinel, but master name seems to not
|
||||
// monitored
|
||||
throw new JedisException("Can connect to sentinel, but "
|
||||
+ masterName + " seems to be not monitored...");
|
||||
} else {
|
||||
throw new JedisConnectionException("All sentinels down, cannot determine where is "
|
||||
throw new JedisConnectionException(
|
||||
"All sentinels down, cannot determine where is "
|
||||
+ masterName + " master is running...");
|
||||
}
|
||||
}
|
||||
@@ -193,8 +197,8 @@ public class JedisSentinelPool extends Pool<Jedis> {
|
||||
|
||||
// get a reference because it can change concurrently
|
||||
final HostAndPort master = currentHostMaster;
|
||||
final HostAndPort connection = new HostAndPort(jedis.getClient().getHost(),
|
||||
jedis.getClient().getPort());
|
||||
final HostAndPort connection = new HostAndPort(jedis.getClient()
|
||||
.getHost(), jedis.getClient().getPort());
|
||||
|
||||
if (master.equals(connection)) {
|
||||
// connected to the correct master
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
|
||||
public class JedisSlotBasedConnectionHandler extends
|
||||
JedisClusterConnectionHandler {
|
||||
|
||||
@@ -18,7 +19,8 @@ public class JedisSlotBasedConnectionHandler extends
|
||||
|
||||
public Jedis getConnection() {
|
||||
// In antirez's redis-rb-cluster implementation,
|
||||
// getRandomConnection always return valid connection (able to ping-pong)
|
||||
// getRandomConnection always return valid connection (able to
|
||||
// ping-pong)
|
||||
// or exception if all connections are invalid
|
||||
|
||||
List<JedisPool> pools = getShuffledNodesPool();
|
||||
@@ -52,7 +54,8 @@ public class JedisSlotBasedConnectionHandler extends
|
||||
public Jedis getConnectionFromSlot(int slot) {
|
||||
JedisPool connectionPool = cache.getSlotPool(slot);
|
||||
if (connectionPool != null) {
|
||||
// It can't guaranteed to get valid connection because of node assignment
|
||||
// It can't guaranteed to get valid connection because of node
|
||||
// assignment
|
||||
return connectionPool.getResource();
|
||||
} else {
|
||||
return getConnection();
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
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;
|
||||
|
||||
@@ -147,7 +147,8 @@ abstract class PipelineBase extends Queable implements BinaryRedisPipeline,
|
||||
return bitpos(key, value, new BitPosParams());
|
||||
}
|
||||
|
||||
public Response<Long> bitpos(final String key, final boolean value, final BitPosParams params) {
|
||||
public Response<Long> bitpos(final String key, final boolean value,
|
||||
final BitPosParams params) {
|
||||
getClient(key).bitpos(key, value, params);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
@@ -156,7 +157,8 @@ abstract class PipelineBase extends Queable implements BinaryRedisPipeline,
|
||||
return bitpos(key, value, new BitPosParams());
|
||||
}
|
||||
|
||||
public Response<Long> bitpos(final byte[] key, final boolean value, final BitPosParams params) {
|
||||
public Response<Long> bitpos(final byte[] key, final boolean value,
|
||||
final BitPosParams params) {
|
||||
getClient(key).bitpos(key, value, params);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
@@ -177,7 +179,8 @@ abstract class PipelineBase extends Queable implements BinaryRedisPipeline,
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
|
||||
public Response<byte[]> getrange(byte[] key, long startOffset, long endOffset) {
|
||||
public Response<byte[]> getrange(byte[] key, long startOffset,
|
||||
long endOffset) {
|
||||
getClient(key).getrange(key, startOffset, endOffset);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY);
|
||||
}
|
||||
@@ -1027,77 +1030,89 @@ abstract class PipelineBase extends Queable implements BinaryRedisPipeline,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Long> zlexcount(final byte[] key, final byte[] min, final byte[] max) {
|
||||
public Response<Long> zlexcount(final byte[] key, final byte[] min,
|
||||
final byte[] max) {
|
||||
getClient(key).zlexcount(key, min, max);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Long> zlexcount(final String key, final String min, final String max) {
|
||||
public Response<Long> zlexcount(final String key, final String min,
|
||||
final String max) {
|
||||
getClient(key).zlexcount(key, min, max);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Set<byte[]>> zrangeByLex(final byte[] key, final byte[] min, final byte[] max) {
|
||||
public Response<Set<byte[]>> zrangeByLex(final byte[] key,
|
||||
final byte[] min, final byte[] max) {
|
||||
getClient(key).zrangeByLex(key, min, max);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Set<String>> zrangeByLex(final String key, final String min, final String max) {
|
||||
public Response<Set<String>> zrangeByLex(final String key,
|
||||
final String min, final String max) {
|
||||
getClient(key).zrangeByLex(key, min, max);
|
||||
return getResponse(BuilderFactory.STRING_ZSET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Set<byte[]>> zrangeByLex(final byte[] key, final byte[] min,
|
||||
final byte[] max, final int offset, final int count) {
|
||||
public Response<Set<byte[]>> zrangeByLex(final byte[] key,
|
||||
final byte[] min, final byte[] max, final int offset,
|
||||
final int count) {
|
||||
getClient(key).zrangeByLex(key, min, max, offset, count);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Set<String>> zrangeByLex(final String key, final String min,
|
||||
final String max, final int offset, final int count) {
|
||||
public Response<Set<String>> zrangeByLex(final String key,
|
||||
final String min, final String max, final int offset,
|
||||
final int count) {
|
||||
getClient(key).zrangeByLex(key, min, max, offset, count);
|
||||
return getResponse(BuilderFactory.STRING_ZSET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Set<byte[]>> zrevrangeByLex(final byte[] key, final byte[] max, final byte[] min) {
|
||||
public Response<Set<byte[]>> zrevrangeByLex(final byte[] key,
|
||||
final byte[] max, final byte[] min) {
|
||||
getClient(key).zrevrangeByLex(key, max, min);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Set<String>> zrevrangeByLex(final String key, final String max, final String min) {
|
||||
public Response<Set<String>> zrevrangeByLex(final String key,
|
||||
final String max, final String min) {
|
||||
getClient(key).zrevrangeByLex(key, max, min);
|
||||
return getResponse(BuilderFactory.STRING_ZSET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Set<byte[]>> zrevrangeByLex(final byte[] key, final byte[] max,
|
||||
final byte[] min, final int offset, final int count) {
|
||||
public Response<Set<byte[]>> zrevrangeByLex(final byte[] key,
|
||||
final byte[] max, final byte[] min, final int offset,
|
||||
final int count) {
|
||||
getClient(key).zrevrangeByLex(key, max, min, offset, count);
|
||||
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Set<String>> zrevrangeByLex(final String key, final String max,
|
||||
final String min, final int offset, final int count) {
|
||||
public Response<Set<String>> zrevrangeByLex(final String key,
|
||||
final String max, final String min, final int offset,
|
||||
final int count) {
|
||||
getClient(key).zrevrangeByLex(key, max, min, offset, count);
|
||||
return getResponse(BuilderFactory.STRING_ZSET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Long> zremrangeByLex(final byte[] key, final byte[] min, final byte[] max) {
|
||||
public Response<Long> zremrangeByLex(final byte[] key, final byte[] min,
|
||||
final byte[] max) {
|
||||
getClient(key).zremrangeByLex(key, min, max);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Long> zremrangeByLex(final String key, final String min, final String max) {
|
||||
public Response<Long> zremrangeByLex(final String key, final String min,
|
||||
final String max) {
|
||||
getClient(key).zremrangeByLex(key, min, max);
|
||||
return getResponse(BuilderFactory.LONG);
|
||||
}
|
||||
|
||||
@@ -185,19 +185,23 @@ public interface RedisPipeline {
|
||||
|
||||
Response<Double> zscore(String key, String member);
|
||||
|
||||
Response<Long> zlexcount(final String key, final String min, final String max);
|
||||
Response<Long> zlexcount(final String key, final String min,
|
||||
final String max);
|
||||
|
||||
Response<Set<String>> zrangeByLex(final String key, final String min, final String max);
|
||||
Response<Set<String>> zrangeByLex(final String key, final String min,
|
||||
final String max);
|
||||
|
||||
Response<Set<String>> zrangeByLex(final String key, final String min, final String max,
|
||||
final int offset, final int count);
|
||||
Response<Set<String>> zrangeByLex(final String key, final String min,
|
||||
final String max, final int offset, final int count);
|
||||
|
||||
Response<Set<String>> zrevrangeByLex(final String key, final String max, final String min);
|
||||
Response<Set<String>> zrevrangeByLex(final String key, final String max,
|
||||
final String min);
|
||||
|
||||
Response<Set<String>> zrevrangeByLex(final String key, final String max, final String min,
|
||||
final int offset, final int count);
|
||||
Response<Set<String>> zrevrangeByLex(final String key, final String max,
|
||||
final String min, final int offset, final int count);
|
||||
|
||||
Response<Long> zremrangeByLex(final String key, final String start, final String end);
|
||||
Response<Long> zremrangeByLex(final String key, final String start,
|
||||
final String end);
|
||||
|
||||
Response<Long> bitcount(String key);
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@ import redis.clients.util.SafeEncoder;
|
||||
public class ScanParams {
|
||||
private List<byte[]> params = new ArrayList<byte[]>();
|
||||
public final static String SCAN_POINTER_START = String.valueOf(0);
|
||||
public final static byte[] SCAN_POINTER_START_BINARY = SafeEncoder.encode(SCAN_POINTER_START);
|
||||
public final static byte[] SCAN_POINTER_START_BINARY = SafeEncoder
|
||||
.encode(SCAN_POINTER_START);
|
||||
|
||||
public ScanParams match(final byte[] pattern) {
|
||||
params.add(MATCH.raw);
|
||||
|
||||
@@ -14,9 +14,11 @@ public interface SentinelCommands {
|
||||
|
||||
public String sentinelFailover(String masterName);
|
||||
|
||||
public String sentinelMonitor(String masterName, String ip, int port, int quorum);
|
||||
public String sentinelMonitor(String masterName, String ip, int port,
|
||||
int quorum);
|
||||
|
||||
public String sentinelRemove(String masterName);
|
||||
|
||||
public String sentinelSet(String masterName, Map<String, String> parameterMap);
|
||||
public String sentinelSet(String masterName,
|
||||
Map<String, String> parameterMap);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
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;
|
||||
import redis.clients.util.Pool;
|
||||
|
||||
public class ShardedJedis extends BinaryShardedJedis implements JedisCommands,
|
||||
@@ -126,18 +124,22 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands,
|
||||
Jedis j = getShard(arg);
|
||||
return j.blpop(arg);
|
||||
}
|
||||
|
||||
public List<String> blpop(int timeout, String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.blpop(timeout, key);
|
||||
}
|
||||
|
||||
public List<String> brpop(String arg) {
|
||||
Jedis j = getShard(arg);
|
||||
return j.brpop(arg);
|
||||
}
|
||||
|
||||
public List<String> brpop(int timeout, String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.brpop(timeout, key);
|
||||
}
|
||||
|
||||
public Long decrBy(String key, long integer) {
|
||||
Jedis j = getShard(key);
|
||||
return j.decrBy(key, integer);
|
||||
@@ -550,13 +552,14 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> zrangeByLex(final String key, final String min, final String max) {
|
||||
public Set<String> zrangeByLex(final String key, final String min,
|
||||
final String max) {
|
||||
return getShard(key).zrangeByLex(key, min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> zrangeByLex(final String key, final String min, final String max,
|
||||
final int offset, final int count) {
|
||||
public Set<String> zrangeByLex(final String key, final String min,
|
||||
final String max, final int offset, final int count) {
|
||||
return getShard(key).zrangeByLex(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
@@ -572,7 +575,8 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long zremrangeByLex(final String key, final String min, final String max) {
|
||||
public Long zremrangeByLex(final String key, final String min,
|
||||
final String max) {
|
||||
return getShard(key).zremrangeByLex(key, min, max);
|
||||
}
|
||||
|
||||
@@ -592,7 +596,8 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands,
|
||||
return j.bitcount(key, start, end);
|
||||
}
|
||||
|
||||
public ScanResult<Entry<String, String>> hscan(String key, final String cursor) {
|
||||
public ScanResult<Entry<String, String>> hscan(String key,
|
||||
final String cursor) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hscan(key, cursor);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package redis.clients.util;
|
||||
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
|
||||
public class ClusterNodeInformation {
|
||||
private HostAndPort node;
|
||||
private List<Integer> availableSlots;
|
||||
|
||||
@@ -1,32 +1,46 @@
|
||||
package redis.clients.util;
|
||||
|
||||
/**
|
||||
* CRC16 Implementation according to CCITT standard
|
||||
* Polynomial : 1021 (x^16 + x^12 + x^5 + 1)
|
||||
* CRC16 Implementation according to CCITT standard Polynomial : 1021 (x^16 +
|
||||
* x^12 + x^5 + 1)
|
||||
*
|
||||
* @see http://redis.io/topics/cluster-spec
|
||||
* Appendix A. CRC16 reference implementation in ANSI C
|
||||
* @see http://redis.io/topics/cluster-spec Appendix A. CRC16 reference
|
||||
* implementation in ANSI C
|
||||
*/
|
||||
public class JedisClusterCRC16 {
|
||||
private static final int LOOKUP_TABLE[] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129,
|
||||
0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
|
||||
0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7,
|
||||
0x44A4, 0x5485, 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, 0x3653, 0x2672, 0x1611, 0x0630,
|
||||
0x76D7, 0x66F6, 0x5695, 0x46B4, 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, 0x48C4, 0x58E5,
|
||||
0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
|
||||
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58,
|
||||
0xBB3B, 0xAB1A, 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD,
|
||||
0xAD2A, 0xBD0B, 0x8D68, 0x9D49, 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, 0xFF9F, 0xEFBE,
|
||||
0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
|
||||
0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C,
|
||||
0xE37F, 0xF35E, 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, 0xB5EA, 0xA5CB, 0x95A8, 0x8589,
|
||||
0xF56E, 0xE54F, 0xD52C, 0xC50D, 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 0xA7DB, 0xB7FA,
|
||||
0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
|
||||
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1,
|
||||
0x3882, 0x28A3, 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, 0x4A75, 0x5A54, 0x6A37, 0x7A16,
|
||||
0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, 0x7C26, 0x6C07,
|
||||
0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
|
||||
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0, };
|
||||
private static final int LOOKUP_TABLE[] = { 0x0000, 0x1021, 0x2042, 0x3063,
|
||||
0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B,
|
||||
0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, 0x1231, 0x0210, 0x3273, 0x2252,
|
||||
0x52B5, 0x4294, 0x72F7, 0x62D6, 0x9339, 0x8318, 0xB37B, 0xA35A,
|
||||
0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, 0x2462, 0x3443, 0x0420, 0x1401,
|
||||
0x64E6, 0x74C7, 0x44A4, 0x5485, 0xA56A, 0xB54B, 0x8528, 0x9509,
|
||||
0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, 0x3653, 0x2672, 0x1611, 0x0630,
|
||||
0x76D7, 0x66F6, 0x5695, 0x46B4, 0xB75B, 0xA77A, 0x9719, 0x8738,
|
||||
0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, 0x48C4, 0x58E5, 0x6886, 0x78A7,
|
||||
0x0840, 0x1861, 0x2802, 0x3823, 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF,
|
||||
0x8948, 0x9969, 0xA90A, 0xB92B, 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96,
|
||||
0x1A71, 0x0A50, 0x3A33, 0x2A12, 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E,
|
||||
0x9B79, 0x8B58, 0xBB3B, 0xAB1A, 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5,
|
||||
0x2C22, 0x3C03, 0x0C60, 0x1C41, 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD,
|
||||
0xAD2A, 0xBD0B, 0x8D68, 0x9D49, 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4,
|
||||
0x3E13, 0x2E32, 0x1E51, 0x0E70, 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC,
|
||||
0xBF1B, 0xAF3A, 0x9F59, 0x8F78, 0x9188, 0x81A9, 0xB1CA, 0xA1EB,
|
||||
0xD10C, 0xC12D, 0xF14E, 0xE16F, 0x1080, 0x00A1, 0x30C2, 0x20E3,
|
||||
0x5004, 0x4025, 0x7046, 0x6067, 0x83B9, 0x9398, 0xA3FB, 0xB3DA,
|
||||
0xC33D, 0xD31C, 0xE37F, 0xF35E, 0x02B1, 0x1290, 0x22F3, 0x32D2,
|
||||
0x4235, 0x5214, 0x6277, 0x7256, 0xB5EA, 0xA5CB, 0x95A8, 0x8589,
|
||||
0xF56E, 0xE54F, 0xD52C, 0xC50D, 0x34E2, 0x24C3, 0x14A0, 0x0481,
|
||||
0x7466, 0x6447, 0x5424, 0x4405, 0xA7DB, 0xB7FA, 0x8799, 0x97B8,
|
||||
0xE75F, 0xF77E, 0xC71D, 0xD73C, 0x26D3, 0x36F2, 0x0691, 0x16B0,
|
||||
0x6657, 0x7676, 0x4615, 0x5634, 0xD94C, 0xC96D, 0xF90E, 0xE92F,
|
||||
0x99C8, 0x89E9, 0xB98A, 0xA9AB, 0x5844, 0x4865, 0x7806, 0x6827,
|
||||
0x18C0, 0x08E1, 0x3882, 0x28A3, 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E,
|
||||
0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, 0x4A75, 0x5A54, 0x6A37, 0x7A16,
|
||||
0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D,
|
||||
0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, 0x7C26, 0x6C07, 0x5C64, 0x4C45,
|
||||
0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C,
|
||||
0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, 0x6E17, 0x7E36, 0x4E55, 0x5E74,
|
||||
0x2E93, 0x3EB2, 0x0ED1, 0x1EF0, };
|
||||
|
||||
public static int getSlot(String key) {
|
||||
int s = key.indexOf("{");
|
||||
@@ -42,8 +56,8 @@ public class JedisClusterCRC16 {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a CRC16 checksum from the bytes.
|
||||
* implementation is from mp911de/lettuce, modified with some more optimizations
|
||||
* Create a CRC16 checksum from the bytes. implementation is from
|
||||
* mp911de/lettuce, modified with some more optimizations
|
||||
*
|
||||
* @param bytes
|
||||
* @return CRC16 as integer value
|
||||
|
||||
@@ -12,18 +12,29 @@ public class HostAndPortUtil {
|
||||
private static List<HostAndPort> clusterHostAndPortList = new ArrayList<HostAndPort>();
|
||||
|
||||
static {
|
||||
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT + 1));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT + 2));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT + 3));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT + 4));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT + 5));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT + 6));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_PORT));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_PORT + 1));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_PORT + 2));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_PORT + 3));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_PORT + 4));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_PORT + 5));
|
||||
redisHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_PORT + 6));
|
||||
|
||||
sentinelHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT));
|
||||
sentinelHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT + 1));
|
||||
sentinelHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT + 2));
|
||||
sentinelHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT + 3));
|
||||
sentinelHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_SENTINEL_PORT));
|
||||
sentinelHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_SENTINEL_PORT + 1));
|
||||
sentinelHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_SENTINEL_PORT + 2));
|
||||
sentinelHostAndPortList.add(new HostAndPort("localhost",
|
||||
Protocol.DEFAULT_SENTINEL_PORT + 3));
|
||||
|
||||
clusterHostAndPortList.add(new HostAndPort("localhost", 7379));
|
||||
clusterHostAndPortList.add(new HostAndPort("localhost", 7380));
|
||||
|
||||
@@ -3,6 +3,7 @@ package redis.clients.jedis.tests;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
import redis.clients.util.ClusterNodeInformation;
|
||||
import redis.clients.util.ClusterNodeInformationParser;
|
||||
|
||||
@@ -5,14 +5,13 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.junit.After;
|
||||
@@ -157,8 +156,7 @@ public class JedisClusterTest extends Assert {
|
||||
}
|
||||
|
||||
/**
|
||||
* slot->nodes
|
||||
* 15363 node3 e
|
||||
* slot->nodes 15363 node3 e
|
||||
*/
|
||||
@Test
|
||||
public void testMigrate() {
|
||||
@@ -174,14 +172,16 @@ public class JedisClusterTest extends Assert {
|
||||
node2.set("e", "e");
|
||||
} catch (JedisMovedDataException jme) {
|
||||
assertEquals(15363, jme.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()), jme.getTargetNode());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()),
|
||||
jme.getTargetNode());
|
||||
}
|
||||
|
||||
try {
|
||||
node3.set("e", "e");
|
||||
} catch (JedisAskDataException jae) {
|
||||
assertEquals(15363, jae.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo2.getPort()), jae.getTargetNode());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo2.getPort()),
|
||||
jae.getTargetNode());
|
||||
}
|
||||
|
||||
jc.set("e", "e");
|
||||
@@ -190,13 +190,15 @@ public class JedisClusterTest extends Assert {
|
||||
node2.get("e");
|
||||
} catch (JedisMovedDataException jme) {
|
||||
assertEquals(15363, jme.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()), jme.getTargetNode());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()),
|
||||
jme.getTargetNode());
|
||||
}
|
||||
try {
|
||||
node3.get("e");
|
||||
} catch (JedisAskDataException jae) {
|
||||
assertEquals(15363, jae.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo2.getPort()), jae.getTargetNode());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo2.getPort()),
|
||||
jae.getTargetNode());
|
||||
}
|
||||
|
||||
assertEquals("e", jc.get("e"));
|
||||
@@ -208,8 +210,6 @@ public class JedisClusterTest extends Assert {
|
||||
|
||||
// assertEquals("e", node3.get("e"));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -229,14 +229,16 @@ public class JedisClusterTest extends Assert {
|
||||
node4.set("e", "e");
|
||||
} catch (JedisMovedDataException jme) {
|
||||
assertEquals(15363, jme.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()), jme.getTargetNode());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()),
|
||||
jme.getTargetNode());
|
||||
}
|
||||
|
||||
try {
|
||||
node3.set("e", "e");
|
||||
} catch (JedisAskDataException jae) {
|
||||
assertEquals(15363, jae.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo4.getPort()), jae.getTargetNode());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo4.getPort()),
|
||||
jae.getTargetNode());
|
||||
}
|
||||
|
||||
jc.set("e", "e");
|
||||
@@ -245,13 +247,15 @@ public class JedisClusterTest extends Assert {
|
||||
node4.get("e");
|
||||
} catch (JedisMovedDataException jme) {
|
||||
assertEquals(15363, jme.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()), jme.getTargetNode());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()),
|
||||
jme.getTargetNode());
|
||||
}
|
||||
try {
|
||||
node3.get("e");
|
||||
} catch (JedisAskDataException jae) {
|
||||
assertEquals(15363, jae.getSlot());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo4.getPort()), jae.getTargetNode());
|
||||
assertEquals(new HostAndPort(localHost, nodeInfo4.getPort()),
|
||||
jae.getTargetNode());
|
||||
}
|
||||
|
||||
assertEquals("e", jc.get("e"));
|
||||
@@ -286,8 +290,10 @@ public class JedisClusterTest extends Assert {
|
||||
jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
|
||||
JedisCluster jc = new JedisCluster(jedisClusterNode);
|
||||
int slot51 = JedisClusterCRC16.getSlot("51");
|
||||
node3.clusterSetSlotImporting(slot51, JedisClusterTestUtil.getNodeId(node2.clusterNodes()));
|
||||
node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
|
||||
node3.clusterSetSlotImporting(slot51,
|
||||
JedisClusterTestUtil.getNodeId(node2.clusterNodes()));
|
||||
node2.clusterSetSlotMigrating(slot51,
|
||||
JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
|
||||
jc.set("51", "foo");
|
||||
assertEquals("foo", jc.get("51"));
|
||||
}
|
||||
@@ -307,16 +313,21 @@ public class JedisClusterTest extends Assert {
|
||||
JedisCluster jc = new JedisCluster(jedisClusterNode);
|
||||
int slot51 = JedisClusterCRC16.getSlot("51");
|
||||
// This will cause an infinite redirection loop
|
||||
node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
|
||||
node2.clusterSetSlotMigrating(slot51,
|
||||
JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
|
||||
jc.set("51", "foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRedisHashtag() {
|
||||
assertEquals(JedisClusterCRC16.getSlot("{bar"), JedisClusterCRC16.getSlot("foo{{bar}}zap"));
|
||||
assertEquals(JedisClusterCRC16.getSlot("{user1000}.following"), JedisClusterCRC16.getSlot("{user1000}.followers"));
|
||||
assertNotEquals(JedisClusterCRC16.getSlot("foo{}{bar}"), JedisClusterCRC16.getSlot("bar"));
|
||||
assertEquals(JedisClusterCRC16.getSlot("foo{bar}{zap}"), JedisClusterCRC16.getSlot("bar"));
|
||||
assertEquals(JedisClusterCRC16.getSlot("{bar"),
|
||||
JedisClusterCRC16.getSlot("foo{{bar}}zap"));
|
||||
assertEquals(JedisClusterCRC16.getSlot("{user1000}.following"),
|
||||
JedisClusterCRC16.getSlot("{user1000}.followers"));
|
||||
assertNotEquals(JedisClusterCRC16.getSlot("foo{}{bar}"),
|
||||
JedisClusterCRC16.getSlot("bar"));
|
||||
assertEquals(JedisClusterCRC16.getSlot("foo{bar}{zap}"),
|
||||
JedisClusterCRC16.getSlot("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -377,14 +388,17 @@ public class JedisClusterTest extends Assert {
|
||||
@Test
|
||||
public void testClusterKeySlot() {
|
||||
// It assumes JedisClusterCRC16 is correctly implemented
|
||||
assertEquals(node1.clusterKeySlot("foo{bar}zap}").intValue(), JedisClusterCRC16.getSlot("foo{bar}zap"));
|
||||
assertEquals(node1.clusterKeySlot("{user1000}.following").intValue(), JedisClusterCRC16.getSlot("{user1000}.following"));
|
||||
assertEquals(node1.clusterKeySlot("foo{bar}zap}").intValue(),
|
||||
JedisClusterCRC16.getSlot("foo{bar}zap"));
|
||||
assertEquals(node1.clusterKeySlot("{user1000}.following").intValue(),
|
||||
JedisClusterCRC16.getSlot("{user1000}.following"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClusterCountKeysInSlot() {
|
||||
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
|
||||
jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort()));
|
||||
jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1
|
||||
.getPort()));
|
||||
JedisCluster jc = new JedisCluster(jedisClusterNode);
|
||||
|
||||
for (int index = 0; index < 5; index++) {
|
||||
@@ -396,21 +410,25 @@ public class JedisClusterTest extends Assert {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStableSlotWhenMigratingNodeOrImportingNodeIsNotSpecified() throws InterruptedException {
|
||||
public void testStableSlotWhenMigratingNodeOrImportingNodeIsNotSpecified()
|
||||
throws InterruptedException {
|
||||
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
|
||||
jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort()));
|
||||
jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1
|
||||
.getPort()));
|
||||
JedisCluster jc = new JedisCluster(jedisClusterNode);
|
||||
|
||||
int slot51 = JedisClusterCRC16.getSlot("51");
|
||||
jc.set("51", "foo");
|
||||
// node2 is responsible of taking care of slot51 (7186)
|
||||
|
||||
node3.clusterSetSlotImporting(slot51, JedisClusterTestUtil.getNodeId(node2.clusterNodes()));
|
||||
node3.clusterSetSlotImporting(slot51,
|
||||
JedisClusterTestUtil.getNodeId(node2.clusterNodes()));
|
||||
assertEquals("foo", jc.get("51"));
|
||||
node3.clusterSetSlotStable(slot51);
|
||||
assertEquals("foo", jc.get("51"));
|
||||
|
||||
node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
|
||||
node2.clusterSetSlotMigrating(slot51,
|
||||
JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
|
||||
// assertEquals("foo", jc.get("51")); // it leads Max Redirections
|
||||
node2.clusterSetSlotStable(slot51);
|
||||
assertEquals("foo", jc.get("51"));
|
||||
@@ -430,7 +448,8 @@ public class JedisClusterTest extends Assert {
|
||||
@Test
|
||||
public void testCloseable() {
|
||||
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
|
||||
jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort()));
|
||||
jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1
|
||||
.getPort()));
|
||||
|
||||
JedisCluster jc = null;
|
||||
try {
|
||||
@@ -442,7 +461,8 @@ public class JedisClusterTest extends Assert {
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<JedisPool> poolIterator = jc.getClusterNodes().values().iterator();
|
||||
Iterator<JedisPool> poolIterator = jc.getClusterNodes().values()
|
||||
.iterator();
|
||||
while (poolIterator.hasNext()) {
|
||||
JedisPool pool = poolIterator.next();
|
||||
try {
|
||||
@@ -455,19 +475,22 @@ public class JedisClusterTest extends Assert {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJedisClusterRunsWithMultithreaded() throws InterruptedException, ExecutionException {
|
||||
public void testJedisClusterRunsWithMultithreaded()
|
||||
throws InterruptedException, ExecutionException {
|
||||
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
|
||||
jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
|
||||
final JedisCluster jc = new JedisCluster(jedisClusterNode);
|
||||
jc.set("foo", "bar");
|
||||
|
||||
ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 100, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
|
||||
ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 100, 0,
|
||||
TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
|
||||
List<Future<String>> futures = new ArrayList<Future<String>>();
|
||||
for (int i = 0; i < 50; i++) {
|
||||
executor.submit(new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
// FIXME : invalidate slot cache from JedisCluster to test random connection also does work
|
||||
// FIXME : invalidate slot cache from JedisCluster to test
|
||||
// random connection also does work
|
||||
return jc.get("foo");
|
||||
}
|
||||
});
|
||||
@@ -482,7 +505,8 @@ public class JedisClusterTest extends Assert {
|
||||
}
|
||||
|
||||
private static String getNodeServingSlotRange(String infoOutput) {
|
||||
// f4f3dc4befda352a4e0beccf29f5e8828438705d 127.0.0.1:7380 master - 0 1394372400827 0 connected 5461-10922
|
||||
// f4f3dc4befda352a4e0beccf29f5e8828438705d 127.0.0.1:7380 master - 0
|
||||
// 1394372400827 0 connected 5461-10922
|
||||
for (String infoLine : infoOutput.split("\n")) {
|
||||
if (infoLine.contains("myself")) {
|
||||
try {
|
||||
|
||||
@@ -2,7 +2,6 @@ package redis.clients.jedis.tests;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.junit.Before;
|
||||
@@ -49,7 +48,8 @@ public class JedisSentinelPoolTest extends JedisTestBase {
|
||||
wrongSentinels.add(new HostAndPort("localhost", 65432).toString());
|
||||
wrongSentinels.add(new HostAndPort("localhost", 65431).toString());
|
||||
|
||||
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, wrongSentinels);
|
||||
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME,
|
||||
wrongSentinels);
|
||||
pool.destroy();
|
||||
}
|
||||
|
||||
@@ -65,8 +65,8 @@ public class JedisSentinelPoolTest extends JedisTestBase {
|
||||
public void checkCloseableConnections() throws Exception {
|
||||
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
|
||||
|
||||
JedisSentinelPool pool = new JedisSentinelPool(
|
||||
MASTER_NAME, sentinels, config, 1000, "foobared", 2);
|
||||
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels,
|
||||
config, 1000, "foobared", 2);
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.set("foo", "bar");
|
||||
@@ -82,7 +82,8 @@ public class JedisSentinelPoolTest extends JedisTestBase {
|
||||
new GenericObjectPoolConfig(), 1000, "foobared", 2);
|
||||
|
||||
forceFailover(pool);
|
||||
// after failover sentinel needs a bit of time to stabilize before a new failover
|
||||
// after failover sentinel needs a bit of time to stabilize before a new
|
||||
// failover
|
||||
Thread.sleep(100);
|
||||
forceFailover(pool);
|
||||
|
||||
@@ -184,7 +185,8 @@ public class JedisSentinelPoolTest extends JedisTestBase {
|
||||
|
||||
Jedis afterFailoverJedis = pool.getResource();
|
||||
assertEquals("PONG", afterFailoverJedis.ping());
|
||||
assertEquals("foobared", afterFailoverJedis.configGet("requirepass").get(1));
|
||||
assertEquals("foobared", afterFailoverJedis.configGet("requirepass")
|
||||
.get(1));
|
||||
assertEquals(2, afterFailoverJedis.getDB().intValue());
|
||||
|
||||
// returning both connections to the pool should not throw
|
||||
@@ -194,8 +196,8 @@ public class JedisSentinelPoolTest extends JedisTestBase {
|
||||
|
||||
private void waitForFailover(JedisSentinelPool pool, HostAndPort oldMaster)
|
||||
throws InterruptedException {
|
||||
HostAndPort newMaster = JedisSentinelTestUtil
|
||||
.waitForNewPromotedMaster(MASTER_NAME, sentinelJedis1, sentinelJedis2);
|
||||
HostAndPort newMaster = JedisSentinelTestUtil.waitForNewPromotedMaster(
|
||||
MASTER_NAME, sentinelJedis1, sentinelJedis2);
|
||||
|
||||
waitForJedisSentinelPoolRecognizeNewMaster(pool, newMaster);
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ public class JedisSentinelTest extends JedisTestBase {
|
||||
|
||||
protected static HostAndPort master = HostAndPortUtil.getRedisServers()
|
||||
.get(0);
|
||||
protected static HostAndPort slave = HostAndPortUtil.getRedisServers()
|
||||
.get(4);
|
||||
protected static HostAndPort slave = HostAndPortUtil.getRedisServers().get(
|
||||
4);
|
||||
protected static HostAndPort sentinel = HostAndPortUtil
|
||||
.getSentinelServers().get(0);
|
||||
|
||||
@@ -91,10 +91,12 @@ public class JedisSentinelTest extends JedisTestBase {
|
||||
try {
|
||||
List<String> masterHostAndPort = j
|
||||
.sentinelGetMasterAddrByName(FAILOVER_MASTER_NAME);
|
||||
HostAndPort currentMaster = new HostAndPort(masterHostAndPort.get(0),
|
||||
HostAndPort currentMaster = new HostAndPort(
|
||||
masterHostAndPort.get(0),
|
||||
Integer.parseInt(masterHostAndPort.get(1)));
|
||||
|
||||
JedisSentinelTestUtil.waitForNewPromotedMaster(FAILOVER_MASTER_NAME, j, j2);
|
||||
JedisSentinelTestUtil.waitForNewPromotedMaster(
|
||||
FAILOVER_MASTER_NAME, j, j2);
|
||||
|
||||
masterHostAndPort = j
|
||||
.sentinelGetMasterAddrByName(FAILOVER_MASTER_NAME);
|
||||
|
||||
@@ -1,13 +1,24 @@
|
||||
package redis.clients.jedis.tests;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import redis.clients.jedis.*;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.*;
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
import redis.clients.jedis.Response;
|
||||
import redis.clients.jedis.Tuple;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
|
||||
public class PipeliningTest extends Assert {
|
||||
private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0);
|
||||
@@ -63,7 +74,8 @@ public class PipeliningTest extends Assert {
|
||||
Response<Set<Tuple>> zrangeWithScores = p.zrangeWithScores("zset", 0,
|
||||
-1);
|
||||
Response<String> getrange = p.getrange("setrange", 1, 3);
|
||||
Response<byte[]> getrangeBytes = p.getrange("setrangebytes".getBytes(), 6, 8);
|
||||
Response<byte[]> getrangeBytes = p.getrange("setrangebytes".getBytes(),
|
||||
6, 8);
|
||||
p.sync();
|
||||
|
||||
assertEquals("foo", string.get());
|
||||
@@ -401,7 +413,6 @@ public class PipeliningTest extends Assert {
|
||||
hashMap1.put(field3, value3);
|
||||
hashMap1.put(field4, value4);
|
||||
|
||||
|
||||
jedis.set(key1, val1);
|
||||
jedis.set(key2, val2);
|
||||
jedis.hmset(key3, hashMap);
|
||||
@@ -426,7 +437,8 @@ public class PipeliningTest extends Assert {
|
||||
|
||||
assertTrue(result.get(1) instanceof JedisDataException);
|
||||
|
||||
Map<String, String> hashMapReceived = (Map<String, String>)result.get(2);
|
||||
Map<String, String> hashMapReceived = (Map<String, String>) result
|
||||
.get(2);
|
||||
Iterator<String> iterator = hashMapReceived.keySet().iterator();
|
||||
String mapKey1 = iterator.next();
|
||||
String mapKey2 = iterator.next();
|
||||
@@ -439,11 +451,10 @@ public class PipeliningTest extends Assert {
|
||||
assertTrue(result.get(3) instanceof JedisDataException);
|
||||
}
|
||||
|
||||
private void verifyHasBothValues(String firstKey, String secondKey, String value1, String value2) {
|
||||
private void verifyHasBothValues(String firstKey, String secondKey,
|
||||
String value1, String value2) {
|
||||
assertFalse(firstKey.equals(secondKey));
|
||||
assertTrue(firstKey.equals(value1)
|
||||
|| firstKey.equals(value2));
|
||||
assertTrue(secondKey.equals(value1)
|
||||
|| secondKey.equals(value2));
|
||||
assertTrue(firstKey.equals(value1) || firstKey.equals(value2));
|
||||
assertTrue(secondKey.equals(value1) || secondKey.equals(value2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,8 +55,8 @@ public class ProtocolTest extends JedisTestBase {
|
||||
|
||||
try {
|
||||
ros.write((byte) '*');
|
||||
} catch (IOException ioe) {}
|
||||
|
||||
} catch (IOException ioe) {
|
||||
}
|
||||
|
||||
ros.write((byte) '*');
|
||||
|
||||
|
||||
@@ -7,10 +7,9 @@ import redis.clients.util.JedisClusterCRC16;
|
||||
public class CRC16Benchmark {
|
||||
private static final int TOTAL_OPERATIONS = 100000000;
|
||||
|
||||
private static String[] TEST_SET = {
|
||||
"", "123456789", "sfger132515", "hae9Napahngaikeethievubaibogiech",
|
||||
"AAAAAAAAAAAAAAAAAAAAAA", "Hello, World!"
|
||||
};
|
||||
private static String[] TEST_SET = { "", "123456789", "sfger132515",
|
||||
"hae9Napahngaikeethievubaibogiech", "AAAAAAAAAAAAAAAAAAAAAA",
|
||||
"Hello, World!" };
|
||||
|
||||
public static void main(String[] args) {
|
||||
long begin = Calendar.getInstance().getTimeInMillis();
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -10,8 +13,6 @@ import redis.clients.jedis.ScanParams;
|
||||
import redis.clients.jedis.ScanResult;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
@@ -552,7 +553,8 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
jedis.set(bfoo2, bbar);
|
||||
jedis.set(bfoo3, bbar);
|
||||
|
||||
ScanResult<byte[]> bResult = jedis.scan(SCAN_POINTER_START_BINARY, params);
|
||||
ScanResult<byte[]> bResult = jedis.scan(SCAN_POINTER_START_BINARY,
|
||||
params);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
@@ -579,7 +581,8 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
jedis.set(bfoo2, bbar);
|
||||
jedis.set(bfoo3, bbar);
|
||||
|
||||
ScanResult<byte[]> bResult = jedis.scan(SCAN_POINTER_START_BINARY, params);
|
||||
ScanResult<byte[]> bResult = jedis.scan(SCAN_POINTER_START_BINARY,
|
||||
params);
|
||||
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ public class BitCommandsTest extends JedisCommandTestBase {
|
||||
jedis.setbit(foo, 39, true);
|
||||
|
||||
/*
|
||||
* byte: 0 1 2 3 4
|
||||
* bit: 00010001 / 00000100 / 00000000 / 00000000 / 00000001
|
||||
* byte: 0 1 2 3 4 bit: 00010001 / 00000100 / 00000000 / 00000000 /
|
||||
* 00000001
|
||||
*/
|
||||
long offset = jedis.bitpos(foo, true);
|
||||
assertEquals(2, offset);
|
||||
@@ -69,8 +69,8 @@ public class BitCommandsTest extends JedisCommandTestBase {
|
||||
jedis.setbit(bfoo, 39, true);
|
||||
|
||||
/*
|
||||
* byte: 0 1 2 3 4
|
||||
* bit: 00010001 / 00000100 / 00000000 / 00000000 / 00000001
|
||||
* byte: 0 1 2 3 4 bit: 00010001 / 00000100 / 00000000 / 00000000 /
|
||||
* 00000001
|
||||
*/
|
||||
long offset = jedis.bitpos(bfoo, true);
|
||||
assertEquals(2, offset);
|
||||
@@ -101,8 +101,7 @@ public class BitCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
|
||||
/*
|
||||
* byte: 0
|
||||
* bit: 11111111
|
||||
* byte: 0 bit: 11111111
|
||||
*/
|
||||
long offset = jedis.bitpos(foo, false);
|
||||
// offset should be last index + 1
|
||||
@@ -119,8 +118,8 @@ public class BitCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
|
||||
/*
|
||||
* byte: 0 1 2 3 4
|
||||
* bit: 11111111 / 11111111 / 11111111 / 11111111 / 11111111
|
||||
* byte: 0 1 2 3 4 bit: 11111111 / 11111111 / 11111111 / 11111111 /
|
||||
* 11111111
|
||||
*/
|
||||
long offset = jedis.bitpos(foo, false, new BitPosParams(2, 3));
|
||||
// offset should be -1
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -9,14 +12,12 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.Pipeline;
|
||||
import redis.clients.jedis.Response;
|
||||
import redis.clients.jedis.ScanParams;
|
||||
import redis.clients.jedis.ScanResult;
|
||||
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
|
||||
@@ -339,7 +340,8 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
jedis.hset("foo", "b", "b");
|
||||
jedis.hset("foo", "a", "a");
|
||||
|
||||
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo", SCAN_POINTER_START);
|
||||
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo",
|
||||
SCAN_POINTER_START);
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
@@ -347,7 +349,8 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
// binary
|
||||
jedis.hset(bfoo, bbar, bcar);
|
||||
|
||||
ScanResult<Map.Entry<byte[], byte[]>> bResult = jedis.hscan(bfoo, SCAN_POINTER_START_BINARY);
|
||||
ScanResult<Map.Entry<byte[], byte[]>> bResult = jedis.hscan(bfoo,
|
||||
SCAN_POINTER_START_BINARY);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
@@ -376,7 +379,8 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
jedis.hset(bfoo, bbar2, bcar);
|
||||
jedis.hset(bfoo, bbar3, bcar);
|
||||
|
||||
ScanResult<Map.Entry<byte[], byte[]>> bResult = jedis.hscan(bfoo, SCAN_POINTER_START_BINARY, params);
|
||||
ScanResult<Map.Entry<byte[], byte[]>> bResult = jedis.hscan(bfoo,
|
||||
SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
@@ -405,7 +409,8 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
jedis.hset(bfoo, bbar2, bcar);
|
||||
jedis.hset(bfoo, bbar3, bcar);
|
||||
|
||||
ScanResult<Map.Entry<byte[], byte[]>> bResult = jedis.hscan(bfoo, SCAN_POINTER_START_BINARY, params);
|
||||
ScanResult<Map.Entry<byte[], byte[]>> bResult = jedis.hscan(bfoo,
|
||||
SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
|
||||
@@ -65,7 +65,6 @@ public class HyperLogLogCommandsTest extends JedisCommandTestBase {
|
||||
status = jedis.pfcount("hll_1", "hll_2", "hll_3");
|
||||
assertEquals(4, status);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -65,10 +65,10 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
}, "foo");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void pubSubChannels() {
|
||||
final List<String> expectedActiveChannels = Arrays.asList("testchan1", "testchan2", "testchan3");
|
||||
final List<String> expectedActiveChannels = Arrays.asList("testchan1",
|
||||
"testchan2", "testchan3");
|
||||
jedis.subscribe(new JedisPubSub() {
|
||||
private int count = 0;
|
||||
|
||||
@@ -82,8 +82,10 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
// All channels are subscribed
|
||||
if (count == 3) {
|
||||
Jedis otherJedis = createJedis();
|
||||
List<String> activeChannels = otherJedis.pubsubChannels("test*");
|
||||
assertTrue(expectedActiveChannels.containsAll(activeChannels));
|
||||
List<String> activeChannels = otherJedis
|
||||
.pubsubChannels("test*");
|
||||
assertTrue(expectedActiveChannels
|
||||
.containsAll(activeChannels));
|
||||
unsubscribe();
|
||||
}
|
||||
}
|
||||
@@ -97,7 +99,8 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPMessage(String pattern, String channel, String message) {
|
||||
public void onPMessage(String pattern, String channel,
|
||||
String message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,6 +113,7 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
public void pubSubNumPat() {
|
||||
jedis.psubscribe(new JedisPubSub() {
|
||||
private int count = 0;
|
||||
|
||||
@Override
|
||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
||||
}
|
||||
@@ -134,7 +138,8 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPMessage(String pattern, String channel, String message) {
|
||||
public void onPMessage(String pattern, String channel,
|
||||
String message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -150,6 +155,7 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
expectedNumSub.put("testchannel1", "1");
|
||||
jedis.subscribe(new JedisPubSub() {
|
||||
private int count = 0;
|
||||
|
||||
@Override
|
||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
||||
}
|
||||
@@ -159,7 +165,8 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
count++;
|
||||
if (count == 2) {
|
||||
Jedis otherJedis = createJedis();
|
||||
Map<String, String> numSub = otherJedis.pubsubNumSub("testchannel1", "testchannel2");
|
||||
Map<String, String> numSub = otherJedis.pubsubNumSub(
|
||||
"testchannel1", "testchannel2");
|
||||
assertEquals(expectedNumSub, numSub);
|
||||
unsubscribe();
|
||||
}
|
||||
@@ -174,7 +181,8 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPMessage(String pattern, String channel, String message) {
|
||||
public void onPMessage(String pattern, String channel,
|
||||
String message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.Test;
|
||||
import redis.clients.jedis.BinaryJedis;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.BinaryJedis;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
public class ScriptingCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
@@ -183,7 +184,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("key1", results.get(0));
|
||||
assertEquals("key2", results.get(1));
|
||||
assertEquals("1", results.get(2));
|
||||
@@ -194,7 +196,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("key1", results.get(0));
|
||||
assertEquals("key2", results.get(1));
|
||||
assertEquals("1", results.get(2));
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -8,8 +11,6 @@ import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.ScanParams;
|
||||
import redis.clients.jedis.ScanResult;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
public class SetCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
@@ -472,7 +473,8 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
||||
// binary
|
||||
jedis.sadd(bfoo, ba, bb);
|
||||
|
||||
ScanResult<byte[]> bResult = jedis.sscan(bfoo, SCAN_POINTER_START_BINARY);
|
||||
ScanResult<byte[]> bResult = jedis.sscan(bfoo,
|
||||
SCAN_POINTER_START_BINARY);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
@@ -484,7 +486,8 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
||||
params.match("a*");
|
||||
|
||||
jedis.sadd("foo", "b", "a", "aa");
|
||||
ScanResult<String> result = jedis.sscan("foo", SCAN_POINTER_START, params);
|
||||
ScanResult<String> result = jedis.sscan("foo", SCAN_POINTER_START,
|
||||
params);
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
@@ -494,7 +497,8 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
||||
params.match(bbarstar);
|
||||
|
||||
jedis.sadd(bfoo, bbar1, bbar2, bbar3);
|
||||
ScanResult<byte[]> bResult = jedis.sscan(bfoo, SCAN_POINTER_START_BINARY, params);
|
||||
ScanResult<byte[]> bResult = jedis.sscan(bfoo,
|
||||
SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
@@ -507,7 +511,8 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
jedis.sadd("foo", "a1", "a2", "a3", "a4", "a5");
|
||||
|
||||
ScanResult<String> result = jedis.sscan("foo", SCAN_POINTER_START, params);
|
||||
ScanResult<String> result = jedis.sscan("foo", SCAN_POINTER_START,
|
||||
params);
|
||||
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
@@ -516,7 +521,8 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
||||
params.count(2);
|
||||
|
||||
jedis.sadd(bfoo, bbar1, bbar2, bbar3);
|
||||
ScanResult<byte[]> bResult = jedis.sscan(bfoo, SCAN_POINTER_START_BINARY, params);
|
||||
ScanResult<byte[]> bResult = jedis.sscan(bfoo,
|
||||
SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -10,8 +13,6 @@ import redis.clients.jedis.ScanResult;
|
||||
import redis.clients.jedis.Tuple;
|
||||
import redis.clients.jedis.ZParams;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
@@ -128,14 +129,16 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
Set<byte[]> bExpected = new LinkedHashSet<byte[]>();
|
||||
bExpected.add(bb);
|
||||
|
||||
assertEquals(bExpected, jedis.zrangeByLex(bfoo, bInclusiveB, bExclusiveC));
|
||||
assertEquals(bExpected,
|
||||
jedis.zrangeByLex(bfoo, bInclusiveB, bExclusiveC));
|
||||
|
||||
bExpected.clear();
|
||||
bExpected.add(ba);
|
||||
bExpected.add(bb);
|
||||
|
||||
// with LIMIT
|
||||
assertEquals(bExpected, jedis.zrangeByLex(bfoo, bLexMinusInf, bLexPlusInf, 0, 2));
|
||||
assertEquals(bExpected,
|
||||
jedis.zrangeByLex(bfoo, bLexMinusInf, bLexPlusInf, 0, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -170,14 +173,16 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
Set<byte[]> bExpected = new LinkedHashSet<byte[]>();
|
||||
bExpected.add(bb);
|
||||
|
||||
assertEquals(bExpected, jedis.zrevrangeByLex(bfoo, bExclusiveC, bInclusiveB));
|
||||
assertEquals(bExpected,
|
||||
jedis.zrevrangeByLex(bfoo, bExclusiveC, bInclusiveB));
|
||||
|
||||
bExpected.clear();
|
||||
bExpected.add(bb);
|
||||
bExpected.add(ba);
|
||||
|
||||
// with LIMIT
|
||||
assertEquals(bExpected, jedis.zrevrangeByLex(bfoo, bLexPlusInf, bLexMinusInf, 0, 2));
|
||||
assertEquals(bExpected,
|
||||
jedis.zrevrangeByLex(bfoo, bLexPlusInf, bLexMinusInf, 0, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -894,7 +899,8 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
bexpected.add(ba);
|
||||
bexpected.add(bc);
|
||||
|
||||
assertEquals(bexpected, jedis.zrangeByLex(bfoo, bLexMinusInf, bLexPlusInf));
|
||||
assertEquals(bexpected,
|
||||
jedis.zrangeByLex(bfoo, bLexMinusInf, bLexPlusInf));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1067,7 +1073,8 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
jedis.zadd(bfoo, 1, ba);
|
||||
jedis.zadd(bfoo, 1, bb);
|
||||
|
||||
ScanResult<Tuple> bResult = jedis.zscan(bfoo, SCAN_POINTER_START_BINARY);
|
||||
ScanResult<Tuple> bResult = jedis
|
||||
.zscan(bfoo, SCAN_POINTER_START_BINARY);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
@@ -1081,7 +1088,8 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
jedis.zadd("foo", 2, "b");
|
||||
jedis.zadd("foo", 1, "a");
|
||||
jedis.zadd("foo", 11, "aa");
|
||||
ScanResult<Tuple> result = jedis.zscan("foo", SCAN_POINTER_START, params);
|
||||
ScanResult<Tuple> result = jedis.zscan("foo", SCAN_POINTER_START,
|
||||
params);
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
@@ -1093,7 +1101,8 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
jedis.zadd(bfoo, 2, bbar1);
|
||||
jedis.zadd(bfoo, 1, bbar2);
|
||||
jedis.zadd(bfoo, 11, bbar3);
|
||||
ScanResult<Tuple> bResult = jedis.zscan(bfoo, SCAN_POINTER_START_BINARY, params);
|
||||
ScanResult<Tuple> bResult = jedis.zscan(bfoo,
|
||||
SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
@@ -1111,7 +1120,8 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
jedis.zadd("foo", 4, "a4");
|
||||
jedis.zadd("foo", 5, "a5");
|
||||
|
||||
ScanResult<Tuple> result = jedis.zscan("foo", SCAN_POINTER_START, params);
|
||||
ScanResult<Tuple> result = jedis.zscan("foo", SCAN_POINTER_START,
|
||||
params);
|
||||
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
@@ -1123,7 +1133,8 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
jedis.zadd(bfoo, 1, bbar2);
|
||||
jedis.zadd(bfoo, 11, bbar3);
|
||||
|
||||
ScanResult<Tuple> bResult = jedis.zscan(bfoo, SCAN_POINTER_START_BINARY, params);
|
||||
ScanResult<Tuple> bResult = jedis.zscan(bfoo,
|
||||
SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
|
||||
@@ -19,10 +19,13 @@ public class JedisClusterCRC16Test {
|
||||
|
||||
for (Entry<String, Integer> entry : solutions.entrySet()) {
|
||||
// string version
|
||||
assertEquals(entry.getValue().intValue(), JedisClusterCRC16.getCRC16(entry.getKey()));
|
||||
assertEquals(entry.getValue().intValue(),
|
||||
JedisClusterCRC16.getCRC16(entry.getKey()));
|
||||
|
||||
// byte array version
|
||||
assertEquals(entry.getValue().intValue(), JedisClusterCRC16.getCRC16(SafeEncoder.encode(entry.getKey())));
|
||||
assertEquals(entry.getValue().intValue(),
|
||||
JedisClusterCRC16.getCRC16(SafeEncoder.encode(entry
|
||||
.getKey())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@ import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
|
||||
public class JedisClusterTestUtil {
|
||||
public static void waitForClusterReady(Jedis...nodes) throws InterruptedException {
|
||||
public static void waitForClusterReady(Jedis... nodes)
|
||||
throws InterruptedException {
|
||||
boolean clusterOk = false;
|
||||
while (!clusterOk) {
|
||||
boolean isOk = true;
|
||||
@@ -43,15 +44,18 @@ public class JedisClusterTestUtil {
|
||||
return "";
|
||||
}
|
||||
|
||||
public static void assertNodeIsKnown(Jedis node, String targetNodeId, int timeoutMs) {
|
||||
public static void assertNodeIsKnown(Jedis node, String targetNodeId,
|
||||
int timeoutMs) {
|
||||
assertNodeRecognizedStatus(node, targetNodeId, true, timeoutMs);
|
||||
}
|
||||
|
||||
public static void assertNodeIsUnknown(Jedis node, String targetNodeId, int timeoutMs) {
|
||||
public static void assertNodeIsUnknown(Jedis node, String targetNodeId,
|
||||
int timeoutMs) {
|
||||
assertNodeRecognizedStatus(node, targetNodeId, false, timeoutMs);
|
||||
}
|
||||
|
||||
private static void assertNodeRecognizedStatus(Jedis node, String targetNodeId, boolean shouldRecognized, int timeoutMs) {
|
||||
private static void assertNodeRecognizedStatus(Jedis node,
|
||||
String targetNodeId, boolean shouldRecognized, int timeoutMs) {
|
||||
int sleepInterval = 100;
|
||||
for (int sleepTime = 0; sleepTime <= timeoutMs; sleepTime += sleepInterval) {
|
||||
boolean known = isKnownNode(node, targetNodeId);
|
||||
@@ -77,5 +81,4 @@ public class JedisClusterTestUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPubSub;
|
||||
import redis.clients.jedis.tests.utils.FailoverAbortedException;
|
||||
|
||||
public class JedisSentinelTestUtil {
|
||||
public static HostAndPort waitForNewPromotedMaster(final String masterName,
|
||||
@@ -29,8 +28,9 @@ public class JedisSentinelTestUtil {
|
||||
punsubscribe();
|
||||
} else if (channel.startsWith("-failover-abort")) {
|
||||
punsubscribe();
|
||||
throw new FailoverAbortedException("Unfortunately sentinel cannot failover... reason(channel) : " +
|
||||
channel + " / message : " + message);
|
||||
throw new FailoverAbortedException(
|
||||
"Unfortunately sentinel cannot failover... reason(channel) : "
|
||||
+ channel + " / message : " + message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user