diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 69b4acd4780..e2f27a59e84 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -21,9 +21,7 @@ import javax.net.ssl.SSLParameters; import javax.net.ssl.SSLSocketFactory; -import redis.clients.jedis.args.ListDirection; -import redis.clients.jedis.args.FlushMode; -import redis.clients.jedis.args.UnblockType; +import redis.clients.jedis.args.*; import redis.clients.jedis.commands.AdvancedBinaryJedisCommands; import redis.clients.jedis.commands.BasicCommands; import redis.clients.jedis.commands.BinaryJedisCommands; @@ -34,6 +32,7 @@ import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.exceptions.JedisException; import redis.clients.jedis.params.*; +import redis.clients.jedis.resps.*; import redis.clients.jedis.util.JedisURIHelper; public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKeyBinaryCommands, @@ -2660,24 +2659,24 @@ private byte[][] getKeysAndTimeout(double timeout, byte[][] keys) { } @Override - public KeyedTuple bzpopmax(final double timeout, final byte[]... keys) { + public List bzpopmax(final double timeout, final byte[]... keys) { checkIsInMultiOrPipeline(); client.bzpopmax(timeout, keys); client.setTimeoutInfinite(); try { - return BuilderFactory.KEYED_TUPLE.build(client.getBinaryMultiBulkReply()); + return client.getBinaryMultiBulkReply(); } finally { client.rollbackTimeout(); } } @Override - public KeyedTuple bzpopmin(final double timeout, final byte[]... keys) { + public List bzpopmin(final double timeout, final byte[]... keys) { checkIsInMultiOrPipeline(); client.bzpopmin(timeout, keys); client.setTimeoutInfinite(); try { - return BuilderFactory.KEYED_TUPLE.build(client.getBinaryMultiBulkReply()); + return client.getBinaryMultiBulkReply(); } finally { client.rollbackTimeout(); } diff --git a/src/main/java/redis/clients/jedis/BinaryJedisCluster.java b/src/main/java/redis/clients/jedis/BinaryJedisCluster.java index b3ea59987a9..21575113c22 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedisCluster.java +++ b/src/main/java/redis/clients/jedis/BinaryJedisCluster.java @@ -1,12 +1,12 @@ package redis.clients.jedis; -import redis.clients.jedis.args.ListDirection; -import redis.clients.jedis.args.FlushMode; +import redis.clients.jedis.args.*; import redis.clients.jedis.commands.BinaryJedisClusterCommands; import redis.clients.jedis.commands.JedisClusterBinaryScriptingCommands; import redis.clients.jedis.commands.MultiKeyBinaryJedisClusterCommands; import redis.clients.jedis.commands.ProtocolCommand; import redis.clients.jedis.params.*; +import redis.clients.jedis.resps.*; import redis.clients.jedis.util.JedisClusterHashTagUtil; import redis.clients.jedis.util.KeyMergeUtil; import redis.clients.jedis.util.SafeEncoder; @@ -1837,20 +1837,20 @@ public List execute(Jedis connection) { } @Override - public KeyedTuple bzpopmax(double timeout, byte[]... keys) { - return new JedisClusterCommand(connectionHandler, maxAttempts) { + public List bzpopmax(double timeout, byte[]... keys) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { @Override - public KeyedTuple execute(Jedis connection) { + public List execute(Jedis connection) { return connection.bzpopmax(timeout, keys); } }.runBinary(keys.length, keys); } @Override - public KeyedTuple bzpopmin(double timeout, byte[]... keys) { - return new JedisClusterCommand(connectionHandler, maxAttempts) { + public List bzpopmin(double timeout, byte[]... keys) { + return new JedisClusterCommand>(connectionHandler, maxAttempts) { @Override - public KeyedTuple execute(Jedis connection) { + public List execute(Jedis connection) { return connection.bzpopmin(timeout, keys); } }.runBinary(keys.length, keys); diff --git a/src/main/java/redis/clients/jedis/BuilderFactory.java b/src/main/java/redis/clients/jedis/BuilderFactory.java index 1a26f57b18b..2c49fff00e4 100644 --- a/src/main/java/redis/clients/jedis/BuilderFactory.java +++ b/src/main/java/redis/clients/jedis/BuilderFactory.java @@ -10,6 +10,7 @@ import java.util.Map; import java.util.Set; +import redis.clients.jedis.resps.*; import redis.clients.jedis.util.JedisByteHashMap; import redis.clients.jedis.util.SafeEncoder; @@ -356,6 +357,21 @@ public String toString() { }; + public static final Builder KEYED_LIST_ELEMENT = new Builder() { + @Override + @SuppressWarnings("unchecked") + public KeyedListElement build(Object data) { + if (data == null) return null; + List l = (List) data; + return new KeyedListElement(l.get(0), l.get(1)); + } + + @Override + public String toString() { + return "KeyedListElement"; + } + }; + public static final Builder TUPLE = new Builder() { @Override @SuppressWarnings("unchecked") @@ -374,22 +390,21 @@ public String toString() { }; - public static final Builder KEYED_TUPLE = new Builder() { + public static final Builder KEYED_ZSET_ELEMENT = new Builder() { @Override @SuppressWarnings("unchecked") - public KeyedTuple build(Object data) { + public KeyedZSetElement build(Object data) { List l = (List) data; // never null if (l.isEmpty()) { return null; } - return new KeyedTuple(l.get(0), l.get(1), DOUBLE.build(l.get(2))); + return new KeyedZSetElement(l.get(0), l.get(1), DOUBLE.build(l.get(2))); } @Override public String toString() { - return "KeyedTuple"; + return "KeyedZSetElement"; } - }; public static final Builder> TUPLE_ZSET = new Builder>() { diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 06abd01741e..651c41fa987 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -13,10 +13,10 @@ import javax.net.ssl.SSLParameters; import javax.net.ssl.SSLSocketFactory; -import redis.clients.jedis.args.ListDirection; +import redis.clients.jedis.args.*; import redis.clients.jedis.commands.*; import redis.clients.jedis.params.*; -import redis.clients.jedis.args.UnblockType; +import redis.clients.jedis.resps.*; import redis.clients.jedis.util.SafeEncoder; import redis.clients.jedis.util.Slowlog; @@ -2185,8 +2185,15 @@ public List blpop(final int timeout, final String... keys) { } @Override - public List blpop(final double timeout, final String... keys) { - return blpop(getKeysAndTimeout(timeout, keys)); + public KeyedListElement blpop(final double timeout, final String... keys) { + checkIsInMultiOrPipeline(); + client.blpop(timeout, keys); + client.setTimeoutInfinite(); + try { + return BuilderFactory.KEYED_LIST_ELEMENT.build(client.getMultiBulkReply()); + } finally { + client.rollbackTimeout(); + } } /** @@ -2257,8 +2264,15 @@ public List brpop(final int timeout, final String... keys) { } @Override - public List brpop(final double timeout, final String... keys) { - return brpop(getKeysAndTimeout(timeout, keys)); + public KeyedListElement brpop(final double timeout, final String... keys) { + checkIsInMultiOrPipeline(); + client.brpop(timeout, keys); + client.setTimeoutInfinite(); + try { + return BuilderFactory.KEYED_LIST_ELEMENT.build(client.getMultiBulkReply()); + } finally { + client.rollbackTimeout(); + } } private String[] getKeysAndTimeout(int timeout, String[] keys) { @@ -2271,16 +2285,6 @@ private String[] getKeysAndTimeout(int timeout, String[] keys) { return args; } - private String[] getKeysAndTimeout(double timeout, String[] keys) { - final int keyCount = keys.length; - final String[] args = new String[keyCount + 1]; - - System.arraycopy(keys, 0, args, 0, keyCount); - - args[keyCount] = String.valueOf(timeout); - return args; - } - @Override public List blpop(final String... args) { checkIsInMultiOrPipeline(); @@ -2306,24 +2310,24 @@ public List brpop(final String... args) { } @Override - public KeyedTuple bzpopmax(double timeout, String... keys) { + public KeyedZSetElement bzpopmax(double timeout, String... keys) { checkIsInMultiOrPipeline(); client.bzpopmax(timeout, keys); client.setTimeoutInfinite(); try { - return BuilderFactory.KEYED_TUPLE.build(client.getObjectMultiBulkReply()); + return BuilderFactory.KEYED_ZSET_ELEMENT.build(client.getObjectMultiBulkReply()); } finally { client.rollbackTimeout(); } } @Override - public KeyedTuple bzpopmin(double timeout, String... keys) { + public KeyedZSetElement bzpopmin(double timeout, String... keys) { checkIsInMultiOrPipeline(); client.bzpopmin(timeout, keys); client.setTimeoutInfinite(); try { - return BuilderFactory.KEYED_TUPLE.build(client.getObjectMultiBulkReply()); + return BuilderFactory.KEYED_ZSET_ELEMENT.build(client.getObjectMultiBulkReply()); } finally { client.rollbackTimeout(); } @@ -2335,8 +2339,8 @@ public List blpop(final int timeout, final String key) { } @Override - public List blpop(double timeout, String key) { - return blpop(key, String.valueOf(timeout)); + public KeyedListElement blpop(double timeout, String key) { + return blpop(timeout, new String[]{key}); } @Override @@ -2345,8 +2349,8 @@ public List brpop(final int timeout, final String key) { } @Override - public List brpop(double timeout, String key) { - return brpop(key, String.valueOf(timeout)); + public KeyedListElement brpop(double timeout, String key) { + return brpop(timeout, new String[]{key}); } @Override diff --git a/src/main/java/redis/clients/jedis/JedisCluster.java b/src/main/java/redis/clients/jedis/JedisCluster.java index 433089db18a..13571194ab6 100644 --- a/src/main/java/redis/clients/jedis/JedisCluster.java +++ b/src/main/java/redis/clients/jedis/JedisCluster.java @@ -1,11 +1,12 @@ package redis.clients.jedis; -import redis.clients.jedis.args.ListDirection; +import redis.clients.jedis.args.*; import redis.clients.jedis.commands.JedisClusterCommands; import redis.clients.jedis.commands.JedisClusterScriptingCommands; import redis.clients.jedis.commands.MultiKeyJedisClusterCommands; import redis.clients.jedis.commands.ProtocolCommand; import redis.clients.jedis.params.*; +import redis.clients.jedis.resps.*; import redis.clients.jedis.util.JedisClusterHashTagUtil; import redis.clients.jedis.util.KeyMergeUtil; @@ -1854,10 +1855,10 @@ public List execute(Jedis connection) { } @Override - public List blpop(final double timeout, final String... keys) { - return new JedisClusterCommand>(connectionHandler, maxAttempts) { + public KeyedListElement blpop(final double timeout, final String... keys) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { @Override - public List execute(Jedis connection) { + public KeyedListElement execute(Jedis connection) { return connection.blpop(timeout, keys); } }.run(keys.length, keys); @@ -1875,30 +1876,30 @@ public List execute(Jedis connection) { } @Override - public List brpop(final double timeout, final String... keys) { - return new JedisClusterCommand>(connectionHandler, maxAttempts) { + public KeyedListElement brpop(final double timeout, final String... keys) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { @Override - public List execute(Jedis connection) { + public KeyedListElement execute(Jedis connection) { return connection.brpop(timeout, keys); } }.run(keys.length, keys); } @Override - public KeyedTuple bzpopmax(double timeout, String... keys) { - return new JedisClusterCommand(connectionHandler, maxAttempts) { + public KeyedZSetElement bzpopmax(double timeout, String... keys) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { @Override - public KeyedTuple execute(Jedis connection) { + public KeyedZSetElement execute(Jedis connection) { return connection.bzpopmax(timeout, keys); } }.run(keys.length, keys); } @Override - public KeyedTuple bzpopmin(double timeout, String... keys) { - return new JedisClusterCommand(connectionHandler, maxAttempts) { + public KeyedZSetElement bzpopmin(double timeout, String... keys) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { @Override - public KeyedTuple execute(Jedis connection) { + public KeyedZSetElement execute(Jedis connection) { return connection.bzpopmin(timeout, keys); } }.run(keys.length, keys); @@ -1915,10 +1916,10 @@ public List execute(Jedis connection) { } @Override - public List blpop(double timeout, String key) { - return new JedisClusterCommand>(connectionHandler, maxAttempts) { + public KeyedListElement blpop(double timeout, String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { @Override - public List execute(Jedis connection) { + public KeyedListElement execute(Jedis connection) { return connection.blpop(timeout, key); } }.run(key); @@ -1935,10 +1936,10 @@ public List execute(Jedis connection) { } @Override - public List brpop(double timeout, String key) { - return new JedisClusterCommand>(connectionHandler, maxAttempts) { + public KeyedListElement brpop(double timeout, String key) { + return new JedisClusterCommand(connectionHandler, maxAttempts) { @Override - public List execute(Jedis connection) { + public KeyedListElement execute(Jedis connection) { return connection.brpop(timeout, key); } }.run(key); diff --git a/src/main/java/redis/clients/jedis/KeyedTuple.java b/src/main/java/redis/clients/jedis/KeyedTuple.java deleted file mode 100644 index bf0bd39e985..00000000000 --- a/src/main/java/redis/clients/jedis/KeyedTuple.java +++ /dev/null @@ -1,47 +0,0 @@ -package redis.clients.jedis; - -import redis.clients.jedis.util.SafeEncoder; - -import java.util.Arrays; - -public class KeyedTuple extends Tuple { - private byte[] key; - - public KeyedTuple(byte[] key, byte[] element, Double score) { - super(element, score); - this.key = key; - } - - public KeyedTuple(String key, String element, Double score) { - super(element, score); - this.key = SafeEncoder.encode(key); - } - - public String getKey() { - if (null != key) { - return SafeEncoder.encode(key); - } - return null; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof KeyedTuple)) return false; - if (!super.equals(o)) return false; - - KeyedTuple that = (KeyedTuple) o; - return Arrays.equals(key, that.key); - } - - @Override - public int hashCode() { - return 31 * (key != null ? Arrays.hashCode(key) : 0) + super.hashCode(); - } - - @Override - public String toString() { - return "KeyedTuple{" + "key=" + SafeEncoder.encode(key) + ", element='" + getElement() + "'" - + ", score=" + getScore() + "} "; - } -} diff --git a/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java b/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java index cf3c6190f6c..5de5ee2f051 100644 --- a/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java +++ b/src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java @@ -1,9 +1,9 @@ package redis.clients.jedis; -import redis.clients.jedis.args.ListDirection; -import redis.clients.jedis.args.FlushMode; +import redis.clients.jedis.args.*; import redis.clients.jedis.commands.*; import redis.clients.jedis.params.*; +import redis.clients.jedis.resps.*; import java.util.List; import java.util.Map; @@ -97,9 +97,9 @@ public Response> blpop(int timeout, byte[]... keys) { } @Override - public Response> blpop(double timeout, String... keys) { + public Response blpop(double timeout, String... keys) { client.blpop(timeout, keys); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.KEYED_LIST_ELEMENT); } @Override @@ -138,9 +138,9 @@ public Response> brpop(int timeout, byte[]... keys) { } @Override - public Response> brpop(double timeout, String... keys) { + public Response brpop(double timeout, String... keys) { client.brpop(timeout, keys); - return getResponse(BuilderFactory.STRING_LIST); + return getResponse(BuilderFactory.KEYED_LIST_ELEMENT); } @Override @@ -150,27 +150,27 @@ public Response> brpop(double timeout, byte[]... keys) { } @Override - public Response bzpopmax(double timeout, String... keys) { + public Response bzpopmax(double timeout, String... keys) { client.bzpopmax(timeout, keys); - return getResponse(BuilderFactory.KEYED_TUPLE); + return getResponse(BuilderFactory.KEYED_ZSET_ELEMENT); } @Override - public Response bzpopmax(double timeout, byte[]... keys) { + public Response> bzpopmax(double timeout, byte[]... keys) { client.bzpopmax(timeout, keys); - return getResponse(BuilderFactory.KEYED_TUPLE); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } @Override - public Response bzpopmin(double timeout, String... keys) { + public Response bzpopmin(double timeout, String... keys) { client.bzpopmin(timeout, keys); - return getResponse(BuilderFactory.KEYED_TUPLE); + return getResponse(BuilderFactory.KEYED_ZSET_ELEMENT); } @Override - public Response bzpopmin(double timeout, byte[]... keys) { + public Response> bzpopmin(double timeout, byte[]... keys) { client.bzpopmin(timeout, keys); - return getResponse(BuilderFactory.KEYED_TUPLE); + return getResponse(BuilderFactory.BYTE_ARRAY_LIST); } @Override diff --git a/src/main/java/redis/clients/jedis/ShardedJedis.java b/src/main/java/redis/clients/jedis/ShardedJedis.java index e7065e4aa40..f73f0fccb4c 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedis.java +++ b/src/main/java/redis/clients/jedis/ShardedJedis.java @@ -21,6 +21,7 @@ import redis.clients.jedis.params.ZAddParams; import redis.clients.jedis.params.ZIncrByParams; import redis.clients.jedis.params.LPosParams; +import redis.clients.jedis.resps.KeyedListElement; import redis.clients.jedis.util.Hashing; public class ShardedJedis extends BinaryShardedJedis implements JedisCommands, Closeable { @@ -219,7 +220,7 @@ public List blpop(final int timeout, final String key) { } @Override - public List blpop(final double timeout, final String key) { + public KeyedListElement blpop(final double timeout, final String key) { Jedis j = getShard(key); return j.blpop(timeout, key); } @@ -237,7 +238,7 @@ public List brpop(final int timeout, final String key) { } @Override - public List brpop(final double timeout, final String key) { + public KeyedListElement brpop(final double timeout, final String key) { Jedis j = getShard(key); return j.brpop(timeout, key); } diff --git a/src/main/java/redis/clients/jedis/commands/JedisClusterCommands.java b/src/main/java/redis/clients/jedis/commands/JedisClusterCommands.java index 00684fd1eab..1484118ca9f 100644 --- a/src/main/java/redis/clients/jedis/commands/JedisClusterCommands.java +++ b/src/main/java/redis/clients/jedis/commands/JedisClusterCommands.java @@ -23,6 +23,7 @@ import redis.clients.jedis.params.ZAddParams; import redis.clients.jedis.params.ZIncrByParams; import redis.clients.jedis.params.LPosParams; +import redis.clients.jedis.resps.KeyedListElement; import java.util.List; import java.util.Map; @@ -321,11 +322,11 @@ default String setex(String key, int seconds, String value) { List blpop(int timeout, String key); - List blpop(double timeout, String key); + KeyedListElement blpop(double timeout, String key); List brpop(int timeout, String key); - List brpop(double timeout, String key); + KeyedListElement brpop(double timeout, String key); Long del(String key); diff --git a/src/main/java/redis/clients/jedis/commands/JedisCommands.java b/src/main/java/redis/clients/jedis/commands/JedisCommands.java index 1a93de0489a..3e4c2cf90b1 100644 --- a/src/main/java/redis/clients/jedis/commands/JedisCommands.java +++ b/src/main/java/redis/clients/jedis/commands/JedisCommands.java @@ -32,6 +32,7 @@ import redis.clients.jedis.params.ZAddParams; import redis.clients.jedis.params.ZIncrByParams; import redis.clients.jedis.params.LPosParams; +import redis.clients.jedis.resps.KeyedListElement; /** * Common interface for sharded and non-sharded Jedis @@ -343,11 +344,11 @@ default String setex(String key, int seconds, String value) { List blpop(int timeout, String key); - List blpop(double timeout, String key); + KeyedListElement blpop(double timeout, String key); List brpop(int timeout, String key); - List brpop(double timeout, String key); + KeyedListElement brpop(double timeout, String key); Long del(String key); diff --git a/src/main/java/redis/clients/jedis/commands/MultiKeyBinaryCommands.java b/src/main/java/redis/clients/jedis/commands/MultiKeyBinaryCommands.java index 4c525a7ea41..981454c8a58 100644 --- a/src/main/java/redis/clients/jedis/commands/MultiKeyBinaryCommands.java +++ b/src/main/java/redis/clients/jedis/commands/MultiKeyBinaryCommands.java @@ -3,11 +3,10 @@ import redis.clients.jedis.BinaryJedisPubSub; import redis.clients.jedis.BitOP; import redis.clients.jedis.GeoUnit; -import redis.clients.jedis.KeyedTuple; import redis.clients.jedis.SortingParams; import redis.clients.jedis.Tuple; import redis.clients.jedis.ZParams; -import redis.clients.jedis.args.ListDirection; +import redis.clients.jedis.args.*; import redis.clients.jedis.params.GeoRadiusParam; import redis.clients.jedis.params.GeoRadiusStoreParam; import redis.clients.jedis.params.XReadGroupParams; @@ -45,9 +44,9 @@ public interface MultiKeyBinaryCommands { List brpop(byte[]... args); - KeyedTuple bzpopmax(double timeout, byte[]... keys); + List bzpopmax(double timeout, byte[]... keys); - KeyedTuple bzpopmin(double timeout, byte[]... keys); + List bzpopmin(double timeout, byte[]... keys); Set keys(byte[] pattern); diff --git a/src/main/java/redis/clients/jedis/commands/MultiKeyBinaryJedisClusterCommands.java b/src/main/java/redis/clients/jedis/commands/MultiKeyBinaryJedisClusterCommands.java index 378906c6d42..d862721bbde 100644 --- a/src/main/java/redis/clients/jedis/commands/MultiKeyBinaryJedisClusterCommands.java +++ b/src/main/java/redis/clients/jedis/commands/MultiKeyBinaryJedisClusterCommands.java @@ -5,11 +5,10 @@ import redis.clients.jedis.GeoUnit; import redis.clients.jedis.ScanParams; import redis.clients.jedis.ScanResult; -import redis.clients.jedis.KeyedTuple; import redis.clients.jedis.SortingParams; import redis.clients.jedis.Tuple; import redis.clients.jedis.ZParams; -import redis.clients.jedis.args.ListDirection; +import redis.clients.jedis.args.*; import redis.clients.jedis.params.GeoRadiusParam; import redis.clients.jedis.params.GeoRadiusStoreParam; import redis.clients.jedis.params.XReadGroupParams; @@ -41,9 +40,9 @@ public interface MultiKeyBinaryJedisClusterCommands { List brpop(double timeout, byte[]... keys); - KeyedTuple bzpopmax(double timeout, byte[]... keys); + List bzpopmax(double timeout, byte[]... keys); - KeyedTuple bzpopmin(double timeout, byte[]... keys); + List bzpopmin(double timeout, byte[]... keys); List mget(byte[]... keys); diff --git a/src/main/java/redis/clients/jedis/commands/MultiKeyBinaryRedisPipeline.java b/src/main/java/redis/clients/jedis/commands/MultiKeyBinaryRedisPipeline.java index c5a26478361..f077ead00e3 100644 --- a/src/main/java/redis/clients/jedis/commands/MultiKeyBinaryRedisPipeline.java +++ b/src/main/java/redis/clients/jedis/commands/MultiKeyBinaryRedisPipeline.java @@ -3,11 +3,10 @@ import redis.clients.jedis.BitOP; import redis.clients.jedis.GeoUnit; import redis.clients.jedis.Response; -import redis.clients.jedis.KeyedTuple; import redis.clients.jedis.SortingParams; import redis.clients.jedis.Tuple; import redis.clients.jedis.ZParams; -import redis.clients.jedis.args.ListDirection; +import redis.clients.jedis.args.*; import redis.clients.jedis.params.*; import java.util.List; @@ -40,9 +39,9 @@ public interface MultiKeyBinaryRedisPipeline { Response> brpop(double timeout, byte[]... args); - Response bzpopmax(double timeout, byte[]... keys); + Response> bzpopmax(double timeout, byte[]... keys); - Response bzpopmin(double timeout, byte[]... keys); + Response> bzpopmin(double timeout, byte[]... keys); Response> keys(byte[] pattern); diff --git a/src/main/java/redis/clients/jedis/commands/MultiKeyCommands.java b/src/main/java/redis/clients/jedis/commands/MultiKeyCommands.java index a44410f1b27..d0a6b305177 100644 --- a/src/main/java/redis/clients/jedis/commands/MultiKeyCommands.java +++ b/src/main/java/redis/clients/jedis/commands/MultiKeyCommands.java @@ -2,7 +2,7 @@ import redis.clients.jedis.BitOP; import redis.clients.jedis.GeoUnit; -import redis.clients.jedis.KeyedTuple; +import redis.clients.jedis.resps.KeyedZSetElement; import redis.clients.jedis.StreamEntryID; import redis.clients.jedis.JedisPubSub; import redis.clients.jedis.ScanParams; @@ -11,11 +11,12 @@ import redis.clients.jedis.StreamEntry; import redis.clients.jedis.Tuple; import redis.clients.jedis.ZParams; -import redis.clients.jedis.args.ListDirection; +import redis.clients.jedis.args.*; import redis.clients.jedis.params.GeoRadiusParam; import redis.clients.jedis.params.GeoRadiusStoreParam; import redis.clients.jedis.params.XReadGroupParams; import redis.clients.jedis.params.XReadParams; +import redis.clients.jedis.resps.*; import java.util.List; import java.util.Map; @@ -39,19 +40,19 @@ public interface MultiKeyCommands { List blpop(int timeout, String... keys); - List blpop(double timeout, String... keys); + KeyedListElement blpop(double timeout, String... keys); List brpop(int timeout, String... keys); - List brpop(double timeout, String... keys); + KeyedListElement brpop(double timeout, String... keys); List blpop(String... args); List brpop(String... args); - KeyedTuple bzpopmax(double timeout, String... keys); + KeyedZSetElement bzpopmax(double timeout, String... keys); - KeyedTuple bzpopmin(double timeout, String... keys); + KeyedZSetElement bzpopmin(double timeout, String... keys); /** * Returns all the keys matching the glob-style pattern. For example if you have in the database diff --git a/src/main/java/redis/clients/jedis/commands/MultiKeyCommandsPipeline.java b/src/main/java/redis/clients/jedis/commands/MultiKeyCommandsPipeline.java index be177414883..40e698b0b9d 100644 --- a/src/main/java/redis/clients/jedis/commands/MultiKeyCommandsPipeline.java +++ b/src/main/java/redis/clients/jedis/commands/MultiKeyCommandsPipeline.java @@ -3,14 +3,14 @@ import redis.clients.jedis.BitOP; import redis.clients.jedis.GeoUnit; import redis.clients.jedis.Response; -import redis.clients.jedis.KeyedTuple; import redis.clients.jedis.SortingParams; import redis.clients.jedis.StreamEntry; import redis.clients.jedis.StreamEntryID; import redis.clients.jedis.Tuple; import redis.clients.jedis.ZParams; -import redis.clients.jedis.args.ListDirection; +import redis.clients.jedis.args.*; import redis.clients.jedis.params.*; +import redis.clients.jedis.resps.*; import java.util.List; import java.util.Map; @@ -39,17 +39,17 @@ Response blmove(String srcKey, String dstKey, ListDirection from, ListDi Response> blpop(int timeout, String... args); - Response> blpop(double timeout, String... args); + Response blpop(double timeout, String... args); Response> brpop(String... args); Response> brpop(int timeout, String... args); - Response> brpop(double timeout, String... args); + Response brpop(double timeout, String... args); - Response bzpopmax(double timeout, String... keys); + Response bzpopmax(double timeout, String... keys); - Response bzpopmin(double timeout, String... keys); + Response bzpopmin(double timeout, String... keys); Response> keys(String pattern); diff --git a/src/main/java/redis/clients/jedis/commands/MultiKeyJedisClusterCommands.java b/src/main/java/redis/clients/jedis/commands/MultiKeyJedisClusterCommands.java index 4aaf07584a3..4d60b94a401 100644 --- a/src/main/java/redis/clients/jedis/commands/MultiKeyJedisClusterCommands.java +++ b/src/main/java/redis/clients/jedis/commands/MultiKeyJedisClusterCommands.java @@ -5,17 +5,17 @@ import redis.clients.jedis.JedisPubSub; import redis.clients.jedis.ScanParams; import redis.clients.jedis.ScanResult; -import redis.clients.jedis.KeyedTuple; import redis.clients.jedis.SortingParams; import redis.clients.jedis.StreamEntry; import redis.clients.jedis.StreamEntryID; import redis.clients.jedis.Tuple; import redis.clients.jedis.ZParams; -import redis.clients.jedis.args.ListDirection; +import redis.clients.jedis.args.*; import redis.clients.jedis.params.GeoRadiusParam; import redis.clients.jedis.params.GeoRadiusStoreParam; import redis.clients.jedis.params.XReadGroupParams; import redis.clients.jedis.params.XReadParams; +import redis.clients.jedis.resps.*; import java.util.List; import java.util.Map; @@ -36,15 +36,15 @@ public interface MultiKeyJedisClusterCommands { List blpop(int timeout, String... keys); - List blpop(double timeout, String... keys); + KeyedListElement blpop(double timeout, String... keys); List brpop(int timeout, String... keys); - List brpop(double timeout, String... keys); + KeyedListElement brpop(double timeout, String... keys); - KeyedTuple bzpopmax(double timeout, String... keys); + KeyedZSetElement bzpopmax(double timeout, String... keys); - KeyedTuple bzpopmin(double timeout, String... keys); + KeyedZSetElement bzpopmin(double timeout, String... keys); List mget(String... keys); diff --git a/src/main/java/redis/clients/jedis/resps/KeyedListElement.java b/src/main/java/redis/clients/jedis/resps/KeyedListElement.java new file mode 100644 index 00000000000..222fa9fbf13 --- /dev/null +++ b/src/main/java/redis/clients/jedis/resps/KeyedListElement.java @@ -0,0 +1,45 @@ +package redis.clients.jedis.resps; + +import redis.clients.jedis.util.SafeEncoder; + +public class KeyedListElement { + + private final String key; + private final String element; + + public KeyedListElement(byte[] key, byte[] element) { + this(SafeEncoder.encode(key), SafeEncoder.encode(element)); + } + + public KeyedListElement(String key, String element) { + this.key = key; + this.element = element; + } + + public String getKey() { + return key; + } + + public String getElement() { + return element; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof KeyedZSetElement)) return false; + + KeyedListElement other = (KeyedListElement) o; + return key.equals(other.key) && element.equals(other.element); + } + + @Override + public int hashCode() { + return 31 * key.hashCode() + element.hashCode(); + } + + @Override + public String toString() { + return "KeyedListElement{" + "key=" + key + ", element='" + element + "} "; + } +} diff --git a/src/main/java/redis/clients/jedis/resps/KeyedZSetElement.java b/src/main/java/redis/clients/jedis/resps/KeyedZSetElement.java new file mode 100644 index 00000000000..bea9b8a3e3e --- /dev/null +++ b/src/main/java/redis/clients/jedis/resps/KeyedZSetElement.java @@ -0,0 +1,43 @@ +package redis.clients.jedis.resps; + +import redis.clients.jedis.Tuple; +import redis.clients.jedis.util.SafeEncoder; + +public class KeyedZSetElement extends Tuple { + + private final String key; + + public KeyedZSetElement(byte[] key, byte[] element, Double score) { + super(element, score); + this.key = SafeEncoder.encode(key); + } + + public KeyedZSetElement(String key, String element, Double score) { + super(element, score); + this.key = key; + } + + public String getKey() { + return key; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof KeyedZSetElement)) return false; + + if (!key.equals(((KeyedZSetElement) o).key)) return false; + return super.equals(o); + } + + @Override + public int hashCode() { + return 31 * key.hashCode() + super.hashCode(); + } + + @Override + public String toString() { + return "KeyedZSetElement{" + "key=" + key + ", element='" + getElement() + "'" + + ", score=" + getScore() + "} "; + } +} diff --git a/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java index fbaccbc378a..8d0206f19ce 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java @@ -538,8 +538,9 @@ public void brpoplpush() { public void run() { try { Thread.sleep(100); - Jedis j = createJedis(); - j.lpush("foo", "a"); + try (Jedis j = createJedis()) { + j.lpush("foo", "a"); + } } catch (InterruptedException e) { org.apache.logging.log4j.LogManager.getLogger().error("Interruption in string lpush", e); } @@ -559,8 +560,9 @@ public void run() { public void run() { try { Thread.sleep(100); - Jedis j = createJedis(); - j.lpush(bfoo, bA); + try (Jedis j = createJedis()) { + j.lpush(bfoo, bA); + } } catch (InterruptedException e) { org.apache.logging.log4j.LogManager.getLogger().error("Interruption in binary lpush", e); } diff --git a/src/test/java/redis/clients/jedis/tests/commands/SortedSetCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/SortedSetCommandsTest.java index d0ecc3b5494..78bc004df6d 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/SortedSetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/SortedSetCommandsTest.java @@ -4,6 +4,7 @@ import static org.junit.Assert.assertNotNull; import static redis.clients.jedis.ScanParams.SCAN_POINTER_START; import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY; +import static redis.clients.jedis.tests.utils.AssertUtil.assertByteArrayListEquals; import static redis.clients.jedis.tests.utils.AssertUtil.assertByteArraySetEquals; import static redis.clients.jedis.tests.utils.AssertUtil.assertCollectionContains; @@ -12,18 +13,21 @@ import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashSet; +import java.util.List; import java.util.Map; import java.util.Set; import org.junit.Test; +import redis.clients.jedis.BuilderFactory; +import redis.clients.jedis.Protocol; import redis.clients.jedis.ScanParams; import redis.clients.jedis.ScanResult; -import redis.clients.jedis.KeyedTuple; import redis.clients.jedis.Tuple; import redis.clients.jedis.ZParams; import redis.clients.jedis.params.ZAddParams; import redis.clients.jedis.params.ZIncrByParams; +import redis.clients.jedis.resps.KeyedZSetElement; import redis.clients.jedis.util.SafeEncoder; public class SortedSetCommandsTest extends JedisCommandTestBase { @@ -1487,15 +1491,17 @@ public void bzpopmax() { jedis.zadd("foo", 1d, "a", ZAddParams.zAddParams().nx()); jedis.zadd("foo", 10d, "b", ZAddParams.zAddParams().nx()); jedis.zadd("bar", 0.1d, "c", ZAddParams.zAddParams().nx()); - KeyedTuple actual = jedis.bzpopmax(0, "foo", "bar"); - assertEquals(new KeyedTuple("foo", "b", 10d), actual); + assertEquals(new KeyedZSetElement("foo", "b", 10d), jedis.bzpopmax(0, "foo", "bar")); // Binary jedis.zadd(bfoo, 1d, ba); jedis.zadd(bfoo, 10d, bb); jedis.zadd(bbar, 0.1d, bc); - actual = jedis.bzpopmax(0, bfoo, bbar); - assertEquals(new KeyedTuple(bfoo, bb, 10d), actual); + List actual = jedis.bzpopmax(0, bfoo, bbar); + assertEquals(3, actual.size()); + assertArrayEquals(bfoo, actual.get(0)); + assertArrayEquals(bb, actual.get(1)); + assertEquals(10d, BuilderFactory.DOUBLE.build(actual.get(2)), 1e-10); } @Test @@ -1503,15 +1509,17 @@ public void bzpopmin() { jedis.zadd("foo", 1d, "a", ZAddParams.zAddParams().nx()); jedis.zadd("foo", 10d, "b", ZAddParams.zAddParams().nx()); jedis.zadd("bar", 0.1d, "c", ZAddParams.zAddParams().nx()); - KeyedTuple actual = jedis.bzpopmin(0, "bar", "foo"); - assertEquals(new KeyedTuple("bar", "c", 0.1d), actual); + assertEquals(new KeyedZSetElement("bar", "c", 0.1d), jedis.bzpopmin(0, "bar", "foo")); // Binary jedis.zadd(bfoo, 1d, ba); jedis.zadd(bfoo, 10d, bb); jedis.zadd(bbar, 0.1d, bc); - actual = jedis.bzpopmin(0, bbar, bfoo); - assertEquals(new KeyedTuple(bbar, bc, 0.1d), actual); + List actual = jedis.bzpopmin(0, bbar, bfoo); + assertEquals(3, actual.size()); + assertArrayEquals(bbar, actual.get(0)); + assertArrayEquals(bc, actual.get(1)); + assertEquals(0.1d, BuilderFactory.DOUBLE.build(actual.get(2)), 1e-10); } @Test