diff --git a/src/main/java/redis/clients/jedis/BasicCommands.java b/src/main/java/redis/clients/jedis/BasicCommands.java index c201e4108f..6eb3e8a7cd 100644 --- a/src/main/java/redis/clients/jedis/BasicCommands.java +++ b/src/main/java/redis/clients/jedis/BasicCommands.java @@ -1,5 +1,7 @@ package redis.clients.jedis; +import java.util.List; + public interface BasicCommands { String ping(); @@ -41,4 +43,6 @@ public interface BasicCommands { String configResetStat(); Long waitReplicas(int replicas, long timeout); + + List role(); } diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index 4d235b26aa..e9b68cf0ae 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -200,7 +200,7 @@ public void incrBy(final byte[] key, final long integer) { } public void incrByFloat(final byte[] key, final double value) { - sendCommand(INCRBYFLOAT, key, toByteArray(value)); + sendCommand(INCRBYFLOAT, key, toByteArray(value)); } public void incr(final byte[] key) { @@ -320,7 +320,7 @@ public void rpoplpush(final byte[] srckey, final byte[] dstkey) { public void sadd(final byte[] key, final byte[]... members) { sendCommand(SADD, joinParameters(key, members)); } - + public void smembers(final byte[] key) { sendCommand(SMEMBERS, key); } @@ -560,10 +560,11 @@ public void punsubscribe() { public void punsubscribe(final byte[]... patterns) { sendCommand(PUNSUBSCRIBE, patterns); } - + public void pubsub(final byte[]... args) { - sendCommand(PUBSUB, args); + sendCommand(PUBSUB, args); } + public void zcount(final byte[] key, final double min, final double max) { byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf" @@ -929,15 +930,16 @@ public void setbit(byte[] key, long offset, boolean value) { public void getbit(byte[] key, long offset) { sendCommand(GETBIT, key, toByteArray(offset)); } - - public void bitpos(final byte[] key, final boolean value, final BitPosParams params) { + + public void bitpos(final byte[] key, final boolean value, + final BitPosParams params) { final List args = new ArrayList(); args.add(key); args.add(toByteArray(value)); args.addAll(params.getParams()); sendCommand(BITPOS, args.toArray(new byte[args.size()][])); } - + public void setrange(byte[] key, long offset, byte[] value) { sendCommand(SETRANGE, key, toByteArray(offset), value); } @@ -1037,6 +1039,10 @@ public void slowlogLen() { sendCommand(SLOWLOG, LEN.raw); } + public void role() { + sendCommand(ROLE); + } + public void objectRefcount(byte[] key) { sendCommand(OBJECT, REFCOUNT.raw, key); } @@ -1191,7 +1197,7 @@ public void hscan(final byte[] key, int cursor, final ScanParams params) { args.addAll(params.getParams()); sendCommand(HSCAN, args.toArray(new byte[args.size()][])); } - + @Deprecated /** * This method is deprecated due to bug (scan cursor should be unsigned long) @@ -1205,7 +1211,7 @@ public void sscan(final byte[] key, int cursor, final ScanParams params) { args.addAll(params.getParams()); sendCommand(SSCAN, args.toArray(new byte[args.size()][])); } - + @Deprecated /** * This method is deprecated due to bug (scan cursor should be unsigned long) @@ -1219,7 +1225,7 @@ public void zscan(final byte[] key, int cursor, final ScanParams params) { args.addAll(params.getParams()); sendCommand(ZSCAN, args.toArray(new byte[args.size()][])); } - + public void scan(final byte[] cursor, final ScanParams params) { final List args = new ArrayList(); args.add(cursor); @@ -1227,7 +1233,8 @@ public void scan(final byte[] cursor, final ScanParams params) { sendCommand(SCAN, args.toArray(new byte[args.size()][])); } - public void hscan(final byte[] key, final byte[] cursor, final ScanParams params) { + public void hscan(final byte[] key, final byte[] cursor, + final ScanParams params) { final List args = new ArrayList(); args.add(key); args.add(cursor); @@ -1235,7 +1242,8 @@ public void hscan(final byte[] key, final byte[] cursor, final ScanParams params sendCommand(HSCAN, args.toArray(new byte[args.size()][])); } - public void sscan(final byte[] key, final byte[] cursor, final ScanParams params) { + public void sscan(final byte[] key, final byte[] cursor, + final ScanParams params) { final List args = new ArrayList(); args.add(key); args.add(cursor); @@ -1243,7 +1251,8 @@ public void sscan(final byte[] key, final byte[] cursor, final ScanParams params sendCommand(SSCAN, args.toArray(new byte[args.size()][])); } - public void zscan(final byte[] key, final byte[] cursor, final ScanParams params) { + public void zscan(final byte[] key, final byte[] cursor, + final ScanParams params) { final List args = new ArrayList(); args.add(key); args.add(cursor); @@ -1262,20 +1271,20 @@ public void cluster(final byte[]... args) { public void asking() { sendCommand(Command.ASKING); } - + public void pfadd(final byte[] key, final byte[]... elements) { - sendCommand(PFADD, joinParameters(key, elements)); + sendCommand(PFADD, joinParameters(key, elements)); } - + public void pfcount(final byte[] key) { - sendCommand(PFCOUNT, key); + sendCommand(PFCOUNT, key); } - public void pfcount(final byte[]...keys) { - sendCommand(PFCOUNT, keys); + public void pfcount(final byte[]... keys) { + sendCommand(PFCOUNT, keys); } public void pfmerge(final byte[] destkey, final byte[]... sourcekeys) { - sendCommand(PFMERGE, joinParameters(destkey, sourcekeys)); + sendCommand(PFMERGE, joinParameters(destkey, sourcekeys)); } } diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 781f17f179..75764dbdb3 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -3478,6 +3478,13 @@ public Long waitReplicas(int replicas, long timeout) { return client.getIntegerReply(); } + @Override + public List role() { + checkIsInMulti(); + client.role(); + return client.getObjectMultiBulkReply(); + } + @Override public Long pfadd(final byte[] key, final byte[]... elements) { checkIsInMulti(); diff --git a/src/main/java/redis/clients/jedis/JedisCluster.java b/src/main/java/redis/clients/jedis/JedisCluster.java index f6cb6fdcbf..ddb50ab7ac 100644 --- a/src/main/java/redis/clients/jedis/JedisCluster.java +++ b/src/main/java/redis/clients/jedis/JedisCluster.java @@ -46,14 +46,14 @@ public String execute(Jedis connection) { @Override public String set(final String key, final String value, final String nxxx, - final String expx, final long time) { - return new JedisClusterCommand(connectionHandler, timeout, - maxRedirections) { - @Override - public String execute(Jedis connection) { - return connection.set(key, value, nxxx, expx, time); - } - }.run(key); + final String expx, final long time) { + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { + @Override + public String execute(Jedis connection) { + return connection.set(key, value, nxxx, expx, time); + } + }.run(key); } @Override @@ -117,8 +117,7 @@ public Long expireAt(final String key, final long unixTime) { maxRedirections) { @Override public Long execute(Jedis connection) { - return connection - .expireAt(key, unixTime); + return connection.expireAt(key, unixTime); } }.run(key); } @@ -141,8 +140,7 @@ public Boolean setbit(final String key, final long offset, maxRedirections) { @Override public Boolean execute(Jedis connection) { - return connection.setbit(key, offset, - value); + return connection.setbit(key, offset, value); } }.run(key); } @@ -154,8 +152,7 @@ public Boolean setbit(final String key, final long offset, maxRedirections) { @Override public Boolean execute(Jedis connection) { - return connection.setbit(key, offset, - value); + return connection.setbit(key, offset, value); } }.run(key); } @@ -177,8 +174,7 @@ public Long setrange(final String key, final long offset, final String value) { maxRedirections) { @Override public Long execute(Jedis connection) { - return connection.setrange(key, offset, - value); + return connection.setrange(key, offset, value); } }.run(key); } @@ -190,8 +186,7 @@ public String getrange(final String key, final long startOffset, maxRedirections) { @Override public String execute(Jedis connection) { - return connection.getrange(key, - startOffset, endOffset); + return connection.getrange(key, startOffset, endOffset); } }.run(key); } @@ -224,8 +219,7 @@ public String setex(final String key, final int seconds, final String value) { maxRedirections) { @Override public String execute(Jedis connection) { - return connection.setex(key, seconds, - value); + return connection.setex(key, seconds, value); } }.run(key); } @@ -291,8 +285,7 @@ public String substr(final String key, final int start, final int end) { maxRedirections) { @Override public String execute(Jedis connection) { - return connection - .substr(key, start, end); + return connection.substr(key, start, end); } }.run(key); } @@ -303,8 +296,7 @@ public Long hset(final String key, final String field, final String value) { maxRedirections) { @Override public Long execute(Jedis connection) { - return connection - .hset(key, field, value); + return connection.hset(key, field, value); } }.run(key); } @@ -326,8 +318,7 @@ public Long hsetnx(final String key, final String field, final String value) { maxRedirections) { @Override public Long execute(Jedis connection) { - return connection.hsetnx(key, field, - value); + return connection.hsetnx(key, field, value); } }.run(key); } @@ -360,8 +351,7 @@ public Long hincrBy(final String key, final String field, final long value) { maxRedirections) { @Override public Long execute(Jedis connection) { - return connection.hincrBy(key, field, - value); + return connection.hincrBy(key, field, value); } }.run(key); } @@ -472,8 +462,7 @@ public List lrange(final String key, final long start, timeout, maxRedirections) { @Override public List execute(Jedis connection) { - return connection - .lrange(key, start, end); + return connection.lrange(key, start, end); } }.run(key); } @@ -506,8 +495,7 @@ public String lset(final String key, final long index, final String value) { maxRedirections) { @Override public String execute(Jedis connection) { - return connection - .lset(key, index, value); + return connection.lset(key, index, value); } }.run(key); } @@ -518,8 +506,7 @@ public Long lrem(final String key, final long count, final String value) { maxRedirections) { @Override public Long execute(Jedis connection) { - return connection - .lrem(key, count, value); + return connection.lrem(key, count, value); } }.run(key); } @@ -640,8 +627,7 @@ public Long zadd(final String key, final double score, final String member) { maxRedirections) { @Override public Long execute(Jedis connection) { - return connection.zadd(key, score, - member); + return connection.zadd(key, score, member); } }.run(key); } @@ -652,8 +638,7 @@ public Long zadd(final String key, final Map scoreMembers) { maxRedirections) { @Override public Long execute(Jedis connection) { - return connection - .zadd(key, scoreMembers); + return connection.zadd(key, scoreMembers); } }.run(key); } @@ -664,8 +649,7 @@ public Set zrange(final String key, final long start, final long end) { maxRedirections) { @Override public Set execute(Jedis connection) { - return connection - .zrange(key, start, end); + return connection.zrange(key, start, end); } }.run(key); } @@ -688,8 +672,7 @@ public Double zincrby(final String key, final double score, maxRedirections) { @Override public Double execute(Jedis connection) { - return connection.zincrby(key, score, - member); + return connection.zincrby(key, score, member); } }.run(key); } @@ -723,8 +706,7 @@ public Set zrevrange(final String key, final long start, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection.zrevrange(key, start, - end); + return connection.zrevrange(key, start, end); } }.run(key); } @@ -736,8 +718,7 @@ public Set zrangeWithScores(final String key, final long start, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection.zrangeWithScores(key, - start, end); + return connection.zrangeWithScores(key, start, end); } }.run(key); } @@ -749,8 +730,7 @@ public Set zrevrangeWithScores(final String key, final long start, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection.zrevrangeWithScores( - key, start, end); + return connection.zrevrangeWithScores(key, start, end); } }.run(key); } @@ -795,8 +775,7 @@ public List sort(final String key, timeout, maxRedirections) { @Override public List execute(Jedis connection) { - return connection.sort(key, - sortingParameters); + return connection.sort(key, sortingParameters); } }.run(key); } @@ -830,8 +809,7 @@ public Set zrangeByScore(final String key, final double min, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection.zrangeByScore(key, - min, max); + return connection.zrangeByScore(key, min, max); } }.run(key); } @@ -843,8 +821,7 @@ public Set zrangeByScore(final String key, final String min, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection.zrangeByScore(key, - min, max); + return connection.zrangeByScore(key, min, max); } }.run(key); } @@ -856,8 +833,7 @@ public Set zrevrangeByScore(final String key, final double max, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection.zrevrangeByScore(key, - min, max); + return connection.zrevrangeByScore(key, min, max); } }.run(key); } @@ -869,8 +845,7 @@ public Set zrangeByScore(final String key, final double min, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection.zrangeByScore(key, - min, max, offset, count); + return connection.zrangeByScore(key, min, max, offset, count); } }.run(key); } @@ -882,8 +857,7 @@ public Set zrevrangeByScore(final String key, final String max, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection.zrevrangeByScore(key, - min, max); + return connection.zrevrangeByScore(key, min, max); } }.run(key); } @@ -895,8 +869,7 @@ public Set zrangeByScore(final String key, final String min, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection.zrangeByScore(key, - min, max, offset, count); + return connection.zrangeByScore(key, min, max, offset, count); } }.run(key); } @@ -908,8 +881,8 @@ public Set zrevrangeByScore(final String key, final double max, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection.zrevrangeByScore(key, - min, max, offset, count); + return connection + .zrevrangeByScore(key, min, max, offset, count); } }.run(key); } @@ -921,8 +894,7 @@ public Set zrangeByScoreWithScores(final String key, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection - .zrangeByScoreWithScores(key, min, max); + return connection.zrangeByScoreWithScores(key, min, max); } }.run(key); } @@ -934,8 +906,7 @@ public Set zrevrangeByScoreWithScores(final String key, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection - .zrevrangeByScoreWithScores(key, min, max); + return connection.zrevrangeByScoreWithScores(key, min, max); } }.run(key); } @@ -948,8 +919,8 @@ public Set zrangeByScoreWithScores(final String key, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection - .zrangeByScoreWithScores(key, min, max, offset, count); + return connection.zrangeByScoreWithScores(key, min, max, + offset, count); } }.run(key); } @@ -961,8 +932,8 @@ public Set zrevrangeByScore(final String key, final String max, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection.zrevrangeByScore(key, - min, max, offset, count); + return connection + .zrevrangeByScore(key, min, max, offset, count); } }.run(key); } @@ -974,8 +945,7 @@ public Set zrangeByScoreWithScores(final String key, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection - .zrangeByScoreWithScores(key, min, max); + return connection.zrangeByScoreWithScores(key, min, max); } }.run(key); } @@ -987,8 +957,7 @@ public Set zrevrangeByScoreWithScores(final String key, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection - .zrevrangeByScoreWithScores(key, min, max); + return connection.zrevrangeByScoreWithScores(key, min, max); } }.run(key); } @@ -1001,8 +970,8 @@ public Set zrangeByScoreWithScores(final String key, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection - .zrangeByScoreWithScores(key, min, max, offset, count); + return connection.zrangeByScoreWithScores(key, min, max, + offset, count); } }.run(key); } @@ -1015,9 +984,8 @@ public Set zrevrangeByScoreWithScores(final String key, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection - .zrevrangeByScoreWithScores(key, max, min, offset, - count); + return connection.zrevrangeByScoreWithScores(key, max, min, + offset, count); } }.run(key); } @@ -1030,9 +998,8 @@ public Set zrevrangeByScoreWithScores(final String key, maxRedirections) { @Override public Set execute(Jedis connection) { - return connection - .zrevrangeByScoreWithScores(key, max, min, offset, - count); + return connection.zrevrangeByScoreWithScores(key, max, min, + offset, count); } }.run(key); } @@ -1044,8 +1011,7 @@ public Long zremrangeByRank(final String key, final long start, maxRedirections) { @Override public Long execute(Jedis connection) { - return connection.zremrangeByRank(key, - start, end); + return connection.zremrangeByRank(key, start, end); } }.run(key); } @@ -1057,8 +1023,7 @@ public Long zremrangeByScore(final String key, final double start, maxRedirections) { @Override public Long execute(Jedis connection) { - return connection.zremrangeByScore(key, - start, end); + return connection.zremrangeByScore(key, start, end); } }.run(key); } @@ -1070,8 +1035,7 @@ public Long zremrangeByScore(final String key, final String start, maxRedirections) { @Override public Long execute(Jedis connection) { - return connection.zremrangeByScore(key, - start, end); + return connection.zremrangeByScore(key, start, end); } }.run(key); } @@ -1083,8 +1047,7 @@ public Long linsert(final String key, final LIST_POSITION where, maxRedirections) { @Override public Long execute(Jedis connection) { - return connection.linsert(key, where, - pivot, value); + return connection.linsert(key, where, pivot, value); } }.run(key); } @@ -1183,8 +1146,7 @@ public Long bitcount(final String key, final long start, final long end) { maxRedirections) { @Override public Long execute(Jedis connection) { - return connection.bitcount(key, start, - end); + return connection.bitcount(key, start, end); } }.run(key); } @@ -1408,6 +1370,17 @@ public Long waitReplicas(int replicas, long timeout) { return null; } + @Override + public List role() { + return new JedisClusterCommand>(connectionHandler, + timeout, maxRedirections) { + @Override + public List execute(Jedis connection) { + return connection.role(); + } + }.run(null); + } + @Deprecated /** * This method is deprecated due to bug (scan cursor should be unsigned long) @@ -1459,7 +1432,7 @@ public ScanResult execute(Jedis connection) { } }.run(null); } - + @Override public ScanResult> hscan(final String key, final String cursor) { @@ -1471,7 +1444,7 @@ public ScanResult> execute(Jedis connection) { } }.run(null); } - + @Override public ScanResult sscan(final String key, final String cursor) { return new JedisClusterCommand>(connectionHandler, @@ -1482,7 +1455,7 @@ public ScanResult execute(Jedis connection) { } }.run(null); } - + @Override public ScanResult zscan(final String key, final String cursor) { return new JedisClusterCommand>(connectionHandler, @@ -1496,8 +1469,8 @@ public ScanResult execute(Jedis connection) { @Override public Long pfadd(final String key, final String... elements) { - return new JedisClusterCommand(connectionHandler, - timeout, maxRedirections) { + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { @Override public Long execute(Jedis connection) { return connection.pfadd(key, elements); @@ -1507,8 +1480,8 @@ public Long execute(Jedis connection) { @Override public long pfcount(final String key) { - return new JedisClusterCommand(connectionHandler, - timeout, maxRedirections) { + return new JedisClusterCommand(connectionHandler, timeout, + maxRedirections) { @Override public Long execute(Jedis connection) { return connection.pfcount(key); diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index 3f77b9a284..d611952d32 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -59,7 +59,7 @@ public final class Protocol { public static final String CLUSTER_REPLICATE = "replicate"; public static final String CLUSTER_SLAVES = "slaves"; public static final String CLUSTER_FAILOVER = "failover"; - public static final String PUBSUB_CHANNELS= "channels"; + public static final String PUBSUB_CHANNELS = "channels"; public static final String PUBSUB_NUMSUB = "numsub"; public static final String PUBSUB_NUM_PAT = "numpat"; @@ -201,7 +201,7 @@ public static Object read(final RedisInputStream is) { } public static final byte[] toByteArray(final boolean value) { - return toByteArray(value ? 1 : 0); + return toByteArray(value ? 1 : 0); } public static final byte[] toByteArray(final int value) { @@ -217,7 +217,7 @@ public static final byte[] toByteArray(final double value) { } public static enum Command { - PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, PUBSUB, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, BITPOS, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, SENTINEL, DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL, INCRBYFLOAT, PSETEX, CLIENT, TIME, MIGRATE, HINCRBYFLOAT, SCAN, HSCAN, SSCAN, ZSCAN, WAIT, CLUSTER, ASKING, PFADD, PFCOUNT, PFMERGE; + PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, PUBSUB, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, BITPOS, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, SENTINEL, DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL, INCRBYFLOAT, PSETEX, CLIENT, TIME, MIGRATE, HINCRBYFLOAT, SCAN, HSCAN, SSCAN, ZSCAN, WAIT, ROLE, CLUSTER, ASKING, PFADD, PFCOUNT, PFMERGE; public final byte[] raw; diff --git a/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java index 59ec6bcd20..f2d80a198d 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ControlCommandsTest.java @@ -5,9 +5,12 @@ import org.junit.Test; import redis.clients.jedis.DebugParams; +import redis.clients.jedis.HostAndPort; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisMonitor; import redis.clients.jedis.exceptions.JedisDataException; +import redis.clients.jedis.tests.HostAndPortUtil; +import redis.clients.util.SafeEncoder; public class ControlCommandsTest extends JedisCommandTestBase { @Test @@ -123,4 +126,62 @@ public void waitReplicas() { Long replicas = jedis.waitReplicas(1, 100); assertEquals(1, replicas.longValue()); } + + @Test + public void roleWithMasterAndSlave() { + // master including slave + List role = jedis.role(); + + assertNotNull(role); + assertTrue(role.size() >= 3); + + assertEquals("master", SafeEncoder.encode((byte[]) role.get(0))); + assertTrue(role.get(1) instanceof Long); + + List slaves = (List) role.get(2); + List slave = (List) slaves.get(0); + assertEquals(3, slave.size()); + + // get slave + String slaveNodeHost = SafeEncoder.encode((byte[]) slave.get(0)); + int slaveNodePort = Integer.parseInt(SafeEncoder.encode((byte[]) slave + .get(1))); + + // slave + Jedis slaveJedis = new Jedis(slaveNodeHost, slaveNodePort); + slaveJedis.auth("foobared"); + List slaveRole = slaveJedis.role(); + + assertNotNull(slaveRole); + assertTrue(slaveRole.size() == 5); + + assertEquals("slave", SafeEncoder.encode((byte[]) slaveRole.get(0))); + + // 2nd & 3rd argument must point to master node + HostAndPort masterHnP = new HostAndPort( + SafeEncoder.encode((byte[]) slaveRole.get(1)), + ((Long) slaveRole.get(2)).intValue()); + HostAndPort jedisHnP = new HostAndPort(jedis.getClient().getHost(), + jedis.getClient().getPort()); + assertEquals(masterHnP, jedisHnP); + } + + @Test + public void roleWithSentinelNode() { + HostAndPort sentinelHnP = HostAndPortUtil.getSentinelServers().get(0); + + Jedis sentinelJedis = new Jedis(sentinelHnP.getHost(), + sentinelHnP.getPort()); + List role = sentinelJedis.role(); + + assertNotNull(role); + assertTrue(role.size() > 1); + + assertEquals("sentinel", SafeEncoder.encode((byte[]) role.get(0))); + + List master = (List) role.get(1); + assertEquals("mymaster", SafeEncoder.encode((byte[]) master.get(0))); + + sentinelJedis.close(); + } } \ No newline at end of file