diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 6734bb5..f987a96 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -249,9 +249,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, public Set keys(final byte[] pattern) { checkIsInMulti(); client.keys(pattern); - final HashSet keySet = new HashSet( - client.getBinaryMultiBulkReply()); - return keySet; + return new HashSet(client.getBinaryMultiBulkReply()); } /** @@ -515,7 +513,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, /** * Set the the respective keys to the respective values. MSET will replace - * old values with new values, while {@link #msetnx(String...) MSETNX} will + * old values with new values, while {@link #msetnx(byte[]...) MSETNX} will * not perform any operation at all even if just a single key already * exists. *

@@ -528,7 +526,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * either see the changes to both A and B at once, or no modification at * all. * - * @see #msetnx(String...) + * @see #msetnx(byte[]...) * * @param keysvalues * @return Status code reply Basically +OK as MSET can't fail @@ -541,7 +539,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, /** * Set the the respective keys to the respective values. - * {@link #mset(String...) MSET} will replace old values with new values, + * {@link #mset(byte[]...) MSET} will replace old values with new values, * while MSETNX will not perform any operation at all even if just a single * key already exists. *

@@ -554,8 +552,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * either see the changes to both A and B at once, or no modification at * all. * - * @see #mset(String...) - * + * @see #mset(byte[]...) + * * @param keysvalues * @return Integer reply, specifically: 1 if the all the keys were set 0 if * no key was set (at least one key already existed) @@ -567,7 +565,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, } /** - * IDECRBY work just like {@link #decr(String) INCR} but instead to + * DECRRBY work just like {@link #decr(byte[]) INCR} but instead to * decrement by 1 the decrement is integer. *

* INCR commands are limited to 64 bit signed integers. @@ -651,7 +649,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, } /** - * INCRBYFLOAT work just like {@link #incrBy(byte[]) INCRBY} but increments + * INCRBYFLOAT work just like {@link #incrBy(byte[], long)} INCRBY} but increments * by floats instead of integers. *

* INCRBYFLOAT commands are limited to double precision floating point @@ -669,8 +667,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @see #decr(byte[]) * @see #decrBy(byte[], long) * - * @param key - * @param integer + * @param key the key to increment + * @param integer the value to increment by * @return Integer reply, this commands will reply with the new value of key * after the increment. */ @@ -974,8 +972,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, public List hvals(final byte[] key) { checkIsInMulti(); client.hvals(key); - final List lresult = client.getBinaryMultiBulkReply(); - return lresult; + return client.getBinaryMultiBulkReply(); } /** @@ -1180,7 +1177,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * O(N) (with N being the length of the list), setting the first or last * elements of the list is O(1). * - * @see #lindex(byte[], int) + * @see #lindex(byte[], long) * * @param key * @param index @@ -1301,11 +1298,11 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, /** * Return all the members (elements) of the set value stored at key. This is - * just syntax glue for {@link #sinter(String...) SINTER}. + * just syntax glue for {@link #sinter(byte[]...)} SINTER}. *

* Time complexity O(N) * - * @param key + * @param key the key of the set * @return Multi bulk reply */ public Set smembers(final byte[] key) { @@ -1322,8 +1319,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, *

* Time complexity O(1) * - * @param key - * @param member + * @param key the key of the set + * @param member the set member to remove * @return Integer reply, specifically: 1 if the new element was removed 0 * if the new element was not a member of the set */ @@ -1416,7 +1413,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, /** * Return the members of a set resulting from the intersection of all the * sets hold at the specified keys. Like in - * {@link #lrange(byte[], int, int) LRANGE} the result is sent to the client + * {@link #lrange(byte[], 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(byte[]) SMEMBERS}. Actually @@ -1440,7 +1437,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, } /** - * This commnad works exactly like {@link #sinter(String...) SINTER} but + * This commnad works exactly like {@link #sinter(byte[]...) SINTER} but * instead of being returned the resulting set is sotred as dstkey. *

* Time complexity O(N*M) worst case where N is the cardinality of the @@ -1458,7 +1455,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, /** * Return the members of a set resulting from the union of all the sets hold - * at the specified keys. Like in {@link #lrange(byte[], int, int) LRANGE} + * at the specified keys. Like in {@link #lrange(byte[], 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(byte[]) @@ -1480,7 +1477,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, } /** - * This command works exactly like {@link #sunion(String...) SUNION} but + * This command works exactly like {@link #sunion(byte[]...) SUNION} but * instead of being returned the resulting set is stored as dstkey. Any * existing value in dstkey will be over-written. *

@@ -1528,7 +1525,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, } /** - * This command works exactly like {@link #sdiff(String...) SDIFF} but + * This command works exactly like {@link #sdiff(byte[]...) SDIFF} but * instead of being returned the resulting set is stored in dstkey. * * @param dstkey @@ -1722,16 +1719,14 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, final long end) { checkIsInMulti(); client.zrangeWithScores(key, start, end); - Set set = getBinaryTupledSet(); - return set; + return getBinaryTupledSet(); } public Set zrevrangeWithScores(final byte[] key, final long start, final long end) { checkIsInMulti(); client.zrevrangeWithScores(key, start, end); - Set set = getBinaryTupledSet(); - return set; + return getBinaryTupledSet(); } /** @@ -1782,13 +1777,11 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @see https://github.com/xetorthio/jedis/pull/498 */ public List multi(final TransactionBlock jedisTransaction) { - List results = null; jedisTransaction.setClient(client); client.multi(); client.getOne(); // expected OK jedisTransaction.execute(); - results = jedisTransaction.exec(); - return results; + return jedisTransaction.exec(); } protected void checkIsInMulti() { @@ -2008,7 +2001,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, *

* Time complexity: O(1) * - * @see #brpop(int, String...) + * @see #brpop(int, byte[]...) * * @param timeout * @param keys @@ -2021,18 +2014,17 @@ public class BinaryJedis implements BasicCommands, 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)); + return blpop(getArgsAddTimeout(timeout, keys)); + } - client.blpop(args.toArray(new byte[args.size()][])); - client.setTimeoutInfinite(); - final List multiBulkReply = client.getBinaryMultiBulkReply(); - client.rollbackTimeout(); - return multiBulkReply; + private byte[][] getArgsAddTimeout (int timeout, byte[][] keys) { + int size = keys.length; + final byte[][] args = new byte[size + 1][]; + for (int at = 0; at != size; ++at) { + args[at] = keys[at]; + } + args[size] = Protocol.toByteArray(timeout); + return args; } /** @@ -2137,7 +2129,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, *

* Time complexity: O(1) * - * @see #blpop(int, String...) + * @see #blpop(int, byte[]...) * * @param timeout * @param keys @@ -2150,59 +2142,39 @@ public class BinaryJedis implements BasicCommands, 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)); - - client.brpop(args.toArray(new byte[args.size()][])); - client.setTimeoutInfinite(); - final List multiBulkReply = client.getBinaryMultiBulkReply(); - client.rollbackTimeout(); - - return multiBulkReply; + return brpop(getArgsAddTimeout(timeout, keys)); } + @Deprecated public List blpop(byte[] arg) { - checkIsInMulti(); - byte[][] args = new byte[1][]; - args[0] = arg; - client.blpop(args); - client.setTimeoutInfinite(); - final List multiBulkReply = client.getBinaryMultiBulkReply(); - client.rollbackTimeout(); - return multiBulkReply; + return blpop(new byte[][]{arg}); } + @Deprecated public List brpop(byte[] arg) { - checkIsInMulti(); - byte[][] args = new byte[1][]; - args[0] = arg; - client.brpop(args); - client.setTimeoutInfinite(); - final List multiBulkReply = client.getBinaryMultiBulkReply(); - client.rollbackTimeout(); - return multiBulkReply; + return brpop(new byte[][]{arg}); } public List blpop(byte[]... args) { checkIsInMulti(); client.blpop(args); client.setTimeoutInfinite(); - final List multiBulkReply = client.getBinaryMultiBulkReply(); - client.rollbackTimeout(); - return multiBulkReply; + try { + return client.getBinaryMultiBulkReply(); + } finally { + client.rollbackTimeout(); + } } public List brpop(byte[]... args) { checkIsInMulti(); client.brpop(args); client.setTimeoutInfinite(); - final List multiBulkReply = client.getBinaryMultiBulkReply(); - client.rollbackTimeout(); - return multiBulkReply; + try { + return client.getBinaryMultiBulkReply(); + } finally { + client.rollbackTimeout(); + } } /** @@ -2457,8 +2429,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, final byte[] min, final byte[] max) { checkIsInMulti(); client.zrangeByScoreWithScores(key, min, max); - Set set = getBinaryTupledSet(); - return set; + return getBinaryTupledSet(); } /** @@ -2529,8 +2500,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, final int count) { checkIsInMulti(); client.zrangeByScoreWithScores(key, min, max, offset, count); - Set set = getBinaryTupledSet(); - return set; + return getBinaryTupledSet(); } private Set getBinaryTupledSet() { @@ -2587,8 +2557,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, final byte[] max, final byte[] min) { checkIsInMulti(); client.zrevrangeByScoreWithScores(key, max, min); - Set set = getBinaryTupledSet(); - return set; + return getBinaryTupledSet(); } public Set zrevrangeByScoreWithScores(final byte[] key, @@ -2596,8 +2565,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, final int count) { checkIsInMulti(); client.zrevrangeByScoreWithScores(key, max, min, offset, count); - Set set = getBinaryTupledSet(); - return set; + return getBinaryTupledSet(); } /** @@ -2652,10 +2620,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * input keys N, before passing the input keys and the other (optional) * arguments. *

- * As the terms imply, the {@link #zinterstore(String, String...) + * As the terms imply, the {@link #zinterstore(byte[], byte[]...)} * ZINTERSTORE} command requires an element to be present in each of the * given inputs to be inserted in the result. The - * {@link #zunionstore(String, String...) ZUNIONSTORE} command inserts all + * {@link #zunionstore(byte[], byte[]...)}} command inserts all * elements across all inputs. *

* Using the WEIGHTS option, it is possible to add weight to each input @@ -2674,10 +2642,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * sizes of the input sorted sets, and M being the number of elements in the * resulting sorted set * - * @see #zunionstore(String, String...) - * @see #zunionstore(String, ZParams, String...) - * @see #zinterstore(String, String...) - * @see #zinterstore(String, ZParams, String...) + * @see #zunionstore(byte[], byte[]...) + * @see #zunionstore(byte[], ZParams, byte[]...) + * @see #zinterstore(byte[], byte[]...) + * @see #zinterstore(byte[], ZParams, byte[]...) * * @param dstkey * @param sets @@ -2696,10 +2664,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * input keys N, before passing the input keys and the other (optional) * arguments. *

- * As the terms imply, the {@link #zinterstore(String, String...) + * As the terms imply, the {@link #zinterstore(byte[], byte[]...) * ZINTERSTORE} command requires an element to be present in each of the * given inputs to be inserted in the result. The - * {@link #zunionstore(String, String...) ZUNIONSTORE} command inserts all + * {@link #zunionstore(byte[], byte[]...) ZUNIONSTORE} command inserts all * elements across all inputs. *

* Using the WEIGHTS option, it is possible to add weight to each input @@ -2718,10 +2686,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * sizes of the input sorted sets, and M being the number of elements in the * resulting sorted set * - * @see #zunionstore(String, String...) - * @see #zunionstore(String, ZParams, String...) - * @see #zinterstore(String, String...) - * @see #zinterstore(String, ZParams, String...) + * @see #zunionstore(byte[], byte[]...) + * @see #zunionstore(byte[], ZParams, byte[]...) + * @see #zinterstore(byte[], byte[]...) + * @see #zinterstore(byte[], ZParams, byte[]...) * * @param dstkey * @param sets @@ -2742,10 +2710,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * input keys N, before passing the input keys and the other (optional) * arguments. *

- * As the terms imply, the {@link #zinterstore(String, String...) + * As the terms imply, the {@link #zinterstore(byte[], byte[]...) * ZINTERSTORE} command requires an element to be present in each of the * given inputs to be inserted in the result. The - * {@link #zunionstore(String, String...) ZUNIONSTORE} command inserts all + * {@link #zunionstore(byte[], byte[]...) ZUNIONSTORE} command inserts all * elements across all inputs. *

* Using the WEIGHTS option, it is possible to add weight to each input @@ -2764,10 +2732,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * sizes of the input sorted sets, and M being the number of elements in the * resulting sorted set * - * @see #zunionstore(String, String...) - * @see #zunionstore(String, ZParams, String...) - * @see #zinterstore(String, String...) - * @see #zinterstore(String, ZParams, String...) + * @see #zunionstore(byte[], byte[]...) + * @see #zunionstore(byte[], ZParams, byte[]...) + * @see #zinterstore(byte[], byte[]...) + * @see #zinterstore(byte[], ZParams, byte[]...) * * @param dstkey * @param sets @@ -2786,10 +2754,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * input keys N, before passing the input keys and the other (optional) * arguments. *

- * As the terms imply, the {@link #zinterstore(String, String...) + * As the terms imply, the {@link #zinterstore(byte[], byte[]...) * ZINTERSTORE} command requires an element to be present in each of the * given inputs to be inserted in the result. The - * {@link #zunionstore(String, String...) ZUNIONSTORE} command inserts all + * {@link #zunionstore(byte[], byte[]...) ZUNIONSTORE} command inserts all * elements across all inputs. *

* Using the WEIGHTS option, it is possible to add weight to each input @@ -2808,10 +2776,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * sizes of the input sorted sets, and M being the number of elements in the * resulting sorted set * - * @see #zunionstore(String, String...) - * @see #zunionstore(String, ZParams, String...) - * @see #zinterstore(String, String...) - * @see #zinterstore(String, ZParams, String...) + * @see #zunionstore(byte[], byte[]...) + * @see #zunionstore(byte[], ZParams, byte[]...) + * @see #zinterstore(byte[], byte[]...) + * @see #zinterstore(byte[], ZParams, byte[]...) * * @param dstkey * @param sets @@ -2959,7 +2927,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, */ public String shutdown() { client.shutdown(); - String status = null; + String status; try { status = client.getStatusCodeReply(); } catch (JedisException ex) { @@ -3125,7 +3093,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * configuration parameters are supported. *

* The list of configuration parameters supported by CONFIG SET can be - * obtained issuing a {@link #configGet(String) CONFIG GET *} command. + * obtained issuing a {@link #configGet(byte[]) CONFIG GET *} command. *

* The configuration set using CONFIG SET is immediately loaded by the Redis * server that will start acting as specified starting from the next @@ -3229,9 +3197,11 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, public byte[] brpoplpush(byte[] source, byte[] destination, int timeout) { client.brpoplpush(source, destination, timeout); client.setTimeoutInfinite(); - byte[] reply = client.getBinaryBulkReply(); - client.rollbackTimeout(); - return reply; + try { + return client.getBinaryBulkReply(); + } finally { + client.rollbackTimeout(); + } } /** @@ -3291,14 +3261,20 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, public void subscribe(BinaryJedisPubSub jedisPubSub, byte[]... channels) { client.setTimeoutInfinite(); - jedisPubSub.proceed(client, channels); - client.rollbackTimeout(); + try { + jedisPubSub.proceed(client, channels); + } finally { + client.rollbackTimeout(); + } } public void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns) { client.setTimeoutInfinite(); - jedisPubSub.proceedWithPatterns(client, patterns); - client.rollbackTimeout(); + try { + jedisPubSub.proceedWithPatterns(client, patterns); + } finally { + client.rollbackTimeout(); + } } public Long getDB() { @@ -3313,15 +3289,13 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, * @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(); + return eval(script, toByteArray(keys.size()), getParams(keys, args)); } private byte[][] getParams(List keys, List args) { - int keyCount = keys.size(); - int argCount = args.size(); - byte[][] params = new byte[keyCount + args.size()][]; + final int keyCount = keys.size(); + final int argCount = args.size(); + byte[][] params = new byte[keyCount + argCount][]; for (int i = 0; i < keyCount; i++) params[i] = keys.get(i); @@ -3334,49 +3308,38 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, public Object eval(byte[] script, byte[] keyCount, byte[]... params) { client.setTimeoutInfinite(); - client.eval(script, keyCount, params); - return client.getOne(); + try { + client.eval(script, keyCount, params); + return client.getOne(); + } finally { + client.rollbackTimeout(); + } } public Object eval(byte[] script, int keyCount, byte[]... params) { - client.setTimeoutInfinite(); - client.eval(script, SafeEncoder.encode(Integer.toString(keyCount)), - params); - return client.getOne(); + return eval(script, toByteArray(keyCount), params); } public Object eval(byte[] script) { - client.setTimeoutInfinite(); - client.eval(script, 0); - return client.getOne(); + return eval(script, 0); } public Object evalsha(byte[] sha1) { - client.setTimeoutInfinite(); - client.evalsha(sha1, 0); - return client.getOne(); + return evalsha(sha1, 1); } public Object evalsha(byte[] sha1, List keys, List args) { - - int keyCount = keys == null ? 0 : keys.size(); - int argCount = args == null ? 0 : args.size(); - - byte[][] params = new byte[keyCount + argCount][]; - - for (int i = 0; i < keyCount; i++) - params[i] = keys.get(i); - - for (int i = 0; i < argCount; i++) - params[keyCount + i] = args.get(i); - - return evalsha(sha1, keyCount, params); + return evalsha(sha1, keys.size(), getParams(keys, args)); } public Object evalsha(byte[] sha1, int keyCount, byte[]... params) { client.setTimeoutInfinite(); - client.evalsha(sha1, keyCount, params); - return client.getOne(); + try { + client.evalsha(sha1, keyCount, params); + return client.getOne(); + } finally { + client.rollbackTimeout(); + } } public String scriptFlush() { diff --git a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java index bf71ecf..83cdd07 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java +++ b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java @@ -218,8 +218,17 @@ public interface BinaryJedisCommands { Long rpushx(byte[] key, byte[]... arg); + + /** + * @deprecated This command has no meaning. + */ + @Deprecated List blpop(byte[] arg); + /** + * @deprecated This command has no meaning. + */ + @Deprecated List brpop(byte[] arg); Long del(byte[] key); diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index c57b170..7cf9feb 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -42,7 +42,6 @@ public class Connection implements Closeable { if (!isConnected()) { connect(); } - socket.setKeepAlive(true); socket.setSoTimeout(0); } catch (SocketException ex) { broken = true; @@ -53,7 +52,6 @@ public class Connection implements Closeable { public void rollbackTimeout() { try { socket.setSoTimeout(timeout); - socket.setKeepAlive(false); } catch (SocketException ex) { broken = true; throw new JedisConnectionException(ex); diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 361ac0d..c3306ff 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -1845,54 +1845,56 @@ 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)); + return blpop(getArgsAddTimeout(timeout, keys)); + } - client.blpop(args.toArray(new String[args.size()])); - client.setTimeoutInfinite(); - final List multiBulkReply = client.getMultiBulkReply(); - client.rollbackTimeout(); - return multiBulkReply; + private String[] getArgsAddTimeout (int timeout, String[] keys) { + final int keyCount = keys.length; + final String[] args = new String[keyCount + 1]; + for (int at = 0; at != keyCount; ++at) { + args[at] = keys[at]; + } + + args[keyCount] = String.valueOf(timeout); + return args; } public List blpop(String... args) { + checkIsInMulti(); client.blpop(args); client.setTimeoutInfinite(); - final List multiBulkReply = client.getMultiBulkReply(); - client.rollbackTimeout(); - return multiBulkReply; + try { + return client.getMultiBulkReply(); + } finally { + client.rollbackTimeout(); + } } public List brpop(String... args) { + checkIsInMulti(); client.brpop(args); client.setTimeoutInfinite(); - final List multiBulkReply = client.getMultiBulkReply(); - client.rollbackTimeout(); - return multiBulkReply; + try { + return client.getMultiBulkReply(); + } finally { + client.rollbackTimeout(); + } } + /** + * @deprecated unusable command + */ + @Deprecated public List blpop(String arg) { - String[] args = new String[1]; - args[0] = arg; - client.blpop(args); - client.setTimeoutInfinite(); - final List multiBulkReply = client.getMultiBulkReply(); - client.rollbackTimeout(); - return multiBulkReply; + return blpop(new String[]{arg}); } + /** + * @deprecated unusable command + */ + @Deprecated public List brpop(String arg) { - String[] args = new String[1]; - args[0] = arg; - client.brpop(args); - client.setTimeoutInfinite(); - final List multiBulkReply = client.getMultiBulkReply(); - client.rollbackTimeout(); - return multiBulkReply; + return brpop(new String[]{arg}); } /** @@ -2010,19 +2012,7 @@ 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)); - - client.brpop(args.toArray(new String[args.size()])); - client.setTimeoutInfinite(); - List multiBulkReply = client.getMultiBulkReply(); - client.rollbackTimeout(); - - return multiBulkReply; + return brpop(getArgsAddTimeout(timeout, keys)); } public Long zcount(final String key, final double min, final double max) { @@ -2724,9 +2714,11 @@ public class Jedis extends BinaryJedis implements JedisCommands, public String brpoplpush(String source, String destination, int timeout) { client.brpoplpush(source, destination, timeout); client.setTimeoutInfinite(); - String reply = client.getBulkReply(); - client.rollbackTimeout(); - return reply; + try { + return client.getBulkReply(); + } finally { + client.rollbackTimeout(); + } } /** @@ -2861,16 +2853,22 @@ public class Jedis extends BinaryJedis implements JedisCommands, public Object eval(String script, int keyCount, String... params) { client.setTimeoutInfinite(); - client.eval(script, keyCount, params); - - return getEvalResult(); + try { + client.eval(script, keyCount, params); + return getEvalResult(); + } finally { + client.rollbackTimeout(); + } } public void subscribe(final JedisPubSub jedisPubSub, final String... channels) { client.setTimeoutInfinite(); - jedisPubSub.proceed(client, channels); - client.rollbackTimeout(); + try { + jedisPubSub.proceed(client, channels); + } finally { + client.rollbackTimeout(); + } } public Long publish(final String channel, final String message) { @@ -2883,10 +2881,12 @@ public class Jedis extends BinaryJedis implements JedisCommands, public void psubscribe(final JedisPubSub jedisPubSub, final String... patterns) { checkIsInMulti(); - connect(); client.setTimeoutInfinite(); - jedisPubSub.proceedWithPatterns(client, patterns); - client.rollbackTimeout(); + try { + jedisPubSub.proceedWithPatterns(client, patterns); + } finally { + client.rollbackTimeout(); + } } protected static String[] getParams(List keys, List args) { @@ -2944,7 +2944,6 @@ public class Jedis extends BinaryJedis implements JedisCommands, public Object evalsha(String sha1, int keyCount, String... params) { checkIsInMulti(); client.evalsha(sha1, keyCount, params); - return getEvalResult(); } @@ -3503,28 +3502,12 @@ public class Jedis extends BinaryJedis implements JedisCommands, @Override public List blpop(int timeout, String key) { - checkIsInMulti(); - List args = new ArrayList(); - args.add(key); - args.add(String.valueOf(timeout)); - client.blpop(args.toArray(new String[args.size()])); - client.setTimeoutInfinite(); - final List multiBulkReply = client.getMultiBulkReply(); - client.rollbackTimeout(); - return multiBulkReply; + return blpop(key, String.valueOf(timeout)); } @Override public List brpop(int timeout, String key) { - checkIsInMulti(); - List args = new ArrayList(); - args.add(key); - args.add(String.valueOf(timeout)); - client.brpop(args.toArray(new String[args.size()])); - client.setTimeoutInfinite(); - final List multiBulkReply = client.getMultiBulkReply(); - client.rollbackTimeout(); - return multiBulkReply; + return brpop(key, String.valueOf(timeout)); } } diff --git a/src/main/java/redis/clients/jedis/JedisCommands.java b/src/main/java/redis/clients/jedis/JedisCommands.java index e4f9fc2..9282248 100644 --- a/src/main/java/redis/clients/jedis/JedisCommands.java +++ b/src/main/java/redis/clients/jedis/JedisCommands.java @@ -216,10 +216,18 @@ public interface JedisCommands { Long rpushx(String key, String... string); + /** + * @deprecated unusable command + */ + @Deprecated List blpop(String arg); List blpop(int timeout, String key); + /** + * @deprecated unusable command + */ + @Deprecated List brpop(String arg); List brpop(int timeout, String key);