diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index 7bd864d..3b28fad 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -24,12 +24,12 @@ import redis.clients.util.SafeEncoder; public class BinaryClient extends Connection { public enum LIST_POSITION { - BEFORE, AFTER; - public final byte[] raw; + BEFORE, AFTER; + public final byte[] raw; - private LIST_POSITION() { - raw = SafeEncoder.encode(name()); - } + private LIST_POSITION() { + raw = SafeEncoder.encode(name()); + } } private boolean isInMulti; @@ -41,1220 +41,1220 @@ public class BinaryClient extends Connection { private boolean isInWatch; public boolean isInMulti() { - return isInMulti; + return isInMulti; } public boolean isInWatch() { - return isInWatch; + return isInWatch; } public BinaryClient() { - super(); + super(); } public BinaryClient(final String host) { - super(host); + super(host); } public BinaryClient(final String host, final int port) { - super(host, port); + super(host, port); } private byte[][] joinParameters(byte[] first, byte[][] rest) { - byte[][] result = new byte[rest.length + 1][]; - result[0] = first; - for (int i = 0; i < rest.length; i++) { - result[i + 1] = rest[i]; - } - return result; + byte[][] result = new byte[rest.length + 1][]; + result[0] = first; + for (int i = 0; i < rest.length; i++) { + result[i + 1] = rest[i]; + } + return result; } public void setPassword(final String password) { - this.password = password; + this.password = password; } @Override public void connect() { - if (!isConnected()) { - super.connect(); - if (password != null) { - auth(password); - getStatusCodeReply(); - } - if (db > 0) { - select(Long.valueOf(db).intValue()); - getStatusCodeReply(); - } - } + if (!isConnected()) { + super.connect(); + if (password != null) { + auth(password); + getStatusCodeReply(); + } + if (db > 0) { + select(Long.valueOf(db).intValue()); + getStatusCodeReply(); + } + } } public void ping() { - sendCommand(Command.PING); + sendCommand(Command.PING); } public void set(final byte[] key, final byte[] value) { - sendCommand(Command.SET, key, value); + sendCommand(Command.SET, key, value); } public void set(final byte[] key, final byte[] value, final byte[] nxxx, - final byte[] expx, final long time) { - sendCommand(Command.SET, key, value, nxxx, expx, toByteArray(time)); + final byte[] expx, final long time) { + sendCommand(Command.SET, key, value, nxxx, expx, toByteArray(time)); } public void get(final byte[] key) { - sendCommand(Command.GET, key); + sendCommand(Command.GET, key); } public void quit() { - db = 0; - sendCommand(QUIT); + db = 0; + sendCommand(QUIT); } public void exists(final byte[] key) { - sendCommand(EXISTS, key); + sendCommand(EXISTS, key); } public void del(final byte[]... keys) { - sendCommand(DEL, keys); + sendCommand(DEL, keys); } public void type(final byte[] key) { - sendCommand(TYPE, key); + sendCommand(TYPE, key); } public void flushDB() { - sendCommand(FLUSHDB); + sendCommand(FLUSHDB); } public void keys(final byte[] pattern) { - sendCommand(KEYS, pattern); + sendCommand(KEYS, pattern); } public void randomKey() { - sendCommand(RANDOMKEY); + sendCommand(RANDOMKEY); } public void rename(final byte[] oldkey, final byte[] newkey) { - sendCommand(RENAME, oldkey, newkey); + sendCommand(RENAME, oldkey, newkey); } public void renamenx(final byte[] oldkey, final byte[] newkey) { - sendCommand(RENAMENX, oldkey, newkey); + sendCommand(RENAMENX, oldkey, newkey); } public void dbSize() { - sendCommand(DBSIZE); + sendCommand(DBSIZE); } public void expire(final byte[] key, final int seconds) { - sendCommand(EXPIRE, key, toByteArray(seconds)); + sendCommand(EXPIRE, key, toByteArray(seconds)); } public void expireAt(final byte[] key, final long unixTime) { - sendCommand(EXPIREAT, key, toByteArray(unixTime)); + sendCommand(EXPIREAT, key, toByteArray(unixTime)); } public void ttl(final byte[] key) { - sendCommand(TTL, key); + sendCommand(TTL, key); } public void select(final int index) { - db = index; - sendCommand(SELECT, toByteArray(index)); + db = index; + sendCommand(SELECT, toByteArray(index)); } public void move(final byte[] key, final int dbIndex) { - sendCommand(MOVE, key, toByteArray(dbIndex)); + sendCommand(MOVE, key, toByteArray(dbIndex)); } public void flushAll() { - sendCommand(FLUSHALL); + sendCommand(FLUSHALL); } public void getSet(final byte[] key, final byte[] value) { - sendCommand(GETSET, key, value); + sendCommand(GETSET, key, value); } public void mget(final byte[]... keys) { - sendCommand(MGET, keys); + sendCommand(MGET, keys); } public void setnx(final byte[] key, final byte[] value) { - sendCommand(SETNX, key, value); + sendCommand(SETNX, key, value); } public void setex(final byte[] key, final int seconds, final byte[] value) { - sendCommand(SETEX, key, toByteArray(seconds), value); + sendCommand(SETEX, key, toByteArray(seconds), value); } public void mset(final byte[]... keysvalues) { - sendCommand(MSET, keysvalues); + sendCommand(MSET, keysvalues); } public void msetnx(final byte[]... keysvalues) { - sendCommand(MSETNX, keysvalues); + sendCommand(MSETNX, keysvalues); } public void decrBy(final byte[] key, final long integer) { - sendCommand(DECRBY, key, toByteArray(integer)); + sendCommand(DECRBY, key, toByteArray(integer)); } public void decr(final byte[] key) { - sendCommand(DECR, key); + sendCommand(DECR, key); } public void incrBy(final byte[] key, final long integer) { - sendCommand(INCRBY, key, toByteArray(integer)); + sendCommand(INCRBY, key, toByteArray(integer)); } public void incrByFloat(final byte[] key, final double value) { - sendCommand(INCRBYFLOAT, key, toByteArray(value)); + sendCommand(INCRBYFLOAT, key, toByteArray(value)); } public void incr(final byte[] key) { - sendCommand(INCR, key); + sendCommand(INCR, key); } public void append(final byte[] key, final byte[] value) { - sendCommand(APPEND, key, value); + sendCommand(APPEND, key, value); } public void substr(final byte[] key, final int start, final int end) { - sendCommand(SUBSTR, key, toByteArray(start), toByteArray(end)); + sendCommand(SUBSTR, key, toByteArray(start), toByteArray(end)); } public void hset(final byte[] key, final byte[] field, final byte[] value) { - sendCommand(HSET, key, field, value); + sendCommand(HSET, key, field, value); } public void hget(final byte[] key, final byte[] field) { - sendCommand(HGET, key, field); + sendCommand(HGET, key, field); } public void hsetnx(final byte[] key, final byte[] field, final byte[] value) { - sendCommand(HSETNX, key, field, value); + sendCommand(HSETNX, key, field, value); } public void hmset(final byte[] key, final Map hash) { - final List params = new ArrayList(); - params.add(key); + final List params = new ArrayList(); + params.add(key); - for (final Entry entry : hash.entrySet()) { - params.add(entry.getKey()); - params.add(entry.getValue()); - } - sendCommand(HMSET, params.toArray(new byte[params.size()][])); + for (final Entry entry : hash.entrySet()) { + params.add(entry.getKey()); + params.add(entry.getValue()); + } + sendCommand(HMSET, params.toArray(new byte[params.size()][])); } public void hmget(final byte[] key, final byte[]... fields) { - final byte[][] params = new byte[fields.length + 1][]; - params[0] = key; - System.arraycopy(fields, 0, params, 1, fields.length); - sendCommand(HMGET, params); + final byte[][] params = new byte[fields.length + 1][]; + params[0] = key; + System.arraycopy(fields, 0, params, 1, fields.length); + sendCommand(HMGET, params); } public void hincrBy(final byte[] key, final byte[] field, final long value) { - sendCommand(HINCRBY, key, field, toByteArray(value)); + sendCommand(HINCRBY, key, field, toByteArray(value)); } public void hexists(final byte[] key, final byte[] field) { - sendCommand(HEXISTS, key, field); + sendCommand(HEXISTS, key, field); } public void hdel(final byte[] key, final byte[]... fields) { - sendCommand(HDEL, joinParameters(key, fields)); + sendCommand(HDEL, joinParameters(key, fields)); } public void hlen(final byte[] key) { - sendCommand(HLEN, key); + sendCommand(HLEN, key); } public void hkeys(final byte[] key) { - sendCommand(HKEYS, key); + sendCommand(HKEYS, key); } public void hvals(final byte[] key) { - sendCommand(HVALS, key); + sendCommand(HVALS, key); } public void hgetAll(final byte[] key) { - sendCommand(HGETALL, key); + sendCommand(HGETALL, key); } public void rpush(final byte[] key, final byte[]... strings) { - sendCommand(RPUSH, joinParameters(key, strings)); + sendCommand(RPUSH, joinParameters(key, strings)); } public void lpush(final byte[] key, final byte[]... strings) { - sendCommand(LPUSH, joinParameters(key, strings)); + sendCommand(LPUSH, joinParameters(key, strings)); } public void llen(final byte[] key) { - sendCommand(LLEN, key); + sendCommand(LLEN, key); } public void lrange(final byte[] key, final long start, final long end) { - sendCommand(LRANGE, key, toByteArray(start), toByteArray(end)); + sendCommand(LRANGE, key, toByteArray(start), toByteArray(end)); } public void ltrim(final byte[] key, final long start, final long end) { - sendCommand(LTRIM, key, toByteArray(start), toByteArray(end)); + sendCommand(LTRIM, key, toByteArray(start), toByteArray(end)); } public void lindex(final byte[] key, final long index) { - sendCommand(LINDEX, key, toByteArray(index)); + sendCommand(LINDEX, key, toByteArray(index)); } public void lset(final byte[] key, final long index, final byte[] value) { - sendCommand(LSET, key, toByteArray(index), value); + sendCommand(LSET, key, toByteArray(index), value); } public void lrem(final byte[] key, long count, final byte[] value) { - sendCommand(LREM, key, toByteArray(count), value); + sendCommand(LREM, key, toByteArray(count), value); } public void lpop(final byte[] key) { - sendCommand(LPOP, key); + sendCommand(LPOP, key); } public void rpop(final byte[] key) { - sendCommand(RPOP, key); + sendCommand(RPOP, key); } public void rpoplpush(final byte[] srckey, final byte[] dstkey) { - sendCommand(RPOPLPUSH, srckey, dstkey); + sendCommand(RPOPLPUSH, srckey, dstkey); } public void sadd(final byte[] key, final byte[]... members) { - sendCommand(SADD, joinParameters(key, members)); + sendCommand(SADD, joinParameters(key, members)); } public void smembers(final byte[] key) { - sendCommand(SMEMBERS, key); + sendCommand(SMEMBERS, key); } public void srem(final byte[] key, final byte[]... members) { - sendCommand(SREM, joinParameters(key, members)); + sendCommand(SREM, joinParameters(key, members)); } public void spop(final byte[] key) { - sendCommand(SPOP, key); + sendCommand(SPOP, key); } public void smove(final byte[] srckey, final byte[] dstkey, - final byte[] member) { - sendCommand(SMOVE, srckey, dstkey, member); + final byte[] member) { + sendCommand(SMOVE, srckey, dstkey, member); } public void scard(final byte[] key) { - sendCommand(SCARD, key); + sendCommand(SCARD, key); } public void sismember(final byte[] key, final byte[] member) { - sendCommand(SISMEMBER, key, member); + sendCommand(SISMEMBER, key, member); } public void sinter(final byte[]... keys) { - sendCommand(SINTER, keys); + sendCommand(SINTER, keys); } public void sinterstore(final byte[] dstkey, final byte[]... keys) { - final byte[][] params = new byte[keys.length + 1][]; - params[0] = dstkey; - System.arraycopy(keys, 0, params, 1, keys.length); - sendCommand(SINTERSTORE, params); + final byte[][] params = new byte[keys.length + 1][]; + params[0] = dstkey; + System.arraycopy(keys, 0, params, 1, keys.length); + sendCommand(SINTERSTORE, params); } public void sunion(final byte[]... keys) { - sendCommand(SUNION, keys); + sendCommand(SUNION, keys); } public void sunionstore(final byte[] dstkey, final byte[]... keys) { - byte[][] params = new byte[keys.length + 1][]; - params[0] = dstkey; - System.arraycopy(keys, 0, params, 1, keys.length); - sendCommand(SUNIONSTORE, params); + byte[][] params = new byte[keys.length + 1][]; + params[0] = dstkey; + System.arraycopy(keys, 0, params, 1, keys.length); + sendCommand(SUNIONSTORE, params); } public void sdiff(final byte[]... keys) { - sendCommand(SDIFF, keys); + sendCommand(SDIFF, keys); } public void sdiffstore(final byte[] dstkey, final byte[]... keys) { - byte[][] params = new byte[keys.length + 1][]; - params[0] = dstkey; - System.arraycopy(keys, 0, params, 1, keys.length); - sendCommand(SDIFFSTORE, params); + byte[][] params = new byte[keys.length + 1][]; + params[0] = dstkey; + System.arraycopy(keys, 0, params, 1, keys.length); + sendCommand(SDIFFSTORE, params); } public void srandmember(final byte[] key) { - sendCommand(SRANDMEMBER, key); + sendCommand(SRANDMEMBER, key); } public void zadd(final byte[] key, final double score, final byte[] member) { - sendCommand(ZADD, key, toByteArray(score), member); + sendCommand(ZADD, key, toByteArray(score), member); } public void zaddBinary(final byte[] key, - final Map scoreMembers) { + final Map scoreMembers) { - ArrayList args = new ArrayList( - scoreMembers.size() * 2 + 1); - args.add(key); + ArrayList args = new ArrayList( + scoreMembers.size() * 2 + 1); + args.add(key); - for (Map.Entry entry : scoreMembers.entrySet()) { - args.add(toByteArray(entry.getValue())); - args.add(entry.getKey()); - } + for (Map.Entry entry : scoreMembers.entrySet()) { + args.add(toByteArray(entry.getValue())); + args.add(entry.getKey()); + } - byte[][] argsArray = new byte[args.size()][]; - args.toArray(argsArray); + byte[][] argsArray = new byte[args.size()][]; + args.toArray(argsArray); - sendCommand(ZADD, argsArray); + sendCommand(ZADD, argsArray); } public void zrange(final byte[] key, final long start, final long end) { - sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end)); + sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end)); } public void zrem(final byte[] key, final byte[]... members) { - sendCommand(ZREM, joinParameters(key, members)); + sendCommand(ZREM, joinParameters(key, members)); } public void zincrby(final byte[] key, final double score, - final byte[] member) { - sendCommand(ZINCRBY, key, toByteArray(score), member); + final byte[] member) { + sendCommand(ZINCRBY, key, toByteArray(score), member); } public void zrank(final byte[] key, final byte[] member) { - sendCommand(ZRANK, key, member); + sendCommand(ZRANK, key, member); } public void zrevrank(final byte[] key, final byte[] member) { - sendCommand(ZREVRANK, key, member); + sendCommand(ZREVRANK, key, member); } public void zrevrange(final byte[] key, final long start, final long end) { - sendCommand(ZREVRANGE, key, toByteArray(start), toByteArray(end)); + sendCommand(ZREVRANGE, key, toByteArray(start), toByteArray(end)); } public void zrangeWithScores(final byte[] key, final long start, - final long end) { - sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end), - WITHSCORES.raw); + final long end) { + sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end), + WITHSCORES.raw); } public void zrevrangeWithScores(final byte[] key, final long start, - final long end) { - sendCommand(ZREVRANGE, key, toByteArray(start), toByteArray(end), - WITHSCORES.raw); + final long end) { + sendCommand(ZREVRANGE, key, toByteArray(start), toByteArray(end), + WITHSCORES.raw); } public void zcard(final byte[] key) { - sendCommand(ZCARD, key); + sendCommand(ZCARD, key); } public void zscore(final byte[] key, final byte[] member) { - sendCommand(ZSCORE, key, member); + sendCommand(ZSCORE, key, member); } public void multi() { - sendCommand(MULTI); - isInMulti = true; + sendCommand(MULTI); + isInMulti = true; } public void discard() { - sendCommand(DISCARD); - isInMulti = false; - isInWatch = false; + sendCommand(DISCARD); + isInMulti = false; + isInWatch = false; } public void exec() { - sendCommand(EXEC); - isInMulti = false; - isInWatch = false; + sendCommand(EXEC); + isInMulti = false; + isInWatch = false; } public void watch(final byte[]... keys) { - sendCommand(WATCH, keys); - isInWatch = true; + sendCommand(WATCH, keys); + isInWatch = true; } public void unwatch() { - sendCommand(UNWATCH); - isInWatch = false; + sendCommand(UNWATCH); + isInWatch = false; } public void sort(final byte[] key) { - sendCommand(SORT, key); + sendCommand(SORT, key); } public void sort(final byte[] key, final SortingParams sortingParameters) { - final List args = new ArrayList(); - args.add(key); - args.addAll(sortingParameters.getParams()); - sendCommand(SORT, args.toArray(new byte[args.size()][])); + final List args = new ArrayList(); + args.add(key); + args.addAll(sortingParameters.getParams()); + sendCommand(SORT, args.toArray(new byte[args.size()][])); } public void blpop(final byte[][] args) { - sendCommand(BLPOP, args); + sendCommand(BLPOP, args); } public void blpop(final int timeout, final byte[]... keys) { - final List args = new ArrayList(); - for (final byte[] arg : keys) { - args.add(arg); - } - args.add(Protocol.toByteArray(timeout)); - blpop(args.toArray(new byte[args.size()][])); + final List args = new ArrayList(); + for (final byte[] arg : keys) { + args.add(arg); + } + args.add(Protocol.toByteArray(timeout)); + blpop(args.toArray(new byte[args.size()][])); } public void sort(final byte[] key, final SortingParams sortingParameters, - final byte[] dstkey) { - final List args = new ArrayList(); - args.add(key); - args.addAll(sortingParameters.getParams()); - args.add(STORE.raw); - args.add(dstkey); - sendCommand(SORT, args.toArray(new byte[args.size()][])); + final byte[] dstkey) { + final List args = new ArrayList(); + args.add(key); + args.addAll(sortingParameters.getParams()); + args.add(STORE.raw); + args.add(dstkey); + sendCommand(SORT, args.toArray(new byte[args.size()][])); } public void sort(final byte[] key, final byte[] dstkey) { - sendCommand(SORT, key, STORE.raw, dstkey); + sendCommand(SORT, key, STORE.raw, dstkey); } public void brpop(final byte[][] args) { - sendCommand(BRPOP, args); + sendCommand(BRPOP, args); } public void brpop(final int timeout, final byte[]... keys) { - final List args = new ArrayList(); - for (final byte[] arg : keys) { - args.add(arg); - } - args.add(Protocol.toByteArray(timeout)); - brpop(args.toArray(new byte[args.size()][])); + final List args = new ArrayList(); + for (final byte[] arg : keys) { + args.add(arg); + } + args.add(Protocol.toByteArray(timeout)); + brpop(args.toArray(new byte[args.size()][])); } public void auth(final String password) { - setPassword(password); - sendCommand(AUTH, password); + setPassword(password); + sendCommand(AUTH, password); } public void subscribe(final byte[]... channels) { - sendCommand(SUBSCRIBE, channels); + sendCommand(SUBSCRIBE, channels); } public void publish(final byte[] channel, final byte[] message) { - sendCommand(PUBLISH, channel, message); + sendCommand(PUBLISH, channel, message); } public void unsubscribe() { - sendCommand(UNSUBSCRIBE); + sendCommand(UNSUBSCRIBE); } public void unsubscribe(final byte[]... channels) { - sendCommand(UNSUBSCRIBE, channels); + sendCommand(UNSUBSCRIBE, channels); } public void psubscribe(final byte[]... patterns) { - sendCommand(PSUBSCRIBE, patterns); + sendCommand(PSUBSCRIBE, patterns); } public void punsubscribe() { - sendCommand(PUNSUBSCRIBE); + sendCommand(PUNSUBSCRIBE); } public void punsubscribe(final byte[]... patterns) { - sendCommand(PUNSUBSCRIBE, patterns); + sendCommand(PUNSUBSCRIBE, patterns); } public void pubsub(final byte[]... args) { - sendCommand(PUBSUB, args); + sendCommand(PUBSUB, args); } public void zcount(final byte[] key, final double min, final double max) { - byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" - .getBytes() : toByteArray(min); - byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf" - .getBytes() : toByteArray(max); + byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" + .getBytes() : toByteArray(min); + byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf" + .getBytes() : toByteArray(max); - sendCommand(ZCOUNT, key, byteArrayMin, byteArrayMax); + sendCommand(ZCOUNT, key, byteArrayMin, byteArrayMax); } public void zcount(final byte[] key, final byte min[], final byte max[]) { - sendCommand(ZCOUNT, key, min, max); + sendCommand(ZCOUNT, key, min, max); } public void zcount(final byte[] key, final String min, final String max) { - sendCommand(ZCOUNT, key, min.getBytes(), max.getBytes()); + sendCommand(ZCOUNT, key, min.getBytes(), max.getBytes()); } public void zrangeByScore(final byte[] key, final double min, - final double max) { + final double max) { - byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" - .getBytes() : toByteArray(min); - byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf" - .getBytes() : toByteArray(max); + byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" + .getBytes() : toByteArray(min); + byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf" + .getBytes() : toByteArray(max); - sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax); + sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax); } public void zrangeByScore(final byte[] key, final byte[] min, - final byte[] max) { - sendCommand(ZRANGEBYSCORE, key, min, max); + final byte[] max) { + sendCommand(ZRANGEBYSCORE, key, min, max); } public void zrangeByScore(final byte[] key, final String min, - final String max) { - sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes()); + final String max) { + sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes()); } public void zrevrangeByScore(final byte[] key, final double max, - final double min) { + final double min) { - byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" - .getBytes() : toByteArray(min); - byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf" - .getBytes() : toByteArray(max); + byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" + .getBytes() : toByteArray(min); + byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf" + .getBytes() : toByteArray(max); - sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin); + sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin); } public void zrevrangeByScore(final byte[] key, final byte[] max, - final byte[] min) { - sendCommand(ZREVRANGEBYSCORE, key, max, min); + final byte[] min) { + sendCommand(ZREVRANGEBYSCORE, key, max, min); } public void zrevrangeByScore(final byte[] key, final String max, - final String min) { - sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes()); + final String min) { + sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes()); } public void zrangeByScore(final byte[] key, final double min, - final double max, final int offset, int count) { + final double max, final int offset, int count) { - byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" - .getBytes() : toByteArray(min); - byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf" - .getBytes() : toByteArray(max); + byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" + .getBytes() : toByteArray(min); + byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf" + .getBytes() : toByteArray(max); - sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax, LIMIT.raw, - toByteArray(offset), toByteArray(count)); + sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax, LIMIT.raw, + toByteArray(offset), toByteArray(count)); } public void zrangeByScore(final byte[] key, final String min, - final String max, final int offset, int count) { + final String max, final int offset, int count) { - sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes(), - LIMIT.raw, toByteArray(offset), toByteArray(count)); + sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes(), + LIMIT.raw, toByteArray(offset), toByteArray(count)); } public void zrevrangeByScore(final byte[] key, final double max, - final double min, final int offset, int count) { + final double min, final int offset, int count) { - byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" - .getBytes() : toByteArray(min); - byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf" - .getBytes() : toByteArray(max); + byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" + .getBytes() : toByteArray(min); + byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf" + .getBytes() : toByteArray(max); - sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin, - LIMIT.raw, toByteArray(offset), toByteArray(count)); + sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin, + LIMIT.raw, toByteArray(offset), toByteArray(count)); } public void zrevrangeByScore(final byte[] key, final String max, - final String min, final int offset, int count) { + final String min, final int offset, int count) { - sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes(), - LIMIT.raw, toByteArray(offset), toByteArray(count)); + sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes(), + LIMIT.raw, toByteArray(offset), toByteArray(count)); } public void zrangeByScoreWithScores(final byte[] key, final double min, - final double max) { + final double max) { - byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" - .getBytes() : toByteArray(min); - byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf" - .getBytes() : toByteArray(max); + byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" + .getBytes() : toByteArray(min); + byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf" + .getBytes() : toByteArray(max); - sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax, - WITHSCORES.raw); + sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax, + WITHSCORES.raw); } public void zrangeByScoreWithScores(final byte[] key, final String min, - final String max) { + final String max) { - sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes(), - WITHSCORES.raw); + sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes(), + WITHSCORES.raw); } public void zrevrangeByScoreWithScores(final byte[] key, final double max, - final double min) { + final double min) { - byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" - .getBytes() : toByteArray(min); - byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf" - .getBytes() : toByteArray(max); + byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" + .getBytes() : toByteArray(min); + byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf" + .getBytes() : toByteArray(max); - sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin, - WITHSCORES.raw); + sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin, + WITHSCORES.raw); } public void zrevrangeByScoreWithScores(final byte[] key, final String max, - final String min) { - sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes(), - WITHSCORES.raw); + final String min) { + sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes(), + WITHSCORES.raw); } public void zrangeByScoreWithScores(final byte[] key, final double min, - final double max, final int offset, final int count) { + final double max, final int offset, final int count) { - byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" - .getBytes() : toByteArray(min); - byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf" - .getBytes() : toByteArray(max); + byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" + .getBytes() : toByteArray(min); + byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf" + .getBytes() : toByteArray(max); - sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax, LIMIT.raw, - toByteArray(offset), toByteArray(count), WITHSCORES.raw); + sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax, LIMIT.raw, + toByteArray(offset), toByteArray(count), WITHSCORES.raw); } public void zrangeByScoreWithScores(final byte[] key, final String min, - final String max, final int offset, final int count) { - sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes(), - LIMIT.raw, toByteArray(offset), toByteArray(count), - WITHSCORES.raw); + final String max, final int offset, final int count) { + sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes(), + LIMIT.raw, toByteArray(offset), toByteArray(count), + WITHSCORES.raw); } public void zrevrangeByScoreWithScores(final byte[] key, final double max, - final double min, final int offset, final int count) { + final double min, final int offset, final int count) { - byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" - .getBytes() : toByteArray(min); - byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf" - .getBytes() : toByteArray(max); + byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" + .getBytes() : toByteArray(min); + byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf" + .getBytes() : toByteArray(max); - sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin, - LIMIT.raw, toByteArray(offset), toByteArray(count), - WITHSCORES.raw); + sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin, + LIMIT.raw, toByteArray(offset), toByteArray(count), + WITHSCORES.raw); } public void zrevrangeByScoreWithScores(final byte[] key, final String max, - final String min, final int offset, final int count) { + final String min, final int offset, final int count) { - sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes(), - LIMIT.raw, toByteArray(offset), toByteArray(count), - WITHSCORES.raw); + sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes(), + LIMIT.raw, toByteArray(offset), toByteArray(count), + WITHSCORES.raw); } public void zrangeByScore(final byte[] key, final byte[] min, - final byte[] max, final int offset, int count) { - sendCommand(ZRANGEBYSCORE, key, min, max, LIMIT.raw, - toByteArray(offset), toByteArray(count)); + final byte[] max, final int offset, int count) { + sendCommand(ZRANGEBYSCORE, key, min, max, LIMIT.raw, + toByteArray(offset), toByteArray(count)); } public void zrevrangeByScore(final byte[] key, final byte[] max, - final byte[] min, final int offset, int count) { - sendCommand(ZREVRANGEBYSCORE, key, max, min, LIMIT.raw, - toByteArray(offset), toByteArray(count)); + final byte[] min, final int offset, int count) { + sendCommand(ZREVRANGEBYSCORE, key, max, min, LIMIT.raw, + toByteArray(offset), toByteArray(count)); } public void zrangeByScoreWithScores(final byte[] key, final byte[] min, - final byte[] max) { - sendCommand(ZRANGEBYSCORE, key, min, max, WITHSCORES.raw); + final byte[] max) { + sendCommand(ZRANGEBYSCORE, key, min, max, WITHSCORES.raw); } public void zrevrangeByScoreWithScores(final byte[] key, final byte[] max, - final byte[] min) { - sendCommand(ZREVRANGEBYSCORE, key, max, min, WITHSCORES.raw); + final byte[] min) { + sendCommand(ZREVRANGEBYSCORE, key, max, min, WITHSCORES.raw); } public void zrangeByScoreWithScores(final byte[] key, final byte[] min, - final byte[] max, final int offset, final int count) { - sendCommand(ZRANGEBYSCORE, key, min, max, LIMIT.raw, - toByteArray(offset), toByteArray(count), WITHSCORES.raw); + final byte[] max, final int offset, final int count) { + sendCommand(ZRANGEBYSCORE, key, min, max, LIMIT.raw, + toByteArray(offset), toByteArray(count), WITHSCORES.raw); } public void zrevrangeByScoreWithScores(final byte[] key, final byte[] max, - final byte[] min, final int offset, final int count) { - sendCommand(ZREVRANGEBYSCORE, key, max, min, LIMIT.raw, - toByteArray(offset), toByteArray(count), WITHSCORES.raw); + final byte[] min, final int offset, final int count) { + sendCommand(ZREVRANGEBYSCORE, key, max, min, LIMIT.raw, + toByteArray(offset), toByteArray(count), WITHSCORES.raw); } public void zremrangeByRank(final byte[] key, final long start, - final long end) { - sendCommand(ZREMRANGEBYRANK, key, toByteArray(start), toByteArray(end)); + final long end) { + sendCommand(ZREMRANGEBYRANK, key, toByteArray(start), toByteArray(end)); } public void zremrangeByScore(final byte[] key, final byte[] start, - final byte[] end) { - sendCommand(ZREMRANGEBYSCORE, key, start, end); + final byte[] end) { + sendCommand(ZREMRANGEBYSCORE, key, start, end); } public void zremrangeByScore(final byte[] key, final String start, - final String end) { - sendCommand(ZREMRANGEBYSCORE, key, start.getBytes(), end.getBytes()); + final String end) { + sendCommand(ZREMRANGEBYSCORE, key, start.getBytes(), end.getBytes()); } public void zunionstore(final byte[] dstkey, final byte[]... sets) { - final byte[][] params = new byte[sets.length + 2][]; - params[0] = dstkey; - params[1] = toByteArray(sets.length); - System.arraycopy(sets, 0, params, 2, sets.length); - sendCommand(ZUNIONSTORE, params); + final byte[][] params = new byte[sets.length + 2][]; + params[0] = dstkey; + params[1] = toByteArray(sets.length); + System.arraycopy(sets, 0, params, 2, sets.length); + sendCommand(ZUNIONSTORE, params); } public void zunionstore(final byte[] dstkey, final ZParams params, - final byte[]... sets) { - final List args = new ArrayList(); - args.add(dstkey); - args.add(Protocol.toByteArray(sets.length)); - for (final byte[] set : sets) { - args.add(set); - } - args.addAll(params.getParams()); - sendCommand(ZUNIONSTORE, args.toArray(new byte[args.size()][])); + final byte[]... sets) { + final List args = new ArrayList(); + args.add(dstkey); + args.add(Protocol.toByteArray(sets.length)); + for (final byte[] set : sets) { + args.add(set); + } + args.addAll(params.getParams()); + sendCommand(ZUNIONSTORE, args.toArray(new byte[args.size()][])); } public void zinterstore(final byte[] dstkey, final byte[]... sets) { - final byte[][] params = new byte[sets.length + 2][]; - params[0] = dstkey; - params[1] = Protocol.toByteArray(sets.length); - System.arraycopy(sets, 0, params, 2, sets.length); - sendCommand(ZINTERSTORE, params); + final byte[][] params = new byte[sets.length + 2][]; + params[0] = dstkey; + params[1] = Protocol.toByteArray(sets.length); + System.arraycopy(sets, 0, params, 2, sets.length); + sendCommand(ZINTERSTORE, params); } public void zinterstore(final byte[] dstkey, final ZParams params, - final byte[]... sets) { - final List args = new ArrayList(); - args.add(dstkey); - args.add(Protocol.toByteArray(sets.length)); - for (final byte[] set : sets) { - args.add(set); - } - args.addAll(params.getParams()); - sendCommand(ZINTERSTORE, args.toArray(new byte[args.size()][])); + final byte[]... sets) { + final List args = new ArrayList(); + args.add(dstkey); + args.add(Protocol.toByteArray(sets.length)); + for (final byte[] set : sets) { + args.add(set); + } + args.addAll(params.getParams()); + sendCommand(ZINTERSTORE, args.toArray(new byte[args.size()][])); } public void zlexcount(final byte[] key, final byte[] min, final byte[] max) { - sendCommand(ZLEXCOUNT, key, min, max); + sendCommand(ZLEXCOUNT, key, min, max); } public void zrangeByLex(final byte[] key, final byte[] min, final byte[] max) { - sendCommand(ZRANGEBYLEX, key, min, max); + 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)); + 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) { - sendCommand(ZREVRANGEBYLEX, key, max, min); + 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) { - sendCommand(ZREVRANGEBYLEX, key, max, min, LIMIT.raw, - toByteArray(offset), toByteArray(count)); + final byte[] min, final int offset, final int count) { + sendCommand(ZREVRANGEBYLEX, key, max, min, LIMIT.raw, + toByteArray(offset), toByteArray(count)); } public void zremrangeByLex(byte[] key, byte[] min, byte[] max) { - sendCommand(ZREMRANGEBYLEX, key, min, max); + sendCommand(ZREMRANGEBYLEX, key, min, max); } public void save() { - sendCommand(SAVE); + sendCommand(SAVE); } public void bgsave() { - sendCommand(BGSAVE); + sendCommand(BGSAVE); } public void bgrewriteaof() { - sendCommand(BGREWRITEAOF); + sendCommand(BGREWRITEAOF); } public void lastsave() { - sendCommand(LASTSAVE); + sendCommand(LASTSAVE); } public void shutdown() { - sendCommand(SHUTDOWN); + sendCommand(SHUTDOWN); } public void info() { - sendCommand(INFO); + sendCommand(INFO); } public void info(final String section) { - sendCommand(INFO, section); + sendCommand(INFO, section); } public void monitor() { - sendCommand(MONITOR); + sendCommand(MONITOR); } public void slaveof(final String host, final int port) { - sendCommand(SLAVEOF, host, String.valueOf(port)); + sendCommand(SLAVEOF, host, String.valueOf(port)); } public void slaveofNoOne() { - sendCommand(SLAVEOF, NO.raw, ONE.raw); + sendCommand(SLAVEOF, NO.raw, ONE.raw); } public void configGet(final byte[] pattern) { - sendCommand(CONFIG, Keyword.GET.raw, pattern); + sendCommand(CONFIG, Keyword.GET.raw, pattern); } public void configSet(final byte[] parameter, final byte[] value) { - sendCommand(CONFIG, Keyword.SET.raw, parameter, value); + sendCommand(CONFIG, Keyword.SET.raw, parameter, value); } public void strlen(final byte[] key) { - sendCommand(STRLEN, key); + sendCommand(STRLEN, key); } public void sync() { - sendCommand(SYNC); + sendCommand(SYNC); } public void lpushx(final byte[] key, final byte[]... string) { - sendCommand(LPUSHX, joinParameters(key, string)); + sendCommand(LPUSHX, joinParameters(key, string)); } public void persist(final byte[] key) { - sendCommand(PERSIST, key); + sendCommand(PERSIST, key); } public void rpushx(final byte[] key, final byte[]... string) { - sendCommand(RPUSHX, joinParameters(key, string)); + sendCommand(RPUSHX, joinParameters(key, string)); } public void echo(final byte[] string) { - sendCommand(ECHO, string); + sendCommand(ECHO, string); } public void linsert(final byte[] key, final LIST_POSITION where, - final byte[] pivot, final byte[] value) { - sendCommand(LINSERT, key, where.raw, pivot, value); + final byte[] pivot, final byte[] value) { + sendCommand(LINSERT, key, where.raw, pivot, value); } public void debug(final DebugParams params) { - sendCommand(DEBUG, params.getCommand()); + sendCommand(DEBUG, params.getCommand()); } public void brpoplpush(final byte[] source, final byte[] destination, - final int timeout) { - sendCommand(BRPOPLPUSH, source, destination, toByteArray(timeout)); + final int timeout) { + sendCommand(BRPOPLPUSH, source, destination, toByteArray(timeout)); } public void configResetStat() { - sendCommand(CONFIG, Keyword.RESETSTAT.name()); + sendCommand(CONFIG, Keyword.RESETSTAT.name()); } public void setbit(byte[] key, long offset, byte[] value) { - sendCommand(SETBIT, key, toByteArray(offset), value); + sendCommand(SETBIT, key, toByteArray(offset), value); } public void setbit(byte[] key, long offset, boolean value) { - sendCommand(SETBIT, key, toByteArray(offset), toByteArray(value)); + sendCommand(SETBIT, key, toByteArray(offset), toByteArray(value)); } public void getbit(byte[] key, long offset) { - sendCommand(GETBIT, key, toByteArray(offset)); + sendCommand(GETBIT, key, toByteArray(offset)); } public void bitpos(final byte[] key, final boolean value, - final BitPosParams params) { - final List args = new ArrayList(); - args.add(key); - args.add(toByteArray(value)); - args.addAll(params.getParams()); - sendCommand(BITPOS, args.toArray(new byte[args.size()][])); + final BitPosParams params) { + final List args = new ArrayList(); + args.add(key); + args.add(toByteArray(value)); + args.addAll(params.getParams()); + sendCommand(BITPOS, args.toArray(new byte[args.size()][])); } public void setrange(byte[] key, long offset, byte[] value) { - sendCommand(SETRANGE, key, toByteArray(offset), value); + sendCommand(SETRANGE, key, toByteArray(offset), value); } public void getrange(byte[] key, long startOffset, long endOffset) { - sendCommand(GETRANGE, key, toByteArray(startOffset), - toByteArray(endOffset)); + sendCommand(GETRANGE, key, toByteArray(startOffset), + toByteArray(endOffset)); } public Long getDB() { - return db; + return db; } public void disconnect() { - db = 0; - super.disconnect(); + db = 0; + super.disconnect(); } @Override public void close() { - db = 0; - super.close(); + db = 0; + super.close(); } public void resetState() { - if (isInWatch()) - unwatch(); + if (isInWatch()) + unwatch(); } private void sendEvalCommand(Command command, byte[] script, - byte[] keyCount, byte[][] params) { + byte[] keyCount, byte[][] params) { - final byte[][] allArgs = new byte[params.length + 2][]; + final byte[][] allArgs = new byte[params.length + 2][]; - allArgs[0] = script; - allArgs[1] = keyCount; + allArgs[0] = script; + allArgs[1] = keyCount; - for (int i = 0; i < params.length; i++) - allArgs[i + 2] = params[i]; + for (int i = 0; i < params.length; i++) + allArgs[i + 2] = params[i]; - sendCommand(command, allArgs); + sendCommand(command, allArgs); } public void eval(byte[] script, byte[] keyCount, byte[][] params) { - sendEvalCommand(EVAL, script, keyCount, params); + sendEvalCommand(EVAL, script, keyCount, params); } public void eval(byte[] script, int keyCount, byte[]... params) { - eval(script, toByteArray(keyCount), params); + eval(script, toByteArray(keyCount), params); } public void evalsha(byte[] sha1, byte[] keyCount, byte[]... params) { - sendEvalCommand(EVALSHA, sha1, keyCount, params); + sendEvalCommand(EVALSHA, sha1, keyCount, params); } public void evalsha(byte[] sha1, int keyCount, byte[]... params) { - sendEvalCommand(EVALSHA, sha1, toByteArray(keyCount), params); + sendEvalCommand(EVALSHA, sha1, toByteArray(keyCount), params); } public void scriptFlush() { - sendCommand(SCRIPT, Keyword.FLUSH.raw); + sendCommand(SCRIPT, Keyword.FLUSH.raw); } public void scriptExists(byte[]... sha1) { - byte[][] args = new byte[sha1.length + 1][]; - args[0] = Keyword.EXISTS.raw; - for (int i = 0; i < sha1.length; i++) - args[i + 1] = sha1[i]; + byte[][] args = new byte[sha1.length + 1][]; + args[0] = Keyword.EXISTS.raw; + for (int i = 0; i < sha1.length; i++) + args[i + 1] = sha1[i]; - sendCommand(SCRIPT, args); + sendCommand(SCRIPT, args); } public void scriptLoad(byte[] script) { - sendCommand(SCRIPT, Keyword.LOAD.raw, script); + sendCommand(SCRIPT, Keyword.LOAD.raw, script); } public void scriptKill() { - sendCommand(SCRIPT, Keyword.KILL.raw); + sendCommand(SCRIPT, Keyword.KILL.raw); } public void slowlogGet() { - sendCommand(SLOWLOG, Keyword.GET.raw); + sendCommand(SLOWLOG, Keyword.GET.raw); } public void slowlogGet(long entries) { - sendCommand(SLOWLOG, Keyword.GET.raw, toByteArray(entries)); + sendCommand(SLOWLOG, Keyword.GET.raw, toByteArray(entries)); } public void slowlogReset() { - sendCommand(SLOWLOG, RESET.raw); + sendCommand(SLOWLOG, RESET.raw); } public void slowlogLen() { - sendCommand(SLOWLOG, LEN.raw); + sendCommand(SLOWLOG, LEN.raw); } public void objectRefcount(byte[] key) { - sendCommand(OBJECT, REFCOUNT.raw, key); + sendCommand(OBJECT, REFCOUNT.raw, key); } public void objectIdletime(byte[] key) { - sendCommand(OBJECT, IDLETIME.raw, key); + sendCommand(OBJECT, IDLETIME.raw, key); } public void objectEncoding(byte[] key) { - sendCommand(OBJECT, ENCODING.raw, key); + sendCommand(OBJECT, ENCODING.raw, key); } public void bitcount(byte[] key) { - sendCommand(BITCOUNT, key); + sendCommand(BITCOUNT, key); } public void bitcount(byte[] key, long start, long end) { - sendCommand(BITCOUNT, key, toByteArray(start), toByteArray(end)); + sendCommand(BITCOUNT, key, toByteArray(start), toByteArray(end)); } public void bitop(BitOP op, byte[] destKey, byte[]... srcKeys) { - Keyword kw = Keyword.AND; - int len = srcKeys.length; - switch (op) { - case AND: - kw = Keyword.AND; - break; - case OR: - kw = Keyword.OR; - break; - case XOR: - kw = Keyword.XOR; - break; - case NOT: - kw = Keyword.NOT; - len = Math.min(1, len); - break; - } + Keyword kw = Keyword.AND; + int len = srcKeys.length; + switch (op) { + case AND: + kw = Keyword.AND; + break; + case OR: + kw = Keyword.OR; + break; + case XOR: + kw = Keyword.XOR; + break; + case NOT: + kw = Keyword.NOT; + len = Math.min(1, len); + break; + } - byte[][] bargs = new byte[len + 2][]; - bargs[0] = kw.raw; - bargs[1] = destKey; - for (int i = 0; i < len; ++i) { - bargs[i + 2] = srcKeys[i]; - } + byte[][] bargs = new byte[len + 2][]; + bargs[0] = kw.raw; + bargs[1] = destKey; + for (int i = 0; i < len; ++i) { + bargs[i + 2] = srcKeys[i]; + } - sendCommand(BITOP, bargs); + sendCommand(BITOP, bargs); } public void sentinel(final byte[]... args) { - sendCommand(SENTINEL, args); + sendCommand(SENTINEL, args); } public void dump(final byte[] key) { - sendCommand(DUMP, key); + sendCommand(DUMP, key); } public void restore(final byte[] key, final int ttl, - final byte[] serializedValue) { - sendCommand(RESTORE, key, toByteArray(ttl), serializedValue); + final byte[] serializedValue) { + sendCommand(RESTORE, key, toByteArray(ttl), serializedValue); } public void pexpire(final byte[] key, final long milliseconds) { - sendCommand(PEXPIRE, key, toByteArray(milliseconds)); + sendCommand(PEXPIRE, key, toByteArray(milliseconds)); } public void pexpireAt(final byte[] key, final long millisecondsTimestamp) { - sendCommand(PEXPIREAT, key, toByteArray(millisecondsTimestamp)); + sendCommand(PEXPIREAT, key, toByteArray(millisecondsTimestamp)); } public void pttl(final byte[] key) { - sendCommand(PTTL, key); + sendCommand(PTTL, key); } public void psetex(final byte[] key, final int milliseconds, - final byte[] value) { - sendCommand(PSETEX, key, toByteArray(milliseconds), value); + final byte[] value) { + sendCommand(PSETEX, key, toByteArray(milliseconds), value); } public void set(final byte[] key, final byte[] value, final byte[] nxxx) { - sendCommand(Command.SET, key, value, nxxx); + sendCommand(Command.SET, key, value, nxxx); } public void set(final byte[] key, final byte[] value, final byte[] nxxx, - final byte[] expx, final int time) { - sendCommand(Command.SET, key, value, nxxx, expx, toByteArray(time)); + final byte[] expx, final int time) { + sendCommand(Command.SET, key, value, nxxx, expx, toByteArray(time)); } public void srandmember(final byte[] key, final int count) { - sendCommand(SRANDMEMBER, key, toByteArray(count)); + sendCommand(SRANDMEMBER, key, toByteArray(count)); } public void clientKill(final byte[] client) { - sendCommand(CLIENT, Keyword.KILL.raw, client); + sendCommand(CLIENT, Keyword.KILL.raw, client); } public void clientGetname() { - sendCommand(CLIENT, Keyword.GETNAME.raw); + sendCommand(CLIENT, Keyword.GETNAME.raw); } public void clientList() { - sendCommand(CLIENT, Keyword.LIST.raw); + sendCommand(CLIENT, Keyword.LIST.raw); } public void clientSetname(final byte[] name) { - sendCommand(CLIENT, Keyword.SETNAME.raw, name); + sendCommand(CLIENT, Keyword.SETNAME.raw, name); } public void time() { - sendCommand(TIME); + sendCommand(TIME); } public void migrate(final byte[] host, final int port, final byte[] key, - final int destinationDb, final int timeout) { - sendCommand(MIGRATE, host, toByteArray(port), key, - toByteArray(destinationDb), toByteArray(timeout)); + final int destinationDb, final int timeout) { + sendCommand(MIGRATE, host, toByteArray(port), key, + toByteArray(destinationDb), toByteArray(timeout)); } public void hincrByFloat(final byte[] key, final byte[] field, - double increment) { - sendCommand(HINCRBYFLOAT, key, field, toByteArray(increment)); + double increment) { + sendCommand(HINCRBYFLOAT, key, field, toByteArray(increment)); } public void scan(final byte[] cursor, final ScanParams params) { - final List args = new ArrayList(); - args.add(cursor); - args.addAll(params.getParams()); - sendCommand(SCAN, args.toArray(new byte[args.size()][])); + final List args = new ArrayList(); + args.add(cursor); + args.addAll(params.getParams()); + sendCommand(SCAN, args.toArray(new byte[args.size()][])); } public void hscan(final byte[] key, final byte[] cursor, - final ScanParams params) { - final List args = new ArrayList(); - args.add(key); - args.add(cursor); - args.addAll(params.getParams()); - sendCommand(HSCAN, args.toArray(new byte[args.size()][])); + final ScanParams params) { + final List args = new ArrayList(); + args.add(key); + args.add(cursor); + args.addAll(params.getParams()); + sendCommand(HSCAN, args.toArray(new byte[args.size()][])); } public void sscan(final byte[] key, final byte[] cursor, - final ScanParams params) { - final List args = new ArrayList(); - args.add(key); - args.add(cursor); - args.addAll(params.getParams()); - sendCommand(SSCAN, args.toArray(new byte[args.size()][])); + final ScanParams params) { + final List args = new ArrayList(); + args.add(key); + args.add(cursor); + args.addAll(params.getParams()); + sendCommand(SSCAN, args.toArray(new byte[args.size()][])); } public void zscan(final byte[] key, final byte[] cursor, - final ScanParams params) { - final List args = new ArrayList(); - args.add(key); - args.add(cursor); - args.addAll(params.getParams()); - sendCommand(ZSCAN, args.toArray(new byte[args.size()][])); + final ScanParams params) { + final List args = new ArrayList(); + args.add(key); + args.add(cursor); + args.addAll(params.getParams()); + sendCommand(ZSCAN, args.toArray(new byte[args.size()][])); } public void waitReplicas(int replicas, long timeout) { - sendCommand(WAIT, toByteArray(replicas), toByteArray(timeout)); + sendCommand(WAIT, toByteArray(replicas), toByteArray(timeout)); } public void cluster(final byte[]... args) { - sendCommand(CLUSTER, args); + sendCommand(CLUSTER, args); } public void asking() { - sendCommand(Command.ASKING); + sendCommand(Command.ASKING); } public void pfadd(final byte[] key, final byte[]... elements) { - sendCommand(PFADD, joinParameters(key, elements)); + sendCommand(PFADD, joinParameters(key, elements)); } public void pfcount(final byte[] key) { - sendCommand(PFCOUNT, key); + sendCommand(PFCOUNT, key); } public void pfcount(final byte[]... keys) { - sendCommand(PFCOUNT, keys); + sendCommand(PFCOUNT, keys); } public void pfmerge(final byte[] destkey, final byte[]... sourcekeys) { - sendCommand(PFMERGE, joinParameters(destkey, sourcekeys)); + sendCommand(PFMERGE, joinParameters(destkey, sourcekeys)); } } diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 56fd39a..421c64b 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -21,69 +21,69 @@ import redis.clients.util.JedisURIHelper; import redis.clients.util.SafeEncoder; public class BinaryJedis implements BasicCommands, BinaryJedisCommands, - MultiKeyBinaryCommands, AdvancedBinaryJedisCommands, - BinaryScriptingCommands, Closeable { + MultiKeyBinaryCommands, AdvancedBinaryJedisCommands, + BinaryScriptingCommands, Closeable { protected Client client = null; protected Transaction transaction = null; protected Pipeline pipeline = null; public BinaryJedis() { - client = new Client(); + client = new Client(); } public BinaryJedis(final String host) { - URI uri = URI.create(host); - if (uri.getScheme() != null && uri.getScheme().equals("redis")) { - initializeClientFromURI(uri); - } else { - client = new Client(host); - } + URI uri = URI.create(host); + if (uri.getScheme() != null && uri.getScheme().equals("redis")) { + initializeClientFromURI(uri); + } else { + client = new Client(host); + } } public BinaryJedis(final String host, final int port) { - client = new Client(host, port); + client = new Client(host, port); } public BinaryJedis(final String host, final int port, final int timeout) { - client = new Client(host, port); - client.setTimeout(timeout); + client = new Client(host, port); + client.setTimeout(timeout); } public BinaryJedis(final JedisShardInfo shardInfo) { - client = new Client(shardInfo.getHost(), shardInfo.getPort()); - client.setTimeout(shardInfo.getTimeout()); - client.setPassword(shardInfo.getPassword()); + client = new Client(shardInfo.getHost(), shardInfo.getPort()); + client.setTimeout(shardInfo.getTimeout()); + client.setPassword(shardInfo.getPassword()); } public BinaryJedis(URI uri) { - initializeClientFromURI(uri); + initializeClientFromURI(uri); } public BinaryJedis(final URI uri, final int timeout) { - initializeClientFromURI(uri); - client.setTimeout(timeout); + initializeClientFromURI(uri); + client.setTimeout(timeout); } private void initializeClientFromURI(URI uri) { - client = new Client(uri.getHost(), uri.getPort()); + client = new Client(uri.getHost(), uri.getPort()); - String password = JedisURIHelper.getPassword(uri); - if (password != null) { - client.auth(password); - client.getStatusCodeReply(); - } + String password = JedisURIHelper.getPassword(uri); + if (password != null) { + client.auth(password); + client.getStatusCodeReply(); + } - Integer dbIndex = JedisURIHelper.getDBIndex(uri); - if (dbIndex > 0) { - client.select(dbIndex); - client.getStatusCodeReply(); - } + Integer dbIndex = JedisURIHelper.getDBIndex(uri); + if (dbIndex > 0) { + client.select(dbIndex); + client.getStatusCodeReply(); + } } public String ping() { - checkIsInMulti(); - client.ping(); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.ping(); + return client.getStatusCodeReply(); } /** @@ -97,9 +97,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code reply */ public String set(final byte[] key, final byte[] value) { - checkIsInMulti(); - client.set(key, value); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.set(key, value); + return client.getStatusCodeReply(); } /** @@ -118,10 +118,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code reply */ public String set(final byte[] key, final byte[] value, final byte[] nxxx, - final byte[] expx, final long time) { - checkIsInMulti(); - client.set(key, value, nxxx, expx, time); - return client.getStatusCodeReply(); + final byte[] expx, final long time) { + checkIsInMulti(); + client.set(key, value, nxxx, expx, time); + return client.getStatusCodeReply(); } /** @@ -135,18 +135,18 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Bulk reply */ public byte[] get(final byte[] key) { - checkIsInMulti(); - client.get(key); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.get(key); + return client.getBinaryBulkReply(); } /** * Ask the server to silently close the connection. */ public String quit() { - checkIsInMulti(); - client.quit(); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.quit(); + return client.getStatusCodeReply(); } /** @@ -160,9 +160,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Integer reply, "1" if the key exists, otherwise "0" */ public Boolean exists(final byte[] key) { - checkIsInMulti(); - client.exists(key); - return client.getIntegerReply() == 1; + checkIsInMulti(); + client.exists(key); + return client.getIntegerReply() == 1; } /** @@ -176,15 +176,15 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * more keys were removed 0 if none of the specified key existed */ public Long del(final byte[]... keys) { - checkIsInMulti(); - client.del(keys); - return client.getIntegerReply(); + checkIsInMulti(); + client.del(keys); + return client.getIntegerReply(); } public Long del(final byte[] key) { - checkIsInMulti(); - client.del(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.del(key); + return client.getIntegerReply(); } /** @@ -202,9 +202,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * contains a Hash value */ public String type(final byte[] key) { - checkIsInMulti(); - client.type(key); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.type(key); + return client.getStatusCodeReply(); } /** @@ -214,9 +214,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code reply */ public String flushDB() { - checkIsInMulti(); - client.flushDB(); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.flushDB(); + return client.getStatusCodeReply(); } /** @@ -251,9 +251,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Multi bulk reply */ public Set keys(final byte[] pattern) { - checkIsInMulti(); - client.keys(pattern); - return new HashSet(client.getBinaryMultiBulkReply()); + checkIsInMulti(); + client.keys(pattern); + return new HashSet(client.getBinaryMultiBulkReply()); } /** @@ -265,9 +265,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * empty string is the database is empty */ public byte[] randomBinaryKey() { - checkIsInMulti(); - client.randomKey(); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.randomKey(); + return client.getBinaryBulkReply(); } /** @@ -282,9 +282,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code repy */ public String rename(final byte[] oldkey, final byte[] newkey) { - checkIsInMulti(); - client.rename(oldkey, newkey); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.rename(oldkey, newkey); + return client.getStatusCodeReply(); } /** @@ -299,9 +299,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * target key already exist */ public Long renamenx(final byte[] oldkey, final byte[] newkey) { - checkIsInMulti(); - client.renamenx(oldkey, newkey); - return client.getIntegerReply(); + checkIsInMulti(); + client.renamenx(oldkey, newkey); + return client.getIntegerReply(); } /** @@ -310,9 +310,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Integer reply */ public Long dbSize() { - checkIsInMulti(); - client.dbSize(); - return client.getIntegerReply(); + checkIsInMulti(); + client.dbSize(); + return client.getIntegerReply(); } /** @@ -344,9 +344,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * exist. */ public Long expire(final byte[] key, final int seconds) { - checkIsInMulti(); - client.expire(key, seconds); - return client.getIntegerReply(); + checkIsInMulti(); + client.expire(key, seconds); + return client.getIntegerReply(); } /** @@ -380,9 +380,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * exist. */ public Long expireAt(final byte[] key, final long unixTime) { - checkIsInMulti(); - client.expireAt(key, unixTime); - return client.getIntegerReply(); + checkIsInMulti(); + client.expireAt(key, unixTime); + return client.getIntegerReply(); } /** @@ -397,9 +397,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * have an associated expire, -1 is returned. */ public Long ttl(final byte[] key) { - checkIsInMulti(); - client.ttl(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.ttl(key); + return client.getIntegerReply(); } /** @@ -410,9 +410,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code reply */ public String select(final int index) { - checkIsInMulti(); - client.select(index); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.select(index); + return client.getStatusCodeReply(); } /** @@ -429,9 +429,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * found in the current DB. */ public Long move(final byte[] key, final int dbIndex) { - checkIsInMulti(); - client.move(key, dbIndex); - return client.getIntegerReply(); + checkIsInMulti(); + client.move(key, dbIndex); + return client.getIntegerReply(); } /** @@ -441,9 +441,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code reply */ public String flushAll() { - checkIsInMulti(); - client.flushAll(); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.flushAll(); + return client.getStatusCodeReply(); } /** @@ -458,9 +458,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Bulk reply */ public byte[] getSet(final byte[] key, final byte[] value) { - checkIsInMulti(); - client.getSet(key, value); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.getSet(key, value); + return client.getBinaryBulkReply(); } /** @@ -474,9 +474,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Multi bulk reply */ public List mget(final byte[]... keys) { - checkIsInMulti(); - client.mget(keys); - return client.getBinaryMultiBulkReply(); + checkIsInMulti(); + client.mget(keys); + return client.getBinaryMultiBulkReply(); } /** @@ -492,9 +492,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * was not set */ public Long setnx(final byte[] key, final byte[] value) { - checkIsInMulti(); - client.setnx(key, value); - return client.getIntegerReply(); + checkIsInMulti(); + client.setnx(key, value); + return client.getIntegerReply(); } /** @@ -510,9 +510,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code reply */ public String setex(final byte[] key, final int seconds, final byte[] value) { - checkIsInMulti(); - client.setex(key, seconds, value); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.setex(key, seconds, value); + return client.getStatusCodeReply(); } /** @@ -536,9 +536,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code reply Basically +OK as MSET can't fail */ public String mset(final byte[]... keysvalues) { - checkIsInMulti(); - client.mset(keysvalues); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.mset(keysvalues); + return client.getStatusCodeReply(); } /** @@ -563,9 +563,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * no key was set (at least one key already existed) */ public Long msetnx(final byte[]... keysvalues) { - checkIsInMulti(); - client.msetnx(keysvalues); - return client.getIntegerReply(); + checkIsInMulti(); + client.msetnx(keysvalues); + return client.getIntegerReply(); } /** @@ -591,9 +591,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * after the increment. */ public Long decrBy(final byte[] key, final long integer) { - checkIsInMulti(); - client.decrBy(key, integer); - return client.getIntegerReply(); + checkIsInMulti(); + client.decrBy(key, integer); + return client.getIntegerReply(); } /** @@ -619,9 +619,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * after the increment. */ public Long decr(final byte[] key) { - checkIsInMulti(); - client.decr(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.decr(key); + return client.getIntegerReply(); } /** @@ -647,9 +647,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * after the increment. */ public Long incrBy(final byte[] key, final long integer) { - checkIsInMulti(); - client.incrBy(key, integer); - return client.getIntegerReply(); + checkIsInMulti(); + client.incrBy(key, integer); + return client.getIntegerReply(); } /** @@ -677,10 +677,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * after the increment. */ public Double incrByFloat(final byte[] key, final double integer) { - checkIsInMulti(); - client.incrByFloat(key, integer); - String dval = client.getBulkReply(); - return (dval != null ? new Double(dval) : null); + checkIsInMulti(); + client.incrByFloat(key, integer); + String dval = client.getBulkReply(); + return (dval != null ? new Double(dval) : null); } /** @@ -706,9 +706,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * after the increment. */ public Long incr(final byte[] key) { - checkIsInMulti(); - client.incr(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.incr(key); + return client.getIntegerReply(); } /** @@ -728,9 +728,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * the append operation. */ public Long append(final byte[] key, final byte[] value) { - checkIsInMulti(); - client.append(key, value); - return client.getIntegerReply(); + checkIsInMulti(); + client.append(key, value); + return client.getIntegerReply(); } /** @@ -752,9 +752,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Bulk reply */ public byte[] substr(final byte[] key, final int start, final int end) { - checkIsInMulti(); - client.substr(key, start, end); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.substr(key, start, end); + return client.getBinaryBulkReply(); } /** @@ -773,9 +773,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * 1 is returned. */ public Long hset(final byte[] key, final byte[] field, final byte[] value) { - checkIsInMulti(); - client.hset(key, field, value); - return client.getIntegerReply(); + checkIsInMulti(); + client.hset(key, field, value); + return client.getIntegerReply(); } /** @@ -792,9 +792,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Bulk reply */ public byte[] hget(final byte[] key, final byte[] field) { - checkIsInMulti(); - client.hget(key, field); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.hget(key, field); + return client.getBinaryBulkReply(); } /** @@ -809,9 +809,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * field is created 1 is returned. */ public Long hsetnx(final byte[] key, final byte[] field, final byte[] value) { - checkIsInMulti(); - client.hsetnx(key, field, value); - return client.getIntegerReply(); + checkIsInMulti(); + client.hsetnx(key, field, value); + return client.getIntegerReply(); } /** @@ -827,9 +827,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Always OK because HMSET can't fail */ public String hmset(final byte[] key, final Map hash) { - checkIsInMulti(); - client.hmset(key, hash); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.hmset(key, hash); + return client.getStatusCodeReply(); } /** @@ -846,9 +846,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * with the specified fields, in the same order of the request. */ public List hmget(final byte[] key, final byte[]... fields) { - checkIsInMulti(); - client.hmget(key, fields); - return client.getBinaryMultiBulkReply(); + checkIsInMulti(); + client.hmget(key, fields); + return client.getBinaryMultiBulkReply(); } /** @@ -870,9 +870,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * operation. */ public Long hincrBy(final byte[] key, final byte[] field, final long value) { - checkIsInMulti(); - client.hincrBy(key, field, value); - return client.getIntegerReply(); + checkIsInMulti(); + client.hincrBy(key, field, value); + return client.getIntegerReply(); } /** @@ -895,11 +895,11 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * after the increment operation. */ public Double hincrByFloat(final byte[] key, final byte[] field, - final double value) { - checkIsInMulti(); - client.hincrByFloat(key, field, value); - final String dval = client.getBulkReply(); - return (dval != null ? new Double(dval) : null); + final double value) { + checkIsInMulti(); + client.hincrByFloat(key, field, value); + final String dval = client.getBulkReply(); + return (dval != null ? new Double(dval) : null); } /** @@ -913,9 +913,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * Return 0 if the key is not found or the field is not present. */ public Boolean hexists(final byte[] key, final byte[] field) { - checkIsInMulti(); - client.hexists(key, field); - return client.getIntegerReply() == 1; + checkIsInMulti(); + client.hexists(key, field); + return client.getIntegerReply() == 1; } /** @@ -929,9 +929,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * returned, otherwise 0 is returned and no operation is performed. */ public Long hdel(final byte[] key, final byte[]... fields) { - checkIsInMulti(); - client.hdel(key, fields); - return client.getIntegerReply(); + checkIsInMulti(); + client.hdel(key, fields); + return client.getIntegerReply(); } /** @@ -945,9 +945,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * an empty hash. */ public Long hlen(final byte[] key) { - checkIsInMulti(); - client.hlen(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.hlen(key); + return client.getIntegerReply(); } /** @@ -959,10 +959,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return All the fields names contained into a hash. */ public Set hkeys(final byte[] key) { - checkIsInMulti(); - client.hkeys(key); - final List lresult = client.getBinaryMultiBulkReply(); - return new HashSet(lresult); + checkIsInMulti(); + client.hkeys(key); + final List lresult = client.getBinaryMultiBulkReply(); + return new HashSet(lresult); } /** @@ -974,9 +974,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return All the fields values contained into a hash. */ public List hvals(final byte[] key) { - checkIsInMulti(); - client.hvals(key); - return client.getBinaryMultiBulkReply(); + checkIsInMulti(); + client.hvals(key); + return client.getBinaryMultiBulkReply(); } /** @@ -988,16 +988,16 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return All the fields and values contained into a hash. */ public Map hgetAll(final byte[] key) { - checkIsInMulti(); - client.hgetAll(key); - final List flatHash = client.getBinaryMultiBulkReply(); - final Map hash = new JedisByteHashMap(); - final Iterator iterator = flatHash.iterator(); - while (iterator.hasNext()) { - hash.put(iterator.next(), iterator.next()); - } + checkIsInMulti(); + client.hgetAll(key); + final List flatHash = client.getBinaryMultiBulkReply(); + final Map hash = new JedisByteHashMap(); + final Iterator iterator = flatHash.iterator(); + while (iterator.hasNext()) { + hash.put(iterator.next(), iterator.next()); + } - return hash; + return hash; } /** @@ -1016,9 +1016,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * list after the push operation. */ public Long rpush(final byte[] key, final byte[]... strings) { - checkIsInMulti(); - client.rpush(key, strings); - return client.getIntegerReply(); + checkIsInMulti(); + client.rpush(key, strings); + return client.getIntegerReply(); } /** @@ -1037,9 +1037,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * list after the push operation. */ public Long lpush(final byte[] key, final byte[]... strings) { - checkIsInMulti(); - client.lpush(key, strings); - return client.getIntegerReply(); + checkIsInMulti(); + client.lpush(key, strings); + return client.getIntegerReply(); } /** @@ -1053,9 +1053,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return The length of the list. */ public Long llen(final byte[] key) { - checkIsInMulti(); - client.llen(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.llen(key); + return client.getIntegerReply(); } /** @@ -1097,10 +1097,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * specified range. */ public List lrange(final byte[] key, final long start, - final long end) { - checkIsInMulti(); - client.lrange(key, start, end); - return client.getBinaryMultiBulkReply(); + final long end) { + checkIsInMulti(); + client.lrange(key, start, end); + return client.getBinaryMultiBulkReply(); } /** @@ -1138,9 +1138,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code reply */ public String ltrim(final byte[] key, final long start, final long end) { - checkIsInMulti(); - client.ltrim(key, start, end); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.ltrim(key, start, end); + return client.getStatusCodeReply(); } /** @@ -1162,9 +1162,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Bulk reply, specifically the requested element */ public byte[] lindex(final byte[] key, final long index) { - checkIsInMulti(); - client.lindex(key, index); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.lindex(key, index); + return client.getBinaryBulkReply(); } /** @@ -1189,9 +1189,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code reply */ public String lset(final byte[] key, final long index, final byte[] value) { - checkIsInMulti(); - client.lset(key, index, value); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.lset(key, index, value); + return client.getStatusCodeReply(); } /** @@ -1214,9 +1214,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * the operation succeeded */ public Long lrem(final byte[] key, final long count, final byte[] value) { - checkIsInMulti(); - client.lrem(key, count, value); - return client.getIntegerReply(); + checkIsInMulti(); + client.lrem(key, count, value); + return client.getIntegerReply(); } /** @@ -1233,9 +1233,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Bulk reply */ public byte[] lpop(final byte[] key) { - checkIsInMulti(); - client.lpop(key); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.lpop(key); + return client.getBinaryBulkReply(); } /** @@ -1252,9 +1252,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Bulk reply */ public byte[] rpop(final byte[] key) { - checkIsInMulti(); - client.rpop(key); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.rpop(key); + return client.getBinaryBulkReply(); } /** @@ -1276,9 +1276,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Bulk reply */ public byte[] rpoplpush(final byte[] srckey, final byte[] dstkey) { - checkIsInMulti(); - client.rpoplpush(srckey, dstkey); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.rpoplpush(srckey, dstkey); + return client.getBinaryBulkReply(); } /** @@ -1295,9 +1295,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * the element was already a member of the set */ public Long sadd(final byte[] key, final byte[]... members) { - checkIsInMulti(); - client.sadd(key, members); - return client.getIntegerReply(); + checkIsInMulti(); + client.sadd(key, members); + return client.getIntegerReply(); } /** @@ -1310,10 +1310,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Multi bulk reply */ public Set smembers(final byte[] key) { - checkIsInMulti(); - client.smembers(key); - final List members = client.getBinaryMultiBulkReply(); - return new HashSet(members); + checkIsInMulti(); + client.smembers(key); + final List members = client.getBinaryMultiBulkReply(); + return new HashSet(members); } /** @@ -1329,9 +1329,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * if the new element was not a member of the set */ public Long srem(final byte[] key, final byte[]... member) { - checkIsInMulti(); - client.srem(key, member); - return client.getIntegerReply(); + checkIsInMulti(); + client.srem(key, member); + return client.getIntegerReply(); } /** @@ -1347,9 +1347,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Bulk reply */ public byte[] spop(final byte[] key) { - checkIsInMulti(); - client.spop(key); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.spop(key); + return client.getBinaryBulkReply(); } /** @@ -1376,10 +1376,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * performed */ public Long smove(final byte[] srckey, final byte[] dstkey, - final byte[] member) { - checkIsInMulti(); - client.smove(srckey, dstkey, member); - return client.getIntegerReply(); + final byte[] member) { + checkIsInMulti(); + client.smove(srckey, dstkey, member); + return client.getIntegerReply(); } /** @@ -1391,9 +1391,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * of the set as an integer. */ public Long scard(final byte[] key) { - checkIsInMulti(); - client.scard(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.scard(key); + return client.getIntegerReply(); } /** @@ -1409,9 +1409,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * does not exist */ public Boolean sismember(final byte[] key, final byte[] member) { - checkIsInMulti(); - client.sismember(key, member); - return client.getIntegerReply() == 1; + checkIsInMulti(); + client.sismember(key, member); + return client.getIntegerReply() == 1; } /** @@ -1434,10 +1434,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Multi bulk reply, specifically the list of common elements. */ public Set sinter(final byte[]... keys) { - checkIsInMulti(); - client.sinter(keys); - final List members = client.getBinaryMultiBulkReply(); - return new HashSet(members); + checkIsInMulti(); + client.sinter(keys); + final List members = client.getBinaryMultiBulkReply(); + return new HashSet(members); } /** @@ -1452,9 +1452,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code reply */ public Long sinterstore(final byte[] dstkey, final byte[]... keys) { - checkIsInMulti(); - client.sinterstore(dstkey, keys); - return client.getIntegerReply(); + checkIsInMulti(); + client.sinterstore(dstkey, keys); + return client.getIntegerReply(); } /** @@ -1474,10 +1474,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Multi bulk reply, specifically the list of common elements. */ public Set sunion(final byte[]... keys) { - checkIsInMulti(); - client.sunion(keys); - final List members = client.getBinaryMultiBulkReply(); - return new HashSet(members); + checkIsInMulti(); + client.sunion(keys); + final List members = client.getBinaryMultiBulkReply(); + return new HashSet(members); } /** @@ -1493,9 +1493,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code reply */ public Long sunionstore(final byte[] dstkey, final byte[]... keys) { - checkIsInMulti(); - client.sunionstore(dstkey, keys); - return client.getIntegerReply(); + checkIsInMulti(); + client.sunionstore(dstkey, keys); + return client.getIntegerReply(); } /** @@ -1522,10 +1522,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * the first set provided and all the successive sets. */ public Set sdiff(final byte[]... keys) { - checkIsInMulti(); - client.sdiff(keys); - final List members = client.getBinaryMultiBulkReply(); - return new HashSet(members); + checkIsInMulti(); + client.sdiff(keys); + final List members = client.getBinaryMultiBulkReply(); + return new HashSet(members); } /** @@ -1537,9 +1537,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code reply */ public Long sdiffstore(final byte[] dstkey, final byte[]... keys) { - checkIsInMulti(); - client.sdiffstore(dstkey, keys); - return client.getIntegerReply(); + checkIsInMulti(); + client.sdiffstore(dstkey, keys); + return client.getIntegerReply(); } /** @@ -1555,15 +1555,15 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Bulk reply */ public byte[] srandmember(final byte[] key) { - checkIsInMulti(); - client.srandmember(key); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.srandmember(key); + return client.getBinaryBulkReply(); } public List srandmember(final byte[] key, final int count) { - checkIsInMulti(); - client.srandmember(key, count); - return client.getBinaryMultiBulkReply(); + checkIsInMulti(); + client.srandmember(key, count); + return client.getBinaryMultiBulkReply(); } /** @@ -1588,22 +1588,22 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * was updated */ public Long zadd(final byte[] key, final double score, final byte[] member) { - checkIsInMulti(); - client.zadd(key, score, member); - return client.getIntegerReply(); + checkIsInMulti(); + client.zadd(key, score, member); + return client.getIntegerReply(); } public Long zadd(final byte[] key, final Map scoreMembers) { - checkIsInMulti(); - client.zaddBinary(key, scoreMembers); - return client.getIntegerReply(); + checkIsInMulti(); + client.zaddBinary(key, scoreMembers); + return client.getIntegerReply(); } public Set zrange(final byte[] key, final long start, final long end) { - checkIsInMulti(); - client.zrange(key, start, end); - final List members = client.getBinaryMultiBulkReply(); - return new LinkedHashSet(members); + checkIsInMulti(); + client.zrange(key, start, end); + final List members = client.getBinaryMultiBulkReply(); + return new LinkedHashSet(members); } /** @@ -1622,9 +1622,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * if the new element was not a member of the set */ public Long zrem(final byte[] key, final byte[]... members) { - checkIsInMulti(); - client.zrem(key, members); - return client.getIntegerReply(); + checkIsInMulti(); + client.zrem(key, members); + return client.getIntegerReply(); } /** @@ -1652,11 +1652,11 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return The new score */ public Double zincrby(final byte[] key, final double score, - final byte[] member) { - checkIsInMulti(); - client.zincrby(key, score, member); - String newscore = client.getBulkReply(); - return Double.valueOf(newscore); + final byte[] member) { + checkIsInMulti(); + client.zincrby(key, score, member); + String newscore = client.getBulkReply(); + return Double.valueOf(newscore); } /** @@ -1680,9 +1680,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * reply if there is no such element. */ public Long zrank(final byte[] key, final byte[] member) { - checkIsInMulti(); - client.zrank(key, member); - return client.getIntegerReply(); + checkIsInMulti(); + client.zrank(key, member); + return client.getIntegerReply(); } /** @@ -1706,31 +1706,31 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * reply if there is no such element. */ public Long zrevrank(final byte[] key, final byte[] member) { - checkIsInMulti(); - client.zrevrank(key, member); - return client.getIntegerReply(); + checkIsInMulti(); + client.zrevrank(key, member); + return client.getIntegerReply(); } public Set zrevrange(final byte[] key, final long start, - final long end) { - checkIsInMulti(); - client.zrevrange(key, start, end); - final List members = client.getBinaryMultiBulkReply(); - return new LinkedHashSet(members); + final long end) { + checkIsInMulti(); + client.zrevrange(key, start, end); + final List members = client.getBinaryMultiBulkReply(); + return new LinkedHashSet(members); } public Set zrangeWithScores(final byte[] key, final long start, - final long end) { - checkIsInMulti(); - client.zrangeWithScores(key, start, end); - return getBinaryTupledSet(); + final long end) { + checkIsInMulti(); + client.zrangeWithScores(key, start, end); + return getBinaryTupledSet(); } public Set zrevrangeWithScores(final byte[] key, final long start, - final long end) { - checkIsInMulti(); - client.zrevrangeWithScores(key, start, end); - return getBinaryTupledSet(); + final long end) { + checkIsInMulti(); + client.zrevrangeWithScores(key, start, end); + return getBinaryTupledSet(); } /** @@ -1743,9 +1743,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return the cardinality (number of elements) of the set as an integer. */ public Long zcard(final byte[] key) { - checkIsInMulti(); - client.zcard(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.zcard(key); + return client.getIntegerReply(); } /** @@ -1760,68 +1760,68 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return the score */ public Double zscore(final byte[] key, final byte[] member) { - checkIsInMulti(); - client.zscore(key, member); - final String score = client.getBulkReply(); - return (score != null ? new Double(score) : null); + checkIsInMulti(); + client.zscore(key, member); + final String score = client.getBulkReply(); + return (score != null ? new Double(score) : null); } public Transaction multi() { - client.multi(); - client.getOne(); // expected OK - transaction = new Transaction(client); - return transaction; + client.multi(); + client.getOne(); // expected OK + transaction = new Transaction(client); + return transaction; } protected void checkIsInMulti() { - if (client.isInMulti()) { - throw new JedisDataException( - "Cannot use Jedis when in Multi. Please use JedisTransaction instead."); - } + if (client.isInMulti()) { + throw new JedisDataException( + "Cannot use Jedis when in Multi. Please use JedisTransaction instead."); + } } public void connect() { - client.connect(); + client.connect(); } public void disconnect() { - client.disconnect(); + client.disconnect(); } public void resetState() { - if (client.isConnected()) { - if (transaction != null) { - transaction.clear(); - } + if (client.isConnected()) { + if (transaction != null) { + transaction.clear(); + } - if (pipeline != null) { - pipeline.clear(); - } + if (pipeline != null) { + pipeline.clear(); + } - if (client.isInWatch()) { - unwatch(); - } + if (client.isInWatch()) { + unwatch(); + } - client.resetState(); - } + client.resetState(); + } - transaction = null; - pipeline = null; + transaction = null; + pipeline = null; } public String watch(final byte[]... keys) { - client.watch(keys); - return client.getStatusCodeReply(); + client.watch(keys); + return client.getStatusCodeReply(); } public String unwatch() { - client.unwatch(); - return client.getStatusCodeReply(); + client.unwatch(); + return client.getStatusCodeReply(); } @Override public void close() { - client.close(); + client.close(); } /** @@ -1842,9 +1842,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * smallest to the biggest number. */ public List sort(final byte[] key) { - checkIsInMulti(); - client.sort(key); - return client.getBinaryMultiBulkReply(); + checkIsInMulti(); + client.sort(key); + return client.getBinaryMultiBulkReply(); } /** @@ -1924,10 +1924,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return a list of sorted elements. */ public List sort(final byte[] key, - final SortingParams sortingParameters) { - checkIsInMulti(); - client.sort(key, sortingParameters); - return client.getBinaryMultiBulkReply(); + final SortingParams sortingParameters) { + checkIsInMulti(); + client.sort(key, sortingParameters); + return client.getBinaryMultiBulkReply(); } /** @@ -2003,17 +2003,17 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * programming language used. */ public List blpop(final int timeout, final byte[]... keys) { - return blpop(getArgsAddTimeout(timeout, keys)); + return blpop(getArgsAddTimeout(timeout, keys)); } private byte[][] getArgsAddTimeout (int timeout, byte[][] keys) { - int size = keys.length; - final byte[][] args = new byte[size + 1][]; - for (int at = 0; at != size; ++at) { - args[at] = keys[at]; - } - args[size] = Protocol.toByteArray(timeout); - return args; + int size = keys.length; + final byte[][] args = new byte[size + 1][]; + for (int at = 0; at != size; ++at) { + args[at] = keys[at]; + } + args[size] = Protocol.toByteArray(timeout); + return args; } /** @@ -2030,10 +2030,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return The number of elements of the list at dstkey. */ public Long sort(final byte[] key, final SortingParams sortingParameters, - final byte[] dstkey) { - checkIsInMulti(); - client.sort(key, sortingParameters, dstkey); - return client.getIntegerReply(); + final byte[] dstkey) { + checkIsInMulti(); + client.sort(key, sortingParameters, dstkey); + return client.getIntegerReply(); } /** @@ -2053,9 +2053,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return The number of elements of the list at dstkey. */ public Long sort(final byte[] key, final byte[] dstkey) { - checkIsInMulti(); - client.sort(key, dstkey); - return client.getIntegerReply(); + checkIsInMulti(); + client.sort(key, dstkey); + return client.getIntegerReply(); } /** @@ -2131,7 +2131,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * programming language used. */ public List brpop(final int timeout, final byte[]... keys) { - return brpop(getArgsAddTimeout(timeout, keys)); + return brpop(getArgsAddTimeout(timeout, keys)); } @@ -2140,7 +2140,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, */ @Deprecated public List blpop(byte[] arg) { - return blpop(new byte[][]{arg}); + return blpop(new byte[][]{arg}); } /** @@ -2148,29 +2148,29 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, */ @Deprecated public List brpop(byte[] arg) { - return brpop(new byte[][]{arg}); + return brpop(new byte[][]{arg}); } public List blpop(byte[]... args) { - checkIsInMulti(); - client.blpop(args); - client.setTimeoutInfinite(); - try { - return client.getBinaryMultiBulkReply(); - } finally { - client.rollbackTimeout(); - } + checkIsInMulti(); + client.blpop(args); + client.setTimeoutInfinite(); + try { + return client.getBinaryMultiBulkReply(); + } finally { + client.rollbackTimeout(); + } } public List brpop(byte[]... args) { - checkIsInMulti(); - client.brpop(args); - client.setTimeoutInfinite(); - try { - return client.getBinaryMultiBulkReply(); - } finally { - client.rollbackTimeout(); - } + checkIsInMulti(); + client.brpop(args); + client.setTimeoutInfinite(); + try { + return client.getBinaryMultiBulkReply(); + } finally { + client.rollbackTimeout(); + } } /** @@ -2189,25 +2189,25 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code reply */ public String auth(final String password) { - checkIsInMulti(); - client.auth(password); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.auth(password); + return client.getStatusCodeReply(); } public Pipeline pipelined() { - pipeline = new Pipeline(); - pipeline.setClient(client); - return pipeline; + pipeline = new Pipeline(); + pipeline.setClient(client); + return pipeline; } public Long zcount(final byte[] key, final double min, final double max) { - return zcount(key, toByteArray(min), toByteArray(max)); + return zcount(key, toByteArray(min), toByteArray(max)); } public Long zcount(final byte[] key, final byte[] min, final byte[] max) { - checkIsInMulti(); - client.zcount(key, min, max); - return client.getIntegerReply(); + checkIsInMulti(); + client.zcount(key, min, max); + return client.getIntegerReply(); } /** @@ -2267,15 +2267,15 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * score range. */ public Set zrangeByScore(final byte[] key, final double min, - final double max) { - return zrangeByScore(key, toByteArray(min), toByteArray(max)); + final double max) { + return zrangeByScore(key, toByteArray(min), toByteArray(max)); } public Set zrangeByScore(final byte[] key, final byte[] min, - final byte[] max) { - checkIsInMulti(); - client.zrangeByScore(key, min, max); - return new LinkedHashSet(client.getBinaryMultiBulkReply()); + final byte[] max) { + checkIsInMulti(); + client.zrangeByScore(key, min, max); + return new LinkedHashSet(client.getBinaryMultiBulkReply()); } /** @@ -2335,16 +2335,16 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * score range. */ public Set zrangeByScore(final byte[] key, final double min, - final double max, final int offset, final int count) { - return zrangeByScore(key, toByteArray(min), toByteArray(max), offset, - count); + final double max, final int offset, final int count) { + return zrangeByScore(key, toByteArray(min), toByteArray(max), offset, + count); } public Set zrangeByScore(final byte[] key, final byte[] min, - final byte[] max, final int offset, final int count) { - checkIsInMulti(); - client.zrangeByScore(key, min, max, offset, count); - return new LinkedHashSet(client.getBinaryMultiBulkReply()); + final byte[] max, final int offset, final int count) { + checkIsInMulti(); + client.zrangeByScore(key, min, max, offset, count); + return new LinkedHashSet(client.getBinaryMultiBulkReply()); } /** @@ -2404,15 +2404,15 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * score range. */ public Set zrangeByScoreWithScores(final byte[] key, - final double min, final double max) { - return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max)); + final double min, final double max) { + return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max)); } public Set zrangeByScoreWithScores(final byte[] key, - final byte[] min, final byte[] max) { - checkIsInMulti(); - client.zrangeByScoreWithScores(key, min, max); - return getBinaryTupledSet(); + final byte[] min, final byte[] max) { + checkIsInMulti(); + client.zrangeByScoreWithScores(key, min, max); + return getBinaryTupledSet(); } /** @@ -2472,83 +2472,83 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * score range. */ public Set zrangeByScoreWithScores(final byte[] key, - final double min, final double max, final int offset, - final int count) { - return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), - offset, count); + final double min, final double max, final int offset, + final int count) { + return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max), + offset, count); } public Set zrangeByScoreWithScores(final byte[] key, - final byte[] min, final byte[] max, final int offset, - final int count) { - checkIsInMulti(); - client.zrangeByScoreWithScores(key, min, max, offset, count); - return getBinaryTupledSet(); + final byte[] min, final byte[] max, final int offset, + final int count) { + checkIsInMulti(); + client.zrangeByScoreWithScores(key, min, max, offset, count); + return getBinaryTupledSet(); } private Set getBinaryTupledSet() { - checkIsInMulti(); - List membersWithScores = client.getBinaryMultiBulkReply(); - Set set = new LinkedHashSet(); - Iterator iterator = membersWithScores.iterator(); - while (iterator.hasNext()) { - set.add(new Tuple(iterator.next(), Double.valueOf(SafeEncoder - .encode(iterator.next())))); - } - return set; + checkIsInMulti(); + List membersWithScores = client.getBinaryMultiBulkReply(); + Set set = new LinkedHashSet(); + Iterator iterator = membersWithScores.iterator(); + while (iterator.hasNext()) { + set.add(new Tuple(iterator.next(), Double.valueOf(SafeEncoder + .encode(iterator.next())))); + } + return set; } public Set zrevrangeByScore(final byte[] key, final double max, - final double min) { - return zrevrangeByScore(key, toByteArray(max), toByteArray(min)); + final double min) { + return zrevrangeByScore(key, toByteArray(max), toByteArray(min)); } public Set zrevrangeByScore(final byte[] key, final byte[] max, - final byte[] min) { - checkIsInMulti(); - client.zrevrangeByScore(key, max, min); - return new LinkedHashSet(client.getBinaryMultiBulkReply()); + final byte[] min) { + checkIsInMulti(); + client.zrevrangeByScore(key, max, min); + return new LinkedHashSet(client.getBinaryMultiBulkReply()); } public Set zrevrangeByScore(final byte[] key, final double max, - final double min, final int offset, final int count) { - return zrevrangeByScore(key, toByteArray(max), toByteArray(min), - offset, count); + final double min, final int offset, final int count) { + return zrevrangeByScore(key, toByteArray(max), toByteArray(min), + offset, count); } public Set zrevrangeByScore(final byte[] key, final byte[] max, - final byte[] min, final int offset, final int count) { - checkIsInMulti(); - client.zrevrangeByScore(key, max, min, offset, count); - return new LinkedHashSet(client.getBinaryMultiBulkReply()); + final byte[] min, final int offset, final int count) { + checkIsInMulti(); + client.zrevrangeByScore(key, max, min, offset, count); + return new LinkedHashSet(client.getBinaryMultiBulkReply()); } public Set zrevrangeByScoreWithScores(final byte[] key, - final double max, final double min) { - return zrevrangeByScoreWithScores(key, toByteArray(max), - toByteArray(min)); + final double max, final double min) { + return zrevrangeByScoreWithScores(key, toByteArray(max), + toByteArray(min)); } public Set zrevrangeByScoreWithScores(final byte[] key, - final double max, final double min, final int offset, - final int count) { - return zrevrangeByScoreWithScores(key, toByteArray(max), - toByteArray(min), offset, count); + final double max, final double min, final int offset, + final int count) { + return zrevrangeByScoreWithScores(key, toByteArray(max), + toByteArray(min), offset, count); } public Set zrevrangeByScoreWithScores(final byte[] key, - final byte[] max, final byte[] min) { - checkIsInMulti(); - client.zrevrangeByScoreWithScores(key, max, min); - return getBinaryTupledSet(); + final byte[] max, final byte[] min) { + checkIsInMulti(); + client.zrevrangeByScoreWithScores(key, max, min); + return getBinaryTupledSet(); } public Set zrevrangeByScoreWithScores(final byte[] key, - final byte[] max, final byte[] min, final int offset, - final int count) { - checkIsInMulti(); - client.zrevrangeByScoreWithScores(key, max, min, offset, count); - return getBinaryTupledSet(); + final byte[] max, final byte[] min, final int offset, + final int count) { + checkIsInMulti(); + client.zrevrangeByScoreWithScores(key, max, min, offset, count); + return getBinaryTupledSet(); } /** @@ -2565,10 +2565,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * */ public Long zremrangeByRank(final byte[] key, final long start, - final long end) { - checkIsInMulti(); - client.zremrangeByRank(key, start, end); - return client.getIntegerReply(); + final long end) { + checkIsInMulti(); + client.zremrangeByRank(key, start, end); + return client.getIntegerReply(); } /** @@ -2586,15 +2586,15 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Integer reply, specifically the number of elements removed. */ public Long zremrangeByScore(final byte[] key, final double start, - final double end) { - return zremrangeByScore(key, toByteArray(start), toByteArray(end)); + final double end) { + return zremrangeByScore(key, toByteArray(start), toByteArray(end)); } public Long zremrangeByScore(final byte[] key, final byte[] start, - final byte[] end) { - checkIsInMulti(); - client.zremrangeByScore(key, start, end); - return client.getIntegerReply(); + final byte[] end) { + checkIsInMulti(); + client.zremrangeByScore(key, start, end); + return client.getIntegerReply(); } /** @@ -2636,9 +2636,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * set at dstkey */ public Long zunionstore(final byte[] dstkey, final byte[]... sets) { - checkIsInMulti(); - client.zunionstore(dstkey, sets); - return client.getIntegerReply(); + checkIsInMulti(); + client.zunionstore(dstkey, sets); + return client.getIntegerReply(); } /** @@ -2681,10 +2681,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * set at dstkey */ public Long zunionstore(final byte[] dstkey, final ZParams params, - final byte[]... sets) { - checkIsInMulti(); - client.zunionstore(dstkey, params, sets); - return client.getIntegerReply(); + final byte[]... sets) { + checkIsInMulti(); + client.zunionstore(dstkey, params, sets); + return client.getIntegerReply(); } /** @@ -2726,9 +2726,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * set at dstkey */ public Long zinterstore(final byte[] dstkey, final byte[]... sets) { - checkIsInMulti(); - client.zinterstore(dstkey, sets); - return client.getIntegerReply(); + checkIsInMulti(); + client.zinterstore(dstkey, sets); + return client.getIntegerReply(); } /** @@ -2771,56 +2771,56 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * set at dstkey */ public Long zinterstore(final byte[] dstkey, final ZParams params, - final byte[]... sets) { - checkIsInMulti(); - client.zinterstore(dstkey, params, sets); - return client.getIntegerReply(); + final byte[]... sets) { + checkIsInMulti(); + client.zinterstore(dstkey, params, sets); + return client.getIntegerReply(); } @Override public Long zlexcount(final byte[] key, final byte[] min, final byte[] max) { - checkIsInMulti(); - client.zlexcount(key, min, max); - return client.getIntegerReply(); + checkIsInMulti(); + client.zlexcount(key, min, max); + return client.getIntegerReply(); } @Override public Set zrangeByLex(final byte[] key, final byte[] min, - final byte[] max) { - checkIsInMulti(); - client.zrangeByLex(key, min, max); - return new LinkedHashSet(client.getBinaryMultiBulkReply()); + final byte[] max) { + checkIsInMulti(); + client.zrangeByLex(key, min, max); + return new LinkedHashSet(client.getBinaryMultiBulkReply()); } @Override public Set 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(client.getBinaryMultiBulkReply()); + final byte[] max, final int offset, final int count) { + checkIsInMulti(); + client.zrangeByLex(key, min, max, offset, count); + return new LinkedHashSet(client.getBinaryMultiBulkReply()); } @Override public Set zrevrangeByLex(byte[] key, byte[] max, byte[] min) { - checkIsInMulti(); - client.zrevrangeByLex(key, max, min); - return new LinkedHashSet(client.getBinaryMultiBulkReply()); + checkIsInMulti(); + client.zrevrangeByLex(key, max, min); + return new LinkedHashSet(client.getBinaryMultiBulkReply()); } @Override public Set zrevrangeByLex(byte[] key, byte[] max, byte[] min, - int offset, int count) { - checkIsInMulti(); - client.zrevrangeByLex(key, max, min, offset, count); - return new LinkedHashSet(client.getBinaryMultiBulkReply()); + int offset, int count) { + checkIsInMulti(); + client.zrevrangeByLex(key, max, min, offset, count); + return new LinkedHashSet(client.getBinaryMultiBulkReply()); } @Override public Long zremrangeByLex(final byte[] key, final byte[] min, - final byte[] max) { - checkIsInMulti(); - client.zremrangeByLex(key, min, max); - return client.getIntegerReply(); + final byte[] max) { + checkIsInMulti(); + client.zremrangeByLex(key, min, max); + return client.getIntegerReply(); } /** @@ -2840,8 +2840,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code reply */ public String save() { - client.save(); - return client.getStatusCodeReply(); + client.save(); + return client.getStatusCodeReply(); } /** @@ -2855,8 +2855,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code reply */ public String bgsave() { - client.bgsave(); - return client.getStatusCodeReply(); + client.bgsave(); + return client.getStatusCodeReply(); } /** @@ -2878,8 +2878,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code reply */ public String bgrewriteaof() { - client.bgrewriteaof(); - return client.getStatusCodeReply(); + client.bgrewriteaof(); + return client.getStatusCodeReply(); } /** @@ -2894,8 +2894,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Integer reply, specifically an UNIX time stamp. */ public Long lastsave() { - client.lastsave(); - return client.getIntegerReply(); + client.lastsave(); + return client.getIntegerReply(); } /** @@ -2911,14 +2911,14 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * the server quits and the connection is closed. */ public String shutdown() { - client.shutdown(); - String status; - try { - status = client.getStatusCodeReply(); - } catch (JedisException ex) { - status = null; - } - return status; + client.shutdown(); + String status; + try { + status = client.getStatusCodeReply(); + } catch (JedisException ex) { + status = null; + } + return status; } /** @@ -2962,13 +2962,13 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Bulk reply */ public String info() { - client.info(); - return client.getBulkReply(); + client.info(); + return client.getBulkReply(); } public String info(final String section) { - client.info(section); - return client.getBulkReply(); + client.info(section); + return client.getBulkReply(); } /** @@ -2982,9 +2982,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @param jedisMonitor */ public void monitor(final JedisMonitor jedisMonitor) { - client.monitor(); - client.getStatusCodeReply(); - jedisMonitor.proceed(client); + client.monitor(); + client.getStatusCodeReply(); + jedisMonitor.proceed(client); } /** @@ -3013,13 +3013,13 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code reply */ public String slaveof(final String host, final int port) { - client.slaveof(host, port); - return client.getStatusCodeReply(); + client.slaveof(host, port); + return client.getStatusCodeReply(); } public String slaveofNoOne() { - client.slaveofNoOne(); - return client.getStatusCodeReply(); + client.slaveofNoOne(); + return client.getStatusCodeReply(); } /** @@ -3059,8 +3059,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Bulk reply. */ public List configGet(final byte[] pattern) { - client.configGet(pattern); - return client.getBinaryMultiBulkReply(); + client.configGet(pattern); + return client.getBinaryMultiBulkReply(); } /** @@ -3069,8 +3069,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return */ public String configResetStat() { - client.configResetStat(); - return client.getStatusCodeReply(); + client.configResetStat(); + return client.getStatusCodeReply(); } /** @@ -3108,26 +3108,26 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Status code reply */ public byte[] configSet(final byte[] parameter, final byte[] value) { - client.configSet(parameter, value); - return client.getBinaryBulkReply(); + client.configSet(parameter, value); + return client.getBinaryBulkReply(); } public boolean isConnected() { - return client.isConnected(); + return client.isConnected(); } public Long strlen(final byte[] key) { - client.strlen(key); - return client.getIntegerReply(); + client.strlen(key); + return client.getIntegerReply(); } public void sync() { - client.sync(); + client.sync(); } public Long lpushx(final byte[] key, final byte[]... string) { - client.lpushx(key, string); - return client.getIntegerReply(); + client.lpushx(key, string); + return client.getIntegerReply(); } /** @@ -3141,33 +3141,33 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * key is not persist (only happens when key not set). */ public Long persist(final byte[] key) { - client.persist(key); - return client.getIntegerReply(); + client.persist(key); + return client.getIntegerReply(); } public Long rpushx(final byte[] key, final byte[]... string) { - client.rpushx(key, string); - return client.getIntegerReply(); + client.rpushx(key, string); + return client.getIntegerReply(); } public byte[] echo(final byte[] string) { - client.echo(string); - return client.getBinaryBulkReply(); + client.echo(string); + return client.getBinaryBulkReply(); } public Long linsert(final byte[] key, final LIST_POSITION where, - final byte[] pivot, final byte[] value) { - client.linsert(key, where, pivot, value); - return client.getIntegerReply(); + final byte[] pivot, final byte[] value) { + client.linsert(key, where, pivot, value); + return client.getIntegerReply(); } public String debug(final DebugParams params) { - client.debug(params); - return client.getStatusCodeReply(); + client.debug(params); + return client.getStatusCodeReply(); } public Client getClient() { - return client; + return client; } /** @@ -3180,13 +3180,13 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return the element */ public byte[] brpoplpush(byte[] source, byte[] destination, int timeout) { - client.brpoplpush(source, destination, timeout); - client.setTimeoutInfinite(); - try { - return client.getBinaryBulkReply(); - } finally { - client.rollbackTimeout(); - } + client.brpoplpush(source, destination, timeout); + client.setTimeoutInfinite(); + try { + return client.getBinaryBulkReply(); + } finally { + client.rollbackTimeout(); + } } /** @@ -3198,13 +3198,13 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return */ public Boolean setbit(byte[] key, long offset, boolean value) { - client.setbit(key, offset, value); - return client.getIntegerReply() == 1; + client.setbit(key, offset, value); + return client.getIntegerReply() == 1; } public Boolean setbit(byte[] key, long offset, byte[] value) { - client.setbit(key, offset, value); - return client.getIntegerReply() == 1; + client.setbit(key, offset, value); + return client.getIntegerReply() == 1; } /** @@ -3215,55 +3215,55 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return */ public Boolean getbit(byte[] key, long offset) { - client.getbit(key, offset); - return client.getIntegerReply() == 1; + client.getbit(key, offset); + return client.getIntegerReply() == 1; } public Long bitpos(final byte[] key, final boolean value) { - return bitpos(key, value, new BitPosParams()); + return bitpos(key, value, new BitPosParams()); } public Long bitpos(final byte[] key, final boolean value, - final BitPosParams params) { - client.bitpos(key, value, params); - return client.getIntegerReply(); + final BitPosParams params) { + client.bitpos(key, value, params); + return client.getIntegerReply(); } public Long setrange(byte[] key, long offset, byte[] value) { - client.setrange(key, offset, value); - return client.getIntegerReply(); + client.setrange(key, offset, value); + return client.getIntegerReply(); } public byte[] getrange(byte[] key, long startOffset, long endOffset) { - client.getrange(key, startOffset, endOffset); - return client.getBinaryBulkReply(); + client.getrange(key, startOffset, endOffset); + return client.getBinaryBulkReply(); } public Long publish(byte[] channel, byte[] message) { - client.publish(channel, message); - return client.getIntegerReply(); + client.publish(channel, message); + return client.getIntegerReply(); } public void subscribe(BinaryJedisPubSub jedisPubSub, byte[]... channels) { - client.setTimeoutInfinite(); - try { - jedisPubSub.proceed(client, channels); - } finally { - client.rollbackTimeout(); - } + client.setTimeoutInfinite(); + try { + jedisPubSub.proceed(client, channels); + } finally { + client.rollbackTimeout(); + } } public void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns) { - client.setTimeoutInfinite(); - try { - jedisPubSub.proceedWithPatterns(client, patterns); - } finally { - client.rollbackTimeout(); - } + client.setTimeoutInfinite(); + try { + jedisPubSub.proceedWithPatterns(client, patterns); + } finally { + client.rollbackTimeout(); + } } public Long getDB() { - return client.getDB(); + return client.getDB(); } /** @@ -3274,215 +3274,215 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @return Script result */ public Object eval(byte[] script, List keys, List args) { - return eval(script, toByteArray(keys.size()), getParams(keys, args)); + return eval(script, toByteArray(keys.size()), getParams(keys, args)); } private byte[][] getParams(List keys, List args) { - final int keyCount = keys.size(); - final int argCount = args.size(); - byte[][] params = new byte[keyCount + argCount][]; + final int keyCount = keys.size(); + final int argCount = args.size(); + byte[][] params = new byte[keyCount + argCount][]; - for (int i = 0; i < keyCount; i++) - params[i] = keys.get(i); + for (int i = 0; i < keyCount; i++) + params[i] = keys.get(i); - for (int i = 0; i < argCount; i++) - params[keyCount + i] = args.get(i); + for (int i = 0; i < argCount; i++) + params[keyCount + i] = args.get(i); - return params; + return params; } public Object eval(byte[] script, byte[] keyCount, byte[]... params) { - client.setTimeoutInfinite(); - try { - client.eval(script, keyCount, params); - return client.getOne(); - } finally { - client.rollbackTimeout(); - } + client.setTimeoutInfinite(); + try { + client.eval(script, keyCount, params); + return client.getOne(); + } finally { + client.rollbackTimeout(); + } } public Object eval(byte[] script, int keyCount, byte[]... params) { - return eval(script, toByteArray(keyCount), params); + return eval(script, toByteArray(keyCount), params); } public Object eval(byte[] script) { - return eval(script, 0); + return eval(script, 0); } public Object evalsha(byte[] sha1) { - return evalsha(sha1, 1); + return evalsha(sha1, 1); } public Object evalsha(byte[] sha1, List keys, List args) { - return evalsha(sha1, keys.size(), getParams(keys, args)); + return evalsha(sha1, keys.size(), getParams(keys, args)); } public Object evalsha(byte[] sha1, int keyCount, byte[]... params) { - client.setTimeoutInfinite(); - try { - client.evalsha(sha1, keyCount, params); - return client.getOne(); - } finally { - client.rollbackTimeout(); - } + client.setTimeoutInfinite(); + try { + client.evalsha(sha1, keyCount, params); + return client.getOne(); + } finally { + client.rollbackTimeout(); + } } public String scriptFlush() { - client.scriptFlush(); - return client.getStatusCodeReply(); + client.scriptFlush(); + return client.getStatusCodeReply(); } public List scriptExists(byte[]... sha1) { - client.scriptExists(sha1); - return client.getIntegerMultiBulkReply(); + client.scriptExists(sha1); + return client.getIntegerMultiBulkReply(); } public byte[] scriptLoad(byte[] script) { - client.scriptLoad(script); - return client.getBinaryBulkReply(); + client.scriptLoad(script); + return client.getBinaryBulkReply(); } public String scriptKill() { - client.scriptKill(); - return client.getStatusCodeReply(); + client.scriptKill(); + return client.getStatusCodeReply(); } public String slowlogReset() { - client.slowlogReset(); - return client.getBulkReply(); + client.slowlogReset(); + return client.getBulkReply(); } public Long slowlogLen() { - client.slowlogLen(); - return client.getIntegerReply(); + client.slowlogLen(); + return client.getIntegerReply(); } public List slowlogGetBinary() { - client.slowlogGet(); - return client.getBinaryMultiBulkReply(); + client.slowlogGet(); + return client.getBinaryMultiBulkReply(); } public List slowlogGetBinary(long entries) { - client.slowlogGet(entries); - return client.getBinaryMultiBulkReply(); + client.slowlogGet(entries); + return client.getBinaryMultiBulkReply(); } public Long objectRefcount(byte[] key) { - client.objectRefcount(key); - return client.getIntegerReply(); + client.objectRefcount(key); + return client.getIntegerReply(); } public byte[] objectEncoding(byte[] key) { - client.objectEncoding(key); - return client.getBinaryBulkReply(); + client.objectEncoding(key); + return client.getBinaryBulkReply(); } public Long objectIdletime(byte[] key) { - client.objectIdletime(key); - return client.getIntegerReply(); + client.objectIdletime(key); + return client.getIntegerReply(); } public Long bitcount(final byte[] key) { - client.bitcount(key); - return client.getIntegerReply(); + client.bitcount(key); + return client.getIntegerReply(); } public Long bitcount(final byte[] key, long start, long end) { - client.bitcount(key, start, end); - return client.getIntegerReply(); + client.bitcount(key, start, end); + return client.getIntegerReply(); } public Long bitop(BitOP op, final byte[] destKey, byte[]... srcKeys) { - client.bitop(op, destKey, srcKeys); - return client.getIntegerReply(); + client.bitop(op, destKey, srcKeys); + return client.getIntegerReply(); } public byte[] dump(final byte[] key) { - checkIsInMulti(); - client.dump(key); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.dump(key); + return client.getBinaryBulkReply(); } public String restore(final byte[] key, final int ttl, - final byte[] serializedValue) { - checkIsInMulti(); - client.restore(key, ttl, serializedValue); - return client.getStatusCodeReply(); + final byte[] serializedValue) { + checkIsInMulti(); + client.restore(key, ttl, serializedValue); + return client.getStatusCodeReply(); } public Long pexpire(final byte[] key, final long milliseconds) { - checkIsInMulti(); - client.pexpire(key, milliseconds); - return client.getIntegerReply(); + checkIsInMulti(); + client.pexpire(key, milliseconds); + return client.getIntegerReply(); } public Long pexpireAt(final byte[] key, final long millisecondsTimestamp) { - checkIsInMulti(); - client.pexpireAt(key, millisecondsTimestamp); - return client.getIntegerReply(); + checkIsInMulti(); + client.pexpireAt(key, millisecondsTimestamp); + return client.getIntegerReply(); } public Long pttl(final byte[] key) { - checkIsInMulti(); - client.pttl(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.pttl(key); + return client.getIntegerReply(); } public String psetex(final byte[] key, final int milliseconds, - final byte[] value) { - checkIsInMulti(); - client.psetex(key, milliseconds, value); - return client.getStatusCodeReply(); + final byte[] value) { + checkIsInMulti(); + client.psetex(key, milliseconds, value); + return client.getStatusCodeReply(); } public String set(final byte[] key, final byte[] value, final byte[] nxxx) { - checkIsInMulti(); - client.set(key, value, nxxx); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.set(key, value, nxxx); + return client.getStatusCodeReply(); } public String set(final byte[] key, final byte[] value, final byte[] nxxx, - final byte[] expx, final int time) { - checkIsInMulti(); - client.set(key, value, nxxx, expx, time); - return client.getStatusCodeReply(); + final byte[] expx, final int time) { + checkIsInMulti(); + client.set(key, value, nxxx, expx, time); + return client.getStatusCodeReply(); } public String clientKill(final byte[] client) { - checkIsInMulti(); - this.client.clientKill(client); - return this.client.getStatusCodeReply(); + checkIsInMulti(); + this.client.clientKill(client); + return this.client.getStatusCodeReply(); } public String clientGetname() { - checkIsInMulti(); - client.clientGetname(); - return client.getBulkReply(); + checkIsInMulti(); + client.clientGetname(); + return client.getBulkReply(); } public String clientList() { - checkIsInMulti(); - client.clientList(); - return client.getBulkReply(); + checkIsInMulti(); + client.clientList(); + return client.getBulkReply(); } public String clientSetname(final byte[] name) { - checkIsInMulti(); - client.clientSetname(name); - return client.getBulkReply(); + checkIsInMulti(); + client.clientSetname(name); + return client.getBulkReply(); } public List time() { - checkIsInMulti(); - client.time(); - return client.getMultiBulkReply(); + checkIsInMulti(); + client.time(); + return client.getMultiBulkReply(); } public String migrate(final byte[] host, final int port, final byte[] key, - final int destinationDb, final int timeout) { - checkIsInMulti(); - client.migrate(host, port, key, destinationDb, timeout); - return client.getStatusCodeReply(); + final int destinationDb, final int timeout) { + checkIsInMulti(); + client.migrate(host, port, key, destinationDb, timeout); + return client.getStatusCodeReply(); } /** @@ -3493,105 +3493,105 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * so I had to change the name of the method. Sorry :S */ public Long waitReplicas(int replicas, long timeout) { - checkIsInMulti(); - client.waitReplicas(replicas, timeout); - return client.getIntegerReply(); + checkIsInMulti(); + client.waitReplicas(replicas, timeout); + return client.getIntegerReply(); } @Override public Long pfadd(final byte[] key, final byte[]... elements) { - checkIsInMulti(); - client.pfadd(key, elements); - return client.getIntegerReply(); + checkIsInMulti(); + client.pfadd(key, elements); + return client.getIntegerReply(); } @Override public long pfcount(final byte[] key) { - checkIsInMulti(); - client.pfcount(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.pfcount(key); + return client.getIntegerReply(); } @Override public String pfmerge(final byte[] destkey, final byte[]... sourcekeys) { - checkIsInMulti(); - client.pfmerge(destkey, sourcekeys); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.pfmerge(destkey, sourcekeys); + return client.getStatusCodeReply(); } @Override public Long pfcount(byte[]... keys) { - checkIsInMulti(); - client.pfcount(keys); - return client.getIntegerReply(); + checkIsInMulti(); + client.pfcount(keys); + return client.getIntegerReply(); } public ScanResult scan(final byte[] cursor) { - return scan(cursor, new ScanParams()); + return scan(cursor, new ScanParams()); } public ScanResult scan(final byte[] cursor, final ScanParams params) { - checkIsInMulti(); - client.scan(cursor, params); - List result = client.getObjectMultiBulkReply(); - byte[] newcursor = (byte[]) result.get(0); - List rawResults = (List) result.get(1); - return new ScanResult(newcursor, rawResults); + checkIsInMulti(); + client.scan(cursor, params); + List result = client.getObjectMultiBulkReply(); + byte[] newcursor = (byte[]) result.get(0); + List rawResults = (List) result.get(1); + return new ScanResult(newcursor, rawResults); } public ScanResult> hscan(final byte[] key, - final byte[] cursor) { - return hscan(key, cursor, new ScanParams()); + final byte[] cursor) { + return hscan(key, cursor, new ScanParams()); } public ScanResult> hscan(final byte[] key, - final byte[] cursor, final ScanParams params) { - checkIsInMulti(); - client.hscan(key, cursor, params); - List result = client.getObjectMultiBulkReply(); - byte[] newcursor = (byte[]) result.get(0); - List> results = new ArrayList>(); - List rawResults = (List) result.get(1); - Iterator iterator = rawResults.iterator(); - while (iterator.hasNext()) { - results.add(new AbstractMap.SimpleEntry(iterator - .next(), iterator.next())); - } - return new ScanResult>(newcursor, results); + final byte[] cursor, final ScanParams params) { + checkIsInMulti(); + client.hscan(key, cursor, params); + List result = client.getObjectMultiBulkReply(); + byte[] newcursor = (byte[]) result.get(0); + List> results = new ArrayList>(); + List rawResults = (List) result.get(1); + Iterator iterator = rawResults.iterator(); + while (iterator.hasNext()) { + results.add(new AbstractMap.SimpleEntry(iterator + .next(), iterator.next())); + } + return new ScanResult>(newcursor, results); } public ScanResult sscan(final byte[] key, final byte[] cursor) { - return sscan(key, cursor, new ScanParams()); + return sscan(key, cursor, new ScanParams()); } public ScanResult sscan(final byte[] key, final byte[] cursor, - final ScanParams params) { - checkIsInMulti(); - client.sscan(key, cursor, params); - List result = client.getObjectMultiBulkReply(); - byte[] newcursor = (byte[]) result.get(0); - List rawResults = (List) result.get(1); - return new ScanResult(newcursor, rawResults); + final ScanParams params) { + checkIsInMulti(); + client.sscan(key, cursor, params); + List result = client.getObjectMultiBulkReply(); + byte[] newcursor = (byte[]) result.get(0); + List rawResults = (List) result.get(1); + return new ScanResult(newcursor, rawResults); } public ScanResult zscan(final byte[] key, final byte[] cursor) { - return zscan(key, cursor, new ScanParams()); + return zscan(key, cursor, new ScanParams()); } public ScanResult zscan(final byte[] key, final byte[] cursor, - final ScanParams params) { - checkIsInMulti(); - client.zscan(key, cursor, params); - List result = client.getObjectMultiBulkReply(); - byte[] newcursor = (byte[]) result.get(0); - List results = new ArrayList(); - List rawResults = (List) result.get(1); - Iterator iterator = rawResults.iterator(); - while (iterator.hasNext()) { - results.add(new Tuple(iterator.next(), Double.valueOf(SafeEncoder - .encode(iterator.next())))); - } - return new ScanResult(newcursor, results); + final ScanParams params) { + checkIsInMulti(); + client.zscan(key, cursor, params); + List result = client.getObjectMultiBulkReply(); + byte[] newcursor = (byte[]) result.get(0); + List results = new ArrayList(); + List rawResults = (List) result.get(1); + Iterator iterator = rawResults.iterator(); + while (iterator.hasNext()) { + results.add(new Tuple(iterator.next(), Double.valueOf(SafeEncoder + .encode(iterator.next())))); + } + return new ScanResult(newcursor, results); } } diff --git a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java index 3853d0b..901bd19 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java +++ b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java @@ -158,38 +158,38 @@ public interface BinaryJedisCommands { Set zrevrangeByScore(byte[] key, double max, double min); Set zrangeByScore(byte[] key, double min, double max, int offset, - int count); + int count); Set zrevrangeByScore(byte[] key, byte[] max, byte[] min); Set zrangeByScore(byte[] key, byte[] min, byte[] max, int offset, - int count); + int count); Set zrevrangeByScore(byte[] key, double max, double min, - int offset, int count); + int offset, int count); Set zrangeByScoreWithScores(byte[] key, double min, double max); Set zrevrangeByScoreWithScores(byte[] key, double max, double min); Set zrangeByScoreWithScores(byte[] key, double min, double max, - int offset, int count); + int offset, int count); Set zrevrangeByScore(byte[] key, byte[] max, byte[] min, - int offset, int count); + int offset, int count); Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max); Set zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min); Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max, - int offset, int count); + int offset, int count); Set zrevrangeByScoreWithScores(byte[] key, double max, double min, - int offset, int count); + int offset, int count); Set zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min, - int offset, int count); + int offset, int count); Long zremrangeByRank(byte[] key, long start, long end); @@ -202,18 +202,18 @@ public interface BinaryJedisCommands { Set zrangeByLex(final byte[] key, final byte[] min, final byte[] max); Set zrangeByLex(final byte[] key, final byte[] min, - final byte[] max, int offset, int count); + final byte[] max, int offset, int count); Set zrevrangeByLex(final byte[] key, final byte[] max, - final byte[] min); + final byte[] min); Set zrevrangeByLex(final byte[] key, final byte[] max, - final byte[] min, int offset, int count); + final byte[] min, int offset, int count); Long zremrangeByLex(final byte[] key, final byte[] min, final byte[] max); Long linsert(byte[] key, Client.LIST_POSITION where, byte[] pivot, - byte[] value); + byte[] value); Long lpushx(byte[] key, byte[]... arg); diff --git a/src/main/java/redis/clients/jedis/BinaryJedisPubSub.java b/src/main/java/redis/clients/jedis/BinaryJedisPubSub.java index 9d36ae0..08be119 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedisPubSub.java +++ b/src/main/java/redis/clients/jedis/BinaryJedisPubSub.java @@ -16,104 +16,104 @@ public abstract class BinaryJedisPubSub { private int subscribedChannels = 0; private Client client; - public void onMessage(byte[] channel, byte[] message) {} + public void onMessage(byte[] channel, byte[] message) {} - public void onPMessage(byte[] pattern, byte[] channel, byte[] message) {} + public void onPMessage(byte[] pattern, byte[] channel, byte[] message) {} - public void onSubscribe(byte[] channel, int subscribedChannels) {} + public void onSubscribe(byte[] channel, int subscribedChannels) {} - public void onUnsubscribe(byte[] channel, int subscribedChannels) {} + public void onUnsubscribe(byte[] channel, int subscribedChannels) {} - public void onPUnsubscribe(byte[] pattern, int subscribedChannels) {} + public void onPUnsubscribe(byte[] pattern, int subscribedChannels) {} - public void onPSubscribe(byte[] pattern, int subscribedChannels) {} + public void onPSubscribe(byte[] pattern, int subscribedChannels) {} public void unsubscribe() { - client.unsubscribe(); - client.flush(); + client.unsubscribe(); + client.flush(); } public void unsubscribe(byte[]... channels) { - client.unsubscribe(channels); - client.flush(); + client.unsubscribe(channels); + client.flush(); } public void subscribe(byte[]... channels) { - client.subscribe(channels); - client.flush(); + client.subscribe(channels); + client.flush(); } public void psubscribe(byte[]... patterns) { - client.psubscribe(patterns); - client.flush(); + client.psubscribe(patterns); + client.flush(); } public void punsubscribe() { - client.punsubscribe(); - client.flush(); + client.punsubscribe(); + client.flush(); } public void punsubscribe(byte[]... patterns) { - client.punsubscribe(patterns); - client.flush(); + client.punsubscribe(patterns); + client.flush(); } public boolean isSubscribed() { - return subscribedChannels > 0; + return subscribedChannels > 0; } public void proceedWithPatterns(Client client, byte[]... patterns) { - this.client = client; - client.psubscribe(patterns); - process(client); + this.client = client; + client.psubscribe(patterns); + process(client); } public void proceed(Client client, byte[]... channels) { - this.client = client; - client.subscribe(channels); - process(client); + this.client = client; + client.subscribe(channels); + process(client); } private void process(Client client) { - do { - List reply = client.getObjectMultiBulkReply(); - final Object firstObj = reply.get(0); - if (!(firstObj instanceof byte[])) { - throw new JedisException("Unknown message type: " + firstObj); - } - final byte[] resp = (byte[]) firstObj; - if (Arrays.equals(SUBSCRIBE.raw, resp)) { - subscribedChannels = ((Long) reply.get(2)).intValue(); - final byte[] bchannel = (byte[]) reply.get(1); - onSubscribe(bchannel, subscribedChannels); - } else if (Arrays.equals(UNSUBSCRIBE.raw, resp)) { - subscribedChannels = ((Long) reply.get(2)).intValue(); - final byte[] bchannel = (byte[]) reply.get(1); - onUnsubscribe(bchannel, subscribedChannels); - } else if (Arrays.equals(MESSAGE.raw, resp)) { - final byte[] bchannel = (byte[]) reply.get(1); - final byte[] bmesg = (byte[]) reply.get(2); - onMessage(bchannel, bmesg); - } else if (Arrays.equals(PMESSAGE.raw, resp)) { - final byte[] bpattern = (byte[]) reply.get(1); - final byte[] bchannel = (byte[]) reply.get(2); - final byte[] bmesg = (byte[]) reply.get(3); - onPMessage(bpattern, bchannel, bmesg); - } else if (Arrays.equals(PSUBSCRIBE.raw, resp)) { - subscribedChannels = ((Long) reply.get(2)).intValue(); - final byte[] bpattern = (byte[]) reply.get(1); - onPSubscribe(bpattern, subscribedChannels); - } else if (Arrays.equals(PUNSUBSCRIBE.raw, resp)) { - subscribedChannels = ((Long) reply.get(2)).intValue(); - final byte[] bpattern = (byte[]) reply.get(1); - onPUnsubscribe(bpattern, subscribedChannels); - } else { - throw new JedisException("Unknown message type: " + firstObj); - } - } while (isSubscribed()); + do { + List reply = client.getObjectMultiBulkReply(); + final Object firstObj = reply.get(0); + if (!(firstObj instanceof byte[])) { + throw new JedisException("Unknown message type: " + firstObj); + } + final byte[] resp = (byte[]) firstObj; + if (Arrays.equals(SUBSCRIBE.raw, resp)) { + subscribedChannels = ((Long) reply.get(2)).intValue(); + final byte[] bchannel = (byte[]) reply.get(1); + onSubscribe(bchannel, subscribedChannels); + } else if (Arrays.equals(UNSUBSCRIBE.raw, resp)) { + subscribedChannels = ((Long) reply.get(2)).intValue(); + final byte[] bchannel = (byte[]) reply.get(1); + onUnsubscribe(bchannel, subscribedChannels); + } else if (Arrays.equals(MESSAGE.raw, resp)) { + final byte[] bchannel = (byte[]) reply.get(1); + final byte[] bmesg = (byte[]) reply.get(2); + onMessage(bchannel, bmesg); + } else if (Arrays.equals(PMESSAGE.raw, resp)) { + final byte[] bpattern = (byte[]) reply.get(1); + final byte[] bchannel = (byte[]) reply.get(2); + final byte[] bmesg = (byte[]) reply.get(3); + onPMessage(bpattern, bchannel, bmesg); + } else if (Arrays.equals(PSUBSCRIBE.raw, resp)) { + subscribedChannels = ((Long) reply.get(2)).intValue(); + final byte[] bpattern = (byte[]) reply.get(1); + onPSubscribe(bpattern, subscribedChannels); + } else if (Arrays.equals(PUNSUBSCRIBE.raw, resp)) { + subscribedChannels = ((Long) reply.get(2)).intValue(); + final byte[] bpattern = (byte[]) reply.get(1); + onPUnsubscribe(bpattern, subscribedChannels); + } else { + throw new JedisException("Unknown message type: " + firstObj); + } + } while (isSubscribed()); } public int getSubscribedChannels() { - return subscribedChannels; + return subscribedChannels; } } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java b/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java index 333a83a..2462d99 100644 --- a/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java +++ b/src/main/java/redis/clients/jedis/BinaryRedisPipeline.java @@ -67,7 +67,7 @@ public interface BinaryRedisPipeline { Response lindex(byte[] key, long index); Response linsert(byte[] key, BinaryClient.LIST_POSITION where, - byte[] pivot, byte[] value); + byte[] pivot, byte[] value); Response llen(byte[] key); @@ -148,44 +148,44 @@ public interface BinaryRedisPipeline { Response> zrangeByScore(byte[] key, byte[] min, byte[] max); Response> zrangeByScore(byte[] key, double min, double max, - int offset, int count); + int offset, int count); Response> zrangeByScore(byte[] key, byte[] min, byte[] max, - int offset, int count); + int offset, int count); Response> zrangeByScoreWithScores(byte[] key, double min, - double max); + double max); Response> zrangeByScoreWithScores(byte[] key, byte[] min, - byte[] max); + byte[] max); Response> zrangeByScoreWithScores(byte[] key, double min, - double max, int offset, int count); + double max, int offset, int count); Response> zrangeByScoreWithScores(byte[] key, byte[] min, - byte[] max, int offset, int count); + byte[] max, int offset, int count); Response> zrevrangeByScore(byte[] key, double max, double min); Response> zrevrangeByScore(byte[] key, byte[] max, byte[] min); Response> zrevrangeByScore(byte[] key, double max, double min, - int offset, int count); + int offset, int count); Response> zrevrangeByScore(byte[] key, byte[] max, byte[] min, - int offset, int count); + int offset, int count); Response> zrevrangeByScoreWithScores(byte[] key, double max, - double min); + double min); Response> zrevrangeByScoreWithScores(byte[] key, byte[] max, - byte[] min); + byte[] min); Response> zrevrangeByScoreWithScores(byte[] key, double max, - double min, int offset, int count); + double min, int offset, int count); Response> zrevrangeByScoreWithScores(byte[] key, byte[] max, - byte[] min, int offset, int count); + byte[] min, int offset, int count); Response> zrangeWithScores(byte[] key, long start, long end); @@ -208,22 +208,22 @@ public interface BinaryRedisPipeline { Response zscore(byte[] key, byte[] member); Response zlexcount(final byte[] key, final byte[] min, - final byte[] max); + final byte[] max); Response> zrangeByLex(final byte[] key, final byte[] min, - final byte[] max); + final byte[] max); Response> zrangeByLex(final byte[] key, final byte[] min, - final byte[] max, int offset, int count); + final byte[] max, int offset, int count); Response> zrevrangeByLex(final byte[] key, final byte[] max, - final byte[] min); + final byte[] min); Response> zrevrangeByLex(final byte[] key, final byte[] max, - final byte[] min, int offset, int count); + final byte[] min, int offset, int count); Response zremrangeByLex(final byte[] key, final byte[] min, - final byte[] max); + final byte[] max); Response bitcount(byte[] key); diff --git a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java index cb92e73..181c473 100644 --- a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java @@ -11,618 +11,618 @@ import redis.clients.util.Hashing; import redis.clients.util.Sharded; public class BinaryShardedJedis extends Sharded - implements BinaryJedisCommands { + implements BinaryJedisCommands { public BinaryShardedJedis(List shards) { - super(shards); + super(shards); } public BinaryShardedJedis(List shards, Hashing algo) { - super(shards, algo); + super(shards, algo); } public BinaryShardedJedis(List shards, Pattern keyTagPattern) { - super(shards, keyTagPattern); + super(shards, keyTagPattern); } public BinaryShardedJedis(List shards, Hashing algo, - Pattern keyTagPattern) { - super(shards, algo, keyTagPattern); + Pattern keyTagPattern) { + super(shards, algo, keyTagPattern); } public void disconnect() { - for (Jedis jedis : getAllShards()) { - jedis.quit(); - jedis.disconnect(); - } + for (Jedis jedis : getAllShards()) { + jedis.quit(); + jedis.disconnect(); + } } protected Jedis create(JedisShardInfo shard) { - return new Jedis(shard); + return new Jedis(shard); } public String set(byte[] key, byte[] value) { - Jedis j = getShard(key); - return j.set(key, value); + Jedis j = getShard(key); + return j.set(key, value); } public byte[] get(byte[] key) { - Jedis j = getShard(key); - return j.get(key); + Jedis j = getShard(key); + return j.get(key); } public Boolean exists(byte[] key) { - Jedis j = getShard(key); - return j.exists(key); + Jedis j = getShard(key); + return j.exists(key); } public String type(byte[] key) { - Jedis j = getShard(key); - return j.type(key); + Jedis j = getShard(key); + return j.type(key); } public Long expire(byte[] key, int seconds) { - Jedis j = getShard(key); - return j.expire(key, seconds); + Jedis j = getShard(key); + return j.expire(key, seconds); } public Long expireAt(byte[] key, long unixTime) { - Jedis j = getShard(key); - return j.expireAt(key, unixTime); + Jedis j = getShard(key); + return j.expireAt(key, unixTime); } public Long ttl(byte[] key) { - Jedis j = getShard(key); - return j.ttl(key); + Jedis j = getShard(key); + return j.ttl(key); } public byte[] getSet(byte[] key, byte[] value) { - Jedis j = getShard(key); - return j.getSet(key, value); + Jedis j = getShard(key); + return j.getSet(key, value); } public Long setnx(byte[] key, byte[] value) { - Jedis j = getShard(key); - return j.setnx(key, value); + Jedis j = getShard(key); + return j.setnx(key, value); } public String setex(byte[] key, int seconds, byte[] value) { - Jedis j = getShard(key); - return j.setex(key, seconds, value); + Jedis j = getShard(key); + return j.setex(key, seconds, value); } public Long decrBy(byte[] key, long integer) { - Jedis j = getShard(key); - return j.decrBy(key, integer); + Jedis j = getShard(key); + return j.decrBy(key, integer); } public Long decr(byte[] key) { - Jedis j = getShard(key); - return j.decr(key); + Jedis j = getShard(key); + return j.decr(key); } public Long del(byte[] key) { - Jedis j = getShard(key); - return j.del(key); + Jedis j = getShard(key); + return j.del(key); } public Long incrBy(byte[] key, long integer) { - Jedis j = getShard(key); - return j.incrBy(key, integer); + Jedis j = getShard(key); + return j.incrBy(key, integer); } public Double incrByFloat(byte[] key, double integer) { - Jedis j = getShard(key); - return j.incrByFloat(key, integer); + Jedis j = getShard(key); + return j.incrByFloat(key, integer); } public Long incr(byte[] key) { - Jedis j = getShard(key); - return j.incr(key); + Jedis j = getShard(key); + return j.incr(key); } public Long append(byte[] key, byte[] value) { - Jedis j = getShard(key); - return j.append(key, value); + Jedis j = getShard(key); + return j.append(key, value); } public byte[] substr(byte[] key, int start, int end) { - Jedis j = getShard(key); - return j.substr(key, start, end); + Jedis j = getShard(key); + return j.substr(key, start, end); } public Long hset(byte[] key, byte[] field, byte[] value) { - Jedis j = getShard(key); - return j.hset(key, field, value); + Jedis j = getShard(key); + return j.hset(key, field, value); } public byte[] hget(byte[] key, byte[] field) { - Jedis j = getShard(key); - return j.hget(key, field); + Jedis j = getShard(key); + return j.hget(key, field); } public Long hsetnx(byte[] key, byte[] field, byte[] value) { - Jedis j = getShard(key); - return j.hsetnx(key, field, value); + Jedis j = getShard(key); + return j.hsetnx(key, field, value); } public String hmset(byte[] key, Map hash) { - Jedis j = getShard(key); - return j.hmset(key, hash); + Jedis j = getShard(key); + return j.hmset(key, hash); } public List hmget(byte[] key, byte[]... fields) { - Jedis j = getShard(key); - return j.hmget(key, fields); + Jedis j = getShard(key); + return j.hmget(key, fields); } public Long hincrBy(byte[] key, byte[] field, long value) { - Jedis j = getShard(key); - return j.hincrBy(key, field, value); + Jedis j = getShard(key); + return j.hincrBy(key, field, value); } public Double hincrByFloat(byte[] key, byte[] field, double value) { - Jedis j = getShard(key); - return j.hincrByFloat(key, field, value); + Jedis j = getShard(key); + return j.hincrByFloat(key, field, value); } public Boolean hexists(byte[] key, byte[] field) { - Jedis j = getShard(key); - return j.hexists(key, field); + Jedis j = getShard(key); + return j.hexists(key, field); } public Long hdel(byte[] key, byte[]... fields) { - Jedis j = getShard(key); - return j.hdel(key, fields); + Jedis j = getShard(key); + return j.hdel(key, fields); } public Long hlen(byte[] key) { - Jedis j = getShard(key); - return j.hlen(key); + Jedis j = getShard(key); + return j.hlen(key); } public Set hkeys(byte[] key) { - Jedis j = getShard(key); - return j.hkeys(key); + Jedis j = getShard(key); + return j.hkeys(key); } public Collection hvals(byte[] key) { - Jedis j = getShard(key); - return j.hvals(key); + Jedis j = getShard(key); + return j.hvals(key); } public Map hgetAll(byte[] key) { - Jedis j = getShard(key); - return j.hgetAll(key); + Jedis j = getShard(key); + return j.hgetAll(key); } public Long rpush(byte[] key, byte[]... strings) { - Jedis j = getShard(key); - return j.rpush(key, strings); + Jedis j = getShard(key); + return j.rpush(key, strings); } public Long lpush(byte[] key, byte[]... strings) { - Jedis j = getShard(key); - return j.lpush(key, strings); + Jedis j = getShard(key); + return j.lpush(key, strings); } public Long strlen(final byte[] key) { - Jedis j = getShard(key); - return j.strlen(key); + Jedis j = getShard(key); + return j.strlen(key); } public Long lpushx(byte[] key, byte[]... string) { - Jedis j = getShard(key); - return j.lpushx(key, string); + Jedis j = getShard(key); + return j.lpushx(key, string); } public Long persist(final byte[] key) { - Jedis j = getShard(key); - return j.persist(key); + Jedis j = getShard(key); + return j.persist(key); } public Long rpushx(byte[] key, byte[]... string) { - Jedis j = getShard(key); - return j.rpushx(key, string); + Jedis j = getShard(key); + return j.rpushx(key, string); } public Long llen(byte[] key) { - Jedis j = getShard(key); - return j.llen(key); + Jedis j = getShard(key); + return j.llen(key); } public List lrange(byte[] key, long start, long end) { - Jedis j = getShard(key); - return j.lrange(key, start, end); + Jedis j = getShard(key); + return j.lrange(key, start, end); } public String ltrim(byte[] key, long start, long end) { - Jedis j = getShard(key); - return j.ltrim(key, start, end); + Jedis j = getShard(key); + return j.ltrim(key, start, end); } public byte[] lindex(byte[] key, long index) { - Jedis j = getShard(key); - return j.lindex(key, index); + Jedis j = getShard(key); + return j.lindex(key, index); } public String lset(byte[] key, long index, byte[] value) { - Jedis j = getShard(key); - return j.lset(key, index, value); + Jedis j = getShard(key); + return j.lset(key, index, value); } public Long lrem(byte[] key, long count, byte[] value) { - Jedis j = getShard(key); - return j.lrem(key, count, value); + Jedis j = getShard(key); + return j.lrem(key, count, value); } public byte[] lpop(byte[] key) { - Jedis j = getShard(key); - return j.lpop(key); + Jedis j = getShard(key); + return j.lpop(key); } public byte[] rpop(byte[] key) { - Jedis j = getShard(key); - return j.rpop(key); + Jedis j = getShard(key); + return j.rpop(key); } public Long sadd(byte[] key, byte[]... members) { - Jedis j = getShard(key); - return j.sadd(key, members); + Jedis j = getShard(key); + return j.sadd(key, members); } public Set smembers(byte[] key) { - Jedis j = getShard(key); - return j.smembers(key); + Jedis j = getShard(key); + return j.smembers(key); } public Long srem(byte[] key, byte[]... members) { - Jedis j = getShard(key); - return j.srem(key, members); + Jedis j = getShard(key); + return j.srem(key, members); } public byte[] spop(byte[] key) { - Jedis j = getShard(key); - return j.spop(key); + Jedis j = getShard(key); + return j.spop(key); } public Long scard(byte[] key) { - Jedis j = getShard(key); - return j.scard(key); + Jedis j = getShard(key); + return j.scard(key); } public Boolean sismember(byte[] key, byte[] member) { - Jedis j = getShard(key); - return j.sismember(key, member); + Jedis j = getShard(key); + return j.sismember(key, member); } public byte[] srandmember(byte[] key) { - Jedis j = getShard(key); - return j.srandmember(key); + Jedis j = getShard(key); + return j.srandmember(key); } @Override public List srandmember(byte[] key, int count) { - Jedis j = getShard(key); - return j.srandmember(key, count); + Jedis j = getShard(key); + return j.srandmember(key, count); } public Long zadd(byte[] key, double score, byte[] member) { - Jedis j = getShard(key); - return j.zadd(key, score, member); + Jedis j = getShard(key); + return j.zadd(key, score, member); } public Long zadd(byte[] key, Map scoreMembers) { - Jedis j = getShard(key); - return j.zadd(key, scoreMembers); + Jedis j = getShard(key); + return j.zadd(key, scoreMembers); } public Set zrange(byte[] key, long start, long end) { - Jedis j = getShard(key); - return j.zrange(key, start, end); + Jedis j = getShard(key); + return j.zrange(key, start, end); } public Long zrem(byte[] key, byte[]... members) { - Jedis j = getShard(key); - return j.zrem(key, members); + Jedis j = getShard(key); + return j.zrem(key, members); } public Double zincrby(byte[] key, double score, byte[] member) { - Jedis j = getShard(key); - return j.zincrby(key, score, member); + Jedis j = getShard(key); + return j.zincrby(key, score, member); } public Long zrank(byte[] key, byte[] member) { - Jedis j = getShard(key); - return j.zrank(key, member); + Jedis j = getShard(key); + return j.zrank(key, member); } public Long zrevrank(byte[] key, byte[] member) { - Jedis j = getShard(key); - return j.zrevrank(key, member); + Jedis j = getShard(key); + return j.zrevrank(key, member); } public Set zrevrange(byte[] key, long start, long end) { - Jedis j = getShard(key); - return j.zrevrange(key, start, end); + Jedis j = getShard(key); + return j.zrevrange(key, start, end); } public Set zrangeWithScores(byte[] key, long start, long end) { - Jedis j = getShard(key); - return j.zrangeWithScores(key, start, end); + Jedis j = getShard(key); + return j.zrangeWithScores(key, start, end); } public Set zrevrangeWithScores(byte[] key, long start, long end) { - Jedis j = getShard(key); - return j.zrevrangeWithScores(key, start, end); + Jedis j = getShard(key); + return j.zrevrangeWithScores(key, start, end); } public Long zcard(byte[] key) { - Jedis j = getShard(key); - return j.zcard(key); + Jedis j = getShard(key); + return j.zcard(key); } public Double zscore(byte[] key, byte[] member) { - Jedis j = getShard(key); - return j.zscore(key, member); + Jedis j = getShard(key); + return j.zscore(key, member); } public List sort(byte[] key) { - Jedis j = getShard(key); - return j.sort(key); + Jedis j = getShard(key); + return j.sort(key); } public List sort(byte[] key, SortingParams sortingParameters) { - Jedis j = getShard(key); - return j.sort(key, sortingParameters); + Jedis j = getShard(key); + return j.sort(key, sortingParameters); } public Long zcount(byte[] key, double min, double max) { - Jedis j = getShard(key); - return j.zcount(key, min, max); + Jedis j = getShard(key); + return j.zcount(key, min, max); } public Long zcount(byte[] key, byte[] min, byte[] max) { - Jedis j = getShard(key); - return j.zcount(key, min, max); + Jedis j = getShard(key); + return j.zcount(key, min, max); } public Set zrangeByScore(byte[] key, double min, double max) { - Jedis j = getShard(key); - return j.zrangeByScore(key, min, max); + Jedis j = getShard(key); + return j.zrangeByScore(key, min, max); } public Set zrangeByScore(byte[] key, double min, double max, - int offset, int count) { - Jedis j = getShard(key); - return j.zrangeByScore(key, min, max, offset, count); + int offset, int count) { + Jedis j = getShard(key); + return j.zrangeByScore(key, min, max, offset, count); } public Set zrangeByScoreWithScores(byte[] key, double min, double max) { - Jedis j = getShard(key); - return j.zrangeByScoreWithScores(key, min, max); + Jedis j = getShard(key); + return j.zrangeByScoreWithScores(key, min, max); } public Set zrangeByScoreWithScores(byte[] key, double min, - double max, int offset, int count) { - Jedis j = getShard(key); - return j.zrangeByScoreWithScores(key, min, max, offset, count); + double max, int offset, int count) { + Jedis j = getShard(key); + return j.zrangeByScoreWithScores(key, min, max, offset, count); } public Set zrangeByScore(byte[] key, byte[] min, byte[] max) { - Jedis j = getShard(key); - return j.zrangeByScore(key, min, max); + Jedis j = getShard(key); + return j.zrangeByScore(key, min, max); } public Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max) { - Jedis j = getShard(key); - return j.zrangeByScoreWithScores(key, min, max); + Jedis j = getShard(key); + return j.zrangeByScoreWithScores(key, min, max); } public Set zrangeByScoreWithScores(byte[] key, byte[] min, - byte[] max, int offset, int count) { - Jedis j = getShard(key); - return j.zrangeByScoreWithScores(key, min, max, offset, count); + byte[] max, int offset, int count) { + Jedis j = getShard(key); + return j.zrangeByScoreWithScores(key, min, max, offset, count); } public Set zrangeByScore(byte[] key, byte[] min, byte[] max, - int offset, int count) { - Jedis j = getShard(key); - return j.zrangeByScore(key, min, max, offset, count); + int offset, int count) { + Jedis j = getShard(key); + return j.zrangeByScore(key, min, max, offset, count); } public Set zrevrangeByScore(byte[] key, double max, double min) { - Jedis j = getShard(key); - return j.zrevrangeByScore(key, max, min); + Jedis j = getShard(key); + return j.zrevrangeByScore(key, max, min); } public Set zrevrangeByScore(byte[] key, double max, double min, - int offset, int count) { - Jedis j = getShard(key); - return j.zrevrangeByScore(key, max, min, offset, count); + int offset, int count) { + Jedis j = getShard(key); + return j.zrevrangeByScore(key, max, min, offset, count); } public Set zrevrangeByScoreWithScores(byte[] key, double max, - double min) { - Jedis j = getShard(key); - return j.zrevrangeByScoreWithScores(key, max, min); + double min) { + Jedis j = getShard(key); + return j.zrevrangeByScoreWithScores(key, max, min); } public Set zrevrangeByScoreWithScores(byte[] key, double max, - double min, int offset, int count) { - Jedis j = getShard(key); - return j.zrevrangeByScoreWithScores(key, max, min, offset, count); + double min, int offset, int count) { + Jedis j = getShard(key); + return j.zrevrangeByScoreWithScores(key, max, min, offset, count); } public Set zrevrangeByScore(byte[] key, byte[] max, byte[] min) { - Jedis j = getShard(key); - return j.zrevrangeByScore(key, max, min); + Jedis j = getShard(key); + return j.zrevrangeByScore(key, max, min); } public Set zrevrangeByScore(byte[] key, byte[] max, byte[] min, - int offset, int count) { - Jedis j = getShard(key); - return j.zrevrangeByScore(key, max, min, offset, count); + int offset, int count) { + Jedis j = getShard(key); + return j.zrevrangeByScore(key, max, min, offset, count); } public Set zrevrangeByScoreWithScores(byte[] key, byte[] max, - byte[] min) { - Jedis j = getShard(key); - return j.zrevrangeByScoreWithScores(key, max, min); + byte[] min) { + Jedis j = getShard(key); + return j.zrevrangeByScoreWithScores(key, max, min); } public Set zrevrangeByScoreWithScores(byte[] key, byte[] max, - byte[] min, int offset, int count) { - Jedis j = getShard(key); - return j.zrevrangeByScoreWithScores(key, max, min, offset, count); + byte[] min, int offset, int count) { + Jedis j = getShard(key); + return j.zrevrangeByScoreWithScores(key, max, min, offset, count); } public Long zremrangeByRank(byte[] key, long start, long end) { - Jedis j = getShard(key); - return j.zremrangeByRank(key, start, end); + Jedis j = getShard(key); + return j.zremrangeByRank(key, start, end); } public Long zremrangeByScore(byte[] key, double start, double end) { - Jedis j = getShard(key); - return j.zremrangeByScore(key, start, end); + Jedis j = getShard(key); + return j.zremrangeByScore(key, start, end); } public Long zremrangeByScore(byte[] key, byte[] start, byte[] end) { - Jedis j = getShard(key); - return j.zremrangeByScore(key, start, end); + Jedis j = getShard(key); + return j.zremrangeByScore(key, start, end); } @Override public Long zlexcount(final byte[] key, final byte[] min, final byte[] max) { - Jedis j = getShard(key); - return j.zlexcount(key, min, max); + Jedis j = getShard(key); + return j.zlexcount(key, min, max); } @Override public Set zrangeByLex(final byte[] key, final byte[] min, - final byte[] max) { - Jedis j = getShard(key); - return j.zrangeByLex(key, min, max); + final byte[] max) { + Jedis j = getShard(key); + return j.zrangeByLex(key, min, max); } @Override public Set 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); + final byte[] max, final int offset, final int count) { + Jedis j = getShard(key); + return j.zrangeByLex(key, min, max, offset, count); } @Override public Set zrevrangeByLex(byte[] key, byte[] max, byte[] min) { - Jedis j = getShard(key); - return j.zrevrangeByLex(key, max, min); + Jedis j = getShard(key); + return j.zrevrangeByLex(key, max, min); } @Override public Set zrevrangeByLex(byte[] key, byte[] max, byte[] min, - int offset, int count) { - Jedis j = getShard(key); - return j.zrevrangeByLex(key, max, min, offset, count); + int offset, int count) { + Jedis j = getShard(key); + return j.zrevrangeByLex(key, max, min, offset, count); } @Override public Long zremrangeByLex(final byte[] key, final byte[] min, - final byte[] max) { - Jedis j = getShard(key); - return j.zremrangeByLex(key, min, max); + final byte[] max) { + Jedis j = getShard(key); + return j.zremrangeByLex(key, min, max); } public Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, - byte[] value) { - Jedis j = getShard(key); - return j.linsert(key, where, pivot, value); + byte[] value) { + Jedis j = getShard(key); + return j.linsert(key, where, pivot, value); } public ShardedJedisPipeline pipelined() { - ShardedJedisPipeline pipeline = new ShardedJedisPipeline(); - pipeline.setShardedJedis(this); - return pipeline; + ShardedJedisPipeline pipeline = new ShardedJedisPipeline(); + pipeline.setShardedJedis(this); + return pipeline; } public Long objectRefcount(byte[] key) { - Jedis j = getShard(key); - return j.objectRefcount(key); + Jedis j = getShard(key); + return j.objectRefcount(key); } public byte[] objectEncoding(byte[] key) { - Jedis j = getShard(key); - return j.objectEncoding(key); + Jedis j = getShard(key); + return j.objectEncoding(key); } public Long objectIdletime(byte[] key) { - Jedis j = getShard(key); - return j.objectIdletime(key); + Jedis j = getShard(key); + return j.objectIdletime(key); } public Boolean setbit(byte[] key, long offset, boolean value) { - Jedis j = getShard(key); - return j.setbit(key, offset, value); + Jedis j = getShard(key); + return j.setbit(key, offset, value); } public Boolean setbit(byte[] key, long offset, byte[] value) { - Jedis j = getShard(key); - return j.setbit(key, offset, value); + Jedis j = getShard(key); + return j.setbit(key, offset, value); } public Boolean getbit(byte[] key, long offset) { - Jedis j = getShard(key); - return j.getbit(key, offset); + Jedis j = getShard(key); + return j.getbit(key, offset); } public Long setrange(byte[] key, long offset, byte[] value) { - Jedis j = getShard(key); - return j.setrange(key, offset, value); + Jedis j = getShard(key); + return j.setrange(key, offset, value); } public byte[] getrange(byte[] key, long startOffset, long endOffset) { - Jedis j = getShard(key); - return j.getrange(key, startOffset, endOffset); + Jedis j = getShard(key); + return j.getrange(key, startOffset, endOffset); } public Long move(byte[] key, int dbIndex) { - Jedis j = getShard(key); - return j.move(key, dbIndex); + Jedis j = getShard(key); + return j.move(key, dbIndex); } public byte[] echo(byte[] arg) { - Jedis j = getShard(arg); - return j.echo(arg); + Jedis j = getShard(arg); + return j.echo(arg); } public List brpop(byte[] arg) { - Jedis j = getShard(arg); - return j.brpop(arg); + Jedis j = getShard(arg); + return j.brpop(arg); } public List blpop(byte[] arg) { - Jedis j = getShard(arg); - return j.blpop(arg); + Jedis j = getShard(arg); + return j.blpop(arg); } public Long bitcount(byte[] key) { - Jedis j = getShard(key); - return j.bitcount(key); + Jedis j = getShard(key); + return j.bitcount(key); } public Long bitcount(byte[] key, long start, long end) { - Jedis j = getShard(key); - return j.bitcount(key, start, end); + Jedis j = getShard(key); + return j.bitcount(key, start, end); } @Override public Long pfadd(final byte[] key, final byte[]... elements) { - Jedis j = getShard(key); - return j.pfadd(key, elements); + Jedis j = getShard(key); + return j.pfadd(key, elements); } @Override public long pfcount(final byte[] key) { - Jedis j = getShard(key); - return j.pfcount(key); + Jedis j = getShard(key); + return j.pfcount(key); } } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/BitPosParams.java b/src/main/java/redis/clients/jedis/BitPosParams.java index 5522505..2d124e7 100644 --- a/src/main/java/redis/clients/jedis/BitPosParams.java +++ b/src/main/java/redis/clients/jedis/BitPosParams.java @@ -12,16 +12,16 @@ public class BitPosParams { } public BitPosParams(long start) { - params.add(Protocol.toByteArray(start)); + params.add(Protocol.toByteArray(start)); } public BitPosParams(long start, long end) { - this(start); + this(start); - params.add(Protocol.toByteArray(end)); + params.add(Protocol.toByteArray(end)); } public Collection getParams() { - return Collections.unmodifiableCollection(params); + return Collections.unmodifiableCollection(params); } } diff --git a/src/main/java/redis/clients/jedis/BuilderFactory.java b/src/main/java/redis/clients/jedis/BuilderFactory.java index f5d2a42..8fafdfb 100644 --- a/src/main/java/redis/clients/jedis/BuilderFactory.java +++ b/src/main/java/redis/clients/jedis/BuilderFactory.java @@ -14,265 +14,265 @@ import redis.clients.util.SafeEncoder; public class BuilderFactory { public static final Builder DOUBLE = new Builder() { - public Double build(Object data) { - String asString = STRING.build(data); - return asString == null ? null : Double.valueOf(asString); - } + public Double build(Object data) { + String asString = STRING.build(data); + return asString == null ? null : Double.valueOf(asString); + } - public String toString() { - return "double"; - } + public String toString() { + return "double"; + } }; public static final Builder BOOLEAN = new Builder() { - public Boolean build(Object data) { - return ((Long) data) == 1; - } + public Boolean build(Object data) { + return ((Long) data) == 1; + } - public String toString() { - return "boolean"; - } + public String toString() { + return "boolean"; + } }; public static final Builder BYTE_ARRAY = new Builder() { - public byte[] build(Object data) { - return ((byte[]) data); // deleted == 1 - } + public byte[] build(Object data) { + return ((byte[]) data); // deleted == 1 + } - public String toString() { - return "byte[]"; - } + public String toString() { + return "byte[]"; + } }; public static final Builder LONG = new Builder() { - public Long build(Object data) { - return (Long) data; - } + public Long build(Object data) { + return (Long) data; + } - public String toString() { - return "long"; - } + public String toString() { + return "long"; + } }; public static final Builder STRING = new Builder() { - public String build(Object data) { - return data == null ? null : SafeEncoder.encode((byte[]) data); - } + public String build(Object data) { + return data == null ? null : SafeEncoder.encode((byte[]) data); + } - public String toString() { - return "string"; - } + public String toString() { + return "string"; + } }; public static final Builder> STRING_LIST = new Builder>() { - @SuppressWarnings("unchecked") - public List build(Object data) { - if (null == data) { - return null; - } - List l = (List) data; - final ArrayList result = new ArrayList(l.size()); - for (final byte[] barray : l) { - if (barray == null) { - result.add(null); - } else { - result.add(SafeEncoder.encode(barray)); - } - } - return result; - } + @SuppressWarnings("unchecked") + public List build(Object data) { + if (null == data) { + return null; + } + List l = (List) data; + final ArrayList result = new ArrayList(l.size()); + for (final byte[] barray : l) { + if (barray == null) { + result.add(null); + } else { + result.add(SafeEncoder.encode(barray)); + } + } + return result; + } - public String toString() { - return "List"; - } + public String toString() { + return "List"; + } }; public static final Builder> STRING_MAP = new Builder>() { - @SuppressWarnings("unchecked") - public Map build(Object data) { - final List flatHash = (List) data; - final Map hash = new HashMap(); - final Iterator iterator = flatHash.iterator(); - while (iterator.hasNext()) { - hash.put(SafeEncoder.encode(iterator.next()), - SafeEncoder.encode(iterator.next())); - } + @SuppressWarnings("unchecked") + public Map build(Object data) { + final List flatHash = (List) data; + final Map hash = new HashMap(); + final Iterator iterator = flatHash.iterator(); + while (iterator.hasNext()) { + hash.put(SafeEncoder.encode(iterator.next()), + SafeEncoder.encode(iterator.next())); + } - return hash; - } + return hash; + } - public String toString() { - return "Map"; - } + public String toString() { + return "Map"; + } }; public static final Builder> PUBSUB_NUMSUB_MAP = new Builder>() { - @SuppressWarnings("unchecked") - public Map build(Object data) { - final List flatHash = (List) data; - final Map hash = new HashMap(); - final Iterator iterator = flatHash.iterator(); - while (iterator.hasNext()) { - hash.put(SafeEncoder.encode((byte[]) iterator.next()), - String.valueOf((Long) iterator.next())); - } + @SuppressWarnings("unchecked") + public Map build(Object data) { + final List flatHash = (List) data; + final Map hash = new HashMap(); + final Iterator iterator = flatHash.iterator(); + while (iterator.hasNext()) { + hash.put(SafeEncoder.encode((byte[]) iterator.next()), + String.valueOf((Long) iterator.next())); + } - return hash; - } + return hash; + } - public String toString() { - return "PUBSUB_NUMSUB_MAP"; - } + public String toString() { + return "PUBSUB_NUMSUB_MAP"; + } }; public static final Builder> STRING_SET = new Builder>() { - @SuppressWarnings("unchecked") - public Set build(Object data) { - if (null == data) { - return null; - } - List l = (List) data; - final Set result = new HashSet(l.size()); - for (final byte[] barray : l) { - if (barray == null) { - result.add(null); - } else { - result.add(SafeEncoder.encode(barray)); - } - } - return result; - } + @SuppressWarnings("unchecked") + public Set build(Object data) { + if (null == data) { + return null; + } + List l = (List) data; + final Set result = new HashSet(l.size()); + for (final byte[] barray : l) { + if (barray == null) { + result.add(null); + } else { + result.add(SafeEncoder.encode(barray)); + } + } + return result; + } - public String toString() { - return "Set"; - } + public String toString() { + return "Set"; + } }; public static final Builder> BYTE_ARRAY_LIST = new Builder>() { - @SuppressWarnings("unchecked") - public List build(Object data) { - if (null == data) { - return null; - } - List l = (List) data; + @SuppressWarnings("unchecked") + public List build(Object data) { + if (null == data) { + return null; + } + List l = (List) data; - return l; - } + return l; + } - public String toString() { - return "List"; - } + public String toString() { + return "List"; + } }; public static final Builder> BYTE_ARRAY_ZSET = new Builder>() { - @SuppressWarnings("unchecked") - public Set build(Object data) { - if (null == data) { - return null; - } - List l = (List) data; - final Set result = new LinkedHashSet(l); - for (final byte[] barray : l) { - if (barray == null) { - result.add(null); - } else { - result.add(barray); - } - } - return result; - } + @SuppressWarnings("unchecked") + public Set build(Object data) { + if (null == data) { + return null; + } + List l = (List) data; + final Set result = new LinkedHashSet(l); + for (final byte[] barray : l) { + if (barray == null) { + result.add(null); + } else { + result.add(barray); + } + } + return result; + } - public String toString() { - return "ZSet"; - } + public String toString() { + return "ZSet"; + } }; public static final Builder> BYTE_ARRAY_MAP = new Builder>() { - @SuppressWarnings("unchecked") - public Map build(Object data) { - final List flatHash = (List) data; - final Map hash = new JedisByteHashMap(); - final Iterator iterator = flatHash.iterator(); - while (iterator.hasNext()) { - hash.put(iterator.next(), iterator.next()); - } + @SuppressWarnings("unchecked") + public Map build(Object data) { + final List flatHash = (List) data; + final Map hash = new JedisByteHashMap(); + final Iterator iterator = flatHash.iterator(); + while (iterator.hasNext()) { + hash.put(iterator.next(), iterator.next()); + } - return hash; - } + return hash; + } - public String toString() { - return "Map"; - } + public String toString() { + return "Map"; + } }; public static final Builder> STRING_ZSET = new Builder>() { - @SuppressWarnings("unchecked") - public Set build(Object data) { - if (null == data) { - return null; - } - List l = (List) data; - final Set result = new LinkedHashSet(l.size()); - for (final byte[] barray : l) { - if (barray == null) { - result.add(null); - } else { - result.add(SafeEncoder.encode(barray)); - } - } - return result; - } + @SuppressWarnings("unchecked") + public Set build(Object data) { + if (null == data) { + return null; + } + List l = (List) data; + final Set result = new LinkedHashSet(l.size()); + for (final byte[] barray : l) { + if (barray == null) { + result.add(null); + } else { + result.add(SafeEncoder.encode(barray)); + } + } + return result; + } - public String toString() { - return "ZSet"; - } + public String toString() { + return "ZSet"; + } }; public static final Builder> TUPLE_ZSET = new Builder>() { - @SuppressWarnings("unchecked") - public Set build(Object data) { - if (null == data) { - return null; - } - List l = (List) data; - final Set result = new LinkedHashSet(l.size()); - Iterator iterator = l.iterator(); - while (iterator.hasNext()) { - result.add(new Tuple(SafeEncoder.encode(iterator.next()), - Double.valueOf(SafeEncoder.encode(iterator.next())))); - } - return result; - } + @SuppressWarnings("unchecked") + public Set build(Object data) { + if (null == data) { + return null; + } + List l = (List) data; + final Set result = new LinkedHashSet(l.size()); + Iterator iterator = l.iterator(); + while (iterator.hasNext()) { + result.add(new Tuple(SafeEncoder.encode(iterator.next()), + Double.valueOf(SafeEncoder.encode(iterator.next())))); + } + return result; + } - public String toString() { - return "ZSet"; - } + public String toString() { + return "ZSet"; + } }; public static final Builder> TUPLE_ZSET_BINARY = new Builder>() { - @SuppressWarnings("unchecked") - public Set build(Object data) { - if (null == data) { - return null; - } - List l = (List) data; - final Set result = new LinkedHashSet(l.size()); - Iterator iterator = l.iterator(); - while (iterator.hasNext()) { - result.add(new Tuple(iterator.next(), Double - .valueOf(SafeEncoder.encode(iterator.next())))); - } + @SuppressWarnings("unchecked") + public Set build(Object data) { + if (null == data) { + return null; + } + List l = (List) data; + final Set result = new LinkedHashSet(l.size()); + Iterator iterator = l.iterator(); + while (iterator.hasNext()) { + result.add(new Tuple(iterator.next(), Double + .valueOf(SafeEncoder.encode(iterator.next())))); + } - return result; + return result; - } + } - public String toString() { - return "ZSet"; - } + public String toString() { + return "ZSet"; + } }; } diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index d8e85bc..4f23b89 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -14,1020 +14,1020 @@ import redis.clients.util.SafeEncoder; public class Client extends BinaryClient implements Commands { public Client() { - super(); + super(); } public Client(final String host) { - super(host); + super(host); } public Client(final String host, final int port) { - super(host, port); + super(host, port); } public void set(final String key, final String value) { - set(SafeEncoder.encode(key), SafeEncoder.encode(value)); + set(SafeEncoder.encode(key), SafeEncoder.encode(value)); } public void set(final String key, final String value, final String nxxx, - final String expx, final long time) { - set(SafeEncoder.encode(key), SafeEncoder.encode(value), - SafeEncoder.encode(nxxx), SafeEncoder.encode(expx), time); + final String expx, final long time) { + set(SafeEncoder.encode(key), SafeEncoder.encode(value), + SafeEncoder.encode(nxxx), SafeEncoder.encode(expx), time); } public void get(final String key) { - get(SafeEncoder.encode(key)); + get(SafeEncoder.encode(key)); } public void exists(final String key) { - exists(SafeEncoder.encode(key)); + exists(SafeEncoder.encode(key)); } public void del(final String... keys) { - final byte[][] bkeys = new byte[keys.length][]; - for (int i = 0; i < keys.length; i++) { - bkeys[i] = SafeEncoder.encode(keys[i]); - } - del(bkeys); + final byte[][] bkeys = new byte[keys.length][]; + for (int i = 0; i < keys.length; i++) { + bkeys[i] = SafeEncoder.encode(keys[i]); + } + del(bkeys); } public void type(final String key) { - type(SafeEncoder.encode(key)); + type(SafeEncoder.encode(key)); } public void keys(final String pattern) { - keys(SafeEncoder.encode(pattern)); + keys(SafeEncoder.encode(pattern)); } public void rename(final String oldkey, final String newkey) { - rename(SafeEncoder.encode(oldkey), SafeEncoder.encode(newkey)); + rename(SafeEncoder.encode(oldkey), SafeEncoder.encode(newkey)); } public void renamenx(final String oldkey, final String newkey) { - renamenx(SafeEncoder.encode(oldkey), SafeEncoder.encode(newkey)); + renamenx(SafeEncoder.encode(oldkey), SafeEncoder.encode(newkey)); } public void expire(final String key, final int seconds) { - expire(SafeEncoder.encode(key), seconds); + expire(SafeEncoder.encode(key), seconds); } public void expireAt(final String key, final long unixTime) { - expireAt(SafeEncoder.encode(key), unixTime); + expireAt(SafeEncoder.encode(key), unixTime); } public void ttl(final String key) { - ttl(SafeEncoder.encode(key)); + ttl(SafeEncoder.encode(key)); } public void move(final String key, final int dbIndex) { - move(SafeEncoder.encode(key), dbIndex); + move(SafeEncoder.encode(key), dbIndex); } public void getSet(final String key, final String value) { - getSet(SafeEncoder.encode(key), SafeEncoder.encode(value)); + getSet(SafeEncoder.encode(key), SafeEncoder.encode(value)); } public void mget(final String... keys) { - final byte[][] bkeys = new byte[keys.length][]; - for (int i = 0; i < bkeys.length; i++) { - bkeys[i] = SafeEncoder.encode(keys[i]); - } - mget(bkeys); + final byte[][] bkeys = new byte[keys.length][]; + for (int i = 0; i < bkeys.length; i++) { + bkeys[i] = SafeEncoder.encode(keys[i]); + } + mget(bkeys); } public void setnx(final String key, final String value) { - setnx(SafeEncoder.encode(key), SafeEncoder.encode(value)); + setnx(SafeEncoder.encode(key), SafeEncoder.encode(value)); } public void setex(final String key, final int seconds, final String value) { - setex(SafeEncoder.encode(key), seconds, SafeEncoder.encode(value)); + setex(SafeEncoder.encode(key), seconds, SafeEncoder.encode(value)); } public void mset(final String... keysvalues) { - final byte[][] bkeysvalues = new byte[keysvalues.length][]; - for (int i = 0; i < keysvalues.length; i++) { - bkeysvalues[i] = SafeEncoder.encode(keysvalues[i]); - } - mset(bkeysvalues); + final byte[][] bkeysvalues = new byte[keysvalues.length][]; + for (int i = 0; i < keysvalues.length; i++) { + bkeysvalues[i] = SafeEncoder.encode(keysvalues[i]); + } + mset(bkeysvalues); } public void msetnx(final String... keysvalues) { - final byte[][] bkeysvalues = new byte[keysvalues.length][]; - for (int i = 0; i < keysvalues.length; i++) { - bkeysvalues[i] = SafeEncoder.encode(keysvalues[i]); - } - msetnx(bkeysvalues); + final byte[][] bkeysvalues = new byte[keysvalues.length][]; + for (int i = 0; i < keysvalues.length; i++) { + bkeysvalues[i] = SafeEncoder.encode(keysvalues[i]); + } + msetnx(bkeysvalues); } public void decrBy(final String key, final long integer) { - decrBy(SafeEncoder.encode(key), integer); + decrBy(SafeEncoder.encode(key), integer); } public void decr(final String key) { - decr(SafeEncoder.encode(key)); + decr(SafeEncoder.encode(key)); } public void incrBy(final String key, final long integer) { - incrBy(SafeEncoder.encode(key), integer); + incrBy(SafeEncoder.encode(key), integer); } public void incr(final String key) { - incr(SafeEncoder.encode(key)); + incr(SafeEncoder.encode(key)); } public void append(final String key, final String value) { - append(SafeEncoder.encode(key), SafeEncoder.encode(value)); + append(SafeEncoder.encode(key), SafeEncoder.encode(value)); } public void substr(final String key, final int start, final int end) { - substr(SafeEncoder.encode(key), start, end); + substr(SafeEncoder.encode(key), start, end); } public void hset(final String key, final String field, final String value) { - hset(SafeEncoder.encode(key), SafeEncoder.encode(field), - SafeEncoder.encode(value)); + hset(SafeEncoder.encode(key), SafeEncoder.encode(field), + SafeEncoder.encode(value)); } public void hget(final String key, final String field) { - hget(SafeEncoder.encode(key), SafeEncoder.encode(field)); + hget(SafeEncoder.encode(key), SafeEncoder.encode(field)); } public void hsetnx(final String key, final String field, final String value) { - hsetnx(SafeEncoder.encode(key), SafeEncoder.encode(field), - SafeEncoder.encode(value)); + hsetnx(SafeEncoder.encode(key), SafeEncoder.encode(field), + SafeEncoder.encode(value)); } public void hmset(final String key, final Map hash) { - final Map bhash = new HashMap( - hash.size()); - for (final Entry entry : hash.entrySet()) { - bhash.put(SafeEncoder.encode(entry.getKey()), - SafeEncoder.encode(entry.getValue())); - } - hmset(SafeEncoder.encode(key), bhash); + final Map bhash = new HashMap( + hash.size()); + for (final Entry entry : hash.entrySet()) { + bhash.put(SafeEncoder.encode(entry.getKey()), + SafeEncoder.encode(entry.getValue())); + } + hmset(SafeEncoder.encode(key), bhash); } public void hmget(final String key, final String... fields) { - final byte[][] bfields = new byte[fields.length][]; - for (int i = 0; i < bfields.length; i++) { - bfields[i] = SafeEncoder.encode(fields[i]); - } - hmget(SafeEncoder.encode(key), bfields); + final byte[][] bfields = new byte[fields.length][]; + for (int i = 0; i < bfields.length; i++) { + bfields[i] = SafeEncoder.encode(fields[i]); + } + hmget(SafeEncoder.encode(key), bfields); } public void hincrBy(final String key, final String field, final long value) { - hincrBy(SafeEncoder.encode(key), SafeEncoder.encode(field), value); + hincrBy(SafeEncoder.encode(key), SafeEncoder.encode(field), value); } public void hexists(final String key, final String field) { - hexists(SafeEncoder.encode(key), SafeEncoder.encode(field)); + hexists(SafeEncoder.encode(key), SafeEncoder.encode(field)); } public void hdel(final String key, final String... fields) { - hdel(SafeEncoder.encode(key), SafeEncoder.encodeMany(fields)); + hdel(SafeEncoder.encode(key), SafeEncoder.encodeMany(fields)); } public void hlen(final String key) { - hlen(SafeEncoder.encode(key)); + hlen(SafeEncoder.encode(key)); } public void hkeys(final String key) { - hkeys(SafeEncoder.encode(key)); + hkeys(SafeEncoder.encode(key)); } public void hvals(final String key) { - hvals(SafeEncoder.encode(key)); + hvals(SafeEncoder.encode(key)); } public void hgetAll(final String key) { - hgetAll(SafeEncoder.encode(key)); + hgetAll(SafeEncoder.encode(key)); } public void rpush(final String key, final String... string) { - rpush(SafeEncoder.encode(key), SafeEncoder.encodeMany(string)); + rpush(SafeEncoder.encode(key), SafeEncoder.encodeMany(string)); } public void lpush(final String key, final String... string) { - lpush(SafeEncoder.encode(key), SafeEncoder.encodeMany(string)); + lpush(SafeEncoder.encode(key), SafeEncoder.encodeMany(string)); } public void llen(final String key) { - llen(SafeEncoder.encode(key)); + llen(SafeEncoder.encode(key)); } public void lrange(final String key, final long start, final long end) { - lrange(SafeEncoder.encode(key), start, end); + lrange(SafeEncoder.encode(key), start, end); } public void ltrim(final String key, final long start, final long end) { - ltrim(SafeEncoder.encode(key), start, end); + ltrim(SafeEncoder.encode(key), start, end); } public void lindex(final String key, final long index) { - lindex(SafeEncoder.encode(key), index); + lindex(SafeEncoder.encode(key), index); } public void lset(final String key, final long index, final String value) { - lset(SafeEncoder.encode(key), index, SafeEncoder.encode(value)); + lset(SafeEncoder.encode(key), index, SafeEncoder.encode(value)); } public void lrem(final String key, long count, final String value) { - lrem(SafeEncoder.encode(key), count, SafeEncoder.encode(value)); + lrem(SafeEncoder.encode(key), count, SafeEncoder.encode(value)); } public void lpop(final String key) { - lpop(SafeEncoder.encode(key)); + lpop(SafeEncoder.encode(key)); } public void rpop(final String key) { - rpop(SafeEncoder.encode(key)); + rpop(SafeEncoder.encode(key)); } public void rpoplpush(final String srckey, final String dstkey) { - rpoplpush(SafeEncoder.encode(srckey), SafeEncoder.encode(dstkey)); + rpoplpush(SafeEncoder.encode(srckey), SafeEncoder.encode(dstkey)); } public void sadd(final String key, final String... members) { - sadd(SafeEncoder.encode(key), SafeEncoder.encodeMany(members)); + sadd(SafeEncoder.encode(key), SafeEncoder.encodeMany(members)); } public void smembers(final String key) { - smembers(SafeEncoder.encode(key)); + smembers(SafeEncoder.encode(key)); } public void srem(final String key, final String... members) { - srem(SafeEncoder.encode(key), SafeEncoder.encodeMany(members)); + srem(SafeEncoder.encode(key), SafeEncoder.encodeMany(members)); } public void spop(final String key) { - spop(SafeEncoder.encode(key)); + spop(SafeEncoder.encode(key)); } public void smove(final String srckey, final String dstkey, - final String member) { - smove(SafeEncoder.encode(srckey), SafeEncoder.encode(dstkey), - SafeEncoder.encode(member)); + final String member) { + smove(SafeEncoder.encode(srckey), SafeEncoder.encode(dstkey), + SafeEncoder.encode(member)); } public void scard(final String key) { - scard(SafeEncoder.encode(key)); + scard(SafeEncoder.encode(key)); } public void sismember(final String key, final String member) { - sismember(SafeEncoder.encode(key), SafeEncoder.encode(member)); + sismember(SafeEncoder.encode(key), SafeEncoder.encode(member)); } public void sinter(final String... keys) { - final byte[][] bkeys = new byte[keys.length][]; - for (int i = 0; i < bkeys.length; i++) { - bkeys[i] = SafeEncoder.encode(keys[i]); - } - sinter(bkeys); + final byte[][] bkeys = new byte[keys.length][]; + for (int i = 0; i < bkeys.length; i++) { + bkeys[i] = SafeEncoder.encode(keys[i]); + } + sinter(bkeys); } public void sinterstore(final String dstkey, final String... keys) { - final byte[][] bkeys = new byte[keys.length][]; - for (int i = 0; i < bkeys.length; i++) { - bkeys[i] = SafeEncoder.encode(keys[i]); - } - sinterstore(SafeEncoder.encode(dstkey), bkeys); + final byte[][] bkeys = new byte[keys.length][]; + for (int i = 0; i < bkeys.length; i++) { + bkeys[i] = SafeEncoder.encode(keys[i]); + } + sinterstore(SafeEncoder.encode(dstkey), bkeys); } public void sunion(final String... keys) { - final byte[][] bkeys = new byte[keys.length][]; - for (int i = 0; i < bkeys.length; i++) { - bkeys[i] = SafeEncoder.encode(keys[i]); - } - sunion(bkeys); + final byte[][] bkeys = new byte[keys.length][]; + for (int i = 0; i < bkeys.length; i++) { + bkeys[i] = SafeEncoder.encode(keys[i]); + } + sunion(bkeys); } public void sunionstore(final String dstkey, final String... keys) { - final byte[][] bkeys = new byte[keys.length][]; - for (int i = 0; i < bkeys.length; i++) { - bkeys[i] = SafeEncoder.encode(keys[i]); - } - sunionstore(SafeEncoder.encode(dstkey), bkeys); + final byte[][] bkeys = new byte[keys.length][]; + for (int i = 0; i < bkeys.length; i++) { + bkeys[i] = SafeEncoder.encode(keys[i]); + } + sunionstore(SafeEncoder.encode(dstkey), bkeys); } public void sdiff(final String... keys) { - final byte[][] bkeys = new byte[keys.length][]; - for (int i = 0; i < bkeys.length; i++) { - bkeys[i] = SafeEncoder.encode(keys[i]); - } - sdiff(bkeys); + final byte[][] bkeys = new byte[keys.length][]; + for (int i = 0; i < bkeys.length; i++) { + bkeys[i] = SafeEncoder.encode(keys[i]); + } + sdiff(bkeys); } public void sdiffstore(final String dstkey, final String... keys) { - final byte[][] bkeys = new byte[keys.length][]; - for (int i = 0; i < bkeys.length; i++) { - bkeys[i] = SafeEncoder.encode(keys[i]); - } - sdiffstore(SafeEncoder.encode(dstkey), bkeys); + final byte[][] bkeys = new byte[keys.length][]; + for (int i = 0; i < bkeys.length; i++) { + bkeys[i] = SafeEncoder.encode(keys[i]); + } + sdiffstore(SafeEncoder.encode(dstkey), bkeys); } public void srandmember(final String key) { - srandmember(SafeEncoder.encode(key)); + srandmember(SafeEncoder.encode(key)); } public void zadd(final String key, final double score, final String member) { - zadd(SafeEncoder.encode(key), score, SafeEncoder.encode(member)); + zadd(SafeEncoder.encode(key), score, SafeEncoder.encode(member)); } public void zrange(final String key, final long start, final long end) { - zrange(SafeEncoder.encode(key), start, end); + zrange(SafeEncoder.encode(key), start, end); } public void zrem(final String key, final String... members) { - zrem(SafeEncoder.encode(key), SafeEncoder.encodeMany(members)); + zrem(SafeEncoder.encode(key), SafeEncoder.encodeMany(members)); } public void zincrby(final String key, final double score, - final String member) { - zincrby(SafeEncoder.encode(key), score, SafeEncoder.encode(member)); + final String member) { + zincrby(SafeEncoder.encode(key), score, SafeEncoder.encode(member)); } public void zrank(final String key, final String member) { - zrank(SafeEncoder.encode(key), SafeEncoder.encode(member)); + zrank(SafeEncoder.encode(key), SafeEncoder.encode(member)); } public void zrevrank(final String key, final String member) { - zrevrank(SafeEncoder.encode(key), SafeEncoder.encode(member)); + zrevrank(SafeEncoder.encode(key), SafeEncoder.encode(member)); } public void zrevrange(final String key, final long start, final long end) { - zrevrange(SafeEncoder.encode(key), start, end); + zrevrange(SafeEncoder.encode(key), start, end); } public void zrangeWithScores(final String key, final long start, - final long end) { - zrangeWithScores(SafeEncoder.encode(key), start, end); + final long end) { + zrangeWithScores(SafeEncoder.encode(key), start, end); } public void zrevrangeWithScores(final String key, final long start, - final long end) { - zrevrangeWithScores(SafeEncoder.encode(key), start, end); + final long end) { + zrevrangeWithScores(SafeEncoder.encode(key), start, end); } public void zcard(final String key) { - zcard(SafeEncoder.encode(key)); + zcard(SafeEncoder.encode(key)); } public void zscore(final String key, final String member) { - zscore(SafeEncoder.encode(key), SafeEncoder.encode(member)); + zscore(SafeEncoder.encode(key), SafeEncoder.encode(member)); } public void watch(final String... keys) { - final byte[][] bargs = new byte[keys.length][]; - for (int i = 0; i < bargs.length; i++) { - bargs[i] = SafeEncoder.encode(keys[i]); - } - watch(bargs); + final byte[][] bargs = new byte[keys.length][]; + for (int i = 0; i < bargs.length; i++) { + bargs[i] = SafeEncoder.encode(keys[i]); + } + watch(bargs); } public void sort(final String key) { - sort(SafeEncoder.encode(key)); + sort(SafeEncoder.encode(key)); } public void sort(final String key, final SortingParams sortingParameters) { - sort(SafeEncoder.encode(key), sortingParameters); + sort(SafeEncoder.encode(key), sortingParameters); } public void blpop(final String[] args) { - final byte[][] bargs = new byte[args.length][]; - for (int i = 0; i < bargs.length; i++) { - bargs[i] = SafeEncoder.encode(args[i]); - } - blpop(bargs); + final byte[][] bargs = new byte[args.length][]; + for (int i = 0; i < bargs.length; i++) { + bargs[i] = SafeEncoder.encode(args[i]); + } + blpop(bargs); } public void blpop(final int timeout, final String... keys) { - List args = new ArrayList(); - for (String arg : keys) { - args.add(arg); - } - args.add(String.valueOf(timeout)); - blpop(args.toArray(new String[args.size()])); + List args = new ArrayList(); + for (String arg : keys) { + args.add(arg); + } + args.add(String.valueOf(timeout)); + blpop(args.toArray(new String[args.size()])); } public void sort(final String key, final SortingParams sortingParameters, - final String dstkey) { - sort(SafeEncoder.encode(key), sortingParameters, - SafeEncoder.encode(dstkey)); + final String dstkey) { + sort(SafeEncoder.encode(key), sortingParameters, + SafeEncoder.encode(dstkey)); } public void sort(final String key, final String dstkey) { - sort(SafeEncoder.encode(key), SafeEncoder.encode(dstkey)); + sort(SafeEncoder.encode(key), SafeEncoder.encode(dstkey)); } public void brpop(final String[] args) { - final byte[][] bargs = new byte[args.length][]; - for (int i = 0; i < bargs.length; i++) { - bargs[i] = SafeEncoder.encode(args[i]); - } - brpop(bargs); + final byte[][] bargs = new byte[args.length][]; + for (int i = 0; i < bargs.length; i++) { + bargs[i] = SafeEncoder.encode(args[i]); + } + brpop(bargs); } public void brpop(final int timeout, final String... keys) { - List args = new ArrayList(); - for (String arg : keys) { - args.add(arg); - } - args.add(String.valueOf(timeout)); - brpop(args.toArray(new String[args.size()])); + List args = new ArrayList(); + for (String arg : keys) { + args.add(arg); + } + args.add(String.valueOf(timeout)); + brpop(args.toArray(new String[args.size()])); } public void zcount(final String key, final double min, final double max) { - zcount(SafeEncoder.encode(key), toByteArray(min), toByteArray(max)); + zcount(SafeEncoder.encode(key), toByteArray(min), toByteArray(max)); } public void zcount(final String key, final String min, final String max) { - zcount(SafeEncoder.encode(key), SafeEncoder.encode(min), - SafeEncoder.encode(max)); + zcount(SafeEncoder.encode(key), SafeEncoder.encode(min), + SafeEncoder.encode(max)); } public void zrangeByScore(final String key, final double min, - final double max) { - zrangeByScore(SafeEncoder.encode(key), toByteArray(min), - toByteArray(max)); + final double max) { + zrangeByScore(SafeEncoder.encode(key), toByteArray(min), + toByteArray(max)); } public void zrangeByScore(final String key, final String min, - final String max) { - zrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(min), - SafeEncoder.encode(max)); + final String max) { + zrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(min), + SafeEncoder.encode(max)); } public void zrangeByScore(final String key, final double min, - final double max, final int offset, int count) { - zrangeByScore(SafeEncoder.encode(key), toByteArray(min), - toByteArray(max), offset, count); + final double max, final int offset, int count) { + zrangeByScore(SafeEncoder.encode(key), toByteArray(min), + toByteArray(max), offset, count); } public void zrangeByScoreWithScores(final String key, final double min, - final double max) { - zrangeByScoreWithScores(SafeEncoder.encode(key), toByteArray(min), - toByteArray(max)); + final double max) { + zrangeByScoreWithScores(SafeEncoder.encode(key), toByteArray(min), + toByteArray(max)); } public void zrangeByScoreWithScores(final String key, final double min, - final double max, final int offset, final int count) { - zrangeByScoreWithScores(SafeEncoder.encode(key), toByteArray(min), - toByteArray(max), offset, count); + final double max, final int offset, final int count) { + zrangeByScoreWithScores(SafeEncoder.encode(key), toByteArray(min), + toByteArray(max), offset, count); } public void zrevrangeByScore(final String key, final double max, - final double min) { - zrevrangeByScore(SafeEncoder.encode(key), toByteArray(max), - toByteArray(min)); + final double min) { + zrevrangeByScore(SafeEncoder.encode(key), toByteArray(max), + toByteArray(min)); } public void zrangeByScore(final String key, final String min, - final String max, final int offset, int count) { - zrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(min), - SafeEncoder.encode(max), offset, count); + final String max, final int offset, int count) { + zrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(min), + SafeEncoder.encode(max), offset, count); } public void zrangeByScoreWithScores(final String key, final String min, - final String max) { - zrangeByScoreWithScores(SafeEncoder.encode(key), - SafeEncoder.encode(min), SafeEncoder.encode(max)); + final String max) { + zrangeByScoreWithScores(SafeEncoder.encode(key), + SafeEncoder.encode(min), SafeEncoder.encode(max)); } public void zrangeByScoreWithScores(final String key, final String min, - final String max, final int offset, final int count) { - zrangeByScoreWithScores(SafeEncoder.encode(key), - SafeEncoder.encode(min), SafeEncoder.encode(max), offset, count); + final String max, final int offset, final int count) { + zrangeByScoreWithScores(SafeEncoder.encode(key), + SafeEncoder.encode(min), SafeEncoder.encode(max), offset, count); } public void zrevrangeByScore(final String key, final String max, - final String min) { - zrevrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(max), - SafeEncoder.encode(min)); + final String min) { + zrevrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(max), + SafeEncoder.encode(min)); } public void zrevrangeByScore(final String key, final double max, - final double min, final int offset, int count) { - zrevrangeByScore(SafeEncoder.encode(key), toByteArray(max), - toByteArray(min), offset, count); + final double min, final int offset, int count) { + zrevrangeByScore(SafeEncoder.encode(key), toByteArray(max), + toByteArray(min), offset, count); } public void zrevrangeByScore(final String key, final String max, - final String min, final int offset, int count) { - zrevrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(max), - SafeEncoder.encode(min), offset, count); + final String min, final int offset, int count) { + zrevrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(max), + SafeEncoder.encode(min), offset, count); } public void zrevrangeByScoreWithScores(final String key, final double max, - final double min) { - zrevrangeByScoreWithScores(SafeEncoder.encode(key), toByteArray(max), - toByteArray(min)); + final double min) { + zrevrangeByScoreWithScores(SafeEncoder.encode(key), toByteArray(max), + toByteArray(min)); } public void zrevrangeByScoreWithScores(final String key, final String max, - final String min) { - zrevrangeByScoreWithScores(SafeEncoder.encode(key), - SafeEncoder.encode(max), SafeEncoder.encode(min)); + final String min) { + zrevrangeByScoreWithScores(SafeEncoder.encode(key), + SafeEncoder.encode(max), SafeEncoder.encode(min)); } public void zrevrangeByScoreWithScores(final String key, final double max, - final double min, final int offset, final int count) { - zrevrangeByScoreWithScores(SafeEncoder.encode(key), toByteArray(max), - toByteArray(min), offset, count); + final double min, final int offset, final int count) { + zrevrangeByScoreWithScores(SafeEncoder.encode(key), toByteArray(max), + toByteArray(min), offset, count); } public void zrevrangeByScoreWithScores(final String key, final String max, - final String min, final int offset, final int count) { - zrevrangeByScoreWithScores(SafeEncoder.encode(key), - SafeEncoder.encode(max), SafeEncoder.encode(min), offset, count); + final String min, final int offset, final int count) { + zrevrangeByScoreWithScores(SafeEncoder.encode(key), + SafeEncoder.encode(max), SafeEncoder.encode(min), offset, count); } public void zremrangeByRank(final String key, final long start, - final long end) { - zremrangeByRank(SafeEncoder.encode(key), start, end); + final long end) { + zremrangeByRank(SafeEncoder.encode(key), start, end); } public void zremrangeByScore(final String key, final double start, - final double end) { - zremrangeByScore(SafeEncoder.encode(key), toByteArray(start), - toByteArray(end)); + final double end) { + zremrangeByScore(SafeEncoder.encode(key), toByteArray(start), + toByteArray(end)); } public void zremrangeByScore(final String key, final String start, - final String end) { - zremrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(start), - SafeEncoder.encode(end)); + final String end) { + zremrangeByScore(SafeEncoder.encode(key), SafeEncoder.encode(start), + SafeEncoder.encode(end)); } public void zunionstore(final String dstkey, final String... sets) { - final byte[][] bsets = new byte[sets.length][]; - for (int i = 0; i < bsets.length; i++) { - bsets[i] = SafeEncoder.encode(sets[i]); - } - zunionstore(SafeEncoder.encode(dstkey), bsets); + final byte[][] bsets = new byte[sets.length][]; + for (int i = 0; i < bsets.length; i++) { + bsets[i] = SafeEncoder.encode(sets[i]); + } + zunionstore(SafeEncoder.encode(dstkey), bsets); } public void zunionstore(final String dstkey, final ZParams params, - final String... sets) { - final byte[][] bsets = new byte[sets.length][]; - for (int i = 0; i < bsets.length; i++) { - bsets[i] = SafeEncoder.encode(sets[i]); - } - zunionstore(SafeEncoder.encode(dstkey), params, bsets); + final String... sets) { + final byte[][] bsets = new byte[sets.length][]; + for (int i = 0; i < bsets.length; i++) { + bsets[i] = SafeEncoder.encode(sets[i]); + } + zunionstore(SafeEncoder.encode(dstkey), params, bsets); } public void zinterstore(final String dstkey, final String... sets) { - final byte[][] bsets = new byte[sets.length][]; - for (int i = 0; i < bsets.length; i++) { - bsets[i] = SafeEncoder.encode(sets[i]); - } - zinterstore(SafeEncoder.encode(dstkey), bsets); + final byte[][] bsets = new byte[sets.length][]; + for (int i = 0; i < bsets.length; i++) { + bsets[i] = SafeEncoder.encode(sets[i]); + } + zinterstore(SafeEncoder.encode(dstkey), bsets); } public void zinterstore(final String dstkey, final ZParams params, - final String... sets) { - final byte[][] bsets = new byte[sets.length][]; - for (int i = 0; i < bsets.length; i++) { - bsets[i] = SafeEncoder.encode(sets[i]); - } - zinterstore(SafeEncoder.encode(dstkey), params, bsets); + final String... sets) { + final byte[][] bsets = new byte[sets.length][]; + for (int i = 0; i < bsets.length; i++) { + bsets[i] = SafeEncoder.encode(sets[i]); + } + zinterstore(SafeEncoder.encode(dstkey), params, bsets); } 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); + 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); + int 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)); + final String max) { + zremrangeByLex(SafeEncoder.encode(key), SafeEncoder.encode(min), + SafeEncoder.encode(max)); } public void strlen(final String key) { - strlen(SafeEncoder.encode(key)); + strlen(SafeEncoder.encode(key)); } public void lpushx(final String key, final String... string) { - lpushx(SafeEncoder.encode(key), getByteParams(string)); + lpushx(SafeEncoder.encode(key), getByteParams(string)); } public void persist(final String key) { - persist(SafeEncoder.encode(key)); + persist(SafeEncoder.encode(key)); } public void rpushx(final String key, final String... string) { - rpushx(SafeEncoder.encode(key), getByteParams(string)); + rpushx(SafeEncoder.encode(key), getByteParams(string)); } public void echo(final String string) { - echo(SafeEncoder.encode(string)); + echo(SafeEncoder.encode(string)); } public void linsert(final String key, final LIST_POSITION where, - final String pivot, final String value) { - linsert(SafeEncoder.encode(key), where, SafeEncoder.encode(pivot), - SafeEncoder.encode(value)); + final String pivot, final String value) { + linsert(SafeEncoder.encode(key), where, SafeEncoder.encode(pivot), + SafeEncoder.encode(value)); } public void brpoplpush(String source, String destination, int timeout) { - brpoplpush(SafeEncoder.encode(source), SafeEncoder.encode(destination), - timeout); + brpoplpush(SafeEncoder.encode(source), SafeEncoder.encode(destination), + timeout); } public void setbit(final String key, final long offset, final boolean value) { - setbit(SafeEncoder.encode(key), offset, value); + setbit(SafeEncoder.encode(key), offset, value); } public void setbit(final String key, final long offset, final String value) { - setbit(SafeEncoder.encode(key), offset, SafeEncoder.encode(value)); + setbit(SafeEncoder.encode(key), offset, SafeEncoder.encode(value)); } public void getbit(String key, long offset) { - getbit(SafeEncoder.encode(key), offset); + getbit(SafeEncoder.encode(key), offset); } public void bitpos(final String key, final boolean value, - final BitPosParams params) { - bitpos(SafeEncoder.encode(key), value, params); + 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)); + setrange(SafeEncoder.encode(key), offset, SafeEncoder.encode(value)); } public void getrange(String key, long startOffset, long endOffset) { - getrange(SafeEncoder.encode(key), startOffset, endOffset); + getrange(SafeEncoder.encode(key), startOffset, endOffset); } public void publish(final String channel, final String message) { - publish(SafeEncoder.encode(channel), SafeEncoder.encode(message)); + publish(SafeEncoder.encode(channel), SafeEncoder.encode(message)); } public void unsubscribe(final String... channels) { - final byte[][] cs = new byte[channels.length][]; - for (int i = 0; i < cs.length; i++) { - cs[i] = SafeEncoder.encode(channels[i]); - } - unsubscribe(cs); + final byte[][] cs = new byte[channels.length][]; + for (int i = 0; i < cs.length; i++) { + cs[i] = SafeEncoder.encode(channels[i]); + } + unsubscribe(cs); } public void psubscribe(final String... patterns) { - final byte[][] ps = new byte[patterns.length][]; - for (int i = 0; i < ps.length; i++) { - ps[i] = SafeEncoder.encode(patterns[i]); - } - psubscribe(ps); + final byte[][] ps = new byte[patterns.length][]; + for (int i = 0; i < ps.length; i++) { + ps[i] = SafeEncoder.encode(patterns[i]); + } + psubscribe(ps); } public void punsubscribe(final String... patterns) { - final byte[][] ps = new byte[patterns.length][]; - for (int i = 0; i < ps.length; i++) { - ps[i] = SafeEncoder.encode(patterns[i]); - } - punsubscribe(ps); + final byte[][] ps = new byte[patterns.length][]; + for (int i = 0; i < ps.length; i++) { + ps[i] = SafeEncoder.encode(patterns[i]); + } + punsubscribe(ps); } public void subscribe(final String... channels) { - final byte[][] cs = new byte[channels.length][]; - for (int i = 0; i < cs.length; i++) { - cs[i] = SafeEncoder.encode(channels[i]); - } - subscribe(cs); + final byte[][] cs = new byte[channels.length][]; + for (int i = 0; i < cs.length; i++) { + cs[i] = SafeEncoder.encode(channels[i]); + } + subscribe(cs); } public void pubsubChannels(String pattern) { - pubsub(Protocol.PUBSUB_CHANNELS, pattern); + pubsub(Protocol.PUBSUB_CHANNELS, pattern); } public void pubsubNumPat() { - pubsub(Protocol.PUBSUB_NUM_PAT); + pubsub(Protocol.PUBSUB_NUM_PAT); } public void pubsubNumSub(String... channels) { - pubsub(Protocol.PUBSUB_NUMSUB, channels); + pubsub(Protocol.PUBSUB_NUMSUB, channels); } public void configSet(String parameter, String value) { - configSet(SafeEncoder.encode(parameter), SafeEncoder.encode(value)); + configSet(SafeEncoder.encode(parameter), SafeEncoder.encode(value)); } public void configGet(String pattern) { - configGet(SafeEncoder.encode(pattern)); + configGet(SafeEncoder.encode(pattern)); } private byte[][] getByteParams(String... params) { - byte[][] p = new byte[params.length][]; - for (int i = 0; i < params.length; i++) - p[i] = SafeEncoder.encode(params[i]); + byte[][] p = new byte[params.length][]; + for (int i = 0; i < params.length; i++) + p[i] = SafeEncoder.encode(params[i]); - return p; + return p; } public void eval(String script, int keyCount, String... params) { - eval(SafeEncoder.encode(script), toByteArray(keyCount), - getByteParams(params)); + eval(SafeEncoder.encode(script), toByteArray(keyCount), + getByteParams(params)); } public void evalsha(String sha1, int keyCount, String... params) { - evalsha(SafeEncoder.encode(sha1), toByteArray(keyCount), - getByteParams(params)); + evalsha(SafeEncoder.encode(sha1), toByteArray(keyCount), + getByteParams(params)); } public void scriptExists(String... sha1) { - final byte[][] bsha1 = new byte[sha1.length][]; - for (int i = 0; i < bsha1.length; i++) { - bsha1[i] = SafeEncoder.encode(sha1[i]); - } - scriptExists(bsha1); + final byte[][] bsha1 = new byte[sha1.length][]; + for (int i = 0; i < bsha1.length; i++) { + bsha1[i] = SafeEncoder.encode(sha1[i]); + } + scriptExists(bsha1); } public void scriptLoad(String script) { - scriptLoad(SafeEncoder.encode(script)); + scriptLoad(SafeEncoder.encode(script)); } public void zadd(String key, Map scoreMembers) { - HashMap binaryScoreMembers = new HashMap(); + HashMap binaryScoreMembers = new HashMap(); - for (Map.Entry entry : scoreMembers.entrySet()) { + for (Map.Entry entry : scoreMembers.entrySet()) { - binaryScoreMembers.put(SafeEncoder.encode(entry.getKey()), - entry.getValue()); - } + binaryScoreMembers.put(SafeEncoder.encode(entry.getKey()), + entry.getValue()); + } - zaddBinary(SafeEncoder.encode(key), binaryScoreMembers); + zaddBinary(SafeEncoder.encode(key), binaryScoreMembers); } public void objectRefcount(String key) { - objectRefcount(SafeEncoder.encode(key)); + objectRefcount(SafeEncoder.encode(key)); } public void objectIdletime(String key) { - objectIdletime(SafeEncoder.encode(key)); + objectIdletime(SafeEncoder.encode(key)); } public void objectEncoding(String key) { - objectEncoding(SafeEncoder.encode(key)); + objectEncoding(SafeEncoder.encode(key)); } public void bitcount(final String key) { - bitcount(SafeEncoder.encode(key)); + bitcount(SafeEncoder.encode(key)); } public void bitcount(final String key, long start, long end) { - bitcount(SafeEncoder.encode(key), start, end); + bitcount(SafeEncoder.encode(key), start, end); } public void bitop(BitOP op, final String destKey, String... srcKeys) { - bitop(op, SafeEncoder.encode(destKey), getByteParams(srcKeys)); + bitop(op, SafeEncoder.encode(destKey), getByteParams(srcKeys)); } public void sentinel(final String... args) { - final byte[][] arg = new byte[args.length][]; - for (int i = 0; i < arg.length; i++) { - arg[i] = SafeEncoder.encode(args[i]); - } - sentinel(arg); + final byte[][] arg = new byte[args.length][]; + for (int i = 0; i < arg.length; i++) { + arg[i] = SafeEncoder.encode(args[i]); + } + sentinel(arg); } public void dump(final String key) { - dump(SafeEncoder.encode(key)); + dump(SafeEncoder.encode(key)); } public void restore(final String key, final int ttl, - final byte[] serializedValue) { - restore(SafeEncoder.encode(key), ttl, serializedValue); + final byte[] serializedValue) { + restore(SafeEncoder.encode(key), ttl, serializedValue); } public void pexpire(final String key, final long milliseconds) { - pexpire(SafeEncoder.encode(key), milliseconds); + pexpire(SafeEncoder.encode(key), milliseconds); } public void pexpireAt(final String key, final long millisecondsTimestamp) { - pexpireAt(SafeEncoder.encode(key), millisecondsTimestamp); + pexpireAt(SafeEncoder.encode(key), millisecondsTimestamp); } public void pttl(final String key) { - pttl(SafeEncoder.encode(key)); + pttl(SafeEncoder.encode(key)); } public void incrByFloat(final String key, final double increment) { - incrByFloat(SafeEncoder.encode(key), increment); + incrByFloat(SafeEncoder.encode(key), increment); } public void psetex(final String key, final int milliseconds, - final String value) { - psetex(SafeEncoder.encode(key), milliseconds, SafeEncoder.encode(value)); + final String value) { + psetex(SafeEncoder.encode(key), milliseconds, SafeEncoder.encode(value)); } public void set(final String key, final String value, final String nxxx) { - set(SafeEncoder.encode(key), SafeEncoder.encode(value), - SafeEncoder.encode(nxxx)); + set(SafeEncoder.encode(key), SafeEncoder.encode(value), + SafeEncoder.encode(nxxx)); } public void set(final String key, final String value, final String nxxx, - final String expx, final int time) { - set(SafeEncoder.encode(key), SafeEncoder.encode(value), - SafeEncoder.encode(nxxx), SafeEncoder.encode(expx), time); + final String expx, final int time) { + set(SafeEncoder.encode(key), SafeEncoder.encode(value), + SafeEncoder.encode(nxxx), SafeEncoder.encode(expx), time); } public void srandmember(final String key, final int count) { - srandmember(SafeEncoder.encode(key), count); + srandmember(SafeEncoder.encode(key), count); } public void clientKill(final String client) { - clientKill(SafeEncoder.encode(client)); + clientKill(SafeEncoder.encode(client)); } public void clientSetname(final String name) { - clientSetname(SafeEncoder.encode(name)); + clientSetname(SafeEncoder.encode(name)); } public void migrate(final String host, final int port, final String key, - final int destinationDb, final int timeout) { - migrate(SafeEncoder.encode(host), port, SafeEncoder.encode(key), - destinationDb, timeout); + final int destinationDb, final int timeout) { + migrate(SafeEncoder.encode(host), port, SafeEncoder.encode(key), + destinationDb, timeout); } public void hincrByFloat(final String key, final String field, - double increment) { - hincrByFloat(SafeEncoder.encode(key), SafeEncoder.encode(field), - increment); + double increment) { + hincrByFloat(SafeEncoder.encode(key), SafeEncoder.encode(field), + increment); } public void scan(final String cursor, final ScanParams params) { - scan(SafeEncoder.encode(cursor), params); + scan(SafeEncoder.encode(cursor), params); } public void hscan(final String key, final String cursor, - final ScanParams params) { - hscan(SafeEncoder.encode(key), SafeEncoder.encode(cursor), params); + final ScanParams params) { + hscan(SafeEncoder.encode(key), SafeEncoder.encode(cursor), params); } public void sscan(final String key, final String cursor, - final ScanParams params) { - sscan(SafeEncoder.encode(key), SafeEncoder.encode(cursor), params); + final ScanParams params) { + sscan(SafeEncoder.encode(key), SafeEncoder.encode(cursor), params); } public void zscan(final String key, final String cursor, - final ScanParams params) { - zscan(SafeEncoder.encode(key), SafeEncoder.encode(cursor), params); + final ScanParams params) { + zscan(SafeEncoder.encode(key), SafeEncoder.encode(cursor), params); } public void cluster(final String subcommand, final int... args) { - final byte[][] arg = new byte[args.length + 1][]; - for (int i = 1; i < arg.length; i++) { - arg[i] = toByteArray(args[i - 1]); - } - arg[0] = SafeEncoder.encode(subcommand); - cluster(arg); + final byte[][] arg = new byte[args.length + 1][]; + for (int i = 1; i < arg.length; i++) { + arg[i] = toByteArray(args[i - 1]); + } + arg[0] = SafeEncoder.encode(subcommand); + cluster(arg); } public void pubsub(final String subcommand, final String... args) { - final byte[][] arg = new byte[args.length + 1][]; - for (int i = 1; i < arg.length; i++) { - arg[i] = SafeEncoder.encode(args[i - 1]); - } - arg[0] = SafeEncoder.encode(subcommand); - pubsub(arg); + final byte[][] arg = new byte[args.length + 1][]; + for (int i = 1; i < arg.length; i++) { + arg[i] = SafeEncoder.encode(args[i - 1]); + } + arg[0] = SafeEncoder.encode(subcommand); + pubsub(arg); } public void cluster(final String subcommand, final String... args) { - final byte[][] arg = new byte[args.length + 1][]; - for (int i = 1; i < arg.length; i++) { - arg[i] = SafeEncoder.encode(args[i - 1]); - } - arg[0] = SafeEncoder.encode(subcommand); - cluster(arg); + final byte[][] arg = new byte[args.length + 1][]; + for (int i = 1; i < arg.length; i++) { + arg[i] = SafeEncoder.encode(args[i - 1]); + } + arg[0] = SafeEncoder.encode(subcommand); + cluster(arg); } public void cluster(final String subcommand) { - final byte[][] arg = new byte[1][]; - arg[0] = SafeEncoder.encode(subcommand); - cluster(arg); + final byte[][] arg = new byte[1][]; + arg[0] = SafeEncoder.encode(subcommand); + cluster(arg); } public void clusterNodes() { - cluster(Protocol.CLUSTER_NODES); + cluster(Protocol.CLUSTER_NODES); } public void clusterMeet(final String ip, final int port) { - cluster(Protocol.CLUSTER_MEET, ip, String.valueOf(port)); + cluster(Protocol.CLUSTER_MEET, ip, String.valueOf(port)); } public void clusterReset(Reset resetType) { - cluster(Protocol.CLUSTER_RESET, resetType.toString()); + cluster(Protocol.CLUSTER_RESET, resetType.toString()); } public void clusterAddSlots(final int... slots) { - cluster(Protocol.CLUSTER_ADDSLOTS, slots); + cluster(Protocol.CLUSTER_ADDSLOTS, slots); } public void clusterDelSlots(final int... slots) { - cluster(Protocol.CLUSTER_DELSLOTS, slots); + cluster(Protocol.CLUSTER_DELSLOTS, slots); } public void clusterInfo() { - cluster(Protocol.CLUSTER_INFO); + cluster(Protocol.CLUSTER_INFO); } public void clusterGetKeysInSlot(final int slot, final int count) { - final int[] args = new int[] { slot, count }; - cluster(Protocol.CLUSTER_GETKEYSINSLOT, args); + final int[] args = new int[] { slot, count }; + cluster(Protocol.CLUSTER_GETKEYSINSLOT, args); } public void clusterSetSlotNode(final int slot, final String nodeId) { - cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot), - Protocol.CLUSTER_SETSLOT_NODE, nodeId); + cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot), + Protocol.CLUSTER_SETSLOT_NODE, nodeId); } public void clusterSetSlotMigrating(final int slot, final String nodeId) { - cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot), - Protocol.CLUSTER_SETSLOT_MIGRATING, nodeId); + cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot), + Protocol.CLUSTER_SETSLOT_MIGRATING, nodeId); } public void clusterSetSlotImporting(final int slot, final String nodeId) { - cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot), - Protocol.CLUSTER_SETSLOT_IMPORTING, nodeId); + cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot), + Protocol.CLUSTER_SETSLOT_IMPORTING, nodeId); } public void pfadd(String key, final String... elements) { - pfadd(SafeEncoder.encode(key), SafeEncoder.encodeMany(elements)); + pfadd(SafeEncoder.encode(key), SafeEncoder.encodeMany(elements)); } public void pfcount(final String key) { - pfcount(SafeEncoder.encode(key)); + pfcount(SafeEncoder.encode(key)); } public void pfcount(final String... keys) { - pfcount(SafeEncoder.encodeMany(keys)); + pfcount(SafeEncoder.encodeMany(keys)); } public void pfmerge(final String destkey, final String... sourcekeys) { - pfmerge(SafeEncoder.encode(destkey), SafeEncoder.encodeMany(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); + cluster(Protocol.CLUSTER_SETSLOT, String.valueOf(slot), + Protocol.CLUSTER_SETSLOT_STABLE); } public void clusterForget(final String nodeId) { - cluster(Protocol.CLUSTER_FORGET, nodeId); + cluster(Protocol.CLUSTER_FORGET, nodeId); } public void clusterFlushSlots() { - cluster(Protocol.CLUSTER_FLUSHSLOT); + cluster(Protocol.CLUSTER_FLUSHSLOT); } public void clusterKeySlot(final String key) { - cluster(Protocol.CLUSTER_KEYSLOT, key); + cluster(Protocol.CLUSTER_KEYSLOT, key); } public void clusterCountKeysInSlot(final int slot) { - cluster(Protocol.CLUSTER_COUNTKEYINSLOT, String.valueOf(slot)); + cluster(Protocol.CLUSTER_COUNTKEYINSLOT, String.valueOf(slot)); } public void clusterSaveConfig() { - cluster(Protocol.CLUSTER_SAVECONFIG); + cluster(Protocol.CLUSTER_SAVECONFIG); } public void clusterReplicate(final String nodeId) { - cluster(Protocol.CLUSTER_REPLICATE, nodeId); + cluster(Protocol.CLUSTER_REPLICATE, nodeId); } public void clusterSlaves(final String nodeId) { - cluster(Protocol.CLUSTER_SLAVES, nodeId); + cluster(Protocol.CLUSTER_SLAVES, nodeId); } public void clusterFailover() { - cluster(Protocol.CLUSTER_FAILOVER); + cluster(Protocol.CLUSTER_FAILOVER); } public void clusterSlots() { - cluster(Protocol.CLUSTER_SLOTS); + cluster(Protocol.CLUSTER_SLOTS); } } diff --git a/src/main/java/redis/clients/jedis/Commands.java b/src/main/java/redis/clients/jedis/Commands.java index 786f8a3..1f37e49 100644 --- a/src/main/java/redis/clients/jedis/Commands.java +++ b/src/main/java/redis/clients/jedis/Commands.java @@ -9,7 +9,7 @@ public interface Commands { public void set(final String key, final String value); public void set(final String key, final String value, final String nxxx, - final String expx, final long time); + final String expx, final long time); public void get(final String key); @@ -82,7 +82,7 @@ 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); + final double value); public void hexists(final String key, final String field); @@ -127,7 +127,7 @@ public interface Commands { public void spop(final String key); public void smove(final String srckey, final String dstkey, - final String member); + final String member); public void scard(final String key); @@ -156,7 +156,7 @@ public interface Commands { public void zrem(final String key, final String... members); public void zincrby(final String key, final double score, - final String member); + final String member); public void zrank(final String key, final String member); @@ -165,10 +165,10 @@ public interface Commands { public void zrevrange(final String key, final long start, final long end); public void zrangeWithScores(final String key, final long start, - final long end); + final long end); public void zrevrangeWithScores(final String key, final long start, - final long end); + final long end); public void zcard(final String key); @@ -183,79 +183,79 @@ public interface Commands { public void blpop(final String[] args); public void sort(final String key, final SortingParams sortingParameters, - final String dstkey); + final String dstkey); public void sort(final String key, final String dstkey); public void brpop(final String[] args); public void brpoplpush(final String source, final String destination, - final int timeout); + final int timeout); public void zcount(final String key, final double min, final double max); public void zcount(final String key, final String min, final String max); public void zrangeByScore(final String key, final double min, - final double max); + final double max); public void zrangeByScore(final String key, final String min, - final String max); + final String max); public void zrangeByScore(final String key, final double min, - final double max, final int offset, int count); + final double max, final int offset, int count); public void zrangeByScoreWithScores(final String key, final double min, - final double max); + final double max); public void zrangeByScoreWithScores(final String key, final double min, - final double max, final int offset, final int count); + final double max, final int offset, final int count); public void zrangeByScoreWithScores(final String key, final String min, - final String max); + final String max); public void zrangeByScoreWithScores(final String key, final String min, - final String max, final int offset, final int count); + final String max, final int offset, final int count); public void zrevrangeByScore(final String key, final double max, - final double min); + final double min); public void zrevrangeByScore(final String key, final String max, - final String min); + final String min); public void zrevrangeByScore(final String key, final double max, - final double min, final int offset, int count); + final double min, final int offset, int count); public void zrevrangeByScoreWithScores(final String key, final double max, - final double min); + final double min); public void zrevrangeByScoreWithScores(final String key, final double max, - final double min, final int offset, final int count); + final double min, final int offset, final int count); public void zrevrangeByScoreWithScores(final String key, final String max, - final String min); + final String min); public void zrevrangeByScoreWithScores(final String key, final String max, - final String min, final int offset, final int count); + final String min, final int offset, final int count); public void zremrangeByRank(final String key, final long start, - final long end); + final long end); public void zremrangeByScore(final String key, final double start, - final double end); + final double end); public void zremrangeByScore(final String key, final String start, - final String end); + final String end); public void zunionstore(final String dstkey, final String... sets); public void zunionstore(final String dstkey, final ZParams params, - final String... sets); + final String... sets); public void zinterstore(final String dstkey, final String... sets); public void zinterstore(final String dstkey, final ZParams params, - final String... sets); + final String... sets); public void strlen(final String key); @@ -268,7 +268,7 @@ public interface Commands { public void echo(final String string); public void linsert(final String key, final LIST_POSITION where, - final String pivot, final String value); + final String pivot, final String value); public void bgrewriteaof(); @@ -305,13 +305,13 @@ public interface Commands { public void scan(final String cursor, final ScanParams params); public void hscan(final String key, final String cursor, - final ScanParams params); + final ScanParams params); public void sscan(final String key, final String cursor, - final ScanParams params); + final ScanParams params); public void zscan(final String key, final String cursor, - final ScanParams params); + final ScanParams params); public void waitReplicas(int replicas, long timeout); } diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index 69562cb..003efb2 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -29,239 +29,239 @@ public class Connection implements Closeable { } public Connection(final String host) { - this.host = host; + this.host = host; } public Connection(final String host, final int port) { - this.host = host; - this.port = port; + this.host = host; + this.port = port; } public Socket getSocket() { - return socket; + return socket; } public int getTimeout() { - return timeout; + return timeout; } public void setTimeout(final int timeout) { - this.timeout = timeout; + this.timeout = timeout; } public void setTimeoutInfinite() { - try { - if (!isConnected()) { - connect(); - } - socket.setSoTimeout(0); - } catch (SocketException ex) { - broken = true; - throw new JedisConnectionException(ex); - } + try { + if (!isConnected()) { + connect(); + } + socket.setSoTimeout(0); + } catch (SocketException ex) { + broken = true; + throw new JedisConnectionException(ex); + } } public void rollbackTimeout() { - try { - socket.setSoTimeout(timeout); - } catch (SocketException ex) { - broken = true; - throw new JedisConnectionException(ex); - } + try { + socket.setSoTimeout(timeout); + } catch (SocketException ex) { + broken = true; + throw new JedisConnectionException(ex); + } } protected Connection sendCommand(final Command cmd, final String... args) { - final byte[][] bargs = new byte[args.length][]; - for (int i = 0; i < args.length; i++) { - bargs[i] = SafeEncoder.encode(args[i]); - } - return sendCommand(cmd, bargs); + final byte[][] bargs = new byte[args.length][]; + for (int i = 0; i < args.length; i++) { + bargs[i] = SafeEncoder.encode(args[i]); + } + return sendCommand(cmd, bargs); } protected Connection sendCommand(final Command cmd, final byte[]... args) { - try { - connect(); - Protocol.sendCommand(outputStream, cmd, args); - return this; - } catch (JedisConnectionException ex) { - // Any other exceptions related to connection? - broken = true; - throw ex; - } + try { + connect(); + Protocol.sendCommand(outputStream, cmd, args); + return this; + } catch (JedisConnectionException ex) { + // Any other exceptions related to connection? + broken = true; + throw ex; + } } protected Connection sendCommand(final Command cmd) { - try { - connect(); - Protocol.sendCommand(outputStream, cmd, new byte[0][]); - return this; - } catch (JedisConnectionException ex) { - // Any other exceptions related to connection? - broken = true; - throw ex; - } + try { + connect(); + Protocol.sendCommand(outputStream, cmd, new byte[0][]); + return this; + } catch (JedisConnectionException ex) { + // Any other exceptions related to connection? + broken = true; + throw ex; + } } public String getHost() { - return host; + return host; } public void setHost(final String host) { - this.host = host; + this.host = host; } public int getPort() { - return port; + return port; } public void setPort(final int port) { - this.port = port; + this.port = port; } public void connect() { - if (!isConnected()) { - try { - socket = new Socket(); - // ->@wjw_add - socket.setReuseAddress(true); - socket.setKeepAlive(true); // Will monitor the TCP connection is - // valid - socket.setTcpNoDelay(true); // Socket buffer Whetherclosed, to - // ensure timely delivery of data - socket.setSoLinger(true, 0); // Control calls close () method, - // the underlying socket is closed - // immediately - // <-@wjw_add + if (!isConnected()) { + try { + socket = new Socket(); + // ->@wjw_add + socket.setReuseAddress(true); + socket.setKeepAlive(true); // Will monitor the TCP connection is + // valid + socket.setTcpNoDelay(true); // Socket buffer Whetherclosed, to + // ensure timely delivery of data + socket.setSoLinger(true, 0); // Control calls close () method, + // the underlying socket is closed + // immediately + // <-@wjw_add - socket.connect(new InetSocketAddress(host, port), timeout); - socket.setSoTimeout(timeout); - outputStream = new RedisOutputStream(socket.getOutputStream()); - inputStream = new RedisInputStream(socket.getInputStream()); - } catch (IOException ex) { - broken = true; - throw new JedisConnectionException(ex); - } - } + socket.connect(new InetSocketAddress(host, port), timeout); + socket.setSoTimeout(timeout); + outputStream = new RedisOutputStream(socket.getOutputStream()); + inputStream = new RedisInputStream(socket.getInputStream()); + } catch (IOException ex) { + broken = true; + throw new JedisConnectionException(ex); + } + } } @Override public void close() { - disconnect(); + disconnect(); } public void disconnect() { - if (isConnected()) { - try { - inputStream.close(); - if (!socket.isClosed()) { - outputStream.close(); - socket.close(); - } - } catch (IOException ex) { - broken = true; - throw new JedisConnectionException(ex); - } - } + if (isConnected()) { + try { + inputStream.close(); + if (!socket.isClosed()) { + outputStream.close(); + socket.close(); + } + } catch (IOException ex) { + broken = true; + throw new JedisConnectionException(ex); + } + } } public boolean isConnected() { - return socket != null && socket.isBound() && !socket.isClosed() - && socket.isConnected() && !socket.isInputShutdown() - && !socket.isOutputShutdown(); + return socket != null && socket.isBound() && !socket.isClosed() + && socket.isConnected() && !socket.isInputShutdown() + && !socket.isOutputShutdown(); } public String getStatusCodeReply() { - flush(); - final byte[] resp = (byte[]) readProtocolWithCheckingBroken(); - if (null == resp) { - return null; - } else { - return SafeEncoder.encode(resp); - } + flush(); + final byte[] resp = (byte[]) readProtocolWithCheckingBroken(); + if (null == resp) { + return null; + } else { + return SafeEncoder.encode(resp); + } } public String getBulkReply() { - final byte[] result = getBinaryBulkReply(); - if (null != result) { - return SafeEncoder.encode(result); - } else { - return null; - } + final byte[] result = getBinaryBulkReply(); + if (null != result) { + return SafeEncoder.encode(result); + } else { + return null; + } } public byte[] getBinaryBulkReply() { - flush(); - return (byte[]) readProtocolWithCheckingBroken(); + flush(); + return (byte[]) readProtocolWithCheckingBroken(); } public Long getIntegerReply() { - flush(); - return (Long) readProtocolWithCheckingBroken(); + flush(); + return (Long) readProtocolWithCheckingBroken(); } public List getMultiBulkReply() { - return BuilderFactory.STRING_LIST.build(getBinaryMultiBulkReply()); + return BuilderFactory.STRING_LIST.build(getBinaryMultiBulkReply()); } @SuppressWarnings("unchecked") public List getBinaryMultiBulkReply() { - flush(); - return (List) readProtocolWithCheckingBroken(); + flush(); + return (List) readProtocolWithCheckingBroken(); } @SuppressWarnings("unchecked") public List getRawObjectMultiBulkReply() { - return (List) readProtocolWithCheckingBroken(); + return (List) readProtocolWithCheckingBroken(); } public List getObjectMultiBulkReply() { - flush(); - return getRawObjectMultiBulkReply(); + flush(); + return getRawObjectMultiBulkReply(); } @SuppressWarnings("unchecked") public List getIntegerMultiBulkReply() { - flush(); - return (List) Protocol.read(inputStream); + flush(); + return (List) Protocol.read(inputStream); } public Object getOne() { - flush(); - return readProtocolWithCheckingBroken(); + flush(); + return readProtocolWithCheckingBroken(); } public boolean isBroken() { - return broken; + return broken; } protected void flush() { - try { - outputStream.flush(); - } catch (IOException ex) { - broken = true; - throw new JedisConnectionException(ex); - } + try { + outputStream.flush(); + } catch (IOException ex) { + broken = true; + throw new JedisConnectionException(ex); + } } protected Object readProtocolWithCheckingBroken() { - try { - return Protocol.read(inputStream); - } catch (JedisConnectionException exc) { - broken = true; - throw exc; - } + try { + return Protocol.read(inputStream); + } catch (JedisConnectionException exc) { + broken = true; + throw exc; + } } public List getMany(final int count) { - flush(); - final List responses = new ArrayList(count); - for (int i = 0; i < count; i++) { - try { - responses.add(readProtocolWithCheckingBroken()); - } catch (JedisDataException e) { - responses.add(e); - } - } - return responses; + flush(); + final List responses = new ArrayList(count); + for (int i = 0; i < count; i++) { + try { + responses.add(readProtocolWithCheckingBroken()); + } catch (JedisDataException e) { + responses.add(e); + } + } + return responses; } } diff --git a/src/main/java/redis/clients/jedis/DebugParams.java b/src/main/java/redis/clients/jedis/DebugParams.java index 30c639b..fe3c918 100644 --- a/src/main/java/redis/clients/jedis/DebugParams.java +++ b/src/main/java/redis/clients/jedis/DebugParams.java @@ -4,7 +4,7 @@ public class DebugParams { private String[] command; public String[] getCommand() { - return command; + return command; } private DebugParams() { @@ -12,20 +12,20 @@ public class DebugParams { } public static DebugParams SEGFAULT() { - DebugParams debugParams = new DebugParams(); - debugParams.command = new String[] { "SEGFAULT" }; - return debugParams; + DebugParams debugParams = new DebugParams(); + debugParams.command = new String[] { "SEGFAULT" }; + return debugParams; } public static DebugParams OBJECT(String key) { - DebugParams debugParams = new DebugParams(); - debugParams.command = new String[] { "OBJECT", key }; - return debugParams; + DebugParams debugParams = new DebugParams(); + debugParams.command = new String[] { "OBJECT", key }; + return debugParams; } public static DebugParams RELOAD() { - DebugParams debugParams = new DebugParams(); - debugParams.command = new String[] { "RELOAD" }; - return debugParams; + DebugParams debugParams = new DebugParams(); + debugParams.command = new String[] { "RELOAD" }; + return debugParams; } } diff --git a/src/main/java/redis/clients/jedis/HostAndPort.java b/src/main/java/redis/clients/jedis/HostAndPort.java index 7e5cd65..003bffb 100644 --- a/src/main/java/redis/clients/jedis/HostAndPort.java +++ b/src/main/java/redis/clients/jedis/HostAndPort.java @@ -7,48 +7,48 @@ public class HostAndPort { private int port; public HostAndPort(String host, int port) { - this.host = host; - this.port = port; + this.host = host; + this.port = port; } public String getHost() { - return host; + return host; } public int getPort() { - return port; + return port; } @Override public boolean equals(Object obj) { - if (obj instanceof HostAndPort) { - HostAndPort hp = (HostAndPort) obj; + if (obj instanceof HostAndPort) { + HostAndPort hp = (HostAndPort) obj; - String thisHost = convertHost(host); - String hpHost = convertHost(hp.host); - return port == hp.port && thisHost.equals(hpHost); + String thisHost = convertHost(host); + String hpHost = convertHost(hp.host); + return port == hp.port && thisHost.equals(hpHost); - } + } - return false; + return false; } @Override public int hashCode() { - return 31 * convertHost(host).hashCode() + port; + return 31 * convertHost(host).hashCode() + port; } @Override public String toString() { - return host + ":" + port; + return host + ":" + port; } private String convertHost(String host) { - if (host.equals("127.0.0.1")) - return LOCALHOST_STR; - else if (host.equals("::1")) - return LOCALHOST_STR; + if (host.equals("127.0.0.1")) + return LOCALHOST_STR; + else if (host.equals("::1")) + return LOCALHOST_STR; - return host; + return host; } } diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index b030203..6646b87 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -18,37 +18,37 @@ import redis.clients.util.SafeEncoder; import redis.clients.util.Slowlog; public class Jedis extends BinaryJedis implements JedisCommands, - MultiKeyCommands, AdvancedJedisCommands, ScriptingCommands, - BasicCommands, ClusterCommands, SentinelCommands { + MultiKeyCommands, AdvancedJedisCommands, ScriptingCommands, + BasicCommands, ClusterCommands, SentinelCommands { protected Pool dataSource = null; public Jedis() { - super(); + super(); } public Jedis(final String host) { - super(host); + super(host); } public Jedis(final String host, final int port) { - super(host, port); + super(host, port); } public Jedis(final String host, final int port, final int timeout) { - super(host, port, timeout); + super(host, port, timeout); } public Jedis(JedisShardInfo shardInfo) { - super(shardInfo); + super(shardInfo); } public Jedis(URI uri) { - super(uri); + super(uri); } public Jedis(final URI uri, final int timeout) { - super(uri, timeout); + super(uri, timeout); } /** @@ -62,9 +62,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Status code reply */ public String set(final String key, String value) { - checkIsInMulti(); - client.set(key, value); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.set(key, value); + return client.getStatusCodeReply(); } /** @@ -83,10 +83,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Status code reply */ public String set(final String key, final String value, final String nxxx, - final String expx, final long time) { - checkIsInMulti(); - client.set(key, value, nxxx, expx, time); - return client.getStatusCodeReply(); + final String expx, final long time) { + checkIsInMulti(); + client.set(key, value, nxxx, expx, time); + return client.getStatusCodeReply(); } /** @@ -100,9 +100,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Bulk reply */ public String get(final String key) { - checkIsInMulti(); - client.sendCommand(Protocol.Command.GET, key); - return client.getBulkReply(); + checkIsInMulti(); + client.sendCommand(Protocol.Command.GET, key); + return client.getBulkReply(); } /** @@ -116,9 +116,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Boolean reply, true if the key exists, otherwise false */ public Boolean exists(final String key) { - checkIsInMulti(); - client.exists(key); - return client.getIntegerReply() == 1; + checkIsInMulti(); + client.exists(key); + return client.getIntegerReply() == 1; } /** @@ -132,14 +132,14 @@ public class Jedis extends BinaryJedis implements JedisCommands, * more keys were removed 0 if none of the specified key existed */ public Long del(final String... keys) { - checkIsInMulti(); - client.del(keys); - return client.getIntegerReply(); + checkIsInMulti(); + client.del(keys); + return client.getIntegerReply(); } public Long del(String key) { - client.del(key); - return client.getIntegerReply(); + client.del(key); + return client.getIntegerReply(); } /** @@ -157,9 +157,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * contains a Hash value */ public String type(final String key) { - checkIsInMulti(); - client.type(key); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.type(key); + return client.getStatusCodeReply(); } /** @@ -194,10 +194,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Multi bulk reply */ public Set keys(final String pattern) { - checkIsInMulti(); - client.keys(pattern); - return BuilderFactory.STRING_SET - .build(client.getBinaryMultiBulkReply()); + checkIsInMulti(); + client.keys(pattern); + return BuilderFactory.STRING_SET + .build(client.getBinaryMultiBulkReply()); } /** @@ -209,9 +209,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * empty string is the database is empty */ public String randomKey() { - checkIsInMulti(); - client.randomKey(); - return client.getBulkReply(); + checkIsInMulti(); + client.randomKey(); + return client.getBulkReply(); } /** @@ -226,9 +226,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Status code repy */ public String rename(final String oldkey, final String newkey) { - checkIsInMulti(); - client.rename(oldkey, newkey); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.rename(oldkey, newkey); + return client.getStatusCodeReply(); } /** @@ -243,9 +243,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * target key already exist */ public Long renamenx(final String oldkey, final String newkey) { - checkIsInMulti(); - client.renamenx(oldkey, newkey); - return client.getIntegerReply(); + checkIsInMulti(); + client.renamenx(oldkey, newkey); + return client.getIntegerReply(); } /** @@ -277,9 +277,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * exist. */ public Long expire(final String key, final int seconds) { - checkIsInMulti(); - client.expire(key, seconds); - return client.getIntegerReply(); + checkIsInMulti(); + client.expire(key, seconds); + return client.getIntegerReply(); } /** @@ -313,9 +313,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * exist. */ public Long expireAt(final String key, final long unixTime) { - checkIsInMulti(); - client.expireAt(key, unixTime); - return client.getIntegerReply(); + checkIsInMulti(); + client.expireAt(key, unixTime); + return client.getIntegerReply(); } /** @@ -333,9 +333,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * returned. */ public Long ttl(final String key) { - checkIsInMulti(); - client.ttl(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.ttl(key); + return client.getIntegerReply(); } /** @@ -352,9 +352,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * found in the current DB. */ public Long move(final String key, final int dbIndex) { - checkIsInMulti(); - client.move(key, dbIndex); - return client.getIntegerReply(); + checkIsInMulti(); + client.move(key, dbIndex); + return client.getIntegerReply(); } /** @@ -369,9 +369,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Bulk reply */ public String getSet(final String key, final String value) { - checkIsInMulti(); - client.getSet(key, value); - return client.getBulkReply(); + checkIsInMulti(); + client.getSet(key, value); + return client.getBulkReply(); } /** @@ -385,9 +385,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Multi bulk reply */ public List mget(final String... keys) { - checkIsInMulti(); - client.mget(keys); - return client.getMultiBulkReply(); + checkIsInMulti(); + client.mget(keys); + return client.getMultiBulkReply(); } /** @@ -403,9 +403,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * was not set */ public Long setnx(final String key, final String value) { - checkIsInMulti(); - client.setnx(key, value); - return client.getIntegerReply(); + checkIsInMulti(); + client.setnx(key, value); + return client.getIntegerReply(); } /** @@ -421,9 +421,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Status code reply */ public String setex(final String key, final int seconds, final String value) { - checkIsInMulti(); - client.setex(key, seconds, value); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.setex(key, seconds, value); + return client.getStatusCodeReply(); } /** @@ -447,9 +447,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Status code reply Basically +OK as MSET can't fail */ public String mset(final String... keysvalues) { - checkIsInMulti(); - client.mset(keysvalues); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.mset(keysvalues); + return client.getStatusCodeReply(); } /** @@ -474,9 +474,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * no key was set (at least one key already existed) */ public Long msetnx(final String... keysvalues) { - checkIsInMulti(); - client.msetnx(keysvalues); - return client.getIntegerReply(); + checkIsInMulti(); + client.msetnx(keysvalues); + return client.getIntegerReply(); } /** @@ -502,9 +502,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * after the increment. */ public Long decrBy(final String key, final long integer) { - checkIsInMulti(); - client.decrBy(key, integer); - return client.getIntegerReply(); + checkIsInMulti(); + client.decrBy(key, integer); + return client.getIntegerReply(); } /** @@ -530,9 +530,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * after the increment. */ public Long decr(final String key) { - checkIsInMulti(); - client.decr(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.decr(key); + return client.getIntegerReply(); } /** @@ -558,9 +558,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * after the increment. */ public Long incrBy(final String key, final long integer) { - checkIsInMulti(); - client.incrBy(key, integer); - return client.getIntegerReply(); + checkIsInMulti(); + client.incrBy(key, integer); + return client.getIntegerReply(); } /** @@ -583,10 +583,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, * after the increment. */ public Double incrByFloat(final String key, final double value) { - checkIsInMulti(); - client.incrByFloat(key, value); - String dval = client.getBulkReply(); - return (dval != null ? new Double(dval) : null); + checkIsInMulti(); + client.incrByFloat(key, value); + String dval = client.getBulkReply(); + return (dval != null ? new Double(dval) : null); } /** @@ -612,9 +612,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * after the increment. */ public Long incr(final String key) { - checkIsInMulti(); - client.incr(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.incr(key); + return client.getIntegerReply(); } /** @@ -634,9 +634,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * the append operation. */ public Long append(final String key, final String value) { - checkIsInMulti(); - client.append(key, value); - return client.getIntegerReply(); + checkIsInMulti(); + client.append(key, value); + return client.getIntegerReply(); } /** @@ -658,9 +658,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Bulk reply */ public String substr(final String key, final int start, final int end) { - checkIsInMulti(); - client.substr(key, start, end); - return client.getBulkReply(); + checkIsInMulti(); + client.substr(key, start, end); + return client.getBulkReply(); } /** @@ -679,9 +679,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * 1 is returned. */ public Long hset(final String key, final String field, final String value) { - checkIsInMulti(); - client.hset(key, field, value); - return client.getIntegerReply(); + checkIsInMulti(); + client.hset(key, field, value); + return client.getIntegerReply(); } /** @@ -698,9 +698,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Bulk reply */ public String hget(final String key, final String field) { - checkIsInMulti(); - client.hget(key, field); - return client.getBulkReply(); + checkIsInMulti(); + client.hget(key, field); + return client.getBulkReply(); } /** @@ -715,9 +715,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * field is created 1 is returned. */ public Long hsetnx(final String key, final String field, final String value) { - checkIsInMulti(); - client.hsetnx(key, field, value); - return client.getIntegerReply(); + checkIsInMulti(); + client.hsetnx(key, field, value); + return client.getIntegerReply(); } /** @@ -733,9 +733,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Return OK or Exception if hash is empty */ public String hmset(final String key, final Map hash) { - checkIsInMulti(); - client.hmset(key, hash); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.hmset(key, hash); + return client.getStatusCodeReply(); } /** @@ -752,9 +752,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * with the specified fields, in the same order of the request. */ public List hmget(final String key, final String... fields) { - checkIsInMulti(); - client.hmget(key, fields); - return client.getMultiBulkReply(); + checkIsInMulti(); + client.hmget(key, fields); + return client.getMultiBulkReply(); } /** @@ -776,9 +776,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * operation. */ public Long hincrBy(final String key, final String field, final long value) { - checkIsInMulti(); - client.hincrBy(key, field, value); - return client.getIntegerReply(); + checkIsInMulti(); + client.hincrBy(key, field, value); + return client.getIntegerReply(); } /** @@ -801,11 +801,11 @@ public class Jedis extends BinaryJedis implements JedisCommands, * after the increment operation. */ public Double hincrByFloat(final String key, final String field, - final double value) { - checkIsInMulti(); - client.hincrByFloat(key, field, value); - final String dval = client.getBulkReply(); - return (dval != null ? new Double(dval) : null); + final double value) { + checkIsInMulti(); + client.hincrByFloat(key, field, value); + final String dval = client.getBulkReply(); + return (dval != null ? new Double(dval) : null); } /** @@ -819,9 +819,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * Return 0 if the key is not found or the field is not present. */ public Boolean hexists(final String key, final String field) { - checkIsInMulti(); - client.hexists(key, field); - return client.getIntegerReply() == 1; + checkIsInMulti(); + client.hexists(key, field); + return client.getIntegerReply() == 1; } /** @@ -835,9 +835,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * returned, otherwise 0 is returned and no operation is performed. */ public Long hdel(final String key, final String... fields) { - checkIsInMulti(); - client.hdel(key, fields); - return client.getIntegerReply(); + checkIsInMulti(); + client.hdel(key, fields); + return client.getIntegerReply(); } /** @@ -851,9 +851,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * an empty hash. */ public Long hlen(final String key) { - checkIsInMulti(); - client.hlen(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.hlen(key); + return client.getIntegerReply(); } /** @@ -865,10 +865,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return All the fields names contained into a hash. */ public Set hkeys(final String key) { - checkIsInMulti(); - client.hkeys(key); - return BuilderFactory.STRING_SET - .build(client.getBinaryMultiBulkReply()); + checkIsInMulti(); + client.hkeys(key); + return BuilderFactory.STRING_SET + .build(client.getBinaryMultiBulkReply()); } /** @@ -880,10 +880,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return All the fields values contained into a hash. */ public List hvals(final String key) { - checkIsInMulti(); - client.hvals(key); - final List lresult = client.getMultiBulkReply(); - return lresult; + checkIsInMulti(); + client.hvals(key); + final List lresult = client.getMultiBulkReply(); + return lresult; } /** @@ -895,10 +895,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return All the fields and values contained into a hash. */ public Map hgetAll(final String key) { - checkIsInMulti(); - client.hgetAll(key); - return BuilderFactory.STRING_MAP - .build(client.getBinaryMultiBulkReply()); + checkIsInMulti(); + client.hgetAll(key); + return BuilderFactory.STRING_MAP + .build(client.getBinaryMultiBulkReply()); } /** @@ -915,9 +915,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * list after the push operation. */ public Long rpush(final String key, final String... strings) { - checkIsInMulti(); - client.rpush(key, strings); - return client.getIntegerReply(); + checkIsInMulti(); + client.rpush(key, strings); + return client.getIntegerReply(); } /** @@ -934,9 +934,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * list after the push operation. */ public Long lpush(final String key, final String... strings) { - checkIsInMulti(); - client.lpush(key, strings); - return client.getIntegerReply(); + checkIsInMulti(); + client.lpush(key, strings); + return client.getIntegerReply(); } /** @@ -950,9 +950,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return The length of the list. */ public Long llen(final String key) { - checkIsInMulti(); - client.llen(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.llen(key); + return client.getIntegerReply(); } /** @@ -994,10 +994,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, * specified range. */ public List lrange(final String key, final long start, - final long end) { - checkIsInMulti(); - client.lrange(key, start, end); - return client.getMultiBulkReply(); + final long end) { + checkIsInMulti(); + client.lrange(key, start, end); + return client.getMultiBulkReply(); } /** @@ -1035,9 +1035,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Status code reply */ public String ltrim(final String key, final long start, final long end) { - checkIsInMulti(); - client.ltrim(key, start, end); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.ltrim(key, start, end); + return client.getStatusCodeReply(); } /** @@ -1059,9 +1059,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Bulk reply, specifically the requested element */ public String lindex(final String key, final long index) { - checkIsInMulti(); - client.lindex(key, index); - return client.getBulkReply(); + checkIsInMulti(); + client.lindex(key, index); + return client.getBulkReply(); } /** @@ -1086,9 +1086,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Status code reply */ public String lset(final String key, final long index, final String value) { - checkIsInMulti(); - client.lset(key, index, value); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.lset(key, index, value); + return client.getStatusCodeReply(); } /** @@ -1111,9 +1111,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * the operation succeeded */ public Long lrem(final String key, final long count, final String value) { - checkIsInMulti(); - client.lrem(key, count, value); - return client.getIntegerReply(); + checkIsInMulti(); + client.lrem(key, count, value); + return client.getIntegerReply(); } /** @@ -1130,9 +1130,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Bulk reply */ public String lpop(final String key) { - checkIsInMulti(); - client.lpop(key); - return client.getBulkReply(); + checkIsInMulti(); + client.lpop(key); + return client.getBulkReply(); } /** @@ -1149,9 +1149,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Bulk reply */ public String rpop(final String key) { - checkIsInMulti(); - client.rpop(key); - return client.getBulkReply(); + checkIsInMulti(); + client.rpop(key); + return client.getBulkReply(); } /** @@ -1173,9 +1173,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Bulk reply */ public String rpoplpush(final String srckey, final String dstkey) { - checkIsInMulti(); - client.rpoplpush(srckey, dstkey); - return client.getBulkReply(); + checkIsInMulti(); + client.rpoplpush(srckey, dstkey); + return client.getBulkReply(); } /** @@ -1192,9 +1192,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * the element was already a member of the set */ public Long sadd(final String key, final String... members) { - checkIsInMulti(); - client.sadd(key, members); - return client.getIntegerReply(); + checkIsInMulti(); + client.sadd(key, members); + return client.getIntegerReply(); } /** @@ -1207,10 +1207,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Multi bulk reply */ public Set smembers(final String key) { - checkIsInMulti(); - client.smembers(key); - final List members = client.getMultiBulkReply(); - return new HashSet(members); + checkIsInMulti(); + client.smembers(key); + final List members = client.getMultiBulkReply(); + return new HashSet(members); } /** @@ -1226,9 +1226,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * if the new element was not a member of the set */ public Long srem(final String key, final String... members) { - checkIsInMulti(); - client.srem(key, members); - return client.getIntegerReply(); + checkIsInMulti(); + client.srem(key, members); + return client.getIntegerReply(); } /** @@ -1244,9 +1244,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Bulk reply */ public String spop(final String key) { - checkIsInMulti(); - client.spop(key); - return client.getBulkReply(); + checkIsInMulti(); + client.spop(key); + return client.getBulkReply(); } /** @@ -1273,10 +1273,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, * performed */ public Long smove(final String srckey, final String dstkey, - final String member) { - checkIsInMulti(); - client.smove(srckey, dstkey, member); - return client.getIntegerReply(); + final String member) { + checkIsInMulti(); + client.smove(srckey, dstkey, member); + return client.getIntegerReply(); } /** @@ -1288,9 +1288,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * of the set as an integer. */ public Long scard(final String key) { - checkIsInMulti(); - client.scard(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.scard(key); + return client.getIntegerReply(); } /** @@ -1306,9 +1306,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * does not exist */ public Boolean sismember(final String key, final String member) { - checkIsInMulti(); - client.sismember(key, member); - return client.getIntegerReply() == 1; + checkIsInMulti(); + client.sismember(key, member); + return client.getIntegerReply() == 1; } /** @@ -1331,10 +1331,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Multi bulk reply, specifically the list of common elements. */ public Set sinter(final String... keys) { - checkIsInMulti(); - client.sinter(keys); - final List members = client.getMultiBulkReply(); - return new HashSet(members); + checkIsInMulti(); + client.sinter(keys); + final List members = client.getMultiBulkReply(); + return new HashSet(members); } /** @@ -1349,9 +1349,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Status code reply */ public Long sinterstore(final String dstkey, final String... keys) { - checkIsInMulti(); - client.sinterstore(dstkey, keys); - return client.getIntegerReply(); + checkIsInMulti(); + client.sinterstore(dstkey, keys); + return client.getIntegerReply(); } /** @@ -1371,10 +1371,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Multi bulk reply, specifically the list of common elements. */ public Set sunion(final String... keys) { - checkIsInMulti(); - client.sunion(keys); - final List members = client.getMultiBulkReply(); - return new HashSet(members); + checkIsInMulti(); + client.sunion(keys); + final List members = client.getMultiBulkReply(); + return new HashSet(members); } /** @@ -1390,9 +1390,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Status code reply */ public Long sunionstore(final String dstkey, final String... keys) { - checkIsInMulti(); - client.sunionstore(dstkey, keys); - return client.getIntegerReply(); + checkIsInMulti(); + client.sunionstore(dstkey, keys); + return client.getIntegerReply(); } /** @@ -1419,10 +1419,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, * the first set provided and all the successive sets. */ public Set sdiff(final String... keys) { - checkIsInMulti(); - client.sdiff(keys); - return BuilderFactory.STRING_SET - .build(client.getBinaryMultiBulkReply()); + checkIsInMulti(); + client.sdiff(keys); + return BuilderFactory.STRING_SET + .build(client.getBinaryMultiBulkReply()); } /** @@ -1434,9 +1434,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Status code reply */ public Long sdiffstore(final String dstkey, final String... keys) { - checkIsInMulti(); - client.sdiffstore(dstkey, keys); - return client.getIntegerReply(); + checkIsInMulti(); + client.sdiffstore(dstkey, keys); + return client.getIntegerReply(); } /** @@ -1452,15 +1452,15 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Bulk reply */ public String srandmember(final String key) { - checkIsInMulti(); - client.srandmember(key); - return client.getBulkReply(); + checkIsInMulti(); + client.srandmember(key); + return client.getBulkReply(); } public List srandmember(final String key, final int count) { - checkIsInMulti(); - client.srandmember(key, count); - return client.getMultiBulkReply(); + checkIsInMulti(); + client.srandmember(key, count); + return client.getMultiBulkReply(); } /** @@ -1485,22 +1485,22 @@ public class Jedis extends BinaryJedis implements JedisCommands, * was updated */ public Long zadd(final String key, final double score, final String member) { - checkIsInMulti(); - client.zadd(key, score, member); - return client.getIntegerReply(); + checkIsInMulti(); + client.zadd(key, score, member); + return client.getIntegerReply(); } public Long zadd(final String key, final Map scoreMembers) { - checkIsInMulti(); - client.zadd(key, scoreMembers); - return client.getIntegerReply(); + checkIsInMulti(); + client.zadd(key, scoreMembers); + return client.getIntegerReply(); } public Set zrange(final String key, final long start, final long end) { - checkIsInMulti(); - client.zrange(key, start, end); - final List members = client.getMultiBulkReply(); - return new LinkedHashSet(members); + checkIsInMulti(); + client.zrange(key, start, end); + final List members = client.getMultiBulkReply(); + return new LinkedHashSet(members); } /** @@ -1519,9 +1519,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * if the new element was not a member of the set */ public Long zrem(final String key, final String... members) { - checkIsInMulti(); - client.zrem(key, members); - return client.getIntegerReply(); + checkIsInMulti(); + client.zrem(key, members); + return client.getIntegerReply(); } /** @@ -1549,11 +1549,11 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return The new score */ public Double zincrby(final String key, final double score, - final String member) { - checkIsInMulti(); - client.zincrby(key, score, member); - String newscore = client.getBulkReply(); - return Double.valueOf(newscore); + final String member) { + checkIsInMulti(); + client.zincrby(key, score, member); + String newscore = client.getBulkReply(); + return Double.valueOf(newscore); } /** @@ -1577,9 +1577,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * reply if there is no such element. */ public Long zrank(final String key, final String member) { - checkIsInMulti(); - client.zrank(key, member); - return client.getIntegerReply(); + checkIsInMulti(); + client.zrank(key, member); + return client.getIntegerReply(); } /** @@ -1603,33 +1603,33 @@ public class Jedis extends BinaryJedis implements JedisCommands, * reply if there is no such element. */ public Long zrevrank(final String key, final String member) { - checkIsInMulti(); - client.zrevrank(key, member); - return client.getIntegerReply(); + checkIsInMulti(); + client.zrevrank(key, member); + return client.getIntegerReply(); } public Set zrevrange(final String key, final long start, - final long end) { - checkIsInMulti(); - client.zrevrange(key, start, end); - final List members = client.getMultiBulkReply(); - return new LinkedHashSet(members); + final long end) { + checkIsInMulti(); + client.zrevrange(key, start, end); + final List members = client.getMultiBulkReply(); + return new LinkedHashSet(members); } public Set zrangeWithScores(final String key, final long start, - final long end) { - checkIsInMulti(); - client.zrangeWithScores(key, start, end); - Set set = getTupledSet(); - return set; + final long end) { + checkIsInMulti(); + client.zrangeWithScores(key, start, end); + Set set = getTupledSet(); + return set; } public Set zrevrangeWithScores(final String key, final long start, - final long end) { - checkIsInMulti(); - client.zrevrangeWithScores(key, start, end); - Set set = getTupledSet(); - return set; + final long end) { + checkIsInMulti(); + client.zrevrangeWithScores(key, start, end); + Set set = getTupledSet(); + return set; } /** @@ -1642,9 +1642,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return the cardinality (number of elements) of the set as an integer. */ public Long zcard(final String key) { - checkIsInMulti(); - client.zcard(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.zcard(key); + return client.getIntegerReply(); } /** @@ -1659,15 +1659,15 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return the score */ public Double zscore(final String key, final String member) { - checkIsInMulti(); - client.zscore(key, member); - final String score = client.getBulkReply(); - return (score != null ? new Double(score) : null); + checkIsInMulti(); + client.zscore(key, member); + final String score = client.getBulkReply(); + return (score != null ? new Double(score) : null); } public String watch(final String... keys) { - client.watch(keys); - return client.getStatusCodeReply(); + client.watch(keys); + return client.getStatusCodeReply(); } /** @@ -1688,9 +1688,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * smallest to the biggest number. */ public List sort(final String key) { - checkIsInMulti(); - client.sort(key); - return client.getMultiBulkReply(); + checkIsInMulti(); + client.sort(key); + return client.getMultiBulkReply(); } /** @@ -1770,10 +1770,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return a list of sorted elements. */ public List sort(final String key, - final SortingParams sortingParameters) { - checkIsInMulti(); - client.sort(key, sortingParameters); - return client.getMultiBulkReply(); + final SortingParams sortingParameters) { + checkIsInMulti(); + client.sort(key, sortingParameters); + return client.getMultiBulkReply(); } /** @@ -1849,40 +1849,40 @@ public class Jedis extends BinaryJedis implements JedisCommands, * programming language used. */ public List blpop(final int timeout, final String... keys) { - return blpop(getArgsAddTimeout(timeout, keys)); + return blpop(getArgsAddTimeout(timeout, keys)); } private String[] getArgsAddTimeout (int timeout, String[] keys) { - final int keyCount = keys.length; - final String[] args = new String[keyCount + 1]; - for (int at = 0; at != keyCount; ++at) { - args[at] = keys[at]; - } + final int keyCount = keys.length; + final String[] args = new String[keyCount + 1]; + for (int at = 0; at != keyCount; ++at) { + args[at] = keys[at]; + } - args[keyCount] = String.valueOf(timeout); - return args; + args[keyCount] = String.valueOf(timeout); + return args; } public List blpop(String... args) { - checkIsInMulti(); - client.blpop(args); - client.setTimeoutInfinite(); - try { - return client.getMultiBulkReply(); - } finally { - client.rollbackTimeout(); - } + checkIsInMulti(); + client.blpop(args); + client.setTimeoutInfinite(); + try { + return client.getMultiBulkReply(); + } finally { + client.rollbackTimeout(); + } } public List brpop(String... args) { - checkIsInMulti(); - client.brpop(args); - client.setTimeoutInfinite(); - try { - return client.getMultiBulkReply(); - } finally { - client.rollbackTimeout(); - } + checkIsInMulti(); + client.brpop(args); + client.setTimeoutInfinite(); + try { + return client.getMultiBulkReply(); + } finally { + client.rollbackTimeout(); + } } /** @@ -1890,7 +1890,7 @@ public class Jedis extends BinaryJedis implements JedisCommands, */ @Deprecated public List blpop(String arg) { - return blpop(new String[]{arg}); + return blpop(new String[]{arg}); } /** @@ -1898,7 +1898,7 @@ public class Jedis extends BinaryJedis implements JedisCommands, */ @Deprecated public List brpop(String arg) { - return brpop(new String[]{arg}); + return brpop(new String[]{arg}); } /** @@ -1915,10 +1915,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return The number of elements of the list at dstkey. */ public Long sort(final String key, final SortingParams sortingParameters, - final String dstkey) { - checkIsInMulti(); - client.sort(key, sortingParameters, dstkey); - return client.getIntegerReply(); + final String dstkey) { + checkIsInMulti(); + client.sort(key, sortingParameters, dstkey); + return client.getIntegerReply(); } /** @@ -1938,9 +1938,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return The number of elements of the list at dstkey. */ public Long sort(final String key, final String dstkey) { - checkIsInMulti(); - client.sort(key, dstkey); - return client.getIntegerReply(); + checkIsInMulti(); + client.sort(key, dstkey); + return client.getIntegerReply(); } /** @@ -2016,19 +2016,19 @@ public class Jedis extends BinaryJedis implements JedisCommands, * programming language used. */ public List brpop(final int timeout, final String... keys) { - return brpop(getArgsAddTimeout(timeout, keys)); + return brpop(getArgsAddTimeout(timeout, keys)); } public Long zcount(final String key, final double min, final double max) { - checkIsInMulti(); - client.zcount(key, min, max); - return client.getIntegerReply(); + checkIsInMulti(); + client.zcount(key, min, max); + return client.getIntegerReply(); } public Long zcount(final String key, final String min, final String max) { - checkIsInMulti(); - client.zcount(key, min, max); - return client.getIntegerReply(); + checkIsInMulti(); + client.zcount(key, min, max); + return client.getIntegerReply(); } /** @@ -2091,17 +2091,17 @@ public class Jedis extends BinaryJedis implements JedisCommands, * score range. */ public Set zrangeByScore(final String key, final double min, - final double max) { - checkIsInMulti(); - client.zrangeByScore(key, min, max); - return new LinkedHashSet(client.getMultiBulkReply()); + final double max) { + checkIsInMulti(); + client.zrangeByScore(key, min, max); + return new LinkedHashSet(client.getMultiBulkReply()); } public Set zrangeByScore(final String key, final String min, - final String max) { - checkIsInMulti(); - client.zrangeByScore(key, min, max); - return new LinkedHashSet(client.getMultiBulkReply()); + final String max) { + checkIsInMulti(); + client.zrangeByScore(key, min, max); + return new LinkedHashSet(client.getMultiBulkReply()); } /** @@ -2161,17 +2161,17 @@ public class Jedis extends BinaryJedis implements JedisCommands, * score range. */ public Set zrangeByScore(final String key, final double min, - final double max, final int offset, final int count) { - checkIsInMulti(); - client.zrangeByScore(key, min, max, offset, count); - return new LinkedHashSet(client.getMultiBulkReply()); + final double max, final int offset, final int count) { + checkIsInMulti(); + client.zrangeByScore(key, min, max, offset, count); + return new LinkedHashSet(client.getMultiBulkReply()); } public Set zrangeByScore(final String key, final String min, - final String max, final int offset, final int count) { - checkIsInMulti(); - client.zrangeByScore(key, min, max, offset, count); - return new LinkedHashSet(client.getMultiBulkReply()); + final String max, final int offset, final int count) { + checkIsInMulti(); + client.zrangeByScore(key, min, max, offset, count); + return new LinkedHashSet(client.getMultiBulkReply()); } /** @@ -2231,19 +2231,19 @@ public class Jedis extends BinaryJedis implements JedisCommands, * score range. */ public Set zrangeByScoreWithScores(final String key, - final double min, final double max) { - checkIsInMulti(); - client.zrangeByScoreWithScores(key, min, max); - Set set = getTupledSet(); - return set; + final double min, final double max) { + checkIsInMulti(); + client.zrangeByScoreWithScores(key, min, max); + Set set = getTupledSet(); + return set; } public Set zrangeByScoreWithScores(final String key, - final String min, final String max) { - checkIsInMulti(); - client.zrangeByScoreWithScores(key, min, max); - Set set = getTupledSet(); - return set; + final String min, final String max) { + checkIsInMulti(); + client.zrangeByScoreWithScores(key, min, max); + Set set = getTupledSet(); + return set; } /** @@ -2303,94 +2303,94 @@ public class Jedis extends BinaryJedis implements JedisCommands, * score range. */ public Set zrangeByScoreWithScores(final String key, - final double min, final double max, final int offset, - final int count) { - checkIsInMulti(); - client.zrangeByScoreWithScores(key, min, max, offset, count); - Set set = getTupledSet(); - return set; + final double min, final double max, final int offset, + final int count) { + checkIsInMulti(); + client.zrangeByScoreWithScores(key, min, max, offset, count); + Set set = getTupledSet(); + return set; } public Set zrangeByScoreWithScores(final String key, - final String min, final String max, final int offset, - final int count) { - checkIsInMulti(); - client.zrangeByScoreWithScores(key, min, max, offset, count); - Set set = getTupledSet(); - return set; + final String min, final String max, final int offset, + final int count) { + checkIsInMulti(); + client.zrangeByScoreWithScores(key, min, max, offset, count); + Set set = getTupledSet(); + return set; } private Set getTupledSet() { - checkIsInMulti(); - List membersWithScores = client.getMultiBulkReply(); - Set set = new LinkedHashSet(); - Iterator iterator = membersWithScores.iterator(); - while (iterator.hasNext()) { - set.add(new Tuple(iterator.next(), Double.valueOf(iterator.next()))); - } - return set; + checkIsInMulti(); + List membersWithScores = client.getMultiBulkReply(); + Set set = new LinkedHashSet(); + Iterator iterator = membersWithScores.iterator(); + while (iterator.hasNext()) { + set.add(new Tuple(iterator.next(), Double.valueOf(iterator.next()))); + } + return set; } public Set zrevrangeByScore(final String key, final double max, - final double min) { - checkIsInMulti(); - client.zrevrangeByScore(key, max, min); - return new LinkedHashSet(client.getMultiBulkReply()); + final double min) { + checkIsInMulti(); + client.zrevrangeByScore(key, max, min); + return new LinkedHashSet(client.getMultiBulkReply()); } public Set zrevrangeByScore(final String key, final String max, - final String min) { - checkIsInMulti(); - client.zrevrangeByScore(key, max, min); - return new LinkedHashSet(client.getMultiBulkReply()); + final String min) { + checkIsInMulti(); + client.zrevrangeByScore(key, max, min); + return new LinkedHashSet(client.getMultiBulkReply()); } public Set zrevrangeByScore(final String key, final double max, - final double min, final int offset, final int count) { - checkIsInMulti(); - client.zrevrangeByScore(key, max, min, offset, count); - return new LinkedHashSet(client.getMultiBulkReply()); + final double min, final int offset, final int count) { + checkIsInMulti(); + client.zrevrangeByScore(key, max, min, offset, count); + return new LinkedHashSet(client.getMultiBulkReply()); } public Set zrevrangeByScoreWithScores(final String key, - final double max, final double min) { - checkIsInMulti(); - client.zrevrangeByScoreWithScores(key, max, min); - Set set = getTupledSet(); - return set; + final double max, final double min) { + checkIsInMulti(); + client.zrevrangeByScoreWithScores(key, max, min); + Set set = getTupledSet(); + return set; } public Set zrevrangeByScoreWithScores(final String key, - final double max, final double min, final int offset, - final int count) { - checkIsInMulti(); - client.zrevrangeByScoreWithScores(key, max, min, offset, count); - Set set = getTupledSet(); - return set; + final double max, final double min, final int offset, + final int count) { + checkIsInMulti(); + client.zrevrangeByScoreWithScores(key, max, min, offset, count); + Set set = getTupledSet(); + return set; } public Set zrevrangeByScoreWithScores(final String key, - final String max, final String min, final int offset, - final int count) { - checkIsInMulti(); - client.zrevrangeByScoreWithScores(key, max, min, offset, count); - Set set = getTupledSet(); - return set; + final String max, final String min, final int offset, + final int count) { + checkIsInMulti(); + client.zrevrangeByScoreWithScores(key, max, min, offset, count); + Set set = getTupledSet(); + return set; } public Set zrevrangeByScore(final String key, final String max, - final String min, final int offset, final int count) { - checkIsInMulti(); - client.zrevrangeByScore(key, max, min, offset, count); - return new LinkedHashSet(client.getMultiBulkReply()); + final String min, final int offset, final int count) { + checkIsInMulti(); + client.zrevrangeByScore(key, max, min, offset, count); + return new LinkedHashSet(client.getMultiBulkReply()); } public Set zrevrangeByScoreWithScores(final String key, - final String max, final String min) { - checkIsInMulti(); - client.zrevrangeByScoreWithScores(key, max, min); - Set set = getTupledSet(); - return set; + final String max, final String min) { + checkIsInMulti(); + client.zrevrangeByScoreWithScores(key, max, min); + Set set = getTupledSet(); + return set; } /** @@ -2407,10 +2407,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, * */ public Long zremrangeByRank(final String key, final long start, - final long end) { - checkIsInMulti(); - client.zremrangeByRank(key, start, end); - return client.getIntegerReply(); + final long end) { + checkIsInMulti(); + client.zremrangeByRank(key, start, end); + return client.getIntegerReply(); } /** @@ -2428,17 +2428,17 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Integer reply, specifically the number of elements removed. */ public Long zremrangeByScore(final String key, final double start, - final double end) { - checkIsInMulti(); - client.zremrangeByScore(key, start, end); - return client.getIntegerReply(); + final double end) { + checkIsInMulti(); + client.zremrangeByScore(key, start, end); + return client.getIntegerReply(); } public Long zremrangeByScore(final String key, final String start, - final String end) { - checkIsInMulti(); - client.zremrangeByScore(key, start, end); - return client.getIntegerReply(); + final String end) { + checkIsInMulti(); + client.zremrangeByScore(key, start, end); + return client.getIntegerReply(); } /** @@ -2480,9 +2480,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * set at dstkey */ public Long zunionstore(final String dstkey, final String... sets) { - checkIsInMulti(); - client.zunionstore(dstkey, sets); - return client.getIntegerReply(); + checkIsInMulti(); + client.zunionstore(dstkey, sets); + return client.getIntegerReply(); } /** @@ -2525,10 +2525,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, * set at dstkey */ public Long zunionstore(final String dstkey, final ZParams params, - final String... sets) { - checkIsInMulti(); - client.zunionstore(dstkey, params, sets); - return client.getIntegerReply(); + final String... sets) { + checkIsInMulti(); + client.zunionstore(dstkey, params, sets); + return client.getIntegerReply(); } /** @@ -2570,9 +2570,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * set at dstkey */ public Long zinterstore(final String dstkey, final String... sets) { - checkIsInMulti(); - client.zinterstore(dstkey, sets); - return client.getIntegerReply(); + checkIsInMulti(); + client.zinterstore(dstkey, sets); + return client.getIntegerReply(); } /** @@ -2615,66 +2615,66 @@ public class Jedis extends BinaryJedis implements JedisCommands, * set at dstkey */ public Long zinterstore(final String dstkey, final ZParams params, - final String... sets) { - checkIsInMulti(); - client.zinterstore(dstkey, params, sets); - return client.getIntegerReply(); + final String... sets) { + checkIsInMulti(); + client.zinterstore(dstkey, params, sets); + return client.getIntegerReply(); } @Override public Long zlexcount(final String key, final String min, final String max) { - checkIsInMulti(); - client.zlexcount(key, min, max); - return client.getIntegerReply(); + checkIsInMulti(); + client.zlexcount(key, min, max); + return client.getIntegerReply(); } @Override public Set zrangeByLex(final String key, final String min, - final String max) { - checkIsInMulti(); - client.zrangeByLex(key, min, max); - return new LinkedHashSet(client.getMultiBulkReply()); + final String max) { + checkIsInMulti(); + client.zrangeByLex(key, min, max); + return new LinkedHashSet(client.getMultiBulkReply()); } @Override public Set 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(client.getMultiBulkReply()); + final String max, final int offset, final int count) { + checkIsInMulti(); + client.zrangeByLex(key, min, max, offset, count); + return new LinkedHashSet(client.getMultiBulkReply()); } @Override public Set zrevrangeByLex(String key, String max, String min) { - checkIsInMulti(); - client.zrevrangeByLex(key, max, min); - return new LinkedHashSet(client.getMultiBulkReply()); + checkIsInMulti(); + client.zrevrangeByLex(key, max, min); + return new LinkedHashSet(client.getMultiBulkReply()); } @Override public Set zrevrangeByLex(String key, String max, String min, - int offset, int count) { - checkIsInMulti(); - client.zrevrangeByLex(key, max, min, offset, count); - return new LinkedHashSet(client.getMultiBulkReply()); + int offset, int count) { + checkIsInMulti(); + client.zrevrangeByLex(key, max, min, offset, count); + return new LinkedHashSet(client.getMultiBulkReply()); } @Override public Long zremrangeByLex(final String key, final String min, - final String max) { - checkIsInMulti(); - client.zremrangeByLex(key, min, max); - return client.getIntegerReply(); + final String max) { + checkIsInMulti(); + client.zremrangeByLex(key, min, max); + return client.getIntegerReply(); } public Long strlen(final String key) { - client.strlen(key); - return client.getIntegerReply(); + client.strlen(key); + return client.getIntegerReply(); } public Long lpushx(final String key, final String... string) { - client.lpushx(key, string); - return client.getIntegerReply(); + client.lpushx(key, string); + return client.getIntegerReply(); } /** @@ -2688,24 +2688,24 @@ public class Jedis extends BinaryJedis implements JedisCommands, * key is not persist (only happens when key not set). */ public Long persist(final String key) { - client.persist(key); - return client.getIntegerReply(); + client.persist(key); + return client.getIntegerReply(); } public Long rpushx(final String key, final String... string) { - client.rpushx(key, string); - return client.getIntegerReply(); + client.rpushx(key, string); + return client.getIntegerReply(); } public String echo(final String string) { - client.echo(string); - return client.getBulkReply(); + client.echo(string); + return client.getBulkReply(); } public Long linsert(final String key, final LIST_POSITION where, - final String pivot, final String value) { - client.linsert(key, where, pivot, value); - return client.getIntegerReply(); + final String pivot, final String value) { + client.linsert(key, where, pivot, value); + return client.getIntegerReply(); } /** @@ -2718,13 +2718,13 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return the element */ public String brpoplpush(String source, String destination, int timeout) { - client.brpoplpush(source, destination, timeout); - client.setTimeoutInfinite(); - try { - return client.getBulkReply(); - } finally { - client.rollbackTimeout(); - } + client.brpoplpush(source, destination, timeout); + client.setTimeoutInfinite(); + try { + return client.getBulkReply(); + } finally { + client.rollbackTimeout(); + } } /** @@ -2736,13 +2736,13 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return */ public Boolean setbit(String key, long offset, boolean value) { - client.setbit(key, offset, value); - return client.getIntegerReply() == 1; + client.setbit(key, offset, value); + return client.getIntegerReply() == 1; } public Boolean setbit(String key, long offset, String value) { - client.setbit(key, offset, value); - return client.getIntegerReply() == 1; + client.setbit(key, offset, value); + return client.getIntegerReply() == 1; } /** @@ -2753,28 +2753,28 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return */ public Boolean getbit(String key, long offset) { - client.getbit(key, offset); - return client.getIntegerReply() == 1; + client.getbit(key, offset); + return client.getIntegerReply() == 1; } public Long setrange(String key, long offset, String value) { - client.setrange(key, offset, value); - return client.getIntegerReply(); + client.setrange(key, offset, value); + return client.getIntegerReply(); } public String getrange(String key, long startOffset, long endOffset) { - client.getrange(key, startOffset, endOffset); - return client.getBulkReply(); + client.getrange(key, startOffset, endOffset); + return client.getBulkReply(); } public Long bitpos(final String key, final boolean value) { - return bitpos(key, value, new BitPosParams()); + return bitpos(key, value, new BitPosParams()); } public Long bitpos(final String key, final boolean value, - final BitPosParams params) { - client.bitpos(key, value, params); - return client.getIntegerReply(); + final BitPosParams params) { + client.bitpos(key, value, params); + return client.getIntegerReply(); } /** @@ -2814,8 +2814,8 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Bulk reply. */ public List configGet(final String pattern) { - client.configGet(pattern); - return client.getMultiBulkReply(); + client.configGet(pattern); + return client.getMultiBulkReply(); } /** @@ -2853,166 +2853,166 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return Status code reply */ public String configSet(final String parameter, final String value) { - client.configSet(parameter, value); - return client.getStatusCodeReply(); + client.configSet(parameter, value); + return client.getStatusCodeReply(); } public Object eval(String script, int keyCount, String... params) { - client.setTimeoutInfinite(); - try { - client.eval(script, keyCount, params); - return getEvalResult(); - } finally { - client.rollbackTimeout(); - } + client.setTimeoutInfinite(); + try { + client.eval(script, keyCount, params); + return getEvalResult(); + } finally { + client.rollbackTimeout(); + } } public void subscribe(final JedisPubSub jedisPubSub, - final String... channels) { - client.setTimeoutInfinite(); - try { - jedisPubSub.proceed(client, channels); - } finally { - client.rollbackTimeout(); - } + final String... channels) { + client.setTimeoutInfinite(); + try { + jedisPubSub.proceed(client, channels); + } finally { + client.rollbackTimeout(); + } } public Long publish(final String channel, final String message) { - checkIsInMulti(); - connect(); - client.publish(channel, message); - return client.getIntegerReply(); + checkIsInMulti(); + connect(); + client.publish(channel, message); + return client.getIntegerReply(); } public void psubscribe(final JedisPubSub jedisPubSub, - final String... patterns) { - checkIsInMulti(); - client.setTimeoutInfinite(); - try { - jedisPubSub.proceedWithPatterns(client, patterns); - } finally { - client.rollbackTimeout(); - } + final String... patterns) { + checkIsInMulti(); + client.setTimeoutInfinite(); + try { + jedisPubSub.proceedWithPatterns(client, patterns); + } finally { + client.rollbackTimeout(); + } } protected static String[] getParams(List keys, List args) { - int keyCount = keys.size(); - int argCount = args.size(); + int keyCount = keys.size(); + int argCount = args.size(); - String[] params = new String[keyCount + args.size()]; + String[] params = new String[keyCount + args.size()]; - for (int i = 0; i < keyCount; i++) - params[i] = keys.get(i); + for (int i = 0; i < keyCount; i++) + params[i] = keys.get(i); - for (int i = 0; i < argCount; i++) - params[keyCount + i] = args.get(i); + for (int i = 0; i < argCount; i++) + params[keyCount + i] = args.get(i); - return params; + return params; } public Object eval(String script, List keys, List args) { - return eval(script, keys.size(), getParams(keys, args)); + return eval(script, keys.size(), getParams(keys, args)); } public Object eval(String script) { - return eval(script, 0); + return eval(script, 0); } public Object evalsha(String script) { - return evalsha(script, 0); + return evalsha(script, 0); } private Object getEvalResult() { - return evalResult(client.getOne()); + return evalResult(client.getOne()); } private Object evalResult(Object result) { - if (result instanceof byte[]) - return SafeEncoder.encode((byte[]) result); + if (result instanceof byte[]) + return SafeEncoder.encode((byte[]) result); - if (result instanceof List) { - List list = (List) result; - List listResult = new ArrayList(list.size()); - for (Object bin : list) { - listResult.add(evalResult(bin)); - } + if (result instanceof List) { + List list = (List) result; + List listResult = new ArrayList(list.size()); + for (Object bin : list) { + listResult.add(evalResult(bin)); + } - return listResult; - } + return listResult; + } - return result; + return result; } public Object evalsha(String sha1, List keys, List args) { - return evalsha(sha1, keys.size(), getParams(keys, args)); + return evalsha(sha1, keys.size(), getParams(keys, args)); } public Object evalsha(String sha1, int keyCount, String... params) { - checkIsInMulti(); - client.evalsha(sha1, keyCount, params); - return getEvalResult(); + checkIsInMulti(); + client.evalsha(sha1, keyCount, params); + return getEvalResult(); } public Boolean scriptExists(String sha1) { - String[] a = new String[1]; - a[0] = sha1; - return scriptExists(a).get(0); + String[] a = new String[1]; + a[0] = sha1; + return scriptExists(a).get(0); } public List scriptExists(String... sha1) { - client.scriptExists(sha1); - List result = client.getIntegerMultiBulkReply(); - List exists = new ArrayList(); + client.scriptExists(sha1); + List result = client.getIntegerMultiBulkReply(); + List exists = new ArrayList(); - for (Long value : result) - exists.add(value == 1); + for (Long value : result) + exists.add(value == 1); - return exists; + return exists; } public String scriptLoad(String script) { - client.scriptLoad(script); - return client.getBulkReply(); + client.scriptLoad(script); + return client.getBulkReply(); } public List slowlogGet() { - client.slowlogGet(); - return Slowlog.from(client.getObjectMultiBulkReply()); + client.slowlogGet(); + return Slowlog.from(client.getObjectMultiBulkReply()); } public List slowlogGet(long entries) { - client.slowlogGet(entries); - return Slowlog.from(client.getObjectMultiBulkReply()); + client.slowlogGet(entries); + return Slowlog.from(client.getObjectMultiBulkReply()); } public Long objectRefcount(String string) { - client.objectRefcount(string); - return client.getIntegerReply(); + client.objectRefcount(string); + return client.getIntegerReply(); } public String objectEncoding(String string) { - client.objectEncoding(string); - return client.getBulkReply(); + client.objectEncoding(string); + return client.getBulkReply(); } public Long objectIdletime(String string) { - client.objectIdletime(string); - return client.getIntegerReply(); + client.objectIdletime(string); + return client.getIntegerReply(); } public Long bitcount(final String key) { - client.bitcount(key); - return client.getIntegerReply(); + client.bitcount(key); + return client.getIntegerReply(); } public Long bitcount(final String key, long start, long end) { - client.bitcount(key, start, end); - return client.getIntegerReply(); + client.bitcount(key, start, end); + return client.getIntegerReply(); } public Long bitop(BitOP op, final String destKey, String... srcKeys) { - client.bitop(op, destKey, srcKeys); - return client.getIntegerReply(); + client.bitop(op, destKey, srcKeys); + return client.getIntegerReply(); } /** @@ -3049,14 +3049,14 @@ public class Jedis extends BinaryJedis implements JedisCommands, */ @SuppressWarnings("rawtypes") public List> sentinelMasters() { - client.sentinel(Protocol.SENTINEL_MASTERS); - final List reply = client.getObjectMultiBulkReply(); + client.sentinel(Protocol.SENTINEL_MASTERS); + final List reply = client.getObjectMultiBulkReply(); - final List> masters = new ArrayList>(); - for (Object obj : reply) { - masters.add(BuilderFactory.STRING_MAP.build((List) obj)); - } - return masters; + final List> masters = new ArrayList>(); + for (Object obj : reply) { + masters.add(BuilderFactory.STRING_MAP.build((List) obj)); + } + return masters; } /** @@ -3070,9 +3070,9 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return two elements list of strings : host and port. */ public List sentinelGetMasterAddrByName(String masterName) { - client.sentinel(Protocol.SENTINEL_GET_MASTER_ADDR_BY_NAME, masterName); - final List reply = client.getObjectMultiBulkReply(); - return BuilderFactory.STRING_LIST.build(reply); + client.sentinel(Protocol.SENTINEL_GET_MASTER_ADDR_BY_NAME, masterName); + final List reply = client.getObjectMultiBulkReply(); + return BuilderFactory.STRING_LIST.build(reply); } /** @@ -3085,8 +3085,8 @@ public class Jedis extends BinaryJedis implements JedisCommands, * @return */ public Long sentinelReset(String pattern) { - client.sentinel(Protocol.SENTINEL_RESET, pattern); - return client.getIntegerReply(); + client.sentinel(Protocol.SENTINEL_RESET, pattern); + return client.getIntegerReply(); } /** @@ -3127,393 +3127,393 @@ public class Jedis extends BinaryJedis implements JedisCommands, */ @SuppressWarnings("rawtypes") public List> sentinelSlaves(String masterName) { - client.sentinel(Protocol.SENTINEL_SLAVES, masterName); - final List reply = client.getObjectMultiBulkReply(); + client.sentinel(Protocol.SENTINEL_SLAVES, masterName); + final List reply = client.getObjectMultiBulkReply(); - final List> slaves = new ArrayList>(); - for (Object obj : reply) { - slaves.add(BuilderFactory.STRING_MAP.build((List) obj)); - } - return slaves; + final List> slaves = new ArrayList>(); + for (Object obj : reply) { + slaves.add(BuilderFactory.STRING_MAP.build((List) obj)); + } + return slaves; } public String sentinelFailover(String masterName) { - client.sentinel(Protocol.SENTINEL_FAILOVER, masterName); - return client.getStatusCodeReply(); + client.sentinel(Protocol.SENTINEL_FAILOVER, masterName); + return client.getStatusCodeReply(); } public String sentinelMonitor(String masterName, String ip, int port, - int quorum) { - client.sentinel(Protocol.SENTINEL_MONITOR, masterName, ip, - String.valueOf(port), String.valueOf(quorum)); - return client.getStatusCodeReply(); + int quorum) { + client.sentinel(Protocol.SENTINEL_MONITOR, masterName, ip, + String.valueOf(port), String.valueOf(quorum)); + return client.getStatusCodeReply(); } public String sentinelRemove(String masterName) { - client.sentinel(Protocol.SENTINEL_REMOVE, masterName); - return client.getStatusCodeReply(); + client.sentinel(Protocol.SENTINEL_REMOVE, masterName); + return client.getStatusCodeReply(); } public String sentinelSet(String masterName, - Map parameterMap) { - int index = 0; - int paramsLength = parameterMap.size() * 2 + 2; - String[] params = new String[paramsLength]; + Map parameterMap) { + int index = 0; + int paramsLength = parameterMap.size() * 2 + 2; + String[] params = new String[paramsLength]; - params[index++] = Protocol.SENTINEL_SET; - params[index++] = masterName; - for (Entry entry : parameterMap.entrySet()) { - params[index++] = entry.getKey(); - params[index++] = entry.getValue(); - } + params[index++] = Protocol.SENTINEL_SET; + params[index++] = masterName; + for (Entry entry : parameterMap.entrySet()) { + params[index++] = entry.getKey(); + params[index++] = entry.getValue(); + } - client.sentinel(params); - return client.getStatusCodeReply(); + client.sentinel(params); + return client.getStatusCodeReply(); } public byte[] dump(final String key) { - checkIsInMulti(); - client.dump(key); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.dump(key); + return client.getBinaryBulkReply(); } public String restore(final String key, final int ttl, - final byte[] serializedValue) { - checkIsInMulti(); - client.restore(key, ttl, serializedValue); - return client.getStatusCodeReply(); + final byte[] serializedValue) { + checkIsInMulti(); + client.restore(key, ttl, serializedValue); + return client.getStatusCodeReply(); } public Long pexpire(final String key, final long milliseconds) { - checkIsInMulti(); - client.pexpire(key, milliseconds); - return client.getIntegerReply(); + checkIsInMulti(); + client.pexpire(key, milliseconds); + return client.getIntegerReply(); } public Long pexpireAt(final String key, final long millisecondsTimestamp) { - checkIsInMulti(); - client.pexpireAt(key, millisecondsTimestamp); - return client.getIntegerReply(); + checkIsInMulti(); + client.pexpireAt(key, millisecondsTimestamp); + return client.getIntegerReply(); } public Long pttl(final String key) { - checkIsInMulti(); - client.pttl(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.pttl(key); + return client.getIntegerReply(); } public String psetex(final String key, final int milliseconds, - final String value) { - checkIsInMulti(); - client.psetex(key, milliseconds, value); - return client.getStatusCodeReply(); + final String value) { + checkIsInMulti(); + client.psetex(key, milliseconds, value); + return client.getStatusCodeReply(); } public String set(final String key, final String value, final String nxxx) { - checkIsInMulti(); - client.set(key, value, nxxx); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.set(key, value, nxxx); + return client.getStatusCodeReply(); } public String set(final String key, final String value, final String nxxx, - final String expx, final int time) { - checkIsInMulti(); - client.set(key, value, nxxx, expx, time); - return client.getStatusCodeReply(); + final String expx, final int time) { + checkIsInMulti(); + client.set(key, value, nxxx, expx, time); + return client.getStatusCodeReply(); } public String clientKill(final String client) { - checkIsInMulti(); - this.client.clientKill(client); - return this.client.getStatusCodeReply(); + checkIsInMulti(); + this.client.clientKill(client); + return this.client.getStatusCodeReply(); } public String clientSetname(final String name) { - checkIsInMulti(); - client.clientSetname(name); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.clientSetname(name); + return client.getStatusCodeReply(); } public String migrate(final String host, final int port, final String key, - final int destinationDb, final int timeout) { - checkIsInMulti(); - client.migrate(host, port, key, destinationDb, timeout); - return client.getStatusCodeReply(); + final int destinationDb, final int timeout) { + checkIsInMulti(); + client.migrate(host, port, key, destinationDb, timeout); + return client.getStatusCodeReply(); } public ScanResult scan(final String cursor) { - return scan(cursor, new ScanParams()); + return scan(cursor, new ScanParams()); } public ScanResult scan(final String cursor, final ScanParams params) { - checkIsInMulti(); - client.scan(cursor, params); - List result = client.getObjectMultiBulkReply(); - String newcursor = new String((byte[]) result.get(0)); - List results = new ArrayList(); - List rawResults = (List) result.get(1); - for (byte[] bs : rawResults) { - results.add(SafeEncoder.encode(bs)); - } - return new ScanResult(newcursor, results); + checkIsInMulti(); + client.scan(cursor, params); + List result = client.getObjectMultiBulkReply(); + String newcursor = new String((byte[]) result.get(0)); + List results = new ArrayList(); + List rawResults = (List) result.get(1); + for (byte[] bs : rawResults) { + results.add(SafeEncoder.encode(bs)); + } + return new ScanResult(newcursor, results); } public ScanResult> hscan(final String key, - final String cursor) { - return hscan(key, cursor, new ScanParams()); + final String cursor) { + return hscan(key, cursor, new ScanParams()); } public ScanResult> hscan(final String key, - final String cursor, final ScanParams params) { - checkIsInMulti(); - client.hscan(key, cursor, params); - List result = client.getObjectMultiBulkReply(); - String newcursor = new String((byte[]) result.get(0)); - List> results = new ArrayList>(); - List rawResults = (List) result.get(1); - Iterator iterator = rawResults.iterator(); - while (iterator.hasNext()) { - results.add(new AbstractMap.SimpleEntry(SafeEncoder - .encode(iterator.next()), SafeEncoder.encode(iterator - .next()))); - } - return new ScanResult>(newcursor, results); + final String cursor, final ScanParams params) { + checkIsInMulti(); + client.hscan(key, cursor, params); + List result = client.getObjectMultiBulkReply(); + String newcursor = new String((byte[]) result.get(0)); + List> results = new ArrayList>(); + List rawResults = (List) result.get(1); + Iterator iterator = rawResults.iterator(); + while (iterator.hasNext()) { + results.add(new AbstractMap.SimpleEntry(SafeEncoder + .encode(iterator.next()), SafeEncoder.encode(iterator + .next()))); + } + return new ScanResult>(newcursor, results); } public ScanResult sscan(final String key, final String cursor) { - return sscan(key, cursor, new ScanParams()); + return sscan(key, cursor, new ScanParams()); } public ScanResult sscan(final String key, final String cursor, - final ScanParams params) { - checkIsInMulti(); - client.sscan(key, cursor, params); - List result = client.getObjectMultiBulkReply(); - String newcursor = new String((byte[]) result.get(0)); - List results = new ArrayList(); - List rawResults = (List) result.get(1); - for (byte[] bs : rawResults) { - results.add(SafeEncoder.encode(bs)); - } - return new ScanResult(newcursor, results); + final ScanParams params) { + checkIsInMulti(); + client.sscan(key, cursor, params); + List result = client.getObjectMultiBulkReply(); + String newcursor = new String((byte[]) result.get(0)); + List results = new ArrayList(); + List rawResults = (List) result.get(1); + for (byte[] bs : rawResults) { + results.add(SafeEncoder.encode(bs)); + } + return new ScanResult(newcursor, results); } public ScanResult zscan(final String key, final String cursor) { - return zscan(key, cursor, new ScanParams()); + return zscan(key, cursor, new ScanParams()); } public ScanResult zscan(final String key, final String cursor, - final ScanParams params) { - checkIsInMulti(); - client.zscan(key, cursor, params); - List result = client.getObjectMultiBulkReply(); - String newcursor = new String((byte[]) result.get(0)); - List results = new ArrayList(); - List rawResults = (List) result.get(1); - Iterator iterator = rawResults.iterator(); - while (iterator.hasNext()) { - results.add(new Tuple(SafeEncoder.encode(iterator.next()), Double - .valueOf(SafeEncoder.encode(iterator.next())))); - } - return new ScanResult(newcursor, results); + final ScanParams params) { + checkIsInMulti(); + client.zscan(key, cursor, params); + List result = client.getObjectMultiBulkReply(); + String newcursor = new String((byte[]) result.get(0)); + List results = new ArrayList(); + List rawResults = (List) result.get(1); + Iterator iterator = rawResults.iterator(); + while (iterator.hasNext()) { + results.add(new Tuple(SafeEncoder.encode(iterator.next()), Double + .valueOf(SafeEncoder.encode(iterator.next())))); + } + return new ScanResult(newcursor, results); } public String clusterNodes() { - checkIsInMulti(); - client.clusterNodes(); - return client.getBulkReply(); + checkIsInMulti(); + client.clusterNodes(); + return client.getBulkReply(); } public String clusterMeet(final String ip, final int port) { - checkIsInMulti(); - client.clusterMeet(ip, port); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.clusterMeet(ip, port); + return client.getStatusCodeReply(); } public String clusterReset(final Reset resetType) { - checkIsInMulti(); - client.clusterReset(resetType); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.clusterReset(resetType); + return client.getStatusCodeReply(); } public String clusterAddSlots(final int... slots) { - checkIsInMulti(); - client.clusterAddSlots(slots); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.clusterAddSlots(slots); + return client.getStatusCodeReply(); } public String clusterDelSlots(final int... slots) { - checkIsInMulti(); - client.clusterDelSlots(slots); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.clusterDelSlots(slots); + return client.getStatusCodeReply(); } public String clusterInfo() { - checkIsInMulti(); - client.clusterInfo(); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.clusterInfo(); + return client.getStatusCodeReply(); } public List clusterGetKeysInSlot(final int slot, final int count) { - checkIsInMulti(); - client.clusterGetKeysInSlot(slot, count); - return client.getMultiBulkReply(); + checkIsInMulti(); + client.clusterGetKeysInSlot(slot, count); + return client.getMultiBulkReply(); } public String clusterSetSlotNode(final int slot, final String nodeId) { - checkIsInMulti(); - client.clusterSetSlotNode(slot, nodeId); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.clusterSetSlotNode(slot, nodeId); + return client.getStatusCodeReply(); } public String clusterSetSlotMigrating(final int slot, final String nodeId) { - checkIsInMulti(); - client.clusterSetSlotMigrating(slot, nodeId); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.clusterSetSlotMigrating(slot, nodeId); + return client.getStatusCodeReply(); } public String clusterSetSlotImporting(final int slot, final String nodeId) { - checkIsInMulti(); - client.clusterSetSlotImporting(slot, nodeId); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.clusterSetSlotImporting(slot, nodeId); + return client.getStatusCodeReply(); } public String clusterSetSlotStable(final int slot) { - checkIsInMulti(); - client.clusterSetSlotStable(slot); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.clusterSetSlotStable(slot); + return client.getStatusCodeReply(); } public String clusterForget(final String nodeId) { - checkIsInMulti(); - client.clusterForget(nodeId); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.clusterForget(nodeId); + return client.getStatusCodeReply(); } public String clusterFlushSlots() { - checkIsInMulti(); - client.clusterFlushSlots(); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.clusterFlushSlots(); + return client.getStatusCodeReply(); } public Long clusterKeySlot(final String key) { - checkIsInMulti(); - client.clusterKeySlot(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.clusterKeySlot(key); + return client.getIntegerReply(); } public Long clusterCountKeysInSlot(final int slot) { - checkIsInMulti(); - client.clusterCountKeysInSlot(slot); - return client.getIntegerReply(); + checkIsInMulti(); + client.clusterCountKeysInSlot(slot); + return client.getIntegerReply(); } public String clusterSaveConfig() { - checkIsInMulti(); - client.clusterSaveConfig(); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.clusterSaveConfig(); + return client.getStatusCodeReply(); } public String clusterReplicate(final String nodeId) { - checkIsInMulti(); - client.clusterReplicate(nodeId); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.clusterReplicate(nodeId); + return client.getStatusCodeReply(); } public List clusterSlaves(final String nodeId) { - checkIsInMulti(); - client.clusterSlaves(nodeId); - return client.getMultiBulkReply(); + checkIsInMulti(); + client.clusterSlaves(nodeId); + return client.getMultiBulkReply(); } public String clusterFailover() { - checkIsInMulti(); - client.clusterFailover(); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.clusterFailover(); + return client.getStatusCodeReply(); } @Override public List clusterSlots() { - checkIsInMulti(); - client.clusterSlots(); - return client.getObjectMultiBulkReply(); + checkIsInMulti(); + client.clusterSlots(); + return client.getObjectMultiBulkReply(); } public String asking() { - checkIsInMulti(); - client.asking(); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.asking(); + return client.getStatusCodeReply(); } public List pubsubChannels(String pattern) { - checkIsInMulti(); - client.pubsubChannels(pattern); - return client.getMultiBulkReply(); + checkIsInMulti(); + client.pubsubChannels(pattern); + return client.getMultiBulkReply(); } public Long pubsubNumPat() { - checkIsInMulti(); - client.pubsubNumPat(); - return client.getIntegerReply(); + checkIsInMulti(); + client.pubsubNumPat(); + return client.getIntegerReply(); } public Map pubsubNumSub(String... channels) { - checkIsInMulti(); - client.pubsubNumSub(channels); - return BuilderFactory.PUBSUB_NUMSUB_MAP.build(client - .getBinaryMultiBulkReply()); + checkIsInMulti(); + client.pubsubNumSub(channels); + return BuilderFactory.PUBSUB_NUMSUB_MAP.build(client + .getBinaryMultiBulkReply()); } @Override public void close() { - if (dataSource != null) { - if (client.isBroken()) { - this.dataSource.returnBrokenResource(this); - } else { - this.dataSource.returnResource(this); - } - } else { - client.close(); - } + if (dataSource != null) { + if (client.isBroken()) { + this.dataSource.returnBrokenResource(this); + } else { + this.dataSource.returnResource(this); + } + } else { + client.close(); + } } public void setDataSource(Pool jedisPool) { - this.dataSource = jedisPool; + this.dataSource = jedisPool; } public Long pfadd(final String key, final String... elements) { - checkIsInMulti(); - client.pfadd(key, elements); - return client.getIntegerReply(); + checkIsInMulti(); + client.pfadd(key, elements); + return client.getIntegerReply(); } public long pfcount(final String key) { - checkIsInMulti(); - client.pfcount(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.pfcount(key); + return client.getIntegerReply(); } @Override public long pfcount(String... keys) { - checkIsInMulti(); - client.pfcount(keys); - return client.getIntegerReply(); + checkIsInMulti(); + client.pfcount(keys); + return client.getIntegerReply(); } public String pfmerge(final String destkey, final String... sourcekeys) { - checkIsInMulti(); - client.pfmerge(destkey, sourcekeys); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.pfmerge(destkey, sourcekeys); + return client.getStatusCodeReply(); } @Override public List blpop(int timeout, String key) { - return blpop(key, String.valueOf(timeout)); + return blpop(key, String.valueOf(timeout)); } @Override public List brpop(int timeout, String key) { - return brpop(key, String.valueOf(timeout)); + return brpop(key, String.valueOf(timeout)); } } diff --git a/src/main/java/redis/clients/jedis/JedisCluster.java b/src/main/java/redis/clients/jedis/JedisCluster.java index 256ae34..befd352 100644 --- a/src/main/java/redis/clients/jedis/JedisCluster.java +++ b/src/main/java/redis/clients/jedis/JedisCluster.java @@ -16,7 +16,7 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable { private static final int DEFAULT_MAX_REDIRECTIONS = 5; public static enum Reset { - SOFT, HARD + SOFT, HARD } private int timeout; @@ -25,272 +25,272 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable { private JedisClusterConnectionHandler connectionHandler; public JedisCluster(Set nodes, int timeout) { - this(nodes, timeout, DEFAULT_MAX_REDIRECTIONS); + this(nodes, timeout, DEFAULT_MAX_REDIRECTIONS); } public JedisCluster(Set nodes) { - this(nodes, DEFAULT_TIMEOUT); + this(nodes, DEFAULT_TIMEOUT); } public JedisCluster(Set nodes, int timeout, int maxRedirections) { - this(nodes, timeout, maxRedirections, new GenericObjectPoolConfig()); + this(nodes, timeout, maxRedirections, new GenericObjectPoolConfig()); } public JedisCluster(Set nodes, - final GenericObjectPoolConfig poolConfig) { - this(nodes, DEFAULT_TIMEOUT, DEFAULT_MAX_REDIRECTIONS, poolConfig); + final GenericObjectPoolConfig poolConfig) { + this(nodes, DEFAULT_TIMEOUT, DEFAULT_MAX_REDIRECTIONS, poolConfig); } public JedisCluster(Set nodes, int timeout, - final GenericObjectPoolConfig poolConfig) { - this(nodes, timeout, DEFAULT_MAX_REDIRECTIONS, poolConfig); + final GenericObjectPoolConfig poolConfig) { + this(nodes, timeout, DEFAULT_MAX_REDIRECTIONS, poolConfig); } public JedisCluster(Set jedisClusterNode, int timeout, - int maxRedirections, final GenericObjectPoolConfig poolConfig) { - this.connectionHandler = new JedisSlotBasedConnectionHandler( - jedisClusterNode, poolConfig); - this.timeout = timeout; - this.maxRedirections = maxRedirections; + int maxRedirections, final GenericObjectPoolConfig poolConfig) { + this.connectionHandler = new JedisSlotBasedConnectionHandler( + jedisClusterNode, poolConfig); + this.timeout = timeout; + this.maxRedirections = maxRedirections; } @Override public void close() { - if (connectionHandler != null) { - for (JedisPool pool : connectionHandler.getNodes().values()) { - try { - if (pool != null) { - pool.destroy(); - } - } catch (Exception e) { - // pass - } - } - } + if (connectionHandler != null) { + for (JedisPool pool : connectionHandler.getNodes().values()) { + try { + if (pool != null) { + pool.destroy(); + } + } catch (Exception e) { + // pass + } + } + } } @Override public String set(final String key, final String value) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.set(key, value); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.set(key, value); + } + }.run(key); } @Override public String set(final String key, final String value, final String nxxx, - final String expx, final long time) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.set(key, value, nxxx, expx, time); - } - }.run(key); + final String expx, final long time) { + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.set(key, value, nxxx, expx, time); + } + }.run(key); } @Override public String get(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.get(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.get(key); + } + }.run(key); } @Override public Boolean exists(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Boolean execute(Jedis connection) { - return connection.exists(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Boolean execute(Jedis connection) { + return connection.exists(key); + } + }.run(key); } @Override public Long persist(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.persist(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.persist(key); + } + }.run(key); } @Override public String type(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.type(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.type(key); + } + }.run(key); } @Override public Long expire(final String key, final int seconds) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.expire(key, seconds); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.expire(key, seconds); + } + }.run(key); } @Override public Long expireAt(final String key, final long unixTime) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.expireAt(key, unixTime); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.expireAt(key, unixTime); + } + }.run(key); } @Override public Long ttl(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.ttl(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.ttl(key); + } + }.run(key); } @Override public Boolean setbit(final String key, final long offset, - final boolean value) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Boolean execute(Jedis connection) { - return connection.setbit(key, offset, value); - } - }.run(key); + final boolean value) { + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Boolean execute(Jedis connection) { + return connection.setbit(key, offset, value); + } + }.run(key); } @Override public Boolean setbit(final String key, final long offset, - final String value) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Boolean execute(Jedis connection) { - return connection.setbit(key, offset, value); - } - }.run(key); + final String value) { + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Boolean execute(Jedis connection) { + return connection.setbit(key, offset, value); + } + }.run(key); } @Override public Boolean getbit(final String key, final long offset) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Boolean execute(Jedis connection) { - return connection.getbit(key, offset); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Boolean execute(Jedis connection) { + return connection.getbit(key, offset); + } + }.run(key); } @Override public Long setrange(final String key, final long offset, final String value) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.setrange(key, offset, value); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.setrange(key, offset, value); + } + }.run(key); } @Override public String getrange(final String key, final long startOffset, - final long endOffset) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.getrange(key, startOffset, endOffset); - } - }.run(key); + final long endOffset) { + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.getrange(key, startOffset, endOffset); + } + }.run(key); } @Override public String getSet(final String key, final String value) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.getSet(key, value); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.getSet(key, value); + } + }.run(key); } @Override public Long setnx(final String key, final String value) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.setnx(key, value); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.setnx(key, value); + } + }.run(key); } @Override public String setex(final String key, final int seconds, final String value) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.setex(key, seconds, value); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.setex(key, seconds, value); + } + }.run(key); } @Override public Long decrBy(final String key, final long integer) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.decrBy(key, integer); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.decrBy(key, integer); + } + }.run(key); } @Override public Long decr(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.decr(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.decr(key); + } + }.run(key); } @Override public Long incrBy(final String key, final long integer) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.incrBy(key, integer); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.incrBy(key, integer); + } + }.run(key); } @Override @@ -306,1275 +306,1275 @@ public class JedisCluster implements JedisCommands, BasicCommands, Closeable { @Override public Long incr(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.incr(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.incr(key); + } + }.run(key); } @Override public Long append(final String key, final String value) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.append(key, value); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.append(key, value); + } + }.run(key); } @Override public String substr(final String key, final int start, final int end) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.substr(key, start, end); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.substr(key, start, end); + } + }.run(key); } @Override public Long hset(final String key, final String field, final String value) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.hset(key, field, value); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.hset(key, field, value); + } + }.run(key); } @Override public String hget(final String key, final String field) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.hget(key, field); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.hget(key, field); + } + }.run(key); } @Override public Long hsetnx(final String key, final String field, final String value) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.hsetnx(key, field, value); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.hsetnx(key, field, value); + } + }.run(key); } @Override public String hmset(final String key, final Map hash) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.hmset(key, hash); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.hmset(key, hash); + } + }.run(key); } @Override public List hmget(final String key, final String... fields) { - return new JedisClusterCommand>(connectionHandler, - timeout, maxRedirections) { - @Override - public List execute(Jedis connection) { - return connection.hmget(key, fields); - } - }.run(key); + return new JedisClusterCommand>(connectionHandler, + timeout, maxRedirections) { + @Override + public List execute(Jedis connection) { + return connection.hmget(key, fields); + } + }.run(key); } @Override public Long hincrBy(final String key, final String field, final long value) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.hincrBy(key, field, value); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.hincrBy(key, field, value); + } + }.run(key); } @Override public Boolean hexists(final String key, final String field) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Boolean execute(Jedis connection) { - return connection.hexists(key, field); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Boolean execute(Jedis connection) { + return connection.hexists(key, field); + } + }.run(key); } @Override public Long hdel(final String key, final String... field) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.hdel(key, field); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.hdel(key, field); + } + }.run(key); } @Override public Long hlen(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.hlen(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.hlen(key); + } + }.run(key); } @Override public Set hkeys(final String key) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.hkeys(key); - } - }.run(key); + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.hkeys(key); + } + }.run(key); } @Override public List hvals(final String key) { - return new JedisClusterCommand>(connectionHandler, - timeout, maxRedirections) { - @Override - public List execute(Jedis connection) { - return connection.hvals(key); - } - }.run(key); + return new JedisClusterCommand>(connectionHandler, + timeout, maxRedirections) { + @Override + public List execute(Jedis connection) { + return connection.hvals(key); + } + }.run(key); } @Override public Map hgetAll(final String key) { - return new JedisClusterCommand>(connectionHandler, - timeout, maxRedirections) { - @Override - public Map execute(Jedis connection) { - return connection.hgetAll(key); - } - }.run(key); + return new JedisClusterCommand>(connectionHandler, + timeout, maxRedirections) { + @Override + public Map execute(Jedis connection) { + return connection.hgetAll(key); + } + }.run(key); } @Override public Long rpush(final String key, final String... string) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.rpush(key, string); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.rpush(key, string); + } + }.run(key); } @Override public Long lpush(final String key, final String... string) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.lpush(key, string); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.lpush(key, string); + } + }.run(key); } @Override public Long llen(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.llen(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.llen(key); + } + }.run(key); } @Override public List lrange(final String key, final long start, - final long end) { - return new JedisClusterCommand>(connectionHandler, - timeout, maxRedirections) { - @Override - public List execute(Jedis connection) { - return connection.lrange(key, start, end); - } - }.run(key); + final long end) { + return new JedisClusterCommand>(connectionHandler, + timeout, maxRedirections) { + @Override + public List execute(Jedis connection) { + return connection.lrange(key, start, end); + } + }.run(key); } @Override public String ltrim(final String key, final long start, final long end) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.ltrim(key, start, end); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.ltrim(key, start, end); + } + }.run(key); } @Override public String lindex(final String key, final long index) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.lindex(key, index); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.lindex(key, index); + } + }.run(key); } @Override public String lset(final String key, final long index, final String value) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.lset(key, index, value); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.lset(key, index, value); + } + }.run(key); } @Override public Long lrem(final String key, final long count, final String value) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.lrem(key, count, value); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.lrem(key, count, value); + } + }.run(key); } @Override public String lpop(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.lpop(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.lpop(key); + } + }.run(key); } @Override public String rpop(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.rpop(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.rpop(key); + } + }.run(key); } @Override public Long sadd(final String key, final String... member) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.sadd(key, member); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.sadd(key, member); + } + }.run(key); } @Override public Set smembers(final String key) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.smembers(key); - } - }.run(key); + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.smembers(key); + } + }.run(key); } @Override public Long srem(final String key, final String... member) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.srem(key, member); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.srem(key, member); + } + }.run(key); } @Override public String spop(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.spop(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.spop(key); + } + }.run(key); } @Override public Long scard(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.scard(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.scard(key); + } + }.run(key); } @Override public Boolean sismember(final String key, final String member) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Boolean execute(Jedis connection) { - return connection.sismember(key, member); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Boolean execute(Jedis connection) { + return connection.sismember(key, member); + } + }.run(key); } @Override public String srandmember(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.srandmember(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.srandmember(key); + } + }.run(key); } @Override public List srandmember(final String key, final int count) { - return new JedisClusterCommand>(connectionHandler, - timeout, maxRedirections) { - @Override - public List execute(Jedis connection) { - return connection.srandmember(key, count); - } - }.run(key); + return new JedisClusterCommand>(connectionHandler, + timeout, maxRedirections) { + @Override + public List execute(Jedis connection) { + return connection.srandmember(key, count); + } + }.run(key); } @Override public Long strlen(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.strlen(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.strlen(key); + } + }.run(key); } @Override public Long zadd(final String key, final double score, final String member) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.zadd(key, score, member); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.zadd(key, score, member); + } + }.run(key); } @Override public Long zadd(final String key, final Map scoreMembers) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.zadd(key, scoreMembers); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.zadd(key, scoreMembers); + } + }.run(key); } @Override public Set zrange(final String key, final long start, final long end) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrange(key, start, end); - } - }.run(key); + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrange(key, start, end); + } + }.run(key); } @Override public Long zrem(final String key, final String... member) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.zrem(key, member); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.zrem(key, member); + } + }.run(key); } @Override public Double zincrby(final String key, final double score, - final String member) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Double execute(Jedis connection) { - return connection.zincrby(key, score, member); - } - }.run(key); + final String member) { + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Double execute(Jedis connection) { + return connection.zincrby(key, score, member); + } + }.run(key); } @Override public Long zrank(final String key, final String member) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.zrank(key, member); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.zrank(key, member); + } + }.run(key); } @Override public Long zrevrank(final String key, final String member) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.zrevrank(key, member); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.zrevrank(key, member); + } + }.run(key); } @Override public Set zrevrange(final String key, final long start, - final long end) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrevrange(key, start, end); - } - }.run(key); + final long end) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrange(key, start, end); + } + }.run(key); } @Override public Set zrangeWithScores(final String key, final long start, - final long end) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrangeWithScores(key, start, end); - } - }.run(key); + final long end) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeWithScores(key, start, end); + } + }.run(key); } @Override public Set zrevrangeWithScores(final String key, final long start, - final long end) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrevrangeWithScores(key, start, end); - } - }.run(key); + final long end) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeWithScores(key, start, end); + } + }.run(key); } @Override public Long zcard(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.zcard(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.zcard(key); + } + }.run(key); } @Override public Double zscore(final String key, final String member) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Double execute(Jedis connection) { - return connection.zscore(key, member); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Double execute(Jedis connection) { + return connection.zscore(key, member); + } + }.run(key); } @Override public List sort(final String key) { - return new JedisClusterCommand>(connectionHandler, - timeout, maxRedirections) { - @Override - public List execute(Jedis connection) { - return connection.sort(key); - } - }.run(key); + return new JedisClusterCommand>(connectionHandler, + timeout, maxRedirections) { + @Override + public List execute(Jedis connection) { + return connection.sort(key); + } + }.run(key); } @Override public List sort(final String key, - final SortingParams sortingParameters) { - return new JedisClusterCommand>(connectionHandler, - timeout, maxRedirections) { - @Override - public List execute(Jedis connection) { - return connection.sort(key, sortingParameters); - } - }.run(key); + final SortingParams sortingParameters) { + return new JedisClusterCommand>(connectionHandler, + timeout, maxRedirections) { + @Override + public List execute(Jedis connection) { + return connection.sort(key, sortingParameters); + } + }.run(key); } @Override public Long zcount(final String key, final double min, final double max) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.zcount(key, min, max); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.zcount(key, min, max); + } + }.run(key); } @Override public Long zcount(final String key, final String min, final String max) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.zcount(key, min, max); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.zcount(key, min, max); + } + }.run(key); } @Override public Set zrangeByScore(final String key, final double min, - final double max) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrangeByScore(key, min, max); - } - }.run(key); + final double max) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByScore(key, min, max); + } + }.run(key); } @Override public Set zrangeByScore(final String key, final String min, - final String max) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrangeByScore(key, min, max); - } - }.run(key); + final String max) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByScore(key, min, max); + } + }.run(key); } @Override public Set zrevrangeByScore(final String key, final double max, - final double min) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrevrangeByScore(key, min, max); - } - }.run(key); + final double min) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeByScore(key, min, max); + } + }.run(key); } @Override public Set zrangeByScore(final String key, final double min, - final double max, final int offset, final int count) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrangeByScore(key, min, max, offset, count); - } - }.run(key); + final double max, final int offset, final int count) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByScore(key, min, max, offset, count); + } + }.run(key); } @Override public Set zrevrangeByScore(final String key, final String max, - final String min) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrevrangeByScore(key, min, max); - } - }.run(key); + final String min) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeByScore(key, min, max); + } + }.run(key); } @Override public Set zrangeByScore(final String key, final String min, - final String max, final int offset, final int count) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrangeByScore(key, min, max, offset, count); - } - }.run(key); + final String max, final int offset, final int count) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByScore(key, min, max, offset, count); + } + }.run(key); } @Override public Set zrevrangeByScore(final String key, final double max, - final double min, final int offset, final int count) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection - .zrevrangeByScore(key, min, max, offset, count); - } - }.run(key); + final double min, final int offset, final int count) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection + .zrevrangeByScore(key, min, max, offset, count); + } + }.run(key); } @Override public Set zrangeByScoreWithScores(final String key, - final double min, final double max) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrangeByScoreWithScores(key, min, max); - } - }.run(key); + final double min, final double max) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByScoreWithScores(key, min, max); + } + }.run(key); } @Override public Set zrevrangeByScoreWithScores(final String key, - final double max, final double min) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrevrangeByScoreWithScores(key, min, max); - } - }.run(key); + final double max, final double min) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeByScoreWithScores(key, min, max); + } + }.run(key); } @Override public Set zrangeByScoreWithScores(final String key, - final double min, final double max, final int offset, - final int count) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrangeByScoreWithScores(key, min, max, - offset, count); - } - }.run(key); + final double min, final double max, final int offset, + final int count) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByScoreWithScores(key, min, max, + offset, count); + } + }.run(key); } @Override public Set zrevrangeByScore(final String key, final String max, - final String min, final int offset, final int count) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection - .zrevrangeByScore(key, min, max, offset, count); - } - }.run(key); + final String min, final int offset, final int count) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection + .zrevrangeByScore(key, min, max, offset, count); + } + }.run(key); } @Override public Set zrangeByScoreWithScores(final String key, - final String min, final String max) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrangeByScoreWithScores(key, min, max); - } - }.run(key); + final String min, final String max) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByScoreWithScores(key, min, max); + } + }.run(key); } @Override public Set zrevrangeByScoreWithScores(final String key, - final String max, final String min) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrevrangeByScoreWithScores(key, min, max); - } - }.run(key); + final String max, final String min) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeByScoreWithScores(key, min, max); + } + }.run(key); } @Override public Set zrangeByScoreWithScores(final String key, - final String min, final String max, final int offset, - final int count) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrangeByScoreWithScores(key, min, max, - offset, count); - } - }.run(key); + final String min, final String max, final int offset, + final int count) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByScoreWithScores(key, min, max, + offset, count); + } + }.run(key); } @Override public Set zrevrangeByScoreWithScores(final String key, - final double max, final double min, final int offset, - final int count) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrevrangeByScoreWithScores(key, max, min, - offset, count); - } - }.run(key); + final double max, final double min, final int offset, + final int count) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeByScoreWithScores(key, max, min, + offset, count); + } + }.run(key); } @Override public Set zrevrangeByScoreWithScores(final String key, - final String max, final String min, final int offset, - final int count) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrevrangeByScoreWithScores(key, max, min, - offset, count); - } - }.run(key); + final String max, final String min, final int offset, + final int count) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeByScoreWithScores(key, max, min, + offset, count); + } + }.run(key); } @Override public Long zremrangeByRank(final String key, final long start, - final long end) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.zremrangeByRank(key, start, end); - } - }.run(key); + final long end) { + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.zremrangeByRank(key, start, end); + } + }.run(key); } @Override public Long zremrangeByScore(final String key, final double start, - final double end) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.zremrangeByScore(key, start, end); - } - }.run(key); + final double end) { + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.zremrangeByScore(key, start, end); + } + }.run(key); } @Override public Long zremrangeByScore(final String key, final String start, - final String end) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.zremrangeByScore(key, start, end); - } - }.run(key); + final String end) { + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.zremrangeByScore(key, start, end); + } + }.run(key); } @Override public Long zlexcount(final String key, final String min, final String max) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.zlexcount(key, min, max); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.zlexcount(key, min, max); + } + }.run(key); } @Override public Set zrangeByLex(final String key, final String min, - final String max) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrangeByLex(key, min, max); - } - }.run(key); + final String max) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByLex(key, min, max); + } + }.run(key); } @Override public Set zrangeByLex(final String key, final String min, - final String max, final int offset, final int count) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrangeByLex(key, min, max, offset, count); - } - }.run(key); + final String max, final int offset, final int count) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrangeByLex(key, min, max, offset, count); + } + }.run(key); } @Override public Set zrevrangeByLex(final String key, final String max, - final String min) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrevrangeByLex(key, max, min); - } - }.run(key); + final String min) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeByLex(key, max, min); + } + }.run(key); } @Override public Set zrevrangeByLex(final String key, final String max, - final String min, final int offset, final int count) { - return new JedisClusterCommand>(connectionHandler, timeout, - maxRedirections) { - @Override - public Set execute(Jedis connection) { - return connection.zrevrangeByLex(key, max, min, offset, count); - } - }.run(key); + final String min, final int offset, final int count) { + return new JedisClusterCommand>(connectionHandler, timeout, + maxRedirections) { + @Override + public Set execute(Jedis connection) { + return connection.zrevrangeByLex(key, max, min, offset, count); + } + }.run(key); } @Override public Long zremrangeByLex(final String key, final String min, - final String max) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.zremrangeByLex(key, min, max); - } - }.run(key); + final String max) { + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.zremrangeByLex(key, min, max); + } + }.run(key); } @Override public Long linsert(final String key, final LIST_POSITION where, - final String pivot, final String value) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.linsert(key, where, pivot, value); - } - }.run(key); + final String pivot, final String value) { + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.linsert(key, where, pivot, value); + } + }.run(key); } @Override public Long lpushx(final String key, final String... string) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.lpushx(key, string); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.lpushx(key, string); + } + }.run(key); } @Override public Long rpushx(final String key, final String... string) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.rpushx(key, string); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.rpushx(key, string); + } + }.run(key); } @Override public List blpop(final String arg) { - return new JedisClusterCommand>(connectionHandler, - timeout, maxRedirections) { - @Override - public List execute(Jedis connection) { - return connection.blpop(arg); - } - }.run(null); + return new JedisClusterCommand>(connectionHandler, + timeout, maxRedirections) { + @Override + public List execute(Jedis connection) { + return connection.blpop(arg); + } + }.run(null); } @Override public List brpop(final String arg) { - return new JedisClusterCommand>(connectionHandler, - timeout, maxRedirections) { - @Override - public List execute(Jedis connection) { - return connection.brpop(arg); - } - }.run(null); + return new JedisClusterCommand>(connectionHandler, + timeout, maxRedirections) { + @Override + public List execute(Jedis connection) { + return connection.brpop(arg); + } + }.run(null); } @Override public Long del(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.del(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.del(key); + } + }.run(key); } @Override public String echo(final String string) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.echo(string); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.echo(string); + } + }.run(null); } @Override public Long move(final String key, final int dbIndex) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.move(key, dbIndex); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.move(key, dbIndex); + } + }.run(key); } @Override public Long bitcount(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.bitcount(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.bitcount(key); + } + }.run(key); } @Override public Long bitcount(final String key, final long start, final long end) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.bitcount(key, start, end); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.bitcount(key, start, end); + } + }.run(key); } @Override public String ping() { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.ping(); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.ping(); + } + }.run(null); } @Override public String quit() { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.quit(); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.quit(); + } + }.run(null); } @Override public String flushDB() { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.flushDB(); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.flushDB(); + } + }.run(null); } @Override public Long dbSize() { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.dbSize(); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.dbSize(); + } + }.run(null); } @Override public String select(final int index) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.select(index); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.select(index); + } + }.run(null); } @Override public String flushAll() { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.flushAll(); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.flushAll(); + } + }.run(null); } @Override public String auth(final String password) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.auth(password); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.auth(password); + } + }.run(null); } @Override public String save() { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.save(); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.save(); + } + }.run(null); } @Override public String bgsave() { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.bgsave(); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.bgsave(); + } + }.run(null); } @Override public String bgrewriteaof() { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.bgrewriteaof(); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.bgrewriteaof(); + } + }.run(null); } @Override public Long lastsave() { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.lastsave(); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.lastsave(); + } + }.run(null); } @Override public String shutdown() { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.shutdown(); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.shutdown(); + } + }.run(null); } @Override public String info() { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.info(); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.info(); + } + }.run(null); } @Override public String info(final String section) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.info(section); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.info(section); + } + }.run(null); } @Override public String slaveof(final String host, final int port) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.slaveof(host, port); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.slaveof(host, port); + } + }.run(null); } @Override public String slaveofNoOne() { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.slaveofNoOne(); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.slaveofNoOne(); + } + }.run(null); } @Override public Long getDB() { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.getDB(); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.getDB(); + } + }.run(null); } @Override public String debug(final DebugParams params) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.debug(params); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.debug(params); + } + }.run(null); } @Override public String configResetStat() { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.configResetStat(); - } - }.run(null); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.configResetStat(); + } + }.run(null); } public Map getClusterNodes() { - return connectionHandler.getNodes(); + return connectionHandler.getNodes(); } @Override public Long waitReplicas(int replicas, long timeout) { - // TODO Auto-generated method stub - return null; + // TODO Auto-generated method stub + return null; } @Override public ScanResult> hscan(final String key, - final String cursor) { - return new JedisClusterCommand>>( - connectionHandler, timeout, maxRedirections) { - @Override - public ScanResult> execute(Jedis connection) { - return connection.hscan(key, cursor); - } - }.run(null); + final String cursor) { + return new JedisClusterCommand>>( + connectionHandler, timeout, maxRedirections) { + @Override + public ScanResult> execute(Jedis connection) { + return connection.hscan(key, cursor); + } + }.run(null); } @Override public ScanResult sscan(final String key, final String cursor) { - return new JedisClusterCommand>(connectionHandler, - timeout, maxRedirections) { - @Override - public ScanResult execute(Jedis connection) { - return connection.sscan(key, cursor); - } - }.run(null); + return new JedisClusterCommand>(connectionHandler, + timeout, maxRedirections) { + @Override + public ScanResult execute(Jedis connection) { + return connection.sscan(key, cursor); + } + }.run(null); } @Override public ScanResult zscan(final String key, final String cursor) { - return new JedisClusterCommand>(connectionHandler, - timeout, maxRedirections) { - @Override - public ScanResult execute(Jedis connection) { - return connection.zscan(key, cursor); - } - }.run(null); + return new JedisClusterCommand>(connectionHandler, + timeout, maxRedirections) { + @Override + public ScanResult execute(Jedis connection) { + return connection.zscan(key, cursor); + } + }.run(null); } @Override public Long pfadd(final String key, final String... elements) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.pfadd(key, elements); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.pfadd(key, elements); + } + }.run(key); } @Override public long pfcount(final String key) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public Long execute(Jedis connection) { - return connection.pfcount(key); - } - }.run(key); + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public Long execute(Jedis connection) { + return connection.pfcount(key); + } + }.run(key); } @Override public List blpop(final int timeout, final String key) { - return new JedisClusterCommand>(connectionHandler, - timeout, maxRedirections) { - @Override - public List execute(Jedis connection) { - return connection.blpop(timeout, key); - } - }.run(null); + return new JedisClusterCommand>(connectionHandler, + timeout, maxRedirections) { + @Override + public List execute(Jedis connection) { + return connection.blpop(timeout, key); + } + }.run(null); } @Override public List brpop(final int timeout, final String key) { - return new JedisClusterCommand>(connectionHandler, - timeout, maxRedirections) { - @Override - public List execute(Jedis connection) { - return connection.brpop(timeout, key); - } - }.run(null); + return new JedisClusterCommand>(connectionHandler, + timeout, maxRedirections) { + @Override + public List execute(Jedis connection) { + return connection.brpop(timeout, key); + } + }.run(null); } } diff --git a/src/main/java/redis/clients/jedis/JedisClusterCommand.java b/src/main/java/redis/clients/jedis/JedisClusterCommand.java index 231a5ab..514cefa 100644 --- a/src/main/java/redis/clients/jedis/JedisClusterCommand.java +++ b/src/main/java/redis/clients/jedis/JedisClusterCommand.java @@ -16,94 +16,94 @@ public abstract class JedisClusterCommand { private ThreadLocal askConnection = new ThreadLocal(); public JedisClusterCommand(JedisClusterConnectionHandler connectionHandler, - int timeout, int maxRedirections) { - this.connectionHandler = connectionHandler; - this.commandTimeout = timeout; - this.redirections = maxRedirections; + int timeout, int maxRedirections) { + this.connectionHandler = connectionHandler; + this.commandTimeout = timeout; + this.redirections = maxRedirections; } public abstract T execute(Jedis connection); public T run(String key) { - if (key == null) { - throw new JedisClusterException( - "No way to dispatch this command to Redis Cluster."); - } + if (key == null) { + throw new JedisClusterException( + "No way to dispatch this command to Redis Cluster."); + } - return runWithRetries(key, this.redirections, false, false); + return runWithRetries(key, this.redirections, false, false); } private T runWithRetries(String key, int redirections, - boolean tryRandomNode, boolean asking) { - if (redirections <= 0) { - throw new JedisClusterMaxRedirectionsException( - "Too many Cluster redirections?"); - } + boolean tryRandomNode, boolean asking) { + if (redirections <= 0) { + throw new JedisClusterMaxRedirectionsException( + "Too many Cluster redirections?"); + } - Jedis connection = null; - try { + Jedis connection = null; + try { - if (asking) { - // TODO: Pipeline asking with the original command to make it - // faster.... - connection = askConnection.get(); - connection.asking(); + if (asking) { + // TODO: Pipeline asking with the original command to make it + // faster.... + connection = askConnection.get(); + connection.asking(); - // if asking success, reset asking flag - asking = false; - } else { - if (tryRandomNode) { - connection = connectionHandler.getConnection(); - } else { - connection = connectionHandler - .getConnectionFromSlot(JedisClusterCRC16 - .getSlot(key)); - } - } + // if asking success, reset asking flag + asking = false; + } else { + if (tryRandomNode) { + connection = connectionHandler.getConnection(); + } else { + connection = connectionHandler + .getConnectionFromSlot(JedisClusterCRC16 + .getSlot(key)); + } + } - return execute(connection); - } catch (JedisConnectionException jce) { - if (tryRandomNode) { - // maybe all connection is down - throw jce; - } + return execute(connection); + } catch (JedisConnectionException jce) { + if (tryRandomNode) { + // maybe all connection is down + throw jce; + } - releaseConnection(connection, true); - connection = null; + releaseConnection(connection, true); + connection = null; - // retry with random connection - return runWithRetries(key, redirections - 1, true, asking); - } catch (JedisRedirectionException jre) { - if (jre instanceof JedisAskDataException) { - asking = true; - askConnection.set(this.connectionHandler - .getConnectionFromNode(jre.getTargetNode())); - } else if (jre instanceof JedisMovedDataException) { - // it rebuilds cluster's slot cache - // recommended by Redis cluster specification - this.connectionHandler.renewSlotCache(); - } else { - throw new JedisClusterException(jre); - } + // retry with random connection + return runWithRetries(key, redirections - 1, true, asking); + } catch (JedisRedirectionException jre) { + if (jre instanceof JedisAskDataException) { + asking = true; + askConnection.set(this.connectionHandler + .getConnectionFromNode(jre.getTargetNode())); + } else if (jre instanceof JedisMovedDataException) { + // it rebuilds cluster's slot cache + // recommended by Redis cluster specification + this.connectionHandler.renewSlotCache(); + } else { + throw new JedisClusterException(jre); + } - releaseConnection(connection, false); - connection = null; + releaseConnection(connection, false); + connection = null; - return runWithRetries(key, redirections - 1, false, asking); - } finally { - releaseConnection(connection, false); - } + return runWithRetries(key, redirections - 1, false, asking); + } finally { + releaseConnection(connection, false); + } } private void releaseConnection(Jedis connection, boolean broken) { - if (connection != null) { - if (broken) { - connectionHandler.returnBrokenConnection(connection); - } else { - connectionHandler.returnConnection(connection); - } - } + if (connection != null) { + if (broken) { + connectionHandler.returnBrokenConnection(connection); + } else { + connectionHandler.returnConnection(connection); + } + } } } diff --git a/src/main/java/redis/clients/jedis/JedisClusterConnectionHandler.java b/src/main/java/redis/clients/jedis/JedisClusterConnectionHandler.java index 8ae11e9..bdf2ee7 100644 --- a/src/main/java/redis/clients/jedis/JedisClusterConnectionHandler.java +++ b/src/main/java/redis/clients/jedis/JedisClusterConnectionHandler.java @@ -15,75 +15,75 @@ public abstract class JedisClusterConnectionHandler { abstract Jedis getConnection(); public void returnConnection(Jedis connection) { - cache.getNode(getNodeKey(connection.getClient())).returnResource( - connection); + cache.getNode(getNodeKey(connection.getClient())).returnResource( + connection); } public void returnBrokenConnection(Jedis connection) { - cache.getNode(getNodeKey(connection.getClient())).returnBrokenResource( - connection); + cache.getNode(getNodeKey(connection.getClient())).returnBrokenResource( + connection); } abstract Jedis getConnectionFromSlot(int slot); public Jedis getConnectionFromNode(HostAndPort node) { - cache.setNodeIfNotExist(node); - return cache.getNode(JedisClusterInfoCache.getNodeKey(node)) - .getResource(); + cache.setNodeIfNotExist(node); + return cache.getNode(JedisClusterInfoCache.getNodeKey(node)) + .getResource(); } public JedisClusterConnectionHandler(Set nodes, - final GenericObjectPoolConfig poolConfig) { - this.cache = new JedisClusterInfoCache(poolConfig); - initializeSlotsCache(nodes, poolConfig); + final GenericObjectPoolConfig poolConfig) { + this.cache = new JedisClusterInfoCache(poolConfig); + initializeSlotsCache(nodes, poolConfig); } public Map getNodes() { - return cache.getNodes(); + return cache.getNodes(); } public void assignSlotToNode(int slot, HostAndPort targetNode) { - cache.assignSlotToNode(slot, targetNode); + cache.assignSlotToNode(slot, targetNode); } private void initializeSlotsCache(Set startNodes, - GenericObjectPoolConfig poolConfig) { - for (HostAndPort hostAndPort : startNodes) { - JedisPool jp = new JedisPool(poolConfig, hostAndPort.getHost(), - hostAndPort.getPort()); + GenericObjectPoolConfig poolConfig) { + for (HostAndPort hostAndPort : startNodes) { + JedisPool jp = new JedisPool(poolConfig, hostAndPort.getHost(), + hostAndPort.getPort()); - Jedis jedis = null; - try { - jedis = jp.getResource(); - cache.discoverClusterNodesAndSlots(jedis); - break; - } catch (JedisConnectionException e) { - // try next nodes - } finally { - if (jedis != null) { - jedis.close(); - } - } - } + Jedis jedis = null; + try { + jedis = jp.getResource(); + cache.discoverClusterNodesAndSlots(jedis); + break; + } catch (JedisConnectionException e) { + // try next nodes + } finally { + if (jedis != null) { + jedis.close(); + } + } + } - for (HostAndPort node : startNodes) { - cache.setNodeIfNotExist(node); - } + for (HostAndPort node : startNodes) { + cache.setNodeIfNotExist(node); + } } public void renewSlotCache() { - for (JedisPool jp : cache.getNodes().values()) { - Jedis jedis = null; - try { - jedis = jp.getResource(); - cache.discoverClusterSlots(jedis); - break; - } finally { - if (jedis != null) { - jedis.close(); - } - } - } + for (JedisPool jp : cache.getNodes().values()) { + Jedis jedis = null; + try { + jedis = jp.getResource(); + cache.discoverClusterSlots(jedis); + break; + } finally { + if (jedis != null) { + jedis.close(); + } + } + } } } diff --git a/src/main/java/redis/clients/jedis/JedisClusterInfoCache.java b/src/main/java/redis/clients/jedis/JedisClusterInfoCache.java index ebae166..8588196 100644 --- a/src/main/java/redis/clients/jedis/JedisClusterInfoCache.java +++ b/src/main/java/redis/clients/jedis/JedisClusterInfoCache.java @@ -25,166 +25,166 @@ public class JedisClusterInfoCache { private final GenericObjectPoolConfig poolConfig; public JedisClusterInfoCache(final GenericObjectPoolConfig poolConfig) { - this.poolConfig = poolConfig; + this.poolConfig = poolConfig; } public void discoverClusterNodesAndSlots(Jedis jedis) { - w.lock(); + w.lock(); - try { - this.nodes.clear(); - this.slots.clear(); + try { + this.nodes.clear(); + this.slots.clear(); - String localNodes = jedis.clusterNodes(); - for (String nodeInfo : localNodes.split("\n")) { - ClusterNodeInformation clusterNodeInfo = nodeInfoParser.parse( - nodeInfo, new HostAndPort(jedis.getClient().getHost(), - jedis.getClient().getPort())); + String localNodes = jedis.clusterNodes(); + for (String nodeInfo : localNodes.split("\n")) { + ClusterNodeInformation clusterNodeInfo = nodeInfoParser.parse( + nodeInfo, new HostAndPort(jedis.getClient().getHost(), + jedis.getClient().getPort())); - HostAndPort targetNode = clusterNodeInfo.getNode(); - setNodeIfNotExist(targetNode); - assignSlotsToNode(clusterNodeInfo.getAvailableSlots(), - targetNode); - } - } finally { - w.unlock(); - } + HostAndPort targetNode = clusterNodeInfo.getNode(); + setNodeIfNotExist(targetNode); + assignSlotsToNode(clusterNodeInfo.getAvailableSlots(), + targetNode); + } + } finally { + w.unlock(); + } } public void discoverClusterSlots(Jedis jedis) { - w.lock(); + w.lock(); - try { - this.slots.clear(); + try { + this.slots.clear(); - List slots = jedis.clusterSlots(); + List slots = jedis.clusterSlots(); - for (Object slotInfoObj : slots) { - List slotInfo = (List) slotInfoObj; + for (Object slotInfoObj : slots) { + List slotInfo = (List) slotInfoObj; - if (slotInfo.size() <= 2) { - continue; - } + if (slotInfo.size() <= 2) { + continue; + } - List slotNums = getAssignedSlotArray(slotInfo); + List slotNums = getAssignedSlotArray(slotInfo); - // hostInfos - List hostInfos = (List) slotInfo.get(2); - if (hostInfos.size() <= 0) { - continue; - } + // hostInfos + List hostInfos = (List) slotInfo.get(2); + if (hostInfos.size() <= 0) { + continue; + } - // at this time, we just use master, discard slave information - HostAndPort targetNode = generateHostAndPort(hostInfos); + // at this time, we just use master, discard slave information + HostAndPort targetNode = generateHostAndPort(hostInfos); - setNodeIfNotExist(targetNode); - assignSlotsToNode(slotNums, targetNode); - } - } finally { - w.unlock(); - } + setNodeIfNotExist(targetNode); + assignSlotsToNode(slotNums, targetNode); + } + } finally { + w.unlock(); + } } private HostAndPort generateHostAndPort(List hostInfos) { - return new HostAndPort(SafeEncoder.encode((byte[]) hostInfos.get(0)), - ((Long) hostInfos.get(1)).intValue()); + return new HostAndPort(SafeEncoder.encode((byte[]) hostInfos.get(0)), + ((Long) hostInfos.get(1)).intValue()); } public void setNodeIfNotExist(HostAndPort node) { - w.lock(); - try { - String nodeKey = getNodeKey(node); - if (nodes.containsKey(nodeKey)) - return; + w.lock(); + try { + String nodeKey = getNodeKey(node); + if (nodes.containsKey(nodeKey)) + return; - JedisPool nodePool = new JedisPool(poolConfig, node.getHost(), - node.getPort()); - nodes.put(nodeKey, nodePool); - } finally { - w.unlock(); - } + JedisPool nodePool = new JedisPool(poolConfig, node.getHost(), + node.getPort()); + nodes.put(nodeKey, nodePool); + } finally { + w.unlock(); + } } public void assignSlotToNode(int slot, HostAndPort targetNode) { - w.lock(); - try { - JedisPool targetPool = nodes.get(getNodeKey(targetNode)); + w.lock(); + try { + JedisPool targetPool = nodes.get(getNodeKey(targetNode)); - if (targetPool == null) { - setNodeIfNotExist(targetNode); - targetPool = nodes.get(getNodeKey(targetNode)); - } - slots.put(slot, targetPool); - } finally { - w.unlock(); - } + if (targetPool == null) { + setNodeIfNotExist(targetNode); + targetPool = nodes.get(getNodeKey(targetNode)); + } + slots.put(slot, targetPool); + } finally { + w.unlock(); + } } public void assignSlotsToNode(List targetSlots, - HostAndPort targetNode) { - w.lock(); - try { - JedisPool targetPool = nodes.get(getNodeKey(targetNode)); + HostAndPort targetNode) { + w.lock(); + try { + JedisPool targetPool = nodes.get(getNodeKey(targetNode)); - if (targetPool == null) { - setNodeIfNotExist(targetNode); - targetPool = nodes.get(getNodeKey(targetNode)); - } + if (targetPool == null) { + setNodeIfNotExist(targetNode); + targetPool = nodes.get(getNodeKey(targetNode)); + } - for (Integer slot : targetSlots) { - slots.put(slot, targetPool); - } - } finally { - w.unlock(); - } + for (Integer slot : targetSlots) { + slots.put(slot, targetPool); + } + } finally { + w.unlock(); + } } public JedisPool getNode(String nodeKey) { - r.lock(); - try { - return nodes.get(nodeKey); - } finally { - r.unlock(); - } + r.lock(); + try { + return nodes.get(nodeKey); + } finally { + r.unlock(); + } } public JedisPool getSlotPool(int slot) { - r.lock(); - try { - return slots.get(slot); - } finally { - r.unlock(); - } + r.lock(); + try { + return slots.get(slot); + } finally { + r.unlock(); + } } public Map getNodes() { - r.lock(); - try { - return new HashMap(nodes); - } finally { - r.unlock(); - } + r.lock(); + try { + return new HashMap(nodes); + } finally { + r.unlock(); + } } public static String getNodeKey(HostAndPort hnp) { - return hnp.getHost() + ":" + hnp.getPort(); + return hnp.getHost() + ":" + hnp.getPort(); } public static String getNodeKey(Client client) { - return client.getHost() + ":" + client.getPort(); + return client.getHost() + ":" + client.getPort(); } public static String getNodeKey(Jedis jedis) { - return getNodeKey(jedis.getClient()); + return getNodeKey(jedis.getClient()); } private List getAssignedSlotArray(List slotInfo) { - List slotNums = new ArrayList(); - for (int slot = ((Long) slotInfo.get(0)).intValue(); slot <= ((Long) slotInfo - .get(1)).intValue(); slot++) { - slotNums.add(slot); - } - return slotNums; + List slotNums = new ArrayList(); + for (int slot = ((Long) slotInfo.get(0)).intValue(); slot <= ((Long) slotInfo + .get(1)).intValue(); slot++) { + slotNums.add(slot); + } + return slotNums; } } diff --git a/src/main/java/redis/clients/jedis/JedisCommands.java b/src/main/java/redis/clients/jedis/JedisCommands.java index 2ecdeed..a714a3b 100644 --- a/src/main/java/redis/clients/jedis/JedisCommands.java +++ b/src/main/java/redis/clients/jedis/JedisCommands.java @@ -157,38 +157,38 @@ public interface JedisCommands { Set zrevrangeByScore(String key, double max, double min); Set zrangeByScore(String key, double min, double max, int offset, - int count); + int count); Set zrevrangeByScore(String key, String max, String min); Set zrangeByScore(String key, String min, String max, int offset, - int count); + int count); Set zrevrangeByScore(String key, double max, double min, - int offset, int count); + int offset, int count); Set zrangeByScoreWithScores(String key, double min, double max); Set zrevrangeByScoreWithScores(String key, double max, double min); Set zrangeByScoreWithScores(String key, double min, double max, - int offset, int count); + int offset, int count); Set zrevrangeByScore(String key, String max, String min, - int offset, int count); + int offset, int count); Set zrangeByScoreWithScores(String key, String min, String max); Set zrevrangeByScoreWithScores(String key, String max, String min); Set zrangeByScoreWithScores(String key, String min, String max, - int offset, int count); + int offset, int count); Set zrevrangeByScoreWithScores(String key, double max, double min, - int offset, int count); + int offset, int count); Set zrevrangeByScoreWithScores(String key, String max, String min, - int offset, int count); + int offset, int count); Long zremrangeByRank(String key, long start, long end); @@ -201,18 +201,18 @@ public interface JedisCommands { Set zrangeByLex(final String key, final String min, final String max); Set zrangeByLex(final String key, final String min, - final String max, final int offset, final int count); + final String max, final int offset, final int count); Set zrevrangeByLex(final String key, final String max, - final String min); + final String min); Set zrevrangeByLex(final String key, final String max, - final String min, final int offset, final int count); + final String min, final int offset, final int count); Long zremrangeByLex(final String key, final String min, final String max); Long linsert(String key, Client.LIST_POSITION where, String pivot, - String value); + String value); Long lpushx(String key, String... string); @@ -245,7 +245,7 @@ public interface JedisCommands { Long bitcount(final String key, long start, long end); ScanResult> hscan(final String key, - final String cursor); + final String cursor); ScanResult sscan(final String key, final String cursor); diff --git a/src/main/java/redis/clients/jedis/JedisFactory.java b/src/main/java/redis/clients/jedis/JedisFactory.java index f406730..22394f6 100644 --- a/src/main/java/redis/clients/jedis/JedisFactory.java +++ b/src/main/java/redis/clients/jedis/JedisFactory.java @@ -17,91 +17,91 @@ class JedisFactory implements PooledObjectFactory { private final String clientName; public JedisFactory(final String host, final int port, final int timeout, - final String password, final int database) { - this(host, port, timeout, password, database, null); + final String password, final int database) { + this(host, port, timeout, password, database, null); } public JedisFactory(final String host, final int port, final int timeout, - final String password, final int database, final String clientName) { - super(); - this.hostAndPort.set(new HostAndPort(host, port)); - this.timeout = timeout; - this.password = password; - this.database = database; - this.clientName = clientName; + final String password, final int database, final String clientName) { + super(); + this.hostAndPort.set(new HostAndPort(host, port)); + this.timeout = timeout; + this.password = password; + this.database = database; + this.clientName = clientName; } public void setHostAndPort(final HostAndPort hostAndPort) { - this.hostAndPort.set(hostAndPort); + this.hostAndPort.set(hostAndPort); } @Override public void activateObject(PooledObject pooledJedis) - throws Exception { - final BinaryJedis jedis = pooledJedis.getObject(); - if (jedis.getDB() != database) { - jedis.select(database); - } + throws Exception { + final BinaryJedis jedis = pooledJedis.getObject(); + if (jedis.getDB() != database) { + jedis.select(database); + } } @Override public void destroyObject(PooledObject pooledJedis) throws Exception { - final BinaryJedis jedis = pooledJedis.getObject(); - if (jedis.isConnected()) { - try { - try { - jedis.quit(); - } catch (Exception e) { - } - jedis.disconnect(); - } catch (Exception e) { + final BinaryJedis jedis = pooledJedis.getObject(); + if (jedis.isConnected()) { + try { + try { + jedis.quit(); + } catch (Exception e) { + } + jedis.disconnect(); + } catch (Exception e) { - } - } + } + } } @Override public PooledObject makeObject() throws Exception { - final HostAndPort hostAndPort = this.hostAndPort.get(); - final Jedis jedis = new Jedis(hostAndPort.getHost(), - hostAndPort.getPort(), this.timeout); + final HostAndPort hostAndPort = this.hostAndPort.get(); + final Jedis jedis = new Jedis(hostAndPort.getHost(), + hostAndPort.getPort(), this.timeout); - jedis.connect(); - if (null != this.password) { - jedis.auth(this.password); - } - if (database != 0) { - jedis.select(database); - } - if (clientName != null) { - jedis.clientSetname(clientName); - } + jedis.connect(); + if (null != this.password) { + jedis.auth(this.password); + } + if (database != 0) { + jedis.select(database); + } + if (clientName != null) { + jedis.clientSetname(clientName); + } - return new DefaultPooledObject(jedis); + return new DefaultPooledObject(jedis); } @Override public void passivateObject(PooledObject pooledJedis) - throws Exception { - // TODO maybe should select db 0? Not sure right now. + throws Exception { + // TODO maybe should select db 0? Not sure right now. } @Override public boolean validateObject(PooledObject pooledJedis) { - final BinaryJedis jedis = pooledJedis.getObject(); - try { - HostAndPort hostAndPort = this.hostAndPort.get(); + final BinaryJedis jedis = pooledJedis.getObject(); + try { + HostAndPort hostAndPort = this.hostAndPort.get(); - String connectionHost = jedis.getClient().getHost(); - int connectionPort = jedis.getClient().getPort(); + String connectionHost = jedis.getClient().getHost(); + int connectionPort = jedis.getClient().getPort(); - return hostAndPort.getHost().equals(connectionHost) - && hostAndPort.getPort() == connectionPort - && jedis.isConnected() && jedis.ping().equals("PONG"); - } catch (final Exception e) { - return false; - } + return hostAndPort.getHost().equals(connectionHost) + && hostAndPort.getPort() == connectionPort + && jedis.isConnected() && jedis.ping().equals("PONG"); + } catch (final Exception e) { + return false; + } } } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/JedisMonitor.java b/src/main/java/redis/clients/jedis/JedisMonitor.java index cd8e802..57ddb68 100644 --- a/src/main/java/redis/clients/jedis/JedisMonitor.java +++ b/src/main/java/redis/clients/jedis/JedisMonitor.java @@ -4,12 +4,12 @@ public abstract class JedisMonitor { protected Client client; public void proceed(Client client) { - this.client = client; - this.client.setTimeoutInfinite(); - do { - String command = client.getBulkReply(); - onCommand(command); - } while (client.isConnected()); + this.client = client; + this.client.setTimeoutInfinite(); + do { + String command = client.getBulkReply(); + onCommand(command); + } while (client.isConnected()); } public abstract void onCommand(String command); diff --git a/src/main/java/redis/clients/jedis/JedisPool.java b/src/main/java/redis/clients/jedis/JedisPool.java index c75390c..f51ab7e 100644 --- a/src/main/java/redis/clients/jedis/JedisPool.java +++ b/src/main/java/redis/clients/jedis/JedisPool.java @@ -12,104 +12,104 @@ import redis.clients.util.Pool; public class JedisPool extends Pool { public JedisPool() { - this(Protocol.DEFAULT_HOST, Protocol.DEFAULT_PORT); + this(Protocol.DEFAULT_HOST, Protocol.DEFAULT_PORT); } public JedisPool(final GenericObjectPoolConfig poolConfig, final String host) { - this(poolConfig, host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, - null, Protocol.DEFAULT_DATABASE, null); + this(poolConfig, host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, + null, Protocol.DEFAULT_DATABASE, null); } public JedisPool(String host, int port) { - this(new GenericObjectPoolConfig(), host, port, - Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE, null); + this(new GenericObjectPoolConfig(), host, port, + Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE, null); } public JedisPool(final String host) { - URI uri = URI.create(host); - if (uri.getScheme() != null && uri.getScheme().equals("redis")) { - String h = uri.getHost(); - int port = uri.getPort(); - String password = JedisURIHelper.getPassword(uri); - int database = 0; - Integer dbIndex = JedisURIHelper.getDBIndex(uri); - if (dbIndex != null) { - database = dbIndex.intValue(); - } - this.internalPool = new GenericObjectPool( - new JedisFactory(h, port, Protocol.DEFAULT_TIMEOUT, - password, database, null), - new GenericObjectPoolConfig()); - } else { - this.internalPool = new GenericObjectPool(new JedisFactory( - host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, - null, Protocol.DEFAULT_DATABASE, null), - new GenericObjectPoolConfig()); - } + URI uri = URI.create(host); + if (uri.getScheme() != null && uri.getScheme().equals("redis")) { + String h = uri.getHost(); + int port = uri.getPort(); + String password = JedisURIHelper.getPassword(uri); + int database = 0; + Integer dbIndex = JedisURIHelper.getDBIndex(uri); + if (dbIndex != null) { + database = dbIndex.intValue(); + } + this.internalPool = new GenericObjectPool( + new JedisFactory(h, port, Protocol.DEFAULT_TIMEOUT, + password, database, null), + new GenericObjectPoolConfig()); + } else { + this.internalPool = new GenericObjectPool(new JedisFactory( + host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, + null, Protocol.DEFAULT_DATABASE, null), + new GenericObjectPoolConfig()); + } } public JedisPool(final URI uri) { - this(new GenericObjectPoolConfig(), uri, Protocol.DEFAULT_TIMEOUT); + this(new GenericObjectPoolConfig(), uri, Protocol.DEFAULT_TIMEOUT); } public JedisPool(final URI uri, final int timeout) { - this(new GenericObjectPoolConfig(), uri, timeout); + this(new GenericObjectPoolConfig(), uri, timeout); } public JedisPool(final GenericObjectPoolConfig poolConfig, - final String host, int port, int timeout, final String password) { - this(poolConfig, host, port, timeout, password, - Protocol.DEFAULT_DATABASE, null); + final String host, int port, int timeout, final String password) { + this(poolConfig, host, port, timeout, password, + Protocol.DEFAULT_DATABASE, null); } public JedisPool(final GenericObjectPoolConfig poolConfig, - final String host, final int port) { - this(poolConfig, host, port, Protocol.DEFAULT_TIMEOUT, null, - Protocol.DEFAULT_DATABASE, null); + final String host, final int port) { + this(poolConfig, host, port, Protocol.DEFAULT_TIMEOUT, null, + Protocol.DEFAULT_DATABASE, null); } public JedisPool(final GenericObjectPoolConfig poolConfig, - final String host, final int port, final int timeout) { - this(poolConfig, host, port, timeout, null, Protocol.DEFAULT_DATABASE, - null); + final String host, final int port, final int timeout) { + this(poolConfig, host, port, timeout, null, Protocol.DEFAULT_DATABASE, + null); } public JedisPool(final GenericObjectPoolConfig poolConfig, - final String host, int port, int timeout, final String password, - final int database) { - this(poolConfig, host, port, timeout, password, database, null); + final String host, int port, int timeout, final String password, + final int database) { + this(poolConfig, host, port, timeout, password, database, null); } public JedisPool(final GenericObjectPoolConfig poolConfig, - final String host, int port, int timeout, final String password, - final int database, final String clientName) { - super(poolConfig, new JedisFactory(host, port, timeout, password, - database, clientName)); + final String host, int port, int timeout, final String password, + final int database, final String clientName) { + super(poolConfig, new JedisFactory(host, port, timeout, password, + database, clientName)); } public JedisPool(final GenericObjectPoolConfig poolConfig, final URI uri) { - this(poolConfig, uri, Protocol.DEFAULT_TIMEOUT); + this(poolConfig, uri, Protocol.DEFAULT_TIMEOUT); } public JedisPool(final GenericObjectPoolConfig poolConfig, final URI uri, - final int timeout) { - super(poolConfig, new JedisFactory(uri.getHost(), uri.getPort(), - timeout, JedisURIHelper.getPassword(uri), - JedisURIHelper.getDBIndex(uri) != null ? JedisURIHelper - .getDBIndex(uri) : 0, null)); + final int timeout) { + super(poolConfig, new JedisFactory(uri.getHost(), uri.getPort(), + timeout, JedisURIHelper.getPassword(uri), + JedisURIHelper.getDBIndex(uri) != null ? JedisURIHelper + .getDBIndex(uri) : 0, null)); } @Override public Jedis getResource() { - Jedis jedis = super.getResource(); - jedis.setDataSource(this); - return jedis; + Jedis jedis = super.getResource(); + jedis.setDataSource(this); + return jedis; } public void returnBrokenResource(final Jedis resource) { - if (resource != null) { - returnBrokenResourceObject(resource); - } + if (resource != null) { + returnBrokenResourceObject(resource); + } } public void returnResource(final Jedis resource) { @@ -127,10 +127,10 @@ public class JedisPool extends Pool { } public int getNumActive() { - if (this.internalPool == null || this.internalPool.isClosed()) { - return -1; - } + if (this.internalPool == null || this.internalPool.isClosed()) { + return -1; + } - return this.internalPool.getNumActive(); + return this.internalPool.getNumActive(); } } diff --git a/src/main/java/redis/clients/jedis/JedisPoolConfig.java b/src/main/java/redis/clients/jedis/JedisPoolConfig.java index 5efdde8..fa689d0 100644 --- a/src/main/java/redis/clients/jedis/JedisPoolConfig.java +++ b/src/main/java/redis/clients/jedis/JedisPoolConfig.java @@ -4,10 +4,10 @@ import org.apache.commons.pool2.impl.GenericObjectPoolConfig; public class JedisPoolConfig extends GenericObjectPoolConfig { public JedisPoolConfig() { - // defaults to make your life with connection pool easier :) - setTestWhileIdle(true); - setMinEvictableIdleTimeMillis(60000); - setTimeBetweenEvictionRunsMillis(30000); - setNumTestsPerEvictionRun(-1); + // defaults to make your life with connection pool easier :) + setTestWhileIdle(true); + setMinEvictableIdleTimeMillis(60000); + setTimeBetweenEvictionRunsMillis(30000); + setNumTestsPerEvictionRun(-1); } } diff --git a/src/main/java/redis/clients/jedis/JedisPubSub.java b/src/main/java/redis/clients/jedis/JedisPubSub.java index fb892c3..d82d45f 100644 --- a/src/main/java/redis/clients/jedis/JedisPubSub.java +++ b/src/main/java/redis/clients/jedis/JedisPubSub.java @@ -18,152 +18,152 @@ public abstract class JedisPubSub { private int subscribedChannels = 0; private volatile Client client; - public void onMessage(String channel, String message) {} + public void onMessage(String channel, String message) {} - public void onPMessage(String pattern, String channel, String message) {} + public void onPMessage(String pattern, String channel, String message) {} - public void onSubscribe(String channel, int subscribedChannels) {} + public void onSubscribe(String channel, int subscribedChannels) {} - public void onUnsubscribe(String channel, int subscribedChannels) {} + public void onUnsubscribe(String channel, int subscribedChannels) {} - public void onPUnsubscribe(String pattern, int subscribedChannels) {} + public void onPUnsubscribe(String pattern, int subscribedChannels) {} - public void onPSubscribe(String pattern, int subscribedChannels) {} + public void onPSubscribe(String pattern, int subscribedChannels) {} public void unsubscribe() { - if (client == null) { - throw new JedisConnectionException( - "JedisPubSub was not subscribed to a Jedis instance."); - } - client.unsubscribe(); - client.flush(); + if (client == null) { + throw new JedisConnectionException( + "JedisPubSub was not subscribed to a Jedis instance."); + } + client.unsubscribe(); + client.flush(); } public void unsubscribe(String... channels) { - if (client == null) { - throw new JedisConnectionException( - "JedisPubSub is not subscribed to a Jedis instance."); - } - client.unsubscribe(channels); - client.flush(); + if (client == null) { + throw new JedisConnectionException( + "JedisPubSub is not subscribed to a Jedis instance."); + } + client.unsubscribe(channels); + client.flush(); } public void subscribe(String... channels) { - if (client == null) { - throw new JedisConnectionException( - "JedisPubSub is not subscribed to a Jedis instance."); - } - client.subscribe(channels); - client.flush(); + if (client == null) { + throw new JedisConnectionException( + "JedisPubSub is not subscribed to a Jedis instance."); + } + client.subscribe(channels); + client.flush(); } public void psubscribe(String... patterns) { - if (client == null) { - throw new JedisConnectionException( - "JedisPubSub is not subscribed to a Jedis instance."); - } - client.psubscribe(patterns); - client.flush(); + if (client == null) { + throw new JedisConnectionException( + "JedisPubSub is not subscribed to a Jedis instance."); + } + client.psubscribe(patterns); + client.flush(); } public void punsubscribe() { - if (client == null) { - throw new JedisConnectionException( - "JedisPubSub is not subscribed to a Jedis instance."); - } - client.punsubscribe(); - client.flush(); + if (client == null) { + throw new JedisConnectionException( + "JedisPubSub is not subscribed to a Jedis instance."); + } + client.punsubscribe(); + client.flush(); } public void punsubscribe(String... patterns) { - if (client == null) { - throw new JedisConnectionException( - "JedisPubSub is not subscribed to a Jedis instance."); - } - client.punsubscribe(patterns); - client.flush(); + if (client == null) { + throw new JedisConnectionException( + "JedisPubSub is not subscribed to a Jedis instance."); + } + client.punsubscribe(patterns); + client.flush(); } public boolean isSubscribed() { - return subscribedChannels > 0; + return subscribedChannels > 0; } public void proceedWithPatterns(Client client, String... patterns) { - this.client = client; - client.psubscribe(patterns); - client.flush(); - process(client); + this.client = client; + client.psubscribe(patterns); + client.flush(); + process(client); } public void proceed(Client client, String... channels) { - this.client = client; - client.subscribe(channels); - client.flush(); - process(client); + this.client = client; + client.subscribe(channels); + client.flush(); + process(client); } private void process(Client client) { - do { - List reply = client.getRawObjectMultiBulkReply(); - final Object firstObj = reply.get(0); - if (!(firstObj instanceof byte[])) { - throw new JedisException("Unknown message type: " + firstObj); - } - final byte[] resp = (byte[]) firstObj; - if (Arrays.equals(SUBSCRIBE.raw, resp)) { - subscribedChannels = ((Long) reply.get(2)).intValue(); - final byte[] bchannel = (byte[]) reply.get(1); - final String strchannel = (bchannel == null) ? null - : SafeEncoder.encode(bchannel); - onSubscribe(strchannel, subscribedChannels); - } else if (Arrays.equals(UNSUBSCRIBE.raw, resp)) { - subscribedChannels = ((Long) reply.get(2)).intValue(); - final byte[] bchannel = (byte[]) reply.get(1); - final String strchannel = (bchannel == null) ? null - : SafeEncoder.encode(bchannel); - onUnsubscribe(strchannel, subscribedChannels); - } else if (Arrays.equals(MESSAGE.raw, resp)) { - final byte[] bchannel = (byte[]) reply.get(1); - final byte[] bmesg = (byte[]) reply.get(2); - final String strchannel = (bchannel == null) ? null - : SafeEncoder.encode(bchannel); - final String strmesg = (bmesg == null) ? null : SafeEncoder - .encode(bmesg); - onMessage(strchannel, strmesg); - } else if (Arrays.equals(PMESSAGE.raw, resp)) { - final byte[] bpattern = (byte[]) reply.get(1); - final byte[] bchannel = (byte[]) reply.get(2); - final byte[] bmesg = (byte[]) reply.get(3); - final String strpattern = (bpattern == null) ? null - : SafeEncoder.encode(bpattern); - final String strchannel = (bchannel == null) ? null - : SafeEncoder.encode(bchannel); - final String strmesg = (bmesg == null) ? null : SafeEncoder - .encode(bmesg); - onPMessage(strpattern, strchannel, strmesg); - } else if (Arrays.equals(PSUBSCRIBE.raw, resp)) { - subscribedChannels = ((Long) reply.get(2)).intValue(); - final byte[] bpattern = (byte[]) reply.get(1); - final String strpattern = (bpattern == null) ? null - : SafeEncoder.encode(bpattern); - onPSubscribe(strpattern, subscribedChannels); - } else if (Arrays.equals(PUNSUBSCRIBE.raw, resp)) { - subscribedChannels = ((Long) reply.get(2)).intValue(); - final byte[] bpattern = (byte[]) reply.get(1); - final String strpattern = (bpattern == null) ? null - : SafeEncoder.encode(bpattern); - onPUnsubscribe(strpattern, subscribedChannels); - } else { - throw new JedisException("Unknown message type: " + firstObj); - } - } while (isSubscribed()); + do { + List reply = client.getRawObjectMultiBulkReply(); + final Object firstObj = reply.get(0); + if (!(firstObj instanceof byte[])) { + throw new JedisException("Unknown message type: " + firstObj); + } + final byte[] resp = (byte[]) firstObj; + if (Arrays.equals(SUBSCRIBE.raw, resp)) { + subscribedChannels = ((Long) reply.get(2)).intValue(); + final byte[] bchannel = (byte[]) reply.get(1); + final String strchannel = (bchannel == null) ? null + : SafeEncoder.encode(bchannel); + onSubscribe(strchannel, subscribedChannels); + } else if (Arrays.equals(UNSUBSCRIBE.raw, resp)) { + subscribedChannels = ((Long) reply.get(2)).intValue(); + final byte[] bchannel = (byte[]) reply.get(1); + final String strchannel = (bchannel == null) ? null + : SafeEncoder.encode(bchannel); + onUnsubscribe(strchannel, subscribedChannels); + } else if (Arrays.equals(MESSAGE.raw, resp)) { + final byte[] bchannel = (byte[]) reply.get(1); + final byte[] bmesg = (byte[]) reply.get(2); + final String strchannel = (bchannel == null) ? null + : SafeEncoder.encode(bchannel); + final String strmesg = (bmesg == null) ? null : SafeEncoder + .encode(bmesg); + onMessage(strchannel, strmesg); + } else if (Arrays.equals(PMESSAGE.raw, resp)) { + final byte[] bpattern = (byte[]) reply.get(1); + final byte[] bchannel = (byte[]) reply.get(2); + final byte[] bmesg = (byte[]) reply.get(3); + final String strpattern = (bpattern == null) ? null + : SafeEncoder.encode(bpattern); + final String strchannel = (bchannel == null) ? null + : SafeEncoder.encode(bchannel); + final String strmesg = (bmesg == null) ? null : SafeEncoder + .encode(bmesg); + onPMessage(strpattern, strchannel, strmesg); + } else if (Arrays.equals(PSUBSCRIBE.raw, resp)) { + subscribedChannels = ((Long) reply.get(2)).intValue(); + final byte[] bpattern = (byte[]) reply.get(1); + final String strpattern = (bpattern == null) ? null + : SafeEncoder.encode(bpattern); + onPSubscribe(strpattern, subscribedChannels); + } else if (Arrays.equals(PUNSUBSCRIBE.raw, resp)) { + subscribedChannels = ((Long) reply.get(2)).intValue(); + final byte[] bpattern = (byte[]) reply.get(1); + final String strpattern = (bpattern == null) ? null + : SafeEncoder.encode(bpattern); + onPUnsubscribe(strpattern, subscribedChannels); + } else { + throw new JedisException("Unknown message type: " + firstObj); + } + } while (isSubscribed()); - /* Invalidate instance since this thread is no longer listening */ - this.client = null; + /* Invalidate instance since this thread is no longer listening */ + this.client = null; } public int getSubscribedChannels() { - return subscribedChannels; + return subscribedChannels; } } diff --git a/src/main/java/redis/clients/jedis/JedisSentinelPool.java b/src/main/java/redis/clients/jedis/JedisSentinelPool.java index 8c0c1c8..16b058b 100644 --- a/src/main/java/redis/clients/jedis/JedisSentinelPool.java +++ b/src/main/java/redis/clients/jedis/JedisSentinelPool.java @@ -28,294 +28,294 @@ public class JedisSentinelPool extends Pool { protected Logger log = Logger.getLogger(getClass().getName()); public JedisSentinelPool(String masterName, Set sentinels, - final GenericObjectPoolConfig poolConfig) { - this(masterName, sentinels, poolConfig, Protocol.DEFAULT_TIMEOUT, null, - Protocol.DEFAULT_DATABASE); + final GenericObjectPoolConfig poolConfig) { + this(masterName, sentinels, poolConfig, Protocol.DEFAULT_TIMEOUT, null, + Protocol.DEFAULT_DATABASE); } public JedisSentinelPool(String masterName, Set sentinels) { - this(masterName, sentinels, new GenericObjectPoolConfig(), - Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE); + this(masterName, sentinels, new GenericObjectPoolConfig(), + Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE); } public JedisSentinelPool(String masterName, Set sentinels, - String password) { - this(masterName, sentinels, new GenericObjectPoolConfig(), - Protocol.DEFAULT_TIMEOUT, password); + String password) { + this(masterName, sentinels, new GenericObjectPoolConfig(), + Protocol.DEFAULT_TIMEOUT, password); } public JedisSentinelPool(String masterName, Set sentinels, - final GenericObjectPoolConfig poolConfig, int timeout, - final String password) { - this(masterName, sentinels, poolConfig, timeout, password, - Protocol.DEFAULT_DATABASE); + final GenericObjectPoolConfig poolConfig, int timeout, + final String password) { + this(masterName, sentinels, poolConfig, timeout, password, + Protocol.DEFAULT_DATABASE); } public JedisSentinelPool(String masterName, Set sentinels, - final GenericObjectPoolConfig poolConfig, final int timeout) { - this(masterName, sentinels, poolConfig, timeout, null, - Protocol.DEFAULT_DATABASE); + final GenericObjectPoolConfig poolConfig, final int timeout) { + this(masterName, sentinels, poolConfig, timeout, null, + Protocol.DEFAULT_DATABASE); } public JedisSentinelPool(String masterName, Set sentinels, - final GenericObjectPoolConfig poolConfig, final String password) { - this(masterName, sentinels, poolConfig, Protocol.DEFAULT_TIMEOUT, - password); + final GenericObjectPoolConfig poolConfig, final String password) { + this(masterName, sentinels, poolConfig, Protocol.DEFAULT_TIMEOUT, + password); } public JedisSentinelPool(String masterName, Set sentinels, - final GenericObjectPoolConfig poolConfig, int timeout, - final String password, final int database) { + final GenericObjectPoolConfig poolConfig, int timeout, + final String password, final int database) { - this.poolConfig = poolConfig; - this.timeout = timeout; - this.password = password; - this.database = database; + this.poolConfig = poolConfig; + this.timeout = timeout; + this.password = password; + this.database = database; - HostAndPort master = initSentinels(sentinels, masterName); - initPool(master); + HostAndPort master = initSentinels(sentinels, masterName); + initPool(master); } private volatile JedisFactory factory; private volatile HostAndPort currentHostMaster; public void destroy() { - for (MasterListener m : masterListeners) { - m.shutdown(); - } + for (MasterListener m : masterListeners) { + m.shutdown(); + } - super.destroy(); + super.destroy(); } public HostAndPort getCurrentHostMaster() { - return currentHostMaster; + return currentHostMaster; } private void initPool(HostAndPort master) { - if (!master.equals(currentHostMaster)) { - currentHostMaster = master; - if (factory == null) { - factory = new JedisFactory(master.getHost(), master.getPort(), - timeout, password, database); - 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 - internalPool.clear(); - } + if (!master.equals(currentHostMaster)) { + currentHostMaster = master; + if (factory == null) { + factory = new JedisFactory(master.getHost(), master.getPort(), + timeout, password, database); + 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 + internalPool.clear(); + } - log.info("Created JedisPool to master at " + master); - } + log.info("Created JedisPool to master at " + master); + } } private HostAndPort initSentinels(Set sentinels, - final String masterName) { + final String masterName) { - HostAndPort master = null; - boolean sentinelAvailable = false; + HostAndPort master = null; + boolean sentinelAvailable = false; - log.info("Trying to find master from available Sentinels..."); + log.info("Trying to find master from available Sentinels..."); - for (String sentinel : sentinels) { - final HostAndPort hap = toHostAndPort(Arrays.asList(sentinel - .split(":"))); + for (String sentinel : sentinels) { + final HostAndPort hap = toHostAndPort(Arrays.asList(sentinel + .split(":"))); - log.fine("Connecting to Sentinel " + hap); + log.fine("Connecting to Sentinel " + hap); - Jedis jedis = null; - try { - jedis = new Jedis(hap.getHost(), hap.getPort()); + Jedis jedis = null; + try { + jedis = new Jedis(hap.getHost(), hap.getPort()); - List masterAddr = jedis - .sentinelGetMasterAddrByName(masterName); + List masterAddr = jedis + .sentinelGetMasterAddrByName(masterName); - // connected to sentinel... - sentinelAvailable = true; + // connected to sentinel... + sentinelAvailable = true; - if (masterAddr == null || masterAddr.size() != 2) { - log.warning("Can not get master addr, master name: " - + masterName + ". Sentinel: " + hap + "."); - continue; - } + if (masterAddr == null || masterAddr.size() != 2) { + log.warning("Can not get master addr, master name: " + + masterName + ". Sentinel: " + hap + "."); + continue; + } - master = toHostAndPort(masterAddr); - log.fine("Found Redis master at " + master); - break; - } catch (JedisConnectionException e) { - log.warning("Cannot connect to sentinel running @ " + hap - + ". Trying next one."); - } finally { - if (jedis != null) { - jedis.close(); - } - } - } + master = toHostAndPort(masterAddr); + log.fine("Found Redis master at " + master); + break; + } catch (JedisConnectionException e) { + log.warning("Cannot connect to sentinel running @ " + hap + + ". Trying next one."); + } finally { + if (jedis != null) { + jedis.close(); + } + } + } - 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..."); - } else { - throw new JedisConnectionException( - "All sentinels down, cannot determine where is " - + masterName + " master is running..."); - } - } + 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..."); + } else { + throw new JedisConnectionException( + "All sentinels down, cannot determine where is " + + masterName + " master is running..."); + } + } - log.info("Redis master running at " + master - + ", starting Sentinel listeners..."); + log.info("Redis master running at " + master + + ", starting Sentinel listeners..."); - for (String sentinel : sentinels) { - final HostAndPort hap = toHostAndPort(Arrays.asList(sentinel - .split(":"))); - MasterListener masterListener = new MasterListener(masterName, - hap.getHost(), hap.getPort()); - masterListeners.add(masterListener); - masterListener.start(); - } + for (String sentinel : sentinels) { + final HostAndPort hap = toHostAndPort(Arrays.asList(sentinel + .split(":"))); + MasterListener masterListener = new MasterListener(masterName, + hap.getHost(), hap.getPort()); + masterListeners.add(masterListener); + masterListener.start(); + } - return master; + return master; } private HostAndPort toHostAndPort(List getMasterAddrByNameResult) { - String host = getMasterAddrByNameResult.get(0); - int port = Integer.parseInt(getMasterAddrByNameResult.get(1)); + String host = getMasterAddrByNameResult.get(0); + int port = Integer.parseInt(getMasterAddrByNameResult.get(1)); - return new HostAndPort(host, port); + return new HostAndPort(host, port); } @Override public Jedis getResource() { - while (true) { - Jedis jedis = super.getResource(); - jedis.setDataSource(this); + while (true) { + Jedis jedis = super.getResource(); + jedis.setDataSource(this); - // get a reference because it can change concurrently - final HostAndPort master = currentHostMaster; - final HostAndPort connection = new HostAndPort(jedis.getClient() - .getHost(), jedis.getClient().getPort()); + // get a reference because it can change concurrently + final HostAndPort master = currentHostMaster; + final HostAndPort connection = new HostAndPort(jedis.getClient() + .getHost(), jedis.getClient().getPort()); - if (master.equals(connection)) { - // connected to the correct master - return jedis; - } else { - returnBrokenResource(jedis); - } - } + if (master.equals(connection)) { + // connected to the correct master + return jedis; + } else { + returnBrokenResource(jedis); + } + } } public void returnBrokenResource(final Jedis resource) { - if (resource != null) { - returnBrokenResourceObject(resource); - } + if (resource != null) { + returnBrokenResourceObject(resource); + } } public void returnResource(final Jedis resource) { - if (resource != null) { - resource.resetState(); - returnResourceObject(resource); - } + if (resource != null) { + resource.resetState(); + returnResourceObject(resource); + } } protected class MasterListener extends Thread { - protected String masterName; - protected String host; - protected int port; - protected long subscribeRetryWaitTimeMillis = 5000; - protected Jedis j; - protected AtomicBoolean running = new AtomicBoolean(false); + protected String masterName; + protected String host; + protected int port; + protected long subscribeRetryWaitTimeMillis = 5000; + protected Jedis j; + protected AtomicBoolean running = new AtomicBoolean(false); - protected MasterListener() { - } + protected MasterListener() { + } - public MasterListener(String masterName, String host, int port) { - this.masterName = masterName; - this.host = host; - this.port = port; - } + public MasterListener(String masterName, String host, int port) { + this.masterName = masterName; + this.host = host; + this.port = port; + } - public MasterListener(String masterName, String host, int port, - long subscribeRetryWaitTimeMillis) { - this(masterName, host, port); - this.subscribeRetryWaitTimeMillis = subscribeRetryWaitTimeMillis; - } + public MasterListener(String masterName, String host, int port, + long subscribeRetryWaitTimeMillis) { + this(masterName, host, port); + this.subscribeRetryWaitTimeMillis = subscribeRetryWaitTimeMillis; + } - public void run() { + public void run() { - running.set(true); + running.set(true); - while (running.get()) { + while (running.get()) { - j = new Jedis(host, port); + j = new Jedis(host, port); - try { - j.subscribe(new JedisPubSub() { - @Override - public void onMessage(String channel, String message) { - log.fine("Sentinel " + host + ":" + port - + " published: " + message + "."); + try { + j.subscribe(new JedisPubSub() { + @Override + public void onMessage(String channel, String message) { + log.fine("Sentinel " + host + ":" + port + + " published: " + message + "."); - String[] switchMasterMsg = message.split(" "); + String[] switchMasterMsg = message.split(" "); - if (switchMasterMsg.length > 3) { + if (switchMasterMsg.length > 3) { - if (masterName.equals(switchMasterMsg[0])) { - initPool(toHostAndPort(Arrays.asList( - switchMasterMsg[3], - switchMasterMsg[4]))); - } else { - log.fine("Ignoring message on +switch-master for master name " - + switchMasterMsg[0] - + ", our master name is " - + masterName); - } + if (masterName.equals(switchMasterMsg[0])) { + initPool(toHostAndPort(Arrays.asList( + switchMasterMsg[3], + switchMasterMsg[4]))); + } else { + log.fine("Ignoring message on +switch-master for master name " + + switchMasterMsg[0] + + ", our master name is " + + masterName); + } - } else { - log.severe("Invalid message received on Sentinel " - + host - + ":" - + port - + " on channel +switch-master: " - + message); - } - } - }, "+switch-master"); + } else { + log.severe("Invalid message received on Sentinel " + + host + + ":" + + port + + " on channel +switch-master: " + + message); + } + } + }, "+switch-master"); - } catch (JedisConnectionException e) { + } catch (JedisConnectionException e) { - if (running.get()) { - log.severe("Lost connection to Sentinel at " + host - + ":" + port - + ". Sleeping 5000ms and retrying."); - try { - Thread.sleep(subscribeRetryWaitTimeMillis); - } catch (InterruptedException e1) { - e1.printStackTrace(); - } - } else { - log.fine("Unsubscribing from Sentinel at " + host + ":" - + port); - } - } - } - } + if (running.get()) { + log.severe("Lost connection to Sentinel at " + host + + ":" + port + + ". Sleeping 5000ms and retrying."); + try { + Thread.sleep(subscribeRetryWaitTimeMillis); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + } else { + log.fine("Unsubscribing from Sentinel at " + host + ":" + + port); + } + } + } + } - public void shutdown() { - try { - log.fine("Shutting down listener on " + host + ":" + port); - running.set(false); - // This isn't good, the Jedis object is not thread safe - j.disconnect(); - } catch (Exception e) { - log.severe("Caught exception while shutting down: " - + e.getMessage()); - } - } + public void shutdown() { + try { + log.fine("Shutting down listener on " + host + ":" + port); + running.set(false); + // This isn't good, the Jedis object is not thread safe + j.disconnect(); + } catch (Exception e) { + log.severe("Caught exception while shutting down: " + + e.getMessage()); + } + } } } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/JedisShardInfo.java b/src/main/java/redis/clients/jedis/JedisShardInfo.java index 3c9f84d..434d6ca 100644 --- a/src/main/java/redis/clients/jedis/JedisShardInfo.java +++ b/src/main/java/redis/clients/jedis/JedisShardInfo.java @@ -7,7 +7,7 @@ import redis.clients.util.Sharded; public class JedisShardInfo extends ShardInfo { public String toString() { - return host + ":" + port + "*" + getWeight(); + return host + ":" + port + "*" + getWeight(); } private int timeout; @@ -17,83 +17,83 @@ public class JedisShardInfo extends ShardInfo { private String name = null; public String getHost() { - return host; + return host; } public int getPort() { - return port; + return port; } public JedisShardInfo(String host) { - super(Sharded.DEFAULT_WEIGHT); - URI uri = URI.create(host); - if (uri.getScheme() != null && uri.getScheme().equals("redis")) { - this.host = uri.getHost(); - this.port = uri.getPort(); - this.password = uri.getUserInfo().split(":", 2)[1]; - } else { - this.host = host; - this.port = Protocol.DEFAULT_PORT; - } + super(Sharded.DEFAULT_WEIGHT); + URI uri = URI.create(host); + if (uri.getScheme() != null && uri.getScheme().equals("redis")) { + this.host = uri.getHost(); + this.port = uri.getPort(); + this.password = uri.getUserInfo().split(":", 2)[1]; + } else { + this.host = host; + this.port = Protocol.DEFAULT_PORT; + } } public JedisShardInfo(String host, String name) { - this(host, Protocol.DEFAULT_PORT, name); + this(host, Protocol.DEFAULT_PORT, name); } public JedisShardInfo(String host, int port) { - this(host, port, 2000); + this(host, port, 2000); } public JedisShardInfo(String host, int port, String name) { - this(host, port, 2000, name); + this(host, port, 2000, name); } public JedisShardInfo(String host, int port, int timeout) { - this(host, port, timeout, Sharded.DEFAULT_WEIGHT); + this(host, port, timeout, Sharded.DEFAULT_WEIGHT); } public JedisShardInfo(String host, int port, int timeout, String name) { - this(host, port, timeout, Sharded.DEFAULT_WEIGHT); - this.name = name; + this(host, port, timeout, Sharded.DEFAULT_WEIGHT); + this.name = name; } public JedisShardInfo(String host, int port, int timeout, int weight) { - super(weight); - this.host = host; - this.port = port; - this.timeout = timeout; + super(weight); + this.host = host; + this.port = port; + this.timeout = timeout; } public JedisShardInfo(URI uri) { - super(Sharded.DEFAULT_WEIGHT); - this.host = uri.getHost(); - this.port = uri.getPort(); - this.password = uri.getUserInfo().split(":", 2)[1]; + super(Sharded.DEFAULT_WEIGHT); + this.host = uri.getHost(); + this.port = uri.getPort(); + this.password = uri.getUserInfo().split(":", 2)[1]; } public String getPassword() { - return password; + return password; } public void setPassword(String auth) { - this.password = auth; + this.password = auth; } public int getTimeout() { - return timeout; + return timeout; } public void setTimeout(int timeout) { - this.timeout = timeout; + this.timeout = timeout; } public String getName() { - return name; + return name; } @Override public Jedis createResource() { - return new Jedis(this); + return new Jedis(this); } } diff --git a/src/main/java/redis/clients/jedis/JedisSlotBasedConnectionHandler.java b/src/main/java/redis/clients/jedis/JedisSlotBasedConnectionHandler.java index 189e368..d79dbaf 100644 --- a/src/main/java/redis/clients/jedis/JedisSlotBasedConnectionHandler.java +++ b/src/main/java/redis/clients/jedis/JedisSlotBasedConnectionHandler.java @@ -10,63 +10,63 @@ import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import redis.clients.jedis.exceptions.JedisConnectionException; public class JedisSlotBasedConnectionHandler extends - JedisClusterConnectionHandler { + JedisClusterConnectionHandler { public JedisSlotBasedConnectionHandler(Set nodes, - final GenericObjectPoolConfig poolConfig) { - super(nodes, poolConfig); + final GenericObjectPoolConfig poolConfig) { + super(nodes, poolConfig); } public Jedis getConnection() { - // In antirez's redis-rb-cluster implementation, - // getRandomConnection always return valid connection (able to - // ping-pong) - // or exception if all connections are invalid + // In antirez's redis-rb-cluster implementation, + // getRandomConnection always return valid connection (able to + // ping-pong) + // or exception if all connections are invalid - List pools = getShuffledNodesPool(); + List pools = getShuffledNodesPool(); - for (JedisPool pool : pools) { - Jedis jedis = null; - try { - jedis = pool.getResource(); + for (JedisPool pool : pools) { + Jedis jedis = null; + try { + jedis = pool.getResource(); - if (jedis == null) { - continue; - } + if (jedis == null) { + continue; + } - String result = jedis.ping(); + String result = jedis.ping(); - if (result.equalsIgnoreCase("pong")) - return jedis; + if (result.equalsIgnoreCase("pong")) + return jedis; - pool.returnBrokenResource(jedis); - } catch (JedisConnectionException ex) { - if (jedis != null) { - pool.returnBrokenResource(jedis); - } - } - } + pool.returnBrokenResource(jedis); + } catch (JedisConnectionException ex) { + if (jedis != null) { + pool.returnBrokenResource(jedis); + } + } + } - throw new JedisConnectionException("no reachable node in cluster"); + throw new JedisConnectionException("no reachable node in cluster"); } @Override 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 - return connectionPool.getResource(); - } else { - return getConnection(); - } + JedisPool connectionPool = cache.getSlotPool(slot); + if (connectionPool != null) { + // It can't guaranteed to get valid connection because of node + // assignment + return connectionPool.getResource(); + } else { + return getConnection(); + } } private List getShuffledNodesPool() { - List pools = new ArrayList(); - pools.addAll(cache.getNodes().values()); - Collections.shuffle(pools); - return pools; + List pools = new ArrayList(); + pools.addAll(cache.getNodes().values()); + Collections.shuffle(pools); + return pools; } } diff --git a/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java b/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java index 088816d..a84b432 100644 --- a/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java +++ b/src/main/java/redis/clients/jedis/MultiKeyBinaryRedisPipeline.java @@ -40,7 +40,7 @@ public interface MultiKeyBinaryRedisPipeline { Response smove(byte[] srckey, byte[] dstkey, byte[] member); Response sort(byte[] key, SortingParams sortingParameters, - byte[] dstkey); + byte[] dstkey); Response sort(byte[] key, byte[] dstkey); diff --git a/src/main/java/redis/clients/jedis/MultiKeyCommandsPipeline.java b/src/main/java/redis/clients/jedis/MultiKeyCommandsPipeline.java index de79bbf..fee7374 100644 --- a/src/main/java/redis/clients/jedis/MultiKeyCommandsPipeline.java +++ b/src/main/java/redis/clients/jedis/MultiKeyCommandsPipeline.java @@ -39,7 +39,7 @@ public interface MultiKeyCommandsPipeline { Response smove(String srckey, String dstkey, String member); Response sort(String key, SortingParams sortingParameters, - String dstkey); + String dstkey); Response sort(String key, String dstkey); diff --git a/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java b/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java index c1c0b8e..eca7093 100644 --- a/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java +++ b/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java @@ -5,474 +5,474 @@ import java.util.Map; import java.util.Set; abstract class MultiKeyPipelineBase extends PipelineBase implements - BasicRedisPipeline, MultiKeyBinaryRedisPipeline, - MultiKeyCommandsPipeline, ClusterPipeline { + BasicRedisPipeline, MultiKeyBinaryRedisPipeline, + MultiKeyCommandsPipeline, ClusterPipeline { protected Client client = null; public Response> brpop(String... args) { - client.brpop(args); - return getResponse(BuilderFactory.STRING_LIST); + client.brpop(args); + return getResponse(BuilderFactory.STRING_LIST); } public Response> brpop(int timeout, String... keys) { - client.brpop(timeout, keys); - return getResponse(BuilderFactory.STRING_LIST); + client.brpop(timeout, keys); + return getResponse(BuilderFactory.STRING_LIST); } public Response> blpop(String... args) { - client.blpop(args); - return getResponse(BuilderFactory.STRING_LIST); + client.blpop(args); + return getResponse(BuilderFactory.STRING_LIST); } public Response> blpop(int timeout, String... keys) { - client.blpop(timeout, keys); - return getResponse(BuilderFactory.STRING_LIST); + client.blpop(timeout, keys); + return getResponse(BuilderFactory.STRING_LIST); } public Response> blpopMap(int timeout, String... keys) { - client.blpop(timeout, keys); - return getResponse(BuilderFactory.STRING_MAP); + client.blpop(timeout, keys); + return getResponse(BuilderFactory.STRING_MAP); } public Response> brpop(byte[]... args) { - client.brpop(args); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + client.brpop(args); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response> brpop(int timeout, byte[]... keys) { - client.brpop(timeout, keys); - return getResponse(BuilderFactory.STRING_LIST); + client.brpop(timeout, keys); + return getResponse(BuilderFactory.STRING_LIST); } public Response> brpopMap(int timeout, String... keys) { - client.blpop(timeout, keys); - return getResponse(BuilderFactory.STRING_MAP); + client.blpop(timeout, keys); + return getResponse(BuilderFactory.STRING_MAP); } public Response> blpop(byte[]... args) { - client.blpop(args); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + client.blpop(args); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response> blpop(int timeout, byte[]... keys) { - client.blpop(timeout, keys); - return getResponse(BuilderFactory.STRING_LIST); + client.blpop(timeout, keys); + return getResponse(BuilderFactory.STRING_LIST); } public Response del(String... keys) { - client.del(keys); - return getResponse(BuilderFactory.LONG); + client.del(keys); + return getResponse(BuilderFactory.LONG); } public Response del(byte[]... keys) { - client.del(keys); - return getResponse(BuilderFactory.LONG); + client.del(keys); + return getResponse(BuilderFactory.LONG); } public Response> keys(String pattern) { - getClient(pattern).keys(pattern); - return getResponse(BuilderFactory.STRING_SET); + getClient(pattern).keys(pattern); + return getResponse(BuilderFactory.STRING_SET); } public Response> keys(byte[] pattern) { - getClient(pattern).keys(pattern); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + getClient(pattern).keys(pattern); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> mget(String... keys) { - client.mget(keys); - return getResponse(BuilderFactory.STRING_LIST); + client.mget(keys); + return getResponse(BuilderFactory.STRING_LIST); } public Response> mget(byte[]... keys) { - client.mget(keys); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + client.mget(keys); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response mset(String... keysvalues) { - client.mset(keysvalues); - return getResponse(BuilderFactory.STRING); + client.mset(keysvalues); + return getResponse(BuilderFactory.STRING); } public Response mset(byte[]... keysvalues) { - client.mset(keysvalues); - return getResponse(BuilderFactory.STRING); + client.mset(keysvalues); + return getResponse(BuilderFactory.STRING); } public Response msetnx(String... keysvalues) { - client.msetnx(keysvalues); - return getResponse(BuilderFactory.LONG); + client.msetnx(keysvalues); + return getResponse(BuilderFactory.LONG); } public Response msetnx(byte[]... keysvalues) { - client.msetnx(keysvalues); - return getResponse(BuilderFactory.LONG); + client.msetnx(keysvalues); + return getResponse(BuilderFactory.LONG); } public Response rename(String oldkey, String newkey) { - client.rename(oldkey, newkey); - return getResponse(BuilderFactory.STRING); + client.rename(oldkey, newkey); + return getResponse(BuilderFactory.STRING); } public Response rename(byte[] oldkey, byte[] newkey) { - client.rename(oldkey, newkey); - return getResponse(BuilderFactory.STRING); + client.rename(oldkey, newkey); + return getResponse(BuilderFactory.STRING); } public Response renamenx(String oldkey, String newkey) { - client.renamenx(oldkey, newkey); - return getResponse(BuilderFactory.LONG); + client.renamenx(oldkey, newkey); + return getResponse(BuilderFactory.LONG); } public Response renamenx(byte[] oldkey, byte[] newkey) { - client.renamenx(oldkey, newkey); - return getResponse(BuilderFactory.LONG); + client.renamenx(oldkey, newkey); + return getResponse(BuilderFactory.LONG); } public Response rpoplpush(String srckey, String dstkey) { - client.rpoplpush(srckey, dstkey); - return getResponse(BuilderFactory.STRING); + client.rpoplpush(srckey, dstkey); + return getResponse(BuilderFactory.STRING); } public Response rpoplpush(byte[] srckey, byte[] dstkey) { - client.rpoplpush(srckey, dstkey); - return getResponse(BuilderFactory.BYTE_ARRAY); + client.rpoplpush(srckey, dstkey); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response> sdiff(String... keys) { - client.sdiff(keys); - return getResponse(BuilderFactory.STRING_SET); + client.sdiff(keys); + return getResponse(BuilderFactory.STRING_SET); } public Response> sdiff(byte[]... keys) { - client.sdiff(keys); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + client.sdiff(keys); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response sdiffstore(String dstkey, String... keys) { - client.sdiffstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); + client.sdiffstore(dstkey, keys); + return getResponse(BuilderFactory.LONG); } public Response sdiffstore(byte[] dstkey, byte[]... keys) { - client.sdiffstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); + client.sdiffstore(dstkey, keys); + return getResponse(BuilderFactory.LONG); } public Response> sinter(String... keys) { - client.sinter(keys); - return getResponse(BuilderFactory.STRING_SET); + client.sinter(keys); + return getResponse(BuilderFactory.STRING_SET); } public Response> sinter(byte[]... keys) { - client.sinter(keys); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + client.sinter(keys); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response sinterstore(String dstkey, String... keys) { - client.sinterstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); + client.sinterstore(dstkey, keys); + return getResponse(BuilderFactory.LONG); } public Response sinterstore(byte[] dstkey, byte[]... keys) { - client.sinterstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); + client.sinterstore(dstkey, keys); + return getResponse(BuilderFactory.LONG); } public Response smove(String srckey, String dstkey, String member) { - client.smove(srckey, dstkey, member); - return getResponse(BuilderFactory.LONG); + client.smove(srckey, dstkey, member); + return getResponse(BuilderFactory.LONG); } public Response smove(byte[] srckey, byte[] dstkey, byte[] member) { - client.smove(srckey, dstkey, member); - return getResponse(BuilderFactory.LONG); + client.smove(srckey, dstkey, member); + return getResponse(BuilderFactory.LONG); } public Response sort(String key, SortingParams sortingParameters, - String dstkey) { - client.sort(key, sortingParameters, dstkey); - return getResponse(BuilderFactory.LONG); + String dstkey) { + client.sort(key, sortingParameters, dstkey); + return getResponse(BuilderFactory.LONG); } public Response sort(byte[] key, SortingParams sortingParameters, - byte[] dstkey) { - client.sort(key, sortingParameters, dstkey); - return getResponse(BuilderFactory.LONG); + byte[] dstkey) { + client.sort(key, sortingParameters, dstkey); + return getResponse(BuilderFactory.LONG); } public Response sort(String key, String dstkey) { - client.sort(key, dstkey); - return getResponse(BuilderFactory.LONG); + client.sort(key, dstkey); + return getResponse(BuilderFactory.LONG); } public Response sort(byte[] key, byte[] dstkey) { - client.sort(key, dstkey); - return getResponse(BuilderFactory.LONG); + client.sort(key, dstkey); + return getResponse(BuilderFactory.LONG); } public Response> sunion(String... keys) { - client.sunion(keys); - return getResponse(BuilderFactory.STRING_SET); + client.sunion(keys); + return getResponse(BuilderFactory.STRING_SET); } public Response> sunion(byte[]... keys) { - client.sunion(keys); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + client.sunion(keys); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response sunionstore(String dstkey, String... keys) { - client.sunionstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); + client.sunionstore(dstkey, keys); + return getResponse(BuilderFactory.LONG); } public Response sunionstore(byte[] dstkey, byte[]... keys) { - client.sunionstore(dstkey, keys); - return getResponse(BuilderFactory.LONG); + client.sunionstore(dstkey, keys); + return getResponse(BuilderFactory.LONG); } public Response watch(String... keys) { - client.watch(keys); - return getResponse(BuilderFactory.STRING); + client.watch(keys); + return getResponse(BuilderFactory.STRING); } public Response watch(byte[]... keys) { - client.watch(keys); - return getResponse(BuilderFactory.STRING); + client.watch(keys); + return getResponse(BuilderFactory.STRING); } public Response zinterstore(String dstkey, String... sets) { - client.zinterstore(dstkey, sets); - return getResponse(BuilderFactory.LONG); + client.zinterstore(dstkey, sets); + return getResponse(BuilderFactory.LONG); } public Response zinterstore(byte[] dstkey, byte[]... sets) { - client.zinterstore(dstkey, sets); - return getResponse(BuilderFactory.LONG); + client.zinterstore(dstkey, sets); + return getResponse(BuilderFactory.LONG); } public Response zinterstore(String dstkey, ZParams params, - String... sets) { - client.zinterstore(dstkey, params, sets); - return getResponse(BuilderFactory.LONG); + String... sets) { + client.zinterstore(dstkey, params, sets); + return getResponse(BuilderFactory.LONG); } public Response zinterstore(byte[] dstkey, ZParams params, - byte[]... sets) { - client.zinterstore(dstkey, params, sets); - return getResponse(BuilderFactory.LONG); + byte[]... sets) { + client.zinterstore(dstkey, params, sets); + return getResponse(BuilderFactory.LONG); } public Response zunionstore(String dstkey, String... sets) { - client.zunionstore(dstkey, sets); - return getResponse(BuilderFactory.LONG); + client.zunionstore(dstkey, sets); + return getResponse(BuilderFactory.LONG); } public Response zunionstore(byte[] dstkey, byte[]... sets) { - client.zunionstore(dstkey, sets); - return getResponse(BuilderFactory.LONG); + client.zunionstore(dstkey, sets); + return getResponse(BuilderFactory.LONG); } public Response zunionstore(String dstkey, ZParams params, - String... sets) { - client.zunionstore(dstkey, params, sets); - return getResponse(BuilderFactory.LONG); + String... sets) { + client.zunionstore(dstkey, params, sets); + return getResponse(BuilderFactory.LONG); } public Response zunionstore(byte[] dstkey, ZParams params, - byte[]... sets) { - client.zunionstore(dstkey, params, sets); - return getResponse(BuilderFactory.LONG); + byte[]... sets) { + client.zunionstore(dstkey, params, sets); + return getResponse(BuilderFactory.LONG); } public Response bgrewriteaof() { - client.bgrewriteaof(); - return getResponse(BuilderFactory.STRING); + client.bgrewriteaof(); + return getResponse(BuilderFactory.STRING); } public Response bgsave() { - client.bgsave(); - return getResponse(BuilderFactory.STRING); + client.bgsave(); + return getResponse(BuilderFactory.STRING); } public Response configGet(String pattern) { - client.configGet(pattern); - return getResponse(BuilderFactory.STRING); + client.configGet(pattern); + return getResponse(BuilderFactory.STRING); } public Response configSet(String parameter, String value) { - client.configSet(parameter, value); - return getResponse(BuilderFactory.STRING); + client.configSet(parameter, value); + return getResponse(BuilderFactory.STRING); } public Response brpoplpush(String source, String destination, - int timeout) { - client.brpoplpush(source, destination, timeout); - return getResponse(BuilderFactory.STRING); + int timeout) { + client.brpoplpush(source, destination, timeout); + return getResponse(BuilderFactory.STRING); } public Response brpoplpush(byte[] source, byte[] destination, - int timeout) { - client.brpoplpush(source, destination, timeout); - return getResponse(BuilderFactory.BYTE_ARRAY); + int timeout) { + client.brpoplpush(source, destination, timeout); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response configResetStat() { - client.configResetStat(); - return getResponse(BuilderFactory.STRING); + client.configResetStat(); + return getResponse(BuilderFactory.STRING); } public Response save() { - client.save(); - return getResponse(BuilderFactory.STRING); + client.save(); + return getResponse(BuilderFactory.STRING); } public Response lastsave() { - client.lastsave(); - return getResponse(BuilderFactory.LONG); + client.lastsave(); + return getResponse(BuilderFactory.LONG); } public Response publish(String channel, String message) { - client.publish(channel, message); - return getResponse(BuilderFactory.LONG); + client.publish(channel, message); + return getResponse(BuilderFactory.LONG); } public Response publish(byte[] channel, byte[] message) { - client.publish(channel, message); - return getResponse(BuilderFactory.LONG); + client.publish(channel, message); + return getResponse(BuilderFactory.LONG); } public Response randomKey() { - client.randomKey(); - return getResponse(BuilderFactory.STRING); + client.randomKey(); + return getResponse(BuilderFactory.STRING); } public Response randomKeyBinary() { - client.randomKey(); - return getResponse(BuilderFactory.BYTE_ARRAY); + client.randomKey(); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response flushDB() { - client.flushDB(); - return getResponse(BuilderFactory.STRING); + client.flushDB(); + return getResponse(BuilderFactory.STRING); } public Response flushAll() { - client.flushAll(); - return getResponse(BuilderFactory.STRING); + client.flushAll(); + return getResponse(BuilderFactory.STRING); } public Response info() { - client.info(); - return getResponse(BuilderFactory.STRING); + client.info(); + return getResponse(BuilderFactory.STRING); } public Response> time() { - client.time(); - return getResponse(BuilderFactory.STRING_LIST); + client.time(); + return getResponse(BuilderFactory.STRING_LIST); } public Response dbSize() { - client.dbSize(); - return getResponse(BuilderFactory.LONG); + client.dbSize(); + return getResponse(BuilderFactory.LONG); } public Response shutdown() { - client.shutdown(); - return getResponse(BuilderFactory.STRING); + client.shutdown(); + return getResponse(BuilderFactory.STRING); } public Response ping() { - client.ping(); - return getResponse(BuilderFactory.STRING); + client.ping(); + return getResponse(BuilderFactory.STRING); } public Response select(int index) { - client.select(index); - return getResponse(BuilderFactory.STRING); + client.select(index); + return getResponse(BuilderFactory.STRING); } public Response bitop(BitOP op, byte[] destKey, byte[]... srcKeys) { - client.bitop(op, destKey, srcKeys); - return getResponse(BuilderFactory.LONG); + client.bitop(op, destKey, srcKeys); + return getResponse(BuilderFactory.LONG); } public Response bitop(BitOP op, String destKey, String... srcKeys) { - client.bitop(op, destKey, srcKeys); - return getResponse(BuilderFactory.LONG); + client.bitop(op, destKey, srcKeys); + return getResponse(BuilderFactory.LONG); } public Response clusterNodes() { - client.clusterNodes(); - return getResponse(BuilderFactory.STRING); + client.clusterNodes(); + return getResponse(BuilderFactory.STRING); } public Response clusterMeet(final String ip, final int port) { - client.clusterMeet(ip, port); - return getResponse(BuilderFactory.STRING); + client.clusterMeet(ip, port); + return getResponse(BuilderFactory.STRING); } public Response clusterAddSlots(final int... slots) { - client.clusterAddSlots(slots); - return getResponse(BuilderFactory.STRING); + client.clusterAddSlots(slots); + return getResponse(BuilderFactory.STRING); } public Response clusterDelSlots(final int... slots) { - client.clusterDelSlots(slots); - return getResponse(BuilderFactory.STRING); + client.clusterDelSlots(slots); + return getResponse(BuilderFactory.STRING); } public Response clusterInfo() { - client.clusterInfo(); - return getResponse(BuilderFactory.STRING); + client.clusterInfo(); + return getResponse(BuilderFactory.STRING); } public Response> clusterGetKeysInSlot(final int slot, - final int count) { - client.clusterGetKeysInSlot(slot, count); - return getResponse(BuilderFactory.STRING_LIST); + final int count) { + client.clusterGetKeysInSlot(slot, count); + return getResponse(BuilderFactory.STRING_LIST); } public Response clusterSetSlotNode(final int slot, - final String nodeId) { - client.clusterSetSlotNode(slot, nodeId); - return getResponse(BuilderFactory.STRING); + final String nodeId) { + client.clusterSetSlotNode(slot, nodeId); + return getResponse(BuilderFactory.STRING); } public Response clusterSetSlotMigrating(final int slot, - final String nodeId) { - client.clusterSetSlotMigrating(slot, nodeId); - return getResponse(BuilderFactory.STRING); + final String nodeId) { + client.clusterSetSlotMigrating(slot, nodeId); + return getResponse(BuilderFactory.STRING); } public Response clusterSetSlotImporting(final int slot, - final String nodeId) { - client.clusterSetSlotImporting(slot, nodeId); - return getResponse(BuilderFactory.STRING); + final String nodeId) { + client.clusterSetSlotImporting(slot, nodeId); + return getResponse(BuilderFactory.STRING); } @Override public Response pfmerge(byte[] destkey, byte[]... sourcekeys) { - client.pfmerge(destkey, sourcekeys); - return getResponse(BuilderFactory.STRING); + client.pfmerge(destkey, sourcekeys); + return getResponse(BuilderFactory.STRING); } @Override public Response pfmerge(String destkey, String... sourcekeys) { - client.pfmerge(destkey, sourcekeys); - return getResponse(BuilderFactory.STRING); + client.pfmerge(destkey, sourcekeys); + return getResponse(BuilderFactory.STRING); } @Override public Response pfcount(String... keys) { - client.pfcount(keys); - return getResponse(BuilderFactory.LONG); + client.pfcount(keys); + return getResponse(BuilderFactory.LONG); } @Override public Response pfcount(final byte[]... keys) { - client.pfcount(keys); - return getResponse(BuilderFactory.LONG); + client.pfcount(keys); + return getResponse(BuilderFactory.LONG); } } diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index 95e8217..ba0113e 100644 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -10,81 +10,81 @@ public class Pipeline extends MultiKeyPipelineBase { private MultiResponseBuilder currentMulti; private class MultiResponseBuilder extends Builder> { - private List> responses = new ArrayList>(); + private List> responses = new ArrayList>(); - @Override - public List build(Object data) { - @SuppressWarnings("unchecked") - List list = (List) data; - List values = new ArrayList(); + @Override + public List build(Object data) { + @SuppressWarnings("unchecked") + List list = (List) data; + List values = new ArrayList(); - if (list.size() != responses.size()) { - throw new JedisDataException("Expected data size " - + responses.size() + " but was " + list.size()); - } + if (list.size() != responses.size()) { + throw new JedisDataException("Expected data size " + + responses.size() + " but was " + list.size()); + } - for (int i = 0; i < list.size(); i++) { - Response response = responses.get(i); - response.set(list.get(i)); - Object builtResponse; - try { - builtResponse = response.get(); - } catch (JedisDataException e) { - builtResponse = e; - } - values.add(builtResponse); - } - return values; - } + for (int i = 0; i < list.size(); i++) { + Response response = responses.get(i); + response.set(list.get(i)); + Object builtResponse; + try { + builtResponse = response.get(); + } catch (JedisDataException e) { + builtResponse = e; + } + values.add(builtResponse); + } + return values; + } - public void setResponseDependency(Response dependency) { - for (Response response : responses) { - response.setDependency(dependency); - } - } + public void setResponseDependency(Response dependency) { + for (Response response : responses) { + response.setDependency(dependency); + } + } - public void addResponse(Response response) { - responses.add(response); - } + public void addResponse(Response response) { + responses.add(response); + } } @Override protected Response getResponse(Builder builder) { - if (currentMulti != null) { - super.getResponse(BuilderFactory.STRING); // Expected QUEUED + if (currentMulti != null) { + super.getResponse(BuilderFactory.STRING); // Expected QUEUED - Response lr = new Response(builder); - currentMulti.addResponse(lr); - return lr; - } else { - return super.getResponse(builder); - } + Response lr = new Response(builder); + currentMulti.addResponse(lr); + return lr; + } else { + return super.getResponse(builder); + } } public void setClient(Client client) { - this.client = client; + this.client = client; } @Override protected Client getClient(byte[] key) { - return client; + return client; } @Override protected Client getClient(String key) { - return client; + return client; } public void clear() { - if (isInMulti()) { - discard(); - } + if (isInMulti()) { + discard(); + } - sync(); + sync(); } public boolean isInMulti() { - return currentMulti != null; + return currentMulti != null; } /** @@ -93,12 +93,12 @@ public class Pipeline extends MultiKeyPipelineBase { * the different Response of the commands you execute. */ public void sync() { - if (getPipelinedResponseLength() > 0) { + if (getPipelinedResponseLength() > 0) { List unformatted = client.getMany(getPipelinedResponseLength()); for (Object o : unformatted) { generateResponse(o); } - } + } } /** * Synchronize pipeline by reading all responses. This operation close the @@ -126,33 +126,33 @@ public class Pipeline extends MultiKeyPipelineBase { } public Response discard() { - if (currentMulti == null) - throw new JedisDataException("DISCARD without MULTI"); - client.discard(); - currentMulti = null; - return getResponse(BuilderFactory.STRING); + if (currentMulti == null) + throw new JedisDataException("DISCARD without MULTI"); + client.discard(); + currentMulti = null; + return getResponse(BuilderFactory.STRING); } public Response> exec() { - if (currentMulti == null) - throw new JedisDataException("EXEC without MULTI"); + if (currentMulti == null) + throw new JedisDataException("EXEC without MULTI"); - client.exec(); - Response> response = super.getResponse(currentMulti); - currentMulti.setResponseDependency(response); - currentMulti = null; - return response; + client.exec(); + Response> response = super.getResponse(currentMulti); + currentMulti.setResponseDependency(response); + currentMulti = null; + return response; } public Response multi() { - if (currentMulti != null) - throw new JedisDataException("MULTI calls can not be nested"); + if (currentMulti != null) + throw new JedisDataException("MULTI calls can not be nested"); - client.multi(); - Response response = getResponse(BuilderFactory.STRING); // Expecting - // OK - currentMulti = new MultiResponseBuilder(); - return response; + client.multi(); + Response response = getResponse(BuilderFactory.STRING); // Expecting + // OK + currentMulti = new MultiResponseBuilder(); + return response; } } diff --git a/src/main/java/redis/clients/jedis/PipelineBase.java b/src/main/java/redis/clients/jedis/PipelineBase.java index adfc5f6..9dafac5 100644 --- a/src/main/java/redis/clients/jedis/PipelineBase.java +++ b/src/main/java/redis/clients/jedis/PipelineBase.java @@ -9,1332 +9,1332 @@ import java.util.Set; import redis.clients.jedis.BinaryClient.LIST_POSITION; abstract class PipelineBase extends Queable implements BinaryRedisPipeline, - RedisPipeline { + RedisPipeline { protected abstract Client getClient(String key); protected abstract Client getClient(byte[] key); public Response append(String key, String value) { - getClient(key).append(key, value); - return getResponse(BuilderFactory.LONG); + getClient(key).append(key, value); + return getResponse(BuilderFactory.LONG); } public Response append(byte[] key, byte[] value) { - getClient(key).append(key, value); - return getResponse(BuilderFactory.LONG); + getClient(key).append(key, value); + return getResponse(BuilderFactory.LONG); } public Response> blpop(String key) { - String[] temp = new String[1]; - temp[0] = key; - getClient(key).blpop(temp); - return getResponse(BuilderFactory.STRING_LIST); + String[] temp = new String[1]; + temp[0] = key; + getClient(key).blpop(temp); + return getResponse(BuilderFactory.STRING_LIST); } public Response> brpop(String key) { - String[] temp = new String[1]; - temp[0] = key; - getClient(key).brpop(temp); - return getResponse(BuilderFactory.STRING_LIST); + String[] temp = new String[1]; + temp[0] = key; + getClient(key).brpop(temp); + return getResponse(BuilderFactory.STRING_LIST); } public Response> blpop(byte[] key) { - byte[][] temp = new byte[1][]; - temp[0] = key; - getClient(key).blpop(temp); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + byte[][] temp = new byte[1][]; + temp[0] = key; + getClient(key).blpop(temp); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response> brpop(byte[] key) { - byte[][] temp = new byte[1][]; - temp[0] = key; - getClient(key).brpop(temp); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + byte[][] temp = new byte[1][]; + temp[0] = key; + getClient(key).brpop(temp); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response decr(String key) { - getClient(key).decr(key); - return getResponse(BuilderFactory.LONG); + getClient(key).decr(key); + return getResponse(BuilderFactory.LONG); } public Response decr(byte[] key) { - getClient(key).decr(key); - return getResponse(BuilderFactory.LONG); + getClient(key).decr(key); + return getResponse(BuilderFactory.LONG); } public Response decrBy(String key, long integer) { - getClient(key).decrBy(key, integer); - return getResponse(BuilderFactory.LONG); + getClient(key).decrBy(key, integer); + return getResponse(BuilderFactory.LONG); } public Response decrBy(byte[] key, long integer) { - getClient(key).decrBy(key, integer); - return getResponse(BuilderFactory.LONG); + getClient(key).decrBy(key, integer); + return getResponse(BuilderFactory.LONG); } public Response del(String key) { - getClient(key).del(key); - return getResponse(BuilderFactory.LONG); + getClient(key).del(key); + return getResponse(BuilderFactory.LONG); } public Response del(byte[] key) { - getClient(key).del(key); - return getResponse(BuilderFactory.LONG); + getClient(key).del(key); + return getResponse(BuilderFactory.LONG); } public Response echo(String string) { - getClient(string).echo(string); - return getResponse(BuilderFactory.STRING); + getClient(string).echo(string); + return getResponse(BuilderFactory.STRING); } public Response echo(byte[] string) { - getClient(string).echo(string); - return getResponse(BuilderFactory.BYTE_ARRAY); + getClient(string).echo(string); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response exists(String key) { - getClient(key).exists(key); - return getResponse(BuilderFactory.BOOLEAN); + getClient(key).exists(key); + return getResponse(BuilderFactory.BOOLEAN); } public Response exists(byte[] key) { - getClient(key).exists(key); - return getResponse(BuilderFactory.BOOLEAN); + getClient(key).exists(key); + return getResponse(BuilderFactory.BOOLEAN); } public Response expire(String key, int seconds) { - getClient(key).expire(key, seconds); - return getResponse(BuilderFactory.LONG); + getClient(key).expire(key, seconds); + return getResponse(BuilderFactory.LONG); } public Response expire(byte[] key, int seconds) { - getClient(key).expire(key, seconds); - return getResponse(BuilderFactory.LONG); + getClient(key).expire(key, seconds); + return getResponse(BuilderFactory.LONG); } public Response expireAt(String key, long unixTime) { - getClient(key).expireAt(key, unixTime); - return getResponse(BuilderFactory.LONG); + getClient(key).expireAt(key, unixTime); + return getResponse(BuilderFactory.LONG); } public Response expireAt(byte[] key, long unixTime) { - getClient(key).expireAt(key, unixTime); - return getResponse(BuilderFactory.LONG); + getClient(key).expireAt(key, unixTime); + return getResponse(BuilderFactory.LONG); } public Response get(String key) { - getClient(key).get(key); - return getResponse(BuilderFactory.STRING); + getClient(key).get(key); + return getResponse(BuilderFactory.STRING); } public Response get(byte[] key) { - getClient(key).get(key); - return getResponse(BuilderFactory.BYTE_ARRAY); + getClient(key).get(key); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response getbit(String key, long offset) { - getClient(key).getbit(key, offset); - return getResponse(BuilderFactory.BOOLEAN); + getClient(key).getbit(key, offset); + return getResponse(BuilderFactory.BOOLEAN); } public Response getbit(byte[] key, long offset) { - getClient(key).getbit(key, offset); - return getResponse(BuilderFactory.BOOLEAN); + getClient(key).getbit(key, offset); + return getResponse(BuilderFactory.BOOLEAN); } public Response bitpos(final String key, final boolean value) { - return bitpos(key, value, new BitPosParams()); + return bitpos(key, value, new BitPosParams()); } public Response bitpos(final String key, final boolean value, - final BitPosParams params) { - getClient(key).bitpos(key, value, params); - return getResponse(BuilderFactory.LONG); + final BitPosParams params) { + getClient(key).bitpos(key, value, params); + return getResponse(BuilderFactory.LONG); } public Response bitpos(final byte[] key, final boolean value) { - return bitpos(key, value, new BitPosParams()); + return bitpos(key, value, new BitPosParams()); } public Response bitpos(final byte[] key, final boolean value, - final BitPosParams params) { - getClient(key).bitpos(key, value, params); - return getResponse(BuilderFactory.LONG); + final BitPosParams params) { + getClient(key).bitpos(key, value, params); + return getResponse(BuilderFactory.LONG); } public Response getrange(String key, long startOffset, - long endOffset) { - getClient(key).getrange(key, startOffset, endOffset); - return getResponse(BuilderFactory.STRING); + long endOffset) { + getClient(key).getrange(key, startOffset, endOffset); + return getResponse(BuilderFactory.STRING); } public Response getSet(String key, String value) { - getClient(key).getSet(key, value); - return getResponse(BuilderFactory.STRING); + getClient(key).getSet(key, value); + return getResponse(BuilderFactory.STRING); } public Response getSet(byte[] key, byte[] value) { - getClient(key).getSet(key, value); - return getResponse(BuilderFactory.BYTE_ARRAY); + getClient(key).getSet(key, value); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response getrange(byte[] key, long startOffset, - long endOffset) { - getClient(key).getrange(key, startOffset, endOffset); - return getResponse(BuilderFactory.BYTE_ARRAY); + long endOffset) { + getClient(key).getrange(key, startOffset, endOffset); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response hdel(String key, String... field) { - getClient(key).hdel(key, field); - return getResponse(BuilderFactory.LONG); + getClient(key).hdel(key, field); + return getResponse(BuilderFactory.LONG); } public Response hdel(byte[] key, byte[]... field) { - getClient(key).hdel(key, field); - return getResponse(BuilderFactory.LONG); + getClient(key).hdel(key, field); + return getResponse(BuilderFactory.LONG); } public Response hexists(String key, String field) { - getClient(key).hexists(key, field); - return getResponse(BuilderFactory.BOOLEAN); + getClient(key).hexists(key, field); + return getResponse(BuilderFactory.BOOLEAN); } public Response hexists(byte[] key, byte[] field) { - getClient(key).hexists(key, field); - return getResponse(BuilderFactory.BOOLEAN); + getClient(key).hexists(key, field); + return getResponse(BuilderFactory.BOOLEAN); } public Response hget(String key, String field) { - getClient(key).hget(key, field); - return getResponse(BuilderFactory.STRING); + getClient(key).hget(key, field); + return getResponse(BuilderFactory.STRING); } public Response hget(byte[] key, byte[] field) { - getClient(key).hget(key, field); - return getResponse(BuilderFactory.BYTE_ARRAY); + getClient(key).hget(key, field); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response> hgetAll(String key) { - getClient(key).hgetAll(key); - return getResponse(BuilderFactory.STRING_MAP); + getClient(key).hgetAll(key); + return getResponse(BuilderFactory.STRING_MAP); } public Response> hgetAll(byte[] key) { - getClient(key).hgetAll(key); - return getResponse(BuilderFactory.BYTE_ARRAY_MAP); + getClient(key).hgetAll(key); + return getResponse(BuilderFactory.BYTE_ARRAY_MAP); } public Response hincrBy(String key, String field, long value) { - getClient(key).hincrBy(key, field, value); - return getResponse(BuilderFactory.LONG); + getClient(key).hincrBy(key, field, value); + return getResponse(BuilderFactory.LONG); } public Response hincrBy(byte[] key, byte[] field, long value) { - getClient(key).hincrBy(key, field, value); - return getResponse(BuilderFactory.LONG); + getClient(key).hincrBy(key, field, value); + return getResponse(BuilderFactory.LONG); } public Response> hkeys(String key) { - getClient(key).hkeys(key); - return getResponse(BuilderFactory.STRING_SET); + getClient(key).hkeys(key); + return getResponse(BuilderFactory.STRING_SET); } public Response> hkeys(byte[] key) { - getClient(key).hkeys(key); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + getClient(key).hkeys(key); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response hlen(String key) { - getClient(key).hlen(key); - return getResponse(BuilderFactory.LONG); + getClient(key).hlen(key); + return getResponse(BuilderFactory.LONG); } public Response hlen(byte[] key) { - getClient(key).hlen(key); - return getResponse(BuilderFactory.LONG); + getClient(key).hlen(key); + return getResponse(BuilderFactory.LONG); } public Response> hmget(String key, String... fields) { - getClient(key).hmget(key, fields); - return getResponse(BuilderFactory.STRING_LIST); + getClient(key).hmget(key, fields); + return getResponse(BuilderFactory.STRING_LIST); } public Response> hmget(byte[] key, byte[]... fields) { - getClient(key).hmget(key, fields); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + getClient(key).hmget(key, fields); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response hmset(String key, Map hash) { - getClient(key).hmset(key, hash); - return getResponse(BuilderFactory.STRING); + getClient(key).hmset(key, hash); + return getResponse(BuilderFactory.STRING); } public Response hmset(byte[] key, Map hash) { - getClient(key).hmset(key, hash); - return getResponse(BuilderFactory.STRING); + getClient(key).hmset(key, hash); + return getResponse(BuilderFactory.STRING); } public Response hset(String key, String field, String value) { - getClient(key).hset(key, field, value); - return getResponse(BuilderFactory.LONG); + getClient(key).hset(key, field, value); + return getResponse(BuilderFactory.LONG); } public Response hset(byte[] key, byte[] field, byte[] value) { - getClient(key).hset(key, field, value); - return getResponse(BuilderFactory.LONG); + getClient(key).hset(key, field, value); + return getResponse(BuilderFactory.LONG); } public Response hsetnx(String key, String field, String value) { - getClient(key).hsetnx(key, field, value); - return getResponse(BuilderFactory.LONG); + getClient(key).hsetnx(key, field, value); + return getResponse(BuilderFactory.LONG); } public Response hsetnx(byte[] key, byte[] field, byte[] value) { - getClient(key).hsetnx(key, field, value); - return getResponse(BuilderFactory.LONG); + getClient(key).hsetnx(key, field, value); + return getResponse(BuilderFactory.LONG); } public Response> hvals(String key) { - getClient(key).hvals(key); - return getResponse(BuilderFactory.STRING_LIST); + getClient(key).hvals(key); + return getResponse(BuilderFactory.STRING_LIST); } public Response> hvals(byte[] key) { - getClient(key).hvals(key); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + getClient(key).hvals(key); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response incr(String key) { - getClient(key).incr(key); - return getResponse(BuilderFactory.LONG); + getClient(key).incr(key); + return getResponse(BuilderFactory.LONG); } public Response incr(byte[] key) { - getClient(key).incr(key); - return getResponse(BuilderFactory.LONG); + getClient(key).incr(key); + return getResponse(BuilderFactory.LONG); } public Response incrBy(String key, long integer) { - getClient(key).incrBy(key, integer); - return getResponse(BuilderFactory.LONG); + getClient(key).incrBy(key, integer); + return getResponse(BuilderFactory.LONG); } public Response incrBy(byte[] key, long integer) { - getClient(key).incrBy(key, integer); - return getResponse(BuilderFactory.LONG); + getClient(key).incrBy(key, integer); + return getResponse(BuilderFactory.LONG); } public Response lindex(String key, long index) { - getClient(key).lindex(key, index); - return getResponse(BuilderFactory.STRING); + getClient(key).lindex(key, index); + return getResponse(BuilderFactory.STRING); } public Response lindex(byte[] key, long index) { - getClient(key).lindex(key, index); - return getResponse(BuilderFactory.BYTE_ARRAY); + getClient(key).lindex(key, index); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response linsert(String key, LIST_POSITION where, - String pivot, String value) { - getClient(key).linsert(key, where, pivot, value); - return getResponse(BuilderFactory.LONG); + String pivot, String value) { + getClient(key).linsert(key, where, pivot, value); + return getResponse(BuilderFactory.LONG); } public Response linsert(byte[] key, LIST_POSITION where, - byte[] pivot, byte[] value) { - getClient(key).linsert(key, where, pivot, value); - return getResponse(BuilderFactory.LONG); + byte[] pivot, byte[] value) { + getClient(key).linsert(key, where, pivot, value); + return getResponse(BuilderFactory.LONG); } public Response llen(String key) { - getClient(key).llen(key); - return getResponse(BuilderFactory.LONG); + getClient(key).llen(key); + return getResponse(BuilderFactory.LONG); } public Response llen(byte[] key) { - getClient(key).llen(key); - return getResponse(BuilderFactory.LONG); + getClient(key).llen(key); + return getResponse(BuilderFactory.LONG); } public Response lpop(String key) { - getClient(key).lpop(key); - return getResponse(BuilderFactory.STRING); + getClient(key).lpop(key); + return getResponse(BuilderFactory.STRING); } public Response lpop(byte[] key) { - getClient(key).lpop(key); - return getResponse(BuilderFactory.BYTE_ARRAY); + getClient(key).lpop(key); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response lpush(String key, String... string) { - getClient(key).lpush(key, string); - return getResponse(BuilderFactory.LONG); + getClient(key).lpush(key, string); + return getResponse(BuilderFactory.LONG); } public Response lpush(byte[] key, byte[]... string) { - getClient(key).lpush(key, string); - return getResponse(BuilderFactory.LONG); + getClient(key).lpush(key, string); + return getResponse(BuilderFactory.LONG); } public Response lpushx(String key, String... string) { - getClient(key).lpushx(key, string); - return getResponse(BuilderFactory.LONG); + getClient(key).lpushx(key, string); + return getResponse(BuilderFactory.LONG); } public Response lpushx(byte[] key, byte[]... bytes) { - getClient(key).lpushx(key, bytes); - return getResponse(BuilderFactory.LONG); + getClient(key).lpushx(key, bytes); + return getResponse(BuilderFactory.LONG); } public Response> lrange(String key, long start, long end) { - getClient(key).lrange(key, start, end); - return getResponse(BuilderFactory.STRING_LIST); + getClient(key).lrange(key, start, end); + return getResponse(BuilderFactory.STRING_LIST); } public Response> lrange(byte[] key, long start, long end) { - getClient(key).lrange(key, start, end); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + getClient(key).lrange(key, start, end); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response lrem(String key, long count, String value) { - getClient(key).lrem(key, count, value); - return getResponse(BuilderFactory.LONG); + getClient(key).lrem(key, count, value); + return getResponse(BuilderFactory.LONG); } public Response lrem(byte[] key, long count, byte[] value) { - getClient(key).lrem(key, count, value); - return getResponse(BuilderFactory.LONG); + getClient(key).lrem(key, count, value); + return getResponse(BuilderFactory.LONG); } public Response lset(String key, long index, String value) { - getClient(key).lset(key, index, value); - return getResponse(BuilderFactory.STRING); + getClient(key).lset(key, index, value); + return getResponse(BuilderFactory.STRING); } public Response lset(byte[] key, long index, byte[] value) { - getClient(key).lset(key, index, value); - return getResponse(BuilderFactory.STRING); + getClient(key).lset(key, index, value); + return getResponse(BuilderFactory.STRING); } public Response ltrim(String key, long start, long end) { - getClient(key).ltrim(key, start, end); - return getResponse(BuilderFactory.STRING); + getClient(key).ltrim(key, start, end); + return getResponse(BuilderFactory.STRING); } public Response ltrim(byte[] key, long start, long end) { - getClient(key).ltrim(key, start, end); - return getResponse(BuilderFactory.STRING); + getClient(key).ltrim(key, start, end); + return getResponse(BuilderFactory.STRING); } public Response move(String key, int dbIndex) { - getClient(key).move(key, dbIndex); - return getResponse(BuilderFactory.LONG); + getClient(key).move(key, dbIndex); + return getResponse(BuilderFactory.LONG); } public Response move(byte[] key, int dbIndex) { - getClient(key).move(key, dbIndex); - return getResponse(BuilderFactory.LONG); + getClient(key).move(key, dbIndex); + return getResponse(BuilderFactory.LONG); } public Response persist(String key) { - getClient(key).persist(key); - return getResponse(BuilderFactory.LONG); + getClient(key).persist(key); + return getResponse(BuilderFactory.LONG); } public Response persist(byte[] key) { - getClient(key).persist(key); - return getResponse(BuilderFactory.LONG); + getClient(key).persist(key); + return getResponse(BuilderFactory.LONG); } public Response rpop(String key) { - getClient(key).rpop(key); - return getResponse(BuilderFactory.STRING); + getClient(key).rpop(key); + return getResponse(BuilderFactory.STRING); } public Response rpop(byte[] key) { - getClient(key).rpop(key); - return getResponse(BuilderFactory.BYTE_ARRAY); + getClient(key).rpop(key); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response rpush(String key, String... string) { - getClient(key).rpush(key, string); - return getResponse(BuilderFactory.LONG); + getClient(key).rpush(key, string); + return getResponse(BuilderFactory.LONG); } public Response rpush(byte[] key, byte[]... string) { - getClient(key).rpush(key, string); - return getResponse(BuilderFactory.LONG); + getClient(key).rpush(key, string); + return getResponse(BuilderFactory.LONG); } public Response rpushx(String key, String... string) { - getClient(key).rpushx(key, string); - return getResponse(BuilderFactory.LONG); + getClient(key).rpushx(key, string); + return getResponse(BuilderFactory.LONG); } public Response rpushx(byte[] key, byte[]... string) { - getClient(key).rpushx(key, string); - return getResponse(BuilderFactory.LONG); + getClient(key).rpushx(key, string); + return getResponse(BuilderFactory.LONG); } public Response sadd(String key, String... member) { - getClient(key).sadd(key, member); - return getResponse(BuilderFactory.LONG); + getClient(key).sadd(key, member); + return getResponse(BuilderFactory.LONG); } public Response sadd(byte[] key, byte[]... member) { - getClient(key).sadd(key, member); - return getResponse(BuilderFactory.LONG); + getClient(key).sadd(key, member); + return getResponse(BuilderFactory.LONG); } public Response scard(String key) { - getClient(key).scard(key); - return getResponse(BuilderFactory.LONG); + getClient(key).scard(key); + return getResponse(BuilderFactory.LONG); } public Response scard(byte[] key) { - getClient(key).scard(key); - return getResponse(BuilderFactory.LONG); + getClient(key).scard(key); + return getResponse(BuilderFactory.LONG); } public Response set(String key, String value) { - getClient(key).set(key, value); - return getResponse(BuilderFactory.STRING); + getClient(key).set(key, value); + return getResponse(BuilderFactory.STRING); } public Response set(byte[] key, byte[] value) { - getClient(key).set(key, value); - return getResponse(BuilderFactory.STRING); + getClient(key).set(key, value); + return getResponse(BuilderFactory.STRING); } public Response setbit(String key, long offset, boolean value) { - getClient(key).setbit(key, offset, value); - return getResponse(BuilderFactory.BOOLEAN); + getClient(key).setbit(key, offset, value); + return getResponse(BuilderFactory.BOOLEAN); } public Response setbit(byte[] key, long offset, byte[] value) { - getClient(key).setbit(key, offset, value); - return getResponse(BuilderFactory.BOOLEAN); + getClient(key).setbit(key, offset, value); + return getResponse(BuilderFactory.BOOLEAN); } public Response setex(String key, int seconds, String value) { - getClient(key).setex(key, seconds, value); - return getResponse(BuilderFactory.STRING); + getClient(key).setex(key, seconds, value); + return getResponse(BuilderFactory.STRING); } public Response setex(byte[] key, int seconds, byte[] value) { - getClient(key).setex(key, seconds, value); - return getResponse(BuilderFactory.STRING); + getClient(key).setex(key, seconds, value); + return getResponse(BuilderFactory.STRING); } public Response setnx(String key, String value) { - getClient(key).setnx(key, value); - return getResponse(BuilderFactory.LONG); + getClient(key).setnx(key, value); + return getResponse(BuilderFactory.LONG); } public Response setnx(byte[] key, byte[] value) { - getClient(key).setnx(key, value); - return getResponse(BuilderFactory.LONG); + getClient(key).setnx(key, value); + return getResponse(BuilderFactory.LONG); } public Response setrange(String key, long offset, String value) { - getClient(key).setrange(key, offset, value); - return getResponse(BuilderFactory.LONG); + getClient(key).setrange(key, offset, value); + return getResponse(BuilderFactory.LONG); } public Response setrange(byte[] key, long offset, byte[] value) { - getClient(key).setrange(key, offset, value); - return getResponse(BuilderFactory.LONG); + getClient(key).setrange(key, offset, value); + return getResponse(BuilderFactory.LONG); } public Response sismember(String key, String member) { - getClient(key).sismember(key, member); - return getResponse(BuilderFactory.BOOLEAN); + getClient(key).sismember(key, member); + return getResponse(BuilderFactory.BOOLEAN); } public Response sismember(byte[] key, byte[] member) { - getClient(key).sismember(key, member); - return getResponse(BuilderFactory.BOOLEAN); + getClient(key).sismember(key, member); + return getResponse(BuilderFactory.BOOLEAN); } public Response> smembers(String key) { - getClient(key).smembers(key); - return getResponse(BuilderFactory.STRING_SET); + getClient(key).smembers(key); + return getResponse(BuilderFactory.STRING_SET); } public Response> smembers(byte[] key) { - getClient(key).smembers(key); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + getClient(key).smembers(key); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> sort(String key) { - getClient(key).sort(key); - return getResponse(BuilderFactory.STRING_LIST); + getClient(key).sort(key); + return getResponse(BuilderFactory.STRING_LIST); } public Response> sort(byte[] key) { - getClient(key).sort(key); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + getClient(key).sort(key); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response> sort(String key, - SortingParams sortingParameters) { - getClient(key).sort(key, sortingParameters); - return getResponse(BuilderFactory.STRING_LIST); + SortingParams sortingParameters) { + getClient(key).sort(key, sortingParameters); + return getResponse(BuilderFactory.STRING_LIST); } public Response> sort(byte[] key, - SortingParams sortingParameters) { - getClient(key).sort(key, sortingParameters); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + SortingParams sortingParameters) { + getClient(key).sort(key, sortingParameters); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response spop(String key) { - getClient(key).spop(key); - return getResponse(BuilderFactory.STRING); + getClient(key).spop(key); + return getResponse(BuilderFactory.STRING); } public Response spop(byte[] key) { - getClient(key).spop(key); - return getResponse(BuilderFactory.BYTE_ARRAY); + getClient(key).spop(key); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response srandmember(String key) { - getClient(key).srandmember(key); - return getResponse(BuilderFactory.STRING); + getClient(key).srandmember(key); + return getResponse(BuilderFactory.STRING); } public Response> srandmember(String key, int count) { - getClient(key).srandmember(key, count); - return getResponse(BuilderFactory.STRING_LIST); + getClient(key).srandmember(key, count); + return getResponse(BuilderFactory.STRING_LIST); } public Response srandmember(byte[] key) { - getClient(key).srandmember(key); - return getResponse(BuilderFactory.BYTE_ARRAY); + getClient(key).srandmember(key); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response> srandmember(byte[] key, int count) { - getClient(key).srandmember(key, count); - return getResponse(BuilderFactory.BYTE_ARRAY_LIST); + getClient(key).srandmember(key, count); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } public Response srem(String key, String... member) { - getClient(key).srem(key, member); - return getResponse(BuilderFactory.LONG); + getClient(key).srem(key, member); + return getResponse(BuilderFactory.LONG); } public Response srem(byte[] key, byte[]... member) { - getClient(key).srem(key, member); - return getResponse(BuilderFactory.LONG); + getClient(key).srem(key, member); + return getResponse(BuilderFactory.LONG); } public Response strlen(String key) { - getClient(key).strlen(key); - return getResponse(BuilderFactory.LONG); + getClient(key).strlen(key); + return getResponse(BuilderFactory.LONG); } public Response strlen(byte[] key) { - getClient(key).strlen(key); - return getResponse(BuilderFactory.LONG); + getClient(key).strlen(key); + return getResponse(BuilderFactory.LONG); } public Response substr(String key, int start, int end) { - getClient(key).substr(key, start, end); - return getResponse(BuilderFactory.STRING); + getClient(key).substr(key, start, end); + return getResponse(BuilderFactory.STRING); } public Response substr(byte[] key, int start, int end) { - getClient(key).substr(key, start, end); - return getResponse(BuilderFactory.STRING); + getClient(key).substr(key, start, end); + return getResponse(BuilderFactory.STRING); } public Response ttl(String key) { - getClient(key).ttl(key); - return getResponse(BuilderFactory.LONG); + getClient(key).ttl(key); + return getResponse(BuilderFactory.LONG); } public Response ttl(byte[] key) { - getClient(key).ttl(key); - return getResponse(BuilderFactory.LONG); + getClient(key).ttl(key); + return getResponse(BuilderFactory.LONG); } public Response type(String key) { - getClient(key).type(key); - return getResponse(BuilderFactory.STRING); + getClient(key).type(key); + return getResponse(BuilderFactory.STRING); } public Response type(byte[] key) { - getClient(key).type(key); - return getResponse(BuilderFactory.STRING); + getClient(key).type(key); + return getResponse(BuilderFactory.STRING); } public Response zadd(String key, double score, String member) { - getClient(key).zadd(key, score, member); - return getResponse(BuilderFactory.LONG); + getClient(key).zadd(key, score, member); + return getResponse(BuilderFactory.LONG); } public Response zadd(String key, Map scoreMembers) { - getClient(key).zadd(key, scoreMembers); - return getResponse(BuilderFactory.LONG); + getClient(key).zadd(key, scoreMembers); + return getResponse(BuilderFactory.LONG); } public Response zadd(byte[] key, double score, byte[] member) { - getClient(key).zadd(key, score, member); - return getResponse(BuilderFactory.LONG); + getClient(key).zadd(key, score, member); + return getResponse(BuilderFactory.LONG); } public Response zcard(String key) { - getClient(key).zcard(key); - return getResponse(BuilderFactory.LONG); + getClient(key).zcard(key); + return getResponse(BuilderFactory.LONG); } public Response zcard(byte[] key) { - getClient(key).zcard(key); - return getResponse(BuilderFactory.LONG); + getClient(key).zcard(key); + return getResponse(BuilderFactory.LONG); } public Response zcount(String key, double min, double max) { - getClient(key).zcount(key, min, max); - return getResponse(BuilderFactory.LONG); + getClient(key).zcount(key, min, max); + return getResponse(BuilderFactory.LONG); } public Response zcount(String key, String min, String max) { - getClient(key).zcount(key, min, max); - return getResponse(BuilderFactory.LONG); + getClient(key).zcount(key, min, max); + return getResponse(BuilderFactory.LONG); } public Response zcount(byte[] key, double min, double max) { - getClient(key).zcount(key, toByteArray(min), toByteArray(max)); - return getResponse(BuilderFactory.LONG); + getClient(key).zcount(key, toByteArray(min), toByteArray(max)); + return getResponse(BuilderFactory.LONG); } public Response zincrby(String key, double score, String member) { - getClient(key).zincrby(key, score, member); - return getResponse(BuilderFactory.DOUBLE); + getClient(key).zincrby(key, score, member); + return getResponse(BuilderFactory.DOUBLE); } public Response zincrby(byte[] key, double score, byte[] member) { - getClient(key).zincrby(key, score, member); - return getResponse(BuilderFactory.DOUBLE); + getClient(key).zincrby(key, score, member); + return getResponse(BuilderFactory.DOUBLE); } public Response> zrange(String key, long start, long end) { - getClient(key).zrange(key, start, end); - return getResponse(BuilderFactory.STRING_ZSET); + getClient(key).zrange(key, start, end); + return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrange(byte[] key, long start, long end) { - getClient(key).zrange(key, start, end); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + getClient(key).zrange(key, start, end); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrangeByScore(String key, double min, - double max) { - getClient(key).zrangeByScore(key, min, max); - return getResponse(BuilderFactory.STRING_ZSET); + double max) { + getClient(key).zrangeByScore(key, min, max); + return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrangeByScore(byte[] key, double min, - double max) { - return zrangeByScore(key, toByteArray(min), toByteArray(max)); + double max) { + return zrangeByScore(key, toByteArray(min), toByteArray(max)); } public Response> zrangeByScore(String key, String min, - String max) { - getClient(key).zrangeByScore(key, min, max); - return getResponse(BuilderFactory.STRING_ZSET); + String max) { + getClient(key).zrangeByScore(key, min, max); + return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrangeByScore(byte[] key, byte[] min, - byte[] max) { - getClient(key).zrangeByScore(key, min, max); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + byte[] max) { + getClient(key).zrangeByScore(key, min, max); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrangeByScore(String key, double min, - double max, int offset, int count) { - getClient(key).zrangeByScore(key, min, max, offset, count); - return getResponse(BuilderFactory.STRING_ZSET); + double max, int offset, int count) { + getClient(key).zrangeByScore(key, min, max, offset, count); + return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrangeByScore(String key, String min, - String max, int offset, int count) { - getClient(key).zrangeByScore(key, min, max, offset, count); - return getResponse(BuilderFactory.STRING_ZSET); + String max, int offset, int count) { + getClient(key).zrangeByScore(key, min, max, offset, count); + return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrangeByScore(byte[] key, double min, - double max, int offset, int count) { - return zrangeByScore(key, toByteArray(min), toByteArray(max), offset, - count); + double max, int offset, int count) { + return zrangeByScore(key, toByteArray(min), toByteArray(max), offset, + count); } public Response> zrangeByScore(byte[] key, byte[] min, - byte[] max, int offset, int count) { - getClient(key).zrangeByScore(key, min, max, offset, count); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + byte[] max, int offset, int count) { + getClient(key).zrangeByScore(key, min, max, offset, count); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrangeByScoreWithScores(String key, double min, - double max) { - getClient(key).zrangeByScoreWithScores(key, min, max); - return getResponse(BuilderFactory.TUPLE_ZSET); + double max) { + getClient(key).zrangeByScoreWithScores(key, min, max); + return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrangeByScoreWithScores(String key, String min, - String max) { - getClient(key).zrangeByScoreWithScores(key, min, max); - return getResponse(BuilderFactory.TUPLE_ZSET); + String max) { + getClient(key).zrangeByScoreWithScores(key, min, max); + return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrangeByScoreWithScores(byte[] key, double min, - double max) { - return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max)); + double max) { + return zrangeByScoreWithScores(key, toByteArray(min), toByteArray(max)); } public Response> zrangeByScoreWithScores(byte[] key, byte[] min, - byte[] max) { - getClient(key).zrangeByScoreWithScores(key, min, max); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); + byte[] max) { + getClient(key).zrangeByScoreWithScores(key, min, max); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrangeByScoreWithScores(String key, double min, - double max, int offset, int count) { - getClient(key).zrangeByScoreWithScores(key, min, max, offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET); + double max, int offset, int count) { + getClient(key).zrangeByScoreWithScores(key, min, max, offset, count); + return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrangeByScoreWithScores(String key, String min, - String max, int offset, int count) { - getClient(key).zrangeByScoreWithScores(key, min, max, offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET); + String max, int offset, int count) { + getClient(key).zrangeByScoreWithScores(key, min, max, offset, count); + return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrangeByScoreWithScores(byte[] key, double min, - double max, int offset, int count) { - getClient(key).zrangeByScoreWithScores(key, toByteArray(min), - toByteArray(max), offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); + double max, int offset, int count) { + getClient(key).zrangeByScoreWithScores(key, toByteArray(min), + toByteArray(max), offset, count); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrangeByScoreWithScores(byte[] key, byte[] min, - byte[] max, int offset, int count) { - getClient(key).zrangeByScoreWithScores(key, min, max, offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); + byte[] max, int offset, int count) { + getClient(key).zrangeByScoreWithScores(key, min, max, offset, count); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrevrangeByScore(String key, double max, - double min) { - getClient(key).zrevrangeByScore(key, max, min); - return getResponse(BuilderFactory.STRING_ZSET); + double min) { + getClient(key).zrevrangeByScore(key, max, min); + return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrevrangeByScore(byte[] key, double max, - double min) { - getClient(key) - .zrevrangeByScore(key, toByteArray(max), toByteArray(min)); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + double min) { + getClient(key) + .zrevrangeByScore(key, toByteArray(max), toByteArray(min)); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrevrangeByScore(String key, String max, - String min) { - getClient(key).zrevrangeByScore(key, max, min); - return getResponse(BuilderFactory.STRING_ZSET); + String min) { + getClient(key).zrevrangeByScore(key, max, min); + return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrevrangeByScore(byte[] key, byte[] max, - byte[] min) { - getClient(key).zrevrangeByScore(key, max, min); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + byte[] min) { + getClient(key).zrevrangeByScore(key, max, min); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrevrangeByScore(String key, double max, - double min, int offset, int count) { - getClient(key).zrevrangeByScore(key, max, min, offset, count); - return getResponse(BuilderFactory.STRING_ZSET); + double min, int offset, int count) { + getClient(key).zrevrangeByScore(key, max, min, offset, count); + return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrevrangeByScore(String key, String max, - String min, int offset, int count) { - getClient(key).zrevrangeByScore(key, max, min, offset, count); - return getResponse(BuilderFactory.STRING_ZSET); + String min, int offset, int count) { + getClient(key).zrevrangeByScore(key, max, min, offset, count); + return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrevrangeByScore(byte[] key, double max, - double min, int offset, int count) { - getClient(key).zrevrangeByScore(key, toByteArray(max), - toByteArray(min), offset, count); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + double min, int offset, int count) { + getClient(key).zrevrangeByScore(key, toByteArray(max), + toByteArray(min), offset, count); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrevrangeByScore(byte[] key, byte[] max, - byte[] min, int offset, int count) { - getClient(key).zrevrangeByScore(key, max, min, offset, count); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + byte[] min, int offset, int count) { + getClient(key).zrevrangeByScore(key, max, min, offset, count); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrevrangeByScoreWithScores(String key, - double max, double min) { - getClient(key).zrevrangeByScoreWithScores(key, max, min); - return getResponse(BuilderFactory.TUPLE_ZSET); + double max, double min) { + getClient(key).zrevrangeByScoreWithScores(key, max, min); + return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrevrangeByScoreWithScores(String key, - String max, String min) { - getClient(key).zrevrangeByScoreWithScores(key, max, min); - return getResponse(BuilderFactory.TUPLE_ZSET); + String max, String min) { + getClient(key).zrevrangeByScoreWithScores(key, max, min); + return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrevrangeByScoreWithScores(byte[] key, - double max, double min) { - getClient(key).zrevrangeByScoreWithScores(key, toByteArray(max), - toByteArray(min)); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); + double max, double min) { + getClient(key).zrevrangeByScoreWithScores(key, toByteArray(max), + toByteArray(min)); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrevrangeByScoreWithScores(byte[] key, - byte[] max, byte[] min) { - getClient(key).zrevrangeByScoreWithScores(key, max, min); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); + byte[] max, byte[] min) { + getClient(key).zrevrangeByScoreWithScores(key, max, min); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrevrangeByScoreWithScores(String key, - double max, double min, int offset, int count) { - getClient(key).zrevrangeByScoreWithScores(key, max, min, offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET); + double max, double min, int offset, int count) { + getClient(key).zrevrangeByScoreWithScores(key, max, min, offset, count); + return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrevrangeByScoreWithScores(String key, - String max, String min, int offset, int count) { - getClient(key).zrevrangeByScoreWithScores(key, max, min, offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET); + String max, String min, int offset, int count) { + getClient(key).zrevrangeByScoreWithScores(key, max, min, offset, count); + return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrevrangeByScoreWithScores(byte[] key, - double max, double min, int offset, int count) { - getClient(key).zrevrangeByScoreWithScores(key, toByteArray(max), - toByteArray(min), offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); + double max, double min, int offset, int count) { + getClient(key).zrevrangeByScoreWithScores(key, toByteArray(max), + toByteArray(min), offset, count); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrevrangeByScoreWithScores(byte[] key, - byte[] max, byte[] min, int offset, int count) { - getClient(key).zrevrangeByScoreWithScores(key, max, min, offset, count); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); + byte[] max, byte[] min, int offset, int count) { + getClient(key).zrevrangeByScoreWithScores(key, max, min, offset, count); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response> zrangeWithScores(String key, long start, - long end) { - getClient(key).zrangeWithScores(key, start, end); - return getResponse(BuilderFactory.TUPLE_ZSET); + long end) { + getClient(key).zrangeWithScores(key, start, end); + return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrangeWithScores(byte[] key, long start, - long end) { - getClient(key).zrangeWithScores(key, start, end); - return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); + long end) { + getClient(key).zrangeWithScores(key, start, end); + return getResponse(BuilderFactory.TUPLE_ZSET_BINARY); } public Response zrank(String key, String member) { - getClient(key).zrank(key, member); - return getResponse(BuilderFactory.LONG); + getClient(key).zrank(key, member); + return getResponse(BuilderFactory.LONG); } public Response zrank(byte[] key, byte[] member) { - getClient(key).zrank(key, member); - return getResponse(BuilderFactory.LONG); + getClient(key).zrank(key, member); + return getResponse(BuilderFactory.LONG); } public Response zrem(String key, String... member) { - getClient(key).zrem(key, member); - return getResponse(BuilderFactory.LONG); + getClient(key).zrem(key, member); + return getResponse(BuilderFactory.LONG); } public Response zrem(byte[] key, byte[]... member) { - getClient(key).zrem(key, member); - return getResponse(BuilderFactory.LONG); + getClient(key).zrem(key, member); + return getResponse(BuilderFactory.LONG); } public Response zremrangeByRank(String key, long start, long end) { - getClient(key).zremrangeByRank(key, start, end); - return getResponse(BuilderFactory.LONG); + getClient(key).zremrangeByRank(key, start, end); + return getResponse(BuilderFactory.LONG); } public Response zremrangeByRank(byte[] key, long start, long end) { - getClient(key).zremrangeByRank(key, start, end); - return getResponse(BuilderFactory.LONG); + getClient(key).zremrangeByRank(key, start, end); + return getResponse(BuilderFactory.LONG); } public Response zremrangeByScore(String key, double start, double end) { - getClient(key).zremrangeByScore(key, start, end); - return getResponse(BuilderFactory.LONG); + getClient(key).zremrangeByScore(key, start, end); + return getResponse(BuilderFactory.LONG); } public Response zremrangeByScore(String key, String start, String end) { - getClient(key).zremrangeByScore(key, start, end); - return getResponse(BuilderFactory.LONG); + getClient(key).zremrangeByScore(key, start, end); + return getResponse(BuilderFactory.LONG); } public Response zremrangeByScore(byte[] key, double start, double end) { - getClient(key).zremrangeByScore(key, toByteArray(start), - toByteArray(end)); - return getResponse(BuilderFactory.LONG); + getClient(key).zremrangeByScore(key, toByteArray(start), + toByteArray(end)); + return getResponse(BuilderFactory.LONG); } public Response zremrangeByScore(byte[] key, byte[] start, byte[] end) { - getClient(key).zremrangeByScore(key, start, end); - return getResponse(BuilderFactory.LONG); + getClient(key).zremrangeByScore(key, start, end); + return getResponse(BuilderFactory.LONG); } public Response> zrevrange(String key, long start, long end) { - getClient(key).zrevrange(key, start, end); - return getResponse(BuilderFactory.STRING_ZSET); + getClient(key).zrevrange(key, start, end); + return getResponse(BuilderFactory.STRING_ZSET); } public Response> zrevrange(byte[] key, long start, long end) { - getClient(key).zrevrange(key, start, end); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + getClient(key).zrevrange(key, start, end); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } public Response> zrevrangeWithScores(String key, long start, - long end) { - getClient(key).zrevrangeWithScores(key, start, end); - return getResponse(BuilderFactory.TUPLE_ZSET); + long end) { + getClient(key).zrevrangeWithScores(key, start, end); + return getResponse(BuilderFactory.TUPLE_ZSET); } public Response> zrevrangeWithScores(byte[] key, long start, - long end) { - getClient(key).zrevrangeWithScores(key, start, end); - return getResponse(BuilderFactory.TUPLE_ZSET); + long end) { + getClient(key).zrevrangeWithScores(key, start, end); + return getResponse(BuilderFactory.TUPLE_ZSET); } public Response zrevrank(String key, String member) { - getClient(key).zrevrank(key, member); - return getResponse(BuilderFactory.LONG); + getClient(key).zrevrank(key, member); + return getResponse(BuilderFactory.LONG); } public Response zrevrank(byte[] key, byte[] member) { - getClient(key).zrevrank(key, member); - return getResponse(BuilderFactory.LONG); + getClient(key).zrevrank(key, member); + return getResponse(BuilderFactory.LONG); } public Response zscore(String key, String member) { - getClient(key).zscore(key, member); - return getResponse(BuilderFactory.DOUBLE); + getClient(key).zscore(key, member); + return getResponse(BuilderFactory.DOUBLE); } public Response zscore(byte[] key, byte[] member) { - getClient(key).zscore(key, member); - return getResponse(BuilderFactory.DOUBLE); + getClient(key).zscore(key, member); + return getResponse(BuilderFactory.DOUBLE); } @Override public Response zlexcount(final byte[] key, final byte[] min, - final byte[] max) { - getClient(key).zlexcount(key, min, max); - return getResponse(BuilderFactory.LONG); + final byte[] max) { + getClient(key).zlexcount(key, min, max); + return getResponse(BuilderFactory.LONG); } @Override public Response zlexcount(final String key, final String min, - final String max) { - getClient(key).zlexcount(key, min, max); - return getResponse(BuilderFactory.LONG); + final String max) { + getClient(key).zlexcount(key, min, max); + return getResponse(BuilderFactory.LONG); } @Override public Response> zrangeByLex(final byte[] key, - final byte[] min, final byte[] max) { - getClient(key).zrangeByLex(key, min, max); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + final byte[] min, final byte[] max) { + getClient(key).zrangeByLex(key, min, max); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } @Override public Response> zrangeByLex(final String key, - final String min, final String max) { - getClient(key).zrangeByLex(key, min, max); - return getResponse(BuilderFactory.STRING_ZSET); + final String min, final String max) { + getClient(key).zrangeByLex(key, min, max); + return getResponse(BuilderFactory.STRING_ZSET); } @Override public Response> 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); + 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> 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); + 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> zrevrangeByLex(final byte[] key, - final byte[] max, final byte[] min) { - getClient(key).zrevrangeByLex(key, max, min); - return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); + final byte[] max, final byte[] min) { + getClient(key).zrevrangeByLex(key, max, min); + return getResponse(BuilderFactory.BYTE_ARRAY_ZSET); } @Override public Response> zrevrangeByLex(final String key, - final String max, final String min) { - getClient(key).zrevrangeByLex(key, max, min); - return getResponse(BuilderFactory.STRING_ZSET); + final String max, final String min) { + getClient(key).zrevrangeByLex(key, max, min); + return getResponse(BuilderFactory.STRING_ZSET); } @Override public Response> 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); + 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> 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); + 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 zremrangeByLex(final byte[] key, final byte[] min, - final byte[] max) { - getClient(key).zremrangeByLex(key, min, max); - return getResponse(BuilderFactory.LONG); + final byte[] max) { + getClient(key).zremrangeByLex(key, min, max); + return getResponse(BuilderFactory.LONG); } @Override public Response zremrangeByLex(final String key, final String min, - final String max) { - getClient(key).zremrangeByLex(key, min, max); - return getResponse(BuilderFactory.LONG); + final String max) { + getClient(key).zremrangeByLex(key, min, max); + return getResponse(BuilderFactory.LONG); } public Response bitcount(String key) { - getClient(key).bitcount(key); - return getResponse(BuilderFactory.LONG); + getClient(key).bitcount(key); + return getResponse(BuilderFactory.LONG); } public Response bitcount(String key, long start, long end) { - getClient(key).bitcount(key, start, end); - return getResponse(BuilderFactory.LONG); + getClient(key).bitcount(key, start, end); + return getResponse(BuilderFactory.LONG); } public Response bitcount(byte[] key) { - getClient(key).bitcount(key); - return getResponse(BuilderFactory.LONG); + getClient(key).bitcount(key); + return getResponse(BuilderFactory.LONG); } public Response bitcount(byte[] key, long start, long end) { - getClient(key).bitcount(key, start, end); - return getResponse(BuilderFactory.LONG); + getClient(key).bitcount(key, start, end); + return getResponse(BuilderFactory.LONG); } public Response dump(String key) { - getClient(key).dump(key); - return getResponse(BuilderFactory.BYTE_ARRAY); + getClient(key).dump(key); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response dump(byte[] key) { - getClient(key).dump(key); - return getResponse(BuilderFactory.BYTE_ARRAY); + getClient(key).dump(key); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response migrate(String host, int port, String key, - int destinationDb, int timeout) { - getClient(key).migrate(host, port, key, destinationDb, timeout); - return getResponse(BuilderFactory.STRING); + int destinationDb, int timeout) { + getClient(key).migrate(host, port, key, destinationDb, timeout); + return getResponse(BuilderFactory.STRING); } public Response migrate(byte[] host, int port, byte[] key, - int destinationDb, int timeout) { - getClient(key).migrate(host, port, key, destinationDb, timeout); - return getResponse(BuilderFactory.STRING); + int destinationDb, int timeout) { + getClient(key).migrate(host, port, key, destinationDb, timeout); + return getResponse(BuilderFactory.STRING); } public Response objectRefcount(String key) { - getClient(key).objectRefcount(key); - return getResponse(BuilderFactory.LONG); + getClient(key).objectRefcount(key); + return getResponse(BuilderFactory.LONG); } public Response objectRefcount(byte[] key) { - getClient(key).objectRefcount(key); - return getResponse(BuilderFactory.LONG); + getClient(key).objectRefcount(key); + return getResponse(BuilderFactory.LONG); } public Response objectEncoding(String key) { - getClient(key).objectEncoding(key); - return getResponse(BuilderFactory.STRING); + getClient(key).objectEncoding(key); + return getResponse(BuilderFactory.STRING); } public Response objectEncoding(byte[] key) { - getClient(key).objectEncoding(key); - return getResponse(BuilderFactory.BYTE_ARRAY); + getClient(key).objectEncoding(key); + return getResponse(BuilderFactory.BYTE_ARRAY); } public Response objectIdletime(String key) { - getClient(key).objectIdletime(key); - return getResponse(BuilderFactory.LONG); + getClient(key).objectIdletime(key); + return getResponse(BuilderFactory.LONG); } public Response objectIdletime(byte[] key) { - getClient(key).objectIdletime(key); - return getResponse(BuilderFactory.LONG); + getClient(key).objectIdletime(key); + return getResponse(BuilderFactory.LONG); } public Response pexpire(String key, long milliseconds) { - getClient(key).pexpire(key, milliseconds); - return getResponse(BuilderFactory.LONG); + getClient(key).pexpire(key, milliseconds); + return getResponse(BuilderFactory.LONG); } public Response pexpire(byte[] key, long milliseconds) { - getClient(key).pexpire(key, milliseconds); - return getResponse(BuilderFactory.LONG); + getClient(key).pexpire(key, milliseconds); + return getResponse(BuilderFactory.LONG); } public Response pexpireAt(String key, long millisecondsTimestamp) { - getClient(key).pexpireAt(key, millisecondsTimestamp); - return getResponse(BuilderFactory.LONG); + getClient(key).pexpireAt(key, millisecondsTimestamp); + return getResponse(BuilderFactory.LONG); } public Response pexpireAt(byte[] key, long millisecondsTimestamp) { - getClient(key).pexpireAt(key, millisecondsTimestamp); - return getResponse(BuilderFactory.LONG); + getClient(key).pexpireAt(key, millisecondsTimestamp); + return getResponse(BuilderFactory.LONG); } public Response pttl(String key) { - getClient(key).pttl(key); - return getResponse(BuilderFactory.LONG); + getClient(key).pttl(key); + return getResponse(BuilderFactory.LONG); } public Response pttl(byte[] key) { - getClient(key).pttl(key); - return getResponse(BuilderFactory.LONG); + getClient(key).pttl(key); + return getResponse(BuilderFactory.LONG); } public Response restore(String key, int ttl, byte[] serializedValue) { - getClient(key).restore(key, ttl, serializedValue); - return getResponse(BuilderFactory.STRING); + getClient(key).restore(key, ttl, serializedValue); + return getResponse(BuilderFactory.STRING); } public Response restore(byte[] key, int ttl, byte[] serializedValue) { - getClient(key).restore(key, ttl, serializedValue); - return getResponse(BuilderFactory.STRING); + getClient(key).restore(key, ttl, serializedValue); + return getResponse(BuilderFactory.STRING); } public Response incrByFloat(String key, double increment) { - getClient(key).incrByFloat(key, increment); - return getResponse(BuilderFactory.DOUBLE); + getClient(key).incrByFloat(key, increment); + return getResponse(BuilderFactory.DOUBLE); } public Response incrByFloat(byte[] key, double increment) { - getClient(key).incrByFloat(key, increment); - return getResponse(BuilderFactory.DOUBLE); + getClient(key).incrByFloat(key, increment); + return getResponse(BuilderFactory.DOUBLE); } public Response psetex(String key, int milliseconds, String value) { - getClient(key).psetex(key, milliseconds, value); - return getResponse(BuilderFactory.STRING); + getClient(key).psetex(key, milliseconds, value); + return getResponse(BuilderFactory.STRING); } public Response psetex(byte[] key, int milliseconds, byte[] value) { - getClient(key).psetex(key, milliseconds, value); - return getResponse(BuilderFactory.STRING); + getClient(key).psetex(key, milliseconds, value); + return getResponse(BuilderFactory.STRING); } public Response set(String key, String value, String nxxx) { - getClient(key).set(key, value, nxxx); - return getResponse(BuilderFactory.STRING); + getClient(key).set(key, value, nxxx); + return getResponse(BuilderFactory.STRING); } public Response set(byte[] key, byte[] value, byte[] nxxx) { - getClient(key).set(key, value, nxxx); - return getResponse(BuilderFactory.STRING); + getClient(key).set(key, value, nxxx); + return getResponse(BuilderFactory.STRING); } public Response set(String key, String value, String nxxx, - String expx, int time) { - getClient(key).set(key, value, nxxx, expx, time); - return getResponse(BuilderFactory.STRING); + String expx, int time) { + getClient(key).set(key, value, nxxx, expx, time); + return getResponse(BuilderFactory.STRING); } public Response set(byte[] key, byte[] value, byte[] nxxx, - byte[] expx, int time) { - getClient(key).set(key, value, nxxx, expx, time); - return getResponse(BuilderFactory.STRING); + byte[] expx, int time) { + getClient(key).set(key, value, nxxx, expx, time); + return getResponse(BuilderFactory.STRING); } public Response hincrByFloat(String key, String field, - double increment) { - getClient(key).hincrByFloat(key, field, increment); - return getResponse(BuilderFactory.DOUBLE); + double increment) { + getClient(key).hincrByFloat(key, field, increment); + return getResponse(BuilderFactory.DOUBLE); } public Response hincrByFloat(byte[] key, byte[] field, - double increment) { - getClient(key).hincrByFloat(key, field, increment); - return getResponse(BuilderFactory.DOUBLE); + double increment) { + getClient(key).hincrByFloat(key, field, increment); + return getResponse(BuilderFactory.DOUBLE); } public Response eval(String script) { - return this.eval(script, 0, new String[0]); + return this.eval(script, 0, new String[0]); } public Response eval(String script, List keys, - List args) { - String[] argv = Jedis.getParams(keys, args); - return this.eval(script, keys.size(), argv); + List args) { + String[] argv = Jedis.getParams(keys, args); + return this.eval(script, keys.size(), argv); } public Response eval(String script, int numKeys, String[] argv) { - getClient(script).eval(script, numKeys, argv); - return getResponse(BuilderFactory.STRING); + getClient(script).eval(script, numKeys, argv); + return getResponse(BuilderFactory.STRING); } public Response evalsha(String script) { - return this.evalsha(script, 0, new String[0]); + return this.evalsha(script, 0, new String[0]); } public Response evalsha(String sha1, List keys, - List args) { - String[] argv = Jedis.getParams(keys, args); - return this.evalsha(sha1, keys.size(), argv); + List args) { + String[] argv = Jedis.getParams(keys, args); + return this.evalsha(sha1, keys.size(), argv); } public Response evalsha(String sha1, int numKeys, String[] argv) { - getClient(sha1).evalsha(sha1, numKeys, argv); - return getResponse(BuilderFactory.STRING); + getClient(sha1).evalsha(sha1, numKeys, argv); + return getResponse(BuilderFactory.STRING); } @Override public Response pfadd(byte[] key, byte[]... elements) { - getClient(key).pfadd(key, elements); - return getResponse(BuilderFactory.LONG); + getClient(key).pfadd(key, elements); + return getResponse(BuilderFactory.LONG); } @Override public Response pfcount(byte[] key) { - getClient(key).pfcount(key); - return getResponse(BuilderFactory.LONG); + getClient(key).pfcount(key); + return getResponse(BuilderFactory.LONG); } @Override public Response pfadd(String key, String... elements) { - getClient(key).pfadd(key, elements); - return getResponse(BuilderFactory.LONG); + getClient(key).pfadd(key, elements); + return getResponse(BuilderFactory.LONG); } @Override public Response pfcount(String key) { - getClient(key).pfcount(key); - return getResponse(BuilderFactory.LONG); + getClient(key).pfcount(key); + return getResponse(BuilderFactory.LONG); } } diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index 2641313..4b323dc 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -67,168 +67,168 @@ public final class Protocol { public static final String PUBSUB_NUM_PAT = "numpat"; private Protocol() { - // this prevent the class from instantiation + // this prevent the class from instantiation } public static void sendCommand(final RedisOutputStream os, - final Command command, final byte[]... args) { - sendCommand(os, command.raw, args); + final Command command, final byte[]... args) { + sendCommand(os, command.raw, args); } private static void sendCommand(final RedisOutputStream os, - final byte[] command, final byte[]... args) { - try { - os.write(ASTERISK_BYTE); - os.writeIntCrLf(args.length + 1); - os.write(DOLLAR_BYTE); - os.writeIntCrLf(command.length); - os.write(command); - os.writeCrLf(); + final byte[] command, final byte[]... args) { + try { + os.write(ASTERISK_BYTE); + os.writeIntCrLf(args.length + 1); + os.write(DOLLAR_BYTE); + os.writeIntCrLf(command.length); + os.write(command); + os.writeCrLf(); - for (final byte[] arg : args) { - os.write(DOLLAR_BYTE); - os.writeIntCrLf(arg.length); - os.write(arg); - os.writeCrLf(); - } - } catch (IOException e) { - throw new JedisConnectionException(e); - } + for (final byte[] arg : args) { + os.write(DOLLAR_BYTE); + os.writeIntCrLf(arg.length); + os.write(arg); + os.writeCrLf(); + } + } catch (IOException e) { + throw new JedisConnectionException(e); + } } private static void processError(final RedisInputStream is) { - String message = is.readLine(); - // TODO: I'm not sure if this is the best way to do this. - // Maybe Read only first 5 bytes instead? - if (message.startsWith(MOVED_RESPONSE)) { - String[] movedInfo = parseTargetHostAndSlot(message); - throw new JedisMovedDataException(message, new HostAndPort( - movedInfo[1], Integer.valueOf(movedInfo[2])), - Integer.valueOf(movedInfo[0])); - } else if (message.startsWith(ASK_RESPONSE)) { - String[] askInfo = parseTargetHostAndSlot(message); - throw new JedisAskDataException(message, new HostAndPort( - askInfo[1], Integer.valueOf(askInfo[2])), - Integer.valueOf(askInfo[0])); - } else if (message.startsWith(CLUSTERDOWN_RESPONSE)) { - throw new JedisClusterException(message); - } - throw new JedisDataException(message); + String message = is.readLine(); + // TODO: I'm not sure if this is the best way to do this. + // Maybe Read only first 5 bytes instead? + if (message.startsWith(MOVED_RESPONSE)) { + String[] movedInfo = parseTargetHostAndSlot(message); + throw new JedisMovedDataException(message, new HostAndPort( + movedInfo[1], Integer.valueOf(movedInfo[2])), + Integer.valueOf(movedInfo[0])); + } else if (message.startsWith(ASK_RESPONSE)) { + String[] askInfo = parseTargetHostAndSlot(message); + throw new JedisAskDataException(message, new HostAndPort( + askInfo[1], Integer.valueOf(askInfo[2])), + Integer.valueOf(askInfo[0])); + } else if (message.startsWith(CLUSTERDOWN_RESPONSE)) { + throw new JedisClusterException(message); + } + throw new JedisDataException(message); } private static String[] parseTargetHostAndSlot( - String clusterRedirectResponse) { - String[] response = new String[3]; - String[] messageInfo = clusterRedirectResponse.split(" "); - String[] targetHostAndPort = messageInfo[2].split(":"); - response[0] = messageInfo[1]; - response[1] = targetHostAndPort[0]; - response[2] = targetHostAndPort[1]; - return response; + String clusterRedirectResponse) { + String[] response = new String[3]; + String[] messageInfo = clusterRedirectResponse.split(" "); + String[] targetHostAndPort = messageInfo[2].split(":"); + response[0] = messageInfo[1]; + response[1] = targetHostAndPort[0]; + response[2] = targetHostAndPort[1]; + return response; } private static Object process(final RedisInputStream is) { - final byte b = is.readByte(); - if (b == PLUS_BYTE) { - return processStatusCodeReply(is); - } else if (b == DOLLAR_BYTE) { - return processBulkReply(is); - } else if (b == ASTERISK_BYTE) { - return processMultiBulkReply(is); - } else if (b == COLON_BYTE) { - return processInteger(is); - } else if (b == MINUS_BYTE) { - processError(is); - return null; - } else { - throw new JedisConnectionException("Unknown reply: " + (char) b); - } + final byte b = is.readByte(); + if (b == PLUS_BYTE) { + return processStatusCodeReply(is); + } else if (b == DOLLAR_BYTE) { + return processBulkReply(is); + } else if (b == ASTERISK_BYTE) { + return processMultiBulkReply(is); + } else if (b == COLON_BYTE) { + return processInteger(is); + } else if (b == MINUS_BYTE) { + processError(is); + return null; + } else { + throw new JedisConnectionException("Unknown reply: " + (char) b); + } } private static byte[] processStatusCodeReply(final RedisInputStream is) { - return is.readLineBytes(); + return is.readLineBytes(); } private static byte[] processBulkReply(final RedisInputStream is) { - final int len = is.readIntCrLf(); - if (len == -1) { - return null; - } + final int len = is.readIntCrLf(); + if (len == -1) { + return null; + } - final byte[] read = new byte[len]; - int offset = 0; - while (offset < len) { - final int size = is.read(read, offset, (len - offset)); - if (size == -1) - throw new JedisConnectionException( - "It seems like server has closed the connection."); - offset += size; - } + final byte[] read = new byte[len]; + int offset = 0; + while (offset < len) { + final int size = is.read(read, offset, (len - offset)); + if (size == -1) + throw new JedisConnectionException( + "It seems like server has closed the connection."); + offset += size; + } - // read 2 more bytes for the command delimiter - is.readByte(); - is.readByte(); + // read 2 more bytes for the command delimiter + is.readByte(); + is.readByte(); - return read; + return read; } private static Long processInteger(final RedisInputStream is) { - return is.readLongCrLf(); + return is.readLongCrLf(); } private static List processMultiBulkReply(final RedisInputStream is) { - final int num = is.readIntCrLf(); - if (num == -1) { - return null; - } - final List ret = new ArrayList(num); - for (int i = 0; i < num; i++) { - try { - ret.add(process(is)); - } catch (JedisDataException e) { - ret.add(e); - } - } - return ret; + final int num = is.readIntCrLf(); + if (num == -1) { + return null; + } + final List ret = new ArrayList(num); + for (int i = 0; i < num; i++) { + try { + ret.add(process(is)); + } catch (JedisDataException e) { + ret.add(e); + } + } + return ret; } public static Object read(final RedisInputStream is) { - return process(is); + return process(is); } public static final byte[] toByteArray(final boolean value) { - return toByteArray(value ? 1 : 0); + return toByteArray(value ? 1 : 0); } public static final byte[] toByteArray(final int value) { - return SafeEncoder.encode(String.valueOf(value)); + return SafeEncoder.encode(String.valueOf(value)); } public static final byte[] toByteArray(final long value) { - return SafeEncoder.encode(String.valueOf(value)); + return SafeEncoder.encode(String.valueOf(value)); } public static final byte[] toByteArray(final double value) { - return SafeEncoder.encode(String.valueOf(value)); + return SafeEncoder.encode(String.valueOf(value)); } public static enum Command { - PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, PUBSUB, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, ZLEXCOUNT, ZRANGEBYLEX, ZREVRANGEBYLEX, ZREMRANGEBYLEX, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, BITPOS, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, SENTINEL, DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL, INCRBYFLOAT, PSETEX, CLIENT, TIME, MIGRATE, HINCRBYFLOAT, SCAN, HSCAN, SSCAN, ZSCAN, WAIT, CLUSTER, ASKING, PFADD, PFCOUNT, PFMERGE; + PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, PUBSUB, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, ZLEXCOUNT, ZRANGEBYLEX, ZREVRANGEBYLEX, ZREMRANGEBYLEX, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, BITPOS, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, SENTINEL, DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL, INCRBYFLOAT, PSETEX, CLIENT, TIME, MIGRATE, HINCRBYFLOAT, SCAN, HSCAN, SSCAN, ZSCAN, WAIT, CLUSTER, ASKING, PFADD, PFCOUNT, PFMERGE; - public final byte[] raw; + public final byte[] raw; - Command() { - raw = SafeEncoder.encode(this.name()); - } + Command() { + raw = SafeEncoder.encode(this.name()); + } } public static enum Keyword { - AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT, RESET, FLUSH, EXISTS, LOAD, KILL, LEN, REFCOUNT, ENCODING, IDLETIME, AND, OR, XOR, NOT, GETNAME, SETNAME, LIST, MATCH, COUNT; - public final byte[] raw; + AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT, RESET, FLUSH, EXISTS, LOAD, KILL, LEN, REFCOUNT, ENCODING, IDLETIME, AND, OR, XOR, NOT, GETNAME, SETNAME, LIST, MATCH, COUNT; + public final byte[] raw; - Keyword() { - raw = SafeEncoder.encode(this.name().toLowerCase()); - } + Keyword() { + raw = SafeEncoder.encode(this.name().toLowerCase()); + } } } diff --git a/src/main/java/redis/clients/jedis/Queable.java b/src/main/java/redis/clients/jedis/Queable.java index 2cd5265..bf827a8 100644 --- a/src/main/java/redis/clients/jedis/Queable.java +++ b/src/main/java/redis/clients/jedis/Queable.java @@ -7,28 +7,28 @@ public class Queable { private Queue> pipelinedResponses = new LinkedList>(); protected void clean() { - pipelinedResponses.clear(); + pipelinedResponses.clear(); } protected Response generateResponse(Object data) { - Response response = pipelinedResponses.poll(); - if (response != null) { - response.set(data); - } - return response; + Response response = pipelinedResponses.poll(); + if (response != null) { + response.set(data); + } + return response; } protected Response getResponse(Builder builder) { - Response lr = new Response(builder); - pipelinedResponses.add(lr); - return lr; + Response lr = new Response(builder); + pipelinedResponses.add(lr); + return lr; } protected boolean hasPipelinedResponse() { - return pipelinedResponses.size() > 0; + return pipelinedResponses.size() > 0; } protected int getPipelinedResponseLength() { - return pipelinedResponses.size(); + return pipelinedResponses.size(); } } diff --git a/src/main/java/redis/clients/jedis/RedisPipeline.java b/src/main/java/redis/clients/jedis/RedisPipeline.java index 6b2cd5d..c3d5acc 100644 --- a/src/main/java/redis/clients/jedis/RedisPipeline.java +++ b/src/main/java/redis/clients/jedis/RedisPipeline.java @@ -67,7 +67,7 @@ public interface RedisPipeline { Response lindex(String key, long index); Response linsert(String key, BinaryClient.LIST_POSITION where, - String pivot, String value); + String pivot, String value); Response llen(String key); @@ -146,26 +146,26 @@ public interface RedisPipeline { Response> zrangeByScore(String key, String min, String max); Response> zrangeByScore(String key, double min, double max, - int offset, int count); + int offset, int count); Response> zrangeByScoreWithScores(String key, double min, - double max); + double max); Response> zrangeByScoreWithScores(String key, double min, - double max, int offset, int count); + double max, int offset, int count); Response> zrevrangeByScore(String key, double max, double min); Response> zrevrangeByScore(String key, String max, String min); Response> zrevrangeByScore(String key, double max, double min, - int offset, int count); + int offset, int count); Response> zrevrangeByScoreWithScores(String key, double max, - double min); + double min); Response> zrevrangeByScoreWithScores(String key, double max, - double min, int offset, int count); + double min, int offset, int count); Response> zrangeWithScores(String key, long start, long end); @@ -186,22 +186,22 @@ public interface RedisPipeline { Response zscore(String key, String member); Response zlexcount(final String key, final String min, - final String max); + final String max); Response> zrangeByLex(final String key, final String min, - final String max); + final String max); Response> zrangeByLex(final String key, final String min, - final String max, final int offset, final int count); + final String max, final int offset, final int count); Response> zrevrangeByLex(final String key, final String max, - final String min); + final String min); Response> zrevrangeByLex(final String key, final String max, - final String min, final int offset, final int count); + final String min, final int offset, final int count); Response zremrangeByLex(final String key, final String start, - final String end); + final String end); Response bitcount(String key); diff --git a/src/main/java/redis/clients/jedis/Response.java b/src/main/java/redis/clients/jedis/Response.java index 955277a..4c7b04e 100644 --- a/src/main/java/redis/clients/jedis/Response.java +++ b/src/main/java/redis/clients/jedis/Response.java @@ -12,50 +12,50 @@ public class Response { private boolean requestDependencyBuild = false; public Response(Builder b) { - this.builder = b; + this.builder = b; } public void set(Object data) { - this.data = data; - set = true; + this.data = data; + set = true; } public T get() { - // if response has dependency response and dependency is not built, - // build it first and no more!! - if (!requestDependencyBuild && dependency != null && dependency.set - && !dependency.built) { - requestDependencyBuild = true; - dependency.build(); - } - if (!set) { - throw new JedisDataException( - "Please close pipeline or multi block before calling this method."); - } - if (!built) { - build(); - } - return response; + // if response has dependency response and dependency is not built, + // build it first and no more!! + if (!requestDependencyBuild && dependency != null && dependency.set + && !dependency.built) { + requestDependencyBuild = true; + dependency.build(); + } + if (!set) { + throw new JedisDataException( + "Please close pipeline or multi block before calling this method."); + } + if (!built) { + build(); + } + return response; } public void setDependency(Response dependency) { - this.dependency = dependency; - this.requestDependencyBuild = false; + this.dependency = dependency; + this.requestDependencyBuild = false; } private void build() { - if (data != null) { - if (data instanceof JedisDataException) { - throw new JedisDataException((JedisDataException) data); - } - response = builder.build(data); - } - data = null; - built = true; + if (data != null) { + if (data instanceof JedisDataException) { + throw new JedisDataException((JedisDataException) data); + } + response = builder.build(data); + } + data = null; + built = true; } public String toString() { - return "Response " + builder.toString(); + return "Response " + builder.toString(); } } diff --git a/src/main/java/redis/clients/jedis/ScanParams.java b/src/main/java/redis/clients/jedis/ScanParams.java index 6542ce6..6fd78f7 100644 --- a/src/main/java/redis/clients/jedis/ScanParams.java +++ b/src/main/java/redis/clients/jedis/ScanParams.java @@ -14,27 +14,27 @@ public class ScanParams { private List params = new ArrayList(); public final static String SCAN_POINTER_START = String.valueOf(0); public final static byte[] SCAN_POINTER_START_BINARY = SafeEncoder - .encode(SCAN_POINTER_START); + .encode(SCAN_POINTER_START); public ScanParams match(final byte[] pattern) { - params.add(MATCH.raw); - params.add(pattern); - return this; + params.add(MATCH.raw); + params.add(pattern); + return this; } public ScanParams match(final String pattern) { - params.add(MATCH.raw); - params.add(SafeEncoder.encode(pattern)); - return this; + params.add(MATCH.raw); + params.add(SafeEncoder.encode(pattern)); + return this; } public ScanParams count(final int count) { - params.add(COUNT.raw); - params.add(Protocol.toByteArray(count)); - return this; + params.add(COUNT.raw); + params.add(Protocol.toByteArray(count)); + return this; } public Collection getParams() { - return Collections.unmodifiableCollection(params); + return Collections.unmodifiableCollection(params); } } diff --git a/src/main/java/redis/clients/jedis/ScanResult.java b/src/main/java/redis/clients/jedis/ScanResult.java index b387a76..dbcc4bb 100644 --- a/src/main/java/redis/clients/jedis/ScanResult.java +++ b/src/main/java/redis/clients/jedis/ScanResult.java @@ -9,23 +9,23 @@ public class ScanResult { private List results; public ScanResult(String cursor, List results) { - this(SafeEncoder.encode(cursor), results); + this(SafeEncoder.encode(cursor), results); } public ScanResult(byte[] cursor, List results) { - this.cursor = cursor; - this.results = results; + this.cursor = cursor; + this.results = results; } public String getCursor() { - return SafeEncoder.encode(cursor); + return SafeEncoder.encode(cursor); } public byte[] getCursorAsBytes() { - return cursor; + return cursor; } public List getResult() { - return results; + return results; } } diff --git a/src/main/java/redis/clients/jedis/SentinelCommands.java b/src/main/java/redis/clients/jedis/SentinelCommands.java index 954f49f..f4869d5 100644 --- a/src/main/java/redis/clients/jedis/SentinelCommands.java +++ b/src/main/java/redis/clients/jedis/SentinelCommands.java @@ -15,10 +15,10 @@ public interface SentinelCommands { public String sentinelFailover(String masterName); public String sentinelMonitor(String masterName, String ip, int port, - int quorum); + int quorum); public String sentinelRemove(String masterName); public String sentinelSet(String masterName, - Map parameterMap); + Map parameterMap); } diff --git a/src/main/java/redis/clients/jedis/ShardedJedis.java b/src/main/java/redis/clients/jedis/ShardedJedis.java index da94070..ddcc21c 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedis.java +++ b/src/main/java/redis/clients/jedis/ShardedJedis.java @@ -12,648 +12,648 @@ import redis.clients.util.Hashing; import redis.clients.util.Pool; public class ShardedJedis extends BinaryShardedJedis implements JedisCommands, - Closeable { + Closeable { protected Pool dataSource = null; public ShardedJedis(List shards) { - super(shards); + super(shards); } public ShardedJedis(List shards, Hashing algo) { - super(shards, algo); + super(shards, algo); } public ShardedJedis(List shards, Pattern keyTagPattern) { - super(shards, keyTagPattern); + super(shards, keyTagPattern); } public ShardedJedis(List shards, Hashing algo, - Pattern keyTagPattern) { - super(shards, algo, keyTagPattern); + Pattern keyTagPattern) { + super(shards, algo, keyTagPattern); } public String set(String key, String value) { - Jedis j = getShard(key); - return j.set(key, value); + Jedis j = getShard(key); + return j.set(key, value); } @Override public String set(String key, String value, String nxxx, String expx, - long time) { - Jedis j = getShard(key); - return j.set(key, value, nxxx, expx, time); + long time) { + Jedis j = getShard(key); + return j.set(key, value, nxxx, expx, time); } public String get(String key) { - Jedis j = getShard(key); - return j.get(key); + Jedis j = getShard(key); + return j.get(key); } public String echo(String string) { - Jedis j = getShard(string); - return j.echo(string); + Jedis j = getShard(string); + return j.echo(string); } public Boolean exists(String key) { - Jedis j = getShard(key); - return j.exists(key); + Jedis j = getShard(key); + return j.exists(key); } public String type(String key) { - Jedis j = getShard(key); - return j.type(key); + Jedis j = getShard(key); + return j.type(key); } public Long expire(String key, int seconds) { - Jedis j = getShard(key); - return j.expire(key, seconds); + Jedis j = getShard(key); + return j.expire(key, seconds); } public Long expireAt(String key, long unixTime) { - Jedis j = getShard(key); - return j.expireAt(key, unixTime); + Jedis j = getShard(key); + return j.expireAt(key, unixTime); } public Long ttl(String key) { - Jedis j = getShard(key); - return j.ttl(key); + Jedis j = getShard(key); + return j.ttl(key); } public Boolean setbit(String key, long offset, boolean value) { - Jedis j = getShard(key); - return j.setbit(key, offset, value); + Jedis j = getShard(key); + return j.setbit(key, offset, value); } public Boolean setbit(String key, long offset, String value) { - Jedis j = getShard(key); - return j.setbit(key, offset, value); + Jedis j = getShard(key); + return j.setbit(key, offset, value); } public Boolean getbit(String key, long offset) { - Jedis j = getShard(key); - return j.getbit(key, offset); + Jedis j = getShard(key); + return j.getbit(key, offset); } public Long setrange(String key, long offset, String value) { - Jedis j = getShard(key); - return j.setrange(key, offset, value); + Jedis j = getShard(key); + return j.setrange(key, offset, value); } public String getrange(String key, long startOffset, long endOffset) { - Jedis j = getShard(key); - return j.getrange(key, startOffset, endOffset); + Jedis j = getShard(key); + return j.getrange(key, startOffset, endOffset); } public String getSet(String key, String value) { - Jedis j = getShard(key); - return j.getSet(key, value); + Jedis j = getShard(key); + return j.getSet(key, value); } public Long setnx(String key, String value) { - Jedis j = getShard(key); - return j.setnx(key, value); + Jedis j = getShard(key); + return j.setnx(key, value); } public String setex(String key, int seconds, String value) { - Jedis j = getShard(key); - return j.setex(key, seconds, value); + Jedis j = getShard(key); + return j.setex(key, seconds, value); } public List blpop(String arg) { - Jedis j = getShard(arg); - return j.blpop(arg); + Jedis j = getShard(arg); + return j.blpop(arg); } public List blpop(int timeout, String key) { - Jedis j = getShard(key); - return j.blpop(timeout, key); + Jedis j = getShard(key); + return j.blpop(timeout, key); } public List brpop(String arg) { - Jedis j = getShard(arg); - return j.brpop(arg); + Jedis j = getShard(arg); + return j.brpop(arg); } public List brpop(int timeout, String key) { - Jedis j = getShard(key); - return j.brpop(timeout, 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); + Jedis j = getShard(key); + return j.decrBy(key, integer); } public Long decr(String key) { - Jedis j = getShard(key); - return j.decr(key); + Jedis j = getShard(key); + return j.decr(key); } public Long incrBy(String key, long integer) { - Jedis j = getShard(key); - return j.incrBy(key, integer); + Jedis j = getShard(key); + return j.incrBy(key, integer); } public Double incrByFloat(String key, double integer) { - Jedis j = getShard(key); - return j.incrByFloat(key, integer); + Jedis j = getShard(key); + return j.incrByFloat(key, integer); } public Long incr(String key) { - Jedis j = getShard(key); - return j.incr(key); + Jedis j = getShard(key); + return j.incr(key); } public Long append(String key, String value) { - Jedis j = getShard(key); - return j.append(key, value); + Jedis j = getShard(key); + return j.append(key, value); } public String substr(String key, int start, int end) { - Jedis j = getShard(key); - return j.substr(key, start, end); + Jedis j = getShard(key); + return j.substr(key, start, end); } public Long hset(String key, String field, String value) { - Jedis j = getShard(key); - return j.hset(key, field, value); + Jedis j = getShard(key); + return j.hset(key, field, value); } public String hget(String key, String field) { - Jedis j = getShard(key); - return j.hget(key, field); + Jedis j = getShard(key); + return j.hget(key, field); } public Long hsetnx(String key, String field, String value) { - Jedis j = getShard(key); - return j.hsetnx(key, field, value); + Jedis j = getShard(key); + return j.hsetnx(key, field, value); } public String hmset(String key, Map hash) { - Jedis j = getShard(key); - return j.hmset(key, hash); + Jedis j = getShard(key); + return j.hmset(key, hash); } public List hmget(String key, String... fields) { - Jedis j = getShard(key); - return j.hmget(key, fields); + Jedis j = getShard(key); + return j.hmget(key, fields); } public Long hincrBy(String key, String field, long value) { - Jedis j = getShard(key); - return j.hincrBy(key, field, value); + Jedis j = getShard(key); + return j.hincrBy(key, field, value); } public Double hincrByFloat(String key, String field, double value) { - Jedis j = getShard(key); - return j.hincrByFloat(key, field, value); + Jedis j = getShard(key); + return j.hincrByFloat(key, field, value); } public Boolean hexists(String key, String field) { - Jedis j = getShard(key); - return j.hexists(key, field); + Jedis j = getShard(key); + return j.hexists(key, field); } public Long del(String key) { - Jedis j = getShard(key); - return j.del(key); + Jedis j = getShard(key); + return j.del(key); } public Long hdel(String key, String... fields) { - Jedis j = getShard(key); - return j.hdel(key, fields); + Jedis j = getShard(key); + return j.hdel(key, fields); } public Long hlen(String key) { - Jedis j = getShard(key); - return j.hlen(key); + Jedis j = getShard(key); + return j.hlen(key); } public Set hkeys(String key) { - Jedis j = getShard(key); - return j.hkeys(key); + Jedis j = getShard(key); + return j.hkeys(key); } public List hvals(String key) { - Jedis j = getShard(key); - return j.hvals(key); + Jedis j = getShard(key); + return j.hvals(key); } public Map hgetAll(String key) { - Jedis j = getShard(key); - return j.hgetAll(key); + Jedis j = getShard(key); + return j.hgetAll(key); } public Long rpush(String key, String... strings) { - Jedis j = getShard(key); - return j.rpush(key, strings); + Jedis j = getShard(key); + return j.rpush(key, strings); } public Long lpush(String key, String... strings) { - Jedis j = getShard(key); - return j.lpush(key, strings); + Jedis j = getShard(key); + return j.lpush(key, strings); } public Long lpushx(String key, String... string) { - Jedis j = getShard(key); - return j.lpushx(key, string); + Jedis j = getShard(key); + return j.lpushx(key, string); } public Long strlen(final String key) { - Jedis j = getShard(key); - return j.strlen(key); + Jedis j = getShard(key); + return j.strlen(key); } public Long move(String key, int dbIndex) { - Jedis j = getShard(key); - return j.move(key, dbIndex); + Jedis j = getShard(key); + return j.move(key, dbIndex); } public Long rpushx(String key, String... string) { - Jedis j = getShard(key); - return j.rpushx(key, string); + Jedis j = getShard(key); + return j.rpushx(key, string); } public Long persist(final String key) { - Jedis j = getShard(key); - return j.persist(key); + Jedis j = getShard(key); + return j.persist(key); } public Long llen(String key) { - Jedis j = getShard(key); - return j.llen(key); + Jedis j = getShard(key); + return j.llen(key); } public List lrange(String key, long start, long end) { - Jedis j = getShard(key); - return j.lrange(key, start, end); + Jedis j = getShard(key); + return j.lrange(key, start, end); } public String ltrim(String key, long start, long end) { - Jedis j = getShard(key); - return j.ltrim(key, start, end); + Jedis j = getShard(key); + return j.ltrim(key, start, end); } public String lindex(String key, long index) { - Jedis j = getShard(key); - return j.lindex(key, index); + Jedis j = getShard(key); + return j.lindex(key, index); } public String lset(String key, long index, String value) { - Jedis j = getShard(key); - return j.lset(key, index, value); + Jedis j = getShard(key); + return j.lset(key, index, value); } public Long lrem(String key, long count, String value) { - Jedis j = getShard(key); - return j.lrem(key, count, value); + Jedis j = getShard(key); + return j.lrem(key, count, value); } public String lpop(String key) { - Jedis j = getShard(key); - return j.lpop(key); + Jedis j = getShard(key); + return j.lpop(key); } public String rpop(String key) { - Jedis j = getShard(key); - return j.rpop(key); + Jedis j = getShard(key); + return j.rpop(key); } public Long sadd(String key, String... members) { - Jedis j = getShard(key); - return j.sadd(key, members); + Jedis j = getShard(key); + return j.sadd(key, members); } public Set smembers(String key) { - Jedis j = getShard(key); - return j.smembers(key); + Jedis j = getShard(key); + return j.smembers(key); } public Long srem(String key, String... members) { - Jedis j = getShard(key); - return j.srem(key, members); + Jedis j = getShard(key); + return j.srem(key, members); } public String spop(String key) { - Jedis j = getShard(key); - return j.spop(key); + Jedis j = getShard(key); + return j.spop(key); } public Long scard(String key) { - Jedis j = getShard(key); - return j.scard(key); + Jedis j = getShard(key); + return j.scard(key); } public Boolean sismember(String key, String member) { - Jedis j = getShard(key); - return j.sismember(key, member); + Jedis j = getShard(key); + return j.sismember(key, member); } public String srandmember(String key) { - Jedis j = getShard(key); - return j.srandmember(key); + Jedis j = getShard(key); + return j.srandmember(key); } @Override public List srandmember(String key, int count) { - Jedis j = getShard(key); - return j.srandmember(key, count); + Jedis j = getShard(key); + return j.srandmember(key, count); } public Long zadd(String key, double score, String member) { - Jedis j = getShard(key); - return j.zadd(key, score, member); + Jedis j = getShard(key); + return j.zadd(key, score, member); } public Long zadd(String key, Map scoreMembers) { - Jedis j = getShard(key); - return j.zadd(key, scoreMembers); + Jedis j = getShard(key); + return j.zadd(key, scoreMembers); } public Set zrange(String key, long start, long end) { - Jedis j = getShard(key); - return j.zrange(key, start, end); + Jedis j = getShard(key); + return j.zrange(key, start, end); } public Long zrem(String key, String... members) { - Jedis j = getShard(key); - return j.zrem(key, members); + Jedis j = getShard(key); + return j.zrem(key, members); } public Double zincrby(String key, double score, String member) { - Jedis j = getShard(key); - return j.zincrby(key, score, member); + Jedis j = getShard(key); + return j.zincrby(key, score, member); } public Long zrank(String key, String member) { - Jedis j = getShard(key); - return j.zrank(key, member); + Jedis j = getShard(key); + return j.zrank(key, member); } public Long zrevrank(String key, String member) { - Jedis j = getShard(key); - return j.zrevrank(key, member); + Jedis j = getShard(key); + return j.zrevrank(key, member); } public Set zrevrange(String key, long start, long end) { - Jedis j = getShard(key); - return j.zrevrange(key, start, end); + Jedis j = getShard(key); + return j.zrevrange(key, start, end); } public Set zrangeWithScores(String key, long start, long end) { - Jedis j = getShard(key); - return j.zrangeWithScores(key, start, end); + Jedis j = getShard(key); + return j.zrangeWithScores(key, start, end); } public Set zrevrangeWithScores(String key, long start, long end) { - Jedis j = getShard(key); - return j.zrevrangeWithScores(key, start, end); + Jedis j = getShard(key); + return j.zrevrangeWithScores(key, start, end); } public Long zcard(String key) { - Jedis j = getShard(key); - return j.zcard(key); + Jedis j = getShard(key); + return j.zcard(key); } public Double zscore(String key, String member) { - Jedis j = getShard(key); - return j.zscore(key, member); + Jedis j = getShard(key); + return j.zscore(key, member); } public List sort(String key) { - Jedis j = getShard(key); - return j.sort(key); + Jedis j = getShard(key); + return j.sort(key); } public List sort(String key, SortingParams sortingParameters) { - Jedis j = getShard(key); - return j.sort(key, sortingParameters); + Jedis j = getShard(key); + return j.sort(key, sortingParameters); } public Long zcount(String key, double min, double max) { - Jedis j = getShard(key); - return j.zcount(key, min, max); + Jedis j = getShard(key); + return j.zcount(key, min, max); } public Long zcount(String key, String min, String max) { - Jedis j = getShard(key); - return j.zcount(key, min, max); + Jedis j = getShard(key); + return j.zcount(key, min, max); } public Set zrangeByScore(String key, double min, double max) { - Jedis j = getShard(key); - return j.zrangeByScore(key, min, max); + Jedis j = getShard(key); + return j.zrangeByScore(key, min, max); } public Set zrevrangeByScore(String key, double max, double min) { - Jedis j = getShard(key); - return j.zrevrangeByScore(key, max, min); + Jedis j = getShard(key); + return j.zrevrangeByScore(key, max, min); } public Set zrangeByScore(String key, double min, double max, - int offset, int count) { - Jedis j = getShard(key); - return j.zrangeByScore(key, min, max, offset, count); + int offset, int count) { + Jedis j = getShard(key); + return j.zrangeByScore(key, min, max, offset, count); } public Set zrevrangeByScore(String key, double max, double min, - int offset, int count) { - Jedis j = getShard(key); - return j.zrevrangeByScore(key, max, min, offset, count); + int offset, int count) { + Jedis j = getShard(key); + return j.zrevrangeByScore(key, max, min, offset, count); } public Set zrangeByScoreWithScores(String key, double min, double max) { - Jedis j = getShard(key); - return j.zrangeByScoreWithScores(key, min, max); + Jedis j = getShard(key); + return j.zrangeByScoreWithScores(key, min, max); } public Set zrevrangeByScoreWithScores(String key, double max, - double min) { - Jedis j = getShard(key); - return j.zrevrangeByScoreWithScores(key, max, min); + double min) { + Jedis j = getShard(key); + return j.zrevrangeByScoreWithScores(key, max, min); } public Set zrangeByScoreWithScores(String key, double min, - double max, int offset, int count) { - Jedis j = getShard(key); - return j.zrangeByScoreWithScores(key, min, max, offset, count); + double max, int offset, int count) { + Jedis j = getShard(key); + return j.zrangeByScoreWithScores(key, min, max, offset, count); } public Set zrevrangeByScoreWithScores(String key, double max, - double min, int offset, int count) { - Jedis j = getShard(key); - return j.zrevrangeByScoreWithScores(key, max, min, offset, count); + double min, int offset, int count) { + Jedis j = getShard(key); + return j.zrevrangeByScoreWithScores(key, max, min, offset, count); } public Set zrangeByScore(String key, String min, String max) { - Jedis j = getShard(key); - return j.zrangeByScore(key, min, max); + Jedis j = getShard(key); + return j.zrangeByScore(key, min, max); } public Set zrevrangeByScore(String key, String max, String min) { - Jedis j = getShard(key); - return j.zrevrangeByScore(key, max, min); + Jedis j = getShard(key); + return j.zrevrangeByScore(key, max, min); } public Set zrangeByScore(String key, String min, String max, - int offset, int count) { - Jedis j = getShard(key); - return j.zrangeByScore(key, min, max, offset, count); + int offset, int count) { + Jedis j = getShard(key); + return j.zrangeByScore(key, min, max, offset, count); } public Set zrevrangeByScore(String key, String max, String min, - int offset, int count) { - Jedis j = getShard(key); - return j.zrevrangeByScore(key, max, min, offset, count); + int offset, int count) { + Jedis j = getShard(key); + return j.zrevrangeByScore(key, max, min, offset, count); } public Set zrangeByScoreWithScores(String key, String min, String max) { - Jedis j = getShard(key); - return j.zrangeByScoreWithScores(key, min, max); + Jedis j = getShard(key); + return j.zrangeByScoreWithScores(key, min, max); } public Set zrevrangeByScoreWithScores(String key, String max, - String min) { - Jedis j = getShard(key); - return j.zrevrangeByScoreWithScores(key, max, min); + String min) { + Jedis j = getShard(key); + return j.zrevrangeByScoreWithScores(key, max, min); } public Set zrangeByScoreWithScores(String key, String min, - String max, int offset, int count) { - Jedis j = getShard(key); - return j.zrangeByScoreWithScores(key, min, max, offset, count); + String max, int offset, int count) { + Jedis j = getShard(key); + return j.zrangeByScoreWithScores(key, min, max, offset, count); } public Set zrevrangeByScoreWithScores(String key, String max, - String min, int offset, int count) { - Jedis j = getShard(key); - return j.zrevrangeByScoreWithScores(key, max, min, offset, count); + String min, int offset, int count) { + Jedis j = getShard(key); + return j.zrevrangeByScoreWithScores(key, max, min, offset, count); } public Long zremrangeByRank(String key, long start, long end) { - Jedis j = getShard(key); - return j.zremrangeByRank(key, start, end); + Jedis j = getShard(key); + return j.zremrangeByRank(key, start, end); } public Long zremrangeByScore(String key, double start, double end) { - Jedis j = getShard(key); - return j.zremrangeByScore(key, start, end); + Jedis j = getShard(key); + return j.zremrangeByScore(key, start, end); } public Long zremrangeByScore(String key, String start, String end) { - Jedis j = getShard(key); - return j.zremrangeByScore(key, start, end); + Jedis j = getShard(key); + return j.zremrangeByScore(key, start, end); } @Override public Long zlexcount(final String key, final String min, final String max) { - return getShard(key).zlexcount(key, min, max); + return getShard(key).zlexcount(key, min, max); } @Override public Set zrangeByLex(final String key, final String min, - final String max) { - return getShard(key).zrangeByLex(key, min, max); + final String max) { + return getShard(key).zrangeByLex(key, min, max); } @Override public Set 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); + final String max, final int offset, final int count) { + return getShard(key).zrangeByLex(key, min, max, offset, count); } @Override public Set zrevrangeByLex(String key, String max, String min) { - return getShard(key).zrevrangeByLex(key, max, min); + return getShard(key).zrevrangeByLex(key, max, min); } @Override public Set zrevrangeByLex(String key, String max, String min, - int offset, int count) { - return getShard(key).zrevrangeByLex(key, max, min, offset, count); + int offset, int count) { + return getShard(key).zrevrangeByLex(key, max, min, offset, count); } @Override public Long zremrangeByLex(final String key, final String min, - final String max) { - return getShard(key).zremrangeByLex(key, min, max); + final String max) { + return getShard(key).zremrangeByLex(key, min, max); } public Long linsert(String key, LIST_POSITION where, String pivot, - String value) { - Jedis j = getShard(key); - return j.linsert(key, where, pivot, value); + String value) { + Jedis j = getShard(key); + return j.linsert(key, where, pivot, value); } public Long bitcount(final String key) { - Jedis j = getShard(key); - return j.bitcount(key); + Jedis j = getShard(key); + return j.bitcount(key); } public Long bitcount(final String key, long start, long end) { - Jedis j = getShard(key); - return j.bitcount(key, start, end); + Jedis j = getShard(key); + return j.bitcount(key, start, end); } public ScanResult> hscan(String key, - final String cursor) { - Jedis j = getShard(key); - return j.hscan(key, cursor); + final String cursor) { + Jedis j = getShard(key); + return j.hscan(key, cursor); } public ScanResult sscan(String key, final String cursor) { - Jedis j = getShard(key); - return j.sscan(key, cursor); + Jedis j = getShard(key); + return j.sscan(key, cursor); } public ScanResult zscan(String key, final String cursor) { - Jedis j = getShard(key); - return j.zscan(key, cursor); + Jedis j = getShard(key); + return j.zscan(key, cursor); } @Override public void close() { - if (dataSource != null) { - boolean broken = false; + if (dataSource != null) { + boolean broken = false; - for (Jedis jedis : getAllShards()) { - if (jedis.getClient().isBroken()) { - broken = true; - } - } + for (Jedis jedis : getAllShards()) { + if (jedis.getClient().isBroken()) { + broken = true; + } + } - if (broken) { - dataSource.returnBrokenResource(this); - } else { - this.resetState(); - dataSource.returnResource(this); - } + if (broken) { + dataSource.returnBrokenResource(this); + } else { + this.resetState(); + dataSource.returnResource(this); + } - } else { - disconnect(); - } + } else { + disconnect(); + } } public void setDataSource(Pool shardedJedisPool) { - this.dataSource = shardedJedisPool; + this.dataSource = shardedJedisPool; } public void resetState() { - for (Jedis jedis : getAllShards()) { - jedis.resetState(); - } + for (Jedis jedis : getAllShards()) { + jedis.resetState(); + } } public Long pfadd(String key, String... elements) { - Jedis j = getShard(key); - return j.pfadd(key, elements); + Jedis j = getShard(key); + return j.pfadd(key, elements); } @Override public long pfcount(String key) { - Jedis j = getShard(key); - return j.pfcount(key); + Jedis j = getShard(key); + return j.pfcount(key); } } diff --git a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java index 480d153..c28c3a7 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java +++ b/src/main/java/redis/clients/jedis/ShardedJedisPipeline.java @@ -11,27 +11,27 @@ public class ShardedJedisPipeline extends PipelineBase { private Queue clients = new LinkedList(); private static class FutureResult { - private Client client; + private Client client; - public FutureResult(Client client) { - this.client = client; - } + public FutureResult(Client client) { + this.client = client; + } - public Object get() { - return client.getOne(); - } + public Object get() { + return client.getOne(); + } } public void setShardedJedis(BinaryShardedJedis jedis) { - this.jedis = jedis; + this.jedis = jedis; } public List getResults() { - List r = new ArrayList(); - for (FutureResult fr : results) { - r.add(fr.get()); - } - return r; + List r = new ArrayList(); + for (FutureResult fr : results) { + r.add(fr.get()); + } + return r; } /** @@ -40,9 +40,9 @@ public class ShardedJedisPipeline extends PipelineBase { * the different Response<?> of the commands you execute. */ public void sync() { - for (Client client : clients) { - generateResponse(client.getOne()); - } + for (Client client : clients) { + generateResponse(client.getOne()); + } } /** @@ -54,26 +54,26 @@ public class ShardedJedisPipeline extends PipelineBase { * @return A list of all the responses in the order you executed them. */ public List syncAndReturnAll() { - List formatted = new ArrayList(); - for (Client client : clients) { - formatted.add(generateResponse(client.getOne()).get()); - } - return formatted; + List formatted = new ArrayList(); + for (Client client : clients) { + formatted.add(generateResponse(client.getOne()).get()); + } + return formatted; } @Override protected Client getClient(String key) { - Client client = jedis.getShard(key).getClient(); - clients.add(client); - results.add(new FutureResult(client)); - return client; + Client client = jedis.getShard(key).getClient(); + clients.add(client); + results.add(new FutureResult(client)); + return client; } @Override protected Client getClient(byte[] key) { - Client client = jedis.getShard(key).getClient(); - clients.add(client); - results.add(new FutureResult(client)); - return client; + Client client = jedis.getShard(key).getClient(); + clients.add(client); + results.add(new FutureResult(client)); + return client; } } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/ShardedJedisPool.java b/src/main/java/redis/clients/jedis/ShardedJedisPool.java index f50f3e7..5593ecd 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedisPool.java +++ b/src/main/java/redis/clients/jedis/ShardedJedisPool.java @@ -13,113 +13,113 @@ import redis.clients.util.Pool; public class ShardedJedisPool extends Pool { public ShardedJedisPool(final GenericObjectPoolConfig poolConfig, - List shards) { - this(poolConfig, shards, Hashing.MURMUR_HASH); + List shards) { + this(poolConfig, shards, Hashing.MURMUR_HASH); } public ShardedJedisPool(final GenericObjectPoolConfig poolConfig, - List shards, Hashing algo) { - this(poolConfig, shards, algo, null); + List shards, Hashing algo) { + this(poolConfig, shards, algo, null); } public ShardedJedisPool(final GenericObjectPoolConfig poolConfig, - List shards, Pattern keyTagPattern) { - this(poolConfig, shards, Hashing.MURMUR_HASH, keyTagPattern); + List shards, Pattern keyTagPattern) { + this(poolConfig, shards, Hashing.MURMUR_HASH, keyTagPattern); } public ShardedJedisPool(final GenericObjectPoolConfig poolConfig, - List shards, Hashing algo, Pattern keyTagPattern) { - super(poolConfig, new ShardedJedisFactory(shards, algo, keyTagPattern)); + List shards, Hashing algo, Pattern keyTagPattern) { + super(poolConfig, new ShardedJedisFactory(shards, algo, keyTagPattern)); } @Override public ShardedJedis getResource() { - ShardedJedis jedis = super.getResource(); - jedis.setDataSource(this); - return jedis; + ShardedJedis jedis = super.getResource(); + jedis.setDataSource(this); + return jedis; } @Override public void returnBrokenResource(final ShardedJedis resource) { - if (resource != null) { - returnBrokenResourceObject(resource); - } + if (resource != null) { + returnBrokenResourceObject(resource); + } } @Override public void returnResource(final ShardedJedis resource) { - if (resource != null) { - resource.resetState(); - returnResourceObject(resource); - } + if (resource != null) { + resource.resetState(); + returnResourceObject(resource); + } } /** * PoolableObjectFactory custom impl. */ private static class ShardedJedisFactory implements - PooledObjectFactory { - private List shards; - private Hashing algo; - private Pattern keyTagPattern; + PooledObjectFactory { + private List shards; + private Hashing algo; + private Pattern keyTagPattern; - public ShardedJedisFactory(List shards, Hashing algo, - Pattern keyTagPattern) { - this.shards = shards; - this.algo = algo; - this.keyTagPattern = keyTagPattern; - } + public ShardedJedisFactory(List shards, Hashing algo, + Pattern keyTagPattern) { + this.shards = shards; + this.algo = algo; + this.keyTagPattern = keyTagPattern; + } - @Override - public PooledObject makeObject() throws Exception { - ShardedJedis jedis = new ShardedJedis(shards, algo, keyTagPattern); - return new DefaultPooledObject(jedis); - } + @Override + public PooledObject makeObject() throws Exception { + ShardedJedis jedis = new ShardedJedis(shards, algo, keyTagPattern); + return new DefaultPooledObject(jedis); + } - @Override - public void destroyObject(PooledObject pooledShardedJedis) - throws Exception { - final ShardedJedis shardedJedis = pooledShardedJedis.getObject(); - for (Jedis jedis : shardedJedis.getAllShards()) { - try { - try { - jedis.quit(); - } catch (Exception e) { + @Override + public void destroyObject(PooledObject pooledShardedJedis) + throws Exception { + final ShardedJedis shardedJedis = pooledShardedJedis.getObject(); + for (Jedis jedis : shardedJedis.getAllShards()) { + try { + try { + jedis.quit(); + } catch (Exception e) { - } - jedis.disconnect(); - } catch (Exception e) { + } + jedis.disconnect(); + } catch (Exception e) { - } - } - } + } + } + } - @Override - public boolean validateObject( - PooledObject pooledShardedJedis) { - try { - ShardedJedis jedis = pooledShardedJedis.getObject(); - for (Jedis shard : jedis.getAllShards()) { - if (!shard.ping().equals("PONG")) { - return false; - } - } - return true; - } catch (Exception ex) { - return false; - } - } + @Override + public boolean validateObject( + PooledObject pooledShardedJedis) { + try { + ShardedJedis jedis = pooledShardedJedis.getObject(); + for (Jedis shard : jedis.getAllShards()) { + if (!shard.ping().equals("PONG")) { + return false; + } + } + return true; + } catch (Exception ex) { + return false; + } + } - @Override - public void activateObject(PooledObject p) - throws Exception { + @Override + public void activateObject(PooledObject p) + throws Exception { - } + } - @Override - public void passivateObject(PooledObject p) - throws Exception { + @Override + public void passivateObject(PooledObject p) + throws Exception { - } + } } } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/SortingParams.java b/src/main/java/redis/clients/jedis/SortingParams.java index ea0bee8..f25c175 100644 --- a/src/main/java/redis/clients/jedis/SortingParams.java +++ b/src/main/java/redis/clients/jedis/SortingParams.java @@ -36,7 +36,7 @@ public class SortingParams { * @return the SortingParams Object */ public SortingParams by(final String pattern) { - return by(SafeEncoder.encode(pattern)); + return by(SafeEncoder.encode(pattern)); } /** @@ -53,9 +53,9 @@ public class SortingParams { * @return the SortingParams Object */ public SortingParams by(final byte[] pattern) { - params.add(BY.raw); - params.add(pattern); - return this; + params.add(BY.raw); + params.add(pattern); + return this; } /** @@ -67,13 +67,13 @@ public class SortingParams { * @return the SortingParams Object */ public SortingParams nosort() { - params.add(BY.raw); - params.add(NOSORT.raw); - return this; + params.add(BY.raw); + params.add(NOSORT.raw); + return this; } public Collection getParams() { - return Collections.unmodifiableCollection(params); + return Collections.unmodifiableCollection(params); } /** @@ -82,8 +82,8 @@ public class SortingParams { * @return the sortingParams Object */ public SortingParams desc() { - params.add(DESC.raw); - return this; + params.add(DESC.raw); + return this; } /** @@ -92,8 +92,8 @@ public class SortingParams { * @return the SortingParams Object */ public SortingParams asc() { - params.add(ASC.raw); - return this; + params.add(ASC.raw); + return this; } /** @@ -105,10 +105,10 @@ public class SortingParams { * @return the SortingParams Object */ public SortingParams limit(final int start, final int count) { - params.add(LIMIT.raw); - params.add(Protocol.toByteArray(start)); - params.add(Protocol.toByteArray(count)); - return this; + params.add(LIMIT.raw); + params.add(Protocol.toByteArray(start)); + params.add(Protocol.toByteArray(count)); + return this; } /** @@ -118,8 +118,8 @@ public class SortingParams { * @return the SortingParams Object */ public SortingParams alpha() { - params.add(ALPHA.raw); - return this; + params.add(ALPHA.raw); + return this; } /** @@ -138,11 +138,11 @@ public class SortingParams { * @return the SortingParams Object */ public SortingParams get(String... patterns) { - for (final String pattern : patterns) { - params.add(GET.raw); - params.add(SafeEncoder.encode(pattern)); - } - return this; + for (final String pattern : patterns) { + params.add(GET.raw); + params.add(SafeEncoder.encode(pattern)); + } + return this; } /** @@ -161,10 +161,10 @@ public class SortingParams { * @return the SortingParams Object */ public SortingParams get(byte[]... patterns) { - for (final byte[] pattern : patterns) { - params.add(GET.raw); - params.add(pattern); - } - return this; + for (final byte[] pattern : patterns) { + params.add(GET.raw); + params.add(pattern); + } + return this; } } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/Transaction.java b/src/main/java/redis/clients/jedis/Transaction.java index e6088ff..a15ccfe 100644 --- a/src/main/java/redis/clients/jedis/Transaction.java +++ b/src/main/java/redis/clients/jedis/Transaction.java @@ -14,75 +14,75 @@ public class Transaction extends MultiKeyPipelineBase { protected boolean inTransaction = true; protected Transaction() { - // client will be set later in transaction block + // client will be set later in transaction block } public Transaction(final Client client) { - this.client = client; + this.client = client; } @Override protected Client getClient(String key) { - return client; + return client; } @Override protected Client getClient(byte[] key) { - return client; + return client; } public void clear() { - if (inTransaction) { - discard(); - } + if (inTransaction) { + discard(); + } } public List exec() { - // Discard QUEUED or ERROR - client.getMany(getPipelinedResponseLength()); - client.exec(); + // Discard QUEUED or ERROR + client.getMany(getPipelinedResponseLength()); + client.exec(); - List unformatted = client.getObjectMultiBulkReply(); - if (unformatted == null) { - return null; - } - List formatted = new ArrayList(); - for (Object o : unformatted) { - try { - formatted.add(generateResponse(o).get()); - } catch (JedisDataException e) { - formatted.add(e); - } - } - return formatted; + List unformatted = client.getObjectMultiBulkReply(); + if (unformatted == null) { + return null; + } + List formatted = new ArrayList(); + for (Object o : unformatted) { + try { + formatted.add(generateResponse(o).get()); + } catch (JedisDataException e) { + formatted.add(e); + } + } + return formatted; } public List> execGetResponse() { - // Discard QUEUED or ERROR - client.getMany(getPipelinedResponseLength()); - client.exec(); + // Discard QUEUED or ERROR + client.getMany(getPipelinedResponseLength()); + client.exec(); - List unformatted = client.getObjectMultiBulkReply(); - if (unformatted == null) { - return null; - } - List> response = new ArrayList>(); - for (Object o : unformatted) { - response.add(generateResponse(o)); - } - return response; + List unformatted = client.getObjectMultiBulkReply(); + if (unformatted == null) { + return null; + } + List> response = new ArrayList>(); + for (Object o : unformatted) { + response.add(generateResponse(o)); + } + return response; } public String discard() { - client.getMany(getPipelinedResponseLength()); - client.discard(); - inTransaction = false; - clean(); - return client.getStatusCodeReply(); + client.getMany(getPipelinedResponseLength()); + client.discard(); + inTransaction = false; + clean(); + return client.getStatusCodeReply(); } public void setClient(Client client) { - this.client = client; + this.client = client; } } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/Tuple.java b/src/main/java/redis/clients/jedis/Tuple.java index ad8d001..1253a5e 100644 --- a/src/main/java/redis/clients/jedis/Tuple.java +++ b/src/main/java/redis/clients/jedis/Tuple.java @@ -9,72 +9,72 @@ public class Tuple implements Comparable { private Double score; public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result; - if (null != element) { - for (final byte b : element) { - result = prime * result + b; - } - } - long temp; - temp = Double.doubleToLongBits(score); - result = prime * result + (int) (temp ^ (temp >>> 32)); - return result; + final int prime = 31; + int result = 1; + result = prime * result; + if (null != element) { + for (final byte b : element) { + result = prime * result + b; + } + } + long temp; + temp = Double.doubleToLongBits(score); + result = prime * result + (int) (temp ^ (temp >>> 32)); + return result; } public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Tuple other = (Tuple) obj; - if (element == null) { - if (other.element != null) - return false; - } else if (!Arrays.equals(element, other.element)) - return false; - return true; + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Tuple other = (Tuple) obj; + if (element == null) { + if (other.element != null) + return false; + } else if (!Arrays.equals(element, other.element)) + return false; + return true; } public int compareTo(Tuple other) { - if (Arrays.equals(this.element, other.element)) - return 0; - else - return this.score < other.getScore() ? -1 : 1; + if (Arrays.equals(this.element, other.element)) + return 0; + else + return this.score < other.getScore() ? -1 : 1; } public Tuple(String element, Double score) { - super(); - this.element = SafeEncoder.encode(element); - this.score = score; + super(); + this.element = SafeEncoder.encode(element); + this.score = score; } public Tuple(byte[] element, Double score) { - super(); - this.element = element; - this.score = score; + super(); + this.element = element; + this.score = score; } public String getElement() { - if (null != element) { - return SafeEncoder.encode(element); - } else { - return null; - } + if (null != element) { + return SafeEncoder.encode(element); + } else { + return null; + } } public byte[] getBinaryElement() { - return element; + return element; } public double getScore() { - return score; + return score; } public String toString() { - return '[' + Arrays.toString(element) + ',' + score + ']'; + return '[' + Arrays.toString(element) + ',' + score + ']'; } } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/ZParams.java b/src/main/java/redis/clients/jedis/ZParams.java index 17d021e..3977b1e 100644 --- a/src/main/java/redis/clients/jedis/ZParams.java +++ b/src/main/java/redis/clients/jedis/ZParams.java @@ -12,13 +12,13 @@ import redis.clients.util.SafeEncoder; public class ZParams { public enum Aggregate { - SUM, MIN, MAX; + SUM, MIN, MAX; - public final byte[] raw; + public final byte[] raw; - Aggregate() { - raw = SafeEncoder.encode(name()); - } + Aggregate() { + raw = SafeEncoder.encode(name()); + } } private List params = new ArrayList(); @@ -30,21 +30,21 @@ public class ZParams { * weights. */ public ZParams weights(final double... weights) { - params.add(WEIGHTS.raw); - for (final double weight : weights) { - params.add(Protocol.toByteArray(weight)); - } + params.add(WEIGHTS.raw); + for (final double weight : weights) { + params.add(Protocol.toByteArray(weight)); + } - return this; + return this; } public Collection getParams() { - return Collections.unmodifiableCollection(params); + return Collections.unmodifiableCollection(params); } public ZParams aggregate(final Aggregate aggregate) { - params.add(AGGREGATE.raw); - params.add(aggregate.raw); - return this; + params.add(AGGREGATE.raw); + params.add(aggregate.raw); + return this; } } diff --git a/src/main/java/redis/clients/jedis/exceptions/JedisAskDataException.java b/src/main/java/redis/clients/jedis/exceptions/JedisAskDataException.java index 0544109..ce01068 100644 --- a/src/main/java/redis/clients/jedis/exceptions/JedisAskDataException.java +++ b/src/main/java/redis/clients/jedis/exceptions/JedisAskDataException.java @@ -6,18 +6,18 @@ public class JedisAskDataException extends JedisRedirectionException { private static final long serialVersionUID = 3878126572474819403L; public JedisAskDataException(Throwable cause, HostAndPort targetHost, - int slot) { - super(cause, targetHost, slot); + int slot) { + super(cause, targetHost, slot); } public JedisAskDataException(String message, Throwable cause, - HostAndPort targetHost, int slot) { - super(message, cause, targetHost, slot); + HostAndPort targetHost, int slot) { + super(message, cause, targetHost, slot); } public JedisAskDataException(String message, HostAndPort targetHost, - int slot) { - super(message, targetHost, slot); + int slot) { + super(message, targetHost, slot); } } diff --git a/src/main/java/redis/clients/jedis/exceptions/JedisClusterException.java b/src/main/java/redis/clients/jedis/exceptions/JedisClusterException.java index 7e93b26..219a4b3 100644 --- a/src/main/java/redis/clients/jedis/exceptions/JedisClusterException.java +++ b/src/main/java/redis/clients/jedis/exceptions/JedisClusterException.java @@ -4,14 +4,14 @@ public class JedisClusterException extends JedisDataException { private static final long serialVersionUID = 3878126572474819403L; public JedisClusterException(Throwable cause) { - super(cause); + super(cause); } public JedisClusterException(String message, Throwable cause) { - super(message, cause); + super(message, cause); } public JedisClusterException(String message) { - super(message); + super(message); } } diff --git a/src/main/java/redis/clients/jedis/exceptions/JedisClusterMaxRedirectionsException.java b/src/main/java/redis/clients/jedis/exceptions/JedisClusterMaxRedirectionsException.java index 29c289b..b337079 100644 --- a/src/main/java/redis/clients/jedis/exceptions/JedisClusterMaxRedirectionsException.java +++ b/src/main/java/redis/clients/jedis/exceptions/JedisClusterMaxRedirectionsException.java @@ -4,14 +4,14 @@ public class JedisClusterMaxRedirectionsException extends JedisDataException { private static final long serialVersionUID = 3878126572474819403L; public JedisClusterMaxRedirectionsException(Throwable cause) { - super(cause); + super(cause); } public JedisClusterMaxRedirectionsException(String message, Throwable cause) { - super(message, cause); + super(message, cause); } public JedisClusterMaxRedirectionsException(String message) { - super(message); + super(message); } } diff --git a/src/main/java/redis/clients/jedis/exceptions/JedisConnectionException.java b/src/main/java/redis/clients/jedis/exceptions/JedisConnectionException.java index f20c53a..ea2addd 100644 --- a/src/main/java/redis/clients/jedis/exceptions/JedisConnectionException.java +++ b/src/main/java/redis/clients/jedis/exceptions/JedisConnectionException.java @@ -4,14 +4,14 @@ public class JedisConnectionException extends JedisException { private static final long serialVersionUID = 3878126572474819403L; public JedisConnectionException(String message) { - super(message); + super(message); } public JedisConnectionException(Throwable cause) { - super(cause); + super(cause); } public JedisConnectionException(String message, Throwable cause) { - super(message, cause); + super(message, cause); } } diff --git a/src/main/java/redis/clients/jedis/exceptions/JedisDataException.java b/src/main/java/redis/clients/jedis/exceptions/JedisDataException.java index 9872377..d679742 100644 --- a/src/main/java/redis/clients/jedis/exceptions/JedisDataException.java +++ b/src/main/java/redis/clients/jedis/exceptions/JedisDataException.java @@ -4,14 +4,14 @@ public class JedisDataException extends JedisException { private static final long serialVersionUID = 3878126572474819403L; public JedisDataException(String message) { - super(message); + super(message); } public JedisDataException(Throwable cause) { - super(cause); + super(cause); } public JedisDataException(String message, Throwable cause) { - super(message, cause); + super(message, cause); } } diff --git a/src/main/java/redis/clients/jedis/exceptions/JedisException.java b/src/main/java/redis/clients/jedis/exceptions/JedisException.java index f4abb71..181e235 100644 --- a/src/main/java/redis/clients/jedis/exceptions/JedisException.java +++ b/src/main/java/redis/clients/jedis/exceptions/JedisException.java @@ -4,14 +4,14 @@ public class JedisException extends RuntimeException { private static final long serialVersionUID = -2946266495682282677L; public JedisException(String message) { - super(message); + super(message); } public JedisException(Throwable e) { - super(e); + super(e); } public JedisException(String message, Throwable cause) { - super(message, cause); + super(message, cause); } } diff --git a/src/main/java/redis/clients/jedis/exceptions/JedisMovedDataException.java b/src/main/java/redis/clients/jedis/exceptions/JedisMovedDataException.java index 123f5e3..790a741 100644 --- a/src/main/java/redis/clients/jedis/exceptions/JedisMovedDataException.java +++ b/src/main/java/redis/clients/jedis/exceptions/JedisMovedDataException.java @@ -6,17 +6,17 @@ public class JedisMovedDataException extends JedisRedirectionException { private static final long serialVersionUID = 3878126572474819403L; public JedisMovedDataException(String message, HostAndPort targetNode, - int slot) { - super(message, targetNode, slot); + int slot) { + super(message, targetNode, slot); } public JedisMovedDataException(Throwable cause, HostAndPort targetNode, - int slot) { - super(cause, targetNode, slot); + int slot) { + super(cause, targetNode, slot); } public JedisMovedDataException(String message, Throwable cause, - HostAndPort targetNode, int slot) { - super(message, cause, targetNode, slot); + HostAndPort targetNode, int slot) { + super(message, cause, targetNode, slot); } } diff --git a/src/main/java/redis/clients/jedis/exceptions/JedisRedirectionException.java b/src/main/java/redis/clients/jedis/exceptions/JedisRedirectionException.java index ab96287..45a0026 100644 --- a/src/main/java/redis/clients/jedis/exceptions/JedisRedirectionException.java +++ b/src/main/java/redis/clients/jedis/exceptions/JedisRedirectionException.java @@ -9,31 +9,31 @@ public class JedisRedirectionException extends JedisDataException { private int slot; public JedisRedirectionException(String message, HostAndPort targetNode, - int slot) { - super(message); - this.targetNode = targetNode; - this.slot = slot; + int slot) { + super(message); + this.targetNode = targetNode; + this.slot = slot; } public JedisRedirectionException(Throwable cause, HostAndPort targetNode, - int slot) { - super(cause); - this.targetNode = targetNode; - this.slot = slot; + int slot) { + super(cause); + this.targetNode = targetNode; + this.slot = slot; } public JedisRedirectionException(String message, Throwable cause, - HostAndPort targetNode, int slot) { - super(message, cause); - this.targetNode = targetNode; - this.slot = slot; + HostAndPort targetNode, int slot) { + super(message, cause); + this.targetNode = targetNode; + this.slot = slot; } public HostAndPort getTargetNode() { - return targetNode; + return targetNode; } public int getSlot() { - return slot; + return slot; } } diff --git a/src/main/java/redis/clients/util/ClusterNodeInformation.java b/src/main/java/redis/clients/util/ClusterNodeInformation.java index 0d3dee0..7029f67 100644 --- a/src/main/java/redis/clients/util/ClusterNodeInformation.java +++ b/src/main/java/redis/clients/util/ClusterNodeInformation.java @@ -12,37 +12,37 @@ public class ClusterNodeInformation { private List slotsBeingMigrated; public ClusterNodeInformation(HostAndPort node) { - this.node = node; - this.availableSlots = new ArrayList(); - this.slotsBeingImported = new ArrayList(); - this.slotsBeingMigrated = new ArrayList(); + this.node = node; + this.availableSlots = new ArrayList(); + this.slotsBeingImported = new ArrayList(); + this.slotsBeingMigrated = new ArrayList(); } public void addAvailableSlot(int slot) { - availableSlots.add(slot); + availableSlots.add(slot); } public void addSlotBeingImported(int slot) { - slotsBeingImported.add(slot); + slotsBeingImported.add(slot); } public void addSlotBeingMigrated(int slot) { - slotsBeingMigrated.add(slot); + slotsBeingMigrated.add(slot); } public HostAndPort getNode() { - return node; + return node; } public List getAvailableSlots() { - return availableSlots; + return availableSlots; } public List getSlotsBeingImported() { - return slotsBeingImported; + return slotsBeingImported; } public List getSlotsBeingMigrated() { - return slotsBeingMigrated; + return slotsBeingMigrated; } } diff --git a/src/main/java/redis/clients/util/ClusterNodeInformationParser.java b/src/main/java/redis/clients/util/ClusterNodeInformationParser.java index 3c10c95..f8f48ac 100644 --- a/src/main/java/redis/clients/util/ClusterNodeInformationParser.java +++ b/src/main/java/redis/clients/util/ClusterNodeInformationParser.java @@ -9,72 +9,72 @@ public class ClusterNodeInformationParser { public static final int HOST_AND_PORT_INDEX = 1; public ClusterNodeInformation parse(String nodeInfo, HostAndPort current) { - String[] nodeInfoPartArray = nodeInfo.split(" "); + String[] nodeInfoPartArray = nodeInfo.split(" "); - HostAndPort node = getHostAndPortFromNodeLine(nodeInfoPartArray, - current); - ClusterNodeInformation info = new ClusterNodeInformation(node); + HostAndPort node = getHostAndPortFromNodeLine(nodeInfoPartArray, + current); + ClusterNodeInformation info = new ClusterNodeInformation(node); - if (nodeInfoPartArray.length >= SLOT_INFORMATIONS_START_INDEX) { - String[] slotInfoPartArray = extractSlotParts(nodeInfoPartArray); - fillSlotInformation(slotInfoPartArray, info); - } + if (nodeInfoPartArray.length >= SLOT_INFORMATIONS_START_INDEX) { + String[] slotInfoPartArray = extractSlotParts(nodeInfoPartArray); + fillSlotInformation(slotInfoPartArray, info); + } - return info; + return info; } private String[] extractSlotParts(String[] nodeInfoPartArray) { - String[] slotInfoPartArray = new String[nodeInfoPartArray.length - - SLOT_INFORMATIONS_START_INDEX]; - for (int i = SLOT_INFORMATIONS_START_INDEX; i < nodeInfoPartArray.length; i++) { - slotInfoPartArray[i - SLOT_INFORMATIONS_START_INDEX] = nodeInfoPartArray[i]; - } - return slotInfoPartArray; + String[] slotInfoPartArray = new String[nodeInfoPartArray.length + - SLOT_INFORMATIONS_START_INDEX]; + for (int i = SLOT_INFORMATIONS_START_INDEX; i < nodeInfoPartArray.length; i++) { + slotInfoPartArray[i - SLOT_INFORMATIONS_START_INDEX] = nodeInfoPartArray[i]; + } + return slotInfoPartArray; } public HostAndPort getHostAndPortFromNodeLine(String[] nodeInfoPartArray, - HostAndPort current) { - String stringHostAndPort = nodeInfoPartArray[HOST_AND_PORT_INDEX]; + HostAndPort current) { + String stringHostAndPort = nodeInfoPartArray[HOST_AND_PORT_INDEX]; - String[] arrayHostAndPort = stringHostAndPort.split(":"); - return new HostAndPort( - arrayHostAndPort[0].isEmpty() ? current.getHost() - : arrayHostAndPort[0], - arrayHostAndPort[1].isEmpty() ? current.getPort() : Integer - .valueOf(arrayHostAndPort[1])); + String[] arrayHostAndPort = stringHostAndPort.split(":"); + return new HostAndPort( + arrayHostAndPort[0].isEmpty() ? current.getHost() + : arrayHostAndPort[0], + arrayHostAndPort[1].isEmpty() ? current.getPort() : Integer + .valueOf(arrayHostAndPort[1])); } private void fillSlotInformation(String[] slotInfoPartArray, - ClusterNodeInformation info) { - for (String slotRange : slotInfoPartArray) { - fillSlotInformationFromSlotRange(slotRange, info); - } + ClusterNodeInformation info) { + for (String slotRange : slotInfoPartArray) { + fillSlotInformationFromSlotRange(slotRange, info); + } } private void fillSlotInformationFromSlotRange(String slotRange, - ClusterNodeInformation info) { - if (slotRange.startsWith(SLOT_IN_TRANSITION_IDENTIFIER)) { - // slot is in transition - int slot = Integer.parseInt(slotRange.substring(1).split("-")[0]); + ClusterNodeInformation info) { + if (slotRange.startsWith(SLOT_IN_TRANSITION_IDENTIFIER)) { + // slot is in transition + int slot = Integer.parseInt(slotRange.substring(1).split("-")[0]); - if (slotRange.contains(SLOT_IMPORT_IDENTIFIER)) { - // import - info.addSlotBeingImported(slot); - } else { - // migrate (->-) - info.addSlotBeingMigrated(slot); - } - } else if (slotRange.contains("-")) { - // slot range - String[] slotRangePart = slotRange.split("-"); - for (int slot = Integer.valueOf(slotRangePart[0]); slot <= Integer - .valueOf(slotRangePart[1]); slot++) { - info.addAvailableSlot(slot); - } - } else { - // single slot - info.addAvailableSlot(Integer.valueOf(slotRange)); - } + if (slotRange.contains(SLOT_IMPORT_IDENTIFIER)) { + // import + info.addSlotBeingImported(slot); + } else { + // migrate (->-) + info.addSlotBeingMigrated(slot); + } + } else if (slotRange.contains("-")) { + // slot range + String[] slotRangePart = slotRange.split("-"); + for (int slot = Integer.valueOf(slotRangePart[0]); slot <= Integer + .valueOf(slotRangePart[1]); slot++) { + info.addAvailableSlot(slot); + } + } else { + // single slot + info.addAvailableSlot(Integer.valueOf(slotRange)); + } } } diff --git a/src/main/java/redis/clients/util/Hashing.java b/src/main/java/redis/clients/util/Hashing.java index b15a199..647e222 100644 --- a/src/main/java/redis/clients/util/Hashing.java +++ b/src/main/java/redis/clients/util/Hashing.java @@ -8,28 +8,28 @@ public interface Hashing { public ThreadLocal md5Holder = new ThreadLocal(); public static final Hashing MD5 = new Hashing() { - public long hash(String key) { - return hash(SafeEncoder.encode(key)); - } + public long hash(String key) { + return hash(SafeEncoder.encode(key)); + } - public long hash(byte[] key) { - try { - if (md5Holder.get() == null) { - md5Holder.set(MessageDigest.getInstance("MD5")); - } - } catch (NoSuchAlgorithmException e) { - throw new IllegalStateException("++++ no md5 algorythm found"); - } - MessageDigest md5 = md5Holder.get(); + public long hash(byte[] key) { + try { + if (md5Holder.get() == null) { + md5Holder.set(MessageDigest.getInstance("MD5")); + } + } catch (NoSuchAlgorithmException e) { + throw new IllegalStateException("++++ no md5 algorythm found"); + } + MessageDigest md5 = md5Holder.get(); - md5.reset(); - md5.update(key); - byte[] bKey = md5.digest(); - long res = ((long) (bKey[3] & 0xFF) << 24) - | ((long) (bKey[2] & 0xFF) << 16) - | ((long) (bKey[1] & 0xFF) << 8) | (long) (bKey[0] & 0xFF); - return res; - } + md5.reset(); + md5.update(key); + byte[] bKey = md5.digest(); + long res = ((long) (bKey[3] & 0xFF) << 24) + | ((long) (bKey[2] & 0xFF) << 16) + | ((long) (bKey[1] & 0xFF) << 8) | (long) (bKey[0] & 0xFF); + return res; + } }; public long hash(String key); diff --git a/src/main/java/redis/clients/util/JedisByteHashMap.java b/src/main/java/redis/clients/util/JedisByteHashMap.java index cdef172..ceb0b97 100644 --- a/src/main/java/redis/clients/util/JedisByteHashMap.java +++ b/src/main/java/redis/clients/util/JedisByteHashMap.java @@ -10,127 +10,127 @@ import java.util.Map; import java.util.Set; public class JedisByteHashMap implements Map, Cloneable, - Serializable { + Serializable { private static final long serialVersionUID = -6971431362627219416L; private Map internalMap = new HashMap(); public void clear() { - internalMap.clear(); + internalMap.clear(); } public boolean containsKey(Object key) { - if (key instanceof byte[]) - return internalMap.containsKey(new ByteArrayWrapper((byte[]) key)); - return internalMap.containsKey(key); + if (key instanceof byte[]) + return internalMap.containsKey(new ByteArrayWrapper((byte[]) key)); + return internalMap.containsKey(key); } public boolean containsValue(Object value) { - return internalMap.containsValue(value); + return internalMap.containsValue(value); } public Set> entrySet() { - Iterator> iterator = internalMap - .entrySet().iterator(); - HashSet> hashSet = new HashSet>(); - while (iterator.hasNext()) { - Entry entry = iterator.next(); - hashSet.add(new JedisByteEntry(entry.getKey().data, entry - .getValue())); - } - return hashSet; + Iterator> iterator = internalMap + .entrySet().iterator(); + HashSet> hashSet = new HashSet>(); + while (iterator.hasNext()) { + Entry entry = iterator.next(); + hashSet.add(new JedisByteEntry(entry.getKey().data, entry + .getValue())); + } + return hashSet; } public byte[] get(Object key) { - if (key instanceof byte[]) - return internalMap.get(new ByteArrayWrapper((byte[]) key)); - return internalMap.get(key); + if (key instanceof byte[]) + return internalMap.get(new ByteArrayWrapper((byte[]) key)); + return internalMap.get(key); } public boolean isEmpty() { - return internalMap.isEmpty(); + return internalMap.isEmpty(); } public Set keySet() { - Set keySet = new HashSet(); - Iterator iterator = internalMap.keySet().iterator(); - while (iterator.hasNext()) { - keySet.add(iterator.next().data); - } - return keySet; + Set keySet = new HashSet(); + Iterator iterator = internalMap.keySet().iterator(); + while (iterator.hasNext()) { + keySet.add(iterator.next().data); + } + return keySet; } public byte[] put(byte[] key, byte[] value) { - return internalMap.put(new ByteArrayWrapper(key), value); + return internalMap.put(new ByteArrayWrapper(key), value); } @SuppressWarnings("unchecked") public void putAll(Map m) { - Iterator iterator = m.entrySet().iterator(); - while (iterator.hasNext()) { - Entry next = (Entry) iterator - .next(); - internalMap.put(new ByteArrayWrapper(next.getKey()), - next.getValue()); - } + Iterator iterator = m.entrySet().iterator(); + while (iterator.hasNext()) { + Entry next = (Entry) iterator + .next(); + internalMap.put(new ByteArrayWrapper(next.getKey()), + next.getValue()); + } } public byte[] remove(Object key) { - if (key instanceof byte[]) - return internalMap.remove(new ByteArrayWrapper((byte[]) key)); - return internalMap.remove(key); + if (key instanceof byte[]) + return internalMap.remove(new ByteArrayWrapper((byte[]) key)); + return internalMap.remove(key); } public int size() { - return internalMap.size(); + return internalMap.size(); } public Collection values() { - return internalMap.values(); + return internalMap.values(); } private static final class ByteArrayWrapper { - private final byte[] data; + private final byte[] data; - public ByteArrayWrapper(byte[] data) { - if (data == null) { - throw new NullPointerException(); - } - this.data = data; - } + public ByteArrayWrapper(byte[] data) { + if (data == null) { + throw new NullPointerException(); + } + this.data = data; + } - public boolean equals(Object other) { - if (!(other instanceof ByteArrayWrapper)) { - return false; - } - return Arrays.equals(data, ((ByteArrayWrapper) other).data); - } + public boolean equals(Object other) { + if (!(other instanceof ByteArrayWrapper)) { + return false; + } + return Arrays.equals(data, ((ByteArrayWrapper) other).data); + } - public int hashCode() { - return Arrays.hashCode(data); - } + public int hashCode() { + return Arrays.hashCode(data); + } } private static final class JedisByteEntry implements Entry { - private byte[] value; - private byte[] key; + private byte[] value; + private byte[] key; - public JedisByteEntry(byte[] key, byte[] value) { - this.key = key; - this.value = value; - } + public JedisByteEntry(byte[] key, byte[] value) { + this.key = key; + this.value = value; + } - public byte[] getKey() { - return this.key; - } + public byte[] getKey() { + return this.key; + } - public byte[] getValue() { - return this.value; - } + public byte[] getValue() { + return this.value; + } - public byte[] setValue(byte[] value) { - this.value = value; - return value; - } + public byte[] setValue(byte[] value) { + this.value = value; + return value; + } } } \ No newline at end of file diff --git a/src/main/java/redis/clients/util/JedisClusterCRC16.java b/src/main/java/redis/clients/util/JedisClusterCRC16.java index 99e434c..a885dfc 100644 --- a/src/main/java/redis/clients/util/JedisClusterCRC16.java +++ b/src/main/java/redis/clients/util/JedisClusterCRC16.java @@ -9,50 +9,50 @@ package redis.clients.util; */ 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, }; + 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("{"); - if (s > -1) { - int e = key.indexOf("}", s + 1); - if (e > -1 && e != s + 1) { - key = key.substring(s + 1, e); - } - } - // optimization with modulo operator with power of 2 - // equivalent to getCRC16(key) % 16384 - return getCRC16(key) & (16384 - 1); + int s = key.indexOf("{"); + if (s > -1) { + int e = key.indexOf("}", s + 1); + if (e > -1 && e != s + 1) { + key = key.substring(s + 1, e); + } + } + // optimization with modulo operator with power of 2 + // equivalent to getCRC16(key) % 16384 + return getCRC16(key) & (16384 - 1); } /** @@ -64,16 +64,16 @@ public class JedisClusterCRC16 { * @see https://github.com/xetorthio/jedis/pull/733#issuecomment-55840331 */ public static int getCRC16(byte[] bytes) { - int crc = 0x0000; + int crc = 0x0000; - for (byte b : bytes) { - crc = ((crc << 8) ^ LOOKUP_TABLE[((crc >>> 8) ^ (b & 0xFF)) & 0xFF]); - } - return crc & 0xFFFF; + for (byte b : bytes) { + crc = ((crc << 8) ^ LOOKUP_TABLE[((crc >>> 8) ^ (b & 0xFF)) & 0xFF]); + } + return crc & 0xFFFF; } public static int getCRC16(String key) { - return getCRC16(SafeEncoder.encode(key)); + return getCRC16(SafeEncoder.encode(key)); } } \ No newline at end of file diff --git a/src/main/java/redis/clients/util/JedisURIHelper.java b/src/main/java/redis/clients/util/JedisURIHelper.java index d2039a8..d63bad5 100644 --- a/src/main/java/redis/clients/util/JedisURIHelper.java +++ b/src/main/java/redis/clients/util/JedisURIHelper.java @@ -4,23 +4,23 @@ import java.net.URI; public class JedisURIHelper { public static String getPassword(URI uri) { - String userInfo = uri.getUserInfo(); - if (userInfo != null) { - return userInfo.split(":", 2)[1]; - } - return null; + String userInfo = uri.getUserInfo(); + if (userInfo != null) { + return userInfo.split(":", 2)[1]; + } + return null; } public static Integer getDBIndex(URI uri) { - String[] pathSplit = uri.getPath().split("/", 2); - if (pathSplit.length > 1) { - String dbIndexStr = pathSplit[1]; - if (dbIndexStr.isEmpty()) { - return 0; - } - return Integer.parseInt(dbIndexStr); - } else { - return 0; - } + String[] pathSplit = uri.getPath().split("/", 2); + if (pathSplit.length > 1) { + String dbIndexStr = pathSplit[1]; + if (dbIndexStr.isEmpty()) { + return 0; + } + return Integer.parseInt(dbIndexStr); + } else { + return 0; + } } } diff --git a/src/main/java/redis/clients/util/MurmurHash.java b/src/main/java/redis/clients/util/MurmurHash.java index 7f6aecd..d8be869 100644 --- a/src/main/java/redis/clients/util/MurmurHash.java +++ b/src/main/java/redis/clients/util/MurmurHash.java @@ -40,7 +40,7 @@ public class MurmurHash implements Hashing { * @return The 32 bit hash of the bytes in question. */ public static int hash(byte[] data, int seed) { - return hash(ByteBuffer.wrap(data), seed); + return hash(ByteBuffer.wrap(data), seed); } /** @@ -57,7 +57,7 @@ public class MurmurHash implements Hashing { * @return The 32-bit hash of the data in question. */ public static int hash(byte[] data, int offset, int length, int seed) { - return hash(ByteBuffer.wrap(data, offset, length), seed); + return hash(ByteBuffer.wrap(data, offset, length), seed); } /** @@ -70,97 +70,97 @@ public class MurmurHash implements Hashing { * @return The 32 bit murmur hash of the bytes in the buffer. */ public static int hash(ByteBuffer buf, int seed) { - // save byte order for later restoration - ByteOrder byteOrder = buf.order(); - buf.order(ByteOrder.LITTLE_ENDIAN); + // save byte order for later restoration + ByteOrder byteOrder = buf.order(); + buf.order(ByteOrder.LITTLE_ENDIAN); - int m = 0x5bd1e995; - int r = 24; + int m = 0x5bd1e995; + int r = 24; - int h = seed ^ buf.remaining(); + int h = seed ^ buf.remaining(); - int k; - while (buf.remaining() >= 4) { - k = buf.getInt(); + int k; + while (buf.remaining() >= 4) { + k = buf.getInt(); - k *= m; - k ^= k >>> r; - k *= m; + k *= m; + k ^= k >>> r; + k *= m; - h *= m; - h ^= k; - } + h *= m; + h ^= k; + } - if (buf.remaining() > 0) { - ByteBuffer finish = ByteBuffer.allocate(4).order( - ByteOrder.LITTLE_ENDIAN); - // for big-endian version, use this first: - // finish.position(4-buf.remaining()); - finish.put(buf).rewind(); - h ^= finish.getInt(); - h *= m; - } + if (buf.remaining() > 0) { + ByteBuffer finish = ByteBuffer.allocate(4).order( + ByteOrder.LITTLE_ENDIAN); + // for big-endian version, use this first: + // finish.position(4-buf.remaining()); + finish.put(buf).rewind(); + h ^= finish.getInt(); + h *= m; + } - h ^= h >>> 13; - h *= m; - h ^= h >>> 15; + h ^= h >>> 13; + h *= m; + h ^= h >>> 15; - buf.order(byteOrder); - return h; + buf.order(byteOrder); + return h; } public static long hash64A(byte[] data, int seed) { - return hash64A(ByteBuffer.wrap(data), seed); + return hash64A(ByteBuffer.wrap(data), seed); } public static long hash64A(byte[] data, int offset, int length, int seed) { - return hash64A(ByteBuffer.wrap(data, offset, length), seed); + return hash64A(ByteBuffer.wrap(data, offset, length), seed); } public static long hash64A(ByteBuffer buf, int seed) { - ByteOrder byteOrder = buf.order(); - buf.order(ByteOrder.LITTLE_ENDIAN); + ByteOrder byteOrder = buf.order(); + buf.order(ByteOrder.LITTLE_ENDIAN); - long m = 0xc6a4a7935bd1e995L; - int r = 47; + long m = 0xc6a4a7935bd1e995L; + int r = 47; - long h = seed ^ (buf.remaining() * m); + long h = seed ^ (buf.remaining() * m); - long k; - while (buf.remaining() >= 8) { - k = buf.getLong(); + long k; + while (buf.remaining() >= 8) { + k = buf.getLong(); - k *= m; - k ^= k >>> r; - k *= m; + k *= m; + k ^= k >>> r; + k *= m; - h ^= k; - h *= m; - } + h ^= k; + h *= m; + } - if (buf.remaining() > 0) { - ByteBuffer finish = ByteBuffer.allocate(8).order( - ByteOrder.LITTLE_ENDIAN); - // for big-endian version, do this first: - // finish.position(8-buf.remaining()); - finish.put(buf).rewind(); - h ^= finish.getLong(); - h *= m; - } + if (buf.remaining() > 0) { + ByteBuffer finish = ByteBuffer.allocate(8).order( + ByteOrder.LITTLE_ENDIAN); + // for big-endian version, do this first: + // finish.position(8-buf.remaining()); + finish.put(buf).rewind(); + h ^= finish.getLong(); + h *= m; + } - h ^= h >>> r; - h *= m; - h ^= h >>> r; + h ^= h >>> r; + h *= m; + h ^= h >>> r; - buf.order(byteOrder); - return h; + buf.order(byteOrder); + return h; } public long hash(byte[] key) { - return hash64A(key, 0x1234ABCD); + return hash64A(key, 0x1234ABCD); } public long hash(String key) { - return hash(SafeEncoder.encode(key)); + return hash(SafeEncoder.encode(key)); } } \ No newline at end of file diff --git a/src/main/java/redis/clients/util/Pool.java b/src/main/java/redis/clients/util/Pool.java index 106f9d5..471c4d9 100644 --- a/src/main/java/redis/clients/util/Pool.java +++ b/src/main/java/redis/clients/util/Pool.java @@ -21,82 +21,82 @@ public abstract class Pool implements Closeable { @Override public void close() { - closeInternalPool(); + closeInternalPool(); } public boolean isClosed() { - return this.internalPool.isClosed(); + return this.internalPool.isClosed(); } public Pool(final GenericObjectPoolConfig poolConfig, - PooledObjectFactory factory) { - initPool(poolConfig, factory); + PooledObjectFactory factory) { + initPool(poolConfig, factory); } public void initPool(final GenericObjectPoolConfig poolConfig, - PooledObjectFactory factory) { + PooledObjectFactory factory) { - if (this.internalPool != null) { - try { - closeInternalPool(); - } catch (Exception e) { - } - } + if (this.internalPool != null) { + try { + closeInternalPool(); + } catch (Exception e) { + } + } - this.internalPool = new GenericObjectPool(factory, poolConfig); + this.internalPool = new GenericObjectPool(factory, poolConfig); } public T getResource() { - try { - return internalPool.borrowObject(); - } catch (Exception e) { - throw new JedisConnectionException( - "Could not get a resource from the pool", e); - } + try { + return internalPool.borrowObject(); + } catch (Exception e) { + throw new JedisConnectionException( + "Could not get a resource from the pool", e); + } } public void returnResourceObject(final T resource) { - if (resource == null) { - return; - } - try { - internalPool.returnObject(resource); - } catch (Exception e) { - throw new JedisException( - "Could not return the resource to the pool", e); - } + if (resource == null) { + return; + } + try { + internalPool.returnObject(resource); + } catch (Exception e) { + throw new JedisException( + "Could not return the resource to the pool", e); + } } public void returnBrokenResource(final T resource) { - if (resource != null) { - returnBrokenResourceObject(resource); - } + if (resource != null) { + returnBrokenResourceObject(resource); + } } public void returnResource(final T resource) { - if (resource != null) { - returnResourceObject(resource); - } + if (resource != null) { + returnResourceObject(resource); + } } public void destroy() { - closeInternalPool(); + closeInternalPool(); } protected void returnBrokenResourceObject(final T resource) { - try { - internalPool.invalidateObject(resource); - } catch (Exception e) { - throw new JedisException( - "Could not return the resource to the pool", e); - } + try { + internalPool.invalidateObject(resource); + } catch (Exception e) { + throw new JedisException( + "Could not return the resource to the pool", e); + } } protected void closeInternalPool() { - try { - internalPool.close(); - } catch (Exception e) { - throw new JedisException("Could not destroy the pool", e); - } + try { + internalPool.close(); + } catch (Exception e) { + throw new JedisException("Could not destroy the pool", e); + } } } diff --git a/src/main/java/redis/clients/util/RedisInputStream.java b/src/main/java/redis/clients/util/RedisInputStream.java index beae73b..797d07c 100644 --- a/src/main/java/redis/clients/util/RedisInputStream.java +++ b/src/main/java/redis/clients/util/RedisInputStream.java @@ -32,83 +32,83 @@ public class RedisInputStream extends FilterInputStream { protected int count, limit; public RedisInputStream(InputStream in, int size) { - super(in); - if (size <= 0) { - throw new IllegalArgumentException("Buffer size <= 0"); - } - buf = new byte[size]; + super(in); + if (size <= 0) { + throw new IllegalArgumentException("Buffer size <= 0"); + } + buf = new byte[size]; } public RedisInputStream(InputStream in) { - this(in, 8192); + this(in, 8192); } public byte readByte() throws JedisConnectionException { - ensureFill(); - return buf[count++]; + ensureFill(); + return buf[count++]; } public String readLine() { - final StringBuilder sb = new StringBuilder(); - while (true) { - ensureFill(); + final StringBuilder sb = new StringBuilder(); + while (true) { + ensureFill(); - byte b = buf[count++]; - if (b == '\r') { - ensureFill(); // Must be one more byte + byte b = buf[count++]; + if (b == '\r') { + ensureFill(); // Must be one more byte - byte c = buf[count++]; - if (c == '\n') { - break; - } - sb.append((char) b); - sb.append((char) c); - } else { - sb.append((char) b); - } - } + byte c = buf[count++]; + if (c == '\n') { + break; + } + sb.append((char) b); + sb.append((char) c); + } else { + sb.append((char) b); + } + } - final String reply = sb.toString(); - if (reply.length() == 0) { - throw new JedisConnectionException("It seems like server has closed the connection."); - } + final String reply = sb.toString(); + if (reply.length() == 0) { + throw new JedisConnectionException("It seems like server has closed the connection."); + } - return reply; + return reply; } public byte[] readLineBytes() { - /* This operation should only require one fill. In that typical - case we optimize allocation and copy of the byte array. In the - edge case where more than one fill is required then we take a - slower path and expand a byte array output stream as is - necessary. */ + /* This operation should only require one fill. In that typical + case we optimize allocation and copy of the byte array. In the + edge case where more than one fill is required then we take a + slower path and expand a byte array output stream as is + necessary. */ - ensureFill(); + ensureFill(); - int pos = count; - final byte[] buf = this.buf; - while (true) { - if (pos == limit) { - return readLineBytesSlowly(); - } + int pos = count; + final byte[] buf = this.buf; + while (true) { + if (pos == limit) { + return readLineBytesSlowly(); + } - if (buf[pos++] == '\r') { - if (pos == limit) { - return readLineBytesSlowly(); - } + if (buf[pos++] == '\r') { + if (pos == limit) { + return readLineBytesSlowly(); + } - if (buf[pos++] == '\n') { - break; - } - } - } + if (buf[pos++] == '\n') { + break; + } + } + } - final int N = (pos - count) - 2; - final byte[] line = new byte[N]; - System.arraycopy(buf, count, line, 0, N); - count = pos; - return line; + final int N = (pos - count) - 2; + final byte[] line = new byte[N]; + System.arraycopy(buf, count, line, 0, N); + count = pos; + return line; } /** @@ -117,80 +117,80 @@ public class RedisInputStream extends FilterInputStream { * into a String. */ private byte[] readLineBytesSlowly() { - ByteArrayOutputStream bout = null; - while (true) { - ensureFill(); + ByteArrayOutputStream bout = null; + while (true) { + ensureFill(); - byte b = buf[count++]; - if (b == '\r') { - ensureFill(); // Must be one more byte + byte b = buf[count++]; + if (b == '\r') { + ensureFill(); // Must be one more byte - byte c = buf[count++]; - if (c == '\n') { - break; - } + byte c = buf[count++]; + if (c == '\n') { + break; + } - if (bout == null) { - bout = new ByteArrayOutputStream(16); - } + if (bout == null) { + bout = new ByteArrayOutputStream(16); + } - bout.write(b); - bout.write(c); - } else { - if (bout == null) { - bout = new ByteArrayOutputStream(16); - } + bout.write(b); + bout.write(c); + } else { + if (bout == null) { + bout = new ByteArrayOutputStream(16); + } - bout.write(b); - } - } + bout.write(b); + } + } - return bout == null ? new byte[0] : bout.toByteArray(); + return bout == null ? new byte[0] : bout.toByteArray(); } public int readIntCrLf() { - return (int)readLongCrLf(); + return (int)readLongCrLf(); } public long readLongCrLf() { - final byte[] buf = this.buf; + final byte[] buf = this.buf; - ensureFill(); + ensureFill(); - final boolean isNeg = buf[count] == '-'; - if (isNeg) { - ++count; - } + final boolean isNeg = buf[count] == '-'; + if (isNeg) { + ++count; + } - long value = 0; - while (true) { - ensureFill(); + long value = 0; + while (true) { + ensureFill(); - final int b = buf[count++]; - if (b == '\r') { - ensureFill(); + final int b = buf[count++]; + if (b == '\r') { + ensureFill(); - if (buf[count++] != '\n') { - throw new JedisConnectionException("Unexpected character!"); - } + if (buf[count++] != '\n') { + throw new JedisConnectionException("Unexpected character!"); + } - break; - } - else { - value = value * 10 + b - '0'; - } - } + break; + } + else { + value = value * 10 + b - '0'; + } + } - return (isNeg ? -value : value); + return (isNeg ? -value : value); } public int read(byte[] b, int off, int len) throws JedisConnectionException { - ensureFill(); + ensureFill(); - final int length = Math.min(limit - count, len); - System.arraycopy(buf, count, b, off, length); - count += length; - return length; + final int length = Math.min(limit - count, len); + System.arraycopy(buf, count, b, off, length); + count += length; + return length; } /** @@ -199,16 +199,16 @@ public class RedisInputStream extends FilterInputStream { * was smaller than expected. */ private void ensureFill() throws JedisConnectionException { - if (count >= limit) { - try { - limit = in.read(buf); - count = 0; - if (limit == -1) { - throw new JedisConnectionException("Unexpected end of stream."); - } - } catch (IOException e) { - throw new JedisConnectionException(e); - } - } + if (count >= limit) { + try { + limit = in.read(buf); + count = 0; + if (limit == -1) { + throw new JedisConnectionException("Unexpected end of stream."); + } + } catch (IOException e) { + throw new JedisConnectionException(e); + } + } } } diff --git a/src/main/java/redis/clients/util/RedisOutputStream.java b/src/main/java/redis/clients/util/RedisOutputStream.java index dcec7fa..47caf0d 100644 --- a/src/main/java/redis/clients/util/RedisOutputStream.java +++ b/src/main/java/redis/clients/util/RedisOutputStream.java @@ -15,212 +15,212 @@ public final class RedisOutputStream extends FilterOutputStream { protected int count; public RedisOutputStream(final OutputStream out) { - this(out, 8192); + this(out, 8192); } public RedisOutputStream(final OutputStream out, final int size) { - super(out); - if (size <= 0) { - throw new IllegalArgumentException("Buffer size <= 0"); - } - buf = new byte[size]; + super(out); + if (size <= 0) { + throw new IllegalArgumentException("Buffer size <= 0"); + } + buf = new byte[size]; } private void flushBuffer() throws IOException { - if (count > 0) { - out.write(buf, 0, count); - count = 0; - } + if (count > 0) { + out.write(buf, 0, count); + count = 0; + } } public void write(final byte b) throws IOException { - if (count == buf.length) { - flushBuffer(); - } - buf[count++] = b; + if (count == buf.length) { + flushBuffer(); + } + buf[count++] = b; } public void write(final byte[] b) throws IOException { - write(b, 0, b.length); + write(b, 0, b.length); } public void write(final byte b[], final int off, final int len) - throws IOException { - if (len >= buf.length) { - flushBuffer(); - out.write(b, off, len); - } else { - if (len >= buf.length - count) { - flushBuffer(); - } + throws IOException { + if (len >= buf.length) { + flushBuffer(); + out.write(b, off, len); + } else { + if (len >= buf.length - count) { + flushBuffer(); + } - System.arraycopy(b, off, buf, count, len); - count += len; - } + System.arraycopy(b, off, buf, count, len); + count += len; + } } public void writeAsciiCrLf(final String in) throws IOException { - final int size = in.length(); + final int size = in.length(); - for (int i = 0; i != size; ++i) { - if (count == buf.length) { - flushBuffer(); - } - buf[count++] = (byte) in.charAt(i); - } + for (int i = 0; i != size; ++i) { + if (count == buf.length) { + flushBuffer(); + } + buf[count++] = (byte) in.charAt(i); + } - writeCrLf(); + writeCrLf(); } public static boolean isSurrogate(final char ch) { - return ch >= Character.MIN_SURROGATE && ch <= Character.MAX_SURROGATE; + return ch >= Character.MIN_SURROGATE && ch <= Character.MAX_SURROGATE; } public static int utf8Length(final String str) { - int strLen = str.length(), utfLen = 0; - for (int i = 0; i != strLen; ++i) { - char c = str.charAt(i); - if (c < 0x80) { - utfLen++; - } else if (c < 0x800) { - utfLen += 2; - } else if (isSurrogate(c)) { - i++; - utfLen += 4; - } else { - utfLen += 3; - } - } - return utfLen; + int strLen = str.length(), utfLen = 0; + for (int i = 0; i != strLen; ++i) { + char c = str.charAt(i); + if (c < 0x80) { + utfLen++; + } else if (c < 0x800) { + utfLen += 2; + } else if (isSurrogate(c)) { + i++; + utfLen += 4; + } else { + utfLen += 3; + } + } + return utfLen; } public void writeCrLf() throws IOException { - if (2 >= buf.length - count) { - flushBuffer(); - } + if (2 >= buf.length - count) { + flushBuffer(); + } - buf[count++] = '\r'; - buf[count++] = '\n'; + buf[count++] = '\r'; + buf[count++] = '\n'; } public void writeUtf8CrLf(final String str) throws IOException { - int strLen = str.length(); + int strLen = str.length(); - int i; - for (i = 0; i < strLen; i++) { - char c = str.charAt(i); - if (!(c < 0x80)) - break; - if (count == buf.length) { - flushBuffer(); - } - buf[count++] = (byte) c; - } + int i; + for (i = 0; i < strLen; i++) { + char c = str.charAt(i); + if (!(c < 0x80)) + break; + if (count == buf.length) { + flushBuffer(); + } + buf[count++] = (byte) c; + } - for (; i < strLen; i++) { - char c = str.charAt(i); - if (c < 0x80) { - if (count == buf.length) { - flushBuffer(); - } - buf[count++] = (byte) c; - } else if (c < 0x800) { - if (2 >= buf.length - count) { - flushBuffer(); - } - buf[count++] = (byte) (0xc0 | (c >> 6)); - buf[count++] = (byte) (0x80 | (c & 0x3f)); - } else if (isSurrogate(c)) { - if (4 >= buf.length - count) { - flushBuffer(); - } - int uc = Character.toCodePoint(c, str.charAt(i++)); - buf[count++] = ((byte) (0xf0 | ((uc >> 18)))); - buf[count++] = ((byte) (0x80 | ((uc >> 12) & 0x3f))); - buf[count++] = ((byte) (0x80 | ((uc >> 6) & 0x3f))); - buf[count++] = ((byte) (0x80 | (uc & 0x3f))); - } else { - if (3 >= buf.length - count) { - flushBuffer(); - } - buf[count++] = ((byte) (0xe0 | ((c >> 12)))); - buf[count++] = ((byte) (0x80 | ((c >> 6) & 0x3f))); - buf[count++] = ((byte) (0x80 | (c & 0x3f))); - } - } + for (; i < strLen; i++) { + char c = str.charAt(i); + if (c < 0x80) { + if (count == buf.length) { + flushBuffer(); + } + buf[count++] = (byte) c; + } else if (c < 0x800) { + if (2 >= buf.length - count) { + flushBuffer(); + } + buf[count++] = (byte) (0xc0 | (c >> 6)); + buf[count++] = (byte) (0x80 | (c & 0x3f)); + } else if (isSurrogate(c)) { + if (4 >= buf.length - count) { + flushBuffer(); + } + int uc = Character.toCodePoint(c, str.charAt(i++)); + buf[count++] = ((byte) (0xf0 | ((uc >> 18)))); + buf[count++] = ((byte) (0x80 | ((uc >> 12) & 0x3f))); + buf[count++] = ((byte) (0x80 | ((uc >> 6) & 0x3f))); + buf[count++] = ((byte) (0x80 | (uc & 0x3f))); + } else { + if (3 >= buf.length - count) { + flushBuffer(); + } + buf[count++] = ((byte) (0xe0 | ((c >> 12)))); + buf[count++] = ((byte) (0x80 | ((c >> 6) & 0x3f))); + buf[count++] = ((byte) (0x80 | (c & 0x3f))); + } + } - writeCrLf(); + writeCrLf(); } private final static int[] sizeTable = { 9, 99, 999, 9999, 99999, 999999, - 9999999, 99999999, 999999999, Integer.MAX_VALUE }; + 9999999, 99999999, 999999999, Integer.MAX_VALUE }; private final static byte[] DigitTens = { '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '1', '1', '1', '1', '1', '1', '1', '1', '1', - '1', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '3', '3', - '3', '3', '3', '3', '3', '3', '3', '3', '4', '4', '4', '4', '4', - '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '5', '5', '5', - '5', '5', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '7', - '7', '7', '7', '7', '7', '7', '7', '7', '7', '8', '8', '8', '8', - '8', '8', '8', '8', '8', '8', '9', '9', '9', '9', '9', '9', '9', - '9', '9', '9', }; + '0', '0', '0', '0', '1', '1', '1', '1', '1', '1', '1', '1', '1', + '1', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '3', '3', + '3', '3', '3', '3', '3', '3', '3', '3', '4', '4', '4', '4', '4', + '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '5', '5', '5', + '5', '5', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '7', + '7', '7', '7', '7', '7', '7', '7', '7', '7', '8', '8', '8', '8', + '8', '8', '8', '8', '8', '8', '9', '9', '9', '9', '9', '9', '9', + '9', '9', '9', }; private final static byte[] DigitOnes = { '0', '1', '2', '3', '4', '5', - '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', - '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', - '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', - '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', - '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', - '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', - '7', '8', '9', }; + '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', + '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', + '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', + '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', + '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', + '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', + '7', '8', '9', }; private final static byte[] digits = { '0', '1', '2', '3', '4', '5', '6', - '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', - 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', - 'x', 'y', 'z' }; + '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', + 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + 'x', 'y', 'z' }; public void writeIntCrLf(int value) throws IOException { - if (value < 0) { - write((byte) '-'); - value = -value; - } + if (value < 0) { + write((byte) '-'); + value = -value; + } - int size = 0; - while (value > sizeTable[size]) - size++; + int size = 0; + while (value > sizeTable[size]) + size++; - size++; - if (size >= buf.length - count) { - flushBuffer(); - } + size++; + if (size >= buf.length - count) { + flushBuffer(); + } - int q, r; - int charPos = count + size; + int q, r; + int charPos = count + size; - while (value >= 65536) { - q = value / 100; - r = value - ((q << 6) + (q << 5) + (q << 2)); - value = q; - buf[--charPos] = DigitOnes[r]; - buf[--charPos] = DigitTens[r]; - } + while (value >= 65536) { + q = value / 100; + r = value - ((q << 6) + (q << 5) + (q << 2)); + value = q; + buf[--charPos] = DigitOnes[r]; + buf[--charPos] = DigitTens[r]; + } - for (;;) { - q = (value * 52429) >>> (16 + 3); - r = value - ((q << 3) + (q << 1)); - buf[--charPos] = digits[r]; - value = q; - if (value == 0) - break; - } - count += size; + for (;;) { + q = (value * 52429) >>> (16 + 3); + r = value - ((q << 3) + (q << 1)); + buf[--charPos] = digits[r]; + value = q; + if (value == 0) + break; + } + count += size; - writeCrLf(); + writeCrLf(); } public void flush() throws IOException { - flushBuffer(); - out.flush(); + flushBuffer(); + out.flush(); } } diff --git a/src/main/java/redis/clients/util/SafeEncoder.java b/src/main/java/redis/clients/util/SafeEncoder.java index 9ec0a7c..32b3482 100644 --- a/src/main/java/redis/clients/util/SafeEncoder.java +++ b/src/main/java/redis/clients/util/SafeEncoder.java @@ -12,30 +12,30 @@ import redis.clients.jedis.exceptions.JedisException; */ public class SafeEncoder { public static byte[][] encodeMany(final String... strs) { - byte[][] many = new byte[strs.length][]; - for (int i = 0; i < strs.length; i++) { - many[i] = encode(strs[i]); - } - return many; + byte[][] many = new byte[strs.length][]; + for (int i = 0; i < strs.length; i++) { + many[i] = encode(strs[i]); + } + return many; } public static byte[] encode(final String str) { - try { - if (str == null) { - throw new JedisDataException( - "value sent to redis cannot be null"); - } - return str.getBytes(Protocol.CHARSET); - } catch (UnsupportedEncodingException e) { - throw new JedisException(e); - } + try { + if (str == null) { + throw new JedisDataException( + "value sent to redis cannot be null"); + } + return str.getBytes(Protocol.CHARSET); + } catch (UnsupportedEncodingException e) { + throw new JedisException(e); + } } public static String encode(final byte[] data) { - try { - return new String(data, Protocol.CHARSET); - } catch (UnsupportedEncodingException e) { - throw new JedisException(e); - } + try { + return new String(data, Protocol.CHARSET); + } catch (UnsupportedEncodingException e) { + throw new JedisException(e); + } } } diff --git a/src/main/java/redis/clients/util/ShardInfo.java b/src/main/java/redis/clients/util/ShardInfo.java index ded32ae..8980f6e 100644 --- a/src/main/java/redis/clients/util/ShardInfo.java +++ b/src/main/java/redis/clients/util/ShardInfo.java @@ -7,11 +7,11 @@ public abstract class ShardInfo { } public ShardInfo(int weight) { - this.weight = weight; + this.weight = weight; } public int getWeight() { - return this.weight; + return this.weight; } protected abstract T createResource(); diff --git a/src/main/java/redis/clients/util/Sharded.java b/src/main/java/redis/clients/util/Sharded.java index 98c74de..e2a92a5 100644 --- a/src/main/java/redis/clients/util/Sharded.java +++ b/src/main/java/redis/clients/util/Sharded.java @@ -26,68 +26,68 @@ public class Sharded> { private Pattern tagPattern = null; // the tag is anything between {} public static final Pattern DEFAULT_KEY_TAG_PATTERN = Pattern - .compile("\\{(.+?)\\}"); + .compile("\\{(.+?)\\}"); public Sharded(List shards) { - this(shards, Hashing.MURMUR_HASH); // MD5 is really not good as we works - // with 64-bits not 128 + this(shards, Hashing.MURMUR_HASH); // MD5 is really not good as we works + // with 64-bits not 128 } public Sharded(List shards, Hashing algo) { - this.algo = algo; - initialize(shards); + this.algo = algo; + initialize(shards); } public Sharded(List shards, Pattern tagPattern) { - this(shards, Hashing.MURMUR_HASH, tagPattern); // MD5 is really not good - // as we works with - // 64-bits not 128 + this(shards, Hashing.MURMUR_HASH, tagPattern); // MD5 is really not good + // as we works with + // 64-bits not 128 } public Sharded(List shards, Hashing algo, Pattern tagPattern) { - this.algo = algo; - this.tagPattern = tagPattern; - initialize(shards); + this.algo = algo; + this.tagPattern = tagPattern; + initialize(shards); } private void initialize(List shards) { - nodes = new TreeMap(); + nodes = new TreeMap(); - for (int i = 0; i != shards.size(); ++i) { - final S shardInfo = shards.get(i); - if (shardInfo.getName() == null) - for (int n = 0; n < 160 * shardInfo.getWeight(); n++) { - nodes.put(this.algo.hash("SHARD-" + i + "-NODE-" + n), - shardInfo); - } - else - for (int n = 0; n < 160 * shardInfo.getWeight(); n++) { - nodes.put( - this.algo.hash(shardInfo.getName() + "*" - + shardInfo.getWeight() + n), shardInfo); - } - resources.put(shardInfo, shardInfo.createResource()); - } + for (int i = 0; i != shards.size(); ++i) { + final S shardInfo = shards.get(i); + if (shardInfo.getName() == null) + for (int n = 0; n < 160 * shardInfo.getWeight(); n++) { + nodes.put(this.algo.hash("SHARD-" + i + "-NODE-" + n), + shardInfo); + } + else + for (int n = 0; n < 160 * shardInfo.getWeight(); n++) { + nodes.put( + this.algo.hash(shardInfo.getName() + "*" + + shardInfo.getWeight() + n), shardInfo); + } + resources.put(shardInfo, shardInfo.createResource()); + } } public R getShard(byte[] key) { - return resources.get(getShardInfo(key)); + return resources.get(getShardInfo(key)); } public R getShard(String key) { - return resources.get(getShardInfo(key)); + return resources.get(getShardInfo(key)); } public S getShardInfo(byte[] key) { - SortedMap tail = nodes.tailMap(algo.hash(key)); - if (tail.isEmpty()) { - return nodes.get(nodes.firstKey()); - } - return tail.get(tail.firstKey()); + SortedMap tail = nodes.tailMap(algo.hash(key)); + if (tail.isEmpty()) { + return nodes.get(nodes.firstKey()); + } + return tail.get(tail.firstKey()); } public S getShardInfo(String key) { - return getShardInfo(SafeEncoder.encode(getKeyTag(key))); + return getShardInfo(SafeEncoder.encode(getKeyTag(key))); } /** @@ -100,19 +100,19 @@ public class Sharded> { * @return The tag if it exists, or the original key */ public String getKeyTag(String key) { - if (tagPattern != null) { - Matcher m = tagPattern.matcher(key); - if (m.find()) - return m.group(1); - } - return key; + if (tagPattern != null) { + Matcher m = tagPattern.matcher(key); + if (m.find()) + return m.group(1); + } + return key; } public Collection getAllShardInfo() { - return Collections.unmodifiableCollection(nodes.values()); + return Collections.unmodifiableCollection(nodes.values()); } public Collection getAllShards() { - return Collections.unmodifiableCollection(resources.values()); + return Collections.unmodifiableCollection(resources.values()); } } diff --git a/src/main/java/redis/clients/util/Slowlog.java b/src/main/java/redis/clients/util/Slowlog.java index 6e286d9..3fe2042 100644 --- a/src/main/java/redis/clients/util/Slowlog.java +++ b/src/main/java/redis/clients/util/Slowlog.java @@ -11,43 +11,43 @@ public class Slowlog { @SuppressWarnings("unchecked") public static List from(List nestedMultiBulkReply) { - List logs = new ArrayList(nestedMultiBulkReply.size()); - for (Object obj : nestedMultiBulkReply) { - List properties = (List) obj; - logs.add(new Slowlog(properties)); - } + List logs = new ArrayList(nestedMultiBulkReply.size()); + for (Object obj : nestedMultiBulkReply) { + List properties = (List) obj; + logs.add(new Slowlog(properties)); + } - return logs; + return logs; } @SuppressWarnings("unchecked") private Slowlog(List properties) { - super(); - this.id = (Long) properties.get(0); - this.timeStamp = (Long) properties.get(1); - this.executionTime = (Long) properties.get(2); + super(); + this.id = (Long) properties.get(0); + this.timeStamp = (Long) properties.get(1); + this.executionTime = (Long) properties.get(2); - List bargs = (List) properties.get(3); - this.args = new ArrayList(bargs.size()); + List bargs = (List) properties.get(3); + this.args = new ArrayList(bargs.size()); - for (byte[] barg : bargs) { - this.args.add(SafeEncoder.encode(barg)); - } + for (byte[] barg : bargs) { + this.args.add(SafeEncoder.encode(barg)); + } } public long getId() { - return id; + return id; } public long getTimeStamp() { - return timeStamp; + return timeStamp; } public long getExecutionTime() { - return executionTime; + return executionTime; } public List getArgs() { - return args; + return args; } } diff --git a/src/test/java/redis/clients/jedis/tests/BuilderFactoryTest.java b/src/test/java/redis/clients/jedis/tests/BuilderFactoryTest.java index 4521112..e178f45 100644 --- a/src/test/java/redis/clients/jedis/tests/BuilderFactoryTest.java +++ b/src/test/java/redis/clients/jedis/tests/BuilderFactoryTest.java @@ -8,7 +8,7 @@ import redis.clients.jedis.BuilderFactory; public class BuilderFactoryTest extends Assert { @Test public void buildDouble() { - Double build = BuilderFactory.DOUBLE.build("1.0".getBytes()); - assertEquals(new Double(1.0), build); + Double build = BuilderFactory.DOUBLE.build("1.0".getBytes()); + assertEquals(new Double(1.0), build); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/ConnectionCloseTest.java b/src/test/java/redis/clients/jedis/tests/ConnectionCloseTest.java index 119c56e..0110302 100644 --- a/src/test/java/redis/clients/jedis/tests/ConnectionCloseTest.java +++ b/src/test/java/redis/clients/jedis/tests/ConnectionCloseTest.java @@ -14,31 +14,31 @@ public class ConnectionCloseTest extends Assert { @Before public void setUp() throws Exception { - client = new Connection(); + client = new Connection(); } @After public void tearDown() throws Exception { - client.close(); + client.close(); } @Test(expected = JedisConnectionException.class) public void checkUnkownHost() { - client.setHost("someunknownhost"); - client.connect(); + client.setHost("someunknownhost"); + client.connect(); } @Test(expected = JedisConnectionException.class) public void checkWrongPort() { - client.setHost("localhost"); - client.setPort(55665); - client.connect(); + client.setHost("localhost"); + client.setPort(55665); + client.connect(); } @Test public void connectIfNotConnectedWhenSettingTimeoutInfinite() { - client.setHost("localhost"); - client.setPort(6379); - client.setTimeoutInfinite(); + client.setHost("localhost"); + client.setPort(6379); + client.setTimeoutInfinite(); } } diff --git a/src/test/java/redis/clients/jedis/tests/ConnectionTest.java b/src/test/java/redis/clients/jedis/tests/ConnectionTest.java index d6175a5..11d3cbc 100644 --- a/src/test/java/redis/clients/jedis/tests/ConnectionTest.java +++ b/src/test/java/redis/clients/jedis/tests/ConnectionTest.java @@ -13,39 +13,39 @@ public class ConnectionTest extends Assert { @Before public void setUp() throws Exception { - client = new Connection(); + client = new Connection(); } @After public void tearDown() throws Exception { - client.disconnect(); + client.disconnect(); } @Test(expected = JedisConnectionException.class) public void checkUnkownHost() { - client.setHost("someunknownhost"); - client.connect(); + client.setHost("someunknownhost"); + client.connect(); } @Test(expected = JedisConnectionException.class) public void checkWrongPort() { - client.setHost("localhost"); - client.setPort(55665); - client.connect(); + client.setHost("localhost"); + client.setPort(55665); + client.connect(); } @Test public void connectIfNotConnectedWhenSettingTimeoutInfinite() { - client.setHost("localhost"); - client.setPort(6379); - client.setTimeoutInfinite(); + client.setHost("localhost"); + client.setPort(6379); + client.setTimeoutInfinite(); } @Test public void checkCloseable() { - client.setHost("localhost"); - client.setPort(6379); - client.connect(); - client.close(); + client.setHost("localhost"); + client.setPort(6379); + client.connect(); + client.close(); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/FragmentedByteArrayInputStream.java b/src/test/java/redis/clients/jedis/tests/FragmentedByteArrayInputStream.java index fdf8d13..908b004 100644 --- a/src/test/java/redis/clients/jedis/tests/FragmentedByteArrayInputStream.java +++ b/src/test/java/redis/clients/jedis/tests/FragmentedByteArrayInputStream.java @@ -9,22 +9,22 @@ public class FragmentedByteArrayInputStream extends ByteArrayInputStream { private int readMethodCallCount = 0; public FragmentedByteArrayInputStream(final byte[] buf) { - super(buf); + super(buf); } public synchronized int read(final byte[] b, final int off, final int len) { - readMethodCallCount++; - if (len <= 10) { - // if the len <= 10, return as usual .. - return super.read(b, off, len); - } else { - // else return the first half .. - return super.read(b, off, len / 2); - } + readMethodCallCount++; + if (len <= 10) { + // if the len <= 10, return as usual .. + return super.read(b, off, len); + } else { + // else return the first half .. + return super.read(b, off, len / 2); + } } public int getReadMethodCallCount() { - return readMethodCallCount; + return readMethodCallCount; } } diff --git a/src/test/java/redis/clients/jedis/tests/HostAndPortUtil.java b/src/test/java/redis/clients/jedis/tests/HostAndPortUtil.java index 0ff0871..8ba615d 100644 --- a/src/test/java/redis/clients/jedis/tests/HostAndPortUtil.java +++ b/src/test/java/redis/clients/jedis/tests/HostAndPortUtil.java @@ -12,93 +12,93 @@ public class HostAndPortUtil { private static List clusterHostAndPortList = new ArrayList(); 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)); - clusterHostAndPortList.add(new HostAndPort("localhost", 7381)); - clusterHostAndPortList.add(new HostAndPort("localhost", 7382)); - clusterHostAndPortList.add(new HostAndPort("localhost", 7383)); - clusterHostAndPortList.add(new HostAndPort("localhost", 7384)); + clusterHostAndPortList.add(new HostAndPort("localhost", 7379)); + clusterHostAndPortList.add(new HostAndPort("localhost", 7380)); + clusterHostAndPortList.add(new HostAndPort("localhost", 7381)); + clusterHostAndPortList.add(new HostAndPort("localhost", 7382)); + clusterHostAndPortList.add(new HostAndPort("localhost", 7383)); + clusterHostAndPortList.add(new HostAndPort("localhost", 7384)); - String envRedisHosts = System.getProperty("redis-hosts"); - String envSentinelHosts = System.getProperty("sentinel-hosts"); - String envClusterHosts = System.getProperty("cluster-hosts"); + String envRedisHosts = System.getProperty("redis-hosts"); + String envSentinelHosts = System.getProperty("sentinel-hosts"); + String envClusterHosts = System.getProperty("cluster-hosts"); - redisHostAndPortList = parseHosts(envRedisHosts, redisHostAndPortList); - sentinelHostAndPortList = parseHosts(envSentinelHosts, - sentinelHostAndPortList); - clusterHostAndPortList = parseHosts(envClusterHosts, - clusterHostAndPortList); + redisHostAndPortList = parseHosts(envRedisHosts, redisHostAndPortList); + sentinelHostAndPortList = parseHosts(envSentinelHosts, + sentinelHostAndPortList); + clusterHostAndPortList = parseHosts(envClusterHosts, + clusterHostAndPortList); } public static List parseHosts(String envHosts, - List existingHostsAndPorts) { + List existingHostsAndPorts) { - if (null != envHosts && 0 < envHosts.length()) { + if (null != envHosts && 0 < envHosts.length()) { - String[] hostDefs = envHosts.split(","); + String[] hostDefs = envHosts.split(","); - if (null != hostDefs && 2 <= hostDefs.length) { + if (null != hostDefs && 2 <= hostDefs.length) { - List envHostsAndPorts = new ArrayList( - hostDefs.length); + List envHostsAndPorts = new ArrayList( + hostDefs.length); - for (String hostDef : hostDefs) { + for (String hostDef : hostDefs) { - String[] hostAndPort = hostDef.split(":"); + String[] hostAndPort = hostDef.split(":"); - if (null != hostAndPort && 2 == hostAndPort.length) { - String host = hostAndPort[0]; - int port = Protocol.DEFAULT_PORT; + if (null != hostAndPort && 2 == hostAndPort.length) { + String host = hostAndPort[0]; + int port = Protocol.DEFAULT_PORT; - try { - port = Integer.parseInt(hostAndPort[1]); - } catch (final NumberFormatException nfe) { - } + try { + port = Integer.parseInt(hostAndPort[1]); + } catch (final NumberFormatException nfe) { + } - envHostsAndPorts.add(new HostAndPort(host, port)); - } - } + envHostsAndPorts.add(new HostAndPort(host, port)); + } + } - return envHostsAndPorts; - } - } + return envHostsAndPorts; + } + } - return existingHostsAndPorts; + return existingHostsAndPorts; } public static List getRedisServers() { - return redisHostAndPortList; + return redisHostAndPortList; } public static List getSentinelServers() { - return sentinelHostAndPortList; + return sentinelHostAndPortList; } public static List getClusterServers() { - return clusterHostAndPortList; + return clusterHostAndPortList; } } diff --git a/src/test/java/redis/clients/jedis/tests/JedisClusterNodeInformationParserTest.java b/src/test/java/redis/clients/jedis/tests/JedisClusterNodeInformationParserTest.java index d30cbc9..f392357 100644 --- a/src/test/java/redis/clients/jedis/tests/JedisClusterNodeInformationParserTest.java +++ b/src/test/java/redis/clients/jedis/tests/JedisClusterNodeInformationParserTest.java @@ -13,52 +13,52 @@ public class JedisClusterNodeInformationParserTest extends Assert { @Before public void setUp() { - parser = new ClusterNodeInformationParser(); + parser = new ClusterNodeInformationParser(); } @Test public void testParseNodeMyself() { - String nodeInfo = "9b0d2ab38ee31482c95fdb2c7847a0d40e88d518 :7379 myself,master - 0 0 1 connected 0-5460"; - HostAndPort current = new HostAndPort("localhost", 7379); - ClusterNodeInformation clusterNodeInfo = parser - .parse(nodeInfo, current); - assertEquals(clusterNodeInfo.getNode(), current); + String nodeInfo = "9b0d2ab38ee31482c95fdb2c7847a0d40e88d518 :7379 myself,master - 0 0 1 connected 0-5460"; + HostAndPort current = new HostAndPort("localhost", 7379); + ClusterNodeInformation clusterNodeInfo = parser + .parse(nodeInfo, current); + assertEquals(clusterNodeInfo.getNode(), current); } @Test public void testParseNormalState() { - String nodeInfo = "5f4a2236d00008fba7ac0dd24b95762b446767bd 192.168.0.3:7380 master - 0 1400598804016 2 connected 5461-10922"; - HostAndPort current = new HostAndPort("localhost", 7379); - ClusterNodeInformation clusterNodeInfo = parser - .parse(nodeInfo, current); - assertNotEquals(clusterNodeInfo.getNode(), current); - assertEquals(clusterNodeInfo.getNode(), new HostAndPort("192.168.0.3", - 7380)); + String nodeInfo = "5f4a2236d00008fba7ac0dd24b95762b446767bd 192.168.0.3:7380 master - 0 1400598804016 2 connected 5461-10922"; + HostAndPort current = new HostAndPort("localhost", 7379); + ClusterNodeInformation clusterNodeInfo = parser + .parse(nodeInfo, current); + assertNotEquals(clusterNodeInfo.getNode(), current); + assertEquals(clusterNodeInfo.getNode(), new HostAndPort("192.168.0.3", + 7380)); - for (int slot = 5461; slot <= 10922; slot++) { - assertTrue(clusterNodeInfo.getAvailableSlots().contains(slot)); - } + for (int slot = 5461; slot <= 10922; slot++) { + assertTrue(clusterNodeInfo.getAvailableSlots().contains(slot)); + } - assertTrue(clusterNodeInfo.getSlotsBeingImported().isEmpty()); - assertTrue(clusterNodeInfo.getSlotsBeingMigrated().isEmpty()); + assertTrue(clusterNodeInfo.getSlotsBeingImported().isEmpty()); + assertTrue(clusterNodeInfo.getSlotsBeingMigrated().isEmpty()); } @Test public void testParseSlotBeingMigrated() { - String nodeInfo = "5f4a2236d00008fba7ac0dd24b95762b446767bd :7379 myself,master - 0 0 1 connected 0-5459 [5460->-5f4a2236d00008fba7ac0dd24b95762b446767bd] [5461-<-5f4a2236d00008fba7ac0dd24b95762b446767bd]"; - HostAndPort current = new HostAndPort("localhost", 7379); - ClusterNodeInformation clusterNodeInfo = parser - .parse(nodeInfo, current); - assertEquals(clusterNodeInfo.getNode(), current); + String nodeInfo = "5f4a2236d00008fba7ac0dd24b95762b446767bd :7379 myself,master - 0 0 1 connected 0-5459 [5460->-5f4a2236d00008fba7ac0dd24b95762b446767bd] [5461-<-5f4a2236d00008fba7ac0dd24b95762b446767bd]"; + HostAndPort current = new HostAndPort("localhost", 7379); + ClusterNodeInformation clusterNodeInfo = parser + .parse(nodeInfo, current); + assertEquals(clusterNodeInfo.getNode(), current); - for (int slot = 0; slot <= 5459; slot++) { - assertTrue(clusterNodeInfo.getAvailableSlots().contains(slot)); - } + for (int slot = 0; slot <= 5459; slot++) { + assertTrue(clusterNodeInfo.getAvailableSlots().contains(slot)); + } - assertEquals(1, clusterNodeInfo.getSlotsBeingMigrated().size()); - assertTrue(clusterNodeInfo.getSlotsBeingMigrated().contains(5460)); - assertEquals(1, clusterNodeInfo.getSlotsBeingImported().size()); - assertTrue(clusterNodeInfo.getSlotsBeingImported().contains(5461)); + assertEquals(1, clusterNodeInfo.getSlotsBeingMigrated().size()); + assertTrue(clusterNodeInfo.getSlotsBeingMigrated().contains(5460)); + assertEquals(1, clusterNodeInfo.getSlotsBeingImported().size()); + assertTrue(clusterNodeInfo.getSlotsBeingImported().contains(5461)); } } diff --git a/src/test/java/redis/clients/jedis/tests/JedisClusterTest.java b/src/test/java/redis/clients/jedis/tests/JedisClusterTest.java index f006c66..7d8ad60 100644 --- a/src/test/java/redis/clients/jedis/tests/JedisClusterTest.java +++ b/src/test/java/redis/clients/jedis/tests/JedisClusterTest.java @@ -49,110 +49,110 @@ public class JedisClusterTest extends Assert { @Before public void setUp() throws InterruptedException { - node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort()); - node1.connect(); - node1.flushAll(); + node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort()); + node1.connect(); + node1.flushAll(); - node2 = new Jedis(nodeInfo2.getHost(), nodeInfo2.getPort()); - node2.connect(); - node2.flushAll(); + node2 = new Jedis(nodeInfo2.getHost(), nodeInfo2.getPort()); + node2.connect(); + node2.flushAll(); - node3 = new Jedis(nodeInfo3.getHost(), nodeInfo3.getPort()); - node3.connect(); - node3.flushAll(); + node3 = new Jedis(nodeInfo3.getHost(), nodeInfo3.getPort()); + node3.connect(); + node3.flushAll(); - node4 = new Jedis(nodeInfo4.getHost(), nodeInfo4.getPort()); - node4.connect(); - node4.flushAll(); + node4 = new Jedis(nodeInfo4.getHost(), nodeInfo4.getPort()); + node4.connect(); + node4.flushAll(); - // ---- configure cluster + // ---- configure cluster - // add nodes to cluster - node1.clusterMeet(localHost, nodeInfo2.getPort()); - node1.clusterMeet(localHost, nodeInfo3.getPort()); + // add nodes to cluster + node1.clusterMeet(localHost, nodeInfo2.getPort()); + node1.clusterMeet(localHost, nodeInfo3.getPort()); - // split available slots across the three nodes - int slotsPerNode = JedisCluster.HASHSLOTS / 3; - int[] node1Slots = new int[slotsPerNode]; - int[] node2Slots = new int[slotsPerNode + 1]; - int[] node3Slots = new int[slotsPerNode]; - for (int i = 0, slot1 = 0, slot2 = 0, slot3 = 0; i < JedisCluster.HASHSLOTS; i++) { - if (i < slotsPerNode) { - node1Slots[slot1++] = i; - } else if (i > slotsPerNode * 2) { - node3Slots[slot3++] = i; - } else { - node2Slots[slot2++] = i; - } - } + // split available slots across the three nodes + int slotsPerNode = JedisCluster.HASHSLOTS / 3; + int[] node1Slots = new int[slotsPerNode]; + int[] node2Slots = new int[slotsPerNode + 1]; + int[] node3Slots = new int[slotsPerNode]; + for (int i = 0, slot1 = 0, slot2 = 0, slot3 = 0; i < JedisCluster.HASHSLOTS; i++) { + if (i < slotsPerNode) { + node1Slots[slot1++] = i; + } else if (i > slotsPerNode * 2) { + node3Slots[slot3++] = i; + } else { + node2Slots[slot2++] = i; + } + } - node1.clusterAddSlots(node1Slots); - node2.clusterAddSlots(node2Slots); - node3.clusterAddSlots(node3Slots); + node1.clusterAddSlots(node1Slots); + node2.clusterAddSlots(node2Slots); + node3.clusterAddSlots(node3Slots); - JedisClusterTestUtil.waitForClusterReady(node1, node2, node3); + JedisClusterTestUtil.waitForClusterReady(node1, node2, node3); } @AfterClass public static void cleanUp() { - node1.flushDB(); - node2.flushDB(); - node3.flushDB(); - node4.flushDB(); - node1.clusterReset(Reset.SOFT); - node2.clusterReset(Reset.SOFT); - node3.clusterReset(Reset.SOFT); - node4.clusterReset(Reset.SOFT); + node1.flushDB(); + node2.flushDB(); + node3.flushDB(); + node4.flushDB(); + node1.clusterReset(Reset.SOFT); + node2.clusterReset(Reset.SOFT); + node3.clusterReset(Reset.SOFT); + node4.clusterReset(Reset.SOFT); } @After public void tearDown() throws InterruptedException { - cleanUp(); + cleanUp(); } @Test(expected = JedisMovedDataException.class) public void testThrowMovedException() { - node1.set("foo", "bar"); + node1.set("foo", "bar"); } @Test public void testMovedExceptionParameters() { - try { - node1.set("foo", "bar"); - } catch (JedisMovedDataException jme) { - assertEquals(12182, jme.getSlot()); - assertEquals(new HostAndPort("127.0.0.1", 7381), - jme.getTargetNode()); - return; - } - fail(); + try { + node1.set("foo", "bar"); + } catch (JedisMovedDataException jme) { + assertEquals(12182, jme.getSlot()); + assertEquals(new HostAndPort("127.0.0.1", 7381), + jme.getTargetNode()); + return; + } + fail(); } @Test(expected = JedisAskDataException.class) public void testThrowAskException() { - int keySlot = JedisClusterCRC16.getSlot("test"); - String node3Id = JedisClusterTestUtil.getNodeId(node3.clusterNodes()); - node2.clusterSetSlotMigrating(keySlot, node3Id); - node2.get("test"); + int keySlot = JedisClusterCRC16.getSlot("test"); + String node3Id = JedisClusterTestUtil.getNodeId(node3.clusterNodes()); + node2.clusterSetSlotMigrating(keySlot, node3Id); + node2.get("test"); } @Test public void testDiscoverNodesAutomatically() { - Set jedisClusterNode = new HashSet(); - jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); - JedisCluster jc = new JedisCluster(jedisClusterNode); - assertEquals(3, jc.getClusterNodes().size()); + Set jedisClusterNode = new HashSet(); + jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); + JedisCluster jc = new JedisCluster(jedisClusterNode); + assertEquals(3, jc.getClusterNodes().size()); } @Test public void testCalculateConnectionPerSlot() { - Set jedisClusterNode = new HashSet(); - jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); - JedisCluster jc = new JedisCluster(jedisClusterNode); - jc.set("foo", "bar"); - jc.set("test", "test"); - assertEquals("bar", node3.get("foo")); - assertEquals("test", node2.get("test")); + Set jedisClusterNode = new HashSet(); + jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); + JedisCluster jc = new JedisCluster(jedisClusterNode); + jc.set("foo", "bar"); + jc.set("test", "test"); + assertEquals("bar", node3.get("foo")); + assertEquals("test", node2.get("test")); } /** @@ -160,389 +160,389 @@ public class JedisClusterTest extends Assert { */ @Test public void testMigrate() { - log.info("test migrate slot"); - Set jedisClusterNode = new HashSet(); - jedisClusterNode.add(nodeInfo1); - JedisCluster jc = new JedisCluster(jedisClusterNode); - String node3Id = JedisClusterTestUtil.getNodeId(node3.clusterNodes()); - String node2Id = JedisClusterTestUtil.getNodeId(node2.clusterNodes()); - node3.clusterSetSlotMigrating(15363, node2Id); - node2.clusterSetSlotImporting(15363, node3Id); - try { - node2.set("e", "e"); - } catch (JedisMovedDataException jme) { - assertEquals(15363, jme.getSlot()); - assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()), - jme.getTargetNode()); - } + log.info("test migrate slot"); + Set jedisClusterNode = new HashSet(); + jedisClusterNode.add(nodeInfo1); + JedisCluster jc = new JedisCluster(jedisClusterNode); + String node3Id = JedisClusterTestUtil.getNodeId(node3.clusterNodes()); + String node2Id = JedisClusterTestUtil.getNodeId(node2.clusterNodes()); + node3.clusterSetSlotMigrating(15363, node2Id); + node2.clusterSetSlotImporting(15363, node3Id); + try { + node2.set("e", "e"); + } catch (JedisMovedDataException jme) { + assertEquals(15363, jme.getSlot()); + 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()); - } + try { + node3.set("e", "e"); + } catch (JedisAskDataException jae) { + assertEquals(15363, jae.getSlot()); + assertEquals(new HostAndPort(localHost, nodeInfo2.getPort()), + jae.getTargetNode()); + } - jc.set("e", "e"); + jc.set("e", "e"); - try { - node2.get("e"); - } catch (JedisMovedDataException jme) { - assertEquals(15363, jme.getSlot()); - 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()); - } + try { + node2.get("e"); + } catch (JedisMovedDataException jme) { + assertEquals(15363, jme.getSlot()); + 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("e", jc.get("e")); + assertEquals("e", jc.get("e")); - node2.clusterSetSlotNode(15363, node2Id); - node3.clusterSetSlotNode(15363, node2Id); - // assertEquals("e", jc.get("e")); - assertEquals("e", node2.get("e")); + node2.clusterSetSlotNode(15363, node2Id); + node3.clusterSetSlotNode(15363, node2Id); + // assertEquals("e", jc.get("e")); + assertEquals("e", node2.get("e")); - // assertEquals("e", node3.get("e")); + // assertEquals("e", node3.get("e")); } @Test public void testMigrateToNewNode() throws InterruptedException { - log.info("test migrate slot to new node"); - Set jedisClusterNode = new HashSet(); - jedisClusterNode.add(nodeInfo1); - JedisCluster jc = new JedisCluster(jedisClusterNode); - node4.clusterMeet(localHost, nodeInfo1.getPort()); + log.info("test migrate slot to new node"); + Set jedisClusterNode = new HashSet(); + jedisClusterNode.add(nodeInfo1); + JedisCluster jc = new JedisCluster(jedisClusterNode); + node4.clusterMeet(localHost, nodeInfo1.getPort()); - String node3Id = JedisClusterTestUtil.getNodeId(node3.clusterNodes()); - String node4Id = JedisClusterTestUtil.getNodeId(node4.clusterNodes()); - JedisClusterTestUtil.waitForClusterReady(node4); - node3.clusterSetSlotMigrating(15363, node4Id); - node4.clusterSetSlotImporting(15363, node3Id); - try { - node4.set("e", "e"); - } catch (JedisMovedDataException jme) { - assertEquals(15363, jme.getSlot()); - assertEquals(new HostAndPort(localHost, nodeInfo3.getPort()), - jme.getTargetNode()); - } + String node3Id = JedisClusterTestUtil.getNodeId(node3.clusterNodes()); + String node4Id = JedisClusterTestUtil.getNodeId(node4.clusterNodes()); + JedisClusterTestUtil.waitForClusterReady(node4); + node3.clusterSetSlotMigrating(15363, node4Id); + node4.clusterSetSlotImporting(15363, node3Id); + try { + node4.set("e", "e"); + } catch (JedisMovedDataException jme) { + assertEquals(15363, jme.getSlot()); + 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()); - } + try { + node3.set("e", "e"); + } catch (JedisAskDataException jae) { + assertEquals(15363, jae.getSlot()); + assertEquals(new HostAndPort(localHost, nodeInfo4.getPort()), + jae.getTargetNode()); + } - jc.set("e", "e"); + jc.set("e", "e"); - try { - node4.get("e"); - } catch (JedisMovedDataException jme) { - assertEquals(15363, jme.getSlot()); - 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()); - } + try { + node4.get("e"); + } catch (JedisMovedDataException jme) { + assertEquals(15363, jme.getSlot()); + 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("e", jc.get("e")); + assertEquals("e", jc.get("e")); - node4.clusterSetSlotNode(15363, node4Id); - node3.clusterSetSlotNode(15363, node4Id); - // assertEquals("e", jc.get("e")); - assertEquals("e", node4.get("e")); + node4.clusterSetSlotNode(15363, node4Id); + node3.clusterSetSlotNode(15363, node4Id); + // assertEquals("e", jc.get("e")); + assertEquals("e", node4.get("e")); - // assertEquals("e", node3.get("e")); + // assertEquals("e", node3.get("e")); } @Test public void testRecalculateSlotsWhenMoved() throws InterruptedException { - Set jedisClusterNode = new HashSet(); - jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); - JedisCluster jc = new JedisCluster(jedisClusterNode); - int slot51 = JedisClusterCRC16.getSlot("51"); - node2.clusterDelSlots(slot51); - node3.clusterDelSlots(slot51); - node3.clusterAddSlots(slot51); + Set jedisClusterNode = new HashSet(); + jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); + JedisCluster jc = new JedisCluster(jedisClusterNode); + int slot51 = JedisClusterCRC16.getSlot("51"); + node2.clusterDelSlots(slot51); + node3.clusterDelSlots(slot51); + node3.clusterAddSlots(slot51); - JedisClusterTestUtil.waitForClusterReady(node1, node2, node3); - jc.set("51", "foo"); - assertEquals("foo", jc.get("51")); + JedisClusterTestUtil.waitForClusterReady(node1, node2, node3); + jc.set("51", "foo"); + assertEquals("foo", jc.get("51")); } @Test public void testAskResponse() throws InterruptedException { - Set jedisClusterNode = new HashSet(); - 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())); - jc.set("51", "foo"); - assertEquals("foo", jc.get("51")); + Set jedisClusterNode = new HashSet(); + 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())); + jc.set("51", "foo"); + assertEquals("foo", jc.get("51")); } @Test(expected = JedisClusterException.class) public void testThrowExceptionWithoutKey() { - Set jedisClusterNode = new HashSet(); - jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); - JedisCluster jc = new JedisCluster(jedisClusterNode); - jc.ping(); + Set jedisClusterNode = new HashSet(); + jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); + JedisCluster jc = new JedisCluster(jedisClusterNode); + jc.ping(); } @Test(expected = JedisClusterMaxRedirectionsException.class) public void testRedisClusterMaxRedirections() { - Set jedisClusterNode = new HashSet(); - jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); - JedisCluster jc = new JedisCluster(jedisClusterNode); - int slot51 = JedisClusterCRC16.getSlot("51"); - // This will cause an infinite redirection loop - node2.clusterSetSlotMigrating(slot51, - JedisClusterTestUtil.getNodeId(node3.clusterNodes())); - jc.set("51", "foo"); + Set jedisClusterNode = new HashSet(); + jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); + JedisCluster jc = new JedisCluster(jedisClusterNode); + int slot51 = JedisClusterCRC16.getSlot("51"); + // This will cause an infinite redirection loop + 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 public void testClusterForgetNode() throws InterruptedException { - // at first, join node4 to cluster - node1.clusterMeet("127.0.0.1", nodeInfo4.getPort()); + // at first, join node4 to cluster + node1.clusterMeet("127.0.0.1", nodeInfo4.getPort()); - String node7Id = JedisClusterTestUtil.getNodeId(node4.clusterNodes()); + String node7Id = JedisClusterTestUtil.getNodeId(node4.clusterNodes()); - JedisClusterTestUtil.assertNodeIsKnown(node3, node7Id, 1000); - JedisClusterTestUtil.assertNodeIsKnown(node2, node7Id, 1000); - JedisClusterTestUtil.assertNodeIsKnown(node1, node7Id, 1000); + JedisClusterTestUtil.assertNodeIsKnown(node3, node7Id, 1000); + JedisClusterTestUtil.assertNodeIsKnown(node2, node7Id, 1000); + JedisClusterTestUtil.assertNodeIsKnown(node1, node7Id, 1000); - assertNodeHandshakeEnded(node3, 1000); - assertNodeHandshakeEnded(node2, 1000); - assertNodeHandshakeEnded(node1, 1000); + assertNodeHandshakeEnded(node3, 1000); + assertNodeHandshakeEnded(node2, 1000); + assertNodeHandshakeEnded(node1, 1000); - assertEquals(4, node1.clusterNodes().split("\n").length); - assertEquals(4, node2.clusterNodes().split("\n").length); - assertEquals(4, node3.clusterNodes().split("\n").length); + assertEquals(4, node1.clusterNodes().split("\n").length); + assertEquals(4, node2.clusterNodes().split("\n").length); + assertEquals(4, node3.clusterNodes().split("\n").length); - // do cluster forget - node1.clusterForget(node7Id); - node2.clusterForget(node7Id); - node3.clusterForget(node7Id); + // do cluster forget + node1.clusterForget(node7Id); + node2.clusterForget(node7Id); + node3.clusterForget(node7Id); - JedisClusterTestUtil.assertNodeIsUnknown(node1, node7Id, 1000); - JedisClusterTestUtil.assertNodeIsUnknown(node2, node7Id, 1000); - JedisClusterTestUtil.assertNodeIsUnknown(node3, node7Id, 1000); + JedisClusterTestUtil.assertNodeIsUnknown(node1, node7Id, 1000); + JedisClusterTestUtil.assertNodeIsUnknown(node2, node7Id, 1000); + JedisClusterTestUtil.assertNodeIsUnknown(node3, node7Id, 1000); - assertEquals(3, node1.clusterNodes().split("\n").length); - assertEquals(3, node2.clusterNodes().split("\n").length); - assertEquals(3, node3.clusterNodes().split("\n").length); + assertEquals(3, node1.clusterNodes().split("\n").length); + assertEquals(3, node2.clusterNodes().split("\n").length); + assertEquals(3, node3.clusterNodes().split("\n").length); } @Test public void testClusterFlushSlots() { - String slotRange = getNodeServingSlotRange(node1.clusterNodes()); - assertNotNull(slotRange); + String slotRange = getNodeServingSlotRange(node1.clusterNodes()); + assertNotNull(slotRange); - try { - node1.clusterFlushSlots(); - assertNull(getNodeServingSlotRange(node1.clusterNodes())); - } finally { - // rollback - String[] rangeInfo = slotRange.split("-"); - int lower = Integer.parseInt(rangeInfo[0]); - int upper = Integer.parseInt(rangeInfo[1]); + try { + node1.clusterFlushSlots(); + assertNull(getNodeServingSlotRange(node1.clusterNodes())); + } finally { + // rollback + String[] rangeInfo = slotRange.split("-"); + int lower = Integer.parseInt(rangeInfo[0]); + int upper = Integer.parseInt(rangeInfo[1]); - int[] node1Slots = new int[upper - lower + 1]; - for (int i = 0; lower <= upper;) { - node1Slots[i++] = lower++; - } - node1.clusterAddSlots(node1Slots); - } + int[] node1Slots = new int[upper - lower + 1]; + for (int i = 0; lower <= upper;) { + node1Slots[i++] = lower++; + } + node1.clusterAddSlots(node1Slots); + } } @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")); + // 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")); } @Test public void testClusterCountKeysInSlot() { - Set jedisClusterNode = new HashSet(); - jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1 - .getPort())); - JedisCluster jc = new JedisCluster(jedisClusterNode); + Set jedisClusterNode = new HashSet(); + jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1 + .getPort())); + JedisCluster jc = new JedisCluster(jedisClusterNode); - for (int index = 0; index < 5; index++) { - jc.set("foo{bar}" + index, "hello"); - } + for (int index = 0; index < 5; index++) { + jc.set("foo{bar}" + index, "hello"); + } - int slot = JedisClusterCRC16.getSlot("foo{bar}"); - assertEquals(5, node1.clusterCountKeysInSlot(slot).intValue()); + int slot = JedisClusterCRC16.getSlot("foo{bar}"); + assertEquals(5, node1.clusterCountKeysInSlot(slot).intValue()); } @Test public void testStableSlotWhenMigratingNodeOrImportingNodeIsNotSpecified() - throws InterruptedException { - Set jedisClusterNode = new HashSet(); - jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1 - .getPort())); - JedisCluster jc = new JedisCluster(jedisClusterNode); + throws InterruptedException { + Set jedisClusterNode = new HashSet(); + 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) + 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())); - assertEquals("foo", jc.get("51")); - node3.clusterSetSlotStable(slot51); - assertEquals("foo", jc.get("51")); + 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())); - // assertEquals("foo", jc.get("51")); // it leads Max Redirections - node2.clusterSetSlotStable(slot51); - assertEquals("foo", jc.get("51")); + node2.clusterSetSlotMigrating(slot51, + JedisClusterTestUtil.getNodeId(node3.clusterNodes())); + // assertEquals("foo", jc.get("51")); // it leads Max Redirections + node2.clusterSetSlotStable(slot51); + assertEquals("foo", jc.get("51")); } @Test(expected = JedisConnectionException.class) public void testIfPoolConfigAppliesToClusterPools() { - GenericObjectPoolConfig config = new GenericObjectPoolConfig(); - config.setMaxTotal(0); - config.setMaxWaitMillis(2000); - Set jedisClusterNode = new HashSet(); - jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); - JedisCluster jc = new JedisCluster(jedisClusterNode, config); - jc.set("52", "poolTestValue"); + GenericObjectPoolConfig config = new GenericObjectPoolConfig(); + config.setMaxTotal(0); + config.setMaxWaitMillis(2000); + Set jedisClusterNode = new HashSet(); + jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); + JedisCluster jc = new JedisCluster(jedisClusterNode, config); + jc.set("52", "poolTestValue"); } @Test public void testCloseable() { - Set jedisClusterNode = new HashSet(); - jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1 - .getPort())); + Set jedisClusterNode = new HashSet(); + jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1 + .getPort())); - JedisCluster jc = null; - try { - jc = new JedisCluster(jedisClusterNode); - jc.set("51", "foo"); - } finally { - if (jc != null) { - jc.close(); - } - } + JedisCluster jc = null; + try { + jc = new JedisCluster(jedisClusterNode); + jc.set("51", "foo"); + } finally { + if (jc != null) { + jc.close(); + } + } - Iterator poolIterator = jc.getClusterNodes().values() - .iterator(); - while (poolIterator.hasNext()) { - JedisPool pool = poolIterator.next(); - try { - pool.getResource(); - fail("JedisCluster's internal pools should be already destroyed"); - } catch (JedisConnectionException e) { - // ok to go... - } - } + Iterator poolIterator = jc.getClusterNodes().values() + .iterator(); + while (poolIterator.hasNext()) { + JedisPool pool = poolIterator.next(); + try { + pool.getResource(); + fail("JedisCluster's internal pools should be already destroyed"); + } catch (JedisConnectionException e) { + // ok to go... + } + } } @Test public void testJedisClusterRunsWithMultithreaded() - throws InterruptedException, ExecutionException { - Set jedisClusterNode = new HashSet(); - jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379)); - final JedisCluster jc = new JedisCluster(jedisClusterNode); - jc.set("foo", "bar"); + throws InterruptedException, ExecutionException { + Set jedisClusterNode = new HashSet(); + 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(10)); - List> futures = new ArrayList>(); - for (int i = 0; i < 50; i++) { - executor.submit(new Callable() { - @Override - public String call() throws Exception { - // FIXME : invalidate slot cache from JedisCluster to test - // random connection also does work - return jc.get("foo"); - } - }); - } + ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 100, 0, + TimeUnit.SECONDS, new ArrayBlockingQueue(10)); + List> futures = new ArrayList>(); + for (int i = 0; i < 50; i++) { + executor.submit(new Callable() { + @Override + public String call() throws Exception { + // FIXME : invalidate slot cache from JedisCluster to test + // random connection also does work + return jc.get("foo"); + } + }); + } - for (Future future : futures) { - String value = future.get(); - assertEquals("bar", value); - } + for (Future future : futures) { + String value = future.get(); + assertEquals("bar", value); + } - jc.close(); + jc.close(); } private static String getNodeServingSlotRange(String infoOutput) { - // f4f3dc4befda352a4e0beccf29f5e8828438705d 127.0.0.1:7380 master - 0 - // 1394372400827 0 connected 5461-10922 - for (String infoLine : infoOutput.split("\n")) { - if (infoLine.contains("myself")) { - try { - return infoLine.split(" ")[8]; - } catch (ArrayIndexOutOfBoundsException e) { - return null; - } - } - } - return null; + // f4f3dc4befda352a4e0beccf29f5e8828438705d 127.0.0.1:7380 master - 0 + // 1394372400827 0 connected 5461-10922 + for (String infoLine : infoOutput.split("\n")) { + if (infoLine.contains("myself")) { + try { + return infoLine.split(" ")[8]; + } catch (ArrayIndexOutOfBoundsException e) { + return null; + } + } + } + return null; } private void assertNodeHandshakeEnded(Jedis node, int timeoutMs) { - int sleepInterval = 100; - for (int sleepTime = 0; sleepTime <= timeoutMs; sleepTime += sleepInterval) { - boolean isHandshaking = isAnyNodeHandshaking(node); - if (!isHandshaking) - return; + int sleepInterval = 100; + for (int sleepTime = 0; sleepTime <= timeoutMs; sleepTime += sleepInterval) { + boolean isHandshaking = isAnyNodeHandshaking(node); + if (!isHandshaking) + return; - try { - Thread.sleep(sleepInterval); - } catch (InterruptedException e) { - } - } + try { + Thread.sleep(sleepInterval); + } catch (InterruptedException e) { + } + } - throw new JedisException("Node handshaking is not ended"); + throw new JedisException("Node handshaking is not ended"); } private boolean isAnyNodeHandshaking(Jedis node) { - String infoOutput = node.clusterNodes(); - for (String infoLine : infoOutput.split("\n")) { - if (infoLine.contains("handshake")) { - return true; - } - } - return false; + String infoOutput = node.clusterNodes(); + for (String infoLine : infoOutput.split("\n")) { + if (infoLine.contains("handshake")) { + return true; + } + } + return false; } } diff --git a/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java b/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java index 5a6fc6c..5464e91 100644 --- a/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java +++ b/src/test/java/redis/clients/jedis/tests/JedisPoolTest.java @@ -24,191 +24,191 @@ public class JedisPoolTest extends Assert { @Test public void checkConnections() { - JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), - hnp.getPort(), 2000); - Jedis jedis = pool.getResource(); - jedis.auth("foobared"); - jedis.set("foo", "bar"); - assertEquals("bar", jedis.get("foo")); - pool.returnResource(jedis); - pool.destroy(); - assertTrue(pool.isClosed()); + JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), + hnp.getPort(), 2000); + Jedis jedis = pool.getResource(); + jedis.auth("foobared"); + jedis.set("foo", "bar"); + assertEquals("bar", jedis.get("foo")); + pool.returnResource(jedis); + pool.destroy(); + assertTrue(pool.isClosed()); } @Test public void checkCloseableConnections() throws Exception { - JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), - hnp.getPort(), 2000); - Jedis jedis = pool.getResource(); - jedis.auth("foobared"); - jedis.set("foo", "bar"); - assertEquals("bar", jedis.get("foo")); - pool.returnResource(jedis); - pool.close(); - assertTrue(pool.isClosed()); + JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), + hnp.getPort(), 2000); + Jedis jedis = pool.getResource(); + jedis.auth("foobared"); + jedis.set("foo", "bar"); + assertEquals("bar", jedis.get("foo")); + pool.returnResource(jedis); + pool.close(); + assertTrue(pool.isClosed()); } @Test public void checkConnectionWithDefaultPort() { - JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), - hnp.getPort()); - Jedis jedis = pool.getResource(); - jedis.auth("foobared"); - jedis.set("foo", "bar"); - assertEquals("bar", jedis.get("foo")); - pool.returnResource(jedis); - pool.destroy(); - assertTrue(pool.isClosed()); + JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), + hnp.getPort()); + Jedis jedis = pool.getResource(); + jedis.auth("foobared"); + jedis.set("foo", "bar"); + assertEquals("bar", jedis.get("foo")); + pool.returnResource(jedis); + pool.destroy(); + assertTrue(pool.isClosed()); } @Test public void checkJedisIsReusedWhenReturned() { - JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), - hnp.getPort()); - Jedis jedis = pool.getResource(); - jedis.auth("foobared"); - jedis.set("foo", "0"); - pool.returnResource(jedis); + JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), + hnp.getPort()); + Jedis jedis = pool.getResource(); + jedis.auth("foobared"); + jedis.set("foo", "0"); + pool.returnResource(jedis); - jedis = pool.getResource(); - jedis.auth("foobared"); - jedis.incr("foo"); - pool.returnResource(jedis); - pool.destroy(); - assertTrue(pool.isClosed()); + jedis = pool.getResource(); + jedis.auth("foobared"); + jedis.incr("foo"); + pool.returnResource(jedis); + pool.destroy(); + assertTrue(pool.isClosed()); } @Test public void checkPoolRepairedWhenJedisIsBroken() { - JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), - hnp.getPort()); - Jedis jedis = pool.getResource(); - jedis.auth("foobared"); - jedis.quit(); - pool.returnBrokenResource(jedis); + JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), + hnp.getPort()); + Jedis jedis = pool.getResource(); + jedis.auth("foobared"); + jedis.quit(); + pool.returnBrokenResource(jedis); - jedis = pool.getResource(); - jedis.auth("foobared"); - jedis.incr("foo"); - pool.returnResource(jedis); - pool.destroy(); - assertTrue(pool.isClosed()); + jedis = pool.getResource(); + jedis.auth("foobared"); + jedis.incr("foo"); + pool.returnResource(jedis); + pool.destroy(); + assertTrue(pool.isClosed()); } @Test(expected = JedisConnectionException.class) public void checkPoolOverflow() { - GenericObjectPoolConfig config = new GenericObjectPoolConfig(); - config.setMaxTotal(1); - config.setBlockWhenExhausted(false); - JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort()); - Jedis jedis = pool.getResource(); - jedis.auth("foobared"); - jedis.set("foo", "0"); + GenericObjectPoolConfig config = new GenericObjectPoolConfig(); + config.setMaxTotal(1); + config.setBlockWhenExhausted(false); + JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort()); + Jedis jedis = pool.getResource(); + jedis.auth("foobared"); + jedis.set("foo", "0"); - Jedis newJedis = pool.getResource(); - newJedis.auth("foobared"); - newJedis.incr("foo"); + Jedis newJedis = pool.getResource(); + newJedis.auth("foobared"); + newJedis.incr("foo"); } @Test public void securePool() { - JedisPoolConfig config = new JedisPoolConfig(); - config.setTestOnBorrow(true); - JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), - 2000, "foobared"); - Jedis jedis = pool.getResource(); - jedis.set("foo", "bar"); - pool.returnResource(jedis); - pool.destroy(); - assertTrue(pool.isClosed()); + JedisPoolConfig config = new JedisPoolConfig(); + config.setTestOnBorrow(true); + JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), + 2000, "foobared"); + Jedis jedis = pool.getResource(); + jedis.set("foo", "bar"); + pool.returnResource(jedis); + pool.destroy(); + assertTrue(pool.isClosed()); } @Test public void nonDefaultDatabase() { - JedisPool pool0 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), - hnp.getPort(), 2000, "foobared"); - Jedis jedis0 = pool0.getResource(); - jedis0.set("foo", "bar"); - assertEquals("bar", jedis0.get("foo")); - pool0.returnResource(jedis0); - pool0.destroy(); - assertTrue(pool0.isClosed()); + JedisPool pool0 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), + hnp.getPort(), 2000, "foobared"); + Jedis jedis0 = pool0.getResource(); + jedis0.set("foo", "bar"); + assertEquals("bar", jedis0.get("foo")); + pool0.returnResource(jedis0); + pool0.destroy(); + assertTrue(pool0.isClosed()); - JedisPool pool1 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), - hnp.getPort(), 2000, "foobared", 1); - Jedis jedis1 = pool1.getResource(); - assertNull(jedis1.get("foo")); - pool1.returnResource(jedis1); - pool1.destroy(); - assertTrue(pool1.isClosed()); + JedisPool pool1 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), + hnp.getPort(), 2000, "foobared", 1); + Jedis jedis1 = pool1.getResource(); + assertNull(jedis1.get("foo")); + pool1.returnResource(jedis1); + pool1.destroy(); + assertTrue(pool1.isClosed()); } @Test public void startWithUrlString() { - Jedis j = new Jedis("localhost", 6380); - j.auth("foobared"); - j.select(2); - j.set("foo", "bar"); - JedisPool pool = new JedisPool("redis://:foobared@localhost:6380/2"); - Jedis jedis = pool.getResource(); - assertEquals("PONG", jedis.ping()); - assertEquals("bar", jedis.get("foo")); + Jedis j = new Jedis("localhost", 6380); + j.auth("foobared"); + j.select(2); + j.set("foo", "bar"); + JedisPool pool = new JedisPool("redis://:foobared@localhost:6380/2"); + Jedis jedis = pool.getResource(); + assertEquals("PONG", jedis.ping()); + assertEquals("bar", jedis.get("foo")); } @Test public void startWithUrl() throws URISyntaxException { - Jedis j = new Jedis("localhost", 6380); - j.auth("foobared"); - j.select(2); - j.set("foo", "bar"); - JedisPool pool = new JedisPool(new URI( - "redis://:foobared@localhost:6380/2")); - Jedis jedis = pool.getResource(); - assertEquals("PONG", jedis.ping()); - assertEquals("bar", jedis.get("foo")); + Jedis j = new Jedis("localhost", 6380); + j.auth("foobared"); + j.select(2); + j.set("foo", "bar"); + JedisPool pool = new JedisPool(new URI( + "redis://:foobared@localhost:6380/2")); + Jedis jedis = pool.getResource(); + assertEquals("PONG", jedis.ping()); + assertEquals("bar", jedis.get("foo")); } @Test public void allowUrlWithNoDBAndNoPassword() throws URISyntaxException { - new JedisPool("redis://localhost:6380"); - new JedisPool(new URI("redis://localhost:6380")); + new JedisPool("redis://localhost:6380"); + new JedisPool(new URI("redis://localhost:6380")); } @Test public void selectDatabaseOnActivation() { - JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), - hnp.getPort(), 2000, "foobared"); + JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), + hnp.getPort(), 2000, "foobared"); - Jedis jedis0 = pool.getResource(); - assertEquals(0L, jedis0.getDB().longValue()); + Jedis jedis0 = pool.getResource(); + assertEquals(0L, jedis0.getDB().longValue()); - jedis0.select(1); - assertEquals(1L, jedis0.getDB().longValue()); + jedis0.select(1); + assertEquals(1L, jedis0.getDB().longValue()); - pool.returnResource(jedis0); + pool.returnResource(jedis0); - Jedis jedis1 = pool.getResource(); - assertTrue("Jedis instance was not reused", jedis1 == jedis0); - assertEquals(0L, jedis1.getDB().longValue()); + Jedis jedis1 = pool.getResource(); + assertTrue("Jedis instance was not reused", jedis1 == jedis0); + assertEquals(0L, jedis1.getDB().longValue()); - pool.returnResource(jedis1); - pool.destroy(); - assertTrue(pool.isClosed()); + pool.returnResource(jedis1); + pool.destroy(); + assertTrue(pool.isClosed()); } @Test public void customClientName() { - JedisPool pool0 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), - hnp.getPort(), 2000, "foobared", 0, "my_shiny_client_name"); + JedisPool pool0 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), + hnp.getPort(), 2000, "foobared", 0, "my_shiny_client_name"); - Jedis jedis = pool0.getResource(); + Jedis jedis = pool0.getResource(); - assertEquals("my_shiny_client_name", jedis.clientGetname()); + assertEquals("my_shiny_client_name", jedis.clientGetname()); - pool0.returnResource(jedis); - pool0.destroy(); - assertTrue(pool0.isClosed()); + pool0.returnResource(jedis); + pool0.destroy(); + assertTrue(pool0.isClosed()); } @Test @@ -263,99 +263,99 @@ public class JedisPoolTest extends Assert { @Test public void returnResourceShouldResetState() { - GenericObjectPoolConfig config = new GenericObjectPoolConfig(); - config.setMaxTotal(1); - config.setBlockWhenExhausted(false); - JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), - 2000, "foobared"); + GenericObjectPoolConfig config = new GenericObjectPoolConfig(); + config.setMaxTotal(1); + config.setBlockWhenExhausted(false); + JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), + 2000, "foobared"); - Jedis jedis = pool.getResource(); - try { - jedis.set("hello", "jedis"); - Transaction t = jedis.multi(); - t.set("hello", "world"); - } finally { - jedis.close(); - } + Jedis jedis = pool.getResource(); + try { + jedis.set("hello", "jedis"); + Transaction t = jedis.multi(); + t.set("hello", "world"); + } finally { + jedis.close(); + } - Jedis jedis2 = pool.getResource(); - try { - assertTrue(jedis == jedis2); - assertEquals("jedis", jedis2.get("hello")); - } finally { - jedis2.close(); - } + Jedis jedis2 = pool.getResource(); + try { + assertTrue(jedis == jedis2); + assertEquals("jedis", jedis2.get("hello")); + } finally { + jedis2.close(); + } - pool.destroy(); - assertTrue(pool.isClosed()); + pool.destroy(); + assertTrue(pool.isClosed()); } @Test public void checkResourceIsCloseable() { - GenericObjectPoolConfig config = new GenericObjectPoolConfig(); - config.setMaxTotal(1); - config.setBlockWhenExhausted(false); - JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), - 2000, "foobared"); + GenericObjectPoolConfig config = new GenericObjectPoolConfig(); + config.setMaxTotal(1); + config.setBlockWhenExhausted(false); + JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), + 2000, "foobared"); - Jedis jedis = pool.getResource(); - try { - jedis.set("hello", "jedis"); - } finally { - jedis.close(); - } + Jedis jedis = pool.getResource(); + try { + jedis.set("hello", "jedis"); + } finally { + jedis.close(); + } - Jedis jedis2 = pool.getResource(); - try { - assertEquals(jedis, jedis2); - } finally { - jedis2.close(); - } + Jedis jedis2 = pool.getResource(); + try { + assertEquals(jedis, jedis2); + } finally { + jedis2.close(); + } } @Test public void returnNullObjectShouldNotFail() { - JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), - hnp.getPort(), 2000, "foobared", 0, "my_shiny_client_name"); + JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), + hnp.getPort(), 2000, "foobared", 0, "my_shiny_client_name"); - pool.returnBrokenResource(null); - pool.returnResource(null); - pool.returnResourceObject(null); + pool.returnBrokenResource(null); + pool.returnResource(null); + pool.returnResourceObject(null); } @Test public void getNumActiveIsNegativeWhenPoolIsClosed() { - JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), - hnp.getPort(), 2000, "foobared", 0, "my_shiny_client_name"); + JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), + hnp.getPort(), 2000, "foobared", 0, "my_shiny_client_name"); - pool.destroy(); - assertTrue(pool.getNumActive() < 0); + pool.destroy(); + assertTrue(pool.getNumActive() < 0); } @Test public void getNumActiveReturnsTheCorrectNumber() { - JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), - hnp.getPort(), 2000); - Jedis jedis = pool.getResource(); - jedis.auth("foobared"); - jedis.set("foo", "bar"); - assertEquals("bar", jedis.get("foo")); + JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), + hnp.getPort(), 2000); + Jedis jedis = pool.getResource(); + jedis.auth("foobared"); + jedis.set("foo", "bar"); + assertEquals("bar", jedis.get("foo")); - assertEquals(1, pool.getNumActive()); + assertEquals(1, pool.getNumActive()); - Jedis jedis2 = pool.getResource(); - jedis.auth("foobared"); - jedis.set("foo", "bar"); + Jedis jedis2 = pool.getResource(); + jedis.auth("foobared"); + jedis.set("foo", "bar"); - assertEquals(2, pool.getNumActive()); + assertEquals(2, pool.getNumActive()); - pool.returnResource(jedis); - assertEquals(1, pool.getNumActive()); + pool.returnResource(jedis); + assertEquals(1, pool.getNumActive()); - pool.returnResource(jedis2); + pool.returnResource(jedis2); - assertEquals(0, pool.getNumActive()); + assertEquals(0, pool.getNumActive()); - pool.destroy(); + pool.destroy(); } } diff --git a/src/test/java/redis/clients/jedis/tests/JedisSentinelPoolTest.java b/src/test/java/redis/clients/jedis/tests/JedisSentinelPoolTest.java index 0d620dd..4bee8fa 100644 --- a/src/test/java/redis/clients/jedis/tests/JedisSentinelPoolTest.java +++ b/src/test/java/redis/clients/jedis/tests/JedisSentinelPoolTest.java @@ -19,14 +19,14 @@ public class JedisSentinelPoolTest extends JedisTestBase { private static final String MASTER_NAME = "mymaster"; protected static HostAndPort master = HostAndPortUtil.getRedisServers() - .get(2); + .get(2); protected static HostAndPort slave1 = HostAndPortUtil.getRedisServers() - .get(3); + .get(3); protected static HostAndPort sentinel1 = HostAndPortUtil - .getSentinelServers().get(1); + .getSentinelServers().get(1); protected static HostAndPort sentinel2 = HostAndPortUtil - .getSentinelServers().get(3); + .getSentinelServers().get(3); protected static Jedis sentinelJedis1; protected static Jedis sentinelJedis2; @@ -35,188 +35,188 @@ public class JedisSentinelPoolTest extends JedisTestBase { @Before public void setUp() throws Exception { - sentinels.add(sentinel1.toString()); - sentinels.add(sentinel2.toString()); + sentinels.add(sentinel1.toString()); + sentinels.add(sentinel2.toString()); - sentinelJedis1 = new Jedis(sentinel1.getHost(), sentinel1.getPort()); - sentinelJedis2 = new Jedis(sentinel2.getHost(), sentinel2.getPort()); + sentinelJedis1 = new Jedis(sentinel1.getHost(), sentinel1.getPort()); + sentinelJedis2 = new Jedis(sentinel2.getHost(), sentinel2.getPort()); } @Test(expected = JedisConnectionException.class) public void initializeWithNotAvailableSentinelsShouldThrowException() { - Set wrongSentinels = new HashSet(); - wrongSentinels.add(new HostAndPort("localhost", 65432).toString()); - wrongSentinels.add(new HostAndPort("localhost", 65431).toString()); + Set wrongSentinels = new HashSet(); + wrongSentinels.add(new HostAndPort("localhost", 65432).toString()); + wrongSentinels.add(new HostAndPort("localhost", 65431).toString()); - JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, - wrongSentinels); - pool.destroy(); + JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, + wrongSentinels); + pool.destroy(); } @Test(expected = JedisException.class) public void initializeWithNotMonitoredMasterNameShouldThrowException() { - final String wrongMasterName = "wrongMasterName"; - JedisSentinelPool pool = new JedisSentinelPool(wrongMasterName, - sentinels); - pool.destroy(); + final String wrongMasterName = "wrongMasterName"; + JedisSentinelPool pool = new JedisSentinelPool(wrongMasterName, + sentinels); + pool.destroy(); } @Test public void checkCloseableConnections() throws Exception { - GenericObjectPoolConfig config = new GenericObjectPoolConfig(); + GenericObjectPoolConfig config = new GenericObjectPoolConfig(); - JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, - config, 1000, "foobared", 2); - Jedis jedis = pool.getResource(); - jedis.auth("foobared"); - jedis.set("foo", "bar"); - assertEquals("bar", jedis.get("foo")); - pool.returnResource(jedis); - pool.close(); - assertTrue(pool.isClosed()); + JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, + config, 1000, "foobared", 2); + Jedis jedis = pool.getResource(); + jedis.auth("foobared"); + jedis.set("foo", "bar"); + assertEquals("bar", jedis.get("foo")); + pool.returnResource(jedis); + pool.close(); + assertTrue(pool.isClosed()); } @Test public void ensureSafeTwiceFailover() throws InterruptedException { - JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, - new GenericObjectPoolConfig(), 1000, "foobared", 2); + JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, + new GenericObjectPoolConfig(), 1000, "foobared", 2); - forceFailover(pool); - // after failover sentinel needs a bit of time to stabilize before a new - // failover - Thread.sleep(100); - forceFailover(pool); + forceFailover(pool); + // after failover sentinel needs a bit of time to stabilize before a new + // failover + Thread.sleep(100); + forceFailover(pool); - // you can test failover as much as possible + // you can test failover as much as possible } @Test public void returnResourceShouldResetState() { - GenericObjectPoolConfig config = new GenericObjectPoolConfig(); - config.setMaxTotal(1); - config.setBlockWhenExhausted(false); - JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, - config, 1000, "foobared", 2); + GenericObjectPoolConfig config = new GenericObjectPoolConfig(); + config.setMaxTotal(1); + config.setBlockWhenExhausted(false); + JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, + config, 1000, "foobared", 2); - Jedis jedis = pool.getResource(); - Jedis jedis2 = null; + Jedis jedis = pool.getResource(); + Jedis jedis2 = null; - try { - jedis.set("hello", "jedis"); - Transaction t = jedis.multi(); - t.set("hello", "world"); - pool.returnResource(jedis); + try { + jedis.set("hello", "jedis"); + Transaction t = jedis.multi(); + t.set("hello", "world"); + pool.returnResource(jedis); - jedis2 = pool.getResource(); + jedis2 = pool.getResource(); - assertTrue(jedis == jedis2); - assertEquals("jedis", jedis2.get("hello")); - } catch (JedisConnectionException e) { - if (jedis2 != null) { - pool.returnBrokenResource(jedis2); - jedis2 = null; - } - } finally { - if (jedis2 != null) - pool.returnResource(jedis2); + assertTrue(jedis == jedis2); + assertEquals("jedis", jedis2.get("hello")); + } catch (JedisConnectionException e) { + if (jedis2 != null) { + pool.returnBrokenResource(jedis2); + jedis2 = null; + } + } finally { + if (jedis2 != null) + pool.returnResource(jedis2); - pool.destroy(); - } + pool.destroy(); + } } @Test public void checkResourceIsCloseable() { - GenericObjectPoolConfig config = new GenericObjectPoolConfig(); - config.setMaxTotal(1); - config.setBlockWhenExhausted(false); - JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, - config, 1000, "foobared", 2); + GenericObjectPoolConfig config = new GenericObjectPoolConfig(); + config.setMaxTotal(1); + config.setBlockWhenExhausted(false); + JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, + config, 1000, "foobared", 2); - Jedis jedis = pool.getResource(); - try { - jedis.set("hello", "jedis"); - } finally { - jedis.close(); - } + Jedis jedis = pool.getResource(); + try { + jedis.set("hello", "jedis"); + } finally { + jedis.close(); + } - Jedis jedis2 = pool.getResource(); - try { - assertEquals(jedis, jedis2); - } finally { - jedis2.close(); - } + Jedis jedis2 = pool.getResource(); + try { + assertEquals(jedis, jedis2); + } finally { + jedis2.close(); + } } @Test public void returnResourceWithNullResource() { - GenericObjectPoolConfig config = new GenericObjectPoolConfig(); - config.setMaxTotal(1); - config.setBlockWhenExhausted(false); - JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, - config, 1000, "foobared", 2); + GenericObjectPoolConfig config = new GenericObjectPoolConfig(); + config.setMaxTotal(1); + config.setBlockWhenExhausted(false); + JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, + config, 1000, "foobared", 2); - Jedis nullJedis = null; - pool.returnResource(nullJedis); - pool.destroy(); + Jedis nullJedis = null; + pool.returnResource(nullJedis); + pool.destroy(); } @Test public void returnBrokenResourceWithNullResource() { - GenericObjectPoolConfig config = new GenericObjectPoolConfig(); - config.setMaxTotal(1); - config.setBlockWhenExhausted(false); - JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, - config, 1000, "foobared", 2); + GenericObjectPoolConfig config = new GenericObjectPoolConfig(); + config.setMaxTotal(1); + config.setBlockWhenExhausted(false); + JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, + config, 1000, "foobared", 2); - Jedis nullJedis = null; - pool.returnBrokenResource(nullJedis); - pool.destroy(); + Jedis nullJedis = null; + pool.returnBrokenResource(nullJedis); + pool.destroy(); } private void forceFailover(JedisSentinelPool pool) - throws InterruptedException { - HostAndPort oldMaster = pool.getCurrentHostMaster(); + throws InterruptedException { + HostAndPort oldMaster = pool.getCurrentHostMaster(); - // jedis connection should be master - Jedis beforeFailoverJedis = pool.getResource(); - assertEquals("PONG", beforeFailoverJedis.ping()); + // jedis connection should be master + Jedis beforeFailoverJedis = pool.getResource(); + assertEquals("PONG", beforeFailoverJedis.ping()); - waitForFailover(pool, oldMaster); + waitForFailover(pool, oldMaster); - Jedis afterFailoverJedis = pool.getResource(); - assertEquals("PONG", afterFailoverJedis.ping()); - assertEquals("foobared", afterFailoverJedis.configGet("requirepass") - .get(1)); - assertEquals(2, afterFailoverJedis.getDB().intValue()); + Jedis afterFailoverJedis = pool.getResource(); + assertEquals("PONG", afterFailoverJedis.ping()); + assertEquals("foobared", afterFailoverJedis.configGet("requirepass") + .get(1)); + assertEquals(2, afterFailoverJedis.getDB().intValue()); - // returning both connections to the pool should not throw - beforeFailoverJedis.close(); - afterFailoverJedis.close(); + // returning both connections to the pool should not throw + beforeFailoverJedis.close(); + afterFailoverJedis.close(); } private void waitForFailover(JedisSentinelPool pool, HostAndPort oldMaster) - throws InterruptedException { - HostAndPort newMaster = JedisSentinelTestUtil.waitForNewPromotedMaster( - MASTER_NAME, sentinelJedis1, sentinelJedis2); + throws InterruptedException { + HostAndPort newMaster = JedisSentinelTestUtil.waitForNewPromotedMaster( + MASTER_NAME, sentinelJedis1, sentinelJedis2); - waitForJedisSentinelPoolRecognizeNewMaster(pool, newMaster); + waitForJedisSentinelPoolRecognizeNewMaster(pool, newMaster); } private void waitForJedisSentinelPoolRecognizeNewMaster( - JedisSentinelPool pool, HostAndPort newMaster) - throws InterruptedException { + JedisSentinelPool pool, HostAndPort newMaster) + throws InterruptedException { - while (true) { - HostAndPort currentHostMaster = pool.getCurrentHostMaster(); + while (true) { + HostAndPort currentHostMaster = pool.getCurrentHostMaster(); - if (newMaster.equals(currentHostMaster)) - break; + if (newMaster.equals(currentHostMaster)) + break; - System.out - .println("JedisSentinelPool's master is not yet changed, sleep..."); + System.out + .println("JedisSentinelPool's master is not yet changed, sleep..."); - Thread.sleep(100); - } + Thread.sleep(100); + } } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/JedisSentinelTest.java b/src/test/java/redis/clients/jedis/tests/JedisSentinelTest.java index 7a8bf87..6f22086 100644 --- a/src/test/java/redis/clients/jedis/tests/JedisSentinelTest.java +++ b/src/test/java/redis/clients/jedis/tests/JedisSentinelTest.java @@ -21,16 +21,16 @@ public class JedisSentinelTest extends JedisTestBase { private static final String MASTER_IP = "127.0.0.1"; protected static HostAndPort master = HostAndPortUtil.getRedisServers() - .get(0); + .get(0); protected static HostAndPort slave = HostAndPortUtil.getRedisServers().get( - 4); + 4); protected static HostAndPort sentinel = HostAndPortUtil - .getSentinelServers().get(0); + .getSentinelServers().get(0); protected static HostAndPort sentinelForFailover = HostAndPortUtil - .getSentinelServers().get(2); + .getSentinelServers().get(2); protected static HostAndPort masterForFailover = HostAndPortUtil - .getRedisServers().get(5); + .getRedisServers().get(5); @Before public void setup() throws InterruptedException { @@ -38,173 +38,173 @@ public class JedisSentinelTest extends JedisTestBase { @After public void clear() throws InterruptedException { - // New Sentinel (after 2.8.1) - // when slave promoted to master (slave of no one), New Sentinel force - // to restore it (demote) - // so, promote(slaveof) slave to master has no effect, not same to old - // Sentinel's behavior - ensureRemoved(MONITOR_MASTER_NAME); - ensureRemoved(REMOVE_MASTER_NAME); + // New Sentinel (after 2.8.1) + // when slave promoted to master (slave of no one), New Sentinel force + // to restore it (demote) + // so, promote(slaveof) slave to master has no effect, not same to old + // Sentinel's behavior + ensureRemoved(MONITOR_MASTER_NAME); + ensureRemoved(REMOVE_MASTER_NAME); } @Test public void sentinel() { - Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort()); + Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort()); - try { - List> masters = j.sentinelMasters(); + try { + List> masters = j.sentinelMasters(); - boolean inMasters = false; - for (Map master : masters) - if (MASTER_NAME.equals(master.get("name"))) - inMasters = true; + boolean inMasters = false; + for (Map master : masters) + if (MASTER_NAME.equals(master.get("name"))) + inMasters = true; - assertTrue(inMasters); + assertTrue(inMasters); - List masterHostAndPort = j - .sentinelGetMasterAddrByName(MASTER_NAME); - HostAndPort masterFromSentinel = new HostAndPort( - masterHostAndPort.get(0), - Integer.parseInt(masterHostAndPort.get(1))); - assertEquals(master, masterFromSentinel); + List masterHostAndPort = j + .sentinelGetMasterAddrByName(MASTER_NAME); + HostAndPort masterFromSentinel = new HostAndPort( + masterHostAndPort.get(0), + Integer.parseInt(masterHostAndPort.get(1))); + assertEquals(master, masterFromSentinel); - List> slaves = j.sentinelSlaves(MASTER_NAME); - assertTrue(slaves.size() > 0); - assertEquals(master.getPort(), - Integer.parseInt(slaves.get(0).get("master-port"))); + List> slaves = j.sentinelSlaves(MASTER_NAME); + assertTrue(slaves.size() > 0); + assertEquals(master.getPort(), + Integer.parseInt(slaves.get(0).get("master-port"))); - // DO NOT RE-RUN TEST TOO FAST, RESET TAKES SOME TIME TO... RESET - assertEquals(Long.valueOf(1), j.sentinelReset(MASTER_NAME)); - assertEquals(Long.valueOf(0), j.sentinelReset("woof" + MASTER_NAME)); - } finally { - j.close(); - } + // DO NOT RE-RUN TEST TOO FAST, RESET TAKES SOME TIME TO... RESET + assertEquals(Long.valueOf(1), j.sentinelReset(MASTER_NAME)); + assertEquals(Long.valueOf(0), j.sentinelReset("woof" + MASTER_NAME)); + } finally { + j.close(); + } } @Test public void sentinelFailover() throws InterruptedException { - Jedis j = new Jedis(sentinelForFailover.getHost(), - sentinelForFailover.getPort()); - Jedis j2 = new Jedis(sentinelForFailover.getHost(), - sentinelForFailover.getPort()); + Jedis j = new Jedis(sentinelForFailover.getHost(), + sentinelForFailover.getPort()); + Jedis j2 = new Jedis(sentinelForFailover.getHost(), + sentinelForFailover.getPort()); - try { - List masterHostAndPort = j - .sentinelGetMasterAddrByName(FAILOVER_MASTER_NAME); - HostAndPort currentMaster = new HostAndPort( - masterHostAndPort.get(0), - Integer.parseInt(masterHostAndPort.get(1))); + try { + List masterHostAndPort = j + .sentinelGetMasterAddrByName(FAILOVER_MASTER_NAME); + 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); - HostAndPort newMaster = new HostAndPort(masterHostAndPort.get(0), - Integer.parseInt(masterHostAndPort.get(1))); + masterHostAndPort = j + .sentinelGetMasterAddrByName(FAILOVER_MASTER_NAME); + HostAndPort newMaster = new HostAndPort(masterHostAndPort.get(0), + Integer.parseInt(masterHostAndPort.get(1))); - assertNotEquals(newMaster, currentMaster); - } finally { - j.close(); - } + assertNotEquals(newMaster, currentMaster); + } finally { + j.close(); + } } @Test public void sentinelMonitor() { - Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort()); + Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort()); - try { - // monitor new master - String result = j.sentinelMonitor(MONITOR_MASTER_NAME, MASTER_IP, - master.getPort(), 1); - assertEquals("OK", result); + try { + // monitor new master + String result = j.sentinelMonitor(MONITOR_MASTER_NAME, MASTER_IP, + master.getPort(), 1); + assertEquals("OK", result); - // already monitored - try { - j.sentinelMonitor(MONITOR_MASTER_NAME, MASTER_IP, - master.getPort(), 1); - fail(); - } catch (JedisDataException e) { - // pass - } - } finally { - j.close(); - } + // already monitored + try { + j.sentinelMonitor(MONITOR_MASTER_NAME, MASTER_IP, + master.getPort(), 1); + fail(); + } catch (JedisDataException e) { + // pass + } + } finally { + j.close(); + } } @Test public void sentinelRemove() { - Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort()); + Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort()); - try { - ensureMonitored(sentinel, REMOVE_MASTER_NAME, MASTER_IP, - master.getPort(), 1); + try { + ensureMonitored(sentinel, REMOVE_MASTER_NAME, MASTER_IP, + master.getPort(), 1); - String result = j.sentinelRemove(REMOVE_MASTER_NAME); - assertEquals("OK", result); + String result = j.sentinelRemove(REMOVE_MASTER_NAME); + assertEquals("OK", result); - // not exist - try { - result = j.sentinelRemove(REMOVE_MASTER_NAME); - assertNotEquals("OK", result); - fail(); - } catch (JedisDataException e) { - // pass - } - } finally { - j.close(); - } + // not exist + try { + result = j.sentinelRemove(REMOVE_MASTER_NAME); + assertNotEquals("OK", result); + fail(); + } catch (JedisDataException e) { + // pass + } + } finally { + j.close(); + } } @Test public void sentinelSet() { - Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort()); + Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort()); - try { - Map parameterMap = new HashMap(); - parameterMap.put("down-after-milliseconds", String.valueOf(1234)); - parameterMap.put("parallel-syncs", String.valueOf(3)); - parameterMap.put("quorum", String.valueOf(2)); - j.sentinelSet(MASTER_NAME, parameterMap); + try { + Map parameterMap = new HashMap(); + parameterMap.put("down-after-milliseconds", String.valueOf(1234)); + parameterMap.put("parallel-syncs", String.valueOf(3)); + parameterMap.put("quorum", String.valueOf(2)); + j.sentinelSet(MASTER_NAME, parameterMap); - List> masters = j.sentinelMasters(); - for (Map master : masters) { - if (master.get("name").equals(MASTER_NAME)) { - assertEquals(1234, Integer.parseInt(master - .get("down-after-milliseconds"))); - assertEquals(3, - Integer.parseInt(master.get("parallel-syncs"))); - assertEquals(2, Integer.parseInt(master.get("quorum"))); - } - } + List> masters = j.sentinelMasters(); + for (Map master : masters) { + if (master.get("name").equals(MASTER_NAME)) { + assertEquals(1234, Integer.parseInt(master + .get("down-after-milliseconds"))); + assertEquals(3, + Integer.parseInt(master.get("parallel-syncs"))); + assertEquals(2, Integer.parseInt(master.get("quorum"))); + } + } - parameterMap.put("quorum", String.valueOf(1)); - j.sentinelSet(MASTER_NAME, parameterMap); - } finally { - j.close(); - } + parameterMap.put("quorum", String.valueOf(1)); + j.sentinelSet(MASTER_NAME, parameterMap); + } finally { + j.close(); + } } private void ensureMonitored(HostAndPort sentinel, String masterName, - String ip, int port, int quorum) { - Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort()); - try { - j.sentinelMonitor(masterName, ip, port, quorum); - } catch (JedisDataException e) { - } finally { - j.close(); - } + String ip, int port, int quorum) { + Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort()); + try { + j.sentinelMonitor(masterName, ip, port, quorum); + } catch (JedisDataException e) { + } finally { + j.close(); + } } private void ensureRemoved(String masterName) { - Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort()); - try { - j.sentinelRemove(masterName); - } catch (JedisDataException e) { - } finally { - j.close(); - } + Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort()); + try { + j.sentinelRemove(masterName); + } catch (JedisDataException e) { + } finally { + j.close(); + } } } diff --git a/src/test/java/redis/clients/jedis/tests/JedisTest.java b/src/test/java/redis/clients/jedis/tests/JedisTest.java index 2e78e57..4f5049b 100644 --- a/src/test/java/redis/clients/jedis/tests/JedisTest.java +++ b/src/test/java/redis/clients/jedis/tests/JedisTest.java @@ -20,107 +20,107 @@ import redis.clients.util.SafeEncoder; public class JedisTest extends JedisCommandTestBase { @Test public void useWithoutConnecting() { - Jedis jedis = new Jedis("localhost"); - jedis.auth("foobared"); - jedis.dbSize(); + Jedis jedis = new Jedis("localhost"); + jedis.auth("foobared"); + jedis.dbSize(); } @Test public void checkBinaryData() { - byte[] bigdata = new byte[1777]; - for (int b = 0; b < bigdata.length; b++) { - bigdata[b] = (byte) ((byte) b % 255); - } - Map hash = new HashMap(); - hash.put("data", SafeEncoder.encode(bigdata)); + byte[] bigdata = new byte[1777]; + for (int b = 0; b < bigdata.length; b++) { + bigdata[b] = (byte) ((byte) b % 255); + } + Map hash = new HashMap(); + hash.put("data", SafeEncoder.encode(bigdata)); - String status = jedis.hmset("foo", hash); - assertEquals("OK", status); - assertEquals(hash, jedis.hgetAll("foo")); + String status = jedis.hmset("foo", hash); + assertEquals("OK", status); + assertEquals(hash, jedis.hgetAll("foo")); } @Test public void connectWithShardInfo() { - JedisShardInfo shardInfo = new JedisShardInfo("localhost", - Protocol.DEFAULT_PORT); - shardInfo.setPassword("foobared"); - Jedis jedis = new Jedis(shardInfo); - jedis.get("foo"); + JedisShardInfo shardInfo = new JedisShardInfo("localhost", + Protocol.DEFAULT_PORT); + shardInfo.setPassword("foobared"); + Jedis jedis = new Jedis(shardInfo); + jedis.get("foo"); } @Test(expected = JedisConnectionException.class) public void timeoutConnection() throws Exception { - jedis = new Jedis("localhost", 6379, 15000); - jedis.auth("foobared"); - jedis.configSet("timeout", "1"); - Thread.sleep(2000); - jedis.hmget("foobar", "foo"); + jedis = new Jedis("localhost", 6379, 15000); + jedis.auth("foobared"); + jedis.configSet("timeout", "1"); + Thread.sleep(2000); + jedis.hmget("foobar", "foo"); } @Test(expected = JedisConnectionException.class) public void timeoutConnectionWithURI() throws Exception { - jedis = new Jedis(new URI("redis://:foobared@localhost:6380/2"), 15000); - jedis.configSet("timeout", "1"); - Thread.sleep(2000); - jedis.hmget("foobar", "foo"); + jedis = new Jedis(new URI("redis://:foobared@localhost:6380/2"), 15000); + jedis.configSet("timeout", "1"); + Thread.sleep(2000); + jedis.hmget("foobar", "foo"); } @Test(expected = JedisDataException.class) public void failWhenSendingNullValues() { - jedis.set("foo", null); + jedis.set("foo", null); } @Test public void shouldReconnectToSameDB() throws IOException { - jedis.select(1); - jedis.set("foo", "bar"); - jedis.getClient().getSocket().shutdownInput(); - jedis.getClient().getSocket().shutdownOutput(); - assertEquals("bar", jedis.get("foo")); + jedis.select(1); + jedis.set("foo", "bar"); + jedis.getClient().getSocket().shutdownInput(); + jedis.getClient().getSocket().shutdownOutput(); + assertEquals("bar", jedis.get("foo")); } @Test public void startWithUrlString() { - Jedis j = new Jedis("localhost", 6380); - j.auth("foobared"); - j.select(2); - j.set("foo", "bar"); - Jedis jedis = new Jedis("redis://:foobared@localhost:6380/2"); - assertEquals("PONG", jedis.ping()); - assertEquals("bar", jedis.get("foo")); + Jedis j = new Jedis("localhost", 6380); + j.auth("foobared"); + j.select(2); + j.set("foo", "bar"); + Jedis jedis = new Jedis("redis://:foobared@localhost:6380/2"); + assertEquals("PONG", jedis.ping()); + assertEquals("bar", jedis.get("foo")); } @Test public void startWithUrl() throws URISyntaxException { - Jedis j = new Jedis("localhost", 6380); - j.auth("foobared"); - j.select(2); - j.set("foo", "bar"); - Jedis jedis = new Jedis(new URI("redis://:foobared@localhost:6380/2")); - assertEquals("PONG", jedis.ping()); - assertEquals("bar", jedis.get("foo")); + Jedis j = new Jedis("localhost", 6380); + j.auth("foobared"); + j.select(2); + j.set("foo", "bar"); + Jedis jedis = new Jedis(new URI("redis://:foobared@localhost:6380/2")); + assertEquals("PONG", jedis.ping()); + assertEquals("bar", jedis.get("foo")); } @Test public void allowUrlWithNoDBAndNoPassword() { - Jedis jedis = new Jedis("redis://localhost:6380"); - jedis.auth("foobared"); - assertEquals(jedis.getClient().getHost(), "localhost"); - assertEquals(jedis.getClient().getPort(), 6380); - assertEquals(jedis.getDB(), (Long) 0L); + Jedis jedis = new Jedis("redis://localhost:6380"); + jedis.auth("foobared"); + assertEquals(jedis.getClient().getHost(), "localhost"); + assertEquals(jedis.getClient().getPort(), 6380); + assertEquals(jedis.getDB(), (Long) 0L); - jedis = new Jedis("redis://localhost:6380/"); - jedis.auth("foobared"); - assertEquals(jedis.getClient().getHost(), "localhost"); - assertEquals(jedis.getClient().getPort(), 6380); - assertEquals(jedis.getDB(), (Long) 0L); + jedis = new Jedis("redis://localhost:6380/"); + jedis.auth("foobared"); + assertEquals(jedis.getClient().getHost(), "localhost"); + assertEquals(jedis.getClient().getPort(), 6380); + assertEquals(jedis.getDB(), (Long) 0L); } @Test public void checkCloseable() { - jedis.close(); - BinaryJedis bj = new BinaryJedis("localhost"); - bj.connect(); - bj.close(); + jedis.close(); + BinaryJedis bj = new BinaryJedis("localhost"); + bj.connect(); + bj.close(); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/JedisTestBase.java b/src/test/java/redis/clients/jedis/tests/JedisTestBase.java index 158e20c..176c9e5 100644 --- a/src/test/java/redis/clients/jedis/tests/JedisTestBase.java +++ b/src/test/java/redis/clients/jedis/tests/JedisTestBase.java @@ -8,18 +8,18 @@ import org.junit.Assert; public abstract class JedisTestBase extends Assert { protected void assertEquals(List expected, List actual) { - assertEquals(expected.size(), actual.size()); - for (int n = 0; n < expected.size(); n++) { - assertArrayEquals(expected.get(n), actual.get(n)); - } + assertEquals(expected.size(), actual.size()); + for (int n = 0; n < expected.size(); n++) { + assertArrayEquals(expected.get(n), actual.get(n)); + } } protected void assertEquals(Set expected, Set actual) { - assertEquals(expected.size(), actual.size()); - Iterator iterator = expected.iterator(); - Iterator iterator2 = actual.iterator(); - while (iterator.hasNext() || iterator2.hasNext()) { - assertArrayEquals(iterator.next(), iterator2.next()); - } + assertEquals(expected.size(), actual.size()); + Iterator iterator = expected.iterator(); + Iterator iterator2 = actual.iterator(); + while (iterator.hasNext() || iterator2.hasNext()) { + assertArrayEquals(iterator.next(), iterator2.next()); + } } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java index 45e6463..4137c76 100644 --- a/src/test/java/redis/clients/jedis/tests/PipeliningTest.java +++ b/src/test/java/redis/clients/jedis/tests/PipeliningTest.java @@ -27,453 +27,453 @@ public class PipeliningTest extends Assert { @Before public void setUp() throws Exception { - jedis = new Jedis(hnp.getHost(), hnp.getPort(), 500); - jedis.connect(); - jedis.auth("foobared"); - jedis.flushAll(); + jedis = new Jedis(hnp.getHost(), hnp.getPort(), 500); + jedis.connect(); + jedis.auth("foobared"); + jedis.flushAll(); } @Test public void pipeline() throws UnsupportedEncodingException { - Pipeline p = jedis.pipelined(); - p.set("foo", "bar"); - p.get("foo"); - List results = p.syncAndReturnAll(); + Pipeline p = jedis.pipelined(); + p.set("foo", "bar"); + p.get("foo"); + List results = p.syncAndReturnAll(); - assertEquals(2, results.size()); - assertEquals("OK", results.get(0)); - assertEquals("bar", results.get(1)); + assertEquals(2, results.size()); + assertEquals("OK", results.get(0)); + assertEquals("bar", results.get(1)); } @Test public void pipelineResponse() { - jedis.set("string", "foo"); - jedis.lpush("list", "foo"); - jedis.hset("hash", "foo", "bar"); - jedis.zadd("zset", 1, "foo"); - jedis.sadd("set", "foo"); - jedis.setrange("setrange", 0, "0123456789"); - byte[] bytesForSetRange = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - jedis.setrange("setrangebytes".getBytes(), 0, bytesForSetRange); + jedis.set("string", "foo"); + jedis.lpush("list", "foo"); + jedis.hset("hash", "foo", "bar"); + jedis.zadd("zset", 1, "foo"); + jedis.sadd("set", "foo"); + jedis.setrange("setrange", 0, "0123456789"); + byte[] bytesForSetRange = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + jedis.setrange("setrangebytes".getBytes(), 0, bytesForSetRange); - Pipeline p = jedis.pipelined(); - Response string = p.get("string"); - Response list = p.lpop("list"); - Response hash = p.hget("hash", "foo"); - Response> zset = p.zrange("zset", 0, -1); - Response set = p.spop("set"); - Response blist = p.exists("list"); - Response zincrby = p.zincrby("zset", 1, "foo"); - Response zcard = p.zcard("zset"); - p.lpush("list", "bar"); - Response> lrange = p.lrange("list", 0, -1); - Response> hgetAll = p.hgetAll("hash"); - p.sadd("set", "foo"); - Response> smembers = p.smembers("set"); - Response> zrangeWithScores = p.zrangeWithScores("zset", 0, - -1); - Response getrange = p.getrange("setrange", 1, 3); - Response getrangeBytes = p.getrange("setrangebytes".getBytes(), - 6, 8); - p.sync(); + Pipeline p = jedis.pipelined(); + Response string = p.get("string"); + Response list = p.lpop("list"); + Response hash = p.hget("hash", "foo"); + Response> zset = p.zrange("zset", 0, -1); + Response set = p.spop("set"); + Response blist = p.exists("list"); + Response zincrby = p.zincrby("zset", 1, "foo"); + Response zcard = p.zcard("zset"); + p.lpush("list", "bar"); + Response> lrange = p.lrange("list", 0, -1); + Response> hgetAll = p.hgetAll("hash"); + p.sadd("set", "foo"); + Response> smembers = p.smembers("set"); + Response> zrangeWithScores = p.zrangeWithScores("zset", 0, + -1); + Response getrange = p.getrange("setrange", 1, 3); + Response getrangeBytes = p.getrange("setrangebytes".getBytes(), + 6, 8); + p.sync(); - assertEquals("foo", string.get()); - assertEquals("foo", list.get()); - assertEquals("bar", hash.get()); - assertEquals("foo", zset.get().iterator().next()); - assertEquals("foo", set.get()); - assertEquals(false, blist.get()); - assertEquals(Double.valueOf(2), zincrby.get()); - assertEquals(Long.valueOf(1), zcard.get()); - assertEquals(1, lrange.get().size()); - assertNotNull(hgetAll.get().get("foo")); - assertEquals(1, smembers.get().size()); - assertEquals(1, zrangeWithScores.get().size()); - assertEquals("123", getrange.get()); - byte[] expectedGetRangeBytes = { 6, 7, 8 }; - assertArrayEquals(expectedGetRangeBytes, getrangeBytes.get()); + assertEquals("foo", string.get()); + assertEquals("foo", list.get()); + assertEquals("bar", hash.get()); + assertEquals("foo", zset.get().iterator().next()); + assertEquals("foo", set.get()); + assertEquals(false, blist.get()); + assertEquals(Double.valueOf(2), zincrby.get()); + assertEquals(Long.valueOf(1), zcard.get()); + assertEquals(1, lrange.get().size()); + assertNotNull(hgetAll.get().get("foo")); + assertEquals(1, smembers.get().size()); + assertEquals(1, zrangeWithScores.get().size()); + assertEquals("123", getrange.get()); + byte[] expectedGetRangeBytes = { 6, 7, 8 }; + assertArrayEquals(expectedGetRangeBytes, getrangeBytes.get()); } @Test public void pipelineResponseWithData() { - jedis.zadd("zset", 1, "foo"); + jedis.zadd("zset", 1, "foo"); - Pipeline p = jedis.pipelined(); - Response score = p.zscore("zset", "foo"); - p.sync(); + Pipeline p = jedis.pipelined(); + Response score = p.zscore("zset", "foo"); + p.sync(); - assertNotNull(score.get()); + assertNotNull(score.get()); } @Test public void pipelineBinarySafeHashCommands() { - jedis.hset("key".getBytes(), "f1".getBytes(), "v111".getBytes()); - jedis.hset("key".getBytes(), "f22".getBytes(), "v2222".getBytes()); + jedis.hset("key".getBytes(), "f1".getBytes(), "v111".getBytes()); + jedis.hset("key".getBytes(), "f22".getBytes(), "v2222".getBytes()); - Pipeline p = jedis.pipelined(); - Response> fmap = p.hgetAll("key".getBytes()); - Response> fkeys = p.hkeys("key".getBytes()); - Response> fordered = p.hmget("key".getBytes(), - "f22".getBytes(), "f1".getBytes()); - Response> fvals = p.hvals("key".getBytes()); - p.sync(); + Pipeline p = jedis.pipelined(); + Response> fmap = p.hgetAll("key".getBytes()); + Response> fkeys = p.hkeys("key".getBytes()); + Response> fordered = p.hmget("key".getBytes(), + "f22".getBytes(), "f1".getBytes()); + Response> fvals = p.hvals("key".getBytes()); + p.sync(); - assertNotNull(fmap.get()); - // we have to do these strange contortions because byte[] is not a very - // good key - // for a java Map. It only works with equality (you need the exact key - // object to retrieve - // the value) I recommend we switch to using ByteBuffer or something - // similar: - // http://stackoverflow.com/questions/1058149/using-a-byte-array-as-hashmap-key-java - Map map = fmap.get(); - Set mapKeys = map.keySet(); - Iterator iterMap = mapKeys.iterator(); - byte[] firstMapKey = iterMap.next(); - byte[] secondMapKey = iterMap.next(); - assertFalse(iterMap.hasNext()); - verifyHasBothValues(firstMapKey, secondMapKey, "f1".getBytes(), - "f22".getBytes()); - byte[] firstMapValue = map.get(firstMapKey); - byte[] secondMapValue = map.get(secondMapKey); - verifyHasBothValues(firstMapValue, secondMapValue, "v111".getBytes(), - "v2222".getBytes()); + assertNotNull(fmap.get()); + // we have to do these strange contortions because byte[] is not a very + // good key + // for a java Map. It only works with equality (you need the exact key + // object to retrieve + // the value) I recommend we switch to using ByteBuffer or something + // similar: + // http://stackoverflow.com/questions/1058149/using-a-byte-array-as-hashmap-key-java + Map map = fmap.get(); + Set mapKeys = map.keySet(); + Iterator iterMap = mapKeys.iterator(); + byte[] firstMapKey = iterMap.next(); + byte[] secondMapKey = iterMap.next(); + assertFalse(iterMap.hasNext()); + verifyHasBothValues(firstMapKey, secondMapKey, "f1".getBytes(), + "f22".getBytes()); + byte[] firstMapValue = map.get(firstMapKey); + byte[] secondMapValue = map.get(secondMapKey); + verifyHasBothValues(firstMapValue, secondMapValue, "v111".getBytes(), + "v2222".getBytes()); - assertNotNull(fkeys.get()); - Iterator iter = fkeys.get().iterator(); - byte[] firstKey = iter.next(); - byte[] secondKey = iter.next(); - assertFalse(iter.hasNext()); - verifyHasBothValues(firstKey, secondKey, "f1".getBytes(), - "f22".getBytes()); + assertNotNull(fkeys.get()); + Iterator iter = fkeys.get().iterator(); + byte[] firstKey = iter.next(); + byte[] secondKey = iter.next(); + assertFalse(iter.hasNext()); + verifyHasBothValues(firstKey, secondKey, "f1".getBytes(), + "f22".getBytes()); - assertNotNull(fordered.get()); - assertArrayEquals("v2222".getBytes(), fordered.get().get(0)); - assertArrayEquals("v111".getBytes(), fordered.get().get(1)); + assertNotNull(fordered.get()); + assertArrayEquals("v2222".getBytes(), fordered.get().get(0)); + assertArrayEquals("v111".getBytes(), fordered.get().get(1)); - assertNotNull(fvals.get()); - assertEquals(2, fvals.get().size()); - byte[] firstValue = fvals.get().get(0); - byte[] secondValue = fvals.get().get(1); - verifyHasBothValues(firstValue, secondValue, "v111".getBytes(), - "v2222".getBytes()); + assertNotNull(fvals.get()); + assertEquals(2, fvals.get().size()); + byte[] firstValue = fvals.get().get(0); + byte[] secondValue = fvals.get().get(1); + verifyHasBothValues(firstValue, secondValue, "v111".getBytes(), + "v2222".getBytes()); } private void verifyHasBothValues(byte[] firstKey, byte[] secondKey, - byte[] value1, byte[] value2) { - assertFalse(Arrays.equals(firstKey, secondKey)); - assertTrue(Arrays.equals(firstKey, value1) - || Arrays.equals(firstKey, value2)); - assertTrue(Arrays.equals(secondKey, value1) - || Arrays.equals(secondKey, value2)); + byte[] value1, byte[] value2) { + assertFalse(Arrays.equals(firstKey, secondKey)); + assertTrue(Arrays.equals(firstKey, value1) + || Arrays.equals(firstKey, value2)); + assertTrue(Arrays.equals(secondKey, value1) + || Arrays.equals(secondKey, value2)); } @Test public void pipelineSelect() { - Pipeline p = jedis.pipelined(); - p.select(1); - p.sync(); + Pipeline p = jedis.pipelined(); + p.select(1); + p.sync(); } @Test public void pipelineResponseWithoutData() { - jedis.zadd("zset", 1, "foo"); + jedis.zadd("zset", 1, "foo"); - Pipeline p = jedis.pipelined(); - Response score = p.zscore("zset", "bar"); - p.sync(); + Pipeline p = jedis.pipelined(); + Response score = p.zscore("zset", "bar"); + p.sync(); - assertNull(score.get()); + assertNull(score.get()); } @Test(expected = JedisDataException.class) public void pipelineResponseWithinPipeline() { - jedis.set("string", "foo"); + jedis.set("string", "foo"); - Pipeline p = jedis.pipelined(); - Response string = p.get("string"); - string.get(); - p.sync(); + Pipeline p = jedis.pipelined(); + Response string = p.get("string"); + string.get(); + p.sync(); } @Test public void pipelineWithPubSub() { - Pipeline pipelined = jedis.pipelined(); - Response p1 = pipelined.publish("foo", "bar"); - Response p2 = pipelined.publish("foo".getBytes(), - "bar".getBytes()); - pipelined.sync(); - assertEquals(0, p1.get().longValue()); - assertEquals(0, p2.get().longValue()); + Pipeline pipelined = jedis.pipelined(); + Response p1 = pipelined.publish("foo", "bar"); + Response p2 = pipelined.publish("foo".getBytes(), + "bar".getBytes()); + pipelined.sync(); + assertEquals(0, p1.get().longValue()); + assertEquals(0, p2.get().longValue()); } @Test public void canRetrieveUnsetKey() { - Pipeline p = jedis.pipelined(); - Response shouldNotExist = p.get(UUID.randomUUID().toString()); - p.sync(); - assertNull(shouldNotExist.get()); + Pipeline p = jedis.pipelined(); + Response shouldNotExist = p.get(UUID.randomUUID().toString()); + p.sync(); + assertNull(shouldNotExist.get()); } @Test public void piplineWithError() { - Pipeline p = jedis.pipelined(); - p.set("foo", "bar"); - Response> error = p.smembers("foo"); - Response r = p.get("foo"); - p.sync(); - try { - error.get(); - fail(); - } catch (JedisDataException e) { - // that is fine we should be here - } - assertEquals(r.get(), "bar"); + Pipeline p = jedis.pipelined(); + p.set("foo", "bar"); + Response> error = p.smembers("foo"); + Response r = p.get("foo"); + p.sync(); + try { + error.get(); + fail(); + } catch (JedisDataException e) { + // that is fine we should be here + } + assertEquals(r.get(), "bar"); } @Test public void multi() { - Pipeline p = jedis.pipelined(); - p.multi(); - Response r1 = p.hincrBy("a", "f1", -1); - Response r2 = p.hincrBy("a", "f1", -2); - Response> r3 = p.exec(); - List result = p.syncAndReturnAll(); + Pipeline p = jedis.pipelined(); + p.multi(); + Response r1 = p.hincrBy("a", "f1", -1); + Response r2 = p.hincrBy("a", "f1", -2); + Response> r3 = p.exec(); + List result = p.syncAndReturnAll(); - assertEquals(new Long(-1), r1.get()); - assertEquals(new Long(-3), r2.get()); + assertEquals(new Long(-1), r1.get()); + assertEquals(new Long(-3), r2.get()); - assertEquals(4, result.size()); + assertEquals(4, result.size()); - assertEquals("OK", result.get(0)); - assertEquals("QUEUED", result.get(1)); - assertEquals("QUEUED", result.get(2)); + assertEquals("OK", result.get(0)); + assertEquals("QUEUED", result.get(1)); + assertEquals("QUEUED", result.get(2)); - // 4th result is a list with the results from the multi - @SuppressWarnings("unchecked") - List multiResult = (List) result.get(3); - assertEquals(new Long(-1), multiResult.get(0)); - assertEquals(new Long(-3), multiResult.get(1)); + // 4th result is a list with the results from the multi + @SuppressWarnings("unchecked") + List multiResult = (List) result.get(3); + assertEquals(new Long(-1), multiResult.get(0)); + assertEquals(new Long(-3), multiResult.get(1)); - assertEquals(new Long(-1), r3.get().get(0)); - assertEquals(new Long(-3), r3.get().get(1)); + assertEquals(new Long(-1), r3.get().get(0)); + assertEquals(new Long(-3), r3.get().get(1)); } @Test public void multiWithSync() { - jedis.set("foo", "314"); - jedis.set("bar", "foo"); - jedis.set("hello", "world"); - Pipeline p = jedis.pipelined(); - Response r1 = p.get("bar"); - p.multi(); - Response r2 = p.get("foo"); - p.exec(); - Response r3 = p.get("hello"); - p.sync(); + jedis.set("foo", "314"); + jedis.set("bar", "foo"); + jedis.set("hello", "world"); + Pipeline p = jedis.pipelined(); + Response r1 = p.get("bar"); + p.multi(); + Response r2 = p.get("foo"); + p.exec(); + Response r3 = p.get("hello"); + p.sync(); - // before multi - assertEquals("foo", r1.get()); - // It should be readable whether exec's response was built or not - assertEquals("314", r2.get()); - // after multi - assertEquals("world", r3.get()); + // before multi + assertEquals("foo", r1.get()); + // It should be readable whether exec's response was built or not + assertEquals("314", r2.get()); + // after multi + assertEquals("world", r3.get()); } @Test(expected = JedisDataException.class) public void pipelineExecShoudThrowJedisDataExceptionWhenNotInMulti() { - Pipeline pipeline = jedis.pipelined(); - pipeline.exec(); + Pipeline pipeline = jedis.pipelined(); + pipeline.exec(); } @Test(expected = JedisDataException.class) public void pipelineDiscardShoudThrowJedisDataExceptionWhenNotInMulti() { - Pipeline pipeline = jedis.pipelined(); - pipeline.discard(); + Pipeline pipeline = jedis.pipelined(); + pipeline.discard(); } @Test(expected = JedisDataException.class) public void pipelineMultiShoudThrowJedisDataExceptionWhenAlreadyInMulti() { - Pipeline pipeline = jedis.pipelined(); - pipeline.multi(); - pipeline.set("foo", "3"); - pipeline.multi(); + Pipeline pipeline = jedis.pipelined(); + pipeline.multi(); + pipeline.set("foo", "3"); + pipeline.multi(); } @Test public void testDiscardInPipeline() { - Pipeline pipeline = jedis.pipelined(); - pipeline.multi(); - pipeline.set("foo", "bar"); - Response discard = pipeline.discard(); - Response get = pipeline.get("foo"); - pipeline.sync(); - discard.get(); - get.get(); + Pipeline pipeline = jedis.pipelined(); + pipeline.multi(); + pipeline.set("foo", "bar"); + Response discard = pipeline.discard(); + Response get = pipeline.get("foo"); + pipeline.sync(); + discard.get(); + get.get(); } @Test public void testEval() { - String script = "return 'success!'"; + String script = "return 'success!'"; - Pipeline p = jedis.pipelined(); - Response result = p.eval(script); - p.sync(); + Pipeline p = jedis.pipelined(); + Response result = p.eval(script); + p.sync(); - assertEquals("success!", result.get()); + assertEquals("success!", result.get()); } @Test public void testEvalKeyAndArg() { - String key = "test"; - String arg = "3"; - String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])"; + String key = "test"; + String arg = "3"; + String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])"; - Pipeline p = jedis.pipelined(); - p.set(key, "0"); - Response result0 = p.eval(script, Arrays.asList(key), - Arrays.asList(arg)); - p.incr(key); - Response result1 = p.eval(script, Arrays.asList(key), - Arrays.asList(arg)); - Response result2 = p.get(key); - p.sync(); + Pipeline p = jedis.pipelined(); + p.set(key, "0"); + Response result0 = p.eval(script, Arrays.asList(key), + Arrays.asList(arg)); + p.incr(key); + Response result1 = p.eval(script, Arrays.asList(key), + Arrays.asList(arg)); + Response result2 = p.get(key); + p.sync(); - assertNull(result0.get()); - assertNull(result1.get()); - assertEquals("13", result2.get()); + assertNull(result0.get()); + assertNull(result1.get()); + assertEquals("13", result2.get()); } @Test public void testEvalsha() { - String script = "return 'success!'"; - String sha1 = jedis.scriptLoad(script); + String script = "return 'success!'"; + String sha1 = jedis.scriptLoad(script); - assertTrue(jedis.scriptExists(sha1)); + assertTrue(jedis.scriptExists(sha1)); - Pipeline p = jedis.pipelined(); - Response result = p.evalsha(sha1); - p.sync(); + Pipeline p = jedis.pipelined(); + Response result = p.evalsha(sha1); + p.sync(); - assertEquals("success!", result.get()); + assertEquals("success!", result.get()); } @Test public void testEvalshaKeyAndArg() { - String key = "test"; - String arg = "3"; - String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])"; - String sha1 = jedis.scriptLoad(script); + String key = "test"; + String arg = "3"; + String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])"; + String sha1 = jedis.scriptLoad(script); - assertTrue(jedis.scriptExists(sha1)); + assertTrue(jedis.scriptExists(sha1)); - Pipeline p = jedis.pipelined(); - p.set(key, "0"); - Response result0 = p.evalsha(sha1, Arrays.asList(key), - Arrays.asList(arg)); - p.incr(key); - Response result1 = p.evalsha(sha1, Arrays.asList(key), - Arrays.asList(arg)); - Response result2 = p.get(key); - p.sync(); + Pipeline p = jedis.pipelined(); + p.set(key, "0"); + Response result0 = p.evalsha(sha1, Arrays.asList(key), + Arrays.asList(arg)); + p.incr(key); + Response result1 = p.evalsha(sha1, Arrays.asList(key), + Arrays.asList(arg)); + Response result2 = p.get(key); + p.sync(); - assertNull(result0.get()); - assertNull(result1.get()); - assertEquals("13", result2.get()); + assertNull(result0.get()); + assertNull(result1.get()); + assertEquals("13", result2.get()); } @Test public void testPipelinedTransactionResponse() { - String key1 = "key1"; - String val1 = "val1"; + String key1 = "key1"; + String val1 = "val1"; - String key2 = "key2"; - String val2 = "val2"; + String key2 = "key2"; + String val2 = "val2"; - String key3 = "key3"; - String field1 = "field1"; - String field2 = "field2"; - String field3 = "field3"; - String field4 = "field4"; + String key3 = "key3"; + String field1 = "field1"; + String field2 = "field2"; + String field3 = "field3"; + String field4 = "field4"; - String value1 = "value1"; - String value2 = "value2"; - String value3 = "value3"; - String value4 = "value4"; + String value1 = "value1"; + String value2 = "value2"; + String value3 = "value3"; + String value4 = "value4"; - Map hashMap = new HashMap(); - hashMap.put(field1, value1); - hashMap.put(field2, value2); + Map hashMap = new HashMap(); + hashMap.put(field1, value1); + hashMap.put(field2, value2); - String key4 = "key4"; - Map hashMap1 = new HashMap(); - hashMap1.put(field3, value3); - hashMap1.put(field4, value4); + String key4 = "key4"; + Map hashMap1 = new HashMap(); + hashMap1.put(field3, value3); + hashMap1.put(field4, value4); - jedis.set(key1, val1); - jedis.set(key2, val2); - jedis.hmset(key3, hashMap); - jedis.hmset(key4, hashMap1); + jedis.set(key1, val1); + jedis.set(key2, val2); + jedis.hmset(key3, hashMap); + jedis.hmset(key4, hashMap1); - Pipeline pipeline = jedis.pipelined(); - pipeline.multi(); + Pipeline pipeline = jedis.pipelined(); + pipeline.multi(); - pipeline.get(key1); - pipeline.hgetAll(key2); - pipeline.hgetAll(key3); - pipeline.get(key4); + pipeline.get(key1); + pipeline.hgetAll(key2); + pipeline.hgetAll(key3); + pipeline.get(key4); - Response> response = pipeline.exec(); - pipeline.sync(); + Response> response = pipeline.exec(); + pipeline.sync(); - List result = response.get(); + List result = response.get(); - assertEquals(4, result.size()); + assertEquals(4, result.size()); - assertEquals("val1", result.get(0)); + assertEquals("val1", result.get(0)); - assertTrue(result.get(1) instanceof JedisDataException); + assertTrue(result.get(1) instanceof JedisDataException); - Map hashMapReceived = (Map) result - .get(2); - Iterator iterator = hashMapReceived.keySet().iterator(); - String mapKey1 = iterator.next(); - String mapKey2 = iterator.next(); - assertFalse(iterator.hasNext()); - verifyHasBothValues(mapKey1, mapKey2, field1, field2); - String mapValue1 = hashMapReceived.get(mapKey1); - String mapValue2 = hashMapReceived.get(mapKey2); - verifyHasBothValues(mapValue1, mapValue2, value1, value2); + Map hashMapReceived = (Map) result + .get(2); + Iterator iterator = hashMapReceived.keySet().iterator(); + String mapKey1 = iterator.next(); + String mapKey2 = iterator.next(); + assertFalse(iterator.hasNext()); + verifyHasBothValues(mapKey1, mapKey2, field1, field2); + String mapValue1 = hashMapReceived.get(mapKey1); + String mapValue2 = hashMapReceived.get(mapKey2); + verifyHasBothValues(mapValue1, mapValue2, value1, value2); - assertTrue(result.get(3) instanceof JedisDataException); + assertTrue(result.get(3) instanceof JedisDataException); } @Test public void testSyncWithNoCommandQueued() { - // we need to test with fresh instance of Jedis - Jedis jedis2 = new Jedis(hnp.getHost(), hnp.getPort(), 500); - - Pipeline pipeline = jedis2.pipelined(); - pipeline.sync(); - - jedis2.close(); - - jedis2 = new Jedis(hnp.getHost(), hnp.getPort(), 500); - - pipeline = jedis2.pipelined(); - List resp = pipeline.syncAndReturnAll(); - assertTrue(resp.isEmpty()); - - jedis2.close(); + // we need to test with fresh instance of Jedis + Jedis jedis2 = new Jedis(hnp.getHost(), hnp.getPort(), 500); + + Pipeline pipeline = jedis2.pipelined(); + pipeline.sync(); + + jedis2.close(); + + jedis2 = new Jedis(hnp.getHost(), hnp.getPort(), 500); + + pipeline = jedis2.pipelined(); + List resp = pipeline.syncAndReturnAll(); + assertTrue(resp.isEmpty()); + + jedis2.close(); } 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)); + String value1, String value2) { + assertFalse(firstKey.equals(secondKey)); + assertTrue(firstKey.equals(value1) || firstKey.equals(value2)); + assertTrue(secondKey.equals(value1) || secondKey.equals(value2)); } } diff --git a/src/test/java/redis/clients/jedis/tests/ProtocolTest.java b/src/test/java/redis/clients/jedis/tests/ProtocolTest.java index 5fbc2c7..79c6ee4 100644 --- a/src/test/java/redis/clients/jedis/tests/ProtocolTest.java +++ b/src/test/java/redis/clients/jedis/tests/ProtocolTest.java @@ -20,108 +20,108 @@ import redis.clients.util.SafeEncoder; public class ProtocolTest extends JedisTestBase { @Test public void buildACommand() throws IOException { - PipedInputStream pis = new PipedInputStream(); - BufferedInputStream bis = new BufferedInputStream(pis); - PipedOutputStream pos = new PipedOutputStream(pis); - RedisOutputStream ros = new RedisOutputStream(pos); + PipedInputStream pis = new PipedInputStream(); + BufferedInputStream bis = new BufferedInputStream(pis); + PipedOutputStream pos = new PipedOutputStream(pis); + RedisOutputStream ros = new RedisOutputStream(pos); - Protocol.sendCommand(ros, Protocol.Command.GET, - "SOMEKEY".getBytes(Protocol.CHARSET)); - ros.flush(); - pos.close(); - String expectedCommand = "*2\r\n$3\r\nGET\r\n$7\r\nSOMEKEY\r\n"; + Protocol.sendCommand(ros, Protocol.Command.GET, + "SOMEKEY".getBytes(Protocol.CHARSET)); + ros.flush(); + pos.close(); + String expectedCommand = "*2\r\n$3\r\nGET\r\n$7\r\nSOMEKEY\r\n"; - int b; - StringBuilder sb = new StringBuilder(); - while ((b = bis.read()) != -1) { - sb.append((char) b); - } + int b; + StringBuilder sb = new StringBuilder(); + while ((b = bis.read()) != -1) { + sb.append((char) b); + } - assertEquals(expectedCommand, sb.toString()); + assertEquals(expectedCommand, sb.toString()); } @Test(expected = IOException.class) public void writeOverflow() throws IOException { - RedisOutputStream ros = new RedisOutputStream(new OutputStream() { + RedisOutputStream ros = new RedisOutputStream(new OutputStream() { - @Override - public void write(int b) throws IOException { - throw new IOException("thrown exception"); + @Override + public void write(int b) throws IOException { + throw new IOException("thrown exception"); - } - }); + } + }); - ros.write(new byte[8191]); + ros.write(new byte[8191]); - try { - ros.write((byte) '*'); - } catch (IOException ioe) { - } + try { + ros.write((byte) '*'); + } catch (IOException ioe) { + } - ros.write((byte) '*'); + ros.write((byte) '*'); } @Test public void bulkReply() { - InputStream is = new ByteArrayInputStream("$6\r\nfoobar\r\n".getBytes()); - byte[] response = (byte[]) Protocol.read(new RedisInputStream(is)); - assertArrayEquals(SafeEncoder.encode("foobar"), response); + InputStream is = new ByteArrayInputStream("$6\r\nfoobar\r\n".getBytes()); + byte[] response = (byte[]) Protocol.read(new RedisInputStream(is)); + assertArrayEquals(SafeEncoder.encode("foobar"), response); } @Test public void fragmentedBulkReply() { - FragmentedByteArrayInputStream fis = new FragmentedByteArrayInputStream( - "$30\r\n012345678901234567890123456789\r\n".getBytes()); - byte[] response = (byte[]) Protocol.read(new RedisInputStream(fis)); - assertArrayEquals(SafeEncoder.encode("012345678901234567890123456789"), - response); + FragmentedByteArrayInputStream fis = new FragmentedByteArrayInputStream( + "$30\r\n012345678901234567890123456789\r\n".getBytes()); + byte[] response = (byte[]) Protocol.read(new RedisInputStream(fis)); + assertArrayEquals(SafeEncoder.encode("012345678901234567890123456789"), + response); } @Test public void nullBulkReply() { - InputStream is = new ByteArrayInputStream("$-1\r\n".getBytes()); - String response = (String) Protocol.read(new RedisInputStream(is)); - assertEquals(null, response); + InputStream is = new ByteArrayInputStream("$-1\r\n".getBytes()); + String response = (String) Protocol.read(new RedisInputStream(is)); + assertEquals(null, response); } @Test public void singleLineReply() { - InputStream is = new ByteArrayInputStream("+OK\r\n".getBytes()); - byte[] response = (byte[]) Protocol.read(new RedisInputStream(is)); - assertArrayEquals(SafeEncoder.encode("OK"), response); + InputStream is = new ByteArrayInputStream("+OK\r\n".getBytes()); + byte[] response = (byte[]) Protocol.read(new RedisInputStream(is)); + assertArrayEquals(SafeEncoder.encode("OK"), response); } @Test public void integerReply() { - InputStream is = new ByteArrayInputStream(":123\r\n".getBytes()); - long response = (Long) Protocol.read(new RedisInputStream(is)); - assertEquals(123, response); + InputStream is = new ByteArrayInputStream(":123\r\n".getBytes()); + long response = (Long) Protocol.read(new RedisInputStream(is)); + assertEquals(123, response); } @SuppressWarnings("unchecked") @Test public void multiBulkReply() { - InputStream is = new ByteArrayInputStream( - "*4\r\n$3\r\nfoo\r\n$3\r\nbar\r\n$5\r\nHello\r\n$5\r\nWorld\r\n" - .getBytes()); - List response = (List) Protocol - .read(new RedisInputStream(is)); - List expected = new ArrayList(); - expected.add(SafeEncoder.encode("foo")); - expected.add(SafeEncoder.encode("bar")); - expected.add(SafeEncoder.encode("Hello")); - expected.add(SafeEncoder.encode("World")); + InputStream is = new ByteArrayInputStream( + "*4\r\n$3\r\nfoo\r\n$3\r\nbar\r\n$5\r\nHello\r\n$5\r\nWorld\r\n" + .getBytes()); + List response = (List) Protocol + .read(new RedisInputStream(is)); + List expected = new ArrayList(); + expected.add(SafeEncoder.encode("foo")); + expected.add(SafeEncoder.encode("bar")); + expected.add(SafeEncoder.encode("Hello")); + expected.add(SafeEncoder.encode("World")); - assertEquals(expected, response); + assertEquals(expected, response); } @SuppressWarnings("unchecked") @Test public void nullMultiBulkReply() { - InputStream is = new ByteArrayInputStream("*-1\r\n".getBytes()); - List response = (List) Protocol - .read(new RedisInputStream(is)); - assertNull(response); + InputStream is = new ByteArrayInputStream("*-1\r\n".getBytes()); + List response = (List) Protocol + .read(new RedisInputStream(is)); + assertNull(response); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/ShardedJedisPipelineTest.java b/src/test/java/redis/clients/jedis/tests/ShardedJedisPipelineTest.java index a6dfaab..06f4487 100644 --- a/src/test/java/redis/clients/jedis/tests/ShardedJedisPipelineTest.java +++ b/src/test/java/redis/clients/jedis/tests/ShardedJedisPipelineTest.java @@ -29,135 +29,135 @@ import redis.clients.jedis.exceptions.JedisDataException; public class ShardedJedisPipelineTest { private static HostAndPort redis1 = HostAndPortUtil.getRedisServers() - .get(0); + .get(0); private static HostAndPort redis2 = HostAndPortUtil.getRedisServers() - .get(1); + .get(1); private ShardedJedis jedis; @Before public void setUp() throws Exception { - Jedis jedis = new Jedis(redis1.getHost(), redis1.getPort()); - jedis.auth("foobared"); - jedis.flushAll(); - jedis.disconnect(); - jedis = new Jedis(redis2.getHost(), redis2.getPort()); - jedis.auth("foobared"); - jedis.flushAll(); - jedis.disconnect(); + Jedis jedis = new Jedis(redis1.getHost(), redis1.getPort()); + jedis.auth("foobared"); + jedis.flushAll(); + jedis.disconnect(); + jedis = new Jedis(redis2.getHost(), redis2.getPort()); + jedis.auth("foobared"); + jedis.flushAll(); + jedis.disconnect(); - JedisShardInfo shardInfo1 = new JedisShardInfo(redis1.getHost(), - redis1.getPort()); - JedisShardInfo shardInfo2 = new JedisShardInfo(redis2.getHost(), - redis2.getPort()); - shardInfo1.setPassword("foobared"); - shardInfo2.setPassword("foobared"); - List shards = new ArrayList(); - shards.add(shardInfo1); - shards.add(shardInfo2); - this.jedis = new ShardedJedis(shards); + JedisShardInfo shardInfo1 = new JedisShardInfo(redis1.getHost(), + redis1.getPort()); + JedisShardInfo shardInfo2 = new JedisShardInfo(redis2.getHost(), + redis2.getPort()); + shardInfo1.setPassword("foobared"); + shardInfo2.setPassword("foobared"); + List shards = new ArrayList(); + shards.add(shardInfo1); + shards.add(shardInfo2); + this.jedis = new ShardedJedis(shards); } @Test public void pipeline() throws UnsupportedEncodingException { - ShardedJedisPipeline p = jedis.pipelined(); - p.set("foo", "bar"); - p.get("foo"); - List results = p.syncAndReturnAll(); + ShardedJedisPipeline p = jedis.pipelined(); + p.set("foo", "bar"); + p.get("foo"); + List results = p.syncAndReturnAll(); - assertEquals(2, results.size()); - assertEquals("OK", results.get(0)); - assertEquals("bar", results.get(1)); + assertEquals(2, results.size()); + assertEquals("OK", results.get(0)); + assertEquals("bar", results.get(1)); } @Test public void pipelineResponse() { - jedis.set("string", "foo"); - jedis.lpush("list", "foo"); - jedis.hset("hash", "foo", "bar"); - jedis.zadd("zset", 1, "foo"); - jedis.sadd("set", "foo"); + jedis.set("string", "foo"); + jedis.lpush("list", "foo"); + jedis.hset("hash", "foo", "bar"); + jedis.zadd("zset", 1, "foo"); + jedis.sadd("set", "foo"); - ShardedJedisPipeline p = jedis.pipelined(); - Response string = p.get("string"); - Response del = p.del("string"); - Response emptyString = p.get("string"); - Response list = p.lpop("list"); - Response hash = p.hget("hash", "foo"); - Response> zset = p.zrange("zset", 0, -1); - Response set = p.spop("set"); - Response blist = p.exists("list"); - Response zincrby = p.zincrby("zset", 1, "foo"); - Response zcard = p.zcard("zset"); - p.lpush("list", "bar"); - Response> lrange = p.lrange("list", 0, -1); - Response> hgetAll = p.hgetAll("hash"); - p.sadd("set", "foo"); - Response> smembers = p.smembers("set"); - Response> zrangeWithScores = p.zrangeWithScores("zset", 0, - -1); - p.sync(); + ShardedJedisPipeline p = jedis.pipelined(); + Response string = p.get("string"); + Response del = p.del("string"); + Response emptyString = p.get("string"); + Response list = p.lpop("list"); + Response hash = p.hget("hash", "foo"); + Response> zset = p.zrange("zset", 0, -1); + Response set = p.spop("set"); + Response blist = p.exists("list"); + Response zincrby = p.zincrby("zset", 1, "foo"); + Response zcard = p.zcard("zset"); + p.lpush("list", "bar"); + Response> lrange = p.lrange("list", 0, -1); + Response> hgetAll = p.hgetAll("hash"); + p.sadd("set", "foo"); + Response> smembers = p.smembers("set"); + Response> zrangeWithScores = p.zrangeWithScores("zset", 0, + -1); + p.sync(); - assertEquals("foo", string.get()); - assertEquals(Long.valueOf(1), del.get()); - assertNull(emptyString.get()); - assertEquals("foo", list.get()); - assertEquals("bar", hash.get()); - assertEquals("foo", zset.get().iterator().next()); - assertEquals("foo", set.get()); - assertFalse(blist.get()); - assertEquals(Double.valueOf(2), zincrby.get()); - assertEquals(Long.valueOf(1), zcard.get()); - assertEquals(1, lrange.get().size()); - assertNotNull(hgetAll.get().get("foo")); - assertEquals(1, smembers.get().size()); - assertEquals(1, zrangeWithScores.get().size()); + assertEquals("foo", string.get()); + assertEquals(Long.valueOf(1), del.get()); + assertNull(emptyString.get()); + assertEquals("foo", list.get()); + assertEquals("bar", hash.get()); + assertEquals("foo", zset.get().iterator().next()); + assertEquals("foo", set.get()); + assertFalse(blist.get()); + assertEquals(Double.valueOf(2), zincrby.get()); + assertEquals(Long.valueOf(1), zcard.get()); + assertEquals(1, lrange.get().size()); + assertNotNull(hgetAll.get().get("foo")); + assertEquals(1, smembers.get().size()); + assertEquals(1, zrangeWithScores.get().size()); } @Test(expected = JedisDataException.class) public void pipelineResponseWithinPipeline() { - jedis.set("string", "foo"); + jedis.set("string", "foo"); - ShardedJedisPipeline p = jedis.pipelined(); - Response string = p.get("string"); - string.get(); - p.sync(); + ShardedJedisPipeline p = jedis.pipelined(); + Response string = p.get("string"); + string.get(); + p.sync(); } @Test public void canRetrieveUnsetKey() { - ShardedJedisPipeline p = jedis.pipelined(); - Response shouldNotExist = p.get(UUID.randomUUID().toString()); - p.sync(); - assertNull(shouldNotExist.get()); + ShardedJedisPipeline p = jedis.pipelined(); + Response shouldNotExist = p.get(UUID.randomUUID().toString()); + p.sync(); + assertNull(shouldNotExist.get()); } @Test public void testSyncWithNoCommandQueued() { - JedisShardInfo shardInfo1 = new JedisShardInfo(redis1.getHost(), - redis1.getPort()); - JedisShardInfo shardInfo2 = new JedisShardInfo(redis2.getHost(), - redis2.getPort()); - shardInfo1.setPassword("foobared"); - shardInfo2.setPassword("foobared"); - List shards = new ArrayList(); - shards.add(shardInfo1); - shards.add(shardInfo2); - - ShardedJedis jedis2 = new ShardedJedis(shards); - - ShardedJedisPipeline pipeline = jedis2.pipelined(); - pipeline.sync(); - - jedis2.close(); - - jedis2 = new ShardedJedis(shards); - pipeline = jedis2.pipelined(); - List resp = pipeline.syncAndReturnAll(); - assertTrue(resp.isEmpty()); - - jedis2.close(); + JedisShardInfo shardInfo1 = new JedisShardInfo(redis1.getHost(), + redis1.getPort()); + JedisShardInfo shardInfo2 = new JedisShardInfo(redis2.getHost(), + redis2.getPort()); + shardInfo1.setPassword("foobared"); + shardInfo2.setPassword("foobared"); + List shards = new ArrayList(); + shards.add(shardInfo1); + shards.add(shardInfo2); + + ShardedJedis jedis2 = new ShardedJedis(shards); + + ShardedJedisPipeline pipeline = jedis2.pipelined(); + pipeline.sync(); + + jedis2.close(); + + jedis2 = new ShardedJedis(shards); + pipeline = jedis2.pipelined(); + List resp = pipeline.syncAndReturnAll(); + assertTrue(resp.isEmpty()); + + jedis2.close(); } } diff --git a/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java b/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java index 4b2da9c..148821f 100644 --- a/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java +++ b/src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java @@ -20,295 +20,295 @@ import redis.clients.jedis.exceptions.JedisConnectionException; public class ShardedJedisPoolTest extends Assert { private static HostAndPort redis1 = HostAndPortUtil.getRedisServers() - .get(0); + .get(0); private static HostAndPort redis2 = HostAndPortUtil.getRedisServers() - .get(1); + .get(1); private List shards; @Before public void startUp() { - shards = new ArrayList(); - shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort())); - shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort())); - shards.get(0).setPassword("foobared"); - shards.get(1).setPassword("foobared"); - Jedis j = new Jedis(shards.get(0)); - j.connect(); - j.flushAll(); - j.disconnect(); - j = new Jedis(shards.get(1)); - j.connect(); - j.flushAll(); - j.disconnect(); + shards = new ArrayList(); + shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort())); + shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort())); + shards.get(0).setPassword("foobared"); + shards.get(1).setPassword("foobared"); + Jedis j = new Jedis(shards.get(0)); + j.connect(); + j.flushAll(); + j.disconnect(); + j = new Jedis(shards.get(1)); + j.connect(); + j.flushAll(); + j.disconnect(); } @Test public void checkConnections() { - ShardedJedisPool pool = new ShardedJedisPool( - new GenericObjectPoolConfig(), shards); - ShardedJedis jedis = pool.getResource(); - jedis.set("foo", "bar"); - assertEquals("bar", jedis.get("foo")); - pool.returnResource(jedis); - pool.destroy(); + ShardedJedisPool pool = new ShardedJedisPool( + new GenericObjectPoolConfig(), shards); + ShardedJedis jedis = pool.getResource(); + jedis.set("foo", "bar"); + assertEquals("bar", jedis.get("foo")); + pool.returnResource(jedis); + pool.destroy(); } @Test public void checkCloseableConnections() throws Exception { - ShardedJedisPool pool = new ShardedJedisPool( - new GenericObjectPoolConfig(), shards); - ShardedJedis jedis = pool.getResource(); - jedis.set("foo", "bar"); - assertEquals("bar", jedis.get("foo")); - pool.returnResource(jedis); - pool.close(); - assertTrue(pool.isClosed()); + ShardedJedisPool pool = new ShardedJedisPool( + new GenericObjectPoolConfig(), shards); + ShardedJedis jedis = pool.getResource(); + jedis.set("foo", "bar"); + assertEquals("bar", jedis.get("foo")); + pool.returnResource(jedis); + pool.close(); + assertTrue(pool.isClosed()); } @Test public void checkConnectionWithDefaultPort() { - ShardedJedisPool pool = new ShardedJedisPool( - new GenericObjectPoolConfig(), shards); - ShardedJedis jedis = pool.getResource(); - jedis.set("foo", "bar"); - assertEquals("bar", jedis.get("foo")); - pool.returnResource(jedis); - pool.destroy(); + ShardedJedisPool pool = new ShardedJedisPool( + new GenericObjectPoolConfig(), shards); + ShardedJedis jedis = pool.getResource(); + jedis.set("foo", "bar"); + assertEquals("bar", jedis.get("foo")); + pool.returnResource(jedis); + pool.destroy(); } @Test public void checkJedisIsReusedWhenReturned() { - ShardedJedisPool pool = new ShardedJedisPool( - new GenericObjectPoolConfig(), shards); - ShardedJedis jedis = pool.getResource(); - jedis.set("foo", "0"); - pool.returnResource(jedis); + ShardedJedisPool pool = new ShardedJedisPool( + new GenericObjectPoolConfig(), shards); + ShardedJedis jedis = pool.getResource(); + jedis.set("foo", "0"); + pool.returnResource(jedis); - jedis = pool.getResource(); - jedis.incr("foo"); - pool.returnResource(jedis); - pool.destroy(); + jedis = pool.getResource(); + jedis.incr("foo"); + pool.returnResource(jedis); + pool.destroy(); } @Test public void checkPoolRepairedWhenJedisIsBroken() { - ShardedJedisPool pool = new ShardedJedisPool( - new GenericObjectPoolConfig(), shards); - ShardedJedis jedis = pool.getResource(); - jedis.disconnect(); - pool.returnBrokenResource(jedis); + ShardedJedisPool pool = new ShardedJedisPool( + new GenericObjectPoolConfig(), shards); + ShardedJedis jedis = pool.getResource(); + jedis.disconnect(); + pool.returnBrokenResource(jedis); - jedis = pool.getResource(); - jedis.incr("foo"); - pool.returnResource(jedis); - pool.destroy(); + jedis = pool.getResource(); + jedis.incr("foo"); + pool.returnResource(jedis); + pool.destroy(); } @Test(expected = JedisConnectionException.class) public void checkPoolOverflow() { - GenericObjectPoolConfig config = new GenericObjectPoolConfig(); - config.setMaxTotal(1); - config.setBlockWhenExhausted(false); + GenericObjectPoolConfig config = new GenericObjectPoolConfig(); + config.setMaxTotal(1); + config.setBlockWhenExhausted(false); - ShardedJedisPool pool = new ShardedJedisPool(config, shards); + ShardedJedisPool pool = new ShardedJedisPool(config, shards); - ShardedJedis jedis = pool.getResource(); - jedis.set("foo", "0"); + ShardedJedis jedis = pool.getResource(); + jedis.set("foo", "0"); - ShardedJedis newJedis = pool.getResource(); - newJedis.incr("foo"); + ShardedJedis newJedis = pool.getResource(); + newJedis.incr("foo"); } @Test public void shouldNotShareInstances() { - GenericObjectPoolConfig config = new GenericObjectPoolConfig(); - config.setMaxTotal(2); + GenericObjectPoolConfig config = new GenericObjectPoolConfig(); + config.setMaxTotal(2); - ShardedJedisPool pool = new ShardedJedisPool(config, shards); + ShardedJedisPool pool = new ShardedJedisPool(config, shards); - ShardedJedis j1 = pool.getResource(); - ShardedJedis j2 = pool.getResource(); + ShardedJedis j1 = pool.getResource(); + ShardedJedis j2 = pool.getResource(); - assertNotSame(j1.getShard("foo"), j2.getShard("foo")); + assertNotSame(j1.getShard("foo"), j2.getShard("foo")); } @Test public void checkFailedJedisServer() { - ShardedJedisPool pool = new ShardedJedisPool( - new GenericObjectPoolConfig(), shards); - ShardedJedis jedis = pool.getResource(); - jedis.incr("foo"); - pool.returnResource(jedis); - pool.destroy(); + ShardedJedisPool pool = new ShardedJedisPool( + new GenericObjectPoolConfig(), shards); + ShardedJedis jedis = pool.getResource(); + jedis.incr("foo"); + pool.returnResource(jedis); + pool.destroy(); } @Test public void shouldReturnActiveShardsWhenOneGoesOffline() { - GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig(); - redisConfig.setTestOnBorrow(false); - ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards); - ShardedJedis jedis = pool.getResource(); - // fill the shards - for (int i = 0; i < 1000; i++) { - jedis.set("a-test-" + i, "0"); - } - pool.returnResource(jedis); - // check quantity for each shard - Jedis j = new Jedis(shards.get(0)); - j.connect(); - Long c1 = j.dbSize(); - j.disconnect(); - j = new Jedis(shards.get(1)); - j.connect(); - Long c2 = j.dbSize(); - j.disconnect(); - // shutdown shard 2 and check thay the pool returns an instance with c1 - // items on one shard - // alter shard 1 and recreate pool - pool.destroy(); - shards.set(1, new JedisShardInfo("localhost", 1234)); - pool = new ShardedJedisPool(redisConfig, shards); - jedis = pool.getResource(); - Long actual = Long.valueOf(0); - Long fails = Long.valueOf(0); - for (int i = 0; i < 1000; i++) { - try { - jedis.get("a-test-" + i); - actual++; - } catch (RuntimeException e) { - fails++; - } - } - pool.returnResource(jedis); - pool.destroy(); - assertEquals(actual, c1); - assertEquals(fails, c2); + GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig(); + redisConfig.setTestOnBorrow(false); + ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards); + ShardedJedis jedis = pool.getResource(); + // fill the shards + for (int i = 0; i < 1000; i++) { + jedis.set("a-test-" + i, "0"); + } + pool.returnResource(jedis); + // check quantity for each shard + Jedis j = new Jedis(shards.get(0)); + j.connect(); + Long c1 = j.dbSize(); + j.disconnect(); + j = new Jedis(shards.get(1)); + j.connect(); + Long c2 = j.dbSize(); + j.disconnect(); + // shutdown shard 2 and check thay the pool returns an instance with c1 + // items on one shard + // alter shard 1 and recreate pool + pool.destroy(); + shards.set(1, new JedisShardInfo("localhost", 1234)); + pool = new ShardedJedisPool(redisConfig, shards); + jedis = pool.getResource(); + Long actual = Long.valueOf(0); + Long fails = Long.valueOf(0); + for (int i = 0; i < 1000; i++) { + try { + jedis.get("a-test-" + i); + actual++; + } catch (RuntimeException e) { + fails++; + } + } + pool.returnResource(jedis); + pool.destroy(); + assertEquals(actual, c1); + assertEquals(fails, c2); } @Test public void startWithUrlString() { - Jedis j = new Jedis("localhost", 6380); - j.auth("foobared"); - j.set("foo", "bar"); + Jedis j = new Jedis("localhost", 6380); + j.auth("foobared"); + j.set("foo", "bar"); - j = new Jedis("localhost", 6379); - j.auth("foobared"); - j.set("foo", "bar"); + j = new Jedis("localhost", 6379); + j.auth("foobared"); + j.set("foo", "bar"); - List shards = new ArrayList(); - shards.add(new JedisShardInfo("redis://:foobared@localhost:6380")); - shards.add(new JedisShardInfo("redis://:foobared@localhost:6379")); + List shards = new ArrayList(); + shards.add(new JedisShardInfo("redis://:foobared@localhost:6380")); + shards.add(new JedisShardInfo("redis://:foobared@localhost:6379")); - GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig(); - ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards); + GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig(); + ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards); - Jedis[] jedises = pool.getResource().getAllShards() - .toArray(new Jedis[2]); + Jedis[] jedises = pool.getResource().getAllShards() + .toArray(new Jedis[2]); - Jedis jedis = jedises[0]; - assertEquals("PONG", jedis.ping()); - assertEquals("bar", jedis.get("foo")); + Jedis jedis = jedises[0]; + assertEquals("PONG", jedis.ping()); + assertEquals("bar", jedis.get("foo")); - jedis = jedises[1]; - assertEquals("PONG", jedis.ping()); - assertEquals("bar", jedis.get("foo")); + jedis = jedises[1]; + assertEquals("PONG", jedis.ping()); + assertEquals("bar", jedis.get("foo")); } @Test public void startWithUrl() throws URISyntaxException { - Jedis j = new Jedis("localhost", 6380); - j.auth("foobared"); - j.set("foo", "bar"); + Jedis j = new Jedis("localhost", 6380); + j.auth("foobared"); + j.set("foo", "bar"); - j = new Jedis("localhost", 6379); - j.auth("foobared"); - j.set("foo", "bar"); + j = new Jedis("localhost", 6379); + j.auth("foobared"); + j.set("foo", "bar"); - List shards = new ArrayList(); - shards.add(new JedisShardInfo(new URI( - "redis://:foobared@localhost:6380"))); - shards.add(new JedisShardInfo(new URI( - "redis://:foobared@localhost:6379"))); + List shards = new ArrayList(); + shards.add(new JedisShardInfo(new URI( + "redis://:foobared@localhost:6380"))); + shards.add(new JedisShardInfo(new URI( + "redis://:foobared@localhost:6379"))); - GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig(); - ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards); + GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig(); + ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards); - Jedis[] jedises = pool.getResource().getAllShards() - .toArray(new Jedis[2]); + Jedis[] jedises = pool.getResource().getAllShards() + .toArray(new Jedis[2]); - Jedis jedis = jedises[0]; - assertEquals("PONG", jedis.ping()); - assertEquals("bar", jedis.get("foo")); + Jedis jedis = jedises[0]; + assertEquals("PONG", jedis.ping()); + assertEquals("bar", jedis.get("foo")); - jedis = jedises[1]; - assertEquals("PONG", jedis.ping()); - assertEquals("bar", jedis.get("foo")); + jedis = jedises[1]; + assertEquals("PONG", jedis.ping()); + assertEquals("bar", jedis.get("foo")); } @Test public void returnResourceShouldResetState() throws URISyntaxException { - GenericObjectPoolConfig config = new GenericObjectPoolConfig(); - config.setMaxTotal(1); - config.setBlockWhenExhausted(false); + GenericObjectPoolConfig config = new GenericObjectPoolConfig(); + config.setMaxTotal(1); + config.setBlockWhenExhausted(false); - List shards = new ArrayList(); - shards.add(new JedisShardInfo(new URI( - "redis://:foobared@localhost:6380"))); - shards.add(new JedisShardInfo(new URI( - "redis://:foobared@localhost:6379"))); + List shards = new ArrayList(); + shards.add(new JedisShardInfo(new URI( + "redis://:foobared@localhost:6380"))); + shards.add(new JedisShardInfo(new URI( + "redis://:foobared@localhost:6379"))); - ShardedJedisPool pool = new ShardedJedisPool(config, shards); + ShardedJedisPool pool = new ShardedJedisPool(config, shards); - ShardedJedis jedis = pool.getResource(); - jedis.set("pipelined", String.valueOf(0)); - jedis.set("pipelined2", String.valueOf(0)); + ShardedJedis jedis = pool.getResource(); + jedis.set("pipelined", String.valueOf(0)); + jedis.set("pipelined2", String.valueOf(0)); - ShardedJedisPipeline pipeline = jedis.pipelined(); + ShardedJedisPipeline pipeline = jedis.pipelined(); - pipeline.incr("pipelined"); - pipeline.incr("pipelined2"); + pipeline.incr("pipelined"); + pipeline.incr("pipelined2"); - jedis.resetState(); + jedis.resetState(); - pipeline = jedis.pipelined(); - pipeline.incr("pipelined"); - pipeline.incr("pipelined2"); - List results = pipeline.syncAndReturnAll(); + pipeline = jedis.pipelined(); + pipeline.incr("pipelined"); + pipeline.incr("pipelined2"); + List results = pipeline.syncAndReturnAll(); - assertEquals(2, results.size()); - pool.returnResource(jedis); - pool.destroy(); + assertEquals(2, results.size()); + pool.returnResource(jedis); + pool.destroy(); } @Test public void checkResourceIsCloseable() throws URISyntaxException { - GenericObjectPoolConfig config = new GenericObjectPoolConfig(); - config.setMaxTotal(1); - config.setBlockWhenExhausted(false); + GenericObjectPoolConfig config = new GenericObjectPoolConfig(); + config.setMaxTotal(1); + config.setBlockWhenExhausted(false); - List shards = new ArrayList(); - shards.add(new JedisShardInfo(new URI( - "redis://:foobared@localhost:6380"))); - shards.add(new JedisShardInfo(new URI( - "redis://:foobared@localhost:6379"))); + List shards = new ArrayList(); + shards.add(new JedisShardInfo(new URI( + "redis://:foobared@localhost:6380"))); + shards.add(new JedisShardInfo(new URI( + "redis://:foobared@localhost:6379"))); - ShardedJedisPool pool = new ShardedJedisPool(config, shards); + ShardedJedisPool pool = new ShardedJedisPool(config, shards); - ShardedJedis jedis = pool.getResource(); - try { - jedis.set("hello", "jedis"); - } finally { - jedis.close(); - } + ShardedJedis jedis = pool.getResource(); + try { + jedis.set("hello", "jedis"); + } finally { + jedis.close(); + } - ShardedJedis jedis2 = pool.getResource(); - try { - assertEquals(jedis, jedis2); - } finally { - jedis2.close(); - } + ShardedJedis jedis2 = pool.getResource(); + try { + assertEquals(jedis, jedis2); + } finally { + jedis2.close(); + } } } diff --git a/src/test/java/redis/clients/jedis/tests/ShardedJedisTest.java b/src/test/java/redis/clients/jedis/tests/ShardedJedisTest.java index 74b2e4b..006a063 100644 --- a/src/test/java/redis/clients/jedis/tests/ShardedJedisTest.java +++ b/src/test/java/redis/clients/jedis/tests/ShardedJedisTest.java @@ -18,278 +18,278 @@ import redis.clients.util.Sharded; public class ShardedJedisTest extends Assert { private static HostAndPort redis1 = HostAndPortUtil.getRedisServers() - .get(0); + .get(0); private static HostAndPort redis2 = HostAndPortUtil.getRedisServers() - .get(1); + .get(1); private List getKeysDifferentShard(ShardedJedis jedis) { - List ret = new ArrayList(); - JedisShardInfo first = jedis.getShardInfo("a0"); - ret.add("a0"); - for (int i = 1; i < 100; ++i) { - JedisShardInfo actual = jedis.getShardInfo("a" + i); - if (actual != first) { - ret.add("a" + i); - break; + List ret = new ArrayList(); + JedisShardInfo first = jedis.getShardInfo("a0"); + ret.add("a0"); + for (int i = 1; i < 100; ++i) { + JedisShardInfo actual = jedis.getShardInfo("a" + i); + if (actual != first) { + ret.add("a" + i); + break; - } + } - } - return ret; + } + return ret; } @Test public void checkSharding() { - List shards = new ArrayList(); - shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort())); - shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort())); - ShardedJedis jedis = new ShardedJedis(shards); - List keys = getKeysDifferentShard(jedis); - JedisShardInfo s1 = jedis.getShardInfo(keys.get(0)); - JedisShardInfo s2 = jedis.getShardInfo(keys.get(1)); - assertNotSame(s1, s2); + List shards = new ArrayList(); + shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort())); + shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort())); + ShardedJedis jedis = new ShardedJedis(shards); + List keys = getKeysDifferentShard(jedis); + JedisShardInfo s1 = jedis.getShardInfo(keys.get(0)); + JedisShardInfo s2 = jedis.getShardInfo(keys.get(1)); + assertNotSame(s1, s2); } @Test public void trySharding() { - List shards = new ArrayList(); - JedisShardInfo si = new JedisShardInfo(redis1.getHost(), - redis1.getPort()); - si.setPassword("foobared"); - shards.add(si); - si = new JedisShardInfo(redis2.getHost(), redis2.getPort()); - si.setPassword("foobared"); - shards.add(si); - ShardedJedis jedis = new ShardedJedis(shards); - jedis.set("a", "bar"); - JedisShardInfo s1 = jedis.getShardInfo("a"); - jedis.set("b", "bar1"); - JedisShardInfo s2 = jedis.getShardInfo("b"); - jedis.disconnect(); + List shards = new ArrayList(); + JedisShardInfo si = new JedisShardInfo(redis1.getHost(), + redis1.getPort()); + si.setPassword("foobared"); + shards.add(si); + si = new JedisShardInfo(redis2.getHost(), redis2.getPort()); + si.setPassword("foobared"); + shards.add(si); + ShardedJedis jedis = new ShardedJedis(shards); + jedis.set("a", "bar"); + JedisShardInfo s1 = jedis.getShardInfo("a"); + jedis.set("b", "bar1"); + JedisShardInfo s2 = jedis.getShardInfo("b"); + jedis.disconnect(); - Jedis j = new Jedis(s1.getHost(), s1.getPort()); - j.auth("foobared"); - assertEquals("bar", j.get("a")); - j.disconnect(); + Jedis j = new Jedis(s1.getHost(), s1.getPort()); + j.auth("foobared"); + assertEquals("bar", j.get("a")); + j.disconnect(); - j = new Jedis(s2.getHost(), s2.getPort()); - j.auth("foobared"); - assertEquals("bar1", j.get("b")); - j.disconnect(); + j = new Jedis(s2.getHost(), s2.getPort()); + j.auth("foobared"); + assertEquals("bar1", j.get("b")); + j.disconnect(); } @Test public void tryShardingWithMurmure() { - List shards = new ArrayList(); - JedisShardInfo si = new JedisShardInfo(redis1.getHost(), - redis1.getPort()); - si.setPassword("foobared"); - shards.add(si); - si = new JedisShardInfo(redis2.getHost(), redis2.getPort()); - si.setPassword("foobared"); - shards.add(si); - ShardedJedis jedis = new ShardedJedis(shards, Hashing.MURMUR_HASH); - jedis.set("a", "bar"); - JedisShardInfo s1 = jedis.getShardInfo("a"); - jedis.set("b", "bar1"); - JedisShardInfo s2 = jedis.getShardInfo("b"); - jedis.disconnect(); + List shards = new ArrayList(); + JedisShardInfo si = new JedisShardInfo(redis1.getHost(), + redis1.getPort()); + si.setPassword("foobared"); + shards.add(si); + si = new JedisShardInfo(redis2.getHost(), redis2.getPort()); + si.setPassword("foobared"); + shards.add(si); + ShardedJedis jedis = new ShardedJedis(shards, Hashing.MURMUR_HASH); + jedis.set("a", "bar"); + JedisShardInfo s1 = jedis.getShardInfo("a"); + jedis.set("b", "bar1"); + JedisShardInfo s2 = jedis.getShardInfo("b"); + jedis.disconnect(); - Jedis j = new Jedis(s1.getHost(), s1.getPort()); - j.auth("foobared"); - assertEquals("bar", j.get("a")); - j.disconnect(); + Jedis j = new Jedis(s1.getHost(), s1.getPort()); + j.auth("foobared"); + assertEquals("bar", j.get("a")); + j.disconnect(); - j = new Jedis(s2.getHost(), s2.getPort()); - j.auth("foobared"); - assertEquals("bar1", j.get("b")); - j.disconnect(); + j = new Jedis(s2.getHost(), s2.getPort()); + j.auth("foobared"); + assertEquals("bar1", j.get("b")); + j.disconnect(); } @Test public void checkKeyTags() { - List shards = new ArrayList(); - shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort())); - shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort())); - ShardedJedis jedis = new ShardedJedis(shards, - ShardedJedis.DEFAULT_KEY_TAG_PATTERN); + List shards = new ArrayList(); + shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort())); + shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort())); + ShardedJedis jedis = new ShardedJedis(shards, + ShardedJedis.DEFAULT_KEY_TAG_PATTERN); - assertEquals(jedis.getKeyTag("foo"), "foo"); - assertEquals(jedis.getKeyTag("foo{bar}"), "bar"); - assertEquals(jedis.getKeyTag("foo{bar}}"), "bar"); // default pattern is - // non greedy - assertEquals(jedis.getKeyTag("{bar}foo"), "bar"); // Key tag may appear - // anywhere - assertEquals(jedis.getKeyTag("f{bar}oo"), "bar"); // Key tag may appear - // anywhere + assertEquals(jedis.getKeyTag("foo"), "foo"); + assertEquals(jedis.getKeyTag("foo{bar}"), "bar"); + assertEquals(jedis.getKeyTag("foo{bar}}"), "bar"); // default pattern is + // non greedy + assertEquals(jedis.getKeyTag("{bar}foo"), "bar"); // Key tag may appear + // anywhere + assertEquals(jedis.getKeyTag("f{bar}oo"), "bar"); // Key tag may appear + // anywhere - JedisShardInfo s1 = jedis.getShardInfo("abc{bar}"); - JedisShardInfo s2 = jedis.getShardInfo("foo{bar}"); - assertSame(s1, s2); + JedisShardInfo s1 = jedis.getShardInfo("abc{bar}"); + JedisShardInfo s2 = jedis.getShardInfo("foo{bar}"); + assertSame(s1, s2); - List keys = getKeysDifferentShard(jedis); - JedisShardInfo s3 = jedis.getShardInfo(keys.get(0)); - JedisShardInfo s4 = jedis.getShardInfo(keys.get(1)); - assertNotSame(s3, s4); + List keys = getKeysDifferentShard(jedis); + JedisShardInfo s3 = jedis.getShardInfo(keys.get(0)); + JedisShardInfo s4 = jedis.getShardInfo(keys.get(1)); + assertNotSame(s3, s4); - ShardedJedis jedis2 = new ShardedJedis(shards); + ShardedJedis jedis2 = new ShardedJedis(shards); - assertEquals(jedis2.getKeyTag("foo"), "foo"); - assertNotSame(jedis2.getKeyTag("foo{bar}"), "bar"); + assertEquals(jedis2.getKeyTag("foo"), "foo"); + assertNotSame(jedis2.getKeyTag("foo{bar}"), "bar"); - JedisShardInfo s5 = jedis2.getShardInfo(keys.get(0) + "{bar}"); - JedisShardInfo s6 = jedis2.getShardInfo(keys.get(1) + "{bar}"); - assertNotSame(s5, s6); + JedisShardInfo s5 = jedis2.getShardInfo(keys.get(0) + "{bar}"); + JedisShardInfo s6 = jedis2.getShardInfo(keys.get(1) + "{bar}"); + assertNotSame(s5, s6); } @Test public void testMD5Sharding() { - List shards = new ArrayList(3); - shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT)); - shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1)); - shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2)); - Sharded sharded = new Sharded( - shards, Hashing.MD5); - int shard_6379 = 0; - int shard_6380 = 0; - int shard_6381 = 0; - for (int i = 0; i < 1000; i++) { - JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer - .toString(i)); - switch (jedisShardInfo.getPort()) { - case 6379: - shard_6379++; - break; - case 6380: - shard_6380++; - break; - case 6381: - shard_6381++; - break; - default: - fail("Attempting to use a non-defined shard!!:" - + jedisShardInfo); - break; - } - } - assertTrue(shard_6379 > 300 && shard_6379 < 400); - assertTrue(shard_6380 > 300 && shard_6380 < 400); - assertTrue(shard_6381 > 300 && shard_6381 < 400); + List shards = new ArrayList(3); + shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT)); + shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1)); + shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2)); + Sharded sharded = new Sharded( + shards, Hashing.MD5); + int shard_6379 = 0; + int shard_6380 = 0; + int shard_6381 = 0; + for (int i = 0; i < 1000; i++) { + JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer + .toString(i)); + switch (jedisShardInfo.getPort()) { + case 6379: + shard_6379++; + break; + case 6380: + shard_6380++; + break; + case 6381: + shard_6381++; + break; + default: + fail("Attempting to use a non-defined shard!!:" + + jedisShardInfo); + break; + } + } + assertTrue(shard_6379 > 300 && shard_6379 < 400); + assertTrue(shard_6380 > 300 && shard_6380 < 400); + assertTrue(shard_6381 > 300 && shard_6381 < 400); } @Test public void testMurmurSharding() { - List shards = new ArrayList(3); - shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT)); - shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1)); - shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2)); - Sharded sharded = new Sharded( - shards, Hashing.MURMUR_HASH); - int shard_6379 = 0; - int shard_6380 = 0; - int shard_6381 = 0; - for (int i = 0; i < 1000; i++) { - JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer - .toString(i)); - switch (jedisShardInfo.getPort()) { - case 6379: - shard_6379++; - break; - case 6380: - shard_6380++; - break; - case 6381: - shard_6381++; - break; - default: - fail("Attempting to use a non-defined shard!!:" - + jedisShardInfo); - break; - } - } - assertTrue(shard_6379 > 300 && shard_6379 < 400); - assertTrue(shard_6380 > 300 && shard_6380 < 400); - assertTrue(shard_6381 > 300 && shard_6381 < 400); + List shards = new ArrayList(3); + shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT)); + shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1)); + shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2)); + Sharded sharded = new Sharded( + shards, Hashing.MURMUR_HASH); + int shard_6379 = 0; + int shard_6380 = 0; + int shard_6381 = 0; + for (int i = 0; i < 1000; i++) { + JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer + .toString(i)); + switch (jedisShardInfo.getPort()) { + case 6379: + shard_6379++; + break; + case 6380: + shard_6380++; + break; + case 6381: + shard_6381++; + break; + default: + fail("Attempting to use a non-defined shard!!:" + + jedisShardInfo); + break; + } + } + assertTrue(shard_6379 > 300 && shard_6379 < 400); + assertTrue(shard_6380 > 300 && shard_6380 < 400); + assertTrue(shard_6381 > 300 && shard_6381 < 400); } @Test public void testMasterSlaveShardingConsistency() { - List shards = new ArrayList(3); - shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT)); - shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1)); - shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2)); - Sharded sharded = new Sharded( - shards, Hashing.MURMUR_HASH); + List shards = new ArrayList(3); + shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT)); + shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1)); + shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2)); + Sharded sharded = new Sharded( + shards, Hashing.MURMUR_HASH); - List otherShards = new ArrayList(3); - otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT)); - otherShards.add(new JedisShardInfo("otherhost", - Protocol.DEFAULT_PORT + 1)); - otherShards.add(new JedisShardInfo("otherhost", - Protocol.DEFAULT_PORT + 2)); - Sharded sharded2 = new Sharded( - otherShards, Hashing.MURMUR_HASH); + List otherShards = new ArrayList(3); + otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT)); + otherShards.add(new JedisShardInfo("otherhost", + Protocol.DEFAULT_PORT + 1)); + otherShards.add(new JedisShardInfo("otherhost", + Protocol.DEFAULT_PORT + 2)); + Sharded sharded2 = new Sharded( + otherShards, Hashing.MURMUR_HASH); - for (int i = 0; i < 1000; i++) { - JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer - .toString(i)); - JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer - .toString(i)); - assertEquals(shards.indexOf(jedisShardInfo), - otherShards.indexOf(jedisShardInfo2)); - } + for (int i = 0; i < 1000; i++) { + JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer + .toString(i)); + JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer + .toString(i)); + assertEquals(shards.indexOf(jedisShardInfo), + otherShards.indexOf(jedisShardInfo2)); + } } @Test public void testMasterSlaveShardingConsistencyWithShardNaming() { - List shards = new ArrayList(3); - shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT, - "HOST1:1234")); - shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1, - "HOST2:1234")); - shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2, - "HOST3:1234")); - Sharded sharded = new Sharded( - shards, Hashing.MURMUR_HASH); + List shards = new ArrayList(3); + shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT, + "HOST1:1234")); + shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1, + "HOST2:1234")); + shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2, + "HOST3:1234")); + Sharded sharded = new Sharded( + shards, Hashing.MURMUR_HASH); - List otherShards = new ArrayList(3); - otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT, - "HOST2:1234")); - otherShards.add(new JedisShardInfo("otherhost", - Protocol.DEFAULT_PORT + 1, "HOST3:1234")); - otherShards.add(new JedisShardInfo("otherhost", - Protocol.DEFAULT_PORT + 2, "HOST1:1234")); - Sharded sharded2 = new Sharded( - otherShards, Hashing.MURMUR_HASH); + List otherShards = new ArrayList(3); + otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT, + "HOST2:1234")); + otherShards.add(new JedisShardInfo("otherhost", + Protocol.DEFAULT_PORT + 1, "HOST3:1234")); + otherShards.add(new JedisShardInfo("otherhost", + Protocol.DEFAULT_PORT + 2, "HOST1:1234")); + Sharded sharded2 = new Sharded( + otherShards, Hashing.MURMUR_HASH); - for (int i = 0; i < 1000; i++) { - JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer - .toString(i)); - JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer - .toString(i)); - assertEquals(jedisShardInfo.getName(), jedisShardInfo2.getName()); - } + for (int i = 0; i < 1000; i++) { + JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer + .toString(i)); + JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer + .toString(i)); + assertEquals(jedisShardInfo.getName(), jedisShardInfo2.getName()); + } } @Test public void checkCloseable() { - List shards = new ArrayList(); - shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort())); - shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort())); - shards.get(0).setPassword("foobared"); - shards.get(1).setPassword("foobared"); + List shards = new ArrayList(); + shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort())); + shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort())); + shards.get(0).setPassword("foobared"); + shards.get(1).setPassword("foobared"); - ShardedJedis jedisShard = new ShardedJedis(shards); - try { - jedisShard.set("shard_closeable", "true"); - } finally { - jedisShard.close(); - } + ShardedJedis jedisShard = new ShardedJedis(shards); + try { + jedisShard.set("shard_closeable", "true"); + } finally { + jedisShard.close(); + } - for (Jedis jedis : jedisShard.getAllShards()) { - assertTrue(!jedis.isConnected()); - } + for (Jedis jedis : jedisShard.getAllShards()) { + assertTrue(!jedis.isConnected()); + } } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/benchmark/CRC16Benchmark.java b/src/test/java/redis/clients/jedis/tests/benchmark/CRC16Benchmark.java index 666851b..311c000 100644 --- a/src/test/java/redis/clients/jedis/tests/benchmark/CRC16Benchmark.java +++ b/src/test/java/redis/clients/jedis/tests/benchmark/CRC16Benchmark.java @@ -8,19 +8,19 @@ public class CRC16Benchmark { private static final int TOTAL_OPERATIONS = 100000000; private static String[] TEST_SET = { "", "123456789", "sfger132515", - "hae9Napahngaikeethievubaibogiech", "AAAAAAAAAAAAAAAAAAAAAA", - "Hello, World!" }; + "hae9Napahngaikeethievubaibogiech", "AAAAAAAAAAAAAAAAAAAAAA", + "Hello, World!" }; public static void main(String[] args) { - long begin = Calendar.getInstance().getTimeInMillis(); + long begin = Calendar.getInstance().getTimeInMillis(); - for (int n = 0; n <= TOTAL_OPERATIONS; n++) { - JedisClusterCRC16.getSlot(TEST_SET[n % TEST_SET.length]); - } + for (int n = 0; n <= TOTAL_OPERATIONS; n++) { + JedisClusterCRC16.getSlot(TEST_SET[n % TEST_SET.length]); + } - long elapsed = Calendar.getInstance().getTimeInMillis() - begin; + long elapsed = Calendar.getInstance().getTimeInMillis() - begin; - System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed) + " ops"); + System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed) + " ops"); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/benchmark/GetSetBenchmark.java b/src/test/java/redis/clients/jedis/tests/benchmark/GetSetBenchmark.java index 4eaa17b..115f38d 100644 --- a/src/test/java/redis/clients/jedis/tests/benchmark/GetSetBenchmark.java +++ b/src/test/java/redis/clients/jedis/tests/benchmark/GetSetBenchmark.java @@ -13,24 +13,24 @@ public class GetSetBenchmark { private static final int TOTAL_OPERATIONS = 100000; public static void main(String[] args) throws UnknownHostException, - IOException { - Jedis jedis = new Jedis(hnp.getHost(), hnp.getPort()); - jedis.connect(); - jedis.auth("foobared"); - jedis.flushAll(); + IOException { + Jedis jedis = new Jedis(hnp.getHost(), hnp.getPort()); + jedis.connect(); + jedis.auth("foobared"); + jedis.flushAll(); - long begin = Calendar.getInstance().getTimeInMillis(); + long begin = Calendar.getInstance().getTimeInMillis(); - for (int n = 0; n <= TOTAL_OPERATIONS; n++) { - String key = "foo" + n; - jedis.set(key, "bar" + n); - jedis.get(key); - } + for (int n = 0; n <= TOTAL_OPERATIONS; n++) { + String key = "foo" + n; + jedis.set(key, "bar" + n); + jedis.get(key); + } - long elapsed = Calendar.getInstance().getTimeInMillis() - begin; + long elapsed = Calendar.getInstance().getTimeInMillis() - begin; - jedis.disconnect(); + jedis.disconnect(); - System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops"); + System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops"); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/benchmark/HashingBenchmark.java b/src/test/java/redis/clients/jedis/tests/benchmark/HashingBenchmark.java index 4c75e5a..fabb690 100644 --- a/src/test/java/redis/clients/jedis/tests/benchmark/HashingBenchmark.java +++ b/src/test/java/redis/clients/jedis/tests/benchmark/HashingBenchmark.java @@ -19,33 +19,33 @@ public class HashingBenchmark { private static final int TOTAL_OPERATIONS = 100000; public static void main(String[] args) throws UnknownHostException, - IOException { - List shards = new ArrayList(); - JedisShardInfo shard = new JedisShardInfo(hnp1.getHost(), - hnp1.getPort()); - shard.setPassword("foobared"); - shards.add(shard); - shard = new JedisShardInfo(hnp2.getHost(), hnp2.getPort()); - shard.setPassword("foobared"); - shards.add(shard); - ShardedJedis jedis = new ShardedJedis(shards); - Collection allShards = jedis.getAllShards(); - for (Jedis j : allShards) { - j.flushAll(); - } + IOException { + List shards = new ArrayList(); + JedisShardInfo shard = new JedisShardInfo(hnp1.getHost(), + hnp1.getPort()); + shard.setPassword("foobared"); + shards.add(shard); + shard = new JedisShardInfo(hnp2.getHost(), hnp2.getPort()); + shard.setPassword("foobared"); + shards.add(shard); + ShardedJedis jedis = new ShardedJedis(shards); + Collection allShards = jedis.getAllShards(); + for (Jedis j : allShards) { + j.flushAll(); + } - long begin = Calendar.getInstance().getTimeInMillis(); + long begin = Calendar.getInstance().getTimeInMillis(); - for (int n = 0; n <= TOTAL_OPERATIONS; n++) { - String key = "foo" + n; - jedis.set(key, "bar" + n); - jedis.get(key); - } + for (int n = 0; n <= TOTAL_OPERATIONS; n++) { + String key = "foo" + n; + jedis.set(key, "bar" + n); + jedis.get(key); + } - long elapsed = Calendar.getInstance().getTimeInMillis() - begin; + long elapsed = Calendar.getInstance().getTimeInMillis() - begin; - jedis.disconnect(); + jedis.disconnect(); - System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops"); + System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops"); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/benchmark/PipelinedGetSetBenchmark.java b/src/test/java/redis/clients/jedis/tests/benchmark/PipelinedGetSetBenchmark.java index b783ca4..86fd0c5 100644 --- a/src/test/java/redis/clients/jedis/tests/benchmark/PipelinedGetSetBenchmark.java +++ b/src/test/java/redis/clients/jedis/tests/benchmark/PipelinedGetSetBenchmark.java @@ -14,26 +14,26 @@ public class PipelinedGetSetBenchmark { private static final int TOTAL_OPERATIONS = 200000; public static void main(String[] args) throws UnknownHostException, - IOException { - Jedis jedis = new Jedis(hnp.getHost(), hnp.getPort()); - jedis.connect(); - jedis.auth("foobared"); - jedis.flushAll(); + IOException { + Jedis jedis = new Jedis(hnp.getHost(), hnp.getPort()); + jedis.connect(); + jedis.auth("foobared"); + jedis.flushAll(); - long begin = Calendar.getInstance().getTimeInMillis(); + long begin = Calendar.getInstance().getTimeInMillis(); - Pipeline p = jedis.pipelined(); - for (int n = 0; n <= TOTAL_OPERATIONS; n++) { - String key = "foo" + n; - p.set(key, "bar" + n); - p.get(key); - } - p.sync(); + Pipeline p = jedis.pipelined(); + for (int n = 0; n <= TOTAL_OPERATIONS; n++) { + String key = "foo" + n; + p.set(key, "bar" + n); + p.get(key); + } + p.sync(); - long elapsed = Calendar.getInstance().getTimeInMillis() - begin; + long elapsed = Calendar.getInstance().getTimeInMillis() - begin; - jedis.disconnect(); + jedis.disconnect(); - System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops"); + System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops"); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/benchmark/PoolBenchmark.java b/src/test/java/redis/clients/jedis/tests/benchmark/PoolBenchmark.java index 095ee5b..6f174df 100644 --- a/src/test/java/redis/clients/jedis/tests/benchmark/PoolBenchmark.java +++ b/src/test/java/redis/clients/jedis/tests/benchmark/PoolBenchmark.java @@ -16,49 +16,49 @@ public class PoolBenchmark { private static final int TOTAL_OPERATIONS = 100000; public static void main(String[] args) throws Exception { - Jedis j = new Jedis(hnp.getHost(), hnp.getPort()); - j.connect(); - j.auth("foobared"); - j.flushAll(); - j.quit(); - j.disconnect(); - long t = System.currentTimeMillis(); - // withoutPool(); - withPool(); - long elapsed = System.currentTimeMillis() - t; - System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops"); + Jedis j = new Jedis(hnp.getHost(), hnp.getPort()); + j.connect(); + j.auth("foobared"); + j.flushAll(); + j.quit(); + j.disconnect(); + long t = System.currentTimeMillis(); + // withoutPool(); + withPool(); + long elapsed = System.currentTimeMillis() - t; + System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops"); } private static void withPool() throws Exception { - final JedisPool pool = new JedisPool(new GenericObjectPoolConfig(), - hnp.getHost(), hnp.getPort(), 2000, "foobared"); - List tds = new ArrayList(); + final JedisPool pool = new JedisPool(new GenericObjectPoolConfig(), + hnp.getHost(), hnp.getPort(), 2000, "foobared"); + List tds = new ArrayList(); - final AtomicInteger ind = new AtomicInteger(); - for (int i = 0; i < 50; i++) { - Thread hj = new Thread(new Runnable() { - public void run() { - for (int i = 0; (i = ind.getAndIncrement()) < TOTAL_OPERATIONS;) { - try { - Jedis j = pool.getResource(); - final String key = "foo" + i; - j.set(key, key); - j.get(key); - pool.returnResource(j); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - }); - tds.add(hj); - hj.start(); - } + final AtomicInteger ind = new AtomicInteger(); + for (int i = 0; i < 50; i++) { + Thread hj = new Thread(new Runnable() { + public void run() { + for (int i = 0; (i = ind.getAndIncrement()) < TOTAL_OPERATIONS;) { + try { + Jedis j = pool.getResource(); + final String key = "foo" + i; + j.set(key, key); + j.get(key); + pool.returnResource(j); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + }); + tds.add(hj); + hj.start(); + } - for (Thread t : tds) - t.join(); + for (Thread t : tds) + t.join(); - pool.destroy(); + pool.destroy(); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/benchmark/ProtocolBenchmark.java b/src/test/java/redis/clients/jedis/tests/benchmark/ProtocolBenchmark.java index eacdfa9..9d828ab 100644 --- a/src/test/java/redis/clients/jedis/tests/benchmark/ProtocolBenchmark.java +++ b/src/test/java/redis/clients/jedis/tests/benchmark/ProtocolBenchmark.java @@ -17,89 +17,89 @@ public class ProtocolBenchmark { private static final int TOTAL_OPERATIONS = 500000; public static void main(String[] args) throws Exception, - IOException { - long total = 0; - for (int at = 0; at != 10; ++at) { - long elapsed = measureInputMulti(); - long ops = ((1000 * 2 * TOTAL_OPERATIONS) / TimeUnit.NANOSECONDS.toMillis(elapsed)); - if (at >= 5) { - total += ops; - } - } - System.out.println((total / 5) + " avg"); + IOException { + long total = 0; + for (int at = 0; at != 10; ++at) { + long elapsed = measureInputMulti(); + long ops = ((1000 * 2 * TOTAL_OPERATIONS) / TimeUnit.NANOSECONDS.toMillis(elapsed)); + if (at >= 5) { + total += ops; + } + } + System.out.println((total / 5) + " avg"); - total = 0; - for (int at = 0; at != 10; ++at) { - long elapsed = measureInputStatus(); - long ops = ((1000 * 2 * TOTAL_OPERATIONS) / TimeUnit.NANOSECONDS.toMillis(elapsed)); - if (at >= 5) { - total += ops; - } - } + total = 0; + for (int at = 0; at != 10; ++at) { + long elapsed = measureInputStatus(); + long ops = ((1000 * 2 * TOTAL_OPERATIONS) / TimeUnit.NANOSECONDS.toMillis(elapsed)); + if (at >= 5) { + total += ops; + } + } - System.out.println((total / 5) + " avg"); + System.out.println((total / 5) + " avg"); - total = 0; - for (int at = 0; at != 10; ++at) { - long elapsed = measureCommand(); - long ops = ((1000 * 2 * TOTAL_OPERATIONS) / TimeUnit.NANOSECONDS.toMillis(elapsed)); - if (at >= 5) { - total += ops; - } - } + total = 0; + for (int at = 0; at != 10; ++at) { + long elapsed = measureCommand(); + long ops = ((1000 * 2 * TOTAL_OPERATIONS) / TimeUnit.NANOSECONDS.toMillis(elapsed)); + if (at >= 5) { + total += ops; + } + } - System.out.println((total / 5) + " avg"); + System.out.println((total / 5) + " avg"); } private static long measureInputMulti() throws Exception { - long duration = 0; + long duration = 0; - InputStream is = new ByteArrayInputStream( - "*4\r\n$3\r\nfoo\r\n$13\r\nbarbarbarfooz\r\n$5\r\nHello\r\n$5\r\nWorld\r\n" - .getBytes()); + InputStream is = new ByteArrayInputStream( + "*4\r\n$3\r\nfoo\r\n$13\r\nbarbarbarfooz\r\n$5\r\nHello\r\n$5\r\nWorld\r\n" + .getBytes()); - RedisInputStream in = new RedisInputStream(is); - for (int n = 0; n <= TOTAL_OPERATIONS; n++) { - long start = System.nanoTime(); - Protocol.read(in); - duration += (System.nanoTime() - start); - in.reset(); - } + RedisInputStream in = new RedisInputStream(is); + for (int n = 0; n <= TOTAL_OPERATIONS; n++) { + long start = System.nanoTime(); + Protocol.read(in); + duration += (System.nanoTime() - start); + in.reset(); + } - return duration; + return duration; } private static long measureInputStatus() throws Exception { - long duration = 0; + long duration = 0; - InputStream is = new ByteArrayInputStream( - "+OK\r\n" - .getBytes()); + InputStream is = new ByteArrayInputStream( + "+OK\r\n" + .getBytes()); - RedisInputStream in = new RedisInputStream(is); - for (int n = 0; n <= TOTAL_OPERATIONS; n++) { - long start = System.nanoTime(); - Protocol.read(in); - duration += (System.nanoTime() - start); - in.reset(); - } + RedisInputStream in = new RedisInputStream(is); + for (int n = 0; n <= TOTAL_OPERATIONS; n++) { + long start = System.nanoTime(); + Protocol.read(in); + duration += (System.nanoTime() - start); + in.reset(); + } - return duration; + return duration; } private static long measureCommand() throws Exception { - long duration = 0; + long duration = 0; - byte[] KEY = "123456789".getBytes(); - byte[] VAL = "FooBar".getBytes(); + byte[] KEY = "123456789".getBytes(); + byte[] VAL = "FooBar".getBytes(); - for (int n = 0; n <= TOTAL_OPERATIONS; n++) { - RedisOutputStream out = new RedisOutputStream(new ByteArrayOutputStream(8192)); - long start = System.nanoTime(); - Protocol.sendCommand(out, Protocol.Command.SET, KEY, VAL); - duration += (System.nanoTime() - start); - } + for (int n = 0; n <= TOTAL_OPERATIONS; n++) { + RedisOutputStream out = new RedisOutputStream(new ByteArrayOutputStream(8192)); + long start = System.nanoTime(); + Protocol.sendCommand(out, Protocol.Command.SET, KEY, VAL); + duration += (System.nanoTime() - start); + } - return duration; + return duration; } } diff --git a/src/test/java/redis/clients/jedis/tests/benchmark/SafeEncoderBenchmark.java b/src/test/java/redis/clients/jedis/tests/benchmark/SafeEncoderBenchmark.java index 3444687..9f84c5d 100644 --- a/src/test/java/redis/clients/jedis/tests/benchmark/SafeEncoderBenchmark.java +++ b/src/test/java/redis/clients/jedis/tests/benchmark/SafeEncoderBenchmark.java @@ -10,29 +10,29 @@ public class SafeEncoderBenchmark { private static final int TOTAL_OPERATIONS = 10000000; public static void main(String[] args) throws UnknownHostException, - IOException { - long begin = Calendar.getInstance().getTimeInMillis(); + IOException { + long begin = Calendar.getInstance().getTimeInMillis(); - for (int n = 0; n <= TOTAL_OPERATIONS; n++) { - SafeEncoder.encode("foo bar!"); - } + for (int n = 0; n <= TOTAL_OPERATIONS; n++) { + SafeEncoder.encode("foo bar!"); + } - long elapsed = Calendar.getInstance().getTimeInMillis() - begin; + long elapsed = Calendar.getInstance().getTimeInMillis() - begin; - System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed) - + " ops to build byte[]"); + System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed) + + " ops to build byte[]"); - begin = Calendar.getInstance().getTimeInMillis(); + begin = Calendar.getInstance().getTimeInMillis(); - byte[] bytes = "foo bar!".getBytes(); - for (int n = 0; n <= TOTAL_OPERATIONS; n++) { - SafeEncoder.encode(bytes); - } + byte[] bytes = "foo bar!".getBytes(); + for (int n = 0; n <= TOTAL_OPERATIONS; n++) { + SafeEncoder.encode(bytes); + } - elapsed = Calendar.getInstance().getTimeInMillis() - begin; + elapsed = Calendar.getInstance().getTimeInMillis() - begin; - System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed) - + " ops to build Strings"); + System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed) + + " ops to build Strings"); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/benchmark/ShardedBenchmark.java b/src/test/java/redis/clients/jedis/tests/benchmark/ShardedBenchmark.java index ec5fed8..9d20d1e 100644 --- a/src/test/java/redis/clients/jedis/tests/benchmark/ShardedBenchmark.java +++ b/src/test/java/redis/clients/jedis/tests/benchmark/ShardedBenchmark.java @@ -10,30 +10,30 @@ public class ShardedBenchmark { private static final int TOTAL_OPERATIONS = 10000000; public static void main(String[] args) throws UnknownHostException, - IOException { + IOException { - long begin = Calendar.getInstance().getTimeInMillis(); + long begin = Calendar.getInstance().getTimeInMillis(); - for (int n = 0; n <= TOTAL_OPERATIONS; n++) { - String key = "foo" + n; - Hashing.MD5.hash(key); - } + for (int n = 0; n <= TOTAL_OPERATIONS; n++) { + String key = "foo" + n; + Hashing.MD5.hash(key); + } - long elapsed = Calendar.getInstance().getTimeInMillis() - begin; + long elapsed = Calendar.getInstance().getTimeInMillis() - begin; - System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed) + " MD5 ops"); + System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed) + " MD5 ops"); - begin = Calendar.getInstance().getTimeInMillis(); + begin = Calendar.getInstance().getTimeInMillis(); - for (int n = 0; n <= TOTAL_OPERATIONS; n++) { - String key = "foo" + n; - Hashing.MURMUR_HASH.hash(key); - } + for (int n = 0; n <= TOTAL_OPERATIONS; n++) { + String key = "foo" + n; + Hashing.MURMUR_HASH.hash(key); + } - elapsed = Calendar.getInstance().getTimeInMillis() - begin; + elapsed = Calendar.getInstance().getTimeInMillis() - begin; - System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed) - + " Murmur ops"); + System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed) + + " Murmur ops"); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java index d206508..6c594ec 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java @@ -30,560 +30,560 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase { @Test public void ping() { - String status = jedis.ping(); - assertEquals("PONG", status); + String status = jedis.ping(); + assertEquals("PONG", status); } @Test public void exists() { - String status = jedis.set("foo", "bar"); - assertEquals("OK", status); + String status = jedis.set("foo", "bar"); + assertEquals("OK", status); - status = jedis.set(bfoo, bbar); - assertEquals("OK", status); + status = jedis.set(bfoo, bbar); + assertEquals("OK", status); - boolean reply = jedis.exists("foo"); - assertTrue(reply); + boolean reply = jedis.exists("foo"); + assertTrue(reply); - reply = jedis.exists(bfoo); - assertTrue(reply); + reply = jedis.exists(bfoo); + assertTrue(reply); - long lreply = jedis.del("foo"); - assertEquals(1, lreply); + long lreply = jedis.del("foo"); + assertEquals(1, lreply); - lreply = jedis.del(bfoo); - assertEquals(1, lreply); + lreply = jedis.del(bfoo); + assertEquals(1, lreply); - reply = jedis.exists("foo"); - assertFalse(reply); + reply = jedis.exists("foo"); + assertFalse(reply); - reply = jedis.exists(bfoo); - assertFalse(reply); + reply = jedis.exists(bfoo); + assertFalse(reply); } @Test public void del() { - jedis.set("foo1", "bar1"); - jedis.set("foo2", "bar2"); - jedis.set("foo3", "bar3"); + jedis.set("foo1", "bar1"); + jedis.set("foo2", "bar2"); + jedis.set("foo3", "bar3"); - long reply = jedis.del("foo1", "foo2", "foo3"); - assertEquals(3, reply); + long reply = jedis.del("foo1", "foo2", "foo3"); + assertEquals(3, reply); - Boolean breply = jedis.exists("foo1"); - assertFalse(breply); - breply = jedis.exists("foo2"); - assertFalse(breply); - breply = jedis.exists("foo3"); - assertFalse(breply); + Boolean breply = jedis.exists("foo1"); + assertFalse(breply); + breply = jedis.exists("foo2"); + assertFalse(breply); + breply = jedis.exists("foo3"); + assertFalse(breply); - jedis.set("foo1", "bar1"); + jedis.set("foo1", "bar1"); - reply = jedis.del("foo1", "foo2"); - assertEquals(1, reply); + reply = jedis.del("foo1", "foo2"); + assertEquals(1, reply); - reply = jedis.del("foo1", "foo2"); - assertEquals(0, reply); + reply = jedis.del("foo1", "foo2"); + assertEquals(0, reply); - // Binary ... - jedis.set(bfoo1, bbar1); - jedis.set(bfoo2, bbar2); - jedis.set(bfoo3, bbar3); + // Binary ... + jedis.set(bfoo1, bbar1); + jedis.set(bfoo2, bbar2); + jedis.set(bfoo3, bbar3); - reply = jedis.del(bfoo1, bfoo2, bfoo3); - assertEquals(3, reply); + reply = jedis.del(bfoo1, bfoo2, bfoo3); + assertEquals(3, reply); - breply = jedis.exists(bfoo1); - assertFalse(breply); - breply = jedis.exists(bfoo2); - assertFalse(breply); - breply = jedis.exists(bfoo3); - assertFalse(breply); + breply = jedis.exists(bfoo1); + assertFalse(breply); + breply = jedis.exists(bfoo2); + assertFalse(breply); + breply = jedis.exists(bfoo3); + assertFalse(breply); - jedis.set(bfoo1, bbar1); + jedis.set(bfoo1, bbar1); - reply = jedis.del(bfoo1, bfoo2); - assertEquals(1, reply); + reply = jedis.del(bfoo1, bfoo2); + assertEquals(1, reply); - reply = jedis.del(bfoo1, bfoo2); - assertEquals(0, reply); + reply = jedis.del(bfoo1, bfoo2); + assertEquals(0, reply); } @Test public void type() { - jedis.set("foo", "bar"); - String status = jedis.type("foo"); - assertEquals("string", status); + jedis.set("foo", "bar"); + String status = jedis.type("foo"); + assertEquals("string", status); - // Binary - jedis.set(bfoo, bbar); - status = jedis.type(bfoo); - assertEquals("string", status); + // Binary + jedis.set(bfoo, bbar); + status = jedis.type(bfoo); + assertEquals("string", status); } @Test public void keys() { - jedis.set("foo", "bar"); - jedis.set("foobar", "bar"); + jedis.set("foo", "bar"); + jedis.set("foobar", "bar"); - Set keys = jedis.keys("foo*"); - Set expected = new HashSet(); - expected.add("foo"); - expected.add("foobar"); - assertEquals(expected, keys); + Set keys = jedis.keys("foo*"); + Set expected = new HashSet(); + expected.add("foo"); + expected.add("foobar"); + assertEquals(expected, keys); - expected = new HashSet(); - keys = jedis.keys("bar*"); + expected = new HashSet(); + keys = jedis.keys("bar*"); - assertEquals(expected, keys); + assertEquals(expected, keys); - // Binary - jedis.set(bfoo, bbar); - jedis.set(bfoobar, bbar); + // Binary + jedis.set(bfoo, bbar); + jedis.set(bfoobar, bbar); - Set bkeys = jedis.keys(bfoostar); - assertEquals(2, bkeys.size()); - assertTrue(setContains(bkeys, bfoo)); - assertTrue(setContains(bkeys, bfoobar)); + Set bkeys = jedis.keys(bfoostar); + assertEquals(2, bkeys.size()); + assertTrue(setContains(bkeys, bfoo)); + assertTrue(setContains(bkeys, bfoobar)); - bkeys = jedis.keys(bbarstar); + bkeys = jedis.keys(bbarstar); - assertEquals(0, bkeys.size()); + assertEquals(0, bkeys.size()); } @Test public void randomKey() { - assertEquals(null, jedis.randomKey()); + assertEquals(null, jedis.randomKey()); - jedis.set("foo", "bar"); + jedis.set("foo", "bar"); - assertEquals("foo", jedis.randomKey()); + assertEquals("foo", jedis.randomKey()); - jedis.set("bar", "foo"); + jedis.set("bar", "foo"); - String randomkey = jedis.randomKey(); - assertTrue(randomkey.equals("foo") || randomkey.equals("bar")); + String randomkey = jedis.randomKey(); + assertTrue(randomkey.equals("foo") || randomkey.equals("bar")); - // Binary - jedis.del("foo"); - jedis.del("bar"); - assertEquals(null, jedis.randomKey()); + // Binary + jedis.del("foo"); + jedis.del("bar"); + assertEquals(null, jedis.randomKey()); - jedis.set(bfoo, bbar); + jedis.set(bfoo, bbar); - assertArrayEquals(bfoo, jedis.randomBinaryKey()); + assertArrayEquals(bfoo, jedis.randomBinaryKey()); - jedis.set(bbar, bfoo); + jedis.set(bbar, bfoo); - byte[] randomBkey = jedis.randomBinaryKey(); - assertTrue(Arrays.equals(randomBkey, bfoo) - || Arrays.equals(randomBkey, bbar)); + byte[] randomBkey = jedis.randomBinaryKey(); + assertTrue(Arrays.equals(randomBkey, bfoo) + || Arrays.equals(randomBkey, bbar)); } @Test public void rename() { - jedis.set("foo", "bar"); - String status = jedis.rename("foo", "bar"); - assertEquals("OK", status); + jedis.set("foo", "bar"); + String status = jedis.rename("foo", "bar"); + assertEquals("OK", status); - String value = jedis.get("foo"); - assertEquals(null, value); + String value = jedis.get("foo"); + assertEquals(null, value); - value = jedis.get("bar"); - assertEquals("bar", value); + value = jedis.get("bar"); + assertEquals("bar", value); - // Binary - jedis.set(bfoo, bbar); - String bstatus = jedis.rename(bfoo, bbar); - assertEquals("OK", bstatus); + // Binary + jedis.set(bfoo, bbar); + String bstatus = jedis.rename(bfoo, bbar); + assertEquals("OK", bstatus); - byte[] bvalue = jedis.get(bfoo); - assertEquals(null, bvalue); + byte[] bvalue = jedis.get(bfoo); + assertEquals(null, bvalue); - bvalue = jedis.get(bbar); - assertArrayEquals(bbar, bvalue); + bvalue = jedis.get(bbar); + assertArrayEquals(bbar, bvalue); } @Test public void renameOldAndNewAreTheSame() { - try { - jedis.set("foo", "bar"); - jedis.rename("foo", "foo"); - fail("JedisDataException expected"); - } catch (final JedisDataException e) { - } + try { + jedis.set("foo", "bar"); + jedis.rename("foo", "foo"); + fail("JedisDataException expected"); + } catch (final JedisDataException e) { + } - // Binary - try { - jedis.set(bfoo, bbar); - jedis.rename(bfoo, bfoo); - fail("JedisDataException expected"); - } catch (final JedisDataException e) { - } + // Binary + try { + jedis.set(bfoo, bbar); + jedis.rename(bfoo, bfoo); + fail("JedisDataException expected"); + } catch (final JedisDataException e) { + } } @Test public void renamenx() { - jedis.set("foo", "bar"); - long status = jedis.renamenx("foo", "bar"); - assertEquals(1, status); + jedis.set("foo", "bar"); + long status = jedis.renamenx("foo", "bar"); + assertEquals(1, status); - jedis.set("foo", "bar"); - status = jedis.renamenx("foo", "bar"); - assertEquals(0, status); + jedis.set("foo", "bar"); + status = jedis.renamenx("foo", "bar"); + assertEquals(0, status); - // Binary - jedis.set(bfoo, bbar); - long bstatus = jedis.renamenx(bfoo, bbar); - assertEquals(1, bstatus); + // Binary + jedis.set(bfoo, bbar); + long bstatus = jedis.renamenx(bfoo, bbar); + assertEquals(1, bstatus); - jedis.set(bfoo, bbar); - bstatus = jedis.renamenx(bfoo, bbar); - assertEquals(0, bstatus); + jedis.set(bfoo, bbar); + bstatus = jedis.renamenx(bfoo, bbar); + assertEquals(0, bstatus); } @Test public void dbSize() { - long size = jedis.dbSize(); - assertEquals(0, size); + long size = jedis.dbSize(); + assertEquals(0, size); - jedis.set("foo", "bar"); - size = jedis.dbSize(); - assertEquals(1, size); + jedis.set("foo", "bar"); + size = jedis.dbSize(); + assertEquals(1, size); - // Binary - jedis.set(bfoo, bbar); - size = jedis.dbSize(); - assertEquals(2, size); + // Binary + jedis.set(bfoo, bbar); + size = jedis.dbSize(); + assertEquals(2, size); } @Test public void expire() { - long status = jedis.expire("foo", 20); - assertEquals(0, status); + long status = jedis.expire("foo", 20); + assertEquals(0, status); - jedis.set("foo", "bar"); - status = jedis.expire("foo", 20); - assertEquals(1, status); + jedis.set("foo", "bar"); + status = jedis.expire("foo", 20); + assertEquals(1, status); - // Binary - long bstatus = jedis.expire(bfoo, 20); - assertEquals(0, bstatus); + // Binary + long bstatus = jedis.expire(bfoo, 20); + assertEquals(0, bstatus); - jedis.set(bfoo, bbar); - bstatus = jedis.expire(bfoo, 20); - assertEquals(1, bstatus); + jedis.set(bfoo, bbar); + bstatus = jedis.expire(bfoo, 20); + assertEquals(1, bstatus); } @Test public void expireAt() { - long unixTime = (System.currentTimeMillis() / 1000L) + 20; + long unixTime = (System.currentTimeMillis() / 1000L) + 20; - long status = jedis.expireAt("foo", unixTime); - assertEquals(0, status); + long status = jedis.expireAt("foo", unixTime); + assertEquals(0, status); - jedis.set("foo", "bar"); - unixTime = (System.currentTimeMillis() / 1000L) + 20; - status = jedis.expireAt("foo", unixTime); - assertEquals(1, status); + jedis.set("foo", "bar"); + unixTime = (System.currentTimeMillis() / 1000L) + 20; + status = jedis.expireAt("foo", unixTime); + assertEquals(1, status); - // Binary - long bstatus = jedis.expireAt(bfoo, unixTime); - assertEquals(0, bstatus); + // Binary + long bstatus = jedis.expireAt(bfoo, unixTime); + assertEquals(0, bstatus); - jedis.set(bfoo, bbar); - unixTime = (System.currentTimeMillis() / 1000L) + 20; - bstatus = jedis.expireAt(bfoo, unixTime); - assertEquals(1, bstatus); + jedis.set(bfoo, bbar); + unixTime = (System.currentTimeMillis() / 1000L) + 20; + bstatus = jedis.expireAt(bfoo, unixTime); + assertEquals(1, bstatus); } @Test public void ttl() { - long ttl = jedis.ttl("foo"); - assertEquals(-2, ttl); + long ttl = jedis.ttl("foo"); + assertEquals(-2, ttl); - jedis.set("foo", "bar"); - ttl = jedis.ttl("foo"); - assertEquals(-1, ttl); + jedis.set("foo", "bar"); + ttl = jedis.ttl("foo"); + assertEquals(-1, ttl); - jedis.expire("foo", 20); - ttl = jedis.ttl("foo"); - assertTrue(ttl >= 0 && ttl <= 20); + jedis.expire("foo", 20); + ttl = jedis.ttl("foo"); + assertTrue(ttl >= 0 && ttl <= 20); - // Binary - long bttl = jedis.ttl(bfoo); - assertEquals(-2, bttl); + // Binary + long bttl = jedis.ttl(bfoo); + assertEquals(-2, bttl); - jedis.set(bfoo, bbar); - bttl = jedis.ttl(bfoo); - assertEquals(-1, bttl); + jedis.set(bfoo, bbar); + bttl = jedis.ttl(bfoo); + assertEquals(-1, bttl); - jedis.expire(bfoo, 20); - bttl = jedis.ttl(bfoo); - assertTrue(bttl >= 0 && bttl <= 20); + jedis.expire(bfoo, 20); + bttl = jedis.ttl(bfoo); + assertTrue(bttl >= 0 && bttl <= 20); } @Test public void select() { - jedis.set("foo", "bar"); - String status = jedis.select(1); - assertEquals("OK", status); - assertEquals(null, jedis.get("foo")); - status = jedis.select(0); - assertEquals("OK", status); - assertEquals("bar", jedis.get("foo")); - // Binary - jedis.set(bfoo, bbar); - String bstatus = jedis.select(1); - assertEquals("OK", bstatus); - assertEquals(null, jedis.get(bfoo)); - bstatus = jedis.select(0); - assertEquals("OK", bstatus); - assertArrayEquals(bbar, jedis.get(bfoo)); + jedis.set("foo", "bar"); + String status = jedis.select(1); + assertEquals("OK", status); + assertEquals(null, jedis.get("foo")); + status = jedis.select(0); + assertEquals("OK", status); + assertEquals("bar", jedis.get("foo")); + // Binary + jedis.set(bfoo, bbar); + String bstatus = jedis.select(1); + assertEquals("OK", bstatus); + assertEquals(null, jedis.get(bfoo)); + bstatus = jedis.select(0); + assertEquals("OK", bstatus); + assertArrayEquals(bbar, jedis.get(bfoo)); } @Test public void getDB() { - assertEquals(0, jedis.getDB().longValue()); - jedis.select(1); - assertEquals(1, jedis.getDB().longValue()); + assertEquals(0, jedis.getDB().longValue()); + jedis.select(1); + assertEquals(1, jedis.getDB().longValue()); } @Test public void move() { - long status = jedis.move("foo", 1); - assertEquals(0, status); + long status = jedis.move("foo", 1); + assertEquals(0, status); - jedis.set("foo", "bar"); - status = jedis.move("foo", 1); - assertEquals(1, status); - assertEquals(null, jedis.get("foo")); + jedis.set("foo", "bar"); + status = jedis.move("foo", 1); + assertEquals(1, status); + assertEquals(null, jedis.get("foo")); - jedis.select(1); - assertEquals("bar", jedis.get("foo")); + jedis.select(1); + assertEquals("bar", jedis.get("foo")); - // Binary - jedis.select(0); - long bstatus = jedis.move(bfoo, 1); - assertEquals(0, bstatus); + // Binary + jedis.select(0); + long bstatus = jedis.move(bfoo, 1); + assertEquals(0, bstatus); - jedis.set(bfoo, bbar); - bstatus = jedis.move(bfoo, 1); - assertEquals(1, bstatus); - assertEquals(null, jedis.get(bfoo)); + jedis.set(bfoo, bbar); + bstatus = jedis.move(bfoo, 1); + assertEquals(1, bstatus); + assertEquals(null, jedis.get(bfoo)); - jedis.select(1); - assertArrayEquals(bbar, jedis.get(bfoo)); + jedis.select(1); + assertArrayEquals(bbar, jedis.get(bfoo)); } @Test public void flushDB() { - jedis.set("foo", "bar"); - assertEquals(1, jedis.dbSize().intValue()); - jedis.set("bar", "foo"); - jedis.move("bar", 1); - String status = jedis.flushDB(); - assertEquals("OK", status); - assertEquals(0, jedis.dbSize().intValue()); - jedis.select(1); - assertEquals(1, jedis.dbSize().intValue()); - jedis.del("bar"); + jedis.set("foo", "bar"); + assertEquals(1, jedis.dbSize().intValue()); + jedis.set("bar", "foo"); + jedis.move("bar", 1); + String status = jedis.flushDB(); + assertEquals("OK", status); + assertEquals(0, jedis.dbSize().intValue()); + jedis.select(1); + assertEquals(1, jedis.dbSize().intValue()); + jedis.del("bar"); - // Binary - jedis.select(0); - jedis.set(bfoo, bbar); - assertEquals(1, jedis.dbSize().intValue()); - jedis.set(bbar, bfoo); - jedis.move(bbar, 1); - String bstatus = jedis.flushDB(); - assertEquals("OK", bstatus); - assertEquals(0, jedis.dbSize().intValue()); - jedis.select(1); - assertEquals(1, jedis.dbSize().intValue()); + // Binary + jedis.select(0); + jedis.set(bfoo, bbar); + assertEquals(1, jedis.dbSize().intValue()); + jedis.set(bbar, bfoo); + jedis.move(bbar, 1); + String bstatus = jedis.flushDB(); + assertEquals("OK", bstatus); + assertEquals(0, jedis.dbSize().intValue()); + jedis.select(1); + assertEquals(1, jedis.dbSize().intValue()); } @Test public void flushAll() { - jedis.set("foo", "bar"); - assertEquals(1, jedis.dbSize().intValue()); - jedis.set("bar", "foo"); - jedis.move("bar", 1); - String status = jedis.flushAll(); - assertEquals("OK", status); - assertEquals(0, jedis.dbSize().intValue()); - jedis.select(1); - assertEquals(0, jedis.dbSize().intValue()); + jedis.set("foo", "bar"); + assertEquals(1, jedis.dbSize().intValue()); + jedis.set("bar", "foo"); + jedis.move("bar", 1); + String status = jedis.flushAll(); + assertEquals("OK", status); + assertEquals(0, jedis.dbSize().intValue()); + jedis.select(1); + assertEquals(0, jedis.dbSize().intValue()); - // Binary - jedis.select(0); - jedis.set(bfoo, bbar); - assertEquals(1, jedis.dbSize().intValue()); - jedis.set(bbar, bfoo); - jedis.move(bbar, 1); - String bstatus = jedis.flushAll(); - assertEquals("OK", bstatus); - assertEquals(0, jedis.dbSize().intValue()); - jedis.select(1); - assertEquals(0, jedis.dbSize().intValue()); + // Binary + jedis.select(0); + jedis.set(bfoo, bbar); + assertEquals(1, jedis.dbSize().intValue()); + jedis.set(bbar, bfoo); + jedis.move(bbar, 1); + String bstatus = jedis.flushAll(); + assertEquals("OK", bstatus); + assertEquals(0, jedis.dbSize().intValue()); + jedis.select(1); + assertEquals(0, jedis.dbSize().intValue()); } @Test public void persist() { - jedis.setex("foo", 60 * 60, "bar"); - assertTrue(jedis.ttl("foo") > 0); - long status = jedis.persist("foo"); - assertEquals(1, status); - assertEquals(-1, jedis.ttl("foo").intValue()); + jedis.setex("foo", 60 * 60, "bar"); + assertTrue(jedis.ttl("foo") > 0); + long status = jedis.persist("foo"); + assertEquals(1, status); + assertEquals(-1, jedis.ttl("foo").intValue()); - // Binary - jedis.setex(bfoo, 60 * 60, bbar); - assertTrue(jedis.ttl(bfoo) > 0); - long bstatus = jedis.persist(bfoo); - assertEquals(1, bstatus); - assertEquals(-1, jedis.ttl(bfoo).intValue()); + // Binary + jedis.setex(bfoo, 60 * 60, bbar); + assertTrue(jedis.ttl(bfoo) > 0); + long bstatus = jedis.persist(bfoo); + assertEquals(1, bstatus); + assertEquals(-1, jedis.ttl(bfoo).intValue()); } @Test public void echo() { - String result = jedis.echo("hello world"); - assertEquals("hello world", result); + String result = jedis.echo("hello world"); + assertEquals("hello world", result); - // Binary - byte[] bresult = jedis.echo(SafeEncoder.encode("hello world")); - assertArrayEquals(SafeEncoder.encode("hello world"), bresult); + // Binary + byte[] bresult = jedis.echo(SafeEncoder.encode("hello world")); + assertArrayEquals(SafeEncoder.encode("hello world"), bresult); } @Test public void dumpAndRestore() { - jedis.set("foo1", "bar1"); - byte[] sv = jedis.dump("foo1"); - jedis.restore("foo2", 0, sv); - assertTrue(jedis.exists("foo2")); + jedis.set("foo1", "bar1"); + byte[] sv = jedis.dump("foo1"); + jedis.restore("foo2", 0, sv); + assertTrue(jedis.exists("foo2")); } @Test public void pexpire() { - long status = jedis.pexpire("foo", 10000); - assertEquals(0, status); + long status = jedis.pexpire("foo", 10000); + assertEquals(0, status); - jedis.set("foo1", "bar1"); - status = jedis.pexpire("foo1", 10000); - assertEquals(1, status); + jedis.set("foo1", "bar1"); + status = jedis.pexpire("foo1", 10000); + assertEquals(1, status); - jedis.set("foo2", "bar2"); - status = jedis.pexpire("foo2", 200000000000L); - assertEquals(1, status); + jedis.set("foo2", "bar2"); + status = jedis.pexpire("foo2", 200000000000L); + assertEquals(1, status); - long pttl = jedis.pttl("foo2"); - assertTrue(pttl > 100000000000L); + long pttl = jedis.pttl("foo2"); + assertTrue(pttl > 100000000000L); } @Test public void pexpireAt() { - long unixTime = (System.currentTimeMillis()) + 10000; + long unixTime = (System.currentTimeMillis()) + 10000; - long status = jedis.pexpireAt("foo", unixTime); - assertEquals(0, status); + long status = jedis.pexpireAt("foo", unixTime); + assertEquals(0, status); - jedis.set("foo", "bar"); - unixTime = (System.currentTimeMillis()) + 10000; - status = jedis.pexpireAt("foo", unixTime); - assertEquals(1, status); + jedis.set("foo", "bar"); + unixTime = (System.currentTimeMillis()) + 10000; + status = jedis.pexpireAt("foo", unixTime); + assertEquals(1, status); } @Test public void pttl() { - long pttl = jedis.pttl("foo"); - assertEquals(-2, pttl); + long pttl = jedis.pttl("foo"); + assertEquals(-2, pttl); - jedis.set("foo", "bar"); - pttl = jedis.pttl("foo"); - assertEquals(-1, pttl); + jedis.set("foo", "bar"); + pttl = jedis.pttl("foo"); + assertEquals(-1, pttl); - jedis.pexpire("foo", 20000); - pttl = jedis.pttl("foo"); - assertTrue(pttl >= 0 && pttl <= 20000); + jedis.pexpire("foo", 20000); + pttl = jedis.pttl("foo"); + assertTrue(pttl >= 0 && pttl <= 20000); } @Test public void scan() { - jedis.set("b", "b"); - jedis.set("a", "a"); + jedis.set("b", "b"); + jedis.set("a", "a"); - ScanResult result = jedis.scan(SCAN_POINTER_START); + ScanResult result = jedis.scan(SCAN_POINTER_START); - assertEquals(SCAN_POINTER_START, result.getCursor()); - assertFalse(result.getResult().isEmpty()); + assertEquals(SCAN_POINTER_START, result.getCursor()); + assertFalse(result.getResult().isEmpty()); - // binary - ScanResult bResult = jedis.scan(SCAN_POINTER_START_BINARY); + // binary + ScanResult bResult = jedis.scan(SCAN_POINTER_START_BINARY); - assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes()); - assertFalse(bResult.getResult().isEmpty()); + assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes()); + assertFalse(bResult.getResult().isEmpty()); } @Test public void scanMatch() { - ScanParams params = new ScanParams(); - params.match("a*"); + ScanParams params = new ScanParams(); + params.match("a*"); - jedis.set("b", "b"); - jedis.set("a", "a"); - jedis.set("aa", "aa"); - ScanResult result = jedis.scan(SCAN_POINTER_START, params); + jedis.set("b", "b"); + jedis.set("a", "a"); + jedis.set("aa", "aa"); + ScanResult result = jedis.scan(SCAN_POINTER_START, params); - assertEquals(SCAN_POINTER_START, result.getCursor()); - assertFalse(result.getResult().isEmpty()); + assertEquals(SCAN_POINTER_START, result.getCursor()); + assertFalse(result.getResult().isEmpty()); - // binary - params = new ScanParams(); - params.match(bfoostar); + // binary + params = new ScanParams(); + params.match(bfoostar); - jedis.set(bfoo1, bbar); - jedis.set(bfoo2, bbar); - jedis.set(bfoo3, bbar); + jedis.set(bfoo1, bbar); + jedis.set(bfoo2, bbar); + jedis.set(bfoo3, bbar); - ScanResult bResult = jedis.scan(SCAN_POINTER_START_BINARY, - params); + ScanResult bResult = jedis.scan(SCAN_POINTER_START_BINARY, + params); - assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes()); - assertFalse(bResult.getResult().isEmpty()); + assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes()); + assertFalse(bResult.getResult().isEmpty()); } @Test public void scanCount() { - ScanParams params = new ScanParams(); - params.count(2); + ScanParams params = new ScanParams(); + params.count(2); - for (int i = 0; i < 10; i++) { - jedis.set("a" + i, "a" + i); - } + for (int i = 0; i < 10; i++) { + jedis.set("a" + i, "a" + i); + } - ScanResult result = jedis.scan(SCAN_POINTER_START, params); + ScanResult result = jedis.scan(SCAN_POINTER_START, params); - assertFalse(result.getResult().isEmpty()); + assertFalse(result.getResult().isEmpty()); - // binary - params = new ScanParams(); - params.count(2); + // binary + params = new ScanParams(); + params.count(2); - jedis.set(bfoo1, bbar); - jedis.set(bfoo2, bbar); - jedis.set(bfoo3, bbar); + jedis.set(bfoo1, bbar); + jedis.set(bfoo2, bbar); + jedis.set(bfoo3, bbar); - ScanResult bResult = jedis.scan(SCAN_POINTER_START_BINARY, - params); + ScanResult bResult = jedis.scan(SCAN_POINTER_START_BINARY, + params); - assertFalse(bResult.getResult().isEmpty()); + assertFalse(bResult.getResult().isEmpty()); } } diff --git a/src/test/java/redis/clients/jedis/tests/commands/BinaryValuesCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/BinaryValuesCommandsTest.java index 2a09268..f0f437a 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/BinaryValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/BinaryValuesCommandsTest.java @@ -23,260 +23,260 @@ public class BinaryValuesCommandsTest extends JedisCommandTestBase { @Before public void startUp() { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); - for (int n = 0; n < 1000; n++) { - sb.append("A"); - } + for (int n = 0; n < 1000; n++) { + sb.append("A"); + } - binaryValue = sb.toString().getBytes(); + binaryValue = sb.toString().getBytes(); } @Test public void setAndGet() { - String status = jedis.set(bfoo, binaryValue); - assertTrue(Keyword.OK.name().equalsIgnoreCase(status)); + String status = jedis.set(bfoo, binaryValue); + assertTrue(Keyword.OK.name().equalsIgnoreCase(status)); - byte[] value = jedis.get(bfoo); - assertTrue(Arrays.equals(binaryValue, value)); + byte[] value = jedis.get(bfoo); + assertTrue(Arrays.equals(binaryValue, value)); - assertNull(jedis.get(bbar)); + assertNull(jedis.get(bbar)); } @Test public void setNxExAndGet() { - String status = jedis.set(bfoo, binaryValue, bnx, bex, expireSeconds); - assertTrue(Keyword.OK.name().equalsIgnoreCase(status)); - byte[] value = jedis.get(bfoo); - assertTrue(Arrays.equals(binaryValue, value)); + String status = jedis.set(bfoo, binaryValue, bnx, bex, expireSeconds); + assertTrue(Keyword.OK.name().equalsIgnoreCase(status)); + byte[] value = jedis.get(bfoo); + assertTrue(Arrays.equals(binaryValue, value)); - assertNull(jedis.get(bbar)); + assertNull(jedis.get(bbar)); } @Test public void setIfNotExistAndGet() { - String status = jedis.set(bfoo, binaryValue); - assertTrue(Keyword.OK.name().equalsIgnoreCase(status)); - // nx should fail if value exists - String statusFail = jedis.set(bfoo, binaryValue, bnx, bex, - expireSeconds); - assertNull(statusFail); + String status = jedis.set(bfoo, binaryValue); + assertTrue(Keyword.OK.name().equalsIgnoreCase(status)); + // nx should fail if value exists + String statusFail = jedis.set(bfoo, binaryValue, bnx, bex, + expireSeconds); + assertNull(statusFail); - byte[] value = jedis.get(bfoo); - assertTrue(Arrays.equals(binaryValue, value)); + byte[] value = jedis.get(bfoo); + assertTrue(Arrays.equals(binaryValue, value)); - assertNull(jedis.get(bbar)); + assertNull(jedis.get(bbar)); } @Test public void setIfExistAndGet() { - String status = jedis.set(bfoo, binaryValue); - assertTrue(Keyword.OK.name().equalsIgnoreCase(status)); - // nx should fail if value exists - String statusSuccess = jedis.set(bfoo, binaryValue, bxx, bex, - expireSeconds); - assertTrue(Keyword.OK.name().equalsIgnoreCase(statusSuccess)); + String status = jedis.set(bfoo, binaryValue); + assertTrue(Keyword.OK.name().equalsIgnoreCase(status)); + // nx should fail if value exists + String statusSuccess = jedis.set(bfoo, binaryValue, bxx, bex, + expireSeconds); + assertTrue(Keyword.OK.name().equalsIgnoreCase(statusSuccess)); - byte[] value = jedis.get(bfoo); - assertTrue(Arrays.equals(binaryValue, value)); + byte[] value = jedis.get(bfoo); + assertTrue(Arrays.equals(binaryValue, value)); - assertNull(jedis.get(bbar)); + assertNull(jedis.get(bbar)); } @Test public void setFailIfNotExistAndGet() { - // xx should fail if value does NOT exists - String statusFail = jedis.set(bfoo, binaryValue, bxx, bex, - expireSeconds); - assertNull(statusFail); + // xx should fail if value does NOT exists + String statusFail = jedis.set(bfoo, binaryValue, bxx, bex, + expireSeconds); + assertNull(statusFail); } @Test public void setAndExpireMillis() { - String status = jedis.set(bfoo, binaryValue, bnx, bpx, expireMillis); - assertTrue(Keyword.OK.name().equalsIgnoreCase(status)); - long ttl = jedis.ttl(bfoo); - assertTrue(ttl > 0 && ttl <= expireSeconds); + String status = jedis.set(bfoo, binaryValue, bnx, bpx, expireMillis); + assertTrue(Keyword.OK.name().equalsIgnoreCase(status)); + long ttl = jedis.ttl(bfoo); + assertTrue(ttl > 0 && ttl <= expireSeconds); } @Test public void setAndExpire() { - String status = jedis.set(bfoo, binaryValue, bnx, bex, expireSeconds); - assertTrue(Keyword.OK.name().equalsIgnoreCase(status)); - long ttl = jedis.ttl(bfoo); - assertTrue(ttl > 0 && ttl <= expireSeconds); + String status = jedis.set(bfoo, binaryValue, bnx, bex, expireSeconds); + assertTrue(Keyword.OK.name().equalsIgnoreCase(status)); + long ttl = jedis.ttl(bfoo); + assertTrue(ttl > 0 && ttl <= expireSeconds); } @Test public void getSet() { - byte[] value = jedis.getSet(bfoo, binaryValue); - assertNull(value); - value = jedis.get(bfoo); - assertTrue(Arrays.equals(binaryValue, value)); + byte[] value = jedis.getSet(bfoo, binaryValue); + assertNull(value); + value = jedis.get(bfoo); + assertTrue(Arrays.equals(binaryValue, value)); } @Test public void mget() { - List values = jedis.mget(bfoo, bbar); - List expected = new ArrayList(); - expected.add(null); - expected.add(null); + List values = jedis.mget(bfoo, bbar); + List expected = new ArrayList(); + expected.add(null); + expected.add(null); - assertEquals(expected, values); + assertEquals(expected, values); - jedis.set(bfoo, binaryValue); + jedis.set(bfoo, binaryValue); - expected = new ArrayList(); - expected.add(binaryValue); - expected.add(null); - values = jedis.mget(bfoo, bbar); + expected = new ArrayList(); + expected.add(binaryValue); + expected.add(null); + values = jedis.mget(bfoo, bbar); - assertEquals(expected, values); + assertEquals(expected, values); - jedis.set(bbar, bfoo); + jedis.set(bbar, bfoo); - expected = new ArrayList(); - expected.add(binaryValue); - expected.add(bfoo); - values = jedis.mget(bfoo, bbar); + expected = new ArrayList(); + expected.add(binaryValue); + expected.add(bfoo); + values = jedis.mget(bfoo, bbar); - assertEquals(expected, values); + assertEquals(expected, values); } @Test public void setnx() { - long status = jedis.setnx(bfoo, binaryValue); - assertEquals(1, status); - assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo))); + long status = jedis.setnx(bfoo, binaryValue); + assertEquals(1, status); + assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo))); - status = jedis.setnx(bfoo, bbar); - assertEquals(0, status); - assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo))); + status = jedis.setnx(bfoo, bbar); + assertEquals(0, status); + assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo))); } @Test public void setex() { - String status = jedis.setex(bfoo, 20, binaryValue); - assertEquals(Keyword.OK.name(), status); - long ttl = jedis.ttl(bfoo); - assertTrue(ttl > 0 && ttl <= 20); + String status = jedis.setex(bfoo, 20, binaryValue); + assertEquals(Keyword.OK.name(), status); + long ttl = jedis.ttl(bfoo); + assertTrue(ttl > 0 && ttl <= 20); } @Test public void mset() { - String status = jedis.mset(bfoo, binaryValue, bbar, bfoo); - assertEquals(Keyword.OK.name(), status); - assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo))); - assertTrue(Arrays.equals(bfoo, jedis.get(bbar))); + String status = jedis.mset(bfoo, binaryValue, bbar, bfoo); + assertEquals(Keyword.OK.name(), status); + assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo))); + assertTrue(Arrays.equals(bfoo, jedis.get(bbar))); } @Test public void msetnx() { - long status = jedis.msetnx(bfoo, binaryValue, bbar, bfoo); - assertEquals(1, status); - assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo))); - assertTrue(Arrays.equals(bfoo, jedis.get(bbar))); + long status = jedis.msetnx(bfoo, binaryValue, bbar, bfoo); + assertEquals(1, status); + assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo))); + assertTrue(Arrays.equals(bfoo, jedis.get(bbar))); - status = jedis.msetnx(bfoo, bbar, "bar2".getBytes(), "foo2".getBytes()); - assertEquals(0, status); - assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo))); - assertTrue(Arrays.equals(bfoo, jedis.get(bbar))); + status = jedis.msetnx(bfoo, bbar, "bar2".getBytes(), "foo2".getBytes()); + assertEquals(0, status); + assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo))); + assertTrue(Arrays.equals(bfoo, jedis.get(bbar))); } @Test(expected = JedisDataException.class) public void incrWrongValue() { - jedis.set(bfoo, binaryValue); - jedis.incr(bfoo); + jedis.set(bfoo, binaryValue); + jedis.incr(bfoo); } @Test public void incr() { - long value = jedis.incr(bfoo); - assertEquals(1, value); - value = jedis.incr(bfoo); - assertEquals(2, value); + long value = jedis.incr(bfoo); + assertEquals(1, value); + value = jedis.incr(bfoo); + assertEquals(2, value); } @Test(expected = JedisDataException.class) public void incrByWrongValue() { - jedis.set(bfoo, binaryValue); - jedis.incrBy(bfoo, 2); + jedis.set(bfoo, binaryValue); + jedis.incrBy(bfoo, 2); } @Test public void incrBy() { - long value = jedis.incrBy(bfoo, 2); - assertEquals(2, value); - value = jedis.incrBy(bfoo, 2); - assertEquals(4, value); + long value = jedis.incrBy(bfoo, 2); + assertEquals(2, value); + value = jedis.incrBy(bfoo, 2); + assertEquals(4, value); } @Test(expected = JedisDataException.class) public void decrWrongValue() { - jedis.set(bfoo, binaryValue); - jedis.decr(bfoo); + jedis.set(bfoo, binaryValue); + jedis.decr(bfoo); } @Test public void decr() { - long value = jedis.decr(bfoo); - assertEquals(-1, value); - value = jedis.decr(bfoo); - assertEquals(-2, value); + long value = jedis.decr(bfoo); + assertEquals(-1, value); + value = jedis.decr(bfoo); + assertEquals(-2, value); } @Test(expected = JedisDataException.class) public void decrByWrongValue() { - jedis.set(bfoo, binaryValue); - jedis.decrBy(bfoo, 2); + jedis.set(bfoo, binaryValue); + jedis.decrBy(bfoo, 2); } @Test public void decrBy() { - long value = jedis.decrBy(bfoo, 2); - assertEquals(-2, value); - value = jedis.decrBy(bfoo, 2); - assertEquals(-4, value); + long value = jedis.decrBy(bfoo, 2); + assertEquals(-2, value); + value = jedis.decrBy(bfoo, 2); + assertEquals(-4, value); } @Test public void append() { - byte[] first512 = new byte[512]; - System.arraycopy(binaryValue, 0, first512, 0, 512); - long value = jedis.append(bfoo, first512); - assertEquals(512, value); - assertTrue(Arrays.equals(first512, jedis.get(bfoo))); + byte[] first512 = new byte[512]; + System.arraycopy(binaryValue, 0, first512, 0, 512); + long value = jedis.append(bfoo, first512); + assertEquals(512, value); + assertTrue(Arrays.equals(first512, jedis.get(bfoo))); - byte[] rest = new byte[binaryValue.length - 512]; - System.arraycopy(binaryValue, 512, rest, 0, binaryValue.length - 512); - value = jedis.append(bfoo, rest); - assertEquals(binaryValue.length, value); + byte[] rest = new byte[binaryValue.length - 512]; + System.arraycopy(binaryValue, 512, rest, 0, binaryValue.length - 512); + value = jedis.append(bfoo, rest); + assertEquals(binaryValue.length, value); - assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo))); + assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo))); } @Test public void substr() { - jedis.set(bfoo, binaryValue); + jedis.set(bfoo, binaryValue); - byte[] first512 = new byte[512]; - System.arraycopy(binaryValue, 0, first512, 0, 512); - byte[] rfirst512 = jedis.substr(bfoo, 0, 511); - assertTrue(Arrays.equals(first512, rfirst512)); + byte[] first512 = new byte[512]; + System.arraycopy(binaryValue, 0, first512, 0, 512); + byte[] rfirst512 = jedis.substr(bfoo, 0, 511); + assertTrue(Arrays.equals(first512, rfirst512)); - byte[] last512 = new byte[512]; - System.arraycopy(binaryValue, binaryValue.length - 512, last512, 0, 512); - assertTrue(Arrays.equals(last512, jedis.substr(bfoo, -512, -1))); + byte[] last512 = new byte[512]; + System.arraycopy(binaryValue, binaryValue.length - 512, last512, 0, 512); + assertTrue(Arrays.equals(last512, jedis.substr(bfoo, -512, -1))); - assertTrue(Arrays.equals(binaryValue, jedis.substr(bfoo, 0, -1))); + assertTrue(Arrays.equals(binaryValue, jedis.substr(bfoo, 0, -1))); - assertTrue(Arrays.equals(last512, - jedis.substr(bfoo, binaryValue.length - 512, 100000))); + assertTrue(Arrays.equals(last512, + jedis.substr(bfoo, binaryValue.length - 512, 100000))); } @Test public void strlen() { - jedis.set(bfoo, binaryValue); - assertEquals(binaryValue.length, jedis.strlen(bfoo).intValue()); + jedis.set(bfoo, binaryValue); + assertEquals(binaryValue.length, jedis.strlen(bfoo).intValue()); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/commands/BitCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/BitCommandsTest.java index d515318..fe72fd8 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/BitCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/BitCommandsTest.java @@ -9,189 +9,189 @@ import redis.clients.jedis.Protocol; public class BitCommandsTest extends JedisCommandTestBase { @Test public void setAndgetbit() { - boolean bit = jedis.setbit("foo", 0, true); - assertEquals(false, bit); + boolean bit = jedis.setbit("foo", 0, true); + assertEquals(false, bit); - bit = jedis.getbit("foo", 0); - assertEquals(true, bit); + bit = jedis.getbit("foo", 0); + assertEquals(true, bit); - boolean bbit = jedis.setbit("bfoo".getBytes(), 0, "1".getBytes()); - assertFalse(bbit); + boolean bbit = jedis.setbit("bfoo".getBytes(), 0, "1".getBytes()); + assertFalse(bbit); - bbit = jedis.getbit("bfoo".getBytes(), 0); - assertTrue(bbit); + bbit = jedis.getbit("bfoo".getBytes(), 0); + assertTrue(bbit); } @Test public void bitpos() { - String foo = "foo"; + String foo = "foo"; - jedis.set(foo, String.valueOf(0)); + jedis.set(foo, String.valueOf(0)); - jedis.setbit(foo, 3, true); - jedis.setbit(foo, 7, true); - jedis.setbit(foo, 13, true); - jedis.setbit(foo, 39, true); + jedis.setbit(foo, 3, true); + jedis.setbit(foo, 7, true); + jedis.setbit(foo, 13, true); + jedis.setbit(foo, 39, true); - /* - * byte: 0 1 2 3 4 bit: 00010001 / 00000100 / 00000000 / 00000000 / - * 00000001 - */ - long offset = jedis.bitpos(foo, true); - assertEquals(2, offset); - offset = jedis.bitpos(foo, false); - assertEquals(0, offset); + /* + * byte: 0 1 2 3 4 bit: 00010001 / 00000100 / 00000000 / 00000000 / + * 00000001 + */ + long offset = jedis.bitpos(foo, true); + assertEquals(2, offset); + offset = jedis.bitpos(foo, false); + assertEquals(0, offset); - offset = jedis.bitpos(foo, true, new BitPosParams(1)); - assertEquals(13, offset); - offset = jedis.bitpos(foo, false, new BitPosParams(1)); - assertEquals(8, offset); + offset = jedis.bitpos(foo, true, new BitPosParams(1)); + assertEquals(13, offset); + offset = jedis.bitpos(foo, false, new BitPosParams(1)); + assertEquals(8, offset); - offset = jedis.bitpos(foo, true, new BitPosParams(2, 3)); - assertEquals(-1, offset); - offset = jedis.bitpos(foo, false, new BitPosParams(2, 3)); - assertEquals(16, offset); + offset = jedis.bitpos(foo, true, new BitPosParams(2, 3)); + assertEquals(-1, offset); + offset = jedis.bitpos(foo, false, new BitPosParams(2, 3)); + assertEquals(16, offset); - offset = jedis.bitpos(foo, true, new BitPosParams(3, 4)); - assertEquals(39, offset); + offset = jedis.bitpos(foo, true, new BitPosParams(3, 4)); + assertEquals(39, offset); } @Test public void bitposBinary() { - // binary - byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; + // binary + byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 }; - jedis.set(bfoo, Protocol.toByteArray(0)); + jedis.set(bfoo, Protocol.toByteArray(0)); - jedis.setbit(bfoo, 3, true); - jedis.setbit(bfoo, 7, true); - jedis.setbit(bfoo, 13, true); - jedis.setbit(bfoo, 39, true); + jedis.setbit(bfoo, 3, true); + jedis.setbit(bfoo, 7, true); + jedis.setbit(bfoo, 13, true); + jedis.setbit(bfoo, 39, true); - /* - * byte: 0 1 2 3 4 bit: 00010001 / 00000100 / 00000000 / 00000000 / - * 00000001 - */ - long offset = jedis.bitpos(bfoo, true); - assertEquals(2, offset); - offset = jedis.bitpos(bfoo, false); - assertEquals(0, offset); + /* + * byte: 0 1 2 3 4 bit: 00010001 / 00000100 / 00000000 / 00000000 / + * 00000001 + */ + long offset = jedis.bitpos(bfoo, true); + assertEquals(2, offset); + offset = jedis.bitpos(bfoo, false); + assertEquals(0, offset); - offset = jedis.bitpos(bfoo, true, new BitPosParams(1)); - assertEquals(13, offset); - offset = jedis.bitpos(bfoo, false, new BitPosParams(1)); - assertEquals(8, offset); + offset = jedis.bitpos(bfoo, true, new BitPosParams(1)); + assertEquals(13, offset); + offset = jedis.bitpos(bfoo, false, new BitPosParams(1)); + assertEquals(8, offset); - offset = jedis.bitpos(bfoo, true, new BitPosParams(2, 3)); - assertEquals(-1, offset); - offset = jedis.bitpos(bfoo, false, new BitPosParams(2, 3)); - assertEquals(16, offset); + offset = jedis.bitpos(bfoo, true, new BitPosParams(2, 3)); + assertEquals(-1, offset); + offset = jedis.bitpos(bfoo, false, new BitPosParams(2, 3)); + assertEquals(16, offset); - offset = jedis.bitpos(bfoo, true, new BitPosParams(3, 4)); - assertEquals(39, offset); + offset = jedis.bitpos(bfoo, true, new BitPosParams(3, 4)); + assertEquals(39, offset); } @Test public void bitposWithNoMatchingBitExist() { - String foo = "foo"; + String foo = "foo"; - jedis.set(foo, String.valueOf(0)); - for (int idx = 0; idx < 8; idx++) { - jedis.setbit(foo, idx, true); - } + jedis.set(foo, String.valueOf(0)); + for (int idx = 0; idx < 8; idx++) { + jedis.setbit(foo, idx, true); + } - /* - * byte: 0 bit: 11111111 - */ - long offset = jedis.bitpos(foo, false); - // offset should be last index + 1 - assertEquals(8, offset); + /* + * byte: 0 bit: 11111111 + */ + long offset = jedis.bitpos(foo, false); + // offset should be last index + 1 + assertEquals(8, offset); } @Test public void bitposWithNoMatchingBitExistWithinRange() { - String foo = "foo"; + String foo = "foo"; - jedis.set(foo, String.valueOf(0)); - for (int idx = 0; idx < 8 * 5; idx++) { - jedis.setbit(foo, idx, true); - } + jedis.set(foo, String.valueOf(0)); + for (int idx = 0; idx < 8 * 5; idx++) { + jedis.setbit(foo, idx, true); + } - /* - * 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 - assertEquals(-1, offset); + /* + * 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 + assertEquals(-1, offset); } @Test public void setAndgetrange() { - jedis.set("key1", "Hello World"); - long reply = jedis.setrange("key1", 6, "Jedis"); - assertEquals(11, reply); + jedis.set("key1", "Hello World"); + long reply = jedis.setrange("key1", 6, "Jedis"); + assertEquals(11, reply); - assertEquals(jedis.get("key1"), "Hello Jedis"); + assertEquals(jedis.get("key1"), "Hello Jedis"); - assertEquals("Hello", jedis.getrange("key1", 0, 4)); - assertEquals("Jedis", jedis.getrange("key1", 6, 11)); + assertEquals("Hello", jedis.getrange("key1", 0, 4)); + assertEquals("Jedis", jedis.getrange("key1", 6, 11)); } @Test public void bitCount() { - jedis.del("foo"); + jedis.del("foo"); - jedis.setbit("foo", 16, true); - jedis.setbit("foo", 24, true); - jedis.setbit("foo", 40, true); - jedis.setbit("foo", 56, true); + jedis.setbit("foo", 16, true); + jedis.setbit("foo", 24, true); + jedis.setbit("foo", 40, true); + jedis.setbit("foo", 56, true); - long c4 = jedis.bitcount("foo"); - assertEquals(4, c4); + long c4 = jedis.bitcount("foo"); + assertEquals(4, c4); - long c3 = jedis.bitcount("foo", 2L, 5L); - assertEquals(3, c3); + long c3 = jedis.bitcount("foo", 2L, 5L); + assertEquals(3, c3); - jedis.del("foo"); + jedis.del("foo"); } @Test public void bitOp() { - jedis.set("key1", "\u0060"); - jedis.set("key2", "\u0044"); + jedis.set("key1", "\u0060"); + jedis.set("key2", "\u0044"); - jedis.bitop(BitOP.AND, "resultAnd", "key1", "key2"); - String resultAnd = jedis.get("resultAnd"); - assertEquals("\u0040", resultAnd); + jedis.bitop(BitOP.AND, "resultAnd", "key1", "key2"); + String resultAnd = jedis.get("resultAnd"); + assertEquals("\u0040", resultAnd); - jedis.bitop(BitOP.OR, "resultOr", "key1", "key2"); - String resultOr = jedis.get("resultOr"); - assertEquals("\u0064", resultOr); + jedis.bitop(BitOP.OR, "resultOr", "key1", "key2"); + String resultOr = jedis.get("resultOr"); + assertEquals("\u0064", resultOr); - jedis.bitop(BitOP.XOR, "resultXor", "key1", "key2"); - String resultXor = jedis.get("resultXor"); - assertEquals("\u0024", resultXor); + jedis.bitop(BitOP.XOR, "resultXor", "key1", "key2"); + String resultXor = jedis.get("resultXor"); + assertEquals("\u0024", resultXor); - jedis.del("resultAnd"); - jedis.del("resultOr"); - jedis.del("resultXor"); - jedis.del("key1"); - jedis.del("key2"); + jedis.del("resultAnd"); + jedis.del("resultOr"); + jedis.del("resultXor"); + jedis.del("key1"); + jedis.del("key2"); } @Test public void bitOpNot() { - jedis.del("key"); - jedis.setbit("key", 0, true); - jedis.setbit("key", 4, true); + jedis.del("key"); + jedis.setbit("key", 0, true); + jedis.setbit("key", 4, true); - jedis.bitop(BitOP.NOT, "resultNot", "key"); + jedis.bitop(BitOP.NOT, "resultNot", "key"); - String resultNot = jedis.get("resultNot"); - assertEquals("\u0077", resultNot); + String resultNot = jedis.get("resultNot"); + assertEquals("\u0077", resultNot); - jedis.del("key"); - jedis.del("resultNot"); + jedis.del("key"); + jedis.del("resultNot"); } } diff --git a/src/test/java/redis/clients/jedis/tests/commands/ClusterCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ClusterCommandsTest.java index f783cee..31840e9 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ClusterCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ClusterCommandsTest.java @@ -24,134 +24,134 @@ public class ClusterCommandsTest extends JedisTestBase { @Before public void setUp() throws Exception { - node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort()); - node1.connect(); - node1.flushAll(); + node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort()); + node1.connect(); + node1.flushAll(); - node2 = new Jedis(nodeInfo2.getHost(), nodeInfo2.getPort()); - node2.connect(); - node2.flushAll(); + node2 = new Jedis(nodeInfo2.getHost(), nodeInfo2.getPort()); + node2.connect(); + node2.flushAll(); } @After public void tearDown() { - node1.disconnect(); - node2.disconnect(); + node1.disconnect(); + node2.disconnect(); } @AfterClass public static void removeSlots() throws InterruptedException { - node1.clusterReset(Reset.SOFT); - node2.clusterReset(Reset.SOFT); + node1.clusterReset(Reset.SOFT); + node2.clusterReset(Reset.SOFT); } @Test public void testClusterSoftReset() { - node1.clusterMeet("127.0.0.1", nodeInfo2.getPort()); - assertTrue(node1.clusterNodes().split("\n").length > 1); - node1.clusterReset(Reset.SOFT); - assertEquals(1, node1.clusterNodes().split("\n").length); + node1.clusterMeet("127.0.0.1", nodeInfo2.getPort()); + assertTrue(node1.clusterNodes().split("\n").length > 1); + node1.clusterReset(Reset.SOFT); + assertEquals(1, node1.clusterNodes().split("\n").length); } @Test public void testClusterHardReset() { - String nodeId = JedisClusterTestUtil.getNodeId(node1.clusterNodes()); - node1.clusterReset(Reset.HARD); - String newNodeId = JedisClusterTestUtil.getNodeId(node1.clusterNodes()); - assertNotEquals(nodeId, newNodeId); + String nodeId = JedisClusterTestUtil.getNodeId(node1.clusterNodes()); + node1.clusterReset(Reset.HARD); + String newNodeId = JedisClusterTestUtil.getNodeId(node1.clusterNodes()); + assertNotEquals(nodeId, newNodeId); } @Test public void clusterSetSlotImporting() { - node2.clusterAddSlots(6000); - String[] nodes = node1.clusterNodes().split("\n"); - String nodeId = nodes[0].split(" ")[0]; - String status = node1.clusterSetSlotImporting(6000, nodeId); - assertEquals("OK", status); + node2.clusterAddSlots(6000); + String[] nodes = node1.clusterNodes().split("\n"); + String nodeId = nodes[0].split(" ")[0]; + String status = node1.clusterSetSlotImporting(6000, nodeId); + assertEquals("OK", status); } @Test public void clusterNodes() { - String nodes = node1.clusterNodes(); - assertTrue(nodes.split("\n").length > 0); + String nodes = node1.clusterNodes(); + assertTrue(nodes.split("\n").length > 0); } @Test public void clusterMeet() { - String status = node1.clusterMeet("127.0.0.1", nodeInfo2.getPort()); - assertEquals("OK", status); + String status = node1.clusterMeet("127.0.0.1", nodeInfo2.getPort()); + assertEquals("OK", status); } @Test public void clusterAddSlots() { - String status = node1.clusterAddSlots(1, 2, 3, 4, 5); - assertEquals("OK", status); + String status = node1.clusterAddSlots(1, 2, 3, 4, 5); + assertEquals("OK", status); } @Test public void clusterDelSlots() { - node1.clusterAddSlots(900); - String status = node1.clusterDelSlots(900); - assertEquals("OK", status); + node1.clusterAddSlots(900); + String status = node1.clusterDelSlots(900); + assertEquals("OK", status); } @Test public void clusterInfo() { - String info = node1.clusterInfo(); - assertNotNull(info); + String info = node1.clusterInfo(); + assertNotNull(info); } @Test public void clusterGetKeysInSlot() { - node1.clusterAddSlots(500); - List keys = node1.clusterGetKeysInSlot(500, 1); - assertEquals(0, keys.size()); + node1.clusterAddSlots(500); + List keys = node1.clusterGetKeysInSlot(500, 1); + assertEquals(0, keys.size()); } @Test public void clusterSetSlotNode() { - String[] nodes = node1.clusterNodes().split("\n"); - String nodeId = nodes[0].split(" ")[0]; - String status = node1.clusterSetSlotNode(10000, nodeId); - assertEquals("OK", status); + String[] nodes = node1.clusterNodes().split("\n"); + String nodeId = nodes[0].split(" ")[0]; + String status = node1.clusterSetSlotNode(10000, nodeId); + assertEquals("OK", status); } @Test public void clusterSetSlotMigrating() { - node1.clusterAddSlots(5000); - String[] nodes = node1.clusterNodes().split("\n"); - String nodeId = nodes[0].split(" ")[0]; - String status = node1.clusterSetSlotMigrating(5000, nodeId); - assertEquals("OK", status); + node1.clusterAddSlots(5000); + String[] nodes = node1.clusterNodes().split("\n"); + String nodeId = nodes[0].split(" ")[0]; + String status = node1.clusterSetSlotMigrating(5000, nodeId); + assertEquals("OK", status); } @Test public void clusterSlots() { - // please see cluster slot output format from below commit - // @see: - // https://github.com/antirez/redis/commit/e14829de3025ffb0d3294e5e5a1553afd9f10b60 - String status = node1.clusterAddSlots(3000, 3001, 3002); - assertEquals("OK", status); - status = node2.clusterAddSlots(4000, 4001, 4002); - assertEquals("OK", status); + // please see cluster slot output format from below commit + // @see: + // https://github.com/antirez/redis/commit/e14829de3025ffb0d3294e5e5a1553afd9f10b60 + String status = node1.clusterAddSlots(3000, 3001, 3002); + assertEquals("OK", status); + status = node2.clusterAddSlots(4000, 4001, 4002); + assertEquals("OK", status); - List slots = node1.clusterSlots(); - assertNotNull(slots); - assertTrue(slots.size() > 0); + List slots = node1.clusterSlots(); + assertNotNull(slots); + assertTrue(slots.size() > 0); - for (Object slotInfoObj : slots) { - List slotInfo = (List) slotInfoObj; - assertNotNull(slots); - assertTrue(slots.size() >= 2); + for (Object slotInfoObj : slots) { + List slotInfo = (List) slotInfoObj; + assertNotNull(slots); + assertTrue(slots.size() >= 2); - assertTrue(slotInfo.get(0) instanceof Long); - assertTrue(slotInfo.get(1) instanceof Long); + assertTrue(slotInfo.get(0) instanceof Long); + assertTrue(slotInfo.get(1) instanceof Long); - if (slots.size() > 2) { - // assigned slots - assertTrue(slotInfo.get(2) instanceof List); - } - } + if (slots.size() > 2) { + // assigned slots + assertTrue(slotInfo.get(2) instanceof List); + } + } } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/commands/ConnectionHandlingCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ConnectionHandlingCommandsTest.java index 1201e8c..e4d8578 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ConnectionHandlingCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ConnectionHandlingCommandsTest.java @@ -11,12 +11,12 @@ public class ConnectionHandlingCommandsTest extends JedisCommandTestBase { @Test public void quit() { - assertEquals("OK", jedis.quit()); + assertEquals("OK", jedis.quit()); } @Test public void binary_quit() { - BinaryJedis bj = new BinaryJedis(hnp.getHost()); - assertEquals("OK", bj.quit()); + BinaryJedis bj = new BinaryJedis(hnp.getHost()); + assertEquals("OK", bj.quit()); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java index 59ec6bc..adbfd16 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java @@ -12,115 +12,115 @@ import redis.clients.jedis.exceptions.JedisDataException; public class ControlCommandsTest extends JedisCommandTestBase { @Test public void save() { - try { - String status = jedis.save(); - assertEquals("OK", status); - } catch (JedisDataException e) { - assertTrue("ERR Background save already in progress" - .equalsIgnoreCase(e.getMessage())); - } + try { + String status = jedis.save(); + assertEquals("OK", status); + } catch (JedisDataException e) { + assertTrue("ERR Background save already in progress" + .equalsIgnoreCase(e.getMessage())); + } } @Test public void bgsave() { - try { - String status = jedis.bgsave(); - assertEquals("Background saving started", status); - } catch (JedisDataException e) { - assertTrue("ERR Background save already in progress" - .equalsIgnoreCase(e.getMessage())); - } + try { + String status = jedis.bgsave(); + assertEquals("Background saving started", status); + } catch (JedisDataException e) { + assertTrue("ERR Background save already in progress" + .equalsIgnoreCase(e.getMessage())); + } } @Test public void bgrewriteaof() { - String scheduled = "Background append only file rewriting scheduled"; - String started = "Background append only file rewriting started"; + String scheduled = "Background append only file rewriting scheduled"; + String started = "Background append only file rewriting started"; - String status = jedis.bgrewriteaof(); + String status = jedis.bgrewriteaof(); - boolean ok = status.equals(scheduled) || status.equals(started); - assertTrue(ok); + boolean ok = status.equals(scheduled) || status.equals(started); + assertTrue(ok); } @Test public void lastsave() throws InterruptedException { - long saved = jedis.lastsave(); - assertTrue(saved > 0); + long saved = jedis.lastsave(); + assertTrue(saved > 0); } @Test public void info() { - String info = jedis.info(); - assertNotNull(info); - info = jedis.info("server"); - assertNotNull(info); + String info = jedis.info(); + assertNotNull(info); + info = jedis.info("server"); + assertNotNull(info); } @Test public void monitor() { - new Thread(new Runnable() { - public void run() { - try { - // sleep 100ms to make sure that monitor thread runs first - Thread.sleep(100); - } catch (InterruptedException e) { - } - Jedis j = new Jedis("localhost"); - j.auth("foobared"); - for (int i = 0; i < 5; i++) { - j.incr("foobared"); - } - j.disconnect(); - } - }).start(); + new Thread(new Runnable() { + public void run() { + try { + // sleep 100ms to make sure that monitor thread runs first + Thread.sleep(100); + } catch (InterruptedException e) { + } + Jedis j = new Jedis("localhost"); + j.auth("foobared"); + for (int i = 0; i < 5; i++) { + j.incr("foobared"); + } + j.disconnect(); + } + }).start(); - jedis.monitor(new JedisMonitor() { - private int count = 0; + jedis.monitor(new JedisMonitor() { + private int count = 0; - public void onCommand(String command) { - if (command.contains("INCR")) { - count++; - } - if (count == 5) { - client.disconnect(); - } - } - }); + public void onCommand(String command) { + if (command.contains("INCR")) { + count++; + } + if (count == 5) { + client.disconnect(); + } + } + }); } @Test public void configGet() { - List info = jedis.configGet("m*"); - assertNotNull(info); + List info = jedis.configGet("m*"); + assertNotNull(info); } @Test public void configSet() { - List info = jedis.configGet("maxmemory"); - String memory = info.get(1); - String status = jedis.configSet("maxmemory", "200"); - assertEquals("OK", status); - jedis.configSet("maxmemory", memory); + List info = jedis.configGet("maxmemory"); + String memory = info.get(1); + String status = jedis.configSet("maxmemory", "200"); + assertEquals("OK", status); + jedis.configSet("maxmemory", memory); } @Test public void sync() { - jedis.sync(); + jedis.sync(); } @Test public void debug() { - jedis.set("foo", "bar"); - String resp = jedis.debug(DebugParams.OBJECT("foo")); - assertNotNull(resp); - resp = jedis.debug(DebugParams.RELOAD()); - assertNotNull(resp); + jedis.set("foo", "bar"); + String resp = jedis.debug(DebugParams.OBJECT("foo")); + assertNotNull(resp); + resp = jedis.debug(DebugParams.RELOAD()); + assertNotNull(resp); } @Test public void waitReplicas() { - Long replicas = jedis.waitReplicas(1, 100); - assertEquals(1, replicas.longValue()); + Long replicas = jedis.waitReplicas(1, 100); + assertEquals(1, replicas.longValue()); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/commands/HashesCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/HashesCommandsTest.java index 353fb23..b9f4358 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/HashesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/HashesCommandsTest.java @@ -30,388 +30,388 @@ public class HashesCommandsTest extends JedisCommandTestBase { @Test public void hset() { - long status = jedis.hset("foo", "bar", "car"); - assertEquals(1, status); - status = jedis.hset("foo", "bar", "foo"); - assertEquals(0, status); + long status = jedis.hset("foo", "bar", "car"); + assertEquals(1, status); + status = jedis.hset("foo", "bar", "foo"); + assertEquals(0, status); - // Binary - long bstatus = jedis.hset(bfoo, bbar, bcar); - assertEquals(1, bstatus); - bstatus = jedis.hset(bfoo, bbar, bfoo); - assertEquals(0, bstatus); + // Binary + long bstatus = jedis.hset(bfoo, bbar, bcar); + assertEquals(1, bstatus); + bstatus = jedis.hset(bfoo, bbar, bfoo); + assertEquals(0, bstatus); } @Test public void hget() { - jedis.hset("foo", "bar", "car"); - assertEquals(null, jedis.hget("bar", "foo")); - assertEquals(null, jedis.hget("foo", "car")); - assertEquals("car", jedis.hget("foo", "bar")); + jedis.hset("foo", "bar", "car"); + assertEquals(null, jedis.hget("bar", "foo")); + assertEquals(null, jedis.hget("foo", "car")); + assertEquals("car", jedis.hget("foo", "bar")); - // Binary - jedis.hset(bfoo, bbar, bcar); - assertEquals(null, jedis.hget(bbar, bfoo)); - assertEquals(null, jedis.hget(bfoo, bcar)); - assertArrayEquals(bcar, jedis.hget(bfoo, bbar)); + // Binary + jedis.hset(bfoo, bbar, bcar); + assertEquals(null, jedis.hget(bbar, bfoo)); + assertEquals(null, jedis.hget(bfoo, bcar)); + assertArrayEquals(bcar, jedis.hget(bfoo, bbar)); } @Test public void hsetnx() { - long status = jedis.hsetnx("foo", "bar", "car"); - assertEquals(1, status); - assertEquals("car", jedis.hget("foo", "bar")); + long status = jedis.hsetnx("foo", "bar", "car"); + assertEquals(1, status); + assertEquals("car", jedis.hget("foo", "bar")); - status = jedis.hsetnx("foo", "bar", "foo"); - assertEquals(0, status); - assertEquals("car", jedis.hget("foo", "bar")); + status = jedis.hsetnx("foo", "bar", "foo"); + assertEquals(0, status); + assertEquals("car", jedis.hget("foo", "bar")); - status = jedis.hsetnx("foo", "car", "bar"); - assertEquals(1, status); - assertEquals("bar", jedis.hget("foo", "car")); + status = jedis.hsetnx("foo", "car", "bar"); + assertEquals(1, status); + assertEquals("bar", jedis.hget("foo", "car")); - // Binary - long bstatus = jedis.hsetnx(bfoo, bbar, bcar); - assertEquals(1, bstatus); - assertArrayEquals(bcar, jedis.hget(bfoo, bbar)); + // Binary + long bstatus = jedis.hsetnx(bfoo, bbar, bcar); + assertEquals(1, bstatus); + assertArrayEquals(bcar, jedis.hget(bfoo, bbar)); - bstatus = jedis.hsetnx(bfoo, bbar, bfoo); - assertEquals(0, bstatus); - assertArrayEquals(bcar, jedis.hget(bfoo, bbar)); + bstatus = jedis.hsetnx(bfoo, bbar, bfoo); + assertEquals(0, bstatus); + assertArrayEquals(bcar, jedis.hget(bfoo, bbar)); - bstatus = jedis.hsetnx(bfoo, bcar, bbar); - assertEquals(1, bstatus); - assertArrayEquals(bbar, jedis.hget(bfoo, bcar)); + bstatus = jedis.hsetnx(bfoo, bcar, bbar); + assertEquals(1, bstatus); + assertArrayEquals(bbar, jedis.hget(bfoo, bcar)); } @Test public void hmset() { - Map hash = new HashMap(); - hash.put("bar", "car"); - hash.put("car", "bar"); - String status = jedis.hmset("foo", hash); - assertEquals("OK", status); - assertEquals("car", jedis.hget("foo", "bar")); - assertEquals("bar", jedis.hget("foo", "car")); + Map hash = new HashMap(); + hash.put("bar", "car"); + hash.put("car", "bar"); + String status = jedis.hmset("foo", hash); + assertEquals("OK", status); + assertEquals("car", jedis.hget("foo", "bar")); + assertEquals("bar", jedis.hget("foo", "car")); - // Binary - Map bhash = new HashMap(); - bhash.put(bbar, bcar); - bhash.put(bcar, bbar); - String bstatus = jedis.hmset(bfoo, bhash); - assertEquals("OK", bstatus); - assertArrayEquals(bcar, jedis.hget(bfoo, bbar)); - assertArrayEquals(bbar, jedis.hget(bfoo, bcar)); + // Binary + Map bhash = new HashMap(); + bhash.put(bbar, bcar); + bhash.put(bcar, bbar); + String bstatus = jedis.hmset(bfoo, bhash); + assertEquals("OK", bstatus); + assertArrayEquals(bcar, jedis.hget(bfoo, bbar)); + assertArrayEquals(bbar, jedis.hget(bfoo, bcar)); } @Test public void hmget() { - Map hash = new HashMap(); - hash.put("bar", "car"); - hash.put("car", "bar"); - jedis.hmset("foo", hash); + Map hash = new HashMap(); + hash.put("bar", "car"); + hash.put("car", "bar"); + jedis.hmset("foo", hash); - List values = jedis.hmget("foo", "bar", "car", "foo"); - List expected = new ArrayList(); - expected.add("car"); - expected.add("bar"); - expected.add(null); + List values = jedis.hmget("foo", "bar", "car", "foo"); + List expected = new ArrayList(); + expected.add("car"); + expected.add("bar"); + expected.add(null); - assertEquals(expected, values); + assertEquals(expected, values); - // Binary - Map bhash = new HashMap(); - bhash.put(bbar, bcar); - bhash.put(bcar, bbar); - jedis.hmset(bfoo, bhash); + // Binary + Map bhash = new HashMap(); + bhash.put(bbar, bcar); + bhash.put(bcar, bbar); + jedis.hmset(bfoo, bhash); - List bvalues = jedis.hmget(bfoo, bbar, bcar, bfoo); - List bexpected = new ArrayList(); - bexpected.add(bcar); - bexpected.add(bbar); - bexpected.add(null); + List bvalues = jedis.hmget(bfoo, bbar, bcar, bfoo); + List bexpected = new ArrayList(); + bexpected.add(bcar); + bexpected.add(bbar); + bexpected.add(null); - assertEquals(bexpected, bvalues); + assertEquals(bexpected, bvalues); } @Test public void hincrBy() { - long value = jedis.hincrBy("foo", "bar", 1); - assertEquals(1, value); - value = jedis.hincrBy("foo", "bar", -1); - assertEquals(0, value); - value = jedis.hincrBy("foo", "bar", -10); - assertEquals(-10, value); + long value = jedis.hincrBy("foo", "bar", 1); + assertEquals(1, value); + value = jedis.hincrBy("foo", "bar", -1); + assertEquals(0, value); + value = jedis.hincrBy("foo", "bar", -10); + assertEquals(-10, value); - // Binary - long bvalue = jedis.hincrBy(bfoo, bbar, 1); - assertEquals(1, bvalue); - bvalue = jedis.hincrBy(bfoo, bbar, -1); - assertEquals(0, bvalue); - bvalue = jedis.hincrBy(bfoo, bbar, -10); - assertEquals(-10, bvalue); + // Binary + long bvalue = jedis.hincrBy(bfoo, bbar, 1); + assertEquals(1, bvalue); + bvalue = jedis.hincrBy(bfoo, bbar, -1); + assertEquals(0, bvalue); + bvalue = jedis.hincrBy(bfoo, bbar, -10); + assertEquals(-10, bvalue); } @Test public void hincrByFloat() { - Double value = jedis.hincrByFloat("foo", "bar", 1.5d); - assertEquals((Double) 1.5d, value); - value = jedis.hincrByFloat("foo", "bar", -1.5d); - assertEquals((Double) 0d, value); - value = jedis.hincrByFloat("foo", "bar", -10.7d); - assertEquals(Double.compare(-10.7d, value), 0); + Double value = jedis.hincrByFloat("foo", "bar", 1.5d); + assertEquals((Double) 1.5d, value); + value = jedis.hincrByFloat("foo", "bar", -1.5d); + assertEquals((Double) 0d, value); + value = jedis.hincrByFloat("foo", "bar", -10.7d); + assertEquals(Double.compare(-10.7d, value), 0); - // Binary - double bvalue = jedis.hincrByFloat(bfoo, bbar, 1.5d); - assertEquals(Double.compare(1.5d, bvalue), 0); - bvalue = jedis.hincrByFloat(bfoo, bbar, -1.5d); - assertEquals(Double.compare(0d, bvalue), 0); - bvalue = jedis.hincrByFloat(bfoo, bbar, -10.7d); - assertEquals(Double.compare(-10.7d, value), 0); + // Binary + double bvalue = jedis.hincrByFloat(bfoo, bbar, 1.5d); + assertEquals(Double.compare(1.5d, bvalue), 0); + bvalue = jedis.hincrByFloat(bfoo, bbar, -1.5d); + assertEquals(Double.compare(0d, bvalue), 0); + bvalue = jedis.hincrByFloat(bfoo, bbar, -10.7d); + assertEquals(Double.compare(-10.7d, value), 0); } @Test public void hexists() { - Map hash = new HashMap(); - hash.put("bar", "car"); - hash.put("car", "bar"); - jedis.hmset("foo", hash); + Map hash = new HashMap(); + hash.put("bar", "car"); + hash.put("car", "bar"); + jedis.hmset("foo", hash); - assertFalse(jedis.hexists("bar", "foo")); - assertFalse(jedis.hexists("foo", "foo")); - assertTrue(jedis.hexists("foo", "bar")); + assertFalse(jedis.hexists("bar", "foo")); + assertFalse(jedis.hexists("foo", "foo")); + assertTrue(jedis.hexists("foo", "bar")); - // Binary - Map bhash = new HashMap(); - bhash.put(bbar, bcar); - bhash.put(bcar, bbar); - jedis.hmset(bfoo, bhash); + // Binary + Map bhash = new HashMap(); + bhash.put(bbar, bcar); + bhash.put(bcar, bbar); + jedis.hmset(bfoo, bhash); - assertFalse(jedis.hexists(bbar, bfoo)); - assertFalse(jedis.hexists(bfoo, bfoo)); - assertTrue(jedis.hexists(bfoo, bbar)); + assertFalse(jedis.hexists(bbar, bfoo)); + assertFalse(jedis.hexists(bfoo, bfoo)); + assertTrue(jedis.hexists(bfoo, bbar)); } @Test public void hdel() { - Map hash = new HashMap(); - hash.put("bar", "car"); - hash.put("car", "bar"); - jedis.hmset("foo", hash); + Map hash = new HashMap(); + hash.put("bar", "car"); + hash.put("car", "bar"); + jedis.hmset("foo", hash); - assertEquals(0, jedis.hdel("bar", "foo").intValue()); - assertEquals(0, jedis.hdel("foo", "foo").intValue()); - assertEquals(1, jedis.hdel("foo", "bar").intValue()); - assertEquals(null, jedis.hget("foo", "bar")); + assertEquals(0, jedis.hdel("bar", "foo").intValue()); + assertEquals(0, jedis.hdel("foo", "foo").intValue()); + assertEquals(1, jedis.hdel("foo", "bar").intValue()); + assertEquals(null, jedis.hget("foo", "bar")); - // Binary - Map bhash = new HashMap(); - bhash.put(bbar, bcar); - bhash.put(bcar, bbar); - jedis.hmset(bfoo, bhash); + // Binary + Map bhash = new HashMap(); + bhash.put(bbar, bcar); + bhash.put(bcar, bbar); + jedis.hmset(bfoo, bhash); - assertEquals(0, jedis.hdel(bbar, bfoo).intValue()); - assertEquals(0, jedis.hdel(bfoo, bfoo).intValue()); - assertEquals(1, jedis.hdel(bfoo, bbar).intValue()); - assertEquals(null, jedis.hget(bfoo, bbar)); + assertEquals(0, jedis.hdel(bbar, bfoo).intValue()); + assertEquals(0, jedis.hdel(bfoo, bfoo).intValue()); + assertEquals(1, jedis.hdel(bfoo, bbar).intValue()); + assertEquals(null, jedis.hget(bfoo, bbar)); } @Test public void hlen() { - Map hash = new HashMap(); - hash.put("bar", "car"); - hash.put("car", "bar"); - jedis.hmset("foo", hash); + Map hash = new HashMap(); + hash.put("bar", "car"); + hash.put("car", "bar"); + jedis.hmset("foo", hash); - assertEquals(0, jedis.hlen("bar").intValue()); - assertEquals(2, jedis.hlen("foo").intValue()); + assertEquals(0, jedis.hlen("bar").intValue()); + assertEquals(2, jedis.hlen("foo").intValue()); - // Binary - Map bhash = new HashMap(); - bhash.put(bbar, bcar); - bhash.put(bcar, bbar); - jedis.hmset(bfoo, bhash); + // Binary + Map bhash = new HashMap(); + bhash.put(bbar, bcar); + bhash.put(bcar, bbar); + jedis.hmset(bfoo, bhash); - assertEquals(0, jedis.hlen(bbar).intValue()); - assertEquals(2, jedis.hlen(bfoo).intValue()); + assertEquals(0, jedis.hlen(bbar).intValue()); + assertEquals(2, jedis.hlen(bfoo).intValue()); } @Test public void hkeys() { - Map hash = new LinkedHashMap(); - hash.put("bar", "car"); - hash.put("car", "bar"); - jedis.hmset("foo", hash); + Map hash = new LinkedHashMap(); + hash.put("bar", "car"); + hash.put("car", "bar"); + jedis.hmset("foo", hash); - Set keys = jedis.hkeys("foo"); - Set expected = new LinkedHashSet(); - expected.add("bar"); - expected.add("car"); - assertEquals(expected, keys); + Set keys = jedis.hkeys("foo"); + Set expected = new LinkedHashSet(); + expected.add("bar"); + expected.add("car"); + assertEquals(expected, keys); - // Binary - Map bhash = new LinkedHashMap(); - bhash.put(bbar, bcar); - bhash.put(bcar, bbar); - jedis.hmset(bfoo, bhash); + // Binary + Map bhash = new LinkedHashMap(); + bhash.put(bbar, bcar); + bhash.put(bcar, bbar); + jedis.hmset(bfoo, bhash); - Set bkeys = jedis.hkeys(bfoo); - Set bexpected = new LinkedHashSet(); - bexpected.add(bbar); - bexpected.add(bcar); - assertEquals(bexpected, bkeys); + Set bkeys = jedis.hkeys(bfoo); + Set bexpected = new LinkedHashSet(); + bexpected.add(bbar); + bexpected.add(bcar); + assertEquals(bexpected, bkeys); } @Test public void hvals() { - Map hash = new LinkedHashMap(); - hash.put("bar", "car"); - hash.put("car", "bar"); - jedis.hmset("foo", hash); + Map hash = new LinkedHashMap(); + hash.put("bar", "car"); + hash.put("car", "bar"); + jedis.hmset("foo", hash); - List vals = jedis.hvals("foo"); - assertEquals(2, vals.size()); - assertTrue(vals.contains("bar")); - assertTrue(vals.contains("car")); + List vals = jedis.hvals("foo"); + assertEquals(2, vals.size()); + assertTrue(vals.contains("bar")); + assertTrue(vals.contains("car")); - // Binary - Map bhash = new LinkedHashMap(); - bhash.put(bbar, bcar); - bhash.put(bcar, bbar); - jedis.hmset(bfoo, bhash); + // Binary + Map bhash = new LinkedHashMap(); + bhash.put(bbar, bcar); + bhash.put(bcar, bbar); + jedis.hmset(bfoo, bhash); - List bvals = jedis.hvals(bfoo); + List bvals = jedis.hvals(bfoo); - assertEquals(2, bvals.size()); - assertTrue(arrayContains(bvals, bbar)); - assertTrue(arrayContains(bvals, bcar)); + assertEquals(2, bvals.size()); + assertTrue(arrayContains(bvals, bbar)); + assertTrue(arrayContains(bvals, bcar)); } @Test public void hgetAll() { - Map h = new HashMap(); - h.put("bar", "car"); - h.put("car", "bar"); - jedis.hmset("foo", h); + Map h = new HashMap(); + h.put("bar", "car"); + h.put("car", "bar"); + jedis.hmset("foo", h); - Map hash = jedis.hgetAll("foo"); - assertEquals(2, hash.size()); - assertEquals("car", hash.get("bar")); - assertEquals("bar", hash.get("car")); + Map hash = jedis.hgetAll("foo"); + assertEquals(2, hash.size()); + assertEquals("car", hash.get("bar")); + assertEquals("bar", hash.get("car")); - // Binary - Map bh = new HashMap(); - bh.put(bbar, bcar); - bh.put(bcar, bbar); - jedis.hmset(bfoo, bh); - Map bhash = jedis.hgetAll(bfoo); + // Binary + Map bh = new HashMap(); + bh.put(bbar, bcar); + bh.put(bcar, bbar); + jedis.hmset(bfoo, bh); + Map bhash = jedis.hgetAll(bfoo); - assertEquals(2, bhash.size()); - assertArrayEquals(bcar, bhash.get(bbar)); - assertArrayEquals(bbar, bhash.get(bcar)); + assertEquals(2, bhash.size()); + assertArrayEquals(bcar, bhash.get(bbar)); + assertArrayEquals(bbar, bhash.get(bcar)); } @Test public void hgetAllPipeline() { - Map bh = new HashMap(); - bh.put(bbar, bcar); - bh.put(bcar, bbar); - jedis.hmset(bfoo, bh); - Pipeline pipeline = jedis.pipelined(); - Response> bhashResponse = pipeline.hgetAll(bfoo); - pipeline.sync(); - Map bhash = bhashResponse.get(); + Map bh = new HashMap(); + bh.put(bbar, bcar); + bh.put(bcar, bbar); + jedis.hmset(bfoo, bh); + Pipeline pipeline = jedis.pipelined(); + Response> bhashResponse = pipeline.hgetAll(bfoo); + pipeline.sync(); + Map bhash = bhashResponse.get(); - assertEquals(2, bhash.size()); - assertArrayEquals(bcar, bhash.get(bbar)); - assertArrayEquals(bbar, bhash.get(bcar)); + assertEquals(2, bhash.size()); + assertArrayEquals(bcar, bhash.get(bbar)); + assertArrayEquals(bbar, bhash.get(bcar)); } @Test public void hscan() { - jedis.hset("foo", "b", "b"); - jedis.hset("foo", "a", "a"); + jedis.hset("foo", "b", "b"); + jedis.hset("foo", "a", "a"); - ScanResult> result = jedis.hscan("foo", - SCAN_POINTER_START); + ScanResult> result = jedis.hscan("foo", + SCAN_POINTER_START); - assertEquals(SCAN_POINTER_START, result.getCursor()); - assertFalse(result.getResult().isEmpty()); + assertEquals(SCAN_POINTER_START, result.getCursor()); + assertFalse(result.getResult().isEmpty()); - // binary - jedis.hset(bfoo, bbar, bcar); + // binary + jedis.hset(bfoo, bbar, bcar); - ScanResult> bResult = jedis.hscan(bfoo, - SCAN_POINTER_START_BINARY); + ScanResult> bResult = jedis.hscan(bfoo, + SCAN_POINTER_START_BINARY); - assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes()); - assertFalse(bResult.getResult().isEmpty()); + assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes()); + assertFalse(bResult.getResult().isEmpty()); } @Test public void hscanMatch() { - ScanParams params = new ScanParams(); - params.match("a*"); + ScanParams params = new ScanParams(); + params.match("a*"); - jedis.hset("foo", "b", "b"); - jedis.hset("foo", "a", "a"); - jedis.hset("foo", "aa", "aa"); - ScanResult> result = jedis.hscan("foo", - SCAN_POINTER_START, params); + jedis.hset("foo", "b", "b"); + jedis.hset("foo", "a", "a"); + jedis.hset("foo", "aa", "aa"); + ScanResult> result = jedis.hscan("foo", + SCAN_POINTER_START, params); - assertEquals(SCAN_POINTER_START, result.getCursor()); - assertFalse(result.getResult().isEmpty()); + assertEquals(SCAN_POINTER_START, result.getCursor()); + assertFalse(result.getResult().isEmpty()); - // binary - params = new ScanParams(); - params.match(bbarstar); + // binary + params = new ScanParams(); + params.match(bbarstar); - jedis.hset(bfoo, bbar, bcar); - jedis.hset(bfoo, bbar1, bcar); - jedis.hset(bfoo, bbar2, bcar); - jedis.hset(bfoo, bbar3, bcar); + jedis.hset(bfoo, bbar, bcar); + jedis.hset(bfoo, bbar1, bcar); + jedis.hset(bfoo, bbar2, bcar); + jedis.hset(bfoo, bbar3, bcar); - ScanResult> bResult = jedis.hscan(bfoo, - SCAN_POINTER_START_BINARY, params); + ScanResult> bResult = jedis.hscan(bfoo, + SCAN_POINTER_START_BINARY, params); - assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes()); - assertFalse(bResult.getResult().isEmpty()); + assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes()); + assertFalse(bResult.getResult().isEmpty()); } @Test public void hscanCount() { - ScanParams params = new ScanParams(); - params.count(2); + ScanParams params = new ScanParams(); + params.count(2); - for (int i = 0; i < 10; i++) { - jedis.hset("foo", "a" + i, "a" + i); - } + for (int i = 0; i < 10; i++) { + jedis.hset("foo", "a" + i, "a" + i); + } - ScanResult> result = jedis.hscan("foo", - SCAN_POINTER_START, params); + ScanResult> result = jedis.hscan("foo", + SCAN_POINTER_START, params); - assertFalse(result.getResult().isEmpty()); + assertFalse(result.getResult().isEmpty()); - // binary - params = new ScanParams(); - params.count(2); + // binary + params = new ScanParams(); + params.count(2); - jedis.hset(bfoo, bbar, bcar); - jedis.hset(bfoo, bbar1, bcar); - jedis.hset(bfoo, bbar2, bcar); - jedis.hset(bfoo, bbar3, bcar); + jedis.hset(bfoo, bbar, bcar); + jedis.hset(bfoo, bbar1, bcar); + jedis.hset(bfoo, bbar2, bcar); + jedis.hset(bfoo, bbar3, bcar); - ScanResult> bResult = jedis.hscan(bfoo, - SCAN_POINTER_START_BINARY, params); + ScanResult> bResult = jedis.hscan(bfoo, + SCAN_POINTER_START_BINARY, params); - assertFalse(bResult.getResult().isEmpty()); + assertFalse(bResult.getResult().isEmpty()); } } diff --git a/src/test/java/redis/clients/jedis/tests/commands/HyperLogLogCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/HyperLogLogCommandsTest.java index 77d42da..962a5b7 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/HyperLogLogCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/HyperLogLogCommandsTest.java @@ -8,122 +8,122 @@ public class HyperLogLogCommandsTest extends JedisCommandTestBase { @Test public void pfadd() { - long status = jedis.pfadd("foo", "a"); - assertEquals(1, status); + long status = jedis.pfadd("foo", "a"); + assertEquals(1, status); - status = jedis.pfadd("foo", "a"); - assertEquals(0, status); + status = jedis.pfadd("foo", "a"); + assertEquals(0, status); } @Test public void pfaddBinary() { - byte[] bFoo = SafeEncoder.encode("foo"); - byte[] bBar = SafeEncoder.encode("bar"); - byte[] bBar2 = SafeEncoder.encode("bar2"); + byte[] bFoo = SafeEncoder.encode("foo"); + byte[] bBar = SafeEncoder.encode("bar"); + byte[] bBar2 = SafeEncoder.encode("bar2"); - long status = jedis.pfadd(bFoo, bBar, bBar2); - assertEquals(1, status); + long status = jedis.pfadd(bFoo, bBar, bBar2); + assertEquals(1, status); - status = jedis.pfadd(bFoo, bBar, bBar2); - assertEquals(0, status); + status = jedis.pfadd(bFoo, bBar, bBar2); + assertEquals(0, status); } @Test public void pfcount() { - long status = jedis.pfadd("hll", "foo", "bar", "zap"); - assertEquals(1, status); + long status = jedis.pfadd("hll", "foo", "bar", "zap"); + assertEquals(1, status); - status = jedis.pfadd("hll", "zap", "zap", "zap"); - assertEquals(0, status); + status = jedis.pfadd("hll", "zap", "zap", "zap"); + assertEquals(0, status); - status = jedis.pfadd("hll", "foo", "bar"); - assertEquals(0, status); + status = jedis.pfadd("hll", "foo", "bar"); + assertEquals(0, status); - status = jedis.pfcount("hll"); - assertEquals(3, status); + status = jedis.pfcount("hll"); + assertEquals(3, status); } @Test public void pfcounts() { - long status = jedis.pfadd("hll_1", "foo", "bar", "zap"); - assertEquals(1, status); - status = jedis.pfadd("hll_2", "foo", "bar", "zap"); - assertEquals(1, status); + long status = jedis.pfadd("hll_1", "foo", "bar", "zap"); + assertEquals(1, status); + status = jedis.pfadd("hll_2", "foo", "bar", "zap"); + assertEquals(1, status); - status = jedis.pfadd("hll_3", "foo", "bar", "baz"); - assertEquals(1, status); - status = jedis.pfcount("hll_1"); - assertEquals(3, status); - status = jedis.pfcount("hll_2"); - assertEquals(3, status); - status = jedis.pfcount("hll_3"); - assertEquals(3, status); + status = jedis.pfadd("hll_3", "foo", "bar", "baz"); + assertEquals(1, status); + status = jedis.pfcount("hll_1"); + assertEquals(3, status); + status = jedis.pfcount("hll_2"); + assertEquals(3, status); + status = jedis.pfcount("hll_3"); + assertEquals(3, status); - status = jedis.pfcount("hll_1", "hll_2"); - assertEquals(3, status); + status = jedis.pfcount("hll_1", "hll_2"); + assertEquals(3, status); - status = jedis.pfcount("hll_1", "hll_2", "hll_3"); - assertEquals(4, status); + status = jedis.pfcount("hll_1", "hll_2", "hll_3"); + assertEquals(4, status); } @Test public void pfcountBinary() { - byte[] bHll = SafeEncoder.encode("hll"); - byte[] bFoo = SafeEncoder.encode("foo"); - byte[] bBar = SafeEncoder.encode("bar"); - byte[] bZap = SafeEncoder.encode("zap"); + byte[] bHll = SafeEncoder.encode("hll"); + byte[] bFoo = SafeEncoder.encode("foo"); + byte[] bBar = SafeEncoder.encode("bar"); + byte[] bZap = SafeEncoder.encode("zap"); - long status = jedis.pfadd(bHll, bFoo, bBar, bZap); - assertEquals(1, status); + long status = jedis.pfadd(bHll, bFoo, bBar, bZap); + assertEquals(1, status); - status = jedis.pfadd(bHll, bZap, bZap, bZap); - assertEquals(0, status); + status = jedis.pfadd(bHll, bZap, bZap, bZap); + assertEquals(0, status); - status = jedis.pfadd(bHll, bFoo, bBar); - assertEquals(0, status); + status = jedis.pfadd(bHll, bFoo, bBar); + assertEquals(0, status); - status = jedis.pfcount(bHll); - assertEquals(3, status); + status = jedis.pfcount(bHll); + assertEquals(3, status); } @Test public void pfmerge() { - long status = jedis.pfadd("hll1", "foo", "bar", "zap", "a"); - assertEquals(1, status); + long status = jedis.pfadd("hll1", "foo", "bar", "zap", "a"); + assertEquals(1, status); - status = jedis.pfadd("hll2", "a", "b", "c", "foo"); - assertEquals(1, status); + status = jedis.pfadd("hll2", "a", "b", "c", "foo"); + assertEquals(1, status); - String mergeStatus = jedis.pfmerge("hll3", "hll1", "hll2"); - assertEquals("OK", mergeStatus); + String mergeStatus = jedis.pfmerge("hll3", "hll1", "hll2"); + assertEquals("OK", mergeStatus); - status = jedis.pfcount("hll3"); - assertEquals(6, status); + status = jedis.pfcount("hll3"); + assertEquals(6, status); } @Test public void pfmergeBinary() { - byte[] bHll1 = SafeEncoder.encode("hll1"); - byte[] bHll2 = SafeEncoder.encode("hll2"); - byte[] bHll3 = SafeEncoder.encode("hll3"); - byte[] bFoo = SafeEncoder.encode("foo"); - byte[] bBar = SafeEncoder.encode("bar"); - byte[] bZap = SafeEncoder.encode("zap"); - byte[] bA = SafeEncoder.encode("a"); - byte[] bB = SafeEncoder.encode("b"); - byte[] bC = SafeEncoder.encode("c"); + byte[] bHll1 = SafeEncoder.encode("hll1"); + byte[] bHll2 = SafeEncoder.encode("hll2"); + byte[] bHll3 = SafeEncoder.encode("hll3"); + byte[] bFoo = SafeEncoder.encode("foo"); + byte[] bBar = SafeEncoder.encode("bar"); + byte[] bZap = SafeEncoder.encode("zap"); + byte[] bA = SafeEncoder.encode("a"); + byte[] bB = SafeEncoder.encode("b"); + byte[] bC = SafeEncoder.encode("c"); - long status = jedis.pfadd(bHll1, bFoo, bBar, bZap, bA); - assertEquals(1, status); + long status = jedis.pfadd(bHll1, bFoo, bBar, bZap, bA); + assertEquals(1, status); - status = jedis.pfadd(bHll2, bA, bB, bC, bFoo); - assertEquals(1, status); + status = jedis.pfadd(bHll2, bA, bB, bC, bFoo); + assertEquals(1, status); - String mergeStatus = jedis.pfmerge(bHll3, bHll1, bHll2); - assertEquals("OK", mergeStatus); + String mergeStatus = jedis.pfmerge(bHll3, bHll1, bHll2); + assertEquals("OK", mergeStatus); - status = jedis.pfcount("hll3"); - assertEquals(6, status); + status = jedis.pfcount("hll3"); + assertEquals(6, status); } } diff --git a/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java b/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java index c6f8d69..79ed013 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java +++ b/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java @@ -20,77 +20,77 @@ public abstract class JedisCommandTestBase extends JedisTestBase { protected Jedis jedis; public JedisCommandTestBase() { - super(); + super(); } @Before public void setUp() throws Exception { - jedis = new Jedis(hnp.getHost(), hnp.getPort(), 500); - jedis.connect(); - jedis.auth("foobared"); - jedis.configSet("timeout", "300"); - jedis.flushAll(); + jedis = new Jedis(hnp.getHost(), hnp.getPort(), 500); + jedis.connect(); + jedis.auth("foobared"); + jedis.configSet("timeout", "300"); + jedis.flushAll(); } @After public void tearDown() { - jedis.disconnect(); + jedis.disconnect(); } protected Jedis createJedis() { - Jedis j = new Jedis(hnp.getHost(), hnp.getPort()); - j.connect(); - j.auth("foobared"); - j.flushAll(); - return j; + Jedis j = new Jedis(hnp.getHost(), hnp.getPort()); + j.connect(); + j.auth("foobared"); + j.flushAll(); + return j; } protected void assertEquals(List expected, List actual) { - assertEquals(expected.size(), actual.size()); - for (int n = 0; n < expected.size(); n++) { - assertArrayEquals(expected.get(n), actual.get(n)); - } + assertEquals(expected.size(), actual.size()); + for (int n = 0; n < expected.size(); n++) { + assertArrayEquals(expected.get(n), actual.get(n)); + } } protected void assertEquals(Set expected, Set actual) { - assertEquals(expected.size(), actual.size()); - Iterator e = expected.iterator(); - while (e.hasNext()) { - byte[] next = e.next(); - boolean contained = false; - for (byte[] element : expected) { - if (Arrays.equals(next, element)) { - contained = true; - } - } - if (!contained) { - throw new ComparisonFailure("element is missing", - Arrays.toString(next), actual.toString()); - } - } + assertEquals(expected.size(), actual.size()); + Iterator e = expected.iterator(); + while (e.hasNext()) { + byte[] next = e.next(); + boolean contained = false; + for (byte[] element : expected) { + if (Arrays.equals(next, element)) { + contained = true; + } + } + if (!contained) { + throw new ComparisonFailure("element is missing", + Arrays.toString(next), actual.toString()); + } + } } protected boolean arrayContains(List array, byte[] expected) { - for (byte[] a : array) { - try { - assertArrayEquals(a, expected); - return true; - } catch (AssertionError e) { + for (byte[] a : array) { + try { + assertArrayEquals(a, expected); + return true; + } catch (AssertionError e) { - } - } - return false; + } + } + return false; } protected boolean setContains(Set set, byte[] expected) { - for (byte[] a : set) { - try { - assertArrayEquals(a, expected); - return true; - } catch (AssertionError e) { + for (byte[] a : set) { + try { + assertArrayEquals(a, expected); + return true; + } catch (AssertionError e) { - } - } - return false; + } + } + return false; } } diff --git a/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java index ce157d8..0fa4641 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java @@ -26,559 +26,559 @@ public class ListCommandsTest extends JedisCommandTestBase { @Test public void rpush() { - long size = jedis.rpush("foo", "bar"); - assertEquals(1, size); - size = jedis.rpush("foo", "foo"); - assertEquals(2, size); - size = jedis.rpush("foo", "bar", "foo"); - assertEquals(4, size); + long size = jedis.rpush("foo", "bar"); + assertEquals(1, size); + size = jedis.rpush("foo", "foo"); + assertEquals(2, size); + size = jedis.rpush("foo", "bar", "foo"); + assertEquals(4, size); - // Binary - long bsize = jedis.rpush(bfoo, bbar); - assertEquals(1, bsize); - bsize = jedis.rpush(bfoo, bfoo); - assertEquals(2, bsize); - bsize = jedis.rpush(bfoo, bbar, bfoo); - assertEquals(4, bsize); + // Binary + long bsize = jedis.rpush(bfoo, bbar); + assertEquals(1, bsize); + bsize = jedis.rpush(bfoo, bfoo); + assertEquals(2, bsize); + bsize = jedis.rpush(bfoo, bbar, bfoo); + assertEquals(4, bsize); } @Test public void lpush() { - long size = jedis.lpush("foo", "bar"); - assertEquals(1, size); - size = jedis.lpush("foo", "foo"); - assertEquals(2, size); - size = jedis.lpush("foo", "bar", "foo"); - assertEquals(4, size); + long size = jedis.lpush("foo", "bar"); + assertEquals(1, size); + size = jedis.lpush("foo", "foo"); + assertEquals(2, size); + size = jedis.lpush("foo", "bar", "foo"); + assertEquals(4, size); - // Binary - long bsize = jedis.lpush(bfoo, bbar); - assertEquals(1, bsize); - bsize = jedis.lpush(bfoo, bfoo); - assertEquals(2, bsize); - bsize = jedis.lpush(bfoo, bbar, bfoo); - assertEquals(4, bsize); + // Binary + long bsize = jedis.lpush(bfoo, bbar); + assertEquals(1, bsize); + bsize = jedis.lpush(bfoo, bfoo); + assertEquals(2, bsize); + bsize = jedis.lpush(bfoo, bbar, bfoo); + assertEquals(4, bsize); } @Test public void llen() { - assertEquals(0, jedis.llen("foo").intValue()); - jedis.lpush("foo", "bar"); - jedis.lpush("foo", "car"); - assertEquals(2, jedis.llen("foo").intValue()); + assertEquals(0, jedis.llen("foo").intValue()); + jedis.lpush("foo", "bar"); + jedis.lpush("foo", "car"); + assertEquals(2, jedis.llen("foo").intValue()); - // Binary - assertEquals(0, jedis.llen(bfoo).intValue()); - jedis.lpush(bfoo, bbar); - jedis.lpush(bfoo, bcar); - assertEquals(2, jedis.llen(bfoo).intValue()); + // Binary + assertEquals(0, jedis.llen(bfoo).intValue()); + jedis.lpush(bfoo, bbar); + jedis.lpush(bfoo, bcar); + assertEquals(2, jedis.llen(bfoo).intValue()); } @Test public void llenNotOnList() { - try { - jedis.set("foo", "bar"); - jedis.llen("foo"); - fail("JedisDataException expected"); - } catch (final JedisDataException e) { - } + try { + jedis.set("foo", "bar"); + jedis.llen("foo"); + fail("JedisDataException expected"); + } catch (final JedisDataException e) { + } - // Binary - try { - jedis.set(bfoo, bbar); - jedis.llen(bfoo); - fail("JedisDataException expected"); - } catch (final JedisDataException e) { - } + // Binary + try { + jedis.set(bfoo, bbar); + jedis.llen(bfoo); + fail("JedisDataException expected"); + } catch (final JedisDataException e) { + } } @Test public void lrange() { - jedis.rpush("foo", "a"); - jedis.rpush("foo", "b"); - jedis.rpush("foo", "c"); + jedis.rpush("foo", "a"); + jedis.rpush("foo", "b"); + jedis.rpush("foo", "c"); - List expected = new ArrayList(); - expected.add("a"); - expected.add("b"); - expected.add("c"); + List expected = new ArrayList(); + expected.add("a"); + expected.add("b"); + expected.add("c"); - List range = jedis.lrange("foo", 0, 2); - assertEquals(expected, range); + List range = jedis.lrange("foo", 0, 2); + assertEquals(expected, range); - range = jedis.lrange("foo", 0, 20); - assertEquals(expected, range); + range = jedis.lrange("foo", 0, 20); + assertEquals(expected, range); - expected = new ArrayList(); - expected.add("b"); - expected.add("c"); + expected = new ArrayList(); + expected.add("b"); + expected.add("c"); - range = jedis.lrange("foo", 1, 2); - assertEquals(expected, range); + range = jedis.lrange("foo", 1, 2); + assertEquals(expected, range); - expected = new ArrayList(); - range = jedis.lrange("foo", 2, 1); - assertEquals(expected, range); + expected = new ArrayList(); + range = jedis.lrange("foo", 2, 1); + assertEquals(expected, range); - // Binary - jedis.rpush(bfoo, bA); - jedis.rpush(bfoo, bB); - jedis.rpush(bfoo, bC); + // Binary + jedis.rpush(bfoo, bA); + jedis.rpush(bfoo, bB); + jedis.rpush(bfoo, bC); - List bexpected = new ArrayList(); - bexpected.add(bA); - bexpected.add(bB); - bexpected.add(bC); + List bexpected = new ArrayList(); + bexpected.add(bA); + bexpected.add(bB); + bexpected.add(bC); - List brange = jedis.lrange(bfoo, 0, 2); - assertEquals(bexpected, brange); + List brange = jedis.lrange(bfoo, 0, 2); + assertEquals(bexpected, brange); - brange = jedis.lrange(bfoo, 0, 20); - assertEquals(bexpected, brange); + brange = jedis.lrange(bfoo, 0, 20); + assertEquals(bexpected, brange); - bexpected = new ArrayList(); - bexpected.add(bB); - bexpected.add(bC); + bexpected = new ArrayList(); + bexpected.add(bB); + bexpected.add(bC); - brange = jedis.lrange(bfoo, 1, 2); - assertEquals(bexpected, brange); + brange = jedis.lrange(bfoo, 1, 2); + assertEquals(bexpected, brange); - bexpected = new ArrayList(); - brange = jedis.lrange(bfoo, 2, 1); - assertEquals(bexpected, brange); + bexpected = new ArrayList(); + brange = jedis.lrange(bfoo, 2, 1); + assertEquals(bexpected, brange); } @Test public void ltrim() { - jedis.lpush("foo", "1"); - jedis.lpush("foo", "2"); - jedis.lpush("foo", "3"); - String status = jedis.ltrim("foo", 0, 1); + jedis.lpush("foo", "1"); + jedis.lpush("foo", "2"); + jedis.lpush("foo", "3"); + String status = jedis.ltrim("foo", 0, 1); - List expected = new ArrayList(); - expected.add("3"); - expected.add("2"); + List expected = new ArrayList(); + expected.add("3"); + expected.add("2"); - assertEquals("OK", status); - assertEquals(2, jedis.llen("foo").intValue()); - assertEquals(expected, jedis.lrange("foo", 0, 100)); + assertEquals("OK", status); + assertEquals(2, jedis.llen("foo").intValue()); + assertEquals(expected, jedis.lrange("foo", 0, 100)); - // Binary - jedis.lpush(bfoo, b1); - jedis.lpush(bfoo, b2); - jedis.lpush(bfoo, b3); - String bstatus = jedis.ltrim(bfoo, 0, 1); + // Binary + jedis.lpush(bfoo, b1); + jedis.lpush(bfoo, b2); + jedis.lpush(bfoo, b3); + String bstatus = jedis.ltrim(bfoo, 0, 1); - List bexpected = new ArrayList(); - bexpected.add(b3); - bexpected.add(b2); + List bexpected = new ArrayList(); + bexpected.add(b3); + bexpected.add(b2); - assertEquals("OK", bstatus); - assertEquals(2, jedis.llen(bfoo).intValue()); - assertEquals(bexpected, jedis.lrange(bfoo, 0, 100)); + assertEquals("OK", bstatus); + assertEquals(2, jedis.llen(bfoo).intValue()); + assertEquals(bexpected, jedis.lrange(bfoo, 0, 100)); } @Test public void lindex() { - jedis.lpush("foo", "1"); - jedis.lpush("foo", "2"); - jedis.lpush("foo", "3"); + jedis.lpush("foo", "1"); + jedis.lpush("foo", "2"); + jedis.lpush("foo", "3"); - List expected = new ArrayList(); - expected.add("3"); - expected.add("bar"); - expected.add("1"); + List expected = new ArrayList(); + expected.add("3"); + expected.add("bar"); + expected.add("1"); - String status = jedis.lset("foo", 1, "bar"); + String status = jedis.lset("foo", 1, "bar"); - assertEquals("OK", status); - assertEquals(expected, jedis.lrange("foo", 0, 100)); + assertEquals("OK", status); + assertEquals(expected, jedis.lrange("foo", 0, 100)); - // Binary - jedis.lpush(bfoo, b1); - jedis.lpush(bfoo, b2); - jedis.lpush(bfoo, b3); + // Binary + jedis.lpush(bfoo, b1); + jedis.lpush(bfoo, b2); + jedis.lpush(bfoo, b3); - List bexpected = new ArrayList(); - bexpected.add(b3); - bexpected.add(bbar); - bexpected.add(b1); + List bexpected = new ArrayList(); + bexpected.add(b3); + bexpected.add(bbar); + bexpected.add(b1); - String bstatus = jedis.lset(bfoo, 1, bbar); + String bstatus = jedis.lset(bfoo, 1, bbar); - assertEquals("OK", bstatus); - assertEquals(bexpected, jedis.lrange(bfoo, 0, 100)); + assertEquals("OK", bstatus); + assertEquals(bexpected, jedis.lrange(bfoo, 0, 100)); } @Test public void lset() { - jedis.lpush("foo", "1"); - jedis.lpush("foo", "2"); - jedis.lpush("foo", "3"); + jedis.lpush("foo", "1"); + jedis.lpush("foo", "2"); + jedis.lpush("foo", "3"); - assertEquals("3", jedis.lindex("foo", 0)); - assertEquals(null, jedis.lindex("foo", 100)); + assertEquals("3", jedis.lindex("foo", 0)); + assertEquals(null, jedis.lindex("foo", 100)); - // Binary - jedis.lpush(bfoo, b1); - jedis.lpush(bfoo, b2); - jedis.lpush(bfoo, b3); + // Binary + jedis.lpush(bfoo, b1); + jedis.lpush(bfoo, b2); + jedis.lpush(bfoo, b3); - assertArrayEquals(b3, jedis.lindex(bfoo, 0)); - assertEquals(null, jedis.lindex(bfoo, 100)); + assertArrayEquals(b3, jedis.lindex(bfoo, 0)); + assertEquals(null, jedis.lindex(bfoo, 100)); } @Test public void lrem() { - jedis.lpush("foo", "hello"); - jedis.lpush("foo", "hello"); - jedis.lpush("foo", "x"); - jedis.lpush("foo", "hello"); - jedis.lpush("foo", "c"); - jedis.lpush("foo", "b"); - jedis.lpush("foo", "a"); + jedis.lpush("foo", "hello"); + jedis.lpush("foo", "hello"); + jedis.lpush("foo", "x"); + jedis.lpush("foo", "hello"); + jedis.lpush("foo", "c"); + jedis.lpush("foo", "b"); + jedis.lpush("foo", "a"); - long count = jedis.lrem("foo", -2, "hello"); + long count = jedis.lrem("foo", -2, "hello"); - List expected = new ArrayList(); - expected.add("a"); - expected.add("b"); - expected.add("c"); - expected.add("hello"); - expected.add("x"); + List expected = new ArrayList(); + expected.add("a"); + expected.add("b"); + expected.add("c"); + expected.add("hello"); + expected.add("x"); - assertEquals(2, count); - assertEquals(expected, jedis.lrange("foo", 0, 1000)); - assertEquals(0, jedis.lrem("bar", 100, "foo").intValue()); + assertEquals(2, count); + assertEquals(expected, jedis.lrange("foo", 0, 1000)); + assertEquals(0, jedis.lrem("bar", 100, "foo").intValue()); - // Binary - jedis.lpush(bfoo, bhello); - jedis.lpush(bfoo, bhello); - jedis.lpush(bfoo, bx); - jedis.lpush(bfoo, bhello); - jedis.lpush(bfoo, bC); - jedis.lpush(bfoo, bB); - jedis.lpush(bfoo, bA); + // Binary + jedis.lpush(bfoo, bhello); + jedis.lpush(bfoo, bhello); + jedis.lpush(bfoo, bx); + jedis.lpush(bfoo, bhello); + jedis.lpush(bfoo, bC); + jedis.lpush(bfoo, bB); + jedis.lpush(bfoo, bA); - long bcount = jedis.lrem(bfoo, -2, bhello); + long bcount = jedis.lrem(bfoo, -2, bhello); - List bexpected = new ArrayList(); - bexpected.add(bA); - bexpected.add(bB); - bexpected.add(bC); - bexpected.add(bhello); - bexpected.add(bx); + List bexpected = new ArrayList(); + bexpected.add(bA); + bexpected.add(bB); + bexpected.add(bC); + bexpected.add(bhello); + bexpected.add(bx); - assertEquals(2, bcount); - assertEquals(bexpected, jedis.lrange(bfoo, 0, 1000)); - assertEquals(0, jedis.lrem(bbar, 100, bfoo).intValue()); + assertEquals(2, bcount); + assertEquals(bexpected, jedis.lrange(bfoo, 0, 1000)); + assertEquals(0, jedis.lrem(bbar, 100, bfoo).intValue()); } @Test public void lpop() { - jedis.rpush("foo", "a"); - jedis.rpush("foo", "b"); - jedis.rpush("foo", "c"); + jedis.rpush("foo", "a"); + jedis.rpush("foo", "b"); + jedis.rpush("foo", "c"); - String element = jedis.lpop("foo"); - assertEquals("a", element); + String element = jedis.lpop("foo"); + assertEquals("a", element); - List expected = new ArrayList(); - expected.add("b"); - expected.add("c"); + List expected = new ArrayList(); + expected.add("b"); + expected.add("c"); - assertEquals(expected, jedis.lrange("foo", 0, 1000)); - jedis.lpop("foo"); - jedis.lpop("foo"); + assertEquals(expected, jedis.lrange("foo", 0, 1000)); + jedis.lpop("foo"); + jedis.lpop("foo"); - element = jedis.lpop("foo"); - assertEquals(null, element); + element = jedis.lpop("foo"); + assertEquals(null, element); - // Binary - jedis.rpush(bfoo, bA); - jedis.rpush(bfoo, bB); - jedis.rpush(bfoo, bC); + // Binary + jedis.rpush(bfoo, bA); + jedis.rpush(bfoo, bB); + jedis.rpush(bfoo, bC); - byte[] belement = jedis.lpop(bfoo); - assertArrayEquals(bA, belement); + byte[] belement = jedis.lpop(bfoo); + assertArrayEquals(bA, belement); - List bexpected = new ArrayList(); - bexpected.add(bB); - bexpected.add(bC); + List bexpected = new ArrayList(); + bexpected.add(bB); + bexpected.add(bC); - assertEquals(bexpected, jedis.lrange(bfoo, 0, 1000)); - jedis.lpop(bfoo); - jedis.lpop(bfoo); + assertEquals(bexpected, jedis.lrange(bfoo, 0, 1000)); + jedis.lpop(bfoo); + jedis.lpop(bfoo); - belement = jedis.lpop(bfoo); - assertEquals(null, belement); + belement = jedis.lpop(bfoo); + assertEquals(null, belement); } @Test public void rpop() { - jedis.rpush("foo", "a"); - jedis.rpush("foo", "b"); - jedis.rpush("foo", "c"); + jedis.rpush("foo", "a"); + jedis.rpush("foo", "b"); + jedis.rpush("foo", "c"); - String element = jedis.rpop("foo"); - assertEquals("c", element); + String element = jedis.rpop("foo"); + assertEquals("c", element); - List expected = new ArrayList(); - expected.add("a"); - expected.add("b"); + List expected = new ArrayList(); + expected.add("a"); + expected.add("b"); - assertEquals(expected, jedis.lrange("foo", 0, 1000)); - jedis.rpop("foo"); - jedis.rpop("foo"); + assertEquals(expected, jedis.lrange("foo", 0, 1000)); + jedis.rpop("foo"); + jedis.rpop("foo"); - element = jedis.rpop("foo"); - assertEquals(null, element); + element = jedis.rpop("foo"); + assertEquals(null, element); - // Binary - jedis.rpush(bfoo, bA); - jedis.rpush(bfoo, bB); - jedis.rpush(bfoo, bC); + // Binary + jedis.rpush(bfoo, bA); + jedis.rpush(bfoo, bB); + jedis.rpush(bfoo, bC); - byte[] belement = jedis.rpop(bfoo); - assertArrayEquals(bC, belement); + byte[] belement = jedis.rpop(bfoo); + assertArrayEquals(bC, belement); - List bexpected = new ArrayList(); - bexpected.add(bA); - bexpected.add(bB); + List bexpected = new ArrayList(); + bexpected.add(bA); + bexpected.add(bB); - assertEquals(bexpected, jedis.lrange(bfoo, 0, 1000)); - jedis.rpop(bfoo); - jedis.rpop(bfoo); + assertEquals(bexpected, jedis.lrange(bfoo, 0, 1000)); + jedis.rpop(bfoo); + jedis.rpop(bfoo); - belement = jedis.rpop(bfoo); - assertEquals(null, belement); + belement = jedis.rpop(bfoo); + assertEquals(null, belement); } @Test public void rpoplpush() { - jedis.rpush("foo", "a"); - jedis.rpush("foo", "b"); - jedis.rpush("foo", "c"); + jedis.rpush("foo", "a"); + jedis.rpush("foo", "b"); + jedis.rpush("foo", "c"); - jedis.rpush("dst", "foo"); - jedis.rpush("dst", "bar"); + jedis.rpush("dst", "foo"); + jedis.rpush("dst", "bar"); - String element = jedis.rpoplpush("foo", "dst"); + String element = jedis.rpoplpush("foo", "dst"); - assertEquals("c", element); + assertEquals("c", element); - List srcExpected = new ArrayList(); - srcExpected.add("a"); - srcExpected.add("b"); + List srcExpected = new ArrayList(); + srcExpected.add("a"); + srcExpected.add("b"); - List dstExpected = new ArrayList(); - dstExpected.add("c"); - dstExpected.add("foo"); - dstExpected.add("bar"); + List dstExpected = new ArrayList(); + dstExpected.add("c"); + dstExpected.add("foo"); + dstExpected.add("bar"); - assertEquals(srcExpected, jedis.lrange("foo", 0, 1000)); - assertEquals(dstExpected, jedis.lrange("dst", 0, 1000)); + assertEquals(srcExpected, jedis.lrange("foo", 0, 1000)); + assertEquals(dstExpected, jedis.lrange("dst", 0, 1000)); - // Binary - jedis.rpush(bfoo, bA); - jedis.rpush(bfoo, bB); - jedis.rpush(bfoo, bC); + // Binary + jedis.rpush(bfoo, bA); + jedis.rpush(bfoo, bB); + jedis.rpush(bfoo, bC); - jedis.rpush(bdst, bfoo); - jedis.rpush(bdst, bbar); + jedis.rpush(bdst, bfoo); + jedis.rpush(bdst, bbar); - byte[] belement = jedis.rpoplpush(bfoo, bdst); + byte[] belement = jedis.rpoplpush(bfoo, bdst); - assertArrayEquals(bC, belement); + assertArrayEquals(bC, belement); - List bsrcExpected = new ArrayList(); - bsrcExpected.add(bA); - bsrcExpected.add(bB); + List bsrcExpected = new ArrayList(); + bsrcExpected.add(bA); + bsrcExpected.add(bB); - List bdstExpected = new ArrayList(); - bdstExpected.add(bC); - bdstExpected.add(bfoo); - bdstExpected.add(bbar); + List bdstExpected = new ArrayList(); + bdstExpected.add(bC); + bdstExpected.add(bfoo); + bdstExpected.add(bbar); - assertEquals(bsrcExpected, jedis.lrange(bfoo, 0, 1000)); - assertEquals(bdstExpected, jedis.lrange(bdst, 0, 1000)); + assertEquals(bsrcExpected, jedis.lrange(bfoo, 0, 1000)); + assertEquals(bdstExpected, jedis.lrange(bdst, 0, 1000)); } @Test public void blpop() throws InterruptedException { - List result = jedis.blpop(1, "foo"); - assertNull(result); + List result = jedis.blpop(1, "foo"); + assertNull(result); - jedis.lpush("foo", "bar"); - result = jedis.blpop(1, "foo"); + jedis.lpush("foo", "bar"); + result = jedis.blpop(1, "foo"); - assertNotNull(result); - assertEquals(2, result.size()); - assertEquals("foo", result.get(0)); - assertEquals("bar", result.get(1)); + assertNotNull(result); + assertEquals(2, result.size()); + assertEquals("foo", result.get(0)); + assertEquals("bar", result.get(1)); - // Binary - jedis.lpush(bfoo, bbar); - List bresult = jedis.blpop(1, bfoo); + // Binary + jedis.lpush(bfoo, bbar); + List bresult = jedis.blpop(1, bfoo); - assertNotNull(bresult); - assertEquals(2, bresult.size()); - assertArrayEquals(bfoo, bresult.get(0)); - assertArrayEquals(bbar, bresult.get(1)); + assertNotNull(bresult); + assertEquals(2, bresult.size()); + assertArrayEquals(bfoo, bresult.get(0)); + assertArrayEquals(bbar, bresult.get(1)); } @Test public void brpop() throws InterruptedException { - List result = jedis.brpop(1, "foo"); - assertNull(result); + List result = jedis.brpop(1, "foo"); + assertNull(result); - jedis.lpush("foo", "bar"); - result = jedis.brpop(1, "foo"); - assertNotNull(result); - assertEquals(2, result.size()); - assertEquals("foo", result.get(0)); - assertEquals("bar", result.get(1)); + jedis.lpush("foo", "bar"); + result = jedis.brpop(1, "foo"); + assertNotNull(result); + assertEquals(2, result.size()); + assertEquals("foo", result.get(0)); + assertEquals("bar", result.get(1)); - // Binary + // Binary - jedis.lpush(bfoo, bbar); - List bresult = jedis.brpop(1, bfoo); - assertNotNull(bresult); - assertEquals(2, bresult.size()); - assertArrayEquals(bfoo, bresult.get(0)); - assertArrayEquals(bbar, bresult.get(1)); + jedis.lpush(bfoo, bbar); + List bresult = jedis.brpop(1, bfoo); + assertNotNull(bresult); + assertEquals(2, bresult.size()); + assertArrayEquals(bfoo, bresult.get(0)); + assertArrayEquals(bbar, bresult.get(1)); } @Test public void lpushx() { - long status = jedis.lpushx("foo", "bar"); - assertEquals(0, status); + long status = jedis.lpushx("foo", "bar"); + assertEquals(0, status); - jedis.lpush("foo", "a"); - status = jedis.lpushx("foo", "b"); - assertEquals(2, status); + jedis.lpush("foo", "a"); + status = jedis.lpushx("foo", "b"); + assertEquals(2, status); - // Binary - long bstatus = jedis.lpushx(bfoo, bbar); - assertEquals(0, bstatus); + // Binary + long bstatus = jedis.lpushx(bfoo, bbar); + assertEquals(0, bstatus); - jedis.lpush(bfoo, bA); - bstatus = jedis.lpushx(bfoo, bB); - assertEquals(2, bstatus); + jedis.lpush(bfoo, bA); + bstatus = jedis.lpushx(bfoo, bB); + assertEquals(2, bstatus); } @Test public void rpushx() { - long status = jedis.rpushx("foo", "bar"); - assertEquals(0, status); + long status = jedis.rpushx("foo", "bar"); + assertEquals(0, status); - jedis.lpush("foo", "a"); - status = jedis.rpushx("foo", "b"); - assertEquals(2, status); + jedis.lpush("foo", "a"); + status = jedis.rpushx("foo", "b"); + assertEquals(2, status); - // Binary - long bstatus = jedis.rpushx(bfoo, bbar); - assertEquals(0, bstatus); + // Binary + long bstatus = jedis.rpushx(bfoo, bbar); + assertEquals(0, bstatus); - jedis.lpush(bfoo, bA); - bstatus = jedis.rpushx(bfoo, bB); - assertEquals(2, bstatus); + jedis.lpush(bfoo, bA); + bstatus = jedis.rpushx(bfoo, bB); + assertEquals(2, bstatus); } @Test public void linsert() { - long status = jedis.linsert("foo", Client.LIST_POSITION.BEFORE, "bar", - "car"); - assertEquals(0, status); + long status = jedis.linsert("foo", Client.LIST_POSITION.BEFORE, "bar", + "car"); + assertEquals(0, status); - jedis.lpush("foo", "a"); - status = jedis.linsert("foo", Client.LIST_POSITION.AFTER, "a", "b"); - assertEquals(2, status); + jedis.lpush("foo", "a"); + status = jedis.linsert("foo", Client.LIST_POSITION.AFTER, "a", "b"); + assertEquals(2, status); - List actual = jedis.lrange("foo", 0, 100); - List expected = new ArrayList(); - expected.add("a"); - expected.add("b"); + List actual = jedis.lrange("foo", 0, 100); + List expected = new ArrayList(); + expected.add("a"); + expected.add("b"); - assertEquals(expected, actual); + assertEquals(expected, actual); - status = jedis - .linsert("foo", Client.LIST_POSITION.BEFORE, "bar", "car"); - assertEquals(-1, status); + status = jedis + .linsert("foo", Client.LIST_POSITION.BEFORE, "bar", "car"); + assertEquals(-1, status); - // Binary - long bstatus = jedis.linsert(bfoo, Client.LIST_POSITION.BEFORE, bbar, - bcar); - assertEquals(0, bstatus); + // Binary + long bstatus = jedis.linsert(bfoo, Client.LIST_POSITION.BEFORE, bbar, + bcar); + assertEquals(0, bstatus); - jedis.lpush(bfoo, bA); - bstatus = jedis.linsert(bfoo, Client.LIST_POSITION.AFTER, bA, bB); - assertEquals(2, bstatus); + jedis.lpush(bfoo, bA); + bstatus = jedis.linsert(bfoo, Client.LIST_POSITION.AFTER, bA, bB); + assertEquals(2, bstatus); - List bactual = jedis.lrange(bfoo, 0, 100); - List bexpected = new ArrayList(); - bexpected.add(bA); - bexpected.add(bB); + List bactual = jedis.lrange(bfoo, 0, 100); + List bexpected = new ArrayList(); + bexpected.add(bA); + bexpected.add(bB); - assertEquals(bexpected, bactual); + assertEquals(bexpected, bactual); - bstatus = jedis.linsert(bfoo, Client.LIST_POSITION.BEFORE, bbar, bcar); - assertEquals(-1, bstatus); + bstatus = jedis.linsert(bfoo, Client.LIST_POSITION.BEFORE, bbar, bcar); + assertEquals(-1, bstatus); } @Test public void brpoplpush() { - (new Thread(new Runnable() { - public void run() { - try { - Thread.sleep(100); - Jedis j = createJedis(); - j.lpush("foo", "a"); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - })).start(); + (new Thread(new Runnable() { + public void run() { + try { + Thread.sleep(100); + Jedis j = createJedis(); + j.lpush("foo", "a"); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + })).start(); - String element = jedis.brpoplpush("foo", "bar", 0); + String element = jedis.brpoplpush("foo", "bar", 0); - assertEquals("a", element); - assertEquals(1, jedis.llen("bar").longValue()); - assertEquals("a", jedis.lrange("bar", 0, -1).get(0)); + assertEquals("a", element); + assertEquals(1, jedis.llen("bar").longValue()); + assertEquals("a", jedis.lrange("bar", 0, -1).get(0)); - (new Thread(new Runnable() { - public void run() { - try { - Thread.sleep(100); - Jedis j = createJedis(); - j.lpush("foo", "a"); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - })).start(); + (new Thread(new Runnable() { + public void run() { + try { + Thread.sleep(100); + Jedis j = createJedis(); + j.lpush("foo", "a"); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + })).start(); - byte[] brpoplpush = jedis.brpoplpush("foo".getBytes(), - "bar".getBytes(), 0); + byte[] brpoplpush = jedis.brpoplpush("foo".getBytes(), + "bar".getBytes(), 0); - assertTrue(Arrays.equals("a".getBytes(), brpoplpush)); - assertEquals(1, jedis.llen("bar").longValue()); - assertEquals("a", jedis.lrange("bar", 0, -1).get(0)); + assertTrue(Arrays.equals("a".getBytes(), brpoplpush)); + assertEquals(1, jedis.llen("bar").longValue()); + assertEquals("a", jedis.lrange("bar", 0, -1).get(0)); } } diff --git a/src/test/java/redis/clients/jedis/tests/commands/ObjectCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ObjectCommandsTest.java index 1da4331..a1f5fa9 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ObjectCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ObjectCommandsTest.java @@ -11,36 +11,36 @@ public class ObjectCommandsTest extends JedisCommandTestBase { @Test public void objectRefcount() { - jedis.lpush(key, "hello world"); - Long refcount = jedis.objectRefcount(key); - assertEquals(new Long(1), refcount); + jedis.lpush(key, "hello world"); + Long refcount = jedis.objectRefcount(key); + assertEquals(new Long(1), refcount); - // Binary - refcount = jedis.objectRefcount(binaryKey); - assertEquals(new Long(1), refcount); + // Binary + refcount = jedis.objectRefcount(binaryKey); + assertEquals(new Long(1), refcount); } @Test public void objectEncoding() { - jedis.lpush(key, "hello world"); - String encoding = jedis.objectEncoding(key); - assertEquals("ziplist", encoding); + jedis.lpush(key, "hello world"); + String encoding = jedis.objectEncoding(key); + assertEquals("ziplist", encoding); - // Binary - encoding = SafeEncoder.encode(jedis.objectEncoding(binaryKey)); - assertEquals("ziplist", encoding); + // Binary + encoding = SafeEncoder.encode(jedis.objectEncoding(binaryKey)); + assertEquals("ziplist", encoding); } @Test public void objectIdletime() throws InterruptedException { - jedis.lpush(key, "hello world"); + jedis.lpush(key, "hello world"); - Long time = jedis.objectIdletime(key); - assertEquals(new Long(0), time); + Long time = jedis.objectIdletime(key); + assertEquals(new Long(0), time); - // Binary - time = jedis.objectIdletime(binaryKey); - assertEquals(new Long(0), time); + // Binary + time = jedis.objectIdletime(binaryKey); + assertEquals(new Long(0), time); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/commands/PublishSubscribeCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/PublishSubscribeCommandsTest.java index 8dd55c3..7d54ea5 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/PublishSubscribeCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/PublishSubscribeCommandsTest.java @@ -16,374 +16,374 @@ import redis.clients.util.SafeEncoder; public class PublishSubscribeCommandsTest extends JedisCommandTestBase { private void publishOne(final String channel, final String message) { - Thread t = new Thread(new Runnable() { - public void run() { - try { - Jedis j = createJedis(); - j.publish(channel, message); - j.disconnect(); - } catch (Exception ex) { - } - } - }); - t.start(); + Thread t = new Thread(new Runnable() { + public void run() { + try { + Jedis j = createJedis(); + j.publish(channel, message); + j.disconnect(); + } catch (Exception ex) { + } + } + }); + t.start(); } @Test public void subscribe() throws InterruptedException { - jedis.subscribe(new JedisPubSub() { - public void onMessage(String channel, String message) { - assertEquals("foo", channel); - assertEquals("exit", message); - unsubscribe(); - } + jedis.subscribe(new JedisPubSub() { + public void onMessage(String channel, String message) { + assertEquals("foo", channel); + assertEquals("exit", message); + unsubscribe(); + } - public void onSubscribe(String channel, int subscribedChannels) { - assertEquals("foo", channel); - assertEquals(1, subscribedChannels); + public void onSubscribe(String channel, int subscribedChannels) { + assertEquals("foo", channel); + assertEquals(1, subscribedChannels); - // now that I'm subscribed... publish - publishOne("foo", "exit"); - } + // now that I'm subscribed... publish + publishOne("foo", "exit"); + } - public void onUnsubscribe(String channel, int subscribedChannels) { - assertEquals("foo", channel); - assertEquals(0, subscribedChannels); - } - }, "foo"); + public void onUnsubscribe(String channel, int subscribedChannels) { + assertEquals("foo", channel); + assertEquals(0, subscribedChannels); + } + }, "foo"); } @Test public void pubSubChannels() { - final List expectedActiveChannels = Arrays.asList("testchan1", - "testchan2", "testchan3"); - jedis.subscribe(new JedisPubSub() { - private int count = 0; + final List expectedActiveChannels = Arrays.asList("testchan1", + "testchan2", "testchan3"); + jedis.subscribe(new JedisPubSub() { + private int count = 0; - @Override - public void onSubscribe(String channel, int subscribedChannels) { - count++; - // All channels are subscribed - if (count == 3) { - Jedis otherJedis = createJedis(); - List activeChannels = otherJedis - .pubsubChannels("test*"); - assertTrue(expectedActiveChannels - .containsAll(activeChannels)); - unsubscribe(); - } - } - }, "testchan1", "testchan2", "testchan3"); + @Override + public void onSubscribe(String channel, int subscribedChannels) { + count++; + // All channels are subscribed + if (count == 3) { + Jedis otherJedis = createJedis(); + List activeChannels = otherJedis + .pubsubChannels("test*"); + assertTrue(expectedActiveChannels + .containsAll(activeChannels)); + unsubscribe(); + } + } + }, "testchan1", "testchan2", "testchan3"); } @Test public void pubSubNumPat() { - jedis.psubscribe(new JedisPubSub() { - private int count = 0; + jedis.psubscribe(new JedisPubSub() { + private int count = 0; - @Override - public void onPSubscribe(String pattern, int subscribedChannels) { - count++; - if (count == 3) { - Jedis otherJedis = createJedis(); - Long numPatterns = otherJedis.pubsubNumPat(); - assertEquals(new Long(2l), numPatterns); - punsubscribe(); - } - } + @Override + public void onPSubscribe(String pattern, int subscribedChannels) { + count++; + if (count == 3) { + Jedis otherJedis = createJedis(); + Long numPatterns = otherJedis.pubsubNumPat(); + assertEquals(new Long(2l), numPatterns); + punsubscribe(); + } + } - }, "test*", "test*", "chan*"); + }, "test*", "test*", "chan*"); } @Test public void pubSubNumSub() { - final Map expectedNumSub = new HashMap(); - expectedNumSub.put("testchannel2", "1"); - expectedNumSub.put("testchannel1", "1"); - jedis.subscribe(new JedisPubSub() { - private int count = 0; + final Map expectedNumSub = new HashMap(); + expectedNumSub.put("testchannel2", "1"); + expectedNumSub.put("testchannel1", "1"); + jedis.subscribe(new JedisPubSub() { + private int count = 0; - @Override - public void onSubscribe(String channel, int subscribedChannels) { - count++; - if (count == 2) { - Jedis otherJedis = createJedis(); - Map numSub = otherJedis.pubsubNumSub( - "testchannel1", "testchannel2"); - assertEquals(expectedNumSub, numSub); - unsubscribe(); - } - } - }, "testchannel1", "testchannel2"); + @Override + public void onSubscribe(String channel, int subscribedChannels) { + count++; + if (count == 2) { + Jedis otherJedis = createJedis(); + Map numSub = otherJedis.pubsubNumSub( + "testchannel1", "testchannel2"); + assertEquals(expectedNumSub, numSub); + unsubscribe(); + } + } + }, "testchannel1", "testchannel2"); } @Test public void subscribeMany() throws UnknownHostException, IOException, - InterruptedException { - jedis.subscribe(new JedisPubSub() { - public void onMessage(String channel, String message) { - unsubscribe(channel); - } + InterruptedException { + jedis.subscribe(new JedisPubSub() { + public void onMessage(String channel, String message) { + unsubscribe(channel); + } - public void onSubscribe(String channel, int subscribedChannels) { - publishOne(channel, "exit"); - } + public void onSubscribe(String channel, int subscribedChannels) { + publishOne(channel, "exit"); + } - }, "foo", "bar"); + }, "foo", "bar"); } @Test public void psubscribe() throws UnknownHostException, IOException, - InterruptedException { - jedis.psubscribe(new JedisPubSub() { - public void onPSubscribe(String pattern, int subscribedChannels) { - assertEquals("foo.*", pattern); - assertEquals(1, subscribedChannels); - publishOne("foo.bar", "exit"); + InterruptedException { + jedis.psubscribe(new JedisPubSub() { + public void onPSubscribe(String pattern, int subscribedChannels) { + assertEquals("foo.*", pattern); + assertEquals(1, subscribedChannels); + publishOne("foo.bar", "exit"); - } + } - public void onPUnsubscribe(String pattern, int subscribedChannels) { - assertEquals("foo.*", pattern); - assertEquals(0, subscribedChannels); - } + public void onPUnsubscribe(String pattern, int subscribedChannels) { + assertEquals("foo.*", pattern); + assertEquals(0, subscribedChannels); + } - public void onPMessage(String pattern, String channel, - String message) { - assertEquals("foo.*", pattern); - assertEquals("foo.bar", channel); - assertEquals("exit", message); - punsubscribe(); - } - }, "foo.*"); + public void onPMessage(String pattern, String channel, + String message) { + assertEquals("foo.*", pattern); + assertEquals("foo.bar", channel); + assertEquals("exit", message); + punsubscribe(); + } + }, "foo.*"); } @Test public void psubscribeMany() throws UnknownHostException, IOException, - InterruptedException { - jedis.psubscribe(new JedisPubSub() { - public void onPSubscribe(String pattern, int subscribedChannels) { - publishOne(pattern.replace("*", "123"), "exit"); - } + InterruptedException { + jedis.psubscribe(new JedisPubSub() { + public void onPSubscribe(String pattern, int subscribedChannels) { + publishOne(pattern.replace("*", "123"), "exit"); + } - public void onPMessage(String pattern, String channel, - String message) { - punsubscribe(pattern); - } - }, "foo.*", "bar.*"); + public void onPMessage(String pattern, String channel, + String message) { + punsubscribe(pattern); + } + }, "foo.*", "bar.*"); } @Test public void subscribeLazily() throws UnknownHostException, IOException, - InterruptedException { - final JedisPubSub pubsub = new JedisPubSub() { - public void onMessage(String channel, String message) { - unsubscribe(channel); - } + InterruptedException { + final JedisPubSub pubsub = new JedisPubSub() { + public void onMessage(String channel, String message) { + unsubscribe(channel); + } - public void onSubscribe(String channel, int subscribedChannels) { - publishOne(channel, "exit"); - if (!channel.equals("bar")) { - this.subscribe("bar"); - this.psubscribe("bar.*"); - } - } + public void onSubscribe(String channel, int subscribedChannels) { + publishOne(channel, "exit"); + if (!channel.equals("bar")) { + this.subscribe("bar"); + this.psubscribe("bar.*"); + } + } - public void onPSubscribe(String pattern, int subscribedChannels) { - publishOne(pattern.replace("*", "123"), "exit"); - } + public void onPSubscribe(String pattern, int subscribedChannels) { + publishOne(pattern.replace("*", "123"), "exit"); + } - public void onPMessage(String pattern, String channel, - String message) { - punsubscribe(pattern); - } - }; + public void onPMessage(String pattern, String channel, + String message) { + punsubscribe(pattern); + } + }; - jedis.subscribe(pubsub, "foo"); + jedis.subscribe(pubsub, "foo"); } @Test public void binarySubscribe() throws UnknownHostException, IOException, - InterruptedException { - jedis.subscribe(new BinaryJedisPubSub() { - public void onMessage(byte[] channel, byte[] message) { - assertTrue(Arrays.equals(SafeEncoder.encode("foo"), channel)); - assertTrue(Arrays.equals(SafeEncoder.encode("exit"), message)); - unsubscribe(); - } + InterruptedException { + jedis.subscribe(new BinaryJedisPubSub() { + public void onMessage(byte[] channel, byte[] message) { + assertTrue(Arrays.equals(SafeEncoder.encode("foo"), channel)); + assertTrue(Arrays.equals(SafeEncoder.encode("exit"), message)); + unsubscribe(); + } - public void onSubscribe(byte[] channel, int subscribedChannels) { - assertTrue(Arrays.equals(SafeEncoder.encode("foo"), channel)); - assertEquals(1, subscribedChannels); - publishOne(SafeEncoder.encode(channel), "exit"); - } + public void onSubscribe(byte[] channel, int subscribedChannels) { + assertTrue(Arrays.equals(SafeEncoder.encode("foo"), channel)); + assertEquals(1, subscribedChannels); + publishOne(SafeEncoder.encode(channel), "exit"); + } - public void onUnsubscribe(byte[] channel, int subscribedChannels) { - assertTrue(Arrays.equals(SafeEncoder.encode("foo"), channel)); - assertEquals(0, subscribedChannels); - } - }, SafeEncoder.encode("foo")); + public void onUnsubscribe(byte[] channel, int subscribedChannels) { + assertTrue(Arrays.equals(SafeEncoder.encode("foo"), channel)); + assertEquals(0, subscribedChannels); + } + }, SafeEncoder.encode("foo")); } @Test public void binarySubscribeMany() throws UnknownHostException, IOException, - InterruptedException { - jedis.subscribe(new BinaryJedisPubSub() { - public void onMessage(byte[] channel, byte[] message) { - unsubscribe(channel); - } + InterruptedException { + jedis.subscribe(new BinaryJedisPubSub() { + public void onMessage(byte[] channel, byte[] message) { + unsubscribe(channel); + } - public void onSubscribe(byte[] channel, int subscribedChannels) { - publishOne(SafeEncoder.encode(channel), "exit"); - } - }, SafeEncoder.encode("foo"), SafeEncoder.encode("bar")); + public void onSubscribe(byte[] channel, int subscribedChannels) { + publishOne(SafeEncoder.encode(channel), "exit"); + } + }, SafeEncoder.encode("foo"), SafeEncoder.encode("bar")); } @Test public void binaryPsubscribe() throws UnknownHostException, IOException, - InterruptedException { - jedis.psubscribe(new BinaryJedisPubSub() { - public void onPSubscribe(byte[] pattern, int subscribedChannels) { - assertTrue(Arrays.equals(SafeEncoder.encode("foo.*"), pattern)); - assertEquals(1, subscribedChannels); - publishOne(SafeEncoder.encode(pattern).replace("*", "bar"), - "exit"); - } + InterruptedException { + jedis.psubscribe(new BinaryJedisPubSub() { + public void onPSubscribe(byte[] pattern, int subscribedChannels) { + assertTrue(Arrays.equals(SafeEncoder.encode("foo.*"), pattern)); + assertEquals(1, subscribedChannels); + publishOne(SafeEncoder.encode(pattern).replace("*", "bar"), + "exit"); + } - public void onPUnsubscribe(byte[] pattern, int subscribedChannels) { - assertTrue(Arrays.equals(SafeEncoder.encode("foo.*"), pattern)); - assertEquals(0, subscribedChannels); - } + public void onPUnsubscribe(byte[] pattern, int subscribedChannels) { + assertTrue(Arrays.equals(SafeEncoder.encode("foo.*"), pattern)); + assertEquals(0, subscribedChannels); + } - public void onPMessage(byte[] pattern, byte[] channel, - byte[] message) { - assertTrue(Arrays.equals(SafeEncoder.encode("foo.*"), pattern)); - assertTrue(Arrays - .equals(SafeEncoder.encode("foo.bar"), channel)); - assertTrue(Arrays.equals(SafeEncoder.encode("exit"), message)); - punsubscribe(); - } - }, SafeEncoder.encode("foo.*")); + public void onPMessage(byte[] pattern, byte[] channel, + byte[] message) { + assertTrue(Arrays.equals(SafeEncoder.encode("foo.*"), pattern)); + assertTrue(Arrays + .equals(SafeEncoder.encode("foo.bar"), channel)); + assertTrue(Arrays.equals(SafeEncoder.encode("exit"), message)); + punsubscribe(); + } + }, SafeEncoder.encode("foo.*")); } @Test public void binaryPsubscribeMany() throws UnknownHostException, - IOException, InterruptedException { - jedis.psubscribe(new BinaryJedisPubSub() { - public void onPSubscribe(byte[] pattern, int subscribedChannels) { - publishOne(SafeEncoder.encode(pattern).replace("*", "123"), - "exit"); - } + IOException, InterruptedException { + jedis.psubscribe(new BinaryJedisPubSub() { + public void onPSubscribe(byte[] pattern, int subscribedChannels) { + publishOne(SafeEncoder.encode(pattern).replace("*", "123"), + "exit"); + } - public void onPMessage(byte[] pattern, byte[] channel, - byte[] message) { - punsubscribe(pattern); - } - }, SafeEncoder.encode("foo.*"), SafeEncoder.encode("bar.*")); + public void onPMessage(byte[] pattern, byte[] channel, + byte[] message) { + punsubscribe(pattern); + } + }, SafeEncoder.encode("foo.*"), SafeEncoder.encode("bar.*")); } @Test public void binarySubscribeLazily() throws UnknownHostException, - IOException, InterruptedException { - final BinaryJedisPubSub pubsub = new BinaryJedisPubSub() { - public void onMessage(byte[] channel, byte[] message) { - unsubscribe(channel); - } + IOException, InterruptedException { + final BinaryJedisPubSub pubsub = new BinaryJedisPubSub() { + public void onMessage(byte[] channel, byte[] message) { + unsubscribe(channel); + } - public void onSubscribe(byte[] channel, int subscribedChannels) { - publishOne(SafeEncoder.encode(channel), "exit"); + public void onSubscribe(byte[] channel, int subscribedChannels) { + publishOne(SafeEncoder.encode(channel), "exit"); - if (!SafeEncoder.encode(channel).equals("bar")) { - this.subscribe(SafeEncoder.encode("bar")); - this.psubscribe(SafeEncoder.encode("bar.*")); - } - } + if (!SafeEncoder.encode(channel).equals("bar")) { + this.subscribe(SafeEncoder.encode("bar")); + this.psubscribe(SafeEncoder.encode("bar.*")); + } + } - public void onPSubscribe(byte[] pattern, int subscribedChannels) { - publishOne(SafeEncoder.encode(pattern).replace("*", "123"), - "exit"); - } + public void onPSubscribe(byte[] pattern, int subscribedChannels) { + publishOne(SafeEncoder.encode(pattern).replace("*", "123"), + "exit"); + } - public void onPMessage(byte[] pattern, byte[] channel, - byte[] message) { - punsubscribe(pattern); - } - }; + public void onPMessage(byte[] pattern, byte[] channel, + byte[] message) { + punsubscribe(pattern); + } + }; - jedis.subscribe(pubsub, SafeEncoder.encode("foo")); + jedis.subscribe(pubsub, SafeEncoder.encode("foo")); } @Test(expected = JedisConnectionException.class) public void unsubscribeWhenNotSusbscribed() throws InterruptedException { - JedisPubSub pubsub = new JedisPubSub() {}; - pubsub.unsubscribe(); + JedisPubSub pubsub = new JedisPubSub() {}; + pubsub.unsubscribe(); } @Test(expected = JedisConnectionException.class) public void handleClientOutputBufferLimitForSubscribeTooSlow() - throws InterruptedException { - final Jedis j = createJedis(); - final AtomicBoolean exit = new AtomicBoolean(false); + throws InterruptedException { + final Jedis j = createJedis(); + final AtomicBoolean exit = new AtomicBoolean(false); - final Thread t = new Thread(new Runnable() { - public void run() { - try { + final Thread t = new Thread(new Runnable() { + public void run() { + try { - // we already set jedis1 config to - // client-output-buffer-limit pubsub 256k 128k 5 - // it means if subscriber delayed to receive over 256k or - // 128k continuously 5 sec, - // redis disconnects subscriber + // we already set jedis1 config to + // client-output-buffer-limit pubsub 256k 128k 5 + // it means if subscriber delayed to receive over 256k or + // 128k continuously 5 sec, + // redis disconnects subscriber - // we publish over 100M data for making situation for exceed - // client-output-buffer-limit - String veryLargeString = makeLargeString(10485760); + // we publish over 100M data for making situation for exceed + // client-output-buffer-limit + String veryLargeString = makeLargeString(10485760); - // 10M * 10 = 100M - for (int i = 0; i < 10 && !exit.get(); i++) { - j.publish("foo", veryLargeString); - } + // 10M * 10 = 100M + for (int i = 0; i < 10 && !exit.get(); i++) { + j.publish("foo", veryLargeString); + } - j.disconnect(); - } catch (Exception ex) { - } - } - }); - t.start(); - try { - jedis.subscribe(new JedisPubSub() { - public void onMessage(String channel, String message) { - try { - // wait 0.5 secs to slow down subscribe and - // client-output-buffer exceed - // System.out.println("channel - " + channel + - // " / message - " + message); - Thread.sleep(100); - } catch (Exception e) { - try { - t.join(); - } catch (InterruptedException e1) { - } + j.disconnect(); + } catch (Exception ex) { + } + } + }); + t.start(); + try { + jedis.subscribe(new JedisPubSub() { + public void onMessage(String channel, String message) { + try { + // wait 0.5 secs to slow down subscribe and + // client-output-buffer exceed + // System.out.println("channel - " + channel + + // " / message - " + message); + Thread.sleep(100); + } catch (Exception e) { + try { + t.join(); + } catch (InterruptedException e1) { + } - fail(e.getMessage()); - } - } - }, "foo"); - } finally { - // exit the publisher thread. if exception is thrown, thread might - // still keep publishing things. - exit.set(true); - if (t.isAlive()) { - t.join(); - } - } + fail(e.getMessage()); + } + } + }, "foo"); + } finally { + // exit the publisher thread. if exception is thrown, thread might + // still keep publishing things. + exit.set(true); + if (t.isAlive()) { + t.join(); + } + } } private String makeLargeString(int size) { - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < size; i++) - sb.append((char) ('a' + i % 26)); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < size; i++) + sb.append((char) ('a' + i % 26)); - return sb.toString(); + return sb.toString(); } } diff --git a/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java index c391495..c8362b4 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ScriptingCommandsTest.java @@ -18,193 +18,193 @@ public class ScriptingCommandsTest extends JedisCommandTestBase { @SuppressWarnings("unchecked") @Test public void evalMultiBulk() { - String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2],ARGV[3]}"; - List keys = new ArrayList(); - keys.add("key1"); - keys.add("key2"); + String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2],ARGV[3]}"; + List keys = new ArrayList(); + keys.add("key1"); + keys.add("key2"); - List args = new ArrayList(); - args.add("first"); - args.add("second"); - args.add("third"); + List args = new ArrayList(); + args.add("first"); + args.add("second"); + args.add("third"); - List response = (List) jedis.eval(script, keys, args); + List response = (List) jedis.eval(script, keys, args); - assertEquals(5, response.size()); - assertEquals("key1", response.get(0)); - assertEquals("key2", response.get(1)); - assertEquals("first", response.get(2)); - assertEquals("second", response.get(3)); - assertEquals("third", response.get(4)); + assertEquals(5, response.size()); + assertEquals("key1", response.get(0)); + assertEquals("key2", response.get(1)); + assertEquals("first", response.get(2)); + assertEquals("second", response.get(3)); + assertEquals("third", response.get(4)); } @SuppressWarnings("unchecked") @Test public void evalMultiBulkWithBinaryJedis() { - String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2],ARGV[3]}"; - List keys = new ArrayList(); - keys.add("key1".getBytes()); - keys.add("key2".getBytes()); + String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2],ARGV[3]}"; + List keys = new ArrayList(); + keys.add("key1".getBytes()); + keys.add("key2".getBytes()); - List args = new ArrayList(); - args.add("first".getBytes()); - args.add("second".getBytes()); - args.add("third".getBytes()); + List args = new ArrayList(); + args.add("first".getBytes()); + args.add("second".getBytes()); + args.add("third".getBytes()); - BinaryJedis binaryJedis = new BinaryJedis(hnp.getHost(), hnp.getPort(), - 500); - binaryJedis.connect(); - binaryJedis.auth("foobared"); + BinaryJedis binaryJedis = new BinaryJedis(hnp.getHost(), hnp.getPort(), + 500); + binaryJedis.connect(); + binaryJedis.auth("foobared"); - List responses = (List) binaryJedis.eval( - script.getBytes(), keys, args); - assertEquals(5, responses.size()); - assertEquals("key1", new String(responses.get(0))); - assertEquals("key2", new String(responses.get(1))); - assertEquals("first", new String(responses.get(2))); - assertEquals("second", new String(responses.get(3))); - assertEquals("third", new String(responses.get(4))); + List responses = (List) binaryJedis.eval( + script.getBytes(), keys, args); + assertEquals(5, responses.size()); + assertEquals("key1", new String(responses.get(0))); + assertEquals("key2", new String(responses.get(1))); + assertEquals("first", new String(responses.get(2))); + assertEquals("second", new String(responses.get(3))); + assertEquals("third", new String(responses.get(4))); } @Test public void evalBulk() { - String script = "return KEYS[1]"; - List keys = new ArrayList(); - keys.add("key1"); + String script = "return KEYS[1]"; + List keys = new ArrayList(); + keys.add("key1"); - List args = new ArrayList(); - args.add("first"); + List args = new ArrayList(); + args.add("first"); - String response = (String) jedis.eval(script, keys, args); + String response = (String) jedis.eval(script, keys, args); - assertEquals("key1", response); + assertEquals("key1", response); } @Test public void evalInt() { - String script = "return 2"; - List keys = new ArrayList(); - keys.add("key1"); + String script = "return 2"; + List keys = new ArrayList(); + keys.add("key1"); - Long response = (Long) jedis - .eval(script, keys, new ArrayList()); + Long response = (Long) jedis + .eval(script, keys, new ArrayList()); - assertEquals(new Long(2), response); + assertEquals(new Long(2), response); } @Test public void evalNestedLists() { - String script = "return { {KEYS[1]} , {2} }"; - List results = (List) jedis.eval(script, 1, "key1"); + String script = "return { {KEYS[1]} , {2} }"; + List results = (List) jedis.eval(script, 1, "key1"); - assertThat((List) results.get(0), listWithItem("key1")); - assertThat((List) results.get(1), listWithItem(2L)); + assertThat((List) results.get(0), listWithItem("key1")); + assertThat((List) results.get(1), listWithItem(2L)); } @Test public void evalNoArgs() { - String script = "return KEYS[1]"; - List keys = new ArrayList(); - keys.add("key1"); - String response = (String) jedis.eval(script, keys, - new ArrayList()); + String script = "return KEYS[1]"; + List keys = new ArrayList(); + keys.add("key1"); + String response = (String) jedis.eval(script, keys, + new ArrayList()); - assertEquals("key1", response); + assertEquals("key1", response); } @Test public void evalsha() { - jedis.set("foo", "bar"); - jedis.eval("return redis.call('get','foo')"); - String result = (String) jedis - .evalsha("6b1bf486c81ceb7edf3c093f4c48582e38c0e791"); + jedis.set("foo", "bar"); + jedis.eval("return redis.call('get','foo')"); + String result = (String) jedis + .evalsha("6b1bf486c81ceb7edf3c093f4c48582e38c0e791"); - assertEquals("bar", result); + assertEquals("bar", result); } @Test(expected = JedisDataException.class) public void evalshaShaNotFound() { - jedis.evalsha("ffffffffffffffffffffffffffffffffffffffff"); + jedis.evalsha("ffffffffffffffffffffffffffffffffffffffff"); } @Test public void scriptFlush() { - jedis.set("foo", "bar"); - jedis.eval("return redis.call('get','foo')"); - jedis.scriptFlush(); - assertFalse(jedis - .scriptExists("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); + jedis.set("foo", "bar"); + jedis.eval("return redis.call('get','foo')"); + jedis.scriptFlush(); + assertFalse(jedis + .scriptExists("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); } @Test public void scriptExists() { - jedis.scriptLoad("return redis.call('get','foo')"); - List exists = jedis.scriptExists( - "ffffffffffffffffffffffffffffffffffffffff", - "6b1bf486c81ceb7edf3c093f4c48582e38c0e791"); - assertFalse(exists.get(0)); - assertTrue(exists.get(1)); + jedis.scriptLoad("return redis.call('get','foo')"); + List exists = jedis.scriptExists( + "ffffffffffffffffffffffffffffffffffffffff", + "6b1bf486c81ceb7edf3c093f4c48582e38c0e791"); + assertFalse(exists.get(0)); + assertTrue(exists.get(1)); } @Test public void scriptExistsBinary() { - jedis.scriptLoad(SafeEncoder.encode("return redis.call('get','foo')")); - List exists = jedis.scriptExists( - SafeEncoder.encode("ffffffffffffffffffffffffffffffffffffffff"), - SafeEncoder.encode("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); - assertEquals(new Long(0), exists.get(0)); - assertEquals(new Long(1), exists.get(1)); + jedis.scriptLoad(SafeEncoder.encode("return redis.call('get','foo')")); + List exists = jedis.scriptExists( + SafeEncoder.encode("ffffffffffffffffffffffffffffffffffffffff"), + SafeEncoder.encode("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); + assertEquals(new Long(0), exists.get(0)); + assertEquals(new Long(1), exists.get(1)); } @Test public void scriptLoad() { - jedis.scriptLoad("return redis.call('get','foo')"); - assertTrue(jedis - .scriptExists("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); + jedis.scriptLoad("return redis.call('get','foo')"); + assertTrue(jedis + .scriptExists("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); } @Test public void scriptLoadBinary() { - jedis.scriptLoad(SafeEncoder.encode("return redis.call('get','foo')")); - List exists = jedis.scriptExists(SafeEncoder - .encode("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); - assertEquals(new Long(1), exists.get(0)); + jedis.scriptLoad(SafeEncoder.encode("return redis.call('get','foo')")); + List exists = jedis.scriptExists(SafeEncoder + .encode("6b1bf486c81ceb7edf3c093f4c48582e38c0e791")); + assertEquals(new Long(1), exists.get(0)); } @Test public void scriptKill() { - try { - jedis.scriptKill(); - } catch (JedisDataException e) { - assertTrue(e.getMessage().contains( - "No scripts in execution right now.")); - } + try { + jedis.scriptKill(); + } catch (JedisDataException e) { + assertTrue(e.getMessage().contains( + "No scripts in execution right now.")); + } } @Test public void scriptEvalReturnNullValues() { - String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}"; - List results = (List) jedis.eval(script, 2, "key1", - "key2", "1", "2"); - assertEquals("key1", results.get(0)); - assertEquals("key2", results.get(1)); - assertEquals("1", results.get(2)); - assertEquals("2", results.get(3)); + String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}"; + List results = (List) jedis.eval(script, 2, "key1", + "key2", "1", "2"); + assertEquals("key1", results.get(0)); + assertEquals("key2", results.get(1)); + assertEquals("1", results.get(2)); + assertEquals("2", results.get(3)); } @Test public void scriptEvalShaReturnNullValues() { - String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}"; - String sha = jedis.scriptLoad(script); - List results = (List) jedis.evalsha(sha, 2, "key1", - "key2", "1", "2"); - assertEquals("key1", results.get(0)); - assertEquals("key2", results.get(1)); - assertEquals("1", results.get(2)); - assertEquals("2", results.get(3)); + String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}"; + String sha = jedis.scriptLoad(script); + List results = (List) jedis.evalsha(sha, 2, "key1", + "key2", "1", "2"); + assertEquals("key1", results.get(0)); + assertEquals("key2", results.get(1)); + assertEquals("1", results.get(2)); + assertEquals("2", results.get(3)); } private Matcher> listWithItem(T expected) { - return CoreMatchers. hasItem(equalTo(expected)); + return CoreMatchers. hasItem(equalTo(expected)); } } diff --git a/src/test/java/redis/clients/jedis/tests/commands/SetCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/SetCommandsTest.java index 6da49bf..b70957f 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/SetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/SetCommandsTest.java @@ -29,501 +29,501 @@ public class SetCommandsTest extends JedisCommandTestBase { @Test public void sadd() { - long status = jedis.sadd("foo", "a"); - assertEquals(1, status); + long status = jedis.sadd("foo", "a"); + assertEquals(1, status); - status = jedis.sadd("foo", "a"); - assertEquals(0, status); + status = jedis.sadd("foo", "a"); + assertEquals(0, status); - long bstatus = jedis.sadd(bfoo, ba); - assertEquals(1, bstatus); + long bstatus = jedis.sadd(bfoo, ba); + assertEquals(1, bstatus); - bstatus = jedis.sadd(bfoo, ba); - assertEquals(0, bstatus); + bstatus = jedis.sadd(bfoo, ba); + assertEquals(0, bstatus); } @Test public void smembers() { - jedis.sadd("foo", "a"); - jedis.sadd("foo", "b"); + jedis.sadd("foo", "a"); + jedis.sadd("foo", "b"); - Set expected = new HashSet(); - expected.add("a"); - expected.add("b"); + Set expected = new HashSet(); + expected.add("a"); + expected.add("b"); - Set members = jedis.smembers("foo"); + Set members = jedis.smembers("foo"); - assertEquals(expected, members); + assertEquals(expected, members); - // Binary - jedis.sadd(bfoo, ba); - jedis.sadd(bfoo, bb); + // Binary + jedis.sadd(bfoo, ba); + jedis.sadd(bfoo, bb); - Set bexpected = new HashSet(); - bexpected.add(bb); - bexpected.add(ba); + Set bexpected = new HashSet(); + bexpected.add(bb); + bexpected.add(ba); - Set bmembers = jedis.smembers(bfoo); + Set bmembers = jedis.smembers(bfoo); - assertEquals(bexpected, bmembers); + assertEquals(bexpected, bmembers); } @Test public void srem() { - jedis.sadd("foo", "a"); - jedis.sadd("foo", "b"); + jedis.sadd("foo", "a"); + jedis.sadd("foo", "b"); - long status = jedis.srem("foo", "a"); + long status = jedis.srem("foo", "a"); - Set expected = new HashSet(); - expected.add("b"); + Set expected = new HashSet(); + expected.add("b"); - assertEquals(1, status); - assertEquals(expected, jedis.smembers("foo")); + assertEquals(1, status); + assertEquals(expected, jedis.smembers("foo")); - status = jedis.srem("foo", "bar"); + status = jedis.srem("foo", "bar"); - assertEquals(0, status); + assertEquals(0, status); - // Binary + // Binary - jedis.sadd(bfoo, ba); - jedis.sadd(bfoo, bb); + jedis.sadd(bfoo, ba); + jedis.sadd(bfoo, bb); - long bstatus = jedis.srem(bfoo, ba); + long bstatus = jedis.srem(bfoo, ba); - Set bexpected = new HashSet(); - bexpected.add(bb); + Set bexpected = new HashSet(); + bexpected.add(bb); - assertEquals(1, bstatus); - assertEquals(bexpected, jedis.smembers(bfoo)); + assertEquals(1, bstatus); + assertEquals(bexpected, jedis.smembers(bfoo)); - bstatus = jedis.srem(bfoo, bbar); + bstatus = jedis.srem(bfoo, bbar); - assertEquals(0, bstatus); + assertEquals(0, bstatus); } @Test public void spop() { - jedis.sadd("foo", "a"); - jedis.sadd("foo", "b"); + jedis.sadd("foo", "a"); + jedis.sadd("foo", "b"); - String member = jedis.spop("foo"); + String member = jedis.spop("foo"); - assertTrue("a".equals(member) || "b".equals(member)); - assertEquals(1, jedis.smembers("foo").size()); + assertTrue("a".equals(member) || "b".equals(member)); + assertEquals(1, jedis.smembers("foo").size()); - member = jedis.spop("bar"); - assertNull(member); + member = jedis.spop("bar"); + assertNull(member); - // Binary - jedis.sadd(bfoo, ba); - jedis.sadd(bfoo, bb); + // Binary + jedis.sadd(bfoo, ba); + jedis.sadd(bfoo, bb); - byte[] bmember = jedis.spop(bfoo); + byte[] bmember = jedis.spop(bfoo); - assertTrue(Arrays.equals(ba, bmember) || Arrays.equals(bb, bmember)); - assertEquals(1, jedis.smembers(bfoo).size()); + assertTrue(Arrays.equals(ba, bmember) || Arrays.equals(bb, bmember)); + assertEquals(1, jedis.smembers(bfoo).size()); - bmember = jedis.spop(bbar); - assertNull(bmember); + bmember = jedis.spop(bbar); + assertNull(bmember); } @Test public void smove() { - jedis.sadd("foo", "a"); - jedis.sadd("foo", "b"); + jedis.sadd("foo", "a"); + jedis.sadd("foo", "b"); - jedis.sadd("bar", "c"); + jedis.sadd("bar", "c"); - long status = jedis.smove("foo", "bar", "a"); + long status = jedis.smove("foo", "bar", "a"); - Set expectedSrc = new HashSet(); - expectedSrc.add("b"); + Set expectedSrc = new HashSet(); + expectedSrc.add("b"); - Set expectedDst = new HashSet(); - expectedDst.add("c"); - expectedDst.add("a"); + Set expectedDst = new HashSet(); + expectedDst.add("c"); + expectedDst.add("a"); - assertEquals(status, 1); - assertEquals(expectedSrc, jedis.smembers("foo")); - assertEquals(expectedDst, jedis.smembers("bar")); + assertEquals(status, 1); + assertEquals(expectedSrc, jedis.smembers("foo")); + assertEquals(expectedDst, jedis.smembers("bar")); - status = jedis.smove("foo", "bar", "a"); + status = jedis.smove("foo", "bar", "a"); - assertEquals(status, 0); + assertEquals(status, 0); - // Binary - jedis.sadd(bfoo, ba); - jedis.sadd(bfoo, bb); + // Binary + jedis.sadd(bfoo, ba); + jedis.sadd(bfoo, bb); - jedis.sadd(bbar, bc); + jedis.sadd(bbar, bc); - long bstatus = jedis.smove(bfoo, bbar, ba); + long bstatus = jedis.smove(bfoo, bbar, ba); - Set bexpectedSrc = new HashSet(); - bexpectedSrc.add(bb); + Set bexpectedSrc = new HashSet(); + bexpectedSrc.add(bb); - Set bexpectedDst = new HashSet(); - bexpectedDst.add(bc); - bexpectedDst.add(ba); + Set bexpectedDst = new HashSet(); + bexpectedDst.add(bc); + bexpectedDst.add(ba); - assertEquals(bstatus, 1); - assertEquals(bexpectedSrc, jedis.smembers(bfoo)); - assertEquals(bexpectedDst, jedis.smembers(bbar)); + assertEquals(bstatus, 1); + assertEquals(bexpectedSrc, jedis.smembers(bfoo)); + assertEquals(bexpectedDst, jedis.smembers(bbar)); - bstatus = jedis.smove(bfoo, bbar, ba); - assertEquals(bstatus, 0); + bstatus = jedis.smove(bfoo, bbar, ba); + assertEquals(bstatus, 0); } @Test public void scard() { - jedis.sadd("foo", "a"); - jedis.sadd("foo", "b"); + jedis.sadd("foo", "a"); + jedis.sadd("foo", "b"); - long card = jedis.scard("foo"); + long card = jedis.scard("foo"); - assertEquals(2, card); + assertEquals(2, card); - card = jedis.scard("bar"); - assertEquals(0, card); + card = jedis.scard("bar"); + assertEquals(0, card); - // Binary - jedis.sadd(bfoo, ba); - jedis.sadd(bfoo, bb); + // Binary + jedis.sadd(bfoo, ba); + jedis.sadd(bfoo, bb); - long bcard = jedis.scard(bfoo); + long bcard = jedis.scard(bfoo); - assertEquals(2, bcard); + assertEquals(2, bcard); - bcard = jedis.scard(bbar); - assertEquals(0, bcard); + bcard = jedis.scard(bbar); + assertEquals(0, bcard); } @Test public void sismember() { - jedis.sadd("foo", "a"); - jedis.sadd("foo", "b"); + jedis.sadd("foo", "a"); + jedis.sadd("foo", "b"); - assertTrue(jedis.sismember("foo", "a")); + assertTrue(jedis.sismember("foo", "a")); - assertFalse(jedis.sismember("foo", "c")); + assertFalse(jedis.sismember("foo", "c")); - // Binary - jedis.sadd(bfoo, ba); - jedis.sadd(bfoo, bb); + // Binary + jedis.sadd(bfoo, ba); + jedis.sadd(bfoo, bb); - assertTrue(jedis.sismember(bfoo, ba)); + assertTrue(jedis.sismember(bfoo, ba)); - assertFalse(jedis.sismember(bfoo, bc)); + assertFalse(jedis.sismember(bfoo, bc)); } @Test public void sinter() { - jedis.sadd("foo", "a"); - jedis.sadd("foo", "b"); + jedis.sadd("foo", "a"); + jedis.sadd("foo", "b"); - jedis.sadd("bar", "b"); - jedis.sadd("bar", "c"); + jedis.sadd("bar", "b"); + jedis.sadd("bar", "c"); - Set expected = new HashSet(); - expected.add("b"); + Set expected = new HashSet(); + expected.add("b"); - Set intersection = jedis.sinter("foo", "bar"); - assertEquals(expected, intersection); + Set intersection = jedis.sinter("foo", "bar"); + assertEquals(expected, intersection); - // Binary - jedis.sadd(bfoo, ba); - jedis.sadd(bfoo, bb); + // Binary + jedis.sadd(bfoo, ba); + jedis.sadd(bfoo, bb); - jedis.sadd(bbar, bb); - jedis.sadd(bbar, bc); + jedis.sadd(bbar, bb); + jedis.sadd(bbar, bc); - Set bexpected = new HashSet(); - bexpected.add(bb); + Set bexpected = new HashSet(); + bexpected.add(bb); - Set bintersection = jedis.sinter(bfoo, bbar); - assertEquals(bexpected, bintersection); + Set bintersection = jedis.sinter(bfoo, bbar); + assertEquals(bexpected, bintersection); } @Test public void sinterstore() { - jedis.sadd("foo", "a"); - jedis.sadd("foo", "b"); + jedis.sadd("foo", "a"); + jedis.sadd("foo", "b"); - jedis.sadd("bar", "b"); - jedis.sadd("bar", "c"); + jedis.sadd("bar", "b"); + jedis.sadd("bar", "c"); - Set expected = new HashSet(); - expected.add("b"); + Set expected = new HashSet(); + expected.add("b"); - long status = jedis.sinterstore("car", "foo", "bar"); - assertEquals(1, status); + long status = jedis.sinterstore("car", "foo", "bar"); + assertEquals(1, status); - assertEquals(expected, jedis.smembers("car")); + assertEquals(expected, jedis.smembers("car")); - // Binary - jedis.sadd(bfoo, ba); - jedis.sadd(bfoo, bb); + // Binary + jedis.sadd(bfoo, ba); + jedis.sadd(bfoo, bb); - jedis.sadd(bbar, bb); - jedis.sadd(bbar, bc); + jedis.sadd(bbar, bb); + jedis.sadd(bbar, bc); - Set bexpected = new HashSet(); - bexpected.add(bb); + Set bexpected = new HashSet(); + bexpected.add(bb); - long bstatus = jedis.sinterstore(bcar, bfoo, bbar); - assertEquals(1, bstatus); + long bstatus = jedis.sinterstore(bcar, bfoo, bbar); + assertEquals(1, bstatus); - assertEquals(bexpected, jedis.smembers(bcar)); + assertEquals(bexpected, jedis.smembers(bcar)); } @Test public void sunion() { - jedis.sadd("foo", "a"); - jedis.sadd("foo", "b"); + jedis.sadd("foo", "a"); + jedis.sadd("foo", "b"); - jedis.sadd("bar", "b"); - jedis.sadd("bar", "c"); + jedis.sadd("bar", "b"); + jedis.sadd("bar", "c"); - Set expected = new HashSet(); - expected.add("a"); - expected.add("b"); - expected.add("c"); + Set expected = new HashSet(); + expected.add("a"); + expected.add("b"); + expected.add("c"); - Set union = jedis.sunion("foo", "bar"); - assertEquals(expected, union); + Set union = jedis.sunion("foo", "bar"); + assertEquals(expected, union); - // Binary - jedis.sadd(bfoo, ba); - jedis.sadd(bfoo, bb); + // Binary + jedis.sadd(bfoo, ba); + jedis.sadd(bfoo, bb); - jedis.sadd(bbar, bb); - jedis.sadd(bbar, bc); + jedis.sadd(bbar, bb); + jedis.sadd(bbar, bc); - Set bexpected = new HashSet(); - bexpected.add(bb); - bexpected.add(bc); - bexpected.add(ba); + Set bexpected = new HashSet(); + bexpected.add(bb); + bexpected.add(bc); + bexpected.add(ba); - Set bunion = jedis.sunion(bfoo, bbar); - assertEquals(bexpected, bunion); + Set bunion = jedis.sunion(bfoo, bbar); + assertEquals(bexpected, bunion); } @Test public void sunionstore() { - jedis.sadd("foo", "a"); - jedis.sadd("foo", "b"); + jedis.sadd("foo", "a"); + jedis.sadd("foo", "b"); - jedis.sadd("bar", "b"); - jedis.sadd("bar", "c"); + jedis.sadd("bar", "b"); + jedis.sadd("bar", "c"); - Set expected = new HashSet(); - expected.add("a"); - expected.add("b"); - expected.add("c"); + Set expected = new HashSet(); + expected.add("a"); + expected.add("b"); + expected.add("c"); - long status = jedis.sunionstore("car", "foo", "bar"); - assertEquals(3, status); + long status = jedis.sunionstore("car", "foo", "bar"); + assertEquals(3, status); - assertEquals(expected, jedis.smembers("car")); + assertEquals(expected, jedis.smembers("car")); - // Binary - jedis.sadd(bfoo, ba); - jedis.sadd(bfoo, bb); + // Binary + jedis.sadd(bfoo, ba); + jedis.sadd(bfoo, bb); - jedis.sadd(bbar, bb); - jedis.sadd(bbar, bc); + jedis.sadd(bbar, bb); + jedis.sadd(bbar, bc); - Set bexpected = new HashSet(); - bexpected.add(bb); - bexpected.add(bc); - bexpected.add(ba); + Set bexpected = new HashSet(); + bexpected.add(bb); + bexpected.add(bc); + bexpected.add(ba); - long bstatus = jedis.sunionstore(bcar, bfoo, bbar); - assertEquals(3, bstatus); + long bstatus = jedis.sunionstore(bcar, bfoo, bbar); + assertEquals(3, bstatus); - assertEquals(bexpected, jedis.smembers(bcar)); + assertEquals(bexpected, jedis.smembers(bcar)); } @Test public void sdiff() { - jedis.sadd("foo", "x"); - jedis.sadd("foo", "a"); - jedis.sadd("foo", "b"); - jedis.sadd("foo", "c"); + jedis.sadd("foo", "x"); + jedis.sadd("foo", "a"); + jedis.sadd("foo", "b"); + jedis.sadd("foo", "c"); - jedis.sadd("bar", "c"); + jedis.sadd("bar", "c"); - jedis.sadd("car", "a"); - jedis.sadd("car", "d"); + jedis.sadd("car", "a"); + jedis.sadd("car", "d"); - Set expected = new HashSet(); - expected.add("x"); - expected.add("b"); + Set expected = new HashSet(); + expected.add("x"); + expected.add("b"); - Set diff = jedis.sdiff("foo", "bar", "car"); - assertEquals(expected, diff); + Set diff = jedis.sdiff("foo", "bar", "car"); + assertEquals(expected, diff); - // Binary - jedis.sadd(bfoo, bx); - jedis.sadd(bfoo, ba); - jedis.sadd(bfoo, bb); - jedis.sadd(bfoo, bc); + // Binary + jedis.sadd(bfoo, bx); + jedis.sadd(bfoo, ba); + jedis.sadd(bfoo, bb); + jedis.sadd(bfoo, bc); - jedis.sadd(bbar, bc); + jedis.sadd(bbar, bc); - jedis.sadd(bcar, ba); - jedis.sadd(bcar, bd); + jedis.sadd(bcar, ba); + jedis.sadd(bcar, bd); - Set bexpected = new HashSet(); - bexpected.add(bb); - bexpected.add(bx); + Set bexpected = new HashSet(); + bexpected.add(bb); + bexpected.add(bx); - Set bdiff = jedis.sdiff(bfoo, bbar, bcar); - assertEquals(bexpected, bdiff); + Set bdiff = jedis.sdiff(bfoo, bbar, bcar); + assertEquals(bexpected, bdiff); } @Test public void sdiffstore() { - jedis.sadd("foo", "x"); - jedis.sadd("foo", "a"); - jedis.sadd("foo", "b"); - jedis.sadd("foo", "c"); + jedis.sadd("foo", "x"); + jedis.sadd("foo", "a"); + jedis.sadd("foo", "b"); + jedis.sadd("foo", "c"); - jedis.sadd("bar", "c"); + jedis.sadd("bar", "c"); - jedis.sadd("car", "a"); - jedis.sadd("car", "d"); + jedis.sadd("car", "a"); + jedis.sadd("car", "d"); - Set expected = new HashSet(); - expected.add("d"); - expected.add("a"); + Set expected = new HashSet(); + expected.add("d"); + expected.add("a"); - long status = jedis.sdiffstore("tar", "foo", "bar", "car"); - assertEquals(2, status); - assertEquals(expected, jedis.smembers("car")); + long status = jedis.sdiffstore("tar", "foo", "bar", "car"); + assertEquals(2, status); + assertEquals(expected, jedis.smembers("car")); - // Binary - jedis.sadd(bfoo, bx); - jedis.sadd(bfoo, ba); - jedis.sadd(bfoo, bb); - jedis.sadd(bfoo, bc); + // Binary + jedis.sadd(bfoo, bx); + jedis.sadd(bfoo, ba); + jedis.sadd(bfoo, bb); + jedis.sadd(bfoo, bc); - jedis.sadd(bbar, bc); + jedis.sadd(bbar, bc); - jedis.sadd(bcar, ba); - jedis.sadd(bcar, bd); + jedis.sadd(bcar, ba); + jedis.sadd(bcar, bd); - Set bexpected = new HashSet(); - bexpected.add(bd); - bexpected.add(ba); + Set bexpected = new HashSet(); + bexpected.add(bd); + bexpected.add(ba); - long bstatus = jedis.sdiffstore("tar".getBytes(), bfoo, bbar, bcar); - assertEquals(2, bstatus); - assertEquals(bexpected, jedis.smembers(bcar)); + long bstatus = jedis.sdiffstore("tar".getBytes(), bfoo, bbar, bcar); + assertEquals(2, bstatus); + assertEquals(bexpected, jedis.smembers(bcar)); } @Test public void srandmember() { - jedis.sadd("foo", "a"); - jedis.sadd("foo", "b"); + jedis.sadd("foo", "a"); + jedis.sadd("foo", "b"); - String member = jedis.srandmember("foo"); + String member = jedis.srandmember("foo"); - assertTrue("a".equals(member) || "b".equals(member)); - assertEquals(2, jedis.smembers("foo").size()); + assertTrue("a".equals(member) || "b".equals(member)); + assertEquals(2, jedis.smembers("foo").size()); - member = jedis.srandmember("bar"); - assertNull(member); + member = jedis.srandmember("bar"); + assertNull(member); - // Binary - jedis.sadd(bfoo, ba); - jedis.sadd(bfoo, bb); + // Binary + jedis.sadd(bfoo, ba); + jedis.sadd(bfoo, bb); - byte[] bmember = jedis.srandmember(bfoo); + byte[] bmember = jedis.srandmember(bfoo); - assertTrue(Arrays.equals(ba, bmember) || Arrays.equals(bb, bmember)); - assertEquals(2, jedis.smembers(bfoo).size()); + assertTrue(Arrays.equals(ba, bmember) || Arrays.equals(bb, bmember)); + assertEquals(2, jedis.smembers(bfoo).size()); - bmember = jedis.srandmember(bbar); - assertNull(bmember); + bmember = jedis.srandmember(bbar); + assertNull(bmember); } @Test public void sscan() { - jedis.sadd("foo", "a", "b"); + jedis.sadd("foo", "a", "b"); - ScanResult result = jedis.sscan("foo", SCAN_POINTER_START); + ScanResult result = jedis.sscan("foo", SCAN_POINTER_START); - assertEquals(SCAN_POINTER_START, result.getCursor()); - assertFalse(result.getResult().isEmpty()); + assertEquals(SCAN_POINTER_START, result.getCursor()); + assertFalse(result.getResult().isEmpty()); - // binary - jedis.sadd(bfoo, ba, bb); + // binary + jedis.sadd(bfoo, ba, bb); - ScanResult bResult = jedis.sscan(bfoo, - SCAN_POINTER_START_BINARY); + ScanResult bResult = jedis.sscan(bfoo, + SCAN_POINTER_START_BINARY); - assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes()); - assertFalse(bResult.getResult().isEmpty()); + assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes()); + assertFalse(bResult.getResult().isEmpty()); } @Test public void sscanMatch() { - ScanParams params = new ScanParams(); - params.match("a*"); + ScanParams params = new ScanParams(); + params.match("a*"); - jedis.sadd("foo", "b", "a", "aa"); - ScanResult result = jedis.sscan("foo", SCAN_POINTER_START, - params); + jedis.sadd("foo", "b", "a", "aa"); + ScanResult result = jedis.sscan("foo", SCAN_POINTER_START, + params); - assertEquals(SCAN_POINTER_START, result.getCursor()); - assertFalse(result.getResult().isEmpty()); + assertEquals(SCAN_POINTER_START, result.getCursor()); + assertFalse(result.getResult().isEmpty()); - // binary - params = new ScanParams(); - params.match(bbarstar); + // binary + params = new ScanParams(); + params.match(bbarstar); - jedis.sadd(bfoo, bbar1, bbar2, bbar3); - ScanResult bResult = jedis.sscan(bfoo, - SCAN_POINTER_START_BINARY, params); + jedis.sadd(bfoo, bbar1, bbar2, bbar3); + ScanResult bResult = jedis.sscan(bfoo, + SCAN_POINTER_START_BINARY, params); - assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes()); - assertFalse(bResult.getResult().isEmpty()); + assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes()); + assertFalse(bResult.getResult().isEmpty()); } @Test public void sscanCount() { - ScanParams params = new ScanParams(); - params.count(2); + ScanParams params = new ScanParams(); + params.count(2); - jedis.sadd("foo", "a1", "a2", "a3", "a4", "a5"); + jedis.sadd("foo", "a1", "a2", "a3", "a4", "a5"); - ScanResult result = jedis.sscan("foo", SCAN_POINTER_START, - params); + ScanResult result = jedis.sscan("foo", SCAN_POINTER_START, + params); - assertFalse(result.getResult().isEmpty()); + assertFalse(result.getResult().isEmpty()); - // binary - params = new ScanParams(); - params.count(2); + // binary + params = new ScanParams(); + params.count(2); - jedis.sadd(bfoo, bbar1, bbar2, bbar3); - ScanResult bResult = jedis.sscan(bfoo, - SCAN_POINTER_START_BINARY, params); + jedis.sadd(bfoo, bbar1, bbar2, bbar3); + ScanResult bResult = jedis.sscan(bfoo, + SCAN_POINTER_START_BINARY, params); - assertFalse(bResult.getResult().isEmpty()); + assertFalse(bResult.getResult().isEmpty()); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/commands/SlowlogCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/SlowlogCommandsTest.java index 55ba9c9..f7a8c2a 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/SlowlogCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/SlowlogCommandsTest.java @@ -10,39 +10,39 @@ public class SlowlogCommandsTest extends JedisCommandTestBase { @Test public void slowlog() { - // do something - jedis.configSet("slowlog-log-slower-than", "0"); - jedis.set("foo", "bar"); - jedis.set("foo2", "bar2"); + // do something + jedis.configSet("slowlog-log-slower-than", "0"); + jedis.set("foo", "bar"); + jedis.set("foo2", "bar2"); - List reducedLog = jedis.slowlogGet(1); - assertEquals(1, reducedLog.size()); + List reducedLog = jedis.slowlogGet(1); + assertEquals(1, reducedLog.size()); - Slowlog log = reducedLog.get(0); - assertTrue(log.getId() > 0); - assertTrue(log.getTimeStamp() > 0); - assertTrue(log.getExecutionTime() > 0); - assertNotNull(log.getArgs()); + Slowlog log = reducedLog.get(0); + assertTrue(log.getId() > 0); + assertTrue(log.getTimeStamp() > 0); + assertTrue(log.getExecutionTime() > 0); + assertNotNull(log.getArgs()); - List breducedLog = jedis.slowlogGetBinary(1); - assertEquals(1, breducedLog.size()); + List breducedLog = jedis.slowlogGetBinary(1); + assertEquals(1, breducedLog.size()); - List log1 = jedis.slowlogGet(); - List blog1 = jedis.slowlogGetBinary(); + List log1 = jedis.slowlogGet(); + List blog1 = jedis.slowlogGetBinary(); - assertNotNull(log1); - assertNotNull(blog1); + assertNotNull(log1); + assertNotNull(blog1); - long len1 = jedis.slowlogLen(); + long len1 = jedis.slowlogLen(); - jedis.slowlogReset(); + jedis.slowlogReset(); - List log2 = jedis.slowlogGet(); - List blog2 = jedis.slowlogGetBinary(); - long len2 = jedis.slowlogLen(); + List log2 = jedis.slowlogGet(); + List blog2 = jedis.slowlogGetBinary(); + long len2 = jedis.slowlogLen(); - assertTrue(len1 > len2); - assertTrue(log1.size() > log2.size()); - assertTrue(blog1.size() > blog2.size()); + assertTrue(len1 > len2); + assertTrue(log1.size() > log2.size()); + assertTrue(blog1.size() > blog2.size()); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/commands/SortedSetCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/SortedSetCommandsTest.java index 8e5cb98..852ce1e 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/SortedSetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/SortedSetCommandsTest.java @@ -33,1109 +33,1109 @@ public class SortedSetCommandsTest extends JedisCommandTestBase { @Test public void zadd() { - long status = jedis.zadd("foo", 1d, "a"); - assertEquals(1, status); + long status = jedis.zadd("foo", 1d, "a"); + assertEquals(1, status); - status = jedis.zadd("foo", 10d, "b"); - assertEquals(1, status); + status = jedis.zadd("foo", 10d, "b"); + assertEquals(1, status); - status = jedis.zadd("foo", 0.1d, "c"); - assertEquals(1, status); + status = jedis.zadd("foo", 0.1d, "c"); + assertEquals(1, status); - status = jedis.zadd("foo", 2d, "a"); - assertEquals(0, status); + status = jedis.zadd("foo", 2d, "a"); + assertEquals(0, status); - // Binary - long bstatus = jedis.zadd(bfoo, 1d, ba); - assertEquals(1, bstatus); + // Binary + long bstatus = jedis.zadd(bfoo, 1d, ba); + assertEquals(1, bstatus); - bstatus = jedis.zadd(bfoo, 10d, bb); - assertEquals(1, bstatus); + bstatus = jedis.zadd(bfoo, 10d, bb); + assertEquals(1, bstatus); - bstatus = jedis.zadd(bfoo, 0.1d, bc); - assertEquals(1, bstatus); + bstatus = jedis.zadd(bfoo, 0.1d, bc); + assertEquals(1, bstatus); - bstatus = jedis.zadd(bfoo, 2d, ba); - assertEquals(0, bstatus); + bstatus = jedis.zadd(bfoo, 2d, ba); + assertEquals(0, bstatus); } @Test public void zrange() { - jedis.zadd("foo", 1d, "a"); - jedis.zadd("foo", 10d, "b"); - jedis.zadd("foo", 0.1d, "c"); - jedis.zadd("foo", 2d, "a"); + jedis.zadd("foo", 1d, "a"); + jedis.zadd("foo", 10d, "b"); + jedis.zadd("foo", 0.1d, "c"); + jedis.zadd("foo", 2d, "a"); - Set expected = new LinkedHashSet(); - expected.add("c"); - expected.add("a"); + Set expected = new LinkedHashSet(); + expected.add("c"); + expected.add("a"); - Set range = jedis.zrange("foo", 0, 1); - assertEquals(expected, range); + Set range = jedis.zrange("foo", 0, 1); + assertEquals(expected, range); - expected.add("b"); - range = jedis.zrange("foo", 0, 100); - assertEquals(expected, range); + expected.add("b"); + range = jedis.zrange("foo", 0, 100); + assertEquals(expected, range); - // Binary - jedis.zadd(bfoo, 1d, ba); - jedis.zadd(bfoo, 10d, bb); - jedis.zadd(bfoo, 0.1d, bc); - jedis.zadd(bfoo, 2d, ba); + // Binary + jedis.zadd(bfoo, 1d, ba); + jedis.zadd(bfoo, 10d, bb); + jedis.zadd(bfoo, 0.1d, bc); + jedis.zadd(bfoo, 2d, ba); - Set bexpected = new LinkedHashSet(); - bexpected.add(bc); - bexpected.add(ba); + Set bexpected = new LinkedHashSet(); + bexpected.add(bc); + bexpected.add(ba); - Set brange = jedis.zrange(bfoo, 0, 1); - assertEquals(bexpected, brange); + Set brange = jedis.zrange(bfoo, 0, 1); + assertEquals(bexpected, brange); - bexpected.add(bb); - brange = jedis.zrange(bfoo, 0, 100); - assertEquals(bexpected, brange); + bexpected.add(bb); + brange = jedis.zrange(bfoo, 0, 100); + assertEquals(bexpected, brange); } @Test public void zrangeByLex() { - jedis.zadd("foo", 1, "aa"); - jedis.zadd("foo", 1, "c"); - jedis.zadd("foo", 1, "bb"); - jedis.zadd("foo", 1, "d"); + jedis.zadd("foo", 1, "aa"); + jedis.zadd("foo", 1, "c"); + jedis.zadd("foo", 1, "bb"); + jedis.zadd("foo", 1, "d"); - Set expected = new LinkedHashSet(); - expected.add("bb"); - expected.add("c"); + Set expected = new LinkedHashSet(); + expected.add("bb"); + expected.add("c"); - // exclusive aa ~ inclusive c - assertEquals(expected, jedis.zrangeByLex("foo", "(aa", "[c")); + // exclusive aa ~ inclusive c + assertEquals(expected, jedis.zrangeByLex("foo", "(aa", "[c")); - expected.clear(); - expected.add("bb"); - expected.add("c"); + expected.clear(); + expected.add("bb"); + expected.add("c"); - // with LIMIT - assertEquals(expected, jedis.zrangeByLex("foo", "-", "+", 1, 2)); + // with LIMIT + assertEquals(expected, jedis.zrangeByLex("foo", "-", "+", 1, 2)); } @Test public void zrangeByLexBinary() { - // binary - jedis.zadd(bfoo, 1, ba); - jedis.zadd(bfoo, 1, bc); - jedis.zadd(bfoo, 1, bb); + // binary + jedis.zadd(bfoo, 1, ba); + jedis.zadd(bfoo, 1, bc); + jedis.zadd(bfoo, 1, bb); - Set bExpected = new LinkedHashSet(); - bExpected.add(bb); + Set bExpected = new LinkedHashSet(); + 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); + bExpected.clear(); + bExpected.add(ba); + bExpected.add(bb); - // with LIMIT - assertEquals(bExpected, - jedis.zrangeByLex(bfoo, bLexMinusInf, bLexPlusInf, 0, 2)); + // with LIMIT + assertEquals(bExpected, + jedis.zrangeByLex(bfoo, bLexMinusInf, bLexPlusInf, 0, 2)); } @Test public void zrevrangeByLex() { - jedis.zadd("foo", 1, "aa"); - jedis.zadd("foo", 1, "c"); - jedis.zadd("foo", 1, "bb"); - jedis.zadd("foo", 1, "d"); + jedis.zadd("foo", 1, "aa"); + jedis.zadd("foo", 1, "c"); + jedis.zadd("foo", 1, "bb"); + jedis.zadd("foo", 1, "d"); - Set expected = new LinkedHashSet(); - expected.add("c"); - expected.add("bb"); + Set expected = new LinkedHashSet(); + expected.add("c"); + expected.add("bb"); - // exclusive aa ~ inclusive c - assertEquals(expected, jedis.zrevrangeByLex("foo", "[c", "(aa")); + // exclusive aa ~ inclusive c + assertEquals(expected, jedis.zrevrangeByLex("foo", "[c", "(aa")); - expected.clear(); - expected.add("c"); - expected.add("bb"); + expected.clear(); + expected.add("c"); + expected.add("bb"); - // with LIMIT - assertEquals(expected, jedis.zrevrangeByLex("foo", "+", "-", 1, 2)); + // with LIMIT + assertEquals(expected, jedis.zrevrangeByLex("foo", "+", "-", 1, 2)); } @Test public void zrevrangeByLexBinary() { - // binary - jedis.zadd(bfoo, 1, ba); - jedis.zadd(bfoo, 1, bc); - jedis.zadd(bfoo, 1, bb); + // binary + jedis.zadd(bfoo, 1, ba); + jedis.zadd(bfoo, 1, bc); + jedis.zadd(bfoo, 1, bb); - Set bExpected = new LinkedHashSet(); - bExpected.add(bb); + Set bExpected = new LinkedHashSet(); + 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); + bExpected.clear(); + bExpected.add(bb); + bExpected.add(ba); - // with LIMIT - assertEquals(bExpected, - jedis.zrevrangeByLex(bfoo, bLexPlusInf, bLexMinusInf, 0, 2)); + // with LIMIT + assertEquals(bExpected, + jedis.zrevrangeByLex(bfoo, bLexPlusInf, bLexMinusInf, 0, 2)); } @Test public void zrevrange() { - jedis.zadd("foo", 1d, "a"); - jedis.zadd("foo", 10d, "b"); - jedis.zadd("foo", 0.1d, "c"); - jedis.zadd("foo", 2d, "a"); + jedis.zadd("foo", 1d, "a"); + jedis.zadd("foo", 10d, "b"); + jedis.zadd("foo", 0.1d, "c"); + jedis.zadd("foo", 2d, "a"); - Set expected = new LinkedHashSet(); - expected.add("b"); - expected.add("a"); + Set expected = new LinkedHashSet(); + expected.add("b"); + expected.add("a"); - Set range = jedis.zrevrange("foo", 0, 1); - assertEquals(expected, range); + Set range = jedis.zrevrange("foo", 0, 1); + assertEquals(expected, range); - expected.add("c"); - range = jedis.zrevrange("foo", 0, 100); - assertEquals(expected, range); + expected.add("c"); + range = jedis.zrevrange("foo", 0, 100); + assertEquals(expected, range); - // Binary - jedis.zadd(bfoo, 1d, ba); - jedis.zadd(bfoo, 10d, bb); - jedis.zadd(bfoo, 0.1d, bc); - jedis.zadd(bfoo, 2d, ba); + // Binary + jedis.zadd(bfoo, 1d, ba); + jedis.zadd(bfoo, 10d, bb); + jedis.zadd(bfoo, 0.1d, bc); + jedis.zadd(bfoo, 2d, ba); - Set bexpected = new LinkedHashSet(); - bexpected.add(bb); - bexpected.add(ba); + Set bexpected = new LinkedHashSet(); + bexpected.add(bb); + bexpected.add(ba); - Set brange = jedis.zrevrange(bfoo, 0, 1); - assertEquals(bexpected, brange); + Set brange = jedis.zrevrange(bfoo, 0, 1); + assertEquals(bexpected, brange); - bexpected.add(bc); - brange = jedis.zrevrange(bfoo, 0, 100); - assertEquals(bexpected, brange); + bexpected.add(bc); + brange = jedis.zrevrange(bfoo, 0, 100); + assertEquals(bexpected, brange); } @Test public void zrem() { - jedis.zadd("foo", 1d, "a"); - jedis.zadd("foo", 2d, "b"); + jedis.zadd("foo", 1d, "a"); + jedis.zadd("foo", 2d, "b"); - long status = jedis.zrem("foo", "a"); + long status = jedis.zrem("foo", "a"); - Set expected = new LinkedHashSet(); - expected.add("b"); + Set expected = new LinkedHashSet(); + expected.add("b"); - assertEquals(1, status); - assertEquals(expected, jedis.zrange("foo", 0, 100)); + assertEquals(1, status); + assertEquals(expected, jedis.zrange("foo", 0, 100)); - status = jedis.zrem("foo", "bar"); + status = jedis.zrem("foo", "bar"); - assertEquals(0, status); + assertEquals(0, status); - // Binary - jedis.zadd(bfoo, 1d, ba); - jedis.zadd(bfoo, 2d, bb); + // Binary + jedis.zadd(bfoo, 1d, ba); + jedis.zadd(bfoo, 2d, bb); - long bstatus = jedis.zrem(bfoo, ba); + long bstatus = jedis.zrem(bfoo, ba); - Set bexpected = new LinkedHashSet(); - bexpected.add(bb); + Set bexpected = new LinkedHashSet(); + bexpected.add(bb); - assertEquals(1, bstatus); - assertEquals(bexpected, jedis.zrange(bfoo, 0, 100)); + assertEquals(1, bstatus); + assertEquals(bexpected, jedis.zrange(bfoo, 0, 100)); - bstatus = jedis.zrem(bfoo, bbar); + bstatus = jedis.zrem(bfoo, bbar); - assertEquals(0, bstatus); + assertEquals(0, bstatus); } @Test public void zincrby() { - jedis.zadd("foo", 1d, "a"); - jedis.zadd("foo", 2d, "b"); + jedis.zadd("foo", 1d, "a"); + jedis.zadd("foo", 2d, "b"); - double score = jedis.zincrby("foo", 2d, "a"); + double score = jedis.zincrby("foo", 2d, "a"); - Set expected = new LinkedHashSet(); - expected.add("a"); - expected.add("b"); + Set expected = new LinkedHashSet(); + expected.add("a"); + expected.add("b"); - assertEquals(3d, score, 0); - assertEquals(expected, jedis.zrange("foo", 0, 100)); + assertEquals(3d, score, 0); + assertEquals(expected, jedis.zrange("foo", 0, 100)); - // Binary - jedis.zadd(bfoo, 1d, ba); - jedis.zadd(bfoo, 2d, bb); + // Binary + jedis.zadd(bfoo, 1d, ba); + jedis.zadd(bfoo, 2d, bb); - double bscore = jedis.zincrby(bfoo, 2d, ba); + double bscore = jedis.zincrby(bfoo, 2d, ba); - Set bexpected = new LinkedHashSet(); - bexpected.add(bb); - bexpected.add(ba); + Set bexpected = new LinkedHashSet(); + bexpected.add(bb); + bexpected.add(ba); - assertEquals(3d, bscore, 0); - assertEquals(bexpected, jedis.zrange(bfoo, 0, 100)); + assertEquals(3d, bscore, 0); + assertEquals(bexpected, jedis.zrange(bfoo, 0, 100)); } @Test public void zrank() { - jedis.zadd("foo", 1d, "a"); - jedis.zadd("foo", 2d, "b"); + jedis.zadd("foo", 1d, "a"); + jedis.zadd("foo", 2d, "b"); - long rank = jedis.zrank("foo", "a"); - assertEquals(0, rank); + long rank = jedis.zrank("foo", "a"); + assertEquals(0, rank); - rank = jedis.zrank("foo", "b"); - assertEquals(1, rank); + rank = jedis.zrank("foo", "b"); + assertEquals(1, rank); - assertNull(jedis.zrank("car", "b")); + assertNull(jedis.zrank("car", "b")); - // Binary - jedis.zadd(bfoo, 1d, ba); - jedis.zadd(bfoo, 2d, bb); + // Binary + jedis.zadd(bfoo, 1d, ba); + jedis.zadd(bfoo, 2d, bb); - long brank = jedis.zrank(bfoo, ba); - assertEquals(0, brank); + long brank = jedis.zrank(bfoo, ba); + assertEquals(0, brank); - brank = jedis.zrank(bfoo, bb); - assertEquals(1, brank); + brank = jedis.zrank(bfoo, bb); + assertEquals(1, brank); - assertNull(jedis.zrank(bcar, bb)); + assertNull(jedis.zrank(bcar, bb)); } @Test public void zrevrank() { - jedis.zadd("foo", 1d, "a"); - jedis.zadd("foo", 2d, "b"); + jedis.zadd("foo", 1d, "a"); + jedis.zadd("foo", 2d, "b"); - long rank = jedis.zrevrank("foo", "a"); - assertEquals(1, rank); + long rank = jedis.zrevrank("foo", "a"); + assertEquals(1, rank); - rank = jedis.zrevrank("foo", "b"); - assertEquals(0, rank); + rank = jedis.zrevrank("foo", "b"); + assertEquals(0, rank); - // Binary - jedis.zadd(bfoo, 1d, ba); - jedis.zadd(bfoo, 2d, bb); + // Binary + jedis.zadd(bfoo, 1d, ba); + jedis.zadd(bfoo, 2d, bb); - long brank = jedis.zrevrank(bfoo, ba); - assertEquals(1, brank); + long brank = jedis.zrevrank(bfoo, ba); + assertEquals(1, brank); - brank = jedis.zrevrank(bfoo, bb); - assertEquals(0, brank); + brank = jedis.zrevrank(bfoo, bb); + assertEquals(0, brank); } @Test public void zrangeWithScores() { - jedis.zadd("foo", 1d, "a"); - jedis.zadd("foo", 10d, "b"); - jedis.zadd("foo", 0.1d, "c"); - jedis.zadd("foo", 2d, "a"); + jedis.zadd("foo", 1d, "a"); + jedis.zadd("foo", 10d, "b"); + jedis.zadd("foo", 0.1d, "c"); + jedis.zadd("foo", 2d, "a"); - Set expected = new LinkedHashSet(); - expected.add(new Tuple("c", 0.1d)); - expected.add(new Tuple("a", 2d)); + Set expected = new LinkedHashSet(); + expected.add(new Tuple("c", 0.1d)); + expected.add(new Tuple("a", 2d)); - Set range = jedis.zrangeWithScores("foo", 0, 1); - assertEquals(expected, range); + Set range = jedis.zrangeWithScores("foo", 0, 1); + assertEquals(expected, range); - expected.add(new Tuple("b", 10d)); - range = jedis.zrangeWithScores("foo", 0, 100); - assertEquals(expected, range); + expected.add(new Tuple("b", 10d)); + range = jedis.zrangeWithScores("foo", 0, 100); + assertEquals(expected, range); - // Binary - jedis.zadd(bfoo, 1d, ba); - jedis.zadd(bfoo, 10d, bb); - jedis.zadd(bfoo, 0.1d, bc); - jedis.zadd(bfoo, 2d, ba); + // Binary + jedis.zadd(bfoo, 1d, ba); + jedis.zadd(bfoo, 10d, bb); + jedis.zadd(bfoo, 0.1d, bc); + jedis.zadd(bfoo, 2d, ba); - Set bexpected = new LinkedHashSet(); - bexpected.add(new Tuple(bc, 0.1d)); - bexpected.add(new Tuple(ba, 2d)); + Set bexpected = new LinkedHashSet(); + bexpected.add(new Tuple(bc, 0.1d)); + bexpected.add(new Tuple(ba, 2d)); - Set brange = jedis.zrangeWithScores(bfoo, 0, 1); - assertEquals(bexpected, brange); + Set brange = jedis.zrangeWithScores(bfoo, 0, 1); + assertEquals(bexpected, brange); - bexpected.add(new Tuple(bb, 10d)); - brange = jedis.zrangeWithScores(bfoo, 0, 100); - assertEquals(bexpected, brange); + bexpected.add(new Tuple(bb, 10d)); + brange = jedis.zrangeWithScores(bfoo, 0, 100); + assertEquals(bexpected, brange); } @Test public void zrevrangeWithScores() { - jedis.zadd("foo", 1d, "a"); - jedis.zadd("foo", 10d, "b"); - jedis.zadd("foo", 0.1d, "c"); - jedis.zadd("foo", 2d, "a"); + jedis.zadd("foo", 1d, "a"); + jedis.zadd("foo", 10d, "b"); + jedis.zadd("foo", 0.1d, "c"); + jedis.zadd("foo", 2d, "a"); - Set expected = new LinkedHashSet(); - expected.add(new Tuple("b", 10d)); - expected.add(new Tuple("a", 2d)); + Set expected = new LinkedHashSet(); + expected.add(new Tuple("b", 10d)); + expected.add(new Tuple("a", 2d)); - Set range = jedis.zrevrangeWithScores("foo", 0, 1); - assertEquals(expected, range); + Set range = jedis.zrevrangeWithScores("foo", 0, 1); + assertEquals(expected, range); - expected.add(new Tuple("c", 0.1d)); - range = jedis.zrevrangeWithScores("foo", 0, 100); - assertEquals(expected, range); + expected.add(new Tuple("c", 0.1d)); + range = jedis.zrevrangeWithScores("foo", 0, 100); + assertEquals(expected, range); - // Binary - jedis.zadd(bfoo, 1d, ba); - jedis.zadd(bfoo, 10d, bb); - jedis.zadd(bfoo, 0.1d, bc); - jedis.zadd(bfoo, 2d, ba); + // Binary + jedis.zadd(bfoo, 1d, ba); + jedis.zadd(bfoo, 10d, bb); + jedis.zadd(bfoo, 0.1d, bc); + jedis.zadd(bfoo, 2d, ba); - Set bexpected = new LinkedHashSet(); - bexpected.add(new Tuple(bb, 10d)); - bexpected.add(new Tuple(ba, 2d)); + Set bexpected = new LinkedHashSet(); + bexpected.add(new Tuple(bb, 10d)); + bexpected.add(new Tuple(ba, 2d)); - Set brange = jedis.zrevrangeWithScores(bfoo, 0, 1); - assertEquals(bexpected, brange); + Set brange = jedis.zrevrangeWithScores(bfoo, 0, 1); + assertEquals(bexpected, brange); - bexpected.add(new Tuple(bc, 0.1d)); - brange = jedis.zrevrangeWithScores(bfoo, 0, 100); - assertEquals(bexpected, brange); + bexpected.add(new Tuple(bc, 0.1d)); + brange = jedis.zrevrangeWithScores(bfoo, 0, 100); + assertEquals(bexpected, brange); } @Test public void zcard() { - jedis.zadd("foo", 1d, "a"); - jedis.zadd("foo", 10d, "b"); - jedis.zadd("foo", 0.1d, "c"); - jedis.zadd("foo", 2d, "a"); + jedis.zadd("foo", 1d, "a"); + jedis.zadd("foo", 10d, "b"); + jedis.zadd("foo", 0.1d, "c"); + jedis.zadd("foo", 2d, "a"); - long size = jedis.zcard("foo"); - assertEquals(3, size); + long size = jedis.zcard("foo"); + assertEquals(3, size); - // Binary - jedis.zadd(bfoo, 1d, ba); - jedis.zadd(bfoo, 10d, bb); - jedis.zadd(bfoo, 0.1d, bc); - jedis.zadd(bfoo, 2d, ba); + // Binary + jedis.zadd(bfoo, 1d, ba); + jedis.zadd(bfoo, 10d, bb); + jedis.zadd(bfoo, 0.1d, bc); + jedis.zadd(bfoo, 2d, ba); - long bsize = jedis.zcard(bfoo); - assertEquals(3, bsize); + long bsize = jedis.zcard(bfoo); + assertEquals(3, bsize); } @Test public void zscore() { - jedis.zadd("foo", 1d, "a"); - jedis.zadd("foo", 10d, "b"); - jedis.zadd("foo", 0.1d, "c"); - jedis.zadd("foo", 2d, "a"); + jedis.zadd("foo", 1d, "a"); + jedis.zadd("foo", 10d, "b"); + jedis.zadd("foo", 0.1d, "c"); + jedis.zadd("foo", 2d, "a"); - Double score = jedis.zscore("foo", "b"); - assertEquals((Double) 10d, score); + Double score = jedis.zscore("foo", "b"); + assertEquals((Double) 10d, score); - score = jedis.zscore("foo", "c"); - assertEquals((Double) 0.1d, score); + score = jedis.zscore("foo", "c"); + assertEquals((Double) 0.1d, score); - score = jedis.zscore("foo", "s"); - assertNull(score); + score = jedis.zscore("foo", "s"); + assertNull(score); - // Binary - jedis.zadd(bfoo, 1d, ba); - jedis.zadd(bfoo, 10d, bb); - jedis.zadd(bfoo, 0.1d, bc); - jedis.zadd(bfoo, 2d, ba); + // Binary + jedis.zadd(bfoo, 1d, ba); + jedis.zadd(bfoo, 10d, bb); + jedis.zadd(bfoo, 0.1d, bc); + jedis.zadd(bfoo, 2d, ba); - Double bscore = jedis.zscore(bfoo, bb); - assertEquals((Double) 10d, bscore); + Double bscore = jedis.zscore(bfoo, bb); + assertEquals((Double) 10d, bscore); - bscore = jedis.zscore(bfoo, bc); - assertEquals((Double) 0.1d, bscore); + bscore = jedis.zscore(bfoo, bc); + assertEquals((Double) 0.1d, bscore); - bscore = jedis.zscore(bfoo, SafeEncoder.encode("s")); - assertNull(bscore); + bscore = jedis.zscore(bfoo, SafeEncoder.encode("s")); + assertNull(bscore); } @Test public void zcount() { - jedis.zadd("foo", 1d, "a"); - jedis.zadd("foo", 10d, "b"); - jedis.zadd("foo", 0.1d, "c"); - jedis.zadd("foo", 2d, "a"); + jedis.zadd("foo", 1d, "a"); + jedis.zadd("foo", 10d, "b"); + jedis.zadd("foo", 0.1d, "c"); + jedis.zadd("foo", 2d, "a"); - long result = jedis.zcount("foo", 0.01d, 2.1d); + long result = jedis.zcount("foo", 0.01d, 2.1d); - assertEquals(2, result); + assertEquals(2, result); - result = jedis.zcount("foo", "(0.01", "+inf"); + result = jedis.zcount("foo", "(0.01", "+inf"); - assertEquals(3, result); + assertEquals(3, result); - // Binary - jedis.zadd(bfoo, 1d, ba); - jedis.zadd(bfoo, 10d, bb); - jedis.zadd(bfoo, 0.1d, bc); - jedis.zadd(bfoo, 2d, ba); + // Binary + jedis.zadd(bfoo, 1d, ba); + jedis.zadd(bfoo, 10d, bb); + jedis.zadd(bfoo, 0.1d, bc); + jedis.zadd(bfoo, 2d, ba); - long bresult = jedis.zcount(bfoo, 0.01d, 2.1d); + long bresult = jedis.zcount(bfoo, 0.01d, 2.1d); - assertEquals(2, bresult); + assertEquals(2, bresult); - bresult = jedis.zcount(bfoo, SafeEncoder.encode("(0.01"), - SafeEncoder.encode("+inf")); + bresult = jedis.zcount(bfoo, SafeEncoder.encode("(0.01"), + SafeEncoder.encode("+inf")); - assertEquals(3, bresult); + assertEquals(3, bresult); } @Test public void zlexcount() { - jedis.zadd("foo", 1, "a"); - jedis.zadd("foo", 1, "b"); - jedis.zadd("foo", 1, "c"); - jedis.zadd("foo", 1, "aa"); + jedis.zadd("foo", 1, "a"); + jedis.zadd("foo", 1, "b"); + jedis.zadd("foo", 1, "c"); + jedis.zadd("foo", 1, "aa"); - long result = jedis.zlexcount("foo", "[aa", "(c"); - assertEquals(2, result); + long result = jedis.zlexcount("foo", "[aa", "(c"); + assertEquals(2, result); - result = jedis.zlexcount("foo", "-", "+"); - assertEquals(4, result); + result = jedis.zlexcount("foo", "-", "+"); + assertEquals(4, result); - result = jedis.zlexcount("foo", "-", "(c"); - assertEquals(3, result); + result = jedis.zlexcount("foo", "-", "(c"); + assertEquals(3, result); - result = jedis.zlexcount("foo", "[aa", "+"); - assertEquals(3, result); + result = jedis.zlexcount("foo", "[aa", "+"); + assertEquals(3, result); } @Test public void zlexcountBinary() { - // Binary - jedis.zadd(bfoo, 1, ba); - jedis.zadd(bfoo, 1, bc); - jedis.zadd(bfoo, 1, bb); + // Binary + jedis.zadd(bfoo, 1, ba); + jedis.zadd(bfoo, 1, bc); + jedis.zadd(bfoo, 1, bb); - long result = jedis.zlexcount(bfoo, bInclusiveB, bExclusiveC); - assertEquals(1, result); + long result = jedis.zlexcount(bfoo, bInclusiveB, bExclusiveC); + assertEquals(1, result); - result = jedis.zlexcount(bfoo, bLexMinusInf, bLexPlusInf); - assertEquals(3, result); + result = jedis.zlexcount(bfoo, bLexMinusInf, bLexPlusInf); + assertEquals(3, result); } @Test public void zrangebyscore() { - jedis.zadd("foo", 1d, "a"); - jedis.zadd("foo", 10d, "b"); - jedis.zadd("foo", 0.1d, "c"); - jedis.zadd("foo", 2d, "a"); + jedis.zadd("foo", 1d, "a"); + jedis.zadd("foo", 10d, "b"); + jedis.zadd("foo", 0.1d, "c"); + jedis.zadd("foo", 2d, "a"); - Set range = jedis.zrangeByScore("foo", 0d, 2d); + Set range = jedis.zrangeByScore("foo", 0d, 2d); - Set expected = new LinkedHashSet(); - expected.add("c"); - expected.add("a"); + Set expected = new LinkedHashSet(); + expected.add("c"); + expected.add("a"); - assertEquals(expected, range); + assertEquals(expected, range); - range = jedis.zrangeByScore("foo", 0d, 2d, 0, 1); + range = jedis.zrangeByScore("foo", 0d, 2d, 0, 1); - expected = new LinkedHashSet(); - expected.add("c"); + expected = new LinkedHashSet(); + expected.add("c"); - assertEquals(expected, range); + assertEquals(expected, range); - range = jedis.zrangeByScore("foo", 0d, 2d, 1, 1); - Set range2 = jedis.zrangeByScore("foo", "-inf", "(2"); - assertEquals(expected, range2); + range = jedis.zrangeByScore("foo", 0d, 2d, 1, 1); + Set range2 = jedis.zrangeByScore("foo", "-inf", "(2"); + assertEquals(expected, range2); - expected = new LinkedHashSet(); - expected.add("a"); + expected = new LinkedHashSet(); + expected.add("a"); - assertEquals(expected, range); + assertEquals(expected, range); - // Binary - jedis.zadd(bfoo, 1d, ba); - jedis.zadd(bfoo, 10d, bb); - jedis.zadd(bfoo, 0.1d, bc); - jedis.zadd(bfoo, 2d, ba); + // Binary + jedis.zadd(bfoo, 1d, ba); + jedis.zadd(bfoo, 10d, bb); + jedis.zadd(bfoo, 0.1d, bc); + jedis.zadd(bfoo, 2d, ba); - Set brange = jedis.zrangeByScore(bfoo, 0d, 2d); + Set brange = jedis.zrangeByScore(bfoo, 0d, 2d); - Set bexpected = new LinkedHashSet(); - bexpected.add(bc); - bexpected.add(ba); + Set bexpected = new LinkedHashSet(); + bexpected.add(bc); + bexpected.add(ba); - assertEquals(bexpected, brange); + assertEquals(bexpected, brange); - brange = jedis.zrangeByScore(bfoo, 0d, 2d, 0, 1); + brange = jedis.zrangeByScore(bfoo, 0d, 2d, 0, 1); - bexpected = new LinkedHashSet(); - bexpected.add(bc); + bexpected = new LinkedHashSet(); + bexpected.add(bc); - assertEquals(bexpected, brange); + assertEquals(bexpected, brange); - brange = jedis.zrangeByScore(bfoo, 0d, 2d, 1, 1); - Set brange2 = jedis.zrangeByScore(bfoo, - SafeEncoder.encode("-inf"), SafeEncoder.encode("(2")); - assertEquals(bexpected, brange2); + brange = jedis.zrangeByScore(bfoo, 0d, 2d, 1, 1); + Set brange2 = jedis.zrangeByScore(bfoo, + SafeEncoder.encode("-inf"), SafeEncoder.encode("(2")); + assertEquals(bexpected, brange2); - bexpected = new LinkedHashSet(); - bexpected.add(ba); + bexpected = new LinkedHashSet(); + bexpected.add(ba); - assertEquals(bexpected, brange); + assertEquals(bexpected, brange); } @Test public void zrevrangebyscore() { - jedis.zadd("foo", 1.0d, "a"); - jedis.zadd("foo", 2.0d, "b"); - jedis.zadd("foo", 3.0d, "c"); - jedis.zadd("foo", 4.0d, "d"); - jedis.zadd("foo", 5.0d, "e"); + jedis.zadd("foo", 1.0d, "a"); + jedis.zadd("foo", 2.0d, "b"); + jedis.zadd("foo", 3.0d, "c"); + jedis.zadd("foo", 4.0d, "d"); + jedis.zadd("foo", 5.0d, "e"); - Set range = jedis.zrevrangeByScore("foo", 3d, - Double.NEGATIVE_INFINITY, 0, 1); - Set expected = new LinkedHashSet(); - expected.add("c"); + Set range = jedis.zrevrangeByScore("foo", 3d, + Double.NEGATIVE_INFINITY, 0, 1); + Set expected = new LinkedHashSet(); + expected.add("c"); - assertEquals(expected, range); + assertEquals(expected, range); - range = jedis.zrevrangeByScore("foo", 3.5d, Double.NEGATIVE_INFINITY, - 0, 2); - expected = new LinkedHashSet(); - expected.add("c"); - expected.add("b"); + range = jedis.zrevrangeByScore("foo", 3.5d, Double.NEGATIVE_INFINITY, + 0, 2); + expected = new LinkedHashSet(); + expected.add("c"); + expected.add("b"); - assertEquals(expected, range); + assertEquals(expected, range); - range = jedis.zrevrangeByScore("foo", 3.5d, Double.NEGATIVE_INFINITY, - 1, 1); - expected = new LinkedHashSet(); - expected.add("b"); + range = jedis.zrevrangeByScore("foo", 3.5d, Double.NEGATIVE_INFINITY, + 1, 1); + expected = new LinkedHashSet(); + expected.add("b"); - assertEquals(expected, range); + assertEquals(expected, range); - range = jedis.zrevrangeByScore("foo", 4d, 2d); - expected = new LinkedHashSet(); - expected.add("d"); - expected.add("c"); - expected.add("b"); + range = jedis.zrevrangeByScore("foo", 4d, 2d); + expected = new LinkedHashSet(); + expected.add("d"); + expected.add("c"); + expected.add("b"); - assertEquals(expected, range); + assertEquals(expected, range); - range = jedis.zrevrangeByScore("foo", "+inf", "(4"); - expected = new LinkedHashSet(); - expected.add("e"); + range = jedis.zrevrangeByScore("foo", "+inf", "(4"); + expected = new LinkedHashSet(); + expected.add("e"); - assertEquals(expected, range); + assertEquals(expected, range); - // Binary - jedis.zadd(bfoo, 1d, ba); - jedis.zadd(bfoo, 10d, bb); - jedis.zadd(bfoo, 0.1d, bc); - jedis.zadd(bfoo, 2d, ba); + // Binary + jedis.zadd(bfoo, 1d, ba); + jedis.zadd(bfoo, 10d, bb); + jedis.zadd(bfoo, 0.1d, bc); + jedis.zadd(bfoo, 2d, ba); - Set brange = jedis.zrevrangeByScore(bfoo, 2d, 0d); + Set brange = jedis.zrevrangeByScore(bfoo, 2d, 0d); - Set bexpected = new LinkedHashSet(); - bexpected.add(bc); - bexpected.add(ba); + Set bexpected = new LinkedHashSet(); + bexpected.add(bc); + bexpected.add(ba); - assertEquals(bexpected, brange); + assertEquals(bexpected, brange); - brange = jedis.zrevrangeByScore(bfoo, 2d, 0d, 0, 1); + brange = jedis.zrevrangeByScore(bfoo, 2d, 0d, 0, 1); - bexpected = new LinkedHashSet(); - bexpected.add(ba); + bexpected = new LinkedHashSet(); + bexpected.add(ba); - assertEquals(bexpected, brange); + assertEquals(bexpected, brange); - Set brange2 = jedis.zrevrangeByScore(bfoo, - SafeEncoder.encode("+inf"), SafeEncoder.encode("(2")); + Set brange2 = jedis.zrevrangeByScore(bfoo, + SafeEncoder.encode("+inf"), SafeEncoder.encode("(2")); - bexpected = new LinkedHashSet(); - bexpected.add(bb); + bexpected = new LinkedHashSet(); + bexpected.add(bb); - assertEquals(bexpected, brange2); + assertEquals(bexpected, brange2); - brange = jedis.zrevrangeByScore(bfoo, 2d, 0d, 1, 1); - bexpected = new LinkedHashSet(); - bexpected.add(bc); + brange = jedis.zrevrangeByScore(bfoo, 2d, 0d, 1, 1); + bexpected = new LinkedHashSet(); + bexpected.add(bc); - assertEquals(bexpected, brange); + assertEquals(bexpected, brange); } @Test public void zrangebyscoreWithScores() { - jedis.zadd("foo", 1d, "a"); - jedis.zadd("foo", 10d, "b"); - jedis.zadd("foo", 0.1d, "c"); - jedis.zadd("foo", 2d, "a"); + jedis.zadd("foo", 1d, "a"); + jedis.zadd("foo", 10d, "b"); + jedis.zadd("foo", 0.1d, "c"); + jedis.zadd("foo", 2d, "a"); - Set range = jedis.zrangeByScoreWithScores("foo", 0d, 2d); + Set range = jedis.zrangeByScoreWithScores("foo", 0d, 2d); - Set expected = new LinkedHashSet(); - expected.add(new Tuple("c", 0.1d)); - expected.add(new Tuple("a", 2d)); + Set expected = new LinkedHashSet(); + expected.add(new Tuple("c", 0.1d)); + expected.add(new Tuple("a", 2d)); - assertEquals(expected, range); + assertEquals(expected, range); - range = jedis.zrangeByScoreWithScores("foo", 0d, 2d, 0, 1); + range = jedis.zrangeByScoreWithScores("foo", 0d, 2d, 0, 1); - expected = new LinkedHashSet(); - expected.add(new Tuple("c", 0.1d)); + expected = new LinkedHashSet(); + expected.add(new Tuple("c", 0.1d)); - assertEquals(expected, range); + assertEquals(expected, range); - range = jedis.zrangeByScoreWithScores("foo", 0d, 2d, 1, 1); + range = jedis.zrangeByScoreWithScores("foo", 0d, 2d, 1, 1); - expected = new LinkedHashSet(); - expected.add(new Tuple("a", 2d)); + expected = new LinkedHashSet(); + expected.add(new Tuple("a", 2d)); - assertEquals(expected, range); + assertEquals(expected, range); - // Binary + // Binary - jedis.zadd(bfoo, 1d, ba); - jedis.zadd(bfoo, 10d, bb); - jedis.zadd(bfoo, 0.1d, bc); - jedis.zadd(bfoo, 2d, ba); + jedis.zadd(bfoo, 1d, ba); + jedis.zadd(bfoo, 10d, bb); + jedis.zadd(bfoo, 0.1d, bc); + jedis.zadd(bfoo, 2d, ba); - Set brange = jedis.zrangeByScoreWithScores(bfoo, 0d, 2d); + Set brange = jedis.zrangeByScoreWithScores(bfoo, 0d, 2d); - Set bexpected = new LinkedHashSet(); - bexpected.add(new Tuple(bc, 0.1d)); - bexpected.add(new Tuple(ba, 2d)); + Set bexpected = new LinkedHashSet(); + bexpected.add(new Tuple(bc, 0.1d)); + bexpected.add(new Tuple(ba, 2d)); - assertEquals(bexpected, brange); + assertEquals(bexpected, brange); - brange = jedis.zrangeByScoreWithScores(bfoo, 0d, 2d, 0, 1); + brange = jedis.zrangeByScoreWithScores(bfoo, 0d, 2d, 0, 1); - bexpected = new LinkedHashSet(); - bexpected.add(new Tuple(bc, 0.1d)); + bexpected = new LinkedHashSet(); + bexpected.add(new Tuple(bc, 0.1d)); - assertEquals(bexpected, brange); + assertEquals(bexpected, brange); - brange = jedis.zrangeByScoreWithScores(bfoo, 0d, 2d, 1, 1); + brange = jedis.zrangeByScoreWithScores(bfoo, 0d, 2d, 1, 1); - bexpected = new LinkedHashSet(); - bexpected.add(new Tuple(ba, 2d)); + bexpected = new LinkedHashSet(); + bexpected.add(new Tuple(ba, 2d)); - assertEquals(bexpected, brange); + assertEquals(bexpected, brange); } @Test public void zrevrangebyscoreWithScores() { - jedis.zadd("foo", 1.0d, "a"); - jedis.zadd("foo", 2.0d, "b"); - jedis.zadd("foo", 3.0d, "c"); - jedis.zadd("foo", 4.0d, "d"); - jedis.zadd("foo", 5.0d, "e"); + jedis.zadd("foo", 1.0d, "a"); + jedis.zadd("foo", 2.0d, "b"); + jedis.zadd("foo", 3.0d, "c"); + jedis.zadd("foo", 4.0d, "d"); + jedis.zadd("foo", 5.0d, "e"); - Set range = jedis.zrevrangeByScoreWithScores("foo", 3d, - Double.NEGATIVE_INFINITY, 0, 1); - Set expected = new LinkedHashSet(); - expected.add(new Tuple("c", 3.0d)); + Set range = jedis.zrevrangeByScoreWithScores("foo", 3d, + Double.NEGATIVE_INFINITY, 0, 1); + Set expected = new LinkedHashSet(); + expected.add(new Tuple("c", 3.0d)); - assertEquals(expected, range); + assertEquals(expected, range); - range = jedis.zrevrangeByScoreWithScores("foo", 3.5d, - Double.NEGATIVE_INFINITY, 0, 2); - expected = new LinkedHashSet(); - expected.add(new Tuple("c", 3.0d)); - expected.add(new Tuple("b", 2.0d)); + range = jedis.zrevrangeByScoreWithScores("foo", 3.5d, + Double.NEGATIVE_INFINITY, 0, 2); + expected = new LinkedHashSet(); + expected.add(new Tuple("c", 3.0d)); + expected.add(new Tuple("b", 2.0d)); - assertEquals(expected, range); + assertEquals(expected, range); - range = jedis.zrevrangeByScoreWithScores("foo", 3.5d, - Double.NEGATIVE_INFINITY, 1, 1); - expected = new LinkedHashSet(); - expected.add(new Tuple("b", 2.0d)); + range = jedis.zrevrangeByScoreWithScores("foo", 3.5d, + Double.NEGATIVE_INFINITY, 1, 1); + expected = new LinkedHashSet(); + expected.add(new Tuple("b", 2.0d)); - assertEquals(expected, range); + assertEquals(expected, range); - range = jedis.zrevrangeByScoreWithScores("foo", 4d, 2d); - expected = new LinkedHashSet(); - expected.add(new Tuple("d", 4.0d)); - expected.add(new Tuple("c", 3.0d)); - expected.add(new Tuple("b", 2.0d)); + range = jedis.zrevrangeByScoreWithScores("foo", 4d, 2d); + expected = new LinkedHashSet(); + expected.add(new Tuple("d", 4.0d)); + expected.add(new Tuple("c", 3.0d)); + expected.add(new Tuple("b", 2.0d)); - assertEquals(expected, range); + assertEquals(expected, range); - // Binary - jedis.zadd(bfoo, 1d, ba); - jedis.zadd(bfoo, 10d, bb); - jedis.zadd(bfoo, 0.1d, bc); - jedis.zadd(bfoo, 2d, ba); + // Binary + jedis.zadd(bfoo, 1d, ba); + jedis.zadd(bfoo, 10d, bb); + jedis.zadd(bfoo, 0.1d, bc); + jedis.zadd(bfoo, 2d, ba); - Set brange = jedis.zrevrangeByScoreWithScores(bfoo, 2d, 0d); + Set brange = jedis.zrevrangeByScoreWithScores(bfoo, 2d, 0d); - Set bexpected = new LinkedHashSet(); - bexpected.add(new Tuple(bc, 0.1d)); - bexpected.add(new Tuple(ba, 2d)); + Set bexpected = new LinkedHashSet(); + bexpected.add(new Tuple(bc, 0.1d)); + bexpected.add(new Tuple(ba, 2d)); - assertEquals(bexpected, brange); + assertEquals(bexpected, brange); - brange = jedis.zrevrangeByScoreWithScores(bfoo, 2d, 0d, 0, 1); + brange = jedis.zrevrangeByScoreWithScores(bfoo, 2d, 0d, 0, 1); - bexpected = new LinkedHashSet(); - bexpected.add(new Tuple(ba, 2d)); + bexpected = new LinkedHashSet(); + bexpected.add(new Tuple(ba, 2d)); - assertEquals(bexpected, brange); + assertEquals(bexpected, brange); - brange = jedis.zrevrangeByScoreWithScores(bfoo, 2d, 0d, 1, 1); + brange = jedis.zrevrangeByScoreWithScores(bfoo, 2d, 0d, 1, 1); - bexpected = new LinkedHashSet(); - bexpected.add(new Tuple(bc, 0.1d)); + bexpected = new LinkedHashSet(); + bexpected.add(new Tuple(bc, 0.1d)); - assertEquals(bexpected, brange); + assertEquals(bexpected, brange); } @Test public void zremrangeByRank() { - jedis.zadd("foo", 1d, "a"); - jedis.zadd("foo", 10d, "b"); - jedis.zadd("foo", 0.1d, "c"); - jedis.zadd("foo", 2d, "a"); + jedis.zadd("foo", 1d, "a"); + jedis.zadd("foo", 10d, "b"); + jedis.zadd("foo", 0.1d, "c"); + jedis.zadd("foo", 2d, "a"); - long result = jedis.zremrangeByRank("foo", 0, 0); + long result = jedis.zremrangeByRank("foo", 0, 0); - assertEquals(1, result); + assertEquals(1, result); - Set expected = new LinkedHashSet(); - expected.add("a"); - expected.add("b"); + Set expected = new LinkedHashSet(); + expected.add("a"); + expected.add("b"); - assertEquals(expected, jedis.zrange("foo", 0, 100)); + assertEquals(expected, jedis.zrange("foo", 0, 100)); - // Binary - jedis.zadd(bfoo, 1d, ba); - jedis.zadd(bfoo, 10d, bb); - jedis.zadd(bfoo, 0.1d, bc); - jedis.zadd(bfoo, 2d, ba); + // Binary + jedis.zadd(bfoo, 1d, ba); + jedis.zadd(bfoo, 10d, bb); + jedis.zadd(bfoo, 0.1d, bc); + jedis.zadd(bfoo, 2d, ba); - long bresult = jedis.zremrangeByRank(bfoo, 0, 0); + long bresult = jedis.zremrangeByRank(bfoo, 0, 0); - assertEquals(1, bresult); + assertEquals(1, bresult); - Set bexpected = new LinkedHashSet(); - bexpected.add(ba); - bexpected.add(bb); + Set bexpected = new LinkedHashSet(); + bexpected.add(ba); + bexpected.add(bb); - assertEquals(bexpected, jedis.zrange(bfoo, 0, 100)); + assertEquals(bexpected, jedis.zrange(bfoo, 0, 100)); } @Test public void zremrangeByScore() { - jedis.zadd("foo", 1d, "a"); - jedis.zadd("foo", 10d, "b"); - jedis.zadd("foo", 0.1d, "c"); - jedis.zadd("foo", 2d, "a"); + jedis.zadd("foo", 1d, "a"); + jedis.zadd("foo", 10d, "b"); + jedis.zadd("foo", 0.1d, "c"); + jedis.zadd("foo", 2d, "a"); - long result = jedis.zremrangeByScore("foo", 0, 2); + long result = jedis.zremrangeByScore("foo", 0, 2); - assertEquals(2, result); + assertEquals(2, result); - Set expected = new LinkedHashSet(); - expected.add("b"); + Set expected = new LinkedHashSet(); + expected.add("b"); - assertEquals(expected, jedis.zrange("foo", 0, 100)); + assertEquals(expected, jedis.zrange("foo", 0, 100)); - // Binary - jedis.zadd(bfoo, 1d, ba); - jedis.zadd(bfoo, 10d, bb); - jedis.zadd(bfoo, 0.1d, bc); - jedis.zadd(bfoo, 2d, ba); + // Binary + jedis.zadd(bfoo, 1d, ba); + jedis.zadd(bfoo, 10d, bb); + jedis.zadd(bfoo, 0.1d, bc); + jedis.zadd(bfoo, 2d, ba); - long bresult = jedis.zremrangeByScore(bfoo, 0, 2); + long bresult = jedis.zremrangeByScore(bfoo, 0, 2); - assertEquals(2, bresult); + assertEquals(2, bresult); - Set bexpected = new LinkedHashSet(); - bexpected.add(bb); + Set bexpected = new LinkedHashSet(); + bexpected.add(bb); - assertEquals(bexpected, jedis.zrange(bfoo, 0, 100)); + assertEquals(bexpected, jedis.zrange(bfoo, 0, 100)); } @Test public void zremrangeByLex() { - jedis.zadd("foo", 1, "a"); - jedis.zadd("foo", 1, "b"); - jedis.zadd("foo", 1, "c"); - jedis.zadd("foo", 1, "aa"); + jedis.zadd("foo", 1, "a"); + jedis.zadd("foo", 1, "b"); + jedis.zadd("foo", 1, "c"); + jedis.zadd("foo", 1, "aa"); - long result = jedis.zremrangeByLex("foo", "[aa", "(c"); + long result = jedis.zremrangeByLex("foo", "[aa", "(c"); - assertEquals(2, result); + assertEquals(2, result); - Set expected = new LinkedHashSet(); - expected.add("a"); - expected.add("c"); + Set expected = new LinkedHashSet(); + expected.add("a"); + expected.add("c"); - assertEquals(expected, jedis.zrangeByLex("foo", "-", "+")); + assertEquals(expected, jedis.zrangeByLex("foo", "-", "+")); } @Test public void zremrangeByLexBinary() { - jedis.zadd(bfoo, 1, ba); - jedis.zadd(bfoo, 1, bc); - jedis.zadd(bfoo, 1, bb); + jedis.zadd(bfoo, 1, ba); + jedis.zadd(bfoo, 1, bc); + jedis.zadd(bfoo, 1, bb); - long bresult = jedis.zremrangeByLex(bfoo, bInclusiveB, bExclusiveC); + long bresult = jedis.zremrangeByLex(bfoo, bInclusiveB, bExclusiveC); - assertEquals(1, bresult); + assertEquals(1, bresult); - Set bexpected = new LinkedHashSet(); - bexpected.add(ba); - bexpected.add(bc); + Set bexpected = new LinkedHashSet(); + bexpected.add(ba); + bexpected.add(bc); - assertEquals(bexpected, - jedis.zrangeByLex(bfoo, bLexMinusInf, bLexPlusInf)); + assertEquals(bexpected, + jedis.zrangeByLex(bfoo, bLexMinusInf, bLexPlusInf)); } @Test public void zunionstore() { - jedis.zadd("foo", 1, "a"); - jedis.zadd("foo", 2, "b"); - jedis.zadd("bar", 2, "a"); - jedis.zadd("bar", 2, "b"); + jedis.zadd("foo", 1, "a"); + jedis.zadd("foo", 2, "b"); + jedis.zadd("bar", 2, "a"); + jedis.zadd("bar", 2, "b"); - long result = jedis.zunionstore("dst", "foo", "bar"); + long result = jedis.zunionstore("dst", "foo", "bar"); - assertEquals(2, result); + assertEquals(2, result); - Set expected = new LinkedHashSet(); - expected.add(new Tuple("b", new Double(4))); - expected.add(new Tuple("a", new Double(3))); + Set expected = new LinkedHashSet(); + expected.add(new Tuple("b", new Double(4))); + expected.add(new Tuple("a", new Double(3))); - assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100)); + assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100)); - // Binary - jedis.zadd(bfoo, 1, ba); - jedis.zadd(bfoo, 2, bb); - jedis.zadd(bbar, 2, ba); - jedis.zadd(bbar, 2, bb); + // Binary + jedis.zadd(bfoo, 1, ba); + jedis.zadd(bfoo, 2, bb); + jedis.zadd(bbar, 2, ba); + jedis.zadd(bbar, 2, bb); - long bresult = jedis.zunionstore(SafeEncoder.encode("dst"), bfoo, bbar); + long bresult = jedis.zunionstore(SafeEncoder.encode("dst"), bfoo, bbar); - assertEquals(2, bresult); + assertEquals(2, bresult); - Set bexpected = new LinkedHashSet(); - bexpected.add(new Tuple(bb, new Double(4))); - bexpected.add(new Tuple(ba, new Double(3))); + Set bexpected = new LinkedHashSet(); + bexpected.add(new Tuple(bb, new Double(4))); + bexpected.add(new Tuple(ba, new Double(3))); - assertEquals(bexpected, - jedis.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100)); + assertEquals(bexpected, + jedis.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100)); } @Test public void zunionstoreParams() { - jedis.zadd("foo", 1, "a"); - jedis.zadd("foo", 2, "b"); - jedis.zadd("bar", 2, "a"); - jedis.zadd("bar", 2, "b"); + jedis.zadd("foo", 1, "a"); + jedis.zadd("foo", 2, "b"); + jedis.zadd("bar", 2, "a"); + jedis.zadd("bar", 2, "b"); - ZParams params = new ZParams(); - params.weights(2, 2.5); - params.aggregate(ZParams.Aggregate.SUM); - long result = jedis.zunionstore("dst", params, "foo", "bar"); + ZParams params = new ZParams(); + params.weights(2, 2.5); + params.aggregate(ZParams.Aggregate.SUM); + long result = jedis.zunionstore("dst", params, "foo", "bar"); - assertEquals(2, result); + assertEquals(2, result); - Set expected = new LinkedHashSet(); - expected.add(new Tuple("b", new Double(9))); - expected.add(new Tuple("a", new Double(7))); + Set expected = new LinkedHashSet(); + expected.add(new Tuple("b", new Double(9))); + expected.add(new Tuple("a", new Double(7))); - assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100)); + assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100)); - // Binary - jedis.zadd(bfoo, 1, ba); - jedis.zadd(bfoo, 2, bb); - jedis.zadd(bbar, 2, ba); - jedis.zadd(bbar, 2, bb); + // Binary + jedis.zadd(bfoo, 1, ba); + jedis.zadd(bfoo, 2, bb); + jedis.zadd(bbar, 2, ba); + jedis.zadd(bbar, 2, bb); - ZParams bparams = new ZParams(); - bparams.weights(2, 2.5); - bparams.aggregate(ZParams.Aggregate.SUM); - long bresult = jedis.zunionstore(SafeEncoder.encode("dst"), bparams, - bfoo, bbar); + ZParams bparams = new ZParams(); + bparams.weights(2, 2.5); + bparams.aggregate(ZParams.Aggregate.SUM); + long bresult = jedis.zunionstore(SafeEncoder.encode("dst"), bparams, + bfoo, bbar); - assertEquals(2, bresult); + assertEquals(2, bresult); - Set bexpected = new LinkedHashSet(); - bexpected.add(new Tuple(bb, new Double(9))); - bexpected.add(new Tuple(ba, new Double(7))); + Set bexpected = new LinkedHashSet(); + bexpected.add(new Tuple(bb, new Double(9))); + bexpected.add(new Tuple(ba, new Double(7))); - assertEquals(bexpected, - jedis.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100)); + assertEquals(bexpected, + jedis.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100)); } @Test public void zinterstore() { - jedis.zadd("foo", 1, "a"); - jedis.zadd("foo", 2, "b"); - jedis.zadd("bar", 2, "a"); + jedis.zadd("foo", 1, "a"); + jedis.zadd("foo", 2, "b"); + jedis.zadd("bar", 2, "a"); - long result = jedis.zinterstore("dst", "foo", "bar"); + long result = jedis.zinterstore("dst", "foo", "bar"); - assertEquals(1, result); + assertEquals(1, result); - Set expected = new LinkedHashSet(); - expected.add(new Tuple("a", new Double(3))); + Set expected = new LinkedHashSet(); + expected.add(new Tuple("a", new Double(3))); - assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100)); + assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100)); - // Binary - jedis.zadd(bfoo, 1, ba); - jedis.zadd(bfoo, 2, bb); - jedis.zadd(bbar, 2, ba); + // Binary + jedis.zadd(bfoo, 1, ba); + jedis.zadd(bfoo, 2, bb); + jedis.zadd(bbar, 2, ba); - long bresult = jedis.zinterstore(SafeEncoder.encode("dst"), bfoo, bbar); + long bresult = jedis.zinterstore(SafeEncoder.encode("dst"), bfoo, bbar); - assertEquals(1, bresult); + assertEquals(1, bresult); - Set bexpected = new LinkedHashSet(); - bexpected.add(new Tuple(ba, new Double(3))); + Set bexpected = new LinkedHashSet(); + bexpected.add(new Tuple(ba, new Double(3))); - assertEquals(bexpected, - jedis.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100)); + assertEquals(bexpected, + jedis.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100)); } @Test public void zintertoreParams() { - jedis.zadd("foo", 1, "a"); - jedis.zadd("foo", 2, "b"); - jedis.zadd("bar", 2, "a"); + jedis.zadd("foo", 1, "a"); + jedis.zadd("foo", 2, "b"); + jedis.zadd("bar", 2, "a"); - ZParams params = new ZParams(); - params.weights(2, 2.5); - params.aggregate(ZParams.Aggregate.SUM); - long result = jedis.zinterstore("dst", params, "foo", "bar"); + ZParams params = new ZParams(); + params.weights(2, 2.5); + params.aggregate(ZParams.Aggregate.SUM); + long result = jedis.zinterstore("dst", params, "foo", "bar"); - assertEquals(1, result); + assertEquals(1, result); - Set expected = new LinkedHashSet(); - expected.add(new Tuple("a", new Double(7))); + Set expected = new LinkedHashSet(); + expected.add(new Tuple("a", new Double(7))); - assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100)); + assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100)); - // Binary - jedis.zadd(bfoo, 1, ba); - jedis.zadd(bfoo, 2, bb); - jedis.zadd(bbar, 2, ba); + // Binary + jedis.zadd(bfoo, 1, ba); + jedis.zadd(bfoo, 2, bb); + jedis.zadd(bbar, 2, ba); - ZParams bparams = new ZParams(); - bparams.weights(2, 2.5); - bparams.aggregate(ZParams.Aggregate.SUM); - long bresult = jedis.zinterstore(SafeEncoder.encode("dst"), bparams, - bfoo, bbar); + ZParams bparams = new ZParams(); + bparams.weights(2, 2.5); + bparams.aggregate(ZParams.Aggregate.SUM); + long bresult = jedis.zinterstore(SafeEncoder.encode("dst"), bparams, + bfoo, bbar); - assertEquals(1, bresult); + assertEquals(1, bresult); - Set bexpected = new LinkedHashSet(); - bexpected.add(new Tuple(ba, new Double(7))); + Set bexpected = new LinkedHashSet(); + bexpected.add(new Tuple(ba, new Double(7))); - assertEquals(bexpected, - jedis.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100)); + assertEquals(bexpected, + jedis.zrangeWithScores(SafeEncoder.encode("dst"), 0, 100)); } @Test public void tupleCompare() { - Tuple t1 = new Tuple("foo", 1d); - Tuple t2 = new Tuple("bar", 2d); + Tuple t1 = new Tuple("foo", 1d); + Tuple t2 = new Tuple("bar", 2d); - assertEquals(-1, t1.compareTo(t2)); - assertEquals(1, t2.compareTo(t1)); - assertEquals(0, t2.compareTo(t2)); + assertEquals(-1, t1.compareTo(t2)); + assertEquals(1, t2.compareTo(t1)); + assertEquals(0, t2.compareTo(t2)); } @Test public void zscan() { - jedis.zadd("foo", 1, "a"); - jedis.zadd("foo", 2, "b"); + jedis.zadd("foo", 1, "a"); + jedis.zadd("foo", 2, "b"); - ScanResult result = jedis.zscan("foo", SCAN_POINTER_START); + ScanResult result = jedis.zscan("foo", SCAN_POINTER_START); - assertEquals(SCAN_POINTER_START, result.getCursor()); - assertFalse(result.getResult().isEmpty()); + assertEquals(SCAN_POINTER_START, result.getCursor()); + assertFalse(result.getResult().isEmpty()); - // binary - jedis.zadd(bfoo, 1, ba); - jedis.zadd(bfoo, 1, bb); + // binary + jedis.zadd(bfoo, 1, ba); + jedis.zadd(bfoo, 1, bb); - ScanResult bResult = jedis - .zscan(bfoo, SCAN_POINTER_START_BINARY); + ScanResult bResult = jedis + .zscan(bfoo, SCAN_POINTER_START_BINARY); - assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes()); - assertFalse(bResult.getResult().isEmpty()); + assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes()); + assertFalse(bResult.getResult().isEmpty()); } @Test public void zscanMatch() { - ScanParams params = new ScanParams(); - params.match("a*"); + ScanParams params = new ScanParams(); + params.match("a*"); - jedis.zadd("foo", 2, "b"); - jedis.zadd("foo", 1, "a"); - jedis.zadd("foo", 11, "aa"); - ScanResult result = jedis.zscan("foo", SCAN_POINTER_START, - params); + jedis.zadd("foo", 2, "b"); + jedis.zadd("foo", 1, "a"); + jedis.zadd("foo", 11, "aa"); + ScanResult result = jedis.zscan("foo", SCAN_POINTER_START, + params); - assertEquals(SCAN_POINTER_START, result.getCursor()); - assertFalse(result.getResult().isEmpty()); + assertEquals(SCAN_POINTER_START, result.getCursor()); + assertFalse(result.getResult().isEmpty()); - // binary - params = new ScanParams(); - params.match(bbarstar); + // binary + params = new ScanParams(); + params.match(bbarstar); - jedis.zadd(bfoo, 2, bbar1); - jedis.zadd(bfoo, 1, bbar2); - jedis.zadd(bfoo, 11, bbar3); - ScanResult bResult = jedis.zscan(bfoo, - SCAN_POINTER_START_BINARY, params); + jedis.zadd(bfoo, 2, bbar1); + jedis.zadd(bfoo, 1, bbar2); + jedis.zadd(bfoo, 11, bbar3); + ScanResult bResult = jedis.zscan(bfoo, + SCAN_POINTER_START_BINARY, params); - assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes()); - assertFalse(bResult.getResult().isEmpty()); + assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getCursorAsBytes()); + assertFalse(bResult.getResult().isEmpty()); } @Test public void zscanCount() { - ScanParams params = new ScanParams(); - params.count(2); + ScanParams params = new ScanParams(); + params.count(2); - jedis.zadd("foo", 1, "a1"); - jedis.zadd("foo", 2, "a2"); - jedis.zadd("foo", 3, "a3"); - jedis.zadd("foo", 4, "a4"); - jedis.zadd("foo", 5, "a5"); + jedis.zadd("foo", 1, "a1"); + jedis.zadd("foo", 2, "a2"); + jedis.zadd("foo", 3, "a3"); + jedis.zadd("foo", 4, "a4"); + jedis.zadd("foo", 5, "a5"); - ScanResult result = jedis.zscan("foo", SCAN_POINTER_START, - params); + ScanResult result = jedis.zscan("foo", SCAN_POINTER_START, + params); - assertFalse(result.getResult().isEmpty()); + assertFalse(result.getResult().isEmpty()); - // binary - params = new ScanParams(); - params.count(2); + // binary + params = new ScanParams(); + params.count(2); - jedis.zadd(bfoo, 2, bbar1); - jedis.zadd(bfoo, 1, bbar2); - jedis.zadd(bfoo, 11, bbar3); + jedis.zadd(bfoo, 2, bbar1); + jedis.zadd(bfoo, 1, bbar2); + jedis.zadd(bfoo, 11, bbar3); - ScanResult bResult = jedis.zscan(bfoo, - SCAN_POINTER_START_BINARY, params); + ScanResult bResult = jedis.zscan(bfoo, + SCAN_POINTER_START_BINARY, params); - assertFalse(bResult.getResult().isEmpty()); + assertFalse(bResult.getResult().isEmpty()); } } diff --git a/src/test/java/redis/clients/jedis/tests/commands/SortingCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/SortingCommandsTest.java index 543dacb..0f52490 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/SortingCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/SortingCommandsTest.java @@ -25,277 +25,277 @@ public class SortingCommandsTest extends JedisCommandTestBase { @Test public void sort() { - jedis.lpush("foo", "3"); - jedis.lpush("foo", "2"); - jedis.lpush("foo", "1"); + jedis.lpush("foo", "3"); + jedis.lpush("foo", "2"); + jedis.lpush("foo", "1"); - List result = jedis.sort("foo"); + List result = jedis.sort("foo"); - List expected = new ArrayList(); - expected.add("1"); - expected.add("2"); - expected.add("3"); + List expected = new ArrayList(); + expected.add("1"); + expected.add("2"); + expected.add("3"); - assertEquals(expected, result); + assertEquals(expected, result); - // Binary - jedis.lpush(bfoo, b3); - jedis.lpush(bfoo, b2); - jedis.lpush(bfoo, b1); + // Binary + jedis.lpush(bfoo, b3); + jedis.lpush(bfoo, b2); + jedis.lpush(bfoo, b1); - List bresult = jedis.sort(bfoo); + List bresult = jedis.sort(bfoo); - List bexpected = new ArrayList(); - bexpected.add(b1); - bexpected.add(b2); - bexpected.add(b3); + List bexpected = new ArrayList(); + bexpected.add(b1); + bexpected.add(b2); + bexpected.add(b3); - assertEquals(bexpected, bresult); + assertEquals(bexpected, bresult); } @Test public void sortBy() { - jedis.lpush("foo", "2"); - jedis.lpush("foo", "3"); - jedis.lpush("foo", "1"); + jedis.lpush("foo", "2"); + jedis.lpush("foo", "3"); + jedis.lpush("foo", "1"); - jedis.set("bar1", "3"); - jedis.set("bar2", "2"); - jedis.set("bar3", "1"); + jedis.set("bar1", "3"); + jedis.set("bar2", "2"); + jedis.set("bar3", "1"); - SortingParams sp = new SortingParams(); - sp.by("bar*"); + SortingParams sp = new SortingParams(); + sp.by("bar*"); - List result = jedis.sort("foo", sp); + List result = jedis.sort("foo", sp); - List expected = new ArrayList(); - expected.add("3"); - expected.add("2"); - expected.add("1"); + List expected = new ArrayList(); + expected.add("3"); + expected.add("2"); + expected.add("1"); - assertEquals(expected, result); + assertEquals(expected, result); - // Binary - jedis.lpush(bfoo, b2); - jedis.lpush(bfoo, b3); - jedis.lpush(bfoo, b1); + // Binary + jedis.lpush(bfoo, b2); + jedis.lpush(bfoo, b3); + jedis.lpush(bfoo, b1); - jedis.set(bbar1, b3); - jedis.set(bbar2, b2); - jedis.set(bbar3, b1); + jedis.set(bbar1, b3); + jedis.set(bbar2, b2); + jedis.set(bbar3, b1); - SortingParams bsp = new SortingParams(); - bsp.by(bbarstar); + SortingParams bsp = new SortingParams(); + bsp.by(bbarstar); - List bresult = jedis.sort(bfoo, bsp); + List bresult = jedis.sort(bfoo, bsp); - List bexpected = new ArrayList(); - bexpected.add(b3); - bexpected.add(b2); - bexpected.add(b1); + List bexpected = new ArrayList(); + bexpected.add(b3); + bexpected.add(b2); + bexpected.add(b1); - assertEquals(bexpected, bresult); + assertEquals(bexpected, bresult); } @Test public void sortDesc() { - jedis.lpush("foo", "3"); - jedis.lpush("foo", "2"); - jedis.lpush("foo", "1"); + jedis.lpush("foo", "3"); + jedis.lpush("foo", "2"); + jedis.lpush("foo", "1"); - SortingParams sp = new SortingParams(); - sp.desc(); + SortingParams sp = new SortingParams(); + sp.desc(); - List result = jedis.sort("foo", sp); + List result = jedis.sort("foo", sp); - List expected = new ArrayList(); - expected.add("3"); - expected.add("2"); - expected.add("1"); + List expected = new ArrayList(); + expected.add("3"); + expected.add("2"); + expected.add("1"); - assertEquals(expected, result); + assertEquals(expected, result); - // Binary - jedis.lpush(bfoo, b3); - jedis.lpush(bfoo, b2); - jedis.lpush(bfoo, b1); + // Binary + jedis.lpush(bfoo, b3); + jedis.lpush(bfoo, b2); + jedis.lpush(bfoo, b1); - SortingParams bsp = new SortingParams(); - bsp.desc(); + SortingParams bsp = new SortingParams(); + bsp.desc(); - List bresult = jedis.sort(bfoo, bsp); + List bresult = jedis.sort(bfoo, bsp); - List bexpected = new ArrayList(); - bexpected.add(b3); - bexpected.add(b2); - bexpected.add(b1); + List bexpected = new ArrayList(); + bexpected.add(b3); + bexpected.add(b2); + bexpected.add(b1); - assertEquals(bexpected, bresult); + assertEquals(bexpected, bresult); } @Test public void sortLimit() { - for (int n = 10; n > 0; n--) { - jedis.lpush("foo", String.valueOf(n)); - } + for (int n = 10; n > 0; n--) { + jedis.lpush("foo", String.valueOf(n)); + } - SortingParams sp = new SortingParams(); - sp.limit(0, 3); + SortingParams sp = new SortingParams(); + sp.limit(0, 3); - List result = jedis.sort("foo", sp); + List result = jedis.sort("foo", sp); - List expected = new ArrayList(); - expected.add("1"); - expected.add("2"); - expected.add("3"); + List expected = new ArrayList(); + expected.add("1"); + expected.add("2"); + expected.add("3"); - assertEquals(expected, result); + assertEquals(expected, result); - // Binary - jedis.rpush(bfoo, new byte[] { (byte) '4' }); - jedis.rpush(bfoo, new byte[] { (byte) '3' }); - jedis.rpush(bfoo, new byte[] { (byte) '2' }); - jedis.rpush(bfoo, new byte[] { (byte) '1' }); + // Binary + jedis.rpush(bfoo, new byte[] { (byte) '4' }); + jedis.rpush(bfoo, new byte[] { (byte) '3' }); + jedis.rpush(bfoo, new byte[] { (byte) '2' }); + jedis.rpush(bfoo, new byte[] { (byte) '1' }); - SortingParams bsp = new SortingParams(); - bsp.limit(0, 3); + SortingParams bsp = new SortingParams(); + bsp.limit(0, 3); - List bresult = jedis.sort(bfoo, bsp); + List bresult = jedis.sort(bfoo, bsp); - List bexpected = new ArrayList(); - bexpected.add(b1); - bexpected.add(b2); - bexpected.add(b3); + List bexpected = new ArrayList(); + bexpected.add(b1); + bexpected.add(b2); + bexpected.add(b3); - assertEquals(bexpected, bresult); + assertEquals(bexpected, bresult); } @Test public void sortAlpha() { - jedis.lpush("foo", "1"); - jedis.lpush("foo", "2"); - jedis.lpush("foo", "10"); + jedis.lpush("foo", "1"); + jedis.lpush("foo", "2"); + jedis.lpush("foo", "10"); - SortingParams sp = new SortingParams(); - sp.alpha(); + SortingParams sp = new SortingParams(); + sp.alpha(); - List result = jedis.sort("foo", sp); + List result = jedis.sort("foo", sp); - List expected = new ArrayList(); - expected.add("1"); - expected.add("10"); - expected.add("2"); + List expected = new ArrayList(); + expected.add("1"); + expected.add("10"); + expected.add("2"); - assertEquals(expected, result); + assertEquals(expected, result); - // Binary - jedis.lpush(bfoo, b1); - jedis.lpush(bfoo, b2); - jedis.lpush(bfoo, b10); + // Binary + jedis.lpush(bfoo, b1); + jedis.lpush(bfoo, b2); + jedis.lpush(bfoo, b10); - SortingParams bsp = new SortingParams(); - bsp.alpha(); + SortingParams bsp = new SortingParams(); + bsp.alpha(); - List bresult = jedis.sort(bfoo, bsp); + List bresult = jedis.sort(bfoo, bsp); - List bexpected = new ArrayList(); - bexpected.add(b1); - bexpected.add(b10); - bexpected.add(b2); + List bexpected = new ArrayList(); + bexpected.add(b1); + bexpected.add(b10); + bexpected.add(b2); - assertEquals(bexpected, bresult); + assertEquals(bexpected, bresult); } @Test public void sortGet() { - jedis.lpush("foo", "1"); - jedis.lpush("foo", "2"); - jedis.lpush("foo", "10"); + jedis.lpush("foo", "1"); + jedis.lpush("foo", "2"); + jedis.lpush("foo", "10"); - jedis.set("bar1", "bar1"); - jedis.set("bar2", "bar2"); - jedis.set("bar10", "bar10"); + jedis.set("bar1", "bar1"); + jedis.set("bar2", "bar2"); + jedis.set("bar10", "bar10"); - jedis.set("car1", "car1"); - jedis.set("car2", "car2"); - jedis.set("car10", "car10"); + jedis.set("car1", "car1"); + jedis.set("car2", "car2"); + jedis.set("car10", "car10"); - SortingParams sp = new SortingParams(); - sp.get("car*", "bar*"); + SortingParams sp = new SortingParams(); + sp.get("car*", "bar*"); - List result = jedis.sort("foo", sp); + List result = jedis.sort("foo", sp); - List expected = new ArrayList(); - expected.add("car1"); - expected.add("bar1"); - expected.add("car2"); - expected.add("bar2"); - expected.add("car10"); - expected.add("bar10"); + List expected = new ArrayList(); + expected.add("car1"); + expected.add("bar1"); + expected.add("car2"); + expected.add("bar2"); + expected.add("car10"); + expected.add("bar10"); - assertEquals(expected, result); + assertEquals(expected, result); - // Binary - jedis.lpush(bfoo, b1); - jedis.lpush(bfoo, b2); - jedis.lpush(bfoo, b10); + // Binary + jedis.lpush(bfoo, b1); + jedis.lpush(bfoo, b2); + jedis.lpush(bfoo, b10); - jedis.set(bbar1, bbar1); - jedis.set(bbar2, bbar2); - jedis.set(bbar10, bbar10); + jedis.set(bbar1, bbar1); + jedis.set(bbar2, bbar2); + jedis.set(bbar10, bbar10); - jedis.set(bcar1, bcar1); - jedis.set(bcar2, bcar2); - jedis.set(bcar10, bcar10); + jedis.set(bcar1, bcar1); + jedis.set(bcar2, bcar2); + jedis.set(bcar10, bcar10); - SortingParams bsp = new SortingParams(); - bsp.get(bcarstar, bbarstar); + SortingParams bsp = new SortingParams(); + bsp.get(bcarstar, bbarstar); - List bresult = jedis.sort(bfoo, bsp); + List bresult = jedis.sort(bfoo, bsp); - List bexpected = new ArrayList(); - bexpected.add(bcar1); - bexpected.add(bbar1); - bexpected.add(bcar2); - bexpected.add(bbar2); - bexpected.add(bcar10); - bexpected.add(bbar10); + List bexpected = new ArrayList(); + bexpected.add(bcar1); + bexpected.add(bbar1); + bexpected.add(bcar2); + bexpected.add(bbar2); + bexpected.add(bcar10); + bexpected.add(bbar10); - assertEquals(bexpected, bresult); + assertEquals(bexpected, bresult); } @Test public void sortStore() { - jedis.lpush("foo", "1"); - jedis.lpush("foo", "2"); - jedis.lpush("foo", "10"); + jedis.lpush("foo", "1"); + jedis.lpush("foo", "2"); + jedis.lpush("foo", "10"); - long result = jedis.sort("foo", "result"); + long result = jedis.sort("foo", "result"); - List expected = new ArrayList(); - expected.add("1"); - expected.add("2"); - expected.add("10"); + List expected = new ArrayList(); + expected.add("1"); + expected.add("2"); + expected.add("10"); - assertEquals(3, result); - assertEquals(expected, jedis.lrange("result", 0, 1000)); + assertEquals(3, result); + assertEquals(expected, jedis.lrange("result", 0, 1000)); - // Binary - jedis.lpush(bfoo, b1); - jedis.lpush(bfoo, b2); - jedis.lpush(bfoo, b10); + // Binary + jedis.lpush(bfoo, b1); + jedis.lpush(bfoo, b2); + jedis.lpush(bfoo, b10); - byte[] bkresult = new byte[] { 0X09, 0x0A, 0x0B, 0x0C }; - long bresult = jedis.sort(bfoo, bkresult); + byte[] bkresult = new byte[] { 0X09, 0x0A, 0x0B, 0x0C }; + long bresult = jedis.sort(bfoo, bkresult); - List bexpected = new ArrayList(); - bexpected.add(b1); - bexpected.add(b2); - bexpected.add(b10); + List bexpected = new ArrayList(); + bexpected.add(b1); + bexpected.add(b2); + bexpected.add(b10); - assertEquals(3, bresult); - assertEquals(bexpected, jedis.lrange(bkresult, 0, 1000)); + assertEquals(3, bresult); + assertEquals(bexpected, jedis.lrange(bkresult, 0, 1000)); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/commands/StringValuesCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/StringValuesCommandsTest.java index 0cfeb90..92293ab 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/StringValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/StringValuesCommandsTest.java @@ -10,206 +10,206 @@ import redis.clients.jedis.exceptions.JedisDataException; public class StringValuesCommandsTest extends JedisCommandTestBase { @Test public void setAndGet() { - String status = jedis.set("foo", "bar"); - assertEquals("OK", status); + String status = jedis.set("foo", "bar"); + assertEquals("OK", status); - String value = jedis.get("foo"); - assertEquals("bar", value); + String value = jedis.get("foo"); + assertEquals("bar", value); - assertEquals(null, jedis.get("bar")); + assertEquals(null, jedis.get("bar")); } @Test public void getSet() { - String value = jedis.getSet("foo", "bar"); - assertEquals(null, value); - value = jedis.get("foo"); - assertEquals("bar", value); + String value = jedis.getSet("foo", "bar"); + assertEquals(null, value); + value = jedis.get("foo"); + assertEquals("bar", value); } @Test public void mget() { - List values = jedis.mget("foo", "bar"); - List expected = new ArrayList(); - expected.add(null); - expected.add(null); + List values = jedis.mget("foo", "bar"); + List expected = new ArrayList(); + expected.add(null); + expected.add(null); - assertEquals(expected, values); + assertEquals(expected, values); - jedis.set("foo", "bar"); + jedis.set("foo", "bar"); - expected = new ArrayList(); - expected.add("bar"); - expected.add(null); - values = jedis.mget("foo", "bar"); + expected = new ArrayList(); + expected.add("bar"); + expected.add(null); + values = jedis.mget("foo", "bar"); - assertEquals(expected, values); + assertEquals(expected, values); - jedis.set("bar", "foo"); + jedis.set("bar", "foo"); - expected = new ArrayList(); - expected.add("bar"); - expected.add("foo"); - values = jedis.mget("foo", "bar"); + expected = new ArrayList(); + expected.add("bar"); + expected.add("foo"); + values = jedis.mget("foo", "bar"); - assertEquals(expected, values); + assertEquals(expected, values); } @Test public void setnx() { - long status = jedis.setnx("foo", "bar"); - assertEquals(1, status); - assertEquals("bar", jedis.get("foo")); + long status = jedis.setnx("foo", "bar"); + assertEquals(1, status); + assertEquals("bar", jedis.get("foo")); - status = jedis.setnx("foo", "bar2"); - assertEquals(0, status); - assertEquals("bar", jedis.get("foo")); + status = jedis.setnx("foo", "bar2"); + assertEquals(0, status); + assertEquals("bar", jedis.get("foo")); } @Test public void setex() { - String status = jedis.setex("foo", 20, "bar"); - assertEquals("OK", status); - long ttl = jedis.ttl("foo"); - assertTrue(ttl > 0 && ttl <= 20); + String status = jedis.setex("foo", 20, "bar"); + assertEquals("OK", status); + long ttl = jedis.ttl("foo"); + assertTrue(ttl > 0 && ttl <= 20); } @Test public void mset() { - String status = jedis.mset("foo", "bar", "bar", "foo"); - assertEquals("OK", status); - assertEquals("bar", jedis.get("foo")); - assertEquals("foo", jedis.get("bar")); + String status = jedis.mset("foo", "bar", "bar", "foo"); + assertEquals("OK", status); + assertEquals("bar", jedis.get("foo")); + assertEquals("foo", jedis.get("bar")); } @Test public void msetnx() { - long status = jedis.msetnx("foo", "bar", "bar", "foo"); - assertEquals(1, status); - assertEquals("bar", jedis.get("foo")); - assertEquals("foo", jedis.get("bar")); + long status = jedis.msetnx("foo", "bar", "bar", "foo"); + assertEquals(1, status); + assertEquals("bar", jedis.get("foo")); + assertEquals("foo", jedis.get("bar")); - status = jedis.msetnx("foo", "bar1", "bar2", "foo2"); - assertEquals(0, status); - assertEquals("bar", jedis.get("foo")); - assertEquals("foo", jedis.get("bar")); + status = jedis.msetnx("foo", "bar1", "bar2", "foo2"); + assertEquals(0, status); + assertEquals("bar", jedis.get("foo")); + assertEquals("foo", jedis.get("bar")); } @Test(expected = JedisDataException.class) public void incrWrongValue() { - jedis.set("foo", "bar"); - jedis.incr("foo"); + jedis.set("foo", "bar"); + jedis.incr("foo"); } @Test public void incr() { - long value = jedis.incr("foo"); - assertEquals(1, value); - value = jedis.incr("foo"); - assertEquals(2, value); + long value = jedis.incr("foo"); + assertEquals(1, value); + value = jedis.incr("foo"); + assertEquals(2, value); } @Test(expected = JedisDataException.class) public void incrByWrongValue() { - jedis.set("foo", "bar"); - jedis.incrBy("foo", 2); + jedis.set("foo", "bar"); + jedis.incrBy("foo", 2); } @Test public void incrBy() { - long value = jedis.incrBy("foo", 2); - assertEquals(2, value); - value = jedis.incrBy("foo", 2); - assertEquals(4, value); + long value = jedis.incrBy("foo", 2); + assertEquals(2, value); + value = jedis.incrBy("foo", 2); + assertEquals(4, value); } @Test(expected = JedisDataException.class) public void incrByFloatWrongValue() { - jedis.set("foo", "bar"); - jedis.incrByFloat("foo", 2d); + jedis.set("foo", "bar"); + jedis.incrByFloat("foo", 2d); } @Test(expected = JedisDataException.class) public void decrWrongValue() { - jedis.set("foo", "bar"); - jedis.decr("foo"); + jedis.set("foo", "bar"); + jedis.decr("foo"); } @Test public void decr() { - long value = jedis.decr("foo"); - assertEquals(-1, value); - value = jedis.decr("foo"); - assertEquals(-2, value); + long value = jedis.decr("foo"); + assertEquals(-1, value); + value = jedis.decr("foo"); + assertEquals(-2, value); } @Test(expected = JedisDataException.class) public void decrByWrongValue() { - jedis.set("foo", "bar"); - jedis.decrBy("foo", 2); + jedis.set("foo", "bar"); + jedis.decrBy("foo", 2); } @Test public void decrBy() { - long value = jedis.decrBy("foo", 2); - assertEquals(-2, value); - value = jedis.decrBy("foo", 2); - assertEquals(-4, value); + long value = jedis.decrBy("foo", 2); + assertEquals(-2, value); + value = jedis.decrBy("foo", 2); + assertEquals(-4, value); } @Test public void append() { - long value = jedis.append("foo", "bar"); - assertEquals(3, value); - assertEquals("bar", jedis.get("foo")); - value = jedis.append("foo", "bar"); - assertEquals(6, value); - assertEquals("barbar", jedis.get("foo")); + long value = jedis.append("foo", "bar"); + assertEquals(3, value); + assertEquals("bar", jedis.get("foo")); + value = jedis.append("foo", "bar"); + assertEquals(6, value); + assertEquals("barbar", jedis.get("foo")); } @Test public void substr() { - jedis.set("s", "This is a string"); - assertEquals("This", jedis.substr("s", 0, 3)); - assertEquals("ing", jedis.substr("s", -3, -1)); - assertEquals("This is a string", jedis.substr("s", 0, -1)); - assertEquals(" string", jedis.substr("s", 9, 100000)); + jedis.set("s", "This is a string"); + assertEquals("This", jedis.substr("s", 0, 3)); + assertEquals("ing", jedis.substr("s", -3, -1)); + assertEquals("This is a string", jedis.substr("s", 0, -1)); + assertEquals(" string", jedis.substr("s", 9, 100000)); } @Test public void strlen() { - jedis.set("s", "This is a string"); - assertEquals("This is a string".length(), jedis.strlen("s").intValue()); + jedis.set("s", "This is a string"); + assertEquals("This is a string".length(), jedis.strlen("s").intValue()); } @Test public void incrLargeNumbers() { - long value = jedis.incr("foo"); - assertEquals(1, value); - assertEquals(1L + Integer.MAX_VALUE, - (long) jedis.incrBy("foo", Integer.MAX_VALUE)); + long value = jedis.incr("foo"); + assertEquals(1, value); + assertEquals(1L + Integer.MAX_VALUE, + (long) jedis.incrBy("foo", Integer.MAX_VALUE)); } @Test(expected = JedisDataException.class) public void incrReallyLargeNumbers() { - jedis.set("foo", Long.toString(Long.MAX_VALUE)); - long value = jedis.incr("foo"); - assertEquals(Long.MIN_VALUE, value); + jedis.set("foo", Long.toString(Long.MAX_VALUE)); + long value = jedis.incr("foo"); + assertEquals(Long.MIN_VALUE, value); } @Test public void incrByFloat() { - double value = jedis.incrByFloat("foo", 10.5); - assertEquals(10.5, value, 0.0); - value = jedis.incrByFloat("foo", 0.1); - assertEquals(10.6, value, 0.0); + double value = jedis.incrByFloat("foo", 10.5); + assertEquals(10.5, value, 0.0); + value = jedis.incrByFloat("foo", 0.1); + assertEquals(10.6, value, 0.0); } @Test public void psetex() { - String status = jedis.psetex("foo", 20000, "bar"); - assertEquals("OK", status); - long ttl = jedis.ttl("foo"); - assertTrue(ttl > 0 && ttl <= 20000); + String status = jedis.psetex("foo", 20000, "bar"); + assertEquals("OK", status); + long ttl = jedis.ttl("foo"); + assertTrue(ttl > 0 && ttl <= 20000); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java index e4c9585..5dc74b2 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java @@ -29,278 +29,278 @@ public class TransactionCommandsTest extends JedisCommandTestBase { @Before public void setUp() throws Exception { - super.setUp(); + super.setUp(); - nj = new Jedis(hnp.getHost(), hnp.getPort(), 500); - nj.connect(); - nj.auth("foobared"); - nj.flushAll(); + nj = new Jedis(hnp.getHost(), hnp.getPort(), 500); + nj.connect(); + nj.auth("foobared"); + nj.flushAll(); } @Test public void multi() { - Transaction trans = jedis.multi(); + Transaction trans = jedis.multi(); - trans.sadd("foo", "a"); - trans.sadd("foo", "b"); - trans.scard("foo"); + trans.sadd("foo", "a"); + trans.sadd("foo", "b"); + trans.scard("foo"); - List response = trans.exec(); + List response = trans.exec(); - List expected = new ArrayList(); - expected.add(1L); - expected.add(1L); - expected.add(2L); - assertEquals(expected, response); + List expected = new ArrayList(); + expected.add(1L); + expected.add(1L); + expected.add(2L); + assertEquals(expected, response); - // Binary - trans = jedis.multi(); + // Binary + trans = jedis.multi(); - trans.sadd(bfoo, ba); - trans.sadd(bfoo, bb); - trans.scard(bfoo); + trans.sadd(bfoo, ba); + trans.sadd(bfoo, bb); + trans.scard(bfoo); - response = trans.exec(); + response = trans.exec(); - expected = new ArrayList(); - expected.add(1L); - expected.add(1L); - expected.add(2L); - assertEquals(expected, response); + expected = new ArrayList(); + expected.add(1L); + expected.add(1L); + expected.add(2L); + assertEquals(expected, response); } @Test public void watch() throws UnknownHostException, IOException { - jedis.watch("mykey", "somekey"); - Transaction t = jedis.multi(); + jedis.watch("mykey", "somekey"); + Transaction t = jedis.multi(); - nj.connect(); - nj.auth("foobared"); - nj.set("mykey", "bar"); - nj.disconnect(); + nj.connect(); + nj.auth("foobared"); + nj.set("mykey", "bar"); + nj.disconnect(); - t.set("mykey", "foo"); - List resp = t.exec(); - assertEquals(null, resp); - assertEquals("bar", jedis.get("mykey")); + t.set("mykey", "foo"); + List resp = t.exec(); + assertEquals(null, resp); + assertEquals("bar", jedis.get("mykey")); - // Binary - jedis.watch(bmykey, "foobar".getBytes()); - t = jedis.multi(); + // Binary + jedis.watch(bmykey, "foobar".getBytes()); + t = jedis.multi(); - nj.connect(); - nj.auth("foobared"); - nj.set(bmykey, bbar); - nj.disconnect(); + nj.connect(); + nj.auth("foobared"); + nj.set(bmykey, bbar); + nj.disconnect(); - t.set(bmykey, bfoo); - resp = t.exec(); - assertEquals(null, resp); - assertTrue(Arrays.equals(bbar, jedis.get(bmykey))); + t.set(bmykey, bfoo); + resp = t.exec(); + assertEquals(null, resp); + assertTrue(Arrays.equals(bbar, jedis.get(bmykey))); } @Test public void unwatch() throws UnknownHostException, IOException { - jedis.watch("mykey"); - String val = jedis.get("mykey"); - val = "foo"; - String status = jedis.unwatch(); - assertEquals("OK", status); - Transaction t = jedis.multi(); + jedis.watch("mykey"); + String val = jedis.get("mykey"); + val = "foo"; + String status = jedis.unwatch(); + assertEquals("OK", status); + Transaction t = jedis.multi(); - nj.connect(); - nj.auth("foobared"); - nj.set("mykey", "bar"); - nj.disconnect(); + nj.connect(); + nj.auth("foobared"); + nj.set("mykey", "bar"); + nj.disconnect(); - t.set("mykey", val); - List resp = t.exec(); - assertEquals(1, resp.size()); - assertEquals("OK", resp.get(0)); + t.set("mykey", val); + List resp = t.exec(); + assertEquals(1, resp.size()); + assertEquals("OK", resp.get(0)); - // Binary - jedis.watch(bmykey); - byte[] bval = jedis.get(bmykey); - bval = bfoo; - status = jedis.unwatch(); - assertEquals(Keyword.OK.name(), status); - t = jedis.multi(); + // Binary + jedis.watch(bmykey); + byte[] bval = jedis.get(bmykey); + bval = bfoo; + status = jedis.unwatch(); + assertEquals(Keyword.OK.name(), status); + t = jedis.multi(); - nj.connect(); - nj.auth("foobared"); - nj.set(bmykey, bbar); - nj.disconnect(); + nj.connect(); + nj.auth("foobared"); + nj.set(bmykey, bbar); + nj.disconnect(); - t.set(bmykey, bval); - resp = t.exec(); - assertEquals(1, resp.size()); - assertEquals("OK", resp.get(0)); + t.set(bmykey, bval); + resp = t.exec(); + assertEquals(1, resp.size()); + assertEquals("OK", resp.get(0)); } @Test(expected = JedisDataException.class) public void validateWhenInMulti() { - jedis.multi(); - jedis.ping(); + jedis.multi(); + jedis.ping(); } @Test public void discard() { - Transaction t = jedis.multi(); - String status = t.discard(); - assertEquals("OK", status); + Transaction t = jedis.multi(); + String status = t.discard(); + assertEquals("OK", status); } @Test public void transactionResponse() { - jedis.set("string", "foo"); - jedis.lpush("list", "foo"); - jedis.hset("hash", "foo", "bar"); - jedis.zadd("zset", 1, "foo"); - jedis.sadd("set", "foo"); + jedis.set("string", "foo"); + jedis.lpush("list", "foo"); + jedis.hset("hash", "foo", "bar"); + jedis.zadd("zset", 1, "foo"); + jedis.sadd("set", "foo"); - Transaction t = jedis.multi(); - Response string = t.get("string"); - Response list = t.lpop("list"); - Response hash = t.hget("hash", "foo"); - Response> zset = t.zrange("zset", 0, -1); - Response set = t.spop("set"); - t.exec(); + Transaction t = jedis.multi(); + Response string = t.get("string"); + Response list = t.lpop("list"); + Response hash = t.hget("hash", "foo"); + Response> zset = t.zrange("zset", 0, -1); + Response set = t.spop("set"); + t.exec(); - assertEquals("foo", string.get()); - assertEquals("foo", list.get()); - assertEquals("bar", hash.get()); - assertEquals("foo", zset.get().iterator().next()); - assertEquals("foo", set.get()); + assertEquals("foo", string.get()); + assertEquals("foo", list.get()); + assertEquals("bar", hash.get()); + assertEquals("foo", zset.get().iterator().next()); + assertEquals("foo", set.get()); } @Test public void transactionResponseBinary() { - jedis.set("string", "foo"); - jedis.lpush("list", "foo"); - jedis.hset("hash", "foo", "bar"); - jedis.zadd("zset", 1, "foo"); - jedis.sadd("set", "foo"); + jedis.set("string", "foo"); + jedis.lpush("list", "foo"); + jedis.hset("hash", "foo", "bar"); + jedis.zadd("zset", 1, "foo"); + jedis.sadd("set", "foo"); - Transaction t = jedis.multi(); - Response string = t.get("string".getBytes()); - Response list = t.lpop("list".getBytes()); - Response hash = t.hget("hash".getBytes(), "foo".getBytes()); - Response> zset = t.zrange("zset".getBytes(), 0, -1); - Response set = t.spop("set".getBytes()); - t.exec(); + Transaction t = jedis.multi(); + Response string = t.get("string".getBytes()); + Response list = t.lpop("list".getBytes()); + Response hash = t.hget("hash".getBytes(), "foo".getBytes()); + Response> zset = t.zrange("zset".getBytes(), 0, -1); + Response set = t.spop("set".getBytes()); + t.exec(); - assertArrayEquals("foo".getBytes(), string.get()); - assertArrayEquals("foo".getBytes(), list.get()); - assertArrayEquals("bar".getBytes(), hash.get()); - assertArrayEquals("foo".getBytes(), zset.get().iterator().next()); - assertArrayEquals("foo".getBytes(), set.get()); + assertArrayEquals("foo".getBytes(), string.get()); + assertArrayEquals("foo".getBytes(), list.get()); + assertArrayEquals("bar".getBytes(), hash.get()); + assertArrayEquals("foo".getBytes(), zset.get().iterator().next()); + assertArrayEquals("foo".getBytes(), set.get()); } @Test(expected = JedisDataException.class) public void transactionResponseWithinPipeline() { - jedis.set("string", "foo"); + jedis.set("string", "foo"); - Transaction t = jedis.multi(); - Response string = t.get("string"); - string.get(); - t.exec(); + Transaction t = jedis.multi(); + Response string = t.get("string"); + string.get(); + t.exec(); } @Test public void transactionResponseWithError() { - Transaction t = jedis.multi(); - t.set("foo", "bar"); - Response> error = t.smembers("foo"); - Response r = t.get("foo"); - List l = t.exec(); - assertEquals(JedisDataException.class, l.get(1).getClass()); - try { - error.get(); - fail("We expect exception here!"); - } catch (JedisDataException e) { - // that is fine we should be here - } - assertEquals(r.get(), "bar"); + Transaction t = jedis.multi(); + t.set("foo", "bar"); + Response> error = t.smembers("foo"); + Response r = t.get("foo"); + List l = t.exec(); + assertEquals(JedisDataException.class, l.get(1).getClass()); + try { + error.get(); + fail("We expect exception here!"); + } catch (JedisDataException e) { + // that is fine we should be here + } + assertEquals(r.get(), "bar"); } @Test public void execGetResponse() { - Transaction t = jedis.multi(); + Transaction t = jedis.multi(); - t.set("foo", "bar"); - t.smembers("foo"); - t.get("foo"); + t.set("foo", "bar"); + t.smembers("foo"); + t.get("foo"); - List> lr = t.execGetResponse(); - try { - lr.get(1).get(); - fail("We expect exception here!"); - } catch (JedisDataException e) { - // that is fine we should be here - } - assertEquals("bar", lr.get(2).get()); + List> lr = t.execGetResponse(); + try { + lr.get(1).get(); + fail("We expect exception here!"); + } catch (JedisDataException e) { + // that is fine we should be here + } + assertEquals("bar", lr.get(2).get()); } @Test public void select() { - jedis.select(1); - jedis.set("foo", "bar"); - jedis.watch("foo"); - Transaction t = jedis.multi(); - t.select(0); - t.set("bar", "foo"); + jedis.select(1); + jedis.set("foo", "bar"); + jedis.watch("foo"); + Transaction t = jedis.multi(); + t.select(0); + t.set("bar", "foo"); - Jedis jedis2 = createJedis(); - jedis2.select(1); - jedis2.set("foo", "bar2"); + Jedis jedis2 = createJedis(); + jedis2.select(1); + jedis2.set("foo", "bar2"); - List results = t.exec(); + List results = t.exec(); - assertNull(results); + assertNull(results); } @Test public void testResetStateWhenInMulti() { - jedis.auth("foobared"); + jedis.auth("foobared"); - Transaction t = jedis.multi(); - t.set("foooo", "barrr"); + Transaction t = jedis.multi(); + t.set("foooo", "barrr"); - jedis.resetState(); - assertEquals(null, jedis.get("foooo")); + jedis.resetState(); + assertEquals(null, jedis.get("foooo")); } @Test public void testResetStateWhenInMultiWithinPipeline() { - jedis.auth("foobared"); + jedis.auth("foobared"); - Pipeline p = jedis.pipelined(); - p.multi(); - p.set("foooo", "barrr"); + Pipeline p = jedis.pipelined(); + p.multi(); + p.set("foooo", "barrr"); - jedis.resetState(); - assertEquals(null, jedis.get("foooo")); + jedis.resetState(); + assertEquals(null, jedis.get("foooo")); } @Test public void testResetStateWhenInWatch() { - jedis.watch("mykey", "somekey"); + jedis.watch("mykey", "somekey"); - // state reset : unwatch - jedis.resetState(); + // state reset : unwatch + jedis.resetState(); - Transaction t = jedis.multi(); + Transaction t = jedis.multi(); - nj.connect(); - nj.auth("foobared"); - nj.set("mykey", "bar"); - nj.disconnect(); + nj.connect(); + nj.auth("foobared"); + nj.set("mykey", "bar"); + nj.disconnect(); - t.set("mykey", "foo"); - List resp = t.exec(); - assertNotNull(resp); - assertEquals(1, resp.size()); - assertEquals("foo", jedis.get("mykey")); + t.set("mykey", "foo"); + List resp = t.exec(); + assertNotNull(resp); + assertEquals(1, resp.size()); + assertEquals("foo", jedis.get("mykey")); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/commands/VariadicCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/VariadicCommandsTest.java index 43bb705..529c1d7 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/VariadicCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/VariadicCommandsTest.java @@ -18,173 +18,173 @@ public class VariadicCommandsTest extends JedisCommandTestBase { @Test public void hdel() { - Map hash = new HashMap(); - hash.put("bar", "car"); - hash.put("car", "bar"); - hash.put("foo2", "bar"); - jedis.hmset("foo", hash); + Map hash = new HashMap(); + hash.put("bar", "car"); + hash.put("car", "bar"); + hash.put("foo2", "bar"); + jedis.hmset("foo", hash); - assertEquals(0, jedis.hdel("bar", "foo", "foo1").intValue()); - assertEquals(0, jedis.hdel("foo", "foo", "foo1").intValue()); - assertEquals(2, jedis.hdel("foo", "bar", "foo2").intValue()); - assertEquals(null, jedis.hget("foo", "bar")); + assertEquals(0, jedis.hdel("bar", "foo", "foo1").intValue()); + assertEquals(0, jedis.hdel("foo", "foo", "foo1").intValue()); + assertEquals(2, jedis.hdel("foo", "bar", "foo2").intValue()); + assertEquals(null, jedis.hget("foo", "bar")); - // Binary - Map bhash = new HashMap(); - bhash.put(bbar, bcar); - bhash.put(bcar, bbar); - bhash.put(bfoo2, bbar); - jedis.hmset(bfoo, bhash); + // Binary + Map bhash = new HashMap(); + bhash.put(bbar, bcar); + bhash.put(bcar, bbar); + bhash.put(bfoo2, bbar); + jedis.hmset(bfoo, bhash); - assertEquals(0, jedis.hdel(bbar, bfoo, bfoo1).intValue()); - assertEquals(0, jedis.hdel(bfoo, bfoo, bfoo1).intValue()); - assertEquals(2, jedis.hdel(bfoo, bbar, bfoo2).intValue()); - assertEquals(null, jedis.hget(bfoo, bbar)); + assertEquals(0, jedis.hdel(bbar, bfoo, bfoo1).intValue()); + assertEquals(0, jedis.hdel(bfoo, bfoo, bfoo1).intValue()); + assertEquals(2, jedis.hdel(bfoo, bbar, bfoo2).intValue()); + assertEquals(null, jedis.hget(bfoo, bbar)); } @Test public void rpush() { - long size = jedis.rpush("foo", "bar", "foo"); - assertEquals(2, size); + long size = jedis.rpush("foo", "bar", "foo"); + assertEquals(2, size); - List expected = new ArrayList(); - expected.add("bar"); - expected.add("foo"); + List expected = new ArrayList(); + expected.add("bar"); + expected.add("foo"); - List values = jedis.lrange("foo", 0, -1); - assertEquals(expected, values); + List values = jedis.lrange("foo", 0, -1); + assertEquals(expected, values); - // Binary - size = jedis.rpush(bfoo, bbar, bfoo); - assertEquals(2, size); + // Binary + size = jedis.rpush(bfoo, bbar, bfoo); + assertEquals(2, size); - List bexpected = new ArrayList(); - bexpected.add(bbar); - bexpected.add(bfoo); + List bexpected = new ArrayList(); + bexpected.add(bbar); + bexpected.add(bfoo); - List bvalues = jedis.lrange(bfoo, 0, -1); - assertEquals(bexpected, bvalues); + List bvalues = jedis.lrange(bfoo, 0, -1); + assertEquals(bexpected, bvalues); } @Test public void lpush() { - long size = jedis.lpush("foo", "bar", "foo"); - assertEquals(2, size); + long size = jedis.lpush("foo", "bar", "foo"); + assertEquals(2, size); - List expected = new ArrayList(); - expected.add("foo"); - expected.add("bar"); + List expected = new ArrayList(); + expected.add("foo"); + expected.add("bar"); - List values = jedis.lrange("foo", 0, -1); - assertEquals(expected, values); + List values = jedis.lrange("foo", 0, -1); + assertEquals(expected, values); - // Binary - size = jedis.lpush(bfoo, bbar, bfoo); - assertEquals(2, size); + // Binary + size = jedis.lpush(bfoo, bbar, bfoo); + assertEquals(2, size); - List bexpected = new ArrayList(); - bexpected.add(bfoo); - bexpected.add(bbar); + List bexpected = new ArrayList(); + bexpected.add(bfoo); + bexpected.add(bbar); - List bvalues = jedis.lrange(bfoo, 0, -1); - assertEquals(bexpected, bvalues); + List bvalues = jedis.lrange(bfoo, 0, -1); + assertEquals(bexpected, bvalues); } @Test public void sadd() { - long status = jedis.sadd("foo", "bar", "foo1"); - assertEquals(2, status); + long status = jedis.sadd("foo", "bar", "foo1"); + assertEquals(2, status); - status = jedis.sadd("foo", "bar", "car"); - assertEquals(1, status); + status = jedis.sadd("foo", "bar", "car"); + assertEquals(1, status); - status = jedis.sadd("foo", "bar", "foo1"); - assertEquals(0, status); + status = jedis.sadd("foo", "bar", "foo1"); + assertEquals(0, status); - status = jedis.sadd(bfoo, bbar, bfoo1); - assertEquals(2, status); + status = jedis.sadd(bfoo, bbar, bfoo1); + assertEquals(2, status); - status = jedis.sadd(bfoo, bbar, bcar); - assertEquals(1, status); + status = jedis.sadd(bfoo, bbar, bcar); + assertEquals(1, status); - status = jedis.sadd(bfoo, bbar, bfoo1); - assertEquals(0, status); + status = jedis.sadd(bfoo, bbar, bfoo1); + assertEquals(0, status); } @Test public void zadd() { - Map scoreMembers = new HashMap(); - scoreMembers.put("bar", 1d); - scoreMembers.put("foo", 10d); + Map scoreMembers = new HashMap(); + scoreMembers.put("bar", 1d); + scoreMembers.put("foo", 10d); - long status = jedis.zadd("foo", scoreMembers); - assertEquals(2, status); + long status = jedis.zadd("foo", scoreMembers); + assertEquals(2, status); - scoreMembers.clear(); - scoreMembers.put("car", 0.1d); - scoreMembers.put("bar", 2d); + scoreMembers.clear(); + scoreMembers.put("car", 0.1d); + scoreMembers.put("bar", 2d); - status = jedis.zadd("foo", scoreMembers); - assertEquals(1, status); + status = jedis.zadd("foo", scoreMembers); + assertEquals(1, status); - Map bscoreMembers = new HashMap(); - bscoreMembers.put(bbar, 1d); - bscoreMembers.put(bfoo, 10d); + Map bscoreMembers = new HashMap(); + bscoreMembers.put(bbar, 1d); + bscoreMembers.put(bfoo, 10d); - status = jedis.zadd(bfoo, bscoreMembers); - assertEquals(2, status); + status = jedis.zadd(bfoo, bscoreMembers); + assertEquals(2, status); - bscoreMembers.clear(); - bscoreMembers.put(bcar, 0.1d); - bscoreMembers.put(bbar, 2d); + bscoreMembers.clear(); + bscoreMembers.put(bcar, 0.1d); + bscoreMembers.put(bbar, 2d); - status = jedis.zadd(bfoo, bscoreMembers); - assertEquals(1, status); + status = jedis.zadd(bfoo, bscoreMembers); + assertEquals(1, status); } @Test public void zrem() { - jedis.zadd("foo", 1d, "bar"); - jedis.zadd("foo", 2d, "car"); - jedis.zadd("foo", 3d, "foo1"); + jedis.zadd("foo", 1d, "bar"); + jedis.zadd("foo", 2d, "car"); + jedis.zadd("foo", 3d, "foo1"); - long status = jedis.zrem("foo", "bar", "car"); + long status = jedis.zrem("foo", "bar", "car"); - Set expected = new LinkedHashSet(); - expected.add("foo1"); + Set expected = new LinkedHashSet(); + expected.add("foo1"); - assertEquals(2, status); - assertEquals(expected, jedis.zrange("foo", 0, 100)); + assertEquals(2, status); + assertEquals(expected, jedis.zrange("foo", 0, 100)); - status = jedis.zrem("foo", "bar", "car"); - assertEquals(0, status); + status = jedis.zrem("foo", "bar", "car"); + assertEquals(0, status); - status = jedis.zrem("foo", "bar", "foo1"); - assertEquals(1, status); + status = jedis.zrem("foo", "bar", "foo1"); + assertEquals(1, status); - // Binary - jedis.zadd(bfoo, 1d, bbar); - jedis.zadd(bfoo, 2d, bcar); - jedis.zadd(bfoo, 3d, bfoo1); + // Binary + jedis.zadd(bfoo, 1d, bbar); + jedis.zadd(bfoo, 2d, bcar); + jedis.zadd(bfoo, 3d, bfoo1); - status = jedis.zrem(bfoo, bbar, bcar); + status = jedis.zrem(bfoo, bbar, bcar); - Set bexpected = new LinkedHashSet(); - bexpected.add(bfoo); + Set bexpected = new LinkedHashSet(); + bexpected.add(bfoo); - assertEquals(2, status); - assertEquals(bexpected, jedis.zrange(bfoo, 0, 100)); + assertEquals(2, status); + assertEquals(bexpected, jedis.zrange(bfoo, 0, 100)); - status = jedis.zrem(bfoo, bbar, bcar); - assertEquals(0, status); + status = jedis.zrem(bfoo, bbar, bcar); + assertEquals(0, status); - status = jedis.zrem(bfoo, bbar, bfoo1); - assertEquals(1, status); + status = jedis.zrem(bfoo, bbar, bfoo1); + assertEquals(1, status); } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/utils/FailoverAbortedException.java b/src/test/java/redis/clients/jedis/tests/utils/FailoverAbortedException.java index e711087..ba7e7cb 100644 --- a/src/test/java/redis/clients/jedis/tests/utils/FailoverAbortedException.java +++ b/src/test/java/redis/clients/jedis/tests/utils/FailoverAbortedException.java @@ -4,14 +4,14 @@ public class FailoverAbortedException extends RuntimeException { private static final long serialVersionUID = 1925110762858409954L; public FailoverAbortedException(String message) { - super(message); + super(message); } public FailoverAbortedException(Throwable cause) { - super(cause); + super(cause); } public FailoverAbortedException(String message, Throwable cause) { - super(message, cause); + super(message, cause); } } diff --git a/src/test/java/redis/clients/jedis/tests/utils/JedisClusterCRC16Test.java b/src/test/java/redis/clients/jedis/tests/utils/JedisClusterCRC16Test.java index 36cb47b..1703df6 100644 --- a/src/test/java/redis/clients/jedis/tests/utils/JedisClusterCRC16Test.java +++ b/src/test/java/redis/clients/jedis/tests/utils/JedisClusterCRC16Test.java @@ -15,33 +15,33 @@ public class JedisClusterCRC16Test { @Test public void testGetCRC16() throws Exception { - Map solutions = prepareSolutionSet(); + Map solutions = prepareSolutionSet(); - for (Entry entry : solutions.entrySet()) { - // string version - assertEquals(entry.getValue().intValue(), - JedisClusterCRC16.getCRC16(entry.getKey())); + for (Entry entry : solutions.entrySet()) { + // string version + assertEquals(entry.getValue().intValue(), + JedisClusterCRC16.getCRC16(entry.getKey())); - // byte array version - assertEquals(entry.getValue().intValue(), - JedisClusterCRC16.getCRC16(SafeEncoder.encode(entry - .getKey()))); - } + // byte array version + assertEquals(entry.getValue().intValue(), + JedisClusterCRC16.getCRC16(SafeEncoder.encode(entry + .getKey()))); + } } @Test public void testGetSlot() { - assertEquals(7186, JedisClusterCRC16.getSlot("51")); + assertEquals(7186, JedisClusterCRC16.getSlot("51")); } private Map prepareSolutionSet() { - Map solutionMap = new HashMap(); - solutionMap.put("", 0x0); - solutionMap.put("123456789", 0x31C3); - solutionMap.put("sfger132515", 0xA45C); - solutionMap.put("hae9Napahngaikeethievubaibogiech", 0x58CE); - solutionMap.put("AAAAAAAAAAAAAAAAAAAAAA", 0x92cd); - solutionMap.put("Hello, World!", 0x4FD6); - return solutionMap; + Map solutionMap = new HashMap(); + solutionMap.put("", 0x0); + solutionMap.put("123456789", 0x31C3); + solutionMap.put("sfger132515", 0xA45C); + solutionMap.put("hae9Napahngaikeethievubaibogiech", 0x58CE); + solutionMap.put("AAAAAAAAAAAAAAAAAAAAAA", 0x92cd); + solutionMap.put("Hello, World!", 0x4FD6); + return solutionMap; } } diff --git a/src/test/java/redis/clients/jedis/tests/utils/JedisClusterTestUtil.java b/src/test/java/redis/clients/jedis/tests/utils/JedisClusterTestUtil.java index fc729e2..3a9c7a7 100644 --- a/src/test/java/redis/clients/jedis/tests/utils/JedisClusterTestUtil.java +++ b/src/test/java/redis/clients/jedis/tests/utils/JedisClusterTestUtil.java @@ -6,79 +6,79 @@ import redis.clients.jedis.exceptions.JedisException; public class JedisClusterTestUtil { public static void waitForClusterReady(Jedis... nodes) - throws InterruptedException { - boolean clusterOk = false; - while (!clusterOk) { - boolean isOk = true; - for (Jedis node : nodes) { - if (!node.clusterInfo().split("\n")[0].contains("ok")) { - isOk = false; - break; - } - } + throws InterruptedException { + boolean clusterOk = false; + while (!clusterOk) { + boolean isOk = true; + for (Jedis node : nodes) { + if (!node.clusterInfo().split("\n")[0].contains("ok")) { + isOk = false; + break; + } + } - if (isOk) { - clusterOk = true; - } + if (isOk) { + clusterOk = true; + } - Thread.sleep(50); - } + Thread.sleep(50); + } } public static String getNodeId(String infoOutput) { - for (String infoLine : infoOutput.split("\n")) { - if (infoLine.contains("myself")) { - return infoLine.split(" ")[0]; - } - } - return ""; + for (String infoLine : infoOutput.split("\n")) { + if (infoLine.contains("myself")) { + return infoLine.split(" ")[0]; + } + } + return ""; } public static String getNodeId(String infoOutput, HostAndPort node) { - for (String infoLine : infoOutput.split("\n")) { - if (infoLine.contains(node.toString())) { - return infoLine.split(" ")[0]; - } - } - return ""; + for (String infoLine : infoOutput.split("\n")) { + if (infoLine.contains(node.toString())) { + return infoLine.split(" ")[0]; + } + } + return ""; } public static void assertNodeIsKnown(Jedis node, String targetNodeId, - int timeoutMs) { - assertNodeRecognizedStatus(node, targetNodeId, true, timeoutMs); + int timeoutMs) { + assertNodeRecognizedStatus(node, targetNodeId, true, timeoutMs); } public static void assertNodeIsUnknown(Jedis node, String targetNodeId, - int timeoutMs) { - assertNodeRecognizedStatus(node, targetNodeId, false, timeoutMs); + int timeoutMs) { + assertNodeRecognizedStatus(node, targetNodeId, false, 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); - if (shouldRecognized == known) - return; + String targetNodeId, boolean shouldRecognized, int timeoutMs) { + int sleepInterval = 100; + for (int sleepTime = 0; sleepTime <= timeoutMs; sleepTime += sleepInterval) { + boolean known = isKnownNode(node, targetNodeId); + if (shouldRecognized == known) + return; - try { - Thread.sleep(sleepInterval); - } catch (InterruptedException e) { - } - } + try { + Thread.sleep(sleepInterval); + } catch (InterruptedException e) { + } + } - throw new JedisException("Node recognize check error"); + throw new JedisException("Node recognize check error"); } private static boolean isKnownNode(Jedis node, String nodeId) { - String infoOutput = node.clusterNodes(); - for (String infoLine : infoOutput.split("\n")) { - if (infoLine.contains(nodeId)) { - return true; - } - } - return false; + String infoOutput = node.clusterNodes(); + for (String infoLine : infoOutput.split("\n")) { + if (infoLine.contains(nodeId)) { + return true; + } + } + return false; } } diff --git a/src/test/java/redis/clients/jedis/tests/utils/JedisSentinelTestUtil.java b/src/test/java/redis/clients/jedis/tests/utils/JedisSentinelTestUtil.java index cde2fe6..e325cee 100644 --- a/src/test/java/redis/clients/jedis/tests/utils/JedisSentinelTestUtil.java +++ b/src/test/java/redis/clients/jedis/tests/utils/JedisSentinelTestUtil.java @@ -8,39 +8,39 @@ import redis.clients.jedis.JedisPubSub; public class JedisSentinelTestUtil { public static HostAndPort waitForNewPromotedMaster(final String masterName, - final Jedis sentinelJedis, final Jedis commandJedis) - throws InterruptedException { + final Jedis sentinelJedis, final Jedis commandJedis) + throws InterruptedException { - final AtomicReference newmaster = new AtomicReference( - ""); + final AtomicReference newmaster = new AtomicReference( + ""); - sentinelJedis.psubscribe(new JedisPubSub() { + sentinelJedis.psubscribe(new JedisPubSub() { - @Override - public void onPMessage(String pattern, String channel, - String message) { - if (channel.equals("+switch-master")) { - newmaster.set(message); - punsubscribe(); - } else if (channel.startsWith("-failover-abort")) { - punsubscribe(); - throw new FailoverAbortedException( - "Unfortunately sentinel cannot failover... reason(channel) : " - + channel + " / message : " + message); - } - } + @Override + public void onPMessage(String pattern, String channel, + String message) { + if (channel.equals("+switch-master")) { + newmaster.set(message); + punsubscribe(); + } else if (channel.startsWith("-failover-abort")) { + punsubscribe(); + throw new FailoverAbortedException( + "Unfortunately sentinel cannot failover... reason(channel) : " + + channel + " / message : " + message); + } + } - @Override - public void onPSubscribe(String pattern, int subscribedChannels) { - commandJedis.sentinelFailover(masterName); - } - }, "*"); + @Override + public void onPSubscribe(String pattern, int subscribedChannels) { + commandJedis.sentinelFailover(masterName); + } + }, "*"); - String[] chunks = newmaster.get().split(" "); - HostAndPort newMaster = new HostAndPort(chunks[3], - Integer.parseInt(chunks[4])); + String[] chunks = newmaster.get().split(" "); + HostAndPort newMaster = new HostAndPort(chunks[3], + Integer.parseInt(chunks[4])); - return newMaster; + return newMaster; } }