diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index bbaa867..5137a5d 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -7,6 +7,8 @@ import static redis.clients.jedis.Protocol.Keyword.NO; import static redis.clients.jedis.Protocol.Keyword.ONE; import static redis.clients.jedis.Protocol.Keyword.STORE; import static redis.clients.jedis.Protocol.Keyword.WITHSCORES; +import static redis.clients.jedis.Protocol.Keyword.RESET; +import static redis.clients.jedis.Protocol.Keyword.LEN; import java.util.ArrayList; import java.util.List; @@ -19,12 +21,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; @@ -34,736 +36,753 @@ public class BinaryClient extends Connection { private long db; public boolean isInMulti() { - return isInMulti; + return isInMulti; } public BinaryClient(final String host) { - super(host); + super(host); } public BinaryClient(final String host, final int port) { - super(host, port); + super(host, port); } 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(PING); + sendCommand(PING); } public void set(final byte[] key, final byte[] value) { - sendCommand(Command.SET, key, value); + sendCommand(Command.SET, key, value); } 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 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[] field) { - sendCommand(HDEL, key, field); + sendCommand(HDEL, key, field); } 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[]... vals) { - byte[][] args = new byte[vals.length+1][]; - args[0] = key; - System.arraycopy(vals, 0, args, 1, vals.length); - sendCommand(RPUSH, args); + byte[][] args = new byte[vals.length + 1][]; + args[0] = key; + System.arraycopy(vals, 0, args, 1, vals.length); + sendCommand(RPUSH, args); } public void lpush(final byte[] key, final byte[]... vals) { - byte [][] args = new byte[vals.length+1][]; - args[0] = key; - System.arraycopy(vals, 0, args, 1, vals.length); - sendCommand(LPUSH, args); + byte[][] args = new byte[vals.length + 1][]; + args[0] = key; + System.arraycopy(vals, 0, args, 1, vals.length); + sendCommand(LPUSH, args); } 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[] member) { - sendCommand(SADD, key, member); + sendCommand(SADD, key, member); } public void smembers(final byte[] key) { - sendCommand(SMEMBERS, key); + sendCommand(SMEMBERS, key); } public void srem(final byte[] key, final byte[] member) { - sendCommand(SREM, key, member); + sendCommand(SREM, key, member); } 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 zrange(final byte[] key, final int start, final int end) { - sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end)); + sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end)); } public void zrem(final byte[] key, final byte[] member) { - sendCommand(ZREM, key, member); + sendCommand(ZREM, key, member); } 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 int start, final int end) { - sendCommand(ZREVRANGE, key, toByteArray(start), toByteArray(end)); + sendCommand(ZREVRANGE, key, toByteArray(start), toByteArray(end)); } public void zrangeWithScores(final byte[] key, final int start, - final int end) { - sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end), - WITHSCORES.raw); + final int end) { + sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end), + WITHSCORES.raw); } public void zrevrangeWithScores(final byte[] key, final int start, - final int end) { - sendCommand(ZREVRANGE, key, toByteArray(start), toByteArray(end), - WITHSCORES.raw); + final int 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; + sendCommand(DISCARD); + isInMulti = false; } public void exec() { - sendCommand(EXEC); - isInMulti = false; + sendCommand(EXEC); + isInMulti = false; } public void watch(final byte[]... keys) { - sendCommand(WATCH, keys); + sendCommand(WATCH, keys); } public void unwatch() { - sendCommand(UNWATCH); + sendCommand(UNWATCH); } 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 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 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 zcount(final byte[] key, final double min, final double max) { - sendCommand(ZCOUNT, key, toByteArray(min), toByteArray(max)); + sendCommand(ZCOUNT, key, toByteArray(min), toByteArray(max)); } public void zrangeByScore(final byte[] key, final double min, - final double max) { - sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max)); + final double max) { + sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max)); } public void zrevrangeByScore(final byte[] key, final double max, - final double min) { - sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min)); + final double min) { + sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min)); } 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 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 zrangeByScore(final byte[] key, final double min, - final double max, final int offset, int count) { - sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max), - LIMIT.raw, toByteArray(offset), toByteArray(count)); + final double max, final int offset, int count) { + sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max), + LIMIT.raw, toByteArray(offset), toByteArray(count)); } public void zrevrangeByScore(final byte[] key, final double max, - final double min, final int offset, int count) { - sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min), - LIMIT.raw, toByteArray(offset), toByteArray(count)); + final double min, final int offset, int count) { + sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min), + LIMIT.raw, toByteArray(offset), toByteArray(count)); } public void zrangeByScoreWithScores(final byte[] key, final double min, - final double max) { - sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max), - WITHSCORES.raw); + final double max) { + sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max), + WITHSCORES.raw); } public void zrevrangeByScoreWithScores(final byte[] key, final double max, - final double min) { - sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min), - WITHSCORES.raw); + final double min) { + sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min), + WITHSCORES.raw); } public void zrangeByScoreWithScores(final byte[] key, final double min, - final double max, final int offset, final int count) { - sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max), - LIMIT.raw, toByteArray(offset), toByteArray(count), - WITHSCORES.raw); + final double max, final int offset, final int count) { + sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max), + 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) { - sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min), - LIMIT.raw, toByteArray(offset), toByteArray(count), - WITHSCORES.raw); + final double min, final int offset, final int count) { + sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min), + LIMIT.raw, toByteArray(offset), toByteArray(count), + WITHSCORES.raw); } public void zremrangeByRank(final byte[] key, final int start, final int end) { - sendCommand(ZREMRANGEBYRANK, key, toByteArray(start), toByteArray(end)); + sendCommand(ZREMRANGEBYRANK, key, toByteArray(start), toByteArray(end)); } public void zremrangeByScore(final byte[] key, final double start, - final double end) { - sendCommand(ZREMRANGEBYSCORE, key, toByteArray(start), toByteArray(end)); + final double end) { + sendCommand(ZREMRANGEBYSCORE, key, toByteArray(start), toByteArray(end)); } 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 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 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, key, string); + sendCommand(LPUSHX, 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, key, string); + sendCommand(RPUSHX, 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 getbit(byte[] key, long offset) { - sendCommand(GETBIT, key, toByteArray(offset)); + sendCommand(GETBIT, key, toByteArray(offset)); } 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(); } - - private void sendEvalCommand(Command command, byte[] script, byte[] keyCount, byte[][] params){ - - final byte[][] allArgs = new byte[params.length + 2][]; - - allArgs[0] = script; - allArgs[1] = keyCount; - - for(int i=0;i keys(final byte[] pattern) { - checkIsInMulti(); - client.keys(pattern); - final HashSet keySet = new HashSet(client - .getBinaryMultiBulkReply()); - return keySet; + checkIsInMulti(); + client.keys(pattern); + final HashSet keySet = new HashSet( + client.getBinaryMultiBulkReply()); + return keySet; } /** @@ -199,9 +199,9 @@ public class BinaryJedis implements BinaryJedisCommands { * empty string is the database is empty */ public byte[] randomBinaryKey() { - checkIsInMulti(); - client.randomKey(); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.randomKey(); + return client.getBinaryBulkReply(); } /** @@ -216,9 +216,9 @@ public class BinaryJedis implements 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(); } /** @@ -233,9 +233,9 @@ public class BinaryJedis implements 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(); } /** @@ -244,9 +244,9 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Integer reply */ public Long dbSize() { - checkIsInMulti(); - client.dbSize(); - return client.getIntegerReply(); + checkIsInMulti(); + client.dbSize(); + return client.getIntegerReply(); } /** @@ -278,9 +278,9 @@ public class BinaryJedis implements 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(); } /** @@ -314,9 +314,9 @@ public class BinaryJedis implements 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(); } /** @@ -331,9 +331,9 @@ public class BinaryJedis implements 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(); } /** @@ -344,9 +344,9 @@ public class BinaryJedis implements 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(); } /** @@ -363,9 +363,9 @@ public class BinaryJedis implements 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(); } /** @@ -375,9 +375,9 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Status code reply */ public String flushAll() { - checkIsInMulti(); - client.flushAll(); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.flushAll(); + return client.getStatusCodeReply(); } /** @@ -392,9 +392,9 @@ public class BinaryJedis implements 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(); } /** @@ -408,9 +408,9 @@ public class BinaryJedis implements 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(); } /** @@ -426,9 +426,9 @@ public class BinaryJedis implements 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(); } /** @@ -444,9 +444,9 @@ public class BinaryJedis implements 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(); } /** @@ -470,9 +470,9 @@ public class BinaryJedis implements 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(); } /** @@ -497,9 +497,9 @@ public class BinaryJedis implements 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(); } /** @@ -525,9 +525,9 @@ public class BinaryJedis implements 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(); } /** @@ -553,9 +553,9 @@ public class BinaryJedis implements BinaryJedisCommands { * after the increment. */ public Long decr(final byte[] key) { - checkIsInMulti(); - client.decr(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.decr(key); + return client.getIntegerReply(); } /** @@ -581,9 +581,9 @@ public class BinaryJedis implements 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(); } /** @@ -609,9 +609,9 @@ public class BinaryJedis implements BinaryJedisCommands { * after the increment. */ public Long incr(final byte[] key) { - checkIsInMulti(); - client.incr(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.incr(key); + return client.getIntegerReply(); } /** @@ -631,9 +631,9 @@ public class BinaryJedis implements 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(); } /** @@ -655,9 +655,9 @@ public class BinaryJedis implements 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(); } /** @@ -676,9 +676,9 @@ public class BinaryJedis implements 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(); } /** @@ -695,9 +695,9 @@ public class BinaryJedis implements 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(); } /** @@ -712,9 +712,9 @@ public class BinaryJedis implements 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(); } /** @@ -730,9 +730,9 @@ public class BinaryJedis implements 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(); } /** @@ -749,9 +749,9 @@ public class BinaryJedis implements 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(); } /** @@ -773,9 +773,9 @@ public class BinaryJedis implements 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(); } /** @@ -789,9 +789,9 @@ public class BinaryJedis implements 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; } /** @@ -805,9 +805,9 @@ public class BinaryJedis implements BinaryJedisCommands { * returned, otherwise 0 is returned and no operation is performed. */ public Long hdel(final byte[] key, final byte[] field) { - checkIsInMulti(); - client.hdel(key, field); - return client.getIntegerReply(); + checkIsInMulti(); + client.hdel(key, field); + return client.getIntegerReply(); } /** @@ -821,9 +821,9 @@ public class BinaryJedis implements BinaryJedisCommands { * an empty hash. */ public Long hlen(final byte[] key) { - checkIsInMulti(); - client.hlen(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.hlen(key); + return client.getIntegerReply(); } /** @@ -835,10 +835,10 @@ public class BinaryJedis implements 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); } /** @@ -850,10 +850,10 @@ public class BinaryJedis implements BinaryJedisCommands { * @return All the fields values contained into a hash. */ public List hvals(final byte[] key) { - checkIsInMulti(); - client.hvals(key); - final List lresult = client.getBinaryMultiBulkReply(); - return lresult; + checkIsInMulti(); + client.hvals(key); + final List lresult = client.getBinaryMultiBulkReply(); + return lresult; } /** @@ -865,16 +865,16 @@ public class BinaryJedis implements 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; } /** @@ -893,9 +893,9 @@ public class BinaryJedis implements BinaryJedisCommands { * list after the push operation. */ public Long rpush(final byte[] key, final byte[]... string) { - checkIsInMulti(); - client.rpush(key, string); - return client.getIntegerReply(); + checkIsInMulti(); + client.rpush(key, string); + return client.getIntegerReply(); } /** @@ -914,9 +914,9 @@ public class BinaryJedis implements BinaryJedisCommands { * list after the push operation. */ public Long lpush(final byte[] key, final byte[]... string) { - checkIsInMulti(); - client.lpush(key, string); - return client.getIntegerReply(); + checkIsInMulti(); + client.lpush(key, string); + return client.getIntegerReply(); } /** @@ -930,9 +930,9 @@ public class BinaryJedis implements 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(); } /** @@ -974,9 +974,9 @@ public class BinaryJedis implements BinaryJedisCommands { * specified range. */ public List lrange(final byte[] key, final int start, final int end) { - checkIsInMulti(); - client.lrange(key, start, end); - return client.getBinaryMultiBulkReply(); + checkIsInMulti(); + client.lrange(key, start, end); + return client.getBinaryMultiBulkReply(); } /** @@ -1014,9 +1014,9 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Status code reply */ public String ltrim(final byte[] key, final int start, final int end) { - checkIsInMulti(); - client.ltrim(key, start, end); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.ltrim(key, start, end); + return client.getStatusCodeReply(); } /** @@ -1038,9 +1038,9 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Bulk reply, specifically the requested element */ public byte[] lindex(final byte[] key, final int index) { - checkIsInMulti(); - client.lindex(key, index); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.lindex(key, index); + return client.getBinaryBulkReply(); } /** @@ -1065,9 +1065,9 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Status code reply */ public String lset(final byte[] key, final int index, final byte[] value) { - checkIsInMulti(); - client.lset(key, index, value); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.lset(key, index, value); + return client.getStatusCodeReply(); } /** @@ -1090,9 +1090,9 @@ public class BinaryJedis implements BinaryJedisCommands { * the operation succeeded */ public Long lrem(final byte[] key, final int count, final byte[] value) { - checkIsInMulti(); - client.lrem(key, count, value); - return client.getIntegerReply(); + checkIsInMulti(); + client.lrem(key, count, value); + return client.getIntegerReply(); } /** @@ -1109,9 +1109,9 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Bulk reply */ public byte[] lpop(final byte[] key) { - checkIsInMulti(); - client.lpop(key); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.lpop(key); + return client.getBinaryBulkReply(); } /** @@ -1128,9 +1128,9 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Bulk reply */ public byte[] rpop(final byte[] key) { - checkIsInMulti(); - client.rpop(key); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.rpop(key); + return client.getBinaryBulkReply(); } /** @@ -1152,9 +1152,9 @@ public class BinaryJedis implements 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(); } /** @@ -1171,9 +1171,9 @@ public class BinaryJedis implements BinaryJedisCommands { * the element was already a member of the set */ public Long sadd(final byte[] key, final byte[] member) { - checkIsInMulti(); - client.sadd(key, member); - return client.getIntegerReply(); + checkIsInMulti(); + client.sadd(key, member); + return client.getIntegerReply(); } /** @@ -1186,10 +1186,10 @@ public class BinaryJedis implements 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); } /** @@ -1205,9 +1205,9 @@ public class BinaryJedis implements 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(); } /** @@ -1223,9 +1223,9 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Bulk reply */ public byte[] spop(final byte[] key) { - checkIsInMulti(); - client.spop(key); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.spop(key); + return client.getBinaryBulkReply(); } /** @@ -1252,10 +1252,10 @@ public class BinaryJedis implements 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(); } /** @@ -1267,9 +1267,9 @@ public class BinaryJedis implements 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(); } /** @@ -1285,9 +1285,9 @@ public class BinaryJedis implements 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; } /** @@ -1310,10 +1310,10 @@ public class BinaryJedis implements 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); } /** @@ -1328,9 +1328,9 @@ public class BinaryJedis implements 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(); } /** @@ -1350,10 +1350,10 @@ public class BinaryJedis implements 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); } /** @@ -1369,9 +1369,9 @@ public class BinaryJedis implements 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(); } /** @@ -1398,10 +1398,10 @@ public class BinaryJedis implements 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); } /** @@ -1413,9 +1413,9 @@ public class BinaryJedis implements 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(); } /** @@ -1431,9 +1431,9 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Bulk reply */ public byte[] srandmember(final byte[] key) { - checkIsInMulti(); - client.srandmember(key); - return client.getBinaryBulkReply(); + checkIsInMulti(); + client.srandmember(key); + return client.getBinaryBulkReply(); } /** @@ -1458,16 +1458,16 @@ public class BinaryJedis implements 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 Set zrange(final byte[] key, final int start, final int 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); } /** @@ -1486,9 +1486,9 @@ public class BinaryJedis implements BinaryJedisCommands { * if the new element was not a member of the set */ public Long zrem(final byte[] key, final byte[] member) { - checkIsInMulti(); - client.zrem(key, member); - return client.getIntegerReply(); + checkIsInMulti(); + client.zrem(key, member); + return client.getIntegerReply(); } /** @@ -1516,11 +1516,11 @@ public class BinaryJedis implements 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); } /** @@ -1544,9 +1544,9 @@ public class BinaryJedis implements 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(); } /** @@ -1570,33 +1570,33 @@ public class BinaryJedis implements 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 int start, - final int end) { - checkIsInMulti(); - client.zrevrange(key, start, end); - final List members = client.getBinaryMultiBulkReply(); - return new LinkedHashSet(members); + final int end) { + checkIsInMulti(); + client.zrevrange(key, start, end); + final List members = client.getBinaryMultiBulkReply(); + return new LinkedHashSet(members); } public Set zrangeWithScores(final byte[] key, final int start, - final int end) { - checkIsInMulti(); - client.zrangeWithScores(key, start, end); - Set set = getBinaryTupledSet(); - return set; + final int end) { + checkIsInMulti(); + client.zrangeWithScores(key, start, end); + Set set = getBinaryTupledSet(); + return set; } public Set zrevrangeWithScores(final byte[] key, final int start, - final int end) { - checkIsInMulti(); - client.zrevrangeWithScores(key, start, end); - Set set = getBinaryTupledSet(); - return set; + final int end) { + checkIsInMulti(); + client.zrevrangeWithScores(key, start, end); + Set set = getBinaryTupledSet(); + return set; } /** @@ -1609,9 +1609,9 @@ public class BinaryJedis implements 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(); } /** @@ -1626,53 +1626,53 @@ public class BinaryJedis implements 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(); - return new Transaction(client); + client.multi(); + return new Transaction(client); } public List multi(final TransactionBlock jedisTransaction) { - List results = null; - jedisTransaction.setClient(client); - try { - client.multi(); - jedisTransaction.execute(); - results = jedisTransaction.exec(); - } catch (Exception ex) { - jedisTransaction.discard(); - } - return results; + List results = null; + jedisTransaction.setClient(client); + try { + client.multi(); + jedisTransaction.execute(); + results = jedisTransaction.exec(); + } catch (Exception ex) { + jedisTransaction.discard(); + } + return results; } 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 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(); } /** @@ -1693,9 +1693,9 @@ public class BinaryJedis implements 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(); } /** @@ -1775,10 +1775,10 @@ public class BinaryJedis implements 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(); } /** @@ -1854,18 +1854,18 @@ public class BinaryJedis implements BinaryJedisCommands { * programming language used. */ public List blpop(final int timeout, final byte[]... keys) { - checkIsInMulti(); - final List args = new ArrayList(); - for (final byte[] arg : keys) { - args.add(arg); - } - args.add(Protocol.toByteArray(timeout)); + checkIsInMulti(); + final List args = new ArrayList(); + for (final byte[] arg : keys) { + args.add(arg); + } + args.add(Protocol.toByteArray(timeout)); - client.blpop(args.toArray(new byte[args.size()][])); - client.setTimeoutInfinite(); - final List multiBulkReply = client.getBinaryMultiBulkReply(); - client.rollbackTimeout(); - return multiBulkReply; + client.blpop(args.toArray(new byte[args.size()][])); + client.setTimeoutInfinite(); + final List multiBulkReply = client.getBinaryMultiBulkReply(); + client.rollbackTimeout(); + return multiBulkReply; } /** @@ -1882,10 +1882,10 @@ public class BinaryJedis implements 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(); } /** @@ -1905,9 +1905,9 @@ public class BinaryJedis implements 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(); } /** @@ -1983,19 +1983,19 @@ public class BinaryJedis implements BinaryJedisCommands { * programming language used. */ public List brpop(final int timeout, final byte[]... keys) { - checkIsInMulti(); - final List args = new ArrayList(); - for (final byte[] arg : keys) { - args.add(arg); - } - args.add(Protocol.toByteArray(timeout)); + checkIsInMulti(); + final List args = new ArrayList(); + for (final byte[] arg : keys) { + args.add(arg); + } + args.add(Protocol.toByteArray(timeout)); - client.brpop(args.toArray(new byte[args.size()][])); - client.setTimeoutInfinite(); - final List multiBulkReply = client.getBinaryMultiBulkReply(); - client.rollbackTimeout(); + client.brpop(args.toArray(new byte[args.size()][])); + client.setTimeoutInfinite(); + final List multiBulkReply = client.getBinaryMultiBulkReply(); + client.rollbackTimeout(); - return multiBulkReply; + return multiBulkReply; } /** @@ -2014,9 +2014,9 @@ public class BinaryJedis implements 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(); } /** @@ -2029,40 +2029,40 @@ public class BinaryJedis implements BinaryJedisCommands { * @return The results of the command in the same order you've run them. */ public List pipelined(final PipelineBlock jedisPipeline) { - jedisPipeline.setClient(client); - jedisPipeline.execute(); - return jedisPipeline.syncAndReturnAll(); + jedisPipeline.setClient(client); + jedisPipeline.execute(); + return jedisPipeline.syncAndReturnAll(); } public Pipeline pipelined() { - Pipeline pipeline = new Pipeline(); - pipeline.setClient(client); - return pipeline; + Pipeline pipeline = new Pipeline(); + pipeline.setClient(client); + return pipeline; } public void subscribe(final JedisPubSub jedisPubSub, - final String... channels) { - client.setTimeoutInfinite(); - jedisPubSub.proceed(client, channels); - client.rollbackTimeout(); + final String... channels) { + client.setTimeoutInfinite(); + jedisPubSub.proceed(client, channels); + client.rollbackTimeout(); } public Long publish(final String channel, final String message) { - client.publish(channel, message); - return client.getIntegerReply(); + client.publish(channel, message); + return client.getIntegerReply(); } public void psubscribe(final JedisPubSub jedisPubSub, - final String... patterns) { - client.setTimeoutInfinite(); - jedisPubSub.proceedWithPatterns(client, patterns); - client.rollbackTimeout(); + final String... patterns) { + client.setTimeoutInfinite(); + jedisPubSub.proceedWithPatterns(client, patterns); + client.rollbackTimeout(); } public Long zcount(final byte[] 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(); } /** @@ -2122,17 +2122,17 @@ public class BinaryJedis implements BinaryJedisCommands { * score range. */ public Set zrangeByScore(final byte[] key, final double min, - final double max) { - checkIsInMulti(); - client.zrangeByScore(key, min, max); - return new LinkedHashSet(client.getBinaryMultiBulkReply()); + final double max) { + checkIsInMulti(); + client.zrangeByScore(key, min, max); + return new LinkedHashSet(client.getBinaryMultiBulkReply()); } 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()); } /** @@ -2192,10 +2192,10 @@ public class BinaryJedis implements BinaryJedisCommands { * score range. */ public Set zrangeByScore(final byte[] 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.getBinaryMultiBulkReply()); + final double max, final int offset, final int count) { + checkIsInMulti(); + client.zrangeByScore(key, min, max, offset, count); + return new LinkedHashSet(client.getBinaryMultiBulkReply()); } /** @@ -2255,11 +2255,11 @@ public class BinaryJedis implements BinaryJedisCommands { * score range. */ public Set zrangeByScoreWithScores(final byte[] key, - final double min, final double max) { - checkIsInMulti(); - client.zrangeByScoreWithScores(key, min, max); - Set set = getBinaryTupledSet(); - return set; + final double min, final double max) { + checkIsInMulti(); + client.zrangeByScoreWithScores(key, min, max); + Set set = getBinaryTupledSet(); + return set; } /** @@ -2319,62 +2319,62 @@ public class BinaryJedis implements BinaryJedisCommands { * score range. */ public Set zrangeByScoreWithScores(final byte[] key, - final double min, final double max, final int offset, - final int count) { - checkIsInMulti(); - client.zrangeByScoreWithScores(key, min, max, offset, count); - Set set = getBinaryTupledSet(); - return set; + final double min, final double max, final int offset, + final int count) { + checkIsInMulti(); + client.zrangeByScoreWithScores(key, min, max, offset, count); + Set set = getBinaryTupledSet(); + return set; } 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) { - checkIsInMulti(); - client.zrevrangeByScore(key, max, min); - return new LinkedHashSet(client.getBinaryMultiBulkReply()); + final double min) { + checkIsInMulti(); + client.zrevrangeByScore(key, max, min); + return new LinkedHashSet(client.getBinaryMultiBulkReply()); } 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) { - checkIsInMulti(); - client.zrevrangeByScore(key, max, min, offset, count); - return new LinkedHashSet(client.getBinaryMultiBulkReply()); + final double 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) { - checkIsInMulti(); - client.zrevrangeByScoreWithScores(key, max, min); - Set set = getBinaryTupledSet(); - return set; + final double max, final double min) { + checkIsInMulti(); + client.zrevrangeByScoreWithScores(key, max, min); + Set set = getBinaryTupledSet(); + return set; } public Set zrevrangeByScoreWithScores(final byte[] key, - final double max, final double min, final int offset, - final int count) { - checkIsInMulti(); - client.zrevrangeByScoreWithScores(key, max, min, offset, count); - Set set = getBinaryTupledSet(); - return set; + final double max, final double min, final int offset, + final int count) { + checkIsInMulti(); + client.zrevrangeByScoreWithScores(key, max, min, offset, count); + Set set = getBinaryTupledSet(); + return set; } /** @@ -2391,9 +2391,9 @@ public class BinaryJedis implements BinaryJedisCommands { * */ public Long zremrangeByRank(final byte[] key, final int start, final int end) { - checkIsInMulti(); - client.zremrangeByRank(key, start, end); - return client.getIntegerReply(); + checkIsInMulti(); + client.zremrangeByRank(key, start, end); + return client.getIntegerReply(); } /** @@ -2411,10 +2411,10 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Integer reply, specifically the number of elements removed. */ public Long zremrangeByScore(final byte[] 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(); } /** @@ -2456,9 +2456,9 @@ public class BinaryJedis implements 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(); } /** @@ -2501,10 +2501,10 @@ public class BinaryJedis implements 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(); } /** @@ -2546,9 +2546,9 @@ public class BinaryJedis implements 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(); } /** @@ -2591,10 +2591,10 @@ public class BinaryJedis implements 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(); } /** @@ -2614,8 +2614,8 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Status code reply */ public String save() { - client.save(); - return client.getStatusCodeReply(); + client.save(); + return client.getStatusCodeReply(); } /** @@ -2629,8 +2629,8 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Status code reply */ public String bgsave() { - client.bgsave(); - return client.getStatusCodeReply(); + client.bgsave(); + return client.getStatusCodeReply(); } /** @@ -2652,8 +2652,8 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Status code reply */ public String bgrewriteaof() { - client.bgrewriteaof(); - return client.getStatusCodeReply(); + client.bgrewriteaof(); + return client.getStatusCodeReply(); } /** @@ -2668,8 +2668,8 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Integer reply, specifically an UNIX time stamp. */ public Long lastsave() { - client.lastsave(); - return client.getIntegerReply(); + client.lastsave(); + return client.getIntegerReply(); } /** @@ -2685,14 +2685,14 @@ public class BinaryJedis implements BinaryJedisCommands { * the server quits and the connection is closed. */ public String shutdown() { - client.shutdown(); - String status = null; - try { - status = client.getStatusCodeReply(); - } catch (JedisException ex) { - status = null; - } - return status; + client.shutdown(); + String status = null; + try { + status = client.getStatusCodeReply(); + } catch (JedisException ex) { + status = null; + } + return status; } /** @@ -2736,8 +2736,8 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Bulk reply */ public String info() { - client.info(); - return client.getBulkReply(); + client.info(); + return client.getBulkReply(); } /** @@ -2751,8 +2751,8 @@ public class BinaryJedis implements BinaryJedisCommands { * @param jedisMonitor */ public void monitor(final JedisMonitor jedisMonitor) { - client.monitor(); - jedisMonitor.proceed(client); + client.monitor(); + jedisMonitor.proceed(client); } /** @@ -2781,13 +2781,13 @@ public class BinaryJedis implements 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(); } /** @@ -2827,8 +2827,8 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Bulk reply. */ public List configGet(final byte[] pattern) { - client.configGet(pattern); - return client.getBinaryMultiBulkReply(); + client.configGet(pattern); + return client.getBinaryMultiBulkReply(); } /** @@ -2837,8 +2837,8 @@ public class BinaryJedis implements BinaryJedisCommands { * @return */ public String configResetStat() { - client.configResetStat(); - return client.getStatusCodeReply(); + client.configResetStat(); + return client.getStatusCodeReply(); } /** @@ -2876,26 +2876,26 @@ public class BinaryJedis implements 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(); } /** @@ -2909,33 +2909,33 @@ public class BinaryJedis implements 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; } /** @@ -2948,11 +2948,11 @@ public class BinaryJedis implements BinaryJedisCommands { * @return the element */ public byte[] brpoplpush(byte[] source, byte[] destination, int timeout) { - client.brpoplpush(source, destination, timeout); - client.setTimeoutInfinite(); - byte[] reply = client.getBinaryBulkReply(); - client.rollbackTimeout(); - return reply; + client.brpoplpush(source, destination, timeout); + client.setTimeoutInfinite(); + byte[] reply = client.getBinaryBulkReply(); + client.rollbackTimeout(); + return reply; } /** @@ -2964,8 +2964,8 @@ public class BinaryJedis implements BinaryJedisCommands { * @return */ 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; } /** @@ -2976,87 +2976,110 @@ public class BinaryJedis implements 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 setrange(byte[] key, long offset, byte[] value) { - client.setrange(key, offset, value); - return client.getIntegerReply(); + client.setrange(key, offset, value); + return client.getIntegerReply(); } public String getrange(byte[] key, long startOffset, long endOffset) { - client.getrange(key, startOffset, endOffset); - return client.getBulkReply(); + client.getrange(key, startOffset, endOffset); + return client.getBulkReply(); } 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(); - jedisPubSub.proceed(client, channels); - client.rollbackTimeout(); + client.setTimeoutInfinite(); + jedisPubSub.proceed(client, channels); + client.rollbackTimeout(); } public void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns) { - client.setTimeoutInfinite(); - jedisPubSub.proceedWithPatterns(client, patterns); - client.rollbackTimeout(); + client.setTimeoutInfinite(); + jedisPubSub.proceedWithPatterns(client, patterns); + client.rollbackTimeout(); } public Long getDB() { - return client.getDB(); + return client.getDB(); } - + /** - * Evaluates scripts using the Lua interpreter built into Redis starting from version 2.6.0. + * Evaluates scripts using the Lua interpreter built into Redis starting + * from version 2.6.0. *

* * @return Script result */ - public Object eval(byte[] script, List keys, List args) { - client.setTimeoutInfinite(); - client.eval(script, toByteArray(keys.size()), getParams(keys, args)); - return client.getOne(); - } - private byte[][] getParams(List keys, List args){ - int keyCount = keys.size(); - byte[][] params = new byte[keyCount + args.size()][]; - - for(int i=0;i keys, List args) { + client.setTimeoutInfinite(); + client.eval(script, toByteArray(keys.size()), getParams(keys, args)); + return client.getOne(); } - public Object eval(byte[] script, byte[] keyCount, byte[][] params) { - client.setTimeoutInfinite(); - client.eval(script, keyCount, params); - return client.getOne(); - } - - public byte[] scriptFlush(){ - client.scriptFlush(); - return client.getBinaryBulkReply(); + + private byte[][] getParams(List keys, List args) { + int keyCount = keys.size(); + byte[][] params = new byte[keyCount + args.size()][]; + + for (int i = 0; i < keyCount; i++) + params[i] = keys.get(i); + + for (int i = 0; i < keys.size(); i++) + params[keyCount + i] = args.get(i); + + return params; } - - public List scriptExists(byte[]... sha1){ - client.scriptExists(sha1); - return client.getIntegerMultiBulkReply(); + + public Object eval(byte[] script, byte[] keyCount, byte[][] params) { + client.setTimeoutInfinite(); + client.eval(script, keyCount, params); + return client.getOne(); } - - public byte[] scriptLoad(byte[] script){ - client.scriptLoad(script); - return client.getBinaryBulkReply(); + + public byte[] scriptFlush() { + client.scriptFlush(); + return client.getBinaryBulkReply(); } - - public byte[] scriptKill(){ - client.scriptKill(); - return client.getBinaryBulkReply(); + + public List scriptExists(byte[]... sha1) { + client.scriptExists(sha1); + return client.getIntegerMultiBulkReply(); + } + + public byte[] scriptLoad(byte[] script) { + client.scriptLoad(script); + return client.getBinaryBulkReply(); + } + + public byte[] scriptKill() { + client.scriptKill(); + return client.getBinaryBulkReply(); + } + + public byte[] slowlogReset() { + client.slowlogReset(); + return client.getBinaryBulkReply(); + } + + public long slowlogLen() { + client.slowlogLen(); + return client.getIntegerReply(); + } + + public List slowlogGetBinary() { + client.slowlogGet(); + return client.getBinaryMultiBulkReply(); + } + + public List slowlogGetBinary(long entries) { + client.slowlogGet(entries); + return client.getBinaryMultiBulkReply(); } } diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 0a4699b..d83853b 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -10,28 +10,29 @@ import java.util.Set; import redis.clients.jedis.BinaryClient.LIST_POSITION; import redis.clients.util.SafeEncoder; +import redis.clients.util.Slowlog; public class Jedis extends BinaryJedis implements JedisCommands { 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 String ping() { - checkIsInMulti(); - client.ping(); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.ping(); + return client.getStatusCodeReply(); } /** @@ -45,9 +46,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(); } /** @@ -61,9 +62,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(); } /** @@ -71,9 +72,9 @@ public class Jedis extends BinaryJedis implements JedisCommands { */ public String quit() { - checkIsInMulti(); - client.quit(); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.quit(); + return client.getStatusCodeReply(); } /** @@ -87,9 +88,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; } /** @@ -103,9 +104,9 @@ 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(); } /** @@ -123,9 +124,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(); } /** @@ -136,9 +137,9 @@ public class Jedis extends BinaryJedis implements JedisCommands { */ public String flushDB() { - checkIsInMulti(); - client.flushDB(); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.flushDB(); + return client.getStatusCodeReply(); } /** @@ -173,10 +174,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()); } /** @@ -188,9 +189,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(); } /** @@ -205,9 +206,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(); } /** @@ -222,9 +223,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(); } /** @@ -256,9 +257,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(); } /** @@ -292,9 +293,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(); } /** @@ -309,9 +310,9 @@ public class Jedis extends BinaryJedis implements JedisCommands { * have an associated expire, -1 is returned. */ public Long ttl(final String key) { - checkIsInMulti(); - client.ttl(key); - return client.getIntegerReply(); + checkIsInMulti(); + client.ttl(key); + return client.getIntegerReply(); } /** @@ -323,9 +324,9 @@ public class Jedis extends BinaryJedis implements JedisCommands { */ public String select(final int index) { - checkIsInMulti(); - client.select(index); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.select(index); + return client.getStatusCodeReply(); } /** @@ -342,9 +343,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(); } /** @@ -355,9 +356,9 @@ public class Jedis extends BinaryJedis implements JedisCommands { */ public String flushAll() { - checkIsInMulti(); - client.flushAll(); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.flushAll(); + return client.getStatusCodeReply(); } /** @@ -372,9 +373,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(); } /** @@ -388,9 +389,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(); } /** @@ -406,9 +407,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(); } /** @@ -424,9 +425,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(); } /** @@ -450,9 +451,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(); } /** @@ -477,9 +478,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(); } /** @@ -505,9 +506,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(); } /** @@ -533,9 +534,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(); } /** @@ -561,9 +562,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(); } /** @@ -589,9 +590,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(); } /** @@ -611,9 +612,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(); } /** @@ -635,9 +636,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(); } /** @@ -656,9 +657,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(); } /** @@ -675,9 +676,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(); } /** @@ -692,9 +693,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(); } /** @@ -710,9 +711,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(); } /** @@ -729,9 +730,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(); } /** @@ -753,9 +754,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(); } /** @@ -769,9 +770,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; } /** @@ -785,9 +786,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 field) { - checkIsInMulti(); - client.hdel(key, field); - return client.getIntegerReply(); + checkIsInMulti(); + client.hdel(key, field); + return client.getIntegerReply(); } /** @@ -801,9 +802,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(); } /** @@ -815,10 +816,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()); } /** @@ -830,10 +831,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; } /** @@ -845,10 +846,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()); } /** @@ -867,9 +868,9 @@ public class Jedis extends BinaryJedis implements JedisCommands { * list after the push operation. */ public Long rpush(final String key, final String... string) { - checkIsInMulti(); - client.rpush(key, string); - return client.getIntegerReply(); + checkIsInMulti(); + client.rpush(key, string); + return client.getIntegerReply(); } /** @@ -888,9 +889,9 @@ public class Jedis extends BinaryJedis implements JedisCommands { * list after the push operation. */ public Long lpush(final String key, final String... string) { - checkIsInMulti(); - client.lpush(key, string); - return client.getIntegerReply(); + checkIsInMulti(); + client.lpush(key, string); + return client.getIntegerReply(); } /** @@ -904,9 +905,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(); } /** @@ -947,10 +948,11 @@ public class Jedis extends BinaryJedis implements JedisCommands { * @return Multi bulk reply, specifically a list of elements in the * specified range. */ - public List lrange(final String key, final long start, final long end) { - checkIsInMulti(); - client.lrange(key, start, end); - return client.getMultiBulkReply(); + public List lrange(final String key, final long start, + final long end) { + checkIsInMulti(); + client.lrange(key, start, end); + return client.getMultiBulkReply(); } /** @@ -988,9 +990,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(); } /** @@ -1012,9 +1014,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(); } /** @@ -1039,9 +1041,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(); } /** @@ -1064,9 +1066,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(); } /** @@ -1083,9 +1085,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(); } /** @@ -1102,9 +1104,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(); } /** @@ -1126,9 +1128,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(); } /** @@ -1145,9 +1147,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 member) { - checkIsInMulti(); - client.sadd(key, member); - return client.getIntegerReply(); + checkIsInMulti(); + client.sadd(key, member); + return client.getIntegerReply(); } /** @@ -1160,10 +1162,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); } /** @@ -1179,9 +1181,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 member) { - checkIsInMulti(); - client.srem(key, member); - return client.getIntegerReply(); + checkIsInMulti(); + client.srem(key, member); + return client.getIntegerReply(); } /** @@ -1197,9 +1199,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(); } /** @@ -1226,10 +1228,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(); } /** @@ -1241,9 +1243,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(); } /** @@ -1259,16 +1261,16 @@ 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; } /** * Return the members of a set resulting from the intersection of all the * sets hold at the specified keys. Like in - * {@link #lrange(String, long, long) LRANGE} the result is sent to the client - * as a multi-bulk reply (see the protocol specification for more + * {@link #lrange(String, long, long) LRANGE} the result is sent to the + * client as a multi-bulk reply (see the protocol specification for more * information). If just a single key is specified, then this command * produces the same result as {@link #smembers(String) SMEMBERS}. Actually * SMEMBERS is just syntax sugar for SINTER. @@ -1284,10 +1286,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); } /** @@ -1302,9 +1304,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(); } /** @@ -1324,10 +1326,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); } /** @@ -1343,9 +1345,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(); } /** @@ -1372,10 +1374,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()); } /** @@ -1387,9 +1389,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(); } /** @@ -1405,9 +1407,9 @@ 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(); } /** @@ -1432,16 +1434,16 @@ 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 Set zrange(final String key, final int start, final int 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); } /** @@ -1460,9 +1462,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 member) { - checkIsInMulti(); - client.zrem(key, member); - return client.getIntegerReply(); + checkIsInMulti(); + client.zrem(key, member); + return client.getIntegerReply(); } /** @@ -1490,11 +1492,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); } /** @@ -1518,9 +1520,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(); } /** @@ -1544,33 +1546,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 int start, - final int end) { - checkIsInMulti(); - client.zrevrange(key, start, end); - final List members = client.getMultiBulkReply(); - return new LinkedHashSet(members); + final int end) { + checkIsInMulti(); + client.zrevrange(key, start, end); + final List members = client.getMultiBulkReply(); + return new LinkedHashSet(members); } public Set zrangeWithScores(final String key, final int start, - final int end) { - checkIsInMulti(); - client.zrangeWithScores(key, start, end); - Set set = getTupledSet(); - return set; + final int end) { + checkIsInMulti(); + client.zrangeWithScores(key, start, end); + Set set = getTupledSet(); + return set; } public Set zrevrangeWithScores(final String key, final int start, - final int end) { - checkIsInMulti(); - client.zrevrangeWithScores(key, start, end); - Set set = getTupledSet(); - return set; + final int end) { + checkIsInMulti(); + client.zrevrangeWithScores(key, start, end); + Set set = getTupledSet(); + return set; } /** @@ -1583,9 +1585,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(); } /** @@ -1600,15 +1602,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(); } /** @@ -1629,9 +1631,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(); } /** @@ -1711,10 +1713,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(); } /** @@ -1790,18 +1792,18 @@ public class Jedis extends BinaryJedis implements JedisCommands { * programming language used. */ public List blpop(final int timeout, final String... keys) { - checkIsInMulti(); - List args = new ArrayList(); - for (String arg : keys) { - args.add(arg); - } - args.add(String.valueOf(timeout)); + checkIsInMulti(); + List args = new ArrayList(); + for (String arg : keys) { + args.add(arg); + } + args.add(String.valueOf(timeout)); - client.blpop(args.toArray(new String[args.size()])); - client.setTimeoutInfinite(); - final List multiBulkReply = client.getMultiBulkReply(); - client.rollbackTimeout(); - return multiBulkReply; + client.blpop(args.toArray(new String[args.size()])); + client.setTimeoutInfinite(); + final List multiBulkReply = client.getMultiBulkReply(); + client.rollbackTimeout(); + return multiBulkReply; } /** @@ -1818,10 +1820,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(); } /** @@ -1841,9 +1843,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(); } /** @@ -1919,19 +1921,19 @@ public class Jedis extends BinaryJedis implements JedisCommands { * programming language used. */ public List brpop(final int timeout, final String... keys) { - checkIsInMulti(); - List args = new ArrayList(); - for (String arg : keys) { - args.add(arg); - } - args.add(String.valueOf(timeout)); + checkIsInMulti(); + List args = new ArrayList(); + for (String arg : keys) { + args.add(arg); + } + args.add(String.valueOf(timeout)); - client.brpop(args.toArray(new String[args.size()])); - client.setTimeoutInfinite(); - List multiBulkReply = client.getMultiBulkReply(); - client.rollbackTimeout(); + client.brpop(args.toArray(new String[args.size()])); + client.setTimeoutInfinite(); + List multiBulkReply = client.getMultiBulkReply(); + client.rollbackTimeout(); - return multiBulkReply; + return multiBulkReply; } /** @@ -1951,37 +1953,37 @@ public class Jedis extends BinaryJedis implements JedisCommands { */ public String auth(final String password) { - checkIsInMulti(); - client.auth(password); - return client.getStatusCodeReply(); + checkIsInMulti(); + client.auth(password); + return client.getStatusCodeReply(); } public void subscribe(JedisPubSub jedisPubSub, String... channels) { - checkIsInMulti(); - connect(); - client.setTimeoutInfinite(); - jedisPubSub.proceed(client, channels); - client.rollbackTimeout(); + checkIsInMulti(); + connect(); + client.setTimeoutInfinite(); + jedisPubSub.proceed(client, channels); + client.rollbackTimeout(); } public Long publish(String channel, String message) { - checkIsInMulti(); - client.publish(channel, message); - return client.getIntegerReply(); + checkIsInMulti(); + client.publish(channel, message); + return client.getIntegerReply(); } public void psubscribe(JedisPubSub jedisPubSub, String... patterns) { - checkIsInMulti(); - connect(); - client.setTimeoutInfinite(); - jedisPubSub.proceedWithPatterns(client, patterns); - client.rollbackTimeout(); + checkIsInMulti(); + connect(); + client.setTimeoutInfinite(); + jedisPubSub.proceedWithPatterns(client, patterns); + client.rollbackTimeout(); } 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(); } /** @@ -2042,17 +2044,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()); } /** @@ -2112,10 +2114,10 @@ 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()); } /** @@ -2175,11 +2177,11 @@ 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; } /** @@ -2239,63 +2241,61 @@ 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; } 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; } /** @@ -2312,9 +2312,9 @@ public class Jedis extends BinaryJedis implements JedisCommands { * */ public Long zremrangeByRank(final String key, final int start, final int end) { - checkIsInMulti(); - client.zremrangeByRank(key, start, end); - return client.getIntegerReply(); + checkIsInMulti(); + client.zremrangeByRank(key, start, end); + return client.getIntegerReply(); } /** @@ -2332,10 +2332,10 @@ 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(); } /** @@ -2377,9 +2377,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(); } /** @@ -2422,10 +2422,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(); } /** @@ -2467,9 +2467,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(); } /** @@ -2512,20 +2512,20 @@ 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(); } 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(); } /** @@ -2539,24 +2539,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(); } /** @@ -2569,11 +2569,11 @@ 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(); - String reply = client.getBulkReply(); - client.rollbackTimeout(); - return reply; + client.brpoplpush(source, destination, timeout); + client.setTimeoutInfinite(); + String reply = client.getBulkReply(); + client.rollbackTimeout(); + return reply; } /** @@ -2585,8 +2585,8 @@ 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; } /** @@ -2597,20 +2597,20 @@ 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(); } - + /** * Retrieve the configuration of a running Redis server. Not all the * configuration parameters are supported. @@ -2648,10 +2648,10 @@ 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(); } - + /** * Alter the configuration of a running Redis server. Not all the * configuration parameters are supported. @@ -2687,92 +2687,102 @@ 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(); - client.eval(script, keyCount, params); - - return getEvalResult(); + client.setTimeoutInfinite(); + client.eval(script, keyCount, params); + + return getEvalResult(); } - - private String[] getParams(List keys, List args){ - int keyCount = keys.size(); - int argCount = args.size(); - - String[] params = new String[keyCount + args.size()]; - - for(int i=0;i keys, List args) { + int keyCount = keys.size(); + int argCount = 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 < argCount; i++) + params[keyCount + i] = args.get(i); + + return params; } - + public Object eval(String script, List keys, List args) { - return eval(script, keys.size(), getParams(keys, args)); - } - - public Object eval(String script) { - return eval(script,0); - } - - public Object evalsha(String script) { - return evalsha(script,0); - } - - private Object getEvalResult(){ - Object result = client.getOne(); - - 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(SafeEncoder.encode((byte[])bin)); - - return listResult; - } - - return result; + return eval(script, keys.size(), getParams(keys, args)); } - + + public Object eval(String script) { + return eval(script, 0); + } + + public Object evalsha(String script) { + return evalsha(script, 0); + } + + private Object getEvalResult() { + Object result = client.getOne(); + + 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(SafeEncoder.encode((byte[]) bin)); + + return listResult; + } + + return result; + } + public Object evalsha(String sha1, List keys, List 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(); - } - - public Boolean scriptExists(String sha1){ - String[] a = new String[1]; - a[0] = sha1; - return scriptExists(a).get(0); + return evalsha(sha1, keys.size(), getParams(keys, args)); } - public List scriptExists(String... sha1){ - client.scriptExists(sha1); - List result = client.getIntegerMultiBulkReply(); - List exists = new ArrayList(); - - for(Long value : result) - exists.add(value == 1); - - return exists; + public Object evalsha(String sha1, int keyCount, String... params) { + checkIsInMulti(); + client.evalsha(sha1, keyCount, params); + + return getEvalResult(); } - - public String scriptLoad(String script){ - client.scriptLoad(script); - return client.getBulkReply(); + + public Boolean scriptExists(String sha1) { + 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(); + + for (Long value : result) + exists.add(value == 1); + + return exists; + } + + public String scriptLoad(String script) { + client.scriptLoad(script); + return client.getBulkReply(); + } + + public List slowlogGet() { + client.slowlogGet(); + return Slowlog.from(client.getObjectMultiBulkReply()); + } + + public List slowlogGet(long entries) { + client.slowlogGet(entries); + return Slowlog.from(client.getObjectMultiBulkReply()); } } diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index 18fd623..767ab04 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -25,143 +25,141 @@ public final class Protocol { public static final byte COLON_BYTE = ':'; 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(); - throw new JedisDataException(message); + String message = is.readLine(); + throw new JedisDataException(message); } private static Object process(final RedisInputStream is) { - try { - byte b = is.readByte(); - if (b == MINUS_BYTE) { - processError(is); - } else if (b == ASTERISK_BYTE) { - return processMultiBulkReply(is); - } else if (b == COLON_BYTE) { - return processInteger(is); - } else if (b == DOLLAR_BYTE) { - return processBulkReply(is); - } else if (b == PLUS_BYTE) { - return processStatusCodeReply(is); - } else { - throw new JedisConnectionException("Unknown reply: " + (char) b); - } - } catch (IOException e) { - throw new JedisConnectionException(e); - } - return null; + try { + byte b = is.readByte(); + if (b == MINUS_BYTE) { + processError(is); + } else if (b == ASTERISK_BYTE) { + return processMultiBulkReply(is); + } else if (b == COLON_BYTE) { + return processInteger(is); + } else if (b == DOLLAR_BYTE) { + return processBulkReply(is); + } else if (b == PLUS_BYTE) { + return processStatusCodeReply(is); + } else { + throw new JedisConnectionException("Unknown reply: " + (char) b); + } + } catch (IOException e) { + throw new JedisConnectionException(e); + } + return null; } private static byte[] processStatusCodeReply(final RedisInputStream is) { - return SafeEncoder.encode(is.readLine()); + return SafeEncoder.encode(is.readLine()); } private static byte[] processBulkReply(final RedisInputStream is) { - int len = Integer.parseInt(is.readLine()); - if (len == -1) { - return null; - } - byte[] read = new byte[len]; - int offset = 0; - try { - while (offset < len) { - offset += is.read(read, offset, (len - offset)); - } - // read 2 more bytes for the command delimiter - is.readByte(); - is.readByte(); - } catch (IOException e) { - throw new JedisConnectionException(e); - } + int len = Integer.parseInt(is.readLine()); + if (len == -1) { + return null; + } + byte[] read = new byte[len]; + int offset = 0; + try { + while (offset < len) { + offset += is.read(read, offset, (len - offset)); + } + // read 2 more bytes for the command delimiter + is.readByte(); + is.readByte(); + } catch (IOException e) { + throw new JedisConnectionException(e); + } - return read; + return read; } private static Long processInteger(final RedisInputStream is) { - String num = is.readLine(); - return Long.valueOf(num); + String num = is.readLine(); + return Long.valueOf(num); } private static List processMultiBulkReply(final RedisInputStream is) { - int num = Integer.parseInt(is.readLine()); - if (num == -1) { - return null; - } - 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; + int num = Integer.parseInt(is.readLine()); + if (num == -1) { + return null; + } + 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 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, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT; + PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG; - 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, FLUSH, EXISTS, LOAD, KILL; - 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; + 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/util/Slowlog.java b/src/main/java/redis/clients/util/Slowlog.java new file mode 100644 index 0000000..0a0e7be --- /dev/null +++ b/src/main/java/redis/clients/util/Slowlog.java @@ -0,0 +1,53 @@ +package redis.clients.util; + +import java.util.ArrayList; +import java.util.List; + +public class Slowlog { + private final long id; + private final long timeStamp; + private final long executionTime; + private final List args; + + @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)); + } + + 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); + + List bargs = (List)properties.get(3); + this.args = new ArrayList(bargs.size()); + + for(byte[] barg:bargs){ + this.args.add(SafeEncoder.encode(barg)); + } + } + + public long getId() { + return id; + } + + public long getTimeStamp() { + return timeStamp; + } + + public long getExecutionTime() { + return executionTime; + } + + public List getArgs() { + return args; + } +} diff --git a/src/test/java/redis/clients/jedis/tests/commands/SlowlogCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/SlowlogCommandsTest.java new file mode 100644 index 0000000..3e37d13 --- /dev/null +++ b/src/test/java/redis/clients/jedis/tests/commands/SlowlogCommandsTest.java @@ -0,0 +1,47 @@ +package redis.clients.jedis.tests.commands; + +import java.util.List; + +import org.junit.Test; + +import redis.clients.util.Slowlog; + +public class SlowlogCommandsTest extends JedisCommandTestBase { + + @Test + public void slowlog() { + //do something + jedis.set("foo", "bar"); + jedis.set("foo2", "bar2"); + + 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()); + + List breducedLog = jedis.slowlogGetBinary(1); + assertEquals(1, breducedLog.size()); + + List log1 = jedis.slowlogGet(); + List blog1 = jedis.slowlogGetBinary(); + + assertNotNull(log1); + assertNotNull(blog1); + + long len1 = jedis.slowlogLen(); + + jedis.slowlogReset(); + + 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()); + } +} \ No newline at end of file