Merge branch 'master' of github.com:rdifalco/jedis into rdifalco-master

Conflicts:
	src/main/java/redis/clients/jedis/BinaryJedis.java
This commit is contained in:
Jungtaek Lim
2014-11-13 13:20:59 +09:00
5 changed files with 197 additions and 226 deletions

View File

@@ -253,9 +253,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
public Set<byte[]> keys(final byte[] pattern) { public Set<byte[]> keys(final byte[] pattern) {
checkIsInMulti(); checkIsInMulti();
client.keys(pattern); client.keys(pattern);
final HashSet<byte[]> keySet = new HashSet<byte[]>( return new HashSet<byte[]>(client.getBinaryMultiBulkReply());
client.getBinaryMultiBulkReply());
return keySet;
} }
/** /**
@@ -519,7 +517,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
/** /**
* Set the the respective keys to the respective values. MSET will replace * 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 * not perform any operation at all even if just a single key already
* exists. * exists.
* <p> * <p>
@@ -532,7 +530,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* either see the changes to both A and B at once, or no modification at * either see the changes to both A and B at once, or no modification at
* all. * all.
* *
* @see #msetnx(String...) * @see #msetnx(byte[]...)
* *
* @param keysvalues * @param keysvalues
* @return Status code reply Basically +OK as MSET can't fail * @return Status code reply Basically +OK as MSET can't fail
@@ -545,7 +543,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
/** /**
* Set the the respective keys to the respective values. * 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 * while MSETNX will not perform any operation at all even if just a single
* key already exists. * key already exists.
* <p> * <p>
@@ -558,7 +556,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* either see the changes to both A and B at once, or no modification at * either see the changes to both A and B at once, or no modification at
* all. * all.
* *
* @see #mset(String...) * @see #mset(byte[]...)
* *
* @param keysvalues * @param keysvalues
* @return Integer reply, specifically: 1 if the all the keys were set 0 if * @return Integer reply, specifically: 1 if the all the keys were set 0 if
@@ -571,7 +569,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
} }
/** /**
* IDECRBY work just like {@link #decr(String) INCR} but instead to * DECRBY work just like {@link #decr(byte[]) INCR} but instead to
* decrement by 1 the decrement is integer. * decrement by 1 the decrement is integer.
* <p> * <p>
* INCR commands are limited to 64 bit signed integers. * INCR commands are limited to 64 bit signed integers.
@@ -655,7 +653,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. * by floats instead of integers.
* <p> * <p>
* INCRBYFLOAT commands are limited to double precision floating point * INCRBYFLOAT commands are limited to double precision floating point
@@ -673,8 +671,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* @see #decr(byte[]) * @see #decr(byte[])
* @see #decrBy(byte[], long) * @see #decrBy(byte[], long)
* *
* @param key * @param key the key to increment
* @param integer * @param integer the value to increment by
* @return Integer reply, this commands will reply with the new value of key * @return Integer reply, this commands will reply with the new value of key
* after the increment. * after the increment.
*/ */
@@ -978,8 +976,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
public List<byte[]> hvals(final byte[] key) { public List<byte[]> hvals(final byte[] key) {
checkIsInMulti(); checkIsInMulti();
client.hvals(key); client.hvals(key);
final List<byte[]> lresult = client.getBinaryMultiBulkReply(); return client.getBinaryMultiBulkReply();
return lresult;
} }
/** /**
@@ -1184,7 +1181,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* O(N) (with N being the length of the list), setting the first or last * O(N) (with N being the length of the list), setting the first or last
* elements of the list is O(1). * elements of the list is O(1).
* *
* @see #lindex(byte[], int) * @see #lindex(byte[], long)
* *
* @param key * @param key
* @param index * @param index
@@ -1305,11 +1302,11 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
/** /**
* Return all the members (elements) of the set value stored at key. This is * 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}.
* <p> * <p>
* Time complexity O(N) * Time complexity O(N)
* *
* @param key * @param key the key of the set
* @return Multi bulk reply * @return Multi bulk reply
*/ */
public Set<byte[]> smembers(final byte[] key) { public Set<byte[]> smembers(final byte[] key) {
@@ -1326,8 +1323,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* <p> * <p>
* Time complexity O(1) * Time complexity O(1)
* *
* @param key * @param key the key of the set
* @param member * @param member the set member to remove
* @return Integer reply, specifically: 1 if the new element was removed 0 * @return Integer reply, specifically: 1 if the new element was removed 0
* if the new element was not a member of the set * if the new element was not a member of the set
*/ */
@@ -1420,7 +1417,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
/** /**
* Return the members of a set resulting from the intersection of all the * Return the members of a set resulting from the intersection of all the
* sets hold at the specified keys. Like in * 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 * as a multi-bulk reply (see the protocol specification for more
* information). If just a single key is specified, then this command * information). If just a single key is specified, then this command
* produces the same result as {@link #smembers(byte[]) SMEMBERS}. Actually * produces the same result as {@link #smembers(byte[]) SMEMBERS}. Actually
@@ -1444,7 +1441,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. * instead of being returned the resulting set is sotred as dstkey.
* <p> * <p>
* Time complexity O(N*M) worst case where N is the cardinality of the * Time complexity O(N*M) worst case where N is the cardinality of the
@@ -1462,7 +1459,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
/** /**
* Return the members of a set resulting from the union of all the sets hold * 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 * 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, * specification for more information). If just a single key is specified,
* then this command produces the same result as {@link #smembers(byte[]) * then this command produces the same result as {@link #smembers(byte[])
@@ -1484,7 +1481,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 * instead of being returned the resulting set is stored as dstkey. Any
* existing value in dstkey will be over-written. * existing value in dstkey will be over-written.
* <p> * <p>
@@ -1532,7 +1529,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. * instead of being returned the resulting set is stored in dstkey.
* *
* @param dstkey * @param dstkey
@@ -1726,16 +1723,14 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
final long end) { final long end) {
checkIsInMulti(); checkIsInMulti();
client.zrangeWithScores(key, start, end); client.zrangeWithScores(key, start, end);
Set<Tuple> set = getBinaryTupledSet(); return getBinaryTupledSet();
return set;
} }
public Set<Tuple> zrevrangeWithScores(final byte[] key, final long start, public Set<Tuple> zrevrangeWithScores(final byte[] key, final long start,
final long end) { final long end) {
checkIsInMulti(); checkIsInMulti();
client.zrevrangeWithScores(key, start, end); client.zrevrangeWithScores(key, start, end);
Set<Tuple> set = getBinaryTupledSet(); return getBinaryTupledSet();
return set;
} }
/** /**
@@ -1995,7 +1990,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* <p> * <p>
* Time complexity: O(1) * Time complexity: O(1)
* *
* @see #brpop(int, String...) * @see #brpop(int, byte[]...)
* *
* @param timeout * @param timeout
* @param keys * @param keys
@@ -2008,18 +2003,17 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* programming language used. * programming language used.
*/ */
public List<byte[]> blpop(final int timeout, final byte[]... keys) { public List<byte[]> blpop(final int timeout, final byte[]... keys) {
checkIsInMulti(); return blpop(getArgsAddTimeout(timeout, keys));
final List<byte[]> args = new ArrayList<byte[]>();
for (final byte[] arg : keys) {
args.add(arg);
} }
args.add(Protocol.toByteArray(timeout));
client.blpop(args.toArray(new byte[args.size()][])); private byte[][] getArgsAddTimeout (int timeout, byte[][] keys) {
client.setTimeoutInfinite(); int size = keys.length;
final List<byte[]> multiBulkReply = client.getBinaryMultiBulkReply(); final byte[][] args = new byte[size + 1][];
client.rollbackTimeout(); for (int at = 0; at != size; ++at) {
return multiBulkReply; args[at] = keys[at];
}
args[size] = Protocol.toByteArray(timeout);
return args;
} }
/** /**
@@ -2124,7 +2118,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* <p> * <p>
* Time complexity: O(1) * Time complexity: O(1)
* *
* @see #blpop(int, String...) * @see #blpop(int, byte[]...)
* *
* @param timeout * @param timeout
* @param keys * @param keys
@@ -2137,59 +2131,46 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* programming language used. * programming language used.
*/ */
public List<byte[]> brpop(final int timeout, final byte[]... keys) { public List<byte[]> brpop(final int timeout, final byte[]... keys) {
checkIsInMulti(); return brpop(getArgsAddTimeout(timeout, keys));
final List<byte[]> args = new ArrayList<byte[]>();
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<byte[]> multiBulkReply = client.getBinaryMultiBulkReply();
client.rollbackTimeout();
return multiBulkReply;
} }
/**
* @deprecated unusable command, this command will be removed in 3.0.0.
*/
@Deprecated
public List<byte[]> blpop(byte[] arg) { public List<byte[]> blpop(byte[] arg) {
checkIsInMulti(); return blpop(new byte[][]{arg});
byte[][] args = new byte[1][];
args[0] = arg;
client.blpop(args);
client.setTimeoutInfinite();
final List<byte[]> multiBulkReply = client.getBinaryMultiBulkReply();
client.rollbackTimeout();
return multiBulkReply;
} }
/**
* @deprecated unusable command, this command will be removed in 3.0.0.
*/
@Deprecated
public List<byte[]> brpop(byte[] arg) { public List<byte[]> brpop(byte[] arg) {
checkIsInMulti(); return brpop(new byte[][]{arg});
byte[][] args = new byte[1][];
args[0] = arg;
client.brpop(args);
client.setTimeoutInfinite();
final List<byte[]> multiBulkReply = client.getBinaryMultiBulkReply();
client.rollbackTimeout();
return multiBulkReply;
} }
public List<byte[]> blpop(byte[]... args) { public List<byte[]> blpop(byte[]... args) {
checkIsInMulti(); checkIsInMulti();
client.blpop(args); client.blpop(args);
client.setTimeoutInfinite(); client.setTimeoutInfinite();
final List<byte[]> multiBulkReply = client.getBinaryMultiBulkReply(); try {
return client.getBinaryMultiBulkReply();
} finally {
client.rollbackTimeout(); client.rollbackTimeout();
return multiBulkReply; }
} }
public List<byte[]> brpop(byte[]... args) { public List<byte[]> brpop(byte[]... args) {
checkIsInMulti(); checkIsInMulti();
client.brpop(args); client.brpop(args);
client.setTimeoutInfinite(); client.setTimeoutInfinite();
final List<byte[]> multiBulkReply = client.getBinaryMultiBulkReply(); try {
return client.getBinaryMultiBulkReply();
} finally {
client.rollbackTimeout(); client.rollbackTimeout();
return multiBulkReply; }
} }
/** /**
@@ -2431,8 +2412,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
final byte[] min, final byte[] max) { final byte[] min, final byte[] max) {
checkIsInMulti(); checkIsInMulti();
client.zrangeByScoreWithScores(key, min, max); client.zrangeByScoreWithScores(key, min, max);
Set<Tuple> set = getBinaryTupledSet(); return getBinaryTupledSet();
return set;
} }
/** /**
@@ -2503,8 +2483,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
final int count) { final int count) {
checkIsInMulti(); checkIsInMulti();
client.zrangeByScoreWithScores(key, min, max, offset, count); client.zrangeByScoreWithScores(key, min, max, offset, count);
Set<Tuple> set = getBinaryTupledSet(); return getBinaryTupledSet();
return set;
} }
private Set<Tuple> getBinaryTupledSet() { private Set<Tuple> getBinaryTupledSet() {
@@ -2561,8 +2540,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
final byte[] max, final byte[] min) { final byte[] max, final byte[] min) {
checkIsInMulti(); checkIsInMulti();
client.zrevrangeByScoreWithScores(key, max, min); client.zrevrangeByScoreWithScores(key, max, min);
Set<Tuple> set = getBinaryTupledSet(); return getBinaryTupledSet();
return set;
} }
public Set<Tuple> zrevrangeByScoreWithScores(final byte[] key, public Set<Tuple> zrevrangeByScoreWithScores(final byte[] key,
@@ -2570,8 +2548,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
final int count) { final int count) {
checkIsInMulti(); checkIsInMulti();
client.zrevrangeByScoreWithScores(key, max, min, offset, count); client.zrevrangeByScoreWithScores(key, max, min, offset, count);
Set<Tuple> set = getBinaryTupledSet(); return getBinaryTupledSet();
return set;
} }
/** /**
@@ -2626,10 +2603,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* input keys N, before passing the input keys and the other (optional) * input keys N, before passing the input keys and the other (optional)
* arguments. * arguments.
* <p> * <p>
* 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 * ZINTERSTORE} command requires an element to be present in each of the
* given inputs to be inserted in the result. 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. * elements across all inputs.
* <p> * <p>
* Using the WEIGHTS option, it is possible to add weight to each input * Using the WEIGHTS option, it is possible to add weight to each input
@@ -2648,10 +2625,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* sizes of the input sorted sets, and M being the number of elements in the * sizes of the input sorted sets, and M being the number of elements in the
* resulting sorted set * resulting sorted set
* *
* @see #zunionstore(String, String...) * @see #zunionstore(byte[], byte[]...)
* @see #zunionstore(String, ZParams, String...) * @see #zunionstore(byte[], ZParams, byte[]...)
* @see #zinterstore(String, String...) * @see #zinterstore(byte[], byte[]...)
* @see #zinterstore(String, ZParams, String...) * @see #zinterstore(byte[], ZParams, byte[]...)
* *
* @param dstkey * @param dstkey
* @param sets * @param sets
@@ -2670,10 +2647,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* input keys N, before passing the input keys and the other (optional) * input keys N, before passing the input keys and the other (optional)
* arguments. * arguments.
* <p> * <p>
* 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 * ZINTERSTORE} command requires an element to be present in each of the
* given inputs to be inserted in the result. 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. * elements across all inputs.
* <p> * <p>
* Using the WEIGHTS option, it is possible to add weight to each input * Using the WEIGHTS option, it is possible to add weight to each input
@@ -2692,10 +2669,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* sizes of the input sorted sets, and M being the number of elements in the * sizes of the input sorted sets, and M being the number of elements in the
* resulting sorted set * resulting sorted set
* *
* @see #zunionstore(String, String...) * @see #zunionstore(byte[], byte[]...)
* @see #zunionstore(String, ZParams, String...) * @see #zunionstore(byte[], ZParams, byte[]...)
* @see #zinterstore(String, String...) * @see #zinterstore(byte[], byte[]...)
* @see #zinterstore(String, ZParams, String...) * @see #zinterstore(byte[], ZParams, byte[]...)
* *
* @param dstkey * @param dstkey
* @param sets * @param sets
@@ -2716,10 +2693,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* input keys N, before passing the input keys and the other (optional) * input keys N, before passing the input keys and the other (optional)
* arguments. * arguments.
* <p> * <p>
* 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 * ZINTERSTORE} command requires an element to be present in each of the
* given inputs to be inserted in the result. 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. * elements across all inputs.
* <p> * <p>
* Using the WEIGHTS option, it is possible to add weight to each input * Using the WEIGHTS option, it is possible to add weight to each input
@@ -2738,10 +2715,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* sizes of the input sorted sets, and M being the number of elements in the * sizes of the input sorted sets, and M being the number of elements in the
* resulting sorted set * resulting sorted set
* *
* @see #zunionstore(String, String...) * @see #zunionstore(byte[], byte[]...)
* @see #zunionstore(String, ZParams, String...) * @see #zunionstore(byte[], ZParams, byte[]...)
* @see #zinterstore(String, String...) * @see #zinterstore(byte[], byte[]...)
* @see #zinterstore(String, ZParams, String...) * @see #zinterstore(byte[], ZParams, byte[]...)
* *
* @param dstkey * @param dstkey
* @param sets * @param sets
@@ -2760,10 +2737,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* input keys N, before passing the input keys and the other (optional) * input keys N, before passing the input keys and the other (optional)
* arguments. * arguments.
* <p> * <p>
* 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 * ZINTERSTORE} command requires an element to be present in each of the
* given inputs to be inserted in the result. 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. * elements across all inputs.
* <p> * <p>
* Using the WEIGHTS option, it is possible to add weight to each input * Using the WEIGHTS option, it is possible to add weight to each input
@@ -2782,10 +2759,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* sizes of the input sorted sets, and M being the number of elements in the * sizes of the input sorted sets, and M being the number of elements in the
* resulting sorted set * resulting sorted set
* *
* @see #zunionstore(String, String...) * @see #zunionstore(byte[], byte[]...)
* @see #zunionstore(String, ZParams, String...) * @see #zunionstore(byte[], ZParams, byte[]...)
* @see #zinterstore(String, String...) * @see #zinterstore(byte[], byte[]...)
* @see #zinterstore(String, ZParams, String...) * @see #zinterstore(byte[], ZParams, byte[]...)
* *
* @param dstkey * @param dstkey
* @param sets * @param sets
@@ -2935,7 +2912,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
*/ */
public String shutdown() { public String shutdown() {
client.shutdown(); client.shutdown();
String status = null; String status;
try { try {
status = client.getStatusCodeReply(); status = client.getStatusCodeReply();
} catch (JedisException ex) { } catch (JedisException ex) {
@@ -3101,7 +3078,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* configuration parameters are supported. * configuration parameters are supported.
* <p> * <p>
* The list of configuration parameters supported by CONFIG SET can be * 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.
* <p> * <p>
* The configuration set using CONFIG SET is immediately loaded by the Redis * The configuration set using CONFIG SET is immediately loaded by the Redis
* server that will start acting as specified starting from the next * server that will start acting as specified starting from the next
@@ -3205,9 +3182,11 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
public byte[] brpoplpush(byte[] source, byte[] destination, int timeout) { public byte[] brpoplpush(byte[] source, byte[] destination, int timeout) {
client.brpoplpush(source, destination, timeout); client.brpoplpush(source, destination, timeout);
client.setTimeoutInfinite(); client.setTimeoutInfinite();
byte[] reply = client.getBinaryBulkReply(); try {
return client.getBinaryBulkReply();
} finally {
client.rollbackTimeout(); client.rollbackTimeout();
return reply; }
} }
/** /**
@@ -3267,15 +3246,21 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
public void subscribe(BinaryJedisPubSub jedisPubSub, byte[]... channels) { public void subscribe(BinaryJedisPubSub jedisPubSub, byte[]... channels) {
client.setTimeoutInfinite(); client.setTimeoutInfinite();
try {
jedisPubSub.proceed(client, channels); jedisPubSub.proceed(client, channels);
} finally {
client.rollbackTimeout(); client.rollbackTimeout();
} }
}
public void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns) { public void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns) {
client.setTimeoutInfinite(); client.setTimeoutInfinite();
try {
jedisPubSub.proceedWithPatterns(client, patterns); jedisPubSub.proceedWithPatterns(client, patterns);
} finally {
client.rollbackTimeout(); client.rollbackTimeout();
} }
}
public Long getDB() { public Long getDB() {
return client.getDB(); return client.getDB();
@@ -3289,15 +3274,13 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
* @return Script result * @return Script result
*/ */
public Object eval(byte[] script, List<byte[]> keys, List<byte[]> args) { public Object eval(byte[] script, List<byte[]> keys, List<byte[]> args) {
client.setTimeoutInfinite(); return eval(script, toByteArray(keys.size()), getParams(keys, args));
client.eval(script, toByteArray(keys.size()), getParams(keys, args));
return client.getOne();
} }
private byte[][] getParams(List<byte[]> keys, List<byte[]> args) { private byte[][] getParams(List<byte[]> keys, List<byte[]> args) {
int keyCount = keys.size(); final int keyCount = keys.size();
int argCount = args.size(); final int argCount = args.size();
byte[][] params = new byte[keyCount + args.size()][]; byte[][] params = new byte[keyCount + argCount][];
for (int i = 0; i < keyCount; i++) for (int i = 0; i < keyCount; i++)
params[i] = keys.get(i); params[i] = keys.get(i);
@@ -3310,49 +3293,38 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
public Object eval(byte[] script, byte[] keyCount, byte[]... params) { public Object eval(byte[] script, byte[] keyCount, byte[]... params) {
client.setTimeoutInfinite(); client.setTimeoutInfinite();
try {
client.eval(script, keyCount, params); client.eval(script, keyCount, params);
return client.getOne(); return client.getOne();
} finally {
client.rollbackTimeout();
}
} }
public Object eval(byte[] script, int keyCount, byte[]... params) { public Object eval(byte[] script, int keyCount, byte[]... params) {
client.setTimeoutInfinite(); return eval(script, toByteArray(keyCount), params);
client.eval(script, SafeEncoder.encode(Integer.toString(keyCount)),
params);
return client.getOne();
} }
public Object eval(byte[] script) { public Object eval(byte[] script) {
client.setTimeoutInfinite(); return eval(script, 0);
client.eval(script, 0);
return client.getOne();
} }
public Object evalsha(byte[] sha1) { public Object evalsha(byte[] sha1) {
client.setTimeoutInfinite(); return evalsha(sha1, 1);
client.evalsha(sha1, 0);
return client.getOne();
} }
public Object evalsha(byte[] sha1, List<byte[]> keys, List<byte[]> args) { public Object evalsha(byte[] sha1, List<byte[]> keys, List<byte[]> args) {
return evalsha(sha1, keys.size(), getParams(keys, 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);
} }
public Object evalsha(byte[] sha1, int keyCount, byte[]... params) { public Object evalsha(byte[] sha1, int keyCount, byte[]... params) {
client.setTimeoutInfinite(); client.setTimeoutInfinite();
try {
client.evalsha(sha1, keyCount, params); client.evalsha(sha1, keyCount, params);
return client.getOne(); return client.getOne();
} finally {
client.rollbackTimeout();
}
} }
public String scriptFlush() { public String scriptFlush() {

View File

@@ -219,8 +219,18 @@ public interface BinaryJedisCommands {
Long rpushx(byte[] key, byte[]... arg); Long rpushx(byte[] key, byte[]... arg);
/**
* @deprecated unusable command, this command will be removed in 3.0.0.
*/
@Deprecated
List<byte[]> blpop(byte[] arg); List<byte[]> blpop(byte[] arg);
/**
* @deprecated unusable command, this command will be removed in 3.0.0.
*/
@Deprecated
List<byte[]> brpop(byte[] arg); List<byte[]> brpop(byte[] arg);
Long del(byte[] key); Long del(byte[] key);

View File

@@ -54,7 +54,6 @@ public class Connection implements Closeable {
if (!isConnected()) { if (!isConnected()) {
connect(); connect();
} }
socket.setKeepAlive(true);
socket.setSoTimeout(0); socket.setSoTimeout(0);
} catch (SocketException ex) { } catch (SocketException ex) {
broken = true; broken = true;
@@ -65,7 +64,6 @@ public class Connection implements Closeable {
public void rollbackTimeout() { public void rollbackTimeout() {
try { try {
socket.setSoTimeout(timeout); socket.setSoTimeout(timeout);
socket.setKeepAlive(false);
} catch (SocketException ex) { } catch (SocketException ex) {
broken = true; broken = true;
throw new JedisConnectionException(ex); throw new JedisConnectionException(ex);

View File

@@ -1849,54 +1849,56 @@ public class Jedis extends BinaryJedis implements JedisCommands,
* programming language used. * programming language used.
*/ */
public List<String> blpop(final int timeout, final String... keys) { public List<String> blpop(final int timeout, final String... keys) {
checkIsInMulti(); return blpop(getArgsAddTimeout(timeout, keys));
List<String> args = new ArrayList<String>();
for (String arg : keys) {
args.add(arg);
} }
args.add(String.valueOf(timeout));
client.blpop(args.toArray(new String[args.size()])); private String[] getArgsAddTimeout (int timeout, String[] keys) {
client.setTimeoutInfinite(); final int keyCount = keys.length;
final List<String> multiBulkReply = client.getMultiBulkReply(); final String[] args = new String[keyCount + 1];
client.rollbackTimeout(); for (int at = 0; at != keyCount; ++at) {
return multiBulkReply; args[at] = keys[at];
}
args[keyCount] = String.valueOf(timeout);
return args;
} }
public List<String> blpop(String... args) { public List<String> blpop(String... args) {
checkIsInMulti();
client.blpop(args); client.blpop(args);
client.setTimeoutInfinite(); client.setTimeoutInfinite();
final List<String> multiBulkReply = client.getMultiBulkReply(); try {
return client.getMultiBulkReply();
} finally {
client.rollbackTimeout(); client.rollbackTimeout();
return multiBulkReply; }
} }
public List<String> brpop(String... args) { public List<String> brpop(String... args) {
checkIsInMulti();
client.brpop(args); client.brpop(args);
client.setTimeoutInfinite(); client.setTimeoutInfinite();
final List<String> multiBulkReply = client.getMultiBulkReply(); try {
return client.getMultiBulkReply();
} finally {
client.rollbackTimeout(); client.rollbackTimeout();
return multiBulkReply; }
} }
/**
* @deprecated unusable command, this command will be removed in 3.0.0.
*/
@Deprecated
public List<String> blpop(String arg) { public List<String> blpop(String arg) {
String[] args = new String[1]; return blpop(new String[]{arg});
args[0] = arg;
client.blpop(args);
client.setTimeoutInfinite();
final List<String> multiBulkReply = client.getMultiBulkReply();
client.rollbackTimeout();
return multiBulkReply;
} }
/**
* @deprecated unusable command, this command will be removed in 3.0.0.
*/
@Deprecated
public List<String> brpop(String arg) { public List<String> brpop(String arg) {
String[] args = new String[1]; return brpop(new String[]{arg});
args[0] = arg;
client.brpop(args);
client.setTimeoutInfinite();
final List<String> multiBulkReply = client.getMultiBulkReply();
client.rollbackTimeout();
return multiBulkReply;
} }
/** /**
@@ -2014,19 +2016,7 @@ public class Jedis extends BinaryJedis implements JedisCommands,
* programming language used. * programming language used.
*/ */
public List<String> brpop(final int timeout, final String... keys) { public List<String> brpop(final int timeout, final String... keys) {
checkIsInMulti(); return brpop(getArgsAddTimeout(timeout, keys));
List<String> args = new ArrayList<String>();
for (String arg : keys) {
args.add(arg);
}
args.add(String.valueOf(timeout));
client.brpop(args.toArray(new String[args.size()]));
client.setTimeoutInfinite();
List<String> multiBulkReply = client.getMultiBulkReply();
client.rollbackTimeout();
return multiBulkReply;
} }
public Long zcount(final String key, final double min, final double max) { public Long zcount(final String key, final double min, final double max) {
@@ -2730,9 +2720,11 @@ public class Jedis extends BinaryJedis implements JedisCommands,
public String brpoplpush(String source, String destination, int timeout) { public String brpoplpush(String source, String destination, int timeout) {
client.brpoplpush(source, destination, timeout); client.brpoplpush(source, destination, timeout);
client.setTimeoutInfinite(); client.setTimeoutInfinite();
String reply = client.getBulkReply(); try {
return client.getBulkReply();
} finally {
client.rollbackTimeout(); client.rollbackTimeout();
return reply; }
} }
/** /**
@@ -2867,17 +2859,23 @@ public class Jedis extends BinaryJedis implements JedisCommands,
public Object eval(String script, int keyCount, String... params) { public Object eval(String script, int keyCount, String... params) {
client.setTimeoutInfinite(); client.setTimeoutInfinite();
try {
client.eval(script, keyCount, params); client.eval(script, keyCount, params);
return getEvalResult(); return getEvalResult();
} finally {
client.rollbackTimeout();
}
} }
public void subscribe(final JedisPubSub jedisPubSub, public void subscribe(final JedisPubSub jedisPubSub,
final String... channels) { final String... channels) {
client.setTimeoutInfinite(); client.setTimeoutInfinite();
try {
jedisPubSub.proceed(client, channels); jedisPubSub.proceed(client, channels);
} finally {
client.rollbackTimeout(); client.rollbackTimeout();
} }
}
public Long publish(final String channel, final String message) { public Long publish(final String channel, final String message) {
checkIsInMulti(); checkIsInMulti();
@@ -2889,11 +2887,13 @@ public class Jedis extends BinaryJedis implements JedisCommands,
public void psubscribe(final JedisPubSub jedisPubSub, public void psubscribe(final JedisPubSub jedisPubSub,
final String... patterns) { final String... patterns) {
checkIsInMulti(); checkIsInMulti();
connect();
client.setTimeoutInfinite(); client.setTimeoutInfinite();
try {
jedisPubSub.proceedWithPatterns(client, patterns); jedisPubSub.proceedWithPatterns(client, patterns);
} finally {
client.rollbackTimeout(); client.rollbackTimeout();
} }
}
protected static String[] getParams(List<String> keys, List<String> args) { protected static String[] getParams(List<String> keys, List<String> args) {
int keyCount = keys.size(); int keyCount = keys.size();
@@ -2950,7 +2950,6 @@ public class Jedis extends BinaryJedis implements JedisCommands,
public Object evalsha(String sha1, int keyCount, String... params) { public Object evalsha(String sha1, int keyCount, String... params) {
checkIsInMulti(); checkIsInMulti();
client.evalsha(sha1, keyCount, params); client.evalsha(sha1, keyCount, params);
return getEvalResult(); return getEvalResult();
} }
@@ -3509,28 +3508,12 @@ public class Jedis extends BinaryJedis implements JedisCommands,
@Override @Override
public List<String> blpop(int timeout, String key) { public List<String> blpop(int timeout, String key) {
checkIsInMulti(); return blpop(key, String.valueOf(timeout));
List<String> args = new ArrayList<String>();
args.add(key);
args.add(String.valueOf(timeout));
client.blpop(args.toArray(new String[args.size()]));
client.setTimeoutInfinite();
final List<String> multiBulkReply = client.getMultiBulkReply();
client.rollbackTimeout();
return multiBulkReply;
} }
@Override @Override
public List<String> brpop(int timeout, String key) { public List<String> brpop(int timeout, String key) {
checkIsInMulti(); return brpop(key, String.valueOf(timeout));
List<String> args = new ArrayList<String>();
args.add(key);
args.add(String.valueOf(timeout));
client.brpop(args.toArray(new String[args.size()]));
client.setTimeoutInfinite();
final List<String> multiBulkReply = client.getMultiBulkReply();
client.rollbackTimeout();
return multiBulkReply;
} }
} }

View File

@@ -216,10 +216,18 @@ public interface JedisCommands {
Long rpushx(String key, String... string); Long rpushx(String key, String... string);
/**
* @deprecated unusable command, this will be removed in 3.0.0.
*/
@Deprecated
List<String> blpop(String arg); List<String> blpop(String arg);
List<String> blpop(int timeout, String key); List<String> blpop(int timeout, String key);
/**
* @deprecated unusable command, this will be removed in 3.0.0.
*/
@Deprecated
List<String> brpop(String arg); List<String> brpop(String arg);
List<String> brpop(int timeout, String key); List<String> brpop(int timeout, String key);