Merge branch 'master' into implements-closeable-to-pooled-jedis-shardedjedis
Conflicts: src/main/java/redis/clients/jedis/Jedis.java src/main/java/redis/clients/jedis/JedisSentinelPool.java src/main/java/redis/clients/jedis/ShardedJedis.java src/test/java/redis/clients/jedis/tests/JedisPoolTest.java
This commit is contained in:
@@ -4,6 +4,7 @@ import static redis.clients.jedis.Protocol.toByteArray;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.net.URI;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -633,6 +634,37 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
/**
|
||||
* INCRBYFLOAT work just like {@link #incrBy(byte[]) INCRBY} but increments
|
||||
* by floats instead of integers.
|
||||
* <p>
|
||||
* INCRBYFLOAT commands are limited to double precision floating point
|
||||
* values.
|
||||
* <p>
|
||||
* Note: this is actually a string operation, that is, in Redis there are
|
||||
* not "double" types. Simply the string stored at the key is parsed as a
|
||||
* base double precision floating point value, incremented, and then
|
||||
* converted back as a string. There is no DECRYBYFLOAT but providing a
|
||||
* negative value will work as expected.
|
||||
* <p>
|
||||
* Time complexity: O(1)
|
||||
*
|
||||
* @see #incr(byte[])
|
||||
* @see #decr(byte[])
|
||||
* @see #decrBy(byte[], long)
|
||||
*
|
||||
* @param key
|
||||
* @param integer
|
||||
* @return Integer reply, this commands will reply with the new value of key
|
||||
* after the increment.
|
||||
*/
|
||||
public Double incrByFloat(final byte[] key, final double integer) {
|
||||
checkIsInMulti();
|
||||
client.incrByFloat(key, integer);
|
||||
String dval = client.getBulkReply();
|
||||
return (dval != null ? new Double(dval) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the number stored at key by one. If the key does not exist or
|
||||
* contains a value of a wrong type, set the key to the value of "0" before
|
||||
@@ -825,6 +857,33 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the number stored at field in the hash at key by a double
|
||||
* precision floating point value. If key does not exist, a new key holding
|
||||
* a hash is created. If field does not exist or holds a string, the value
|
||||
* is set to 0 before applying the operation. Since the value argument is
|
||||
* signed you can use this command to perform both increments and
|
||||
* decrements.
|
||||
* <p>
|
||||
* The range of values supported by HINCRBYFLOAT is limited to double
|
||||
* precision floating point values.
|
||||
* <p>
|
||||
* <b>Time complexity:</b> O(1)
|
||||
*
|
||||
* @param key
|
||||
* @param field
|
||||
* @param value
|
||||
* @return Double precision floating point reply The new value at field
|
||||
* after the increment operation.
|
||||
*/
|
||||
public Double hincrByFloat(final byte[] key, final byte[] field,
|
||||
final double value) {
|
||||
checkIsInMulti();
|
||||
client.hincrByFloat(key, field, value);
|
||||
final String dval = client.getBulkReply();
|
||||
return (dval != null ? new Double(dval) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for existence of a specified field in a hash.
|
||||
*
|
||||
@@ -3128,6 +3187,16 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
|
||||
return client.getIntegerReply() == 1;
|
||||
}
|
||||
|
||||
public Long bitpos(final byte[] key, final boolean value) {
|
||||
return bitpos(key, value, new BitPosParams());
|
||||
}
|
||||
|
||||
public Long bitpos(final byte[] key, final boolean value,
|
||||
final BitPosParams params) {
|
||||
client.bitpos(key, value, params);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public Long setrange(byte[] key, long offset, byte[] value) {
|
||||
client.setrange(key, offset, value);
|
||||
return client.getIntegerReply();
|
||||
@@ -3316,7 +3385,12 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Long pexpire(final byte[] key, final int milliseconds) {
|
||||
return pexpire(key, (long) milliseconds);
|
||||
}
|
||||
|
||||
public Long pexpire(final byte[] key, final long milliseconds) {
|
||||
checkIsInMulti();
|
||||
client.pexpire(key, milliseconds);
|
||||
return client.getIntegerReply();
|
||||
@@ -3334,13 +3408,6 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public Double incrByFloat(final byte[] key, final double increment) {
|
||||
checkIsInMulti();
|
||||
client.incrByFloat(key, increment);
|
||||
String relpy = client.getBulkReply();
|
||||
return (relpy != null ? new Double(relpy) : null);
|
||||
}
|
||||
|
||||
public String psetex(final byte[] key, final int milliseconds,
|
||||
final byte[] value) {
|
||||
checkIsInMulti();
|
||||
@@ -3398,14 +3465,6 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public Double hincrByFloat(final byte[] key, final byte[] field,
|
||||
double increment) {
|
||||
checkIsInMulti();
|
||||
client.hincrByFloat(key, field, increment);
|
||||
String relpy = client.getBulkReply();
|
||||
return (relpy != null ? new Double(relpy) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncrhonous replication of Redis as described here:
|
||||
* http://antirez.com/news/66
|
||||
@@ -3419,4 +3478,99 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long pfadd(final byte[] key, final byte[]... elements) {
|
||||
checkIsInMulti();
|
||||
client.pfadd(key, elements);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long pfcount(final byte[] key) {
|
||||
checkIsInMulti();
|
||||
client.pfcount(key);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String pfmerge(final byte[] destkey, final byte[]... sourcekeys) {
|
||||
checkIsInMulti();
|
||||
client.pfmerge(destkey, sourcekeys);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long pfcount(byte[]... keys) {
|
||||
checkIsInMulti();
|
||||
client.pfcount(keys);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public ScanResult<byte[]> scan(final byte[] cursor) {
|
||||
return scan(cursor, new ScanParams());
|
||||
}
|
||||
|
||||
public ScanResult<byte[]> scan(final byte[] cursor, final ScanParams params) {
|
||||
checkIsInMulti();
|
||||
client.scan(cursor, params);
|
||||
List<Object> result = client.getObjectMultiBulkReply();
|
||||
byte[] newcursor = (byte[]) result.get(0);
|
||||
List<byte[]> rawResults = (List<byte[]>) result.get(1);
|
||||
return new ScanResult<byte[]>(newcursor, rawResults);
|
||||
}
|
||||
|
||||
public ScanResult<Map.Entry<byte[], byte[]>> hscan(final byte[] key,
|
||||
final byte[] cursor) {
|
||||
return hscan(key, cursor, new ScanParams());
|
||||
}
|
||||
|
||||
public ScanResult<Map.Entry<byte[], byte[]>> hscan(final byte[] key,
|
||||
final byte[] cursor, final ScanParams params) {
|
||||
checkIsInMulti();
|
||||
client.hscan(key, cursor, params);
|
||||
List<Object> result = client.getObjectMultiBulkReply();
|
||||
byte[] newcursor = (byte[]) result.get(0);
|
||||
List<Map.Entry<byte[], byte[]>> results = new ArrayList<Map.Entry<byte[], byte[]>>();
|
||||
List<byte[]> rawResults = (List<byte[]>) result.get(1);
|
||||
Iterator<byte[]> iterator = rawResults.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
results.add(new AbstractMap.SimpleEntry<byte[], byte[]>(iterator
|
||||
.next(), iterator.next()));
|
||||
}
|
||||
return new ScanResult<Map.Entry<byte[], byte[]>>(newcursor, results);
|
||||
}
|
||||
|
||||
public ScanResult<byte[]> sscan(final byte[] key, final byte[] cursor) {
|
||||
return sscan(key, cursor, new ScanParams());
|
||||
}
|
||||
|
||||
public ScanResult<byte[]> sscan(final byte[] key, final byte[] cursor,
|
||||
final ScanParams params) {
|
||||
checkIsInMulti();
|
||||
client.sscan(key, cursor, params);
|
||||
List<Object> result = client.getObjectMultiBulkReply();
|
||||
byte[] newcursor = (byte[]) result.get(0);
|
||||
List<byte[]> rawResults = (List<byte[]>) result.get(1);
|
||||
return new ScanResult<byte[]>(newcursor, rawResults);
|
||||
}
|
||||
|
||||
public ScanResult<Tuple> zscan(final byte[] key, final byte[] cursor) {
|
||||
return zscan(key, cursor, new ScanParams());
|
||||
}
|
||||
|
||||
public ScanResult<Tuple> zscan(final byte[] key, final byte[] cursor,
|
||||
final ScanParams params) {
|
||||
checkIsInMulti();
|
||||
client.zscan(key, cursor, params);
|
||||
List<Object> result = client.getObjectMultiBulkReply();
|
||||
byte[] newcursor = (byte[]) result.get(0);
|
||||
List<Tuple> results = new ArrayList<Tuple>();
|
||||
List<byte[]> rawResults = (List<byte[]>) result.get(1);
|
||||
Iterator<byte[]> iterator = rawResults.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
results.add(new Tuple(iterator.next(), Double.valueOf(SafeEncoder
|
||||
.encode(iterator.next()))));
|
||||
}
|
||||
return new ScanResult<Tuple>(newcursor, results);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user