Merge branch 'master' into support-sorted-set-with-lex
Conflicts: src/main/java/redis/clients/jedis/BinaryShardedJedis.java src/main/java/redis/clients/jedis/Jedis.java src/main/java/redis/clients/jedis/Protocol.java src/test/java/redis/clients/jedis/tests/commands/SortedSetCommandsTest.java
This commit is contained in:
@@ -1,23 +1,20 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.util.Pool;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
import redis.clients.util.Slowlog;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
MultiKeyCommands, AdvancedJedisCommands, ScriptingCommands,
|
||||
BasicCommands, ClusterCommands {
|
||||
|
||||
protected Pool<Jedis> dataSource = null;
|
||||
|
||||
public Jedis(final String host) {
|
||||
super(host);
|
||||
}
|
||||
@@ -547,6 +544,31 @@ public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
/**
|
||||
* INCRBYFLOAT
|
||||
* <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)
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return Double reply, this commands will reply with the new value of key
|
||||
* after the increment.
|
||||
*/
|
||||
public Double incrByFloat(final String key, final double value) {
|
||||
checkIsInMulti();
|
||||
client.incrByFloat(key, value);
|
||||
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
|
||||
@@ -739,6 +761,32 @@ public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
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 String key, final String 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.
|
||||
*
|
||||
@@ -1068,8 +1116,8 @@ public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
|
||||
/**
|
||||
* Atomically return and remove the first (LPOP) or last (RPOP) element of
|
||||
* the list. For example if the list contains the elements "a","b","c" LPOP
|
||||
* will return "a" and the list will become "b","c".
|
||||
* the list. For example if the list contains the elements "a","b","c" RPOP
|
||||
* will return "c" and the list will become "a","b".
|
||||
* <p>
|
||||
* If the key does not exist or the list is already empty the special value
|
||||
* 'nil' is returned.
|
||||
@@ -2688,6 +2736,15 @@ public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
client.getrange(key, startOffset, endOffset);
|
||||
return client.getBulkReply();
|
||||
}
|
||||
|
||||
public Long bitpos(final String key, final boolean value) {
|
||||
return bitpos(key, value, new BitPosParams());
|
||||
}
|
||||
|
||||
public Long bitpos(final String key, final boolean value, final BitPosParams params) {
|
||||
client.bitpos(key, value, params);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the configuration of a running Redis server. Not all the
|
||||
@@ -3089,7 +3146,7 @@ public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public Long pexpire(final String key, final int milliseconds) {
|
||||
public Long pexpire(final String key, final long milliseconds) {
|
||||
checkIsInMulti();
|
||||
client.pexpire(key, milliseconds);
|
||||
return client.getIntegerReply();
|
||||
@@ -3107,12 +3164,6 @@ public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public Double incrByFloat(final String key, final double increment) {
|
||||
checkIsInMulti();
|
||||
client.incrByFloat(key, increment);
|
||||
String relpy = client.getBulkReply();
|
||||
return (relpy != null ? new Double(relpy) : null);
|
||||
}
|
||||
|
||||
public String psetex(final String key, final int milliseconds,
|
||||
final String value) {
|
||||
@@ -3153,143 +3204,10 @@ public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public Double hincrByFloat(final String key, final String field,
|
||||
double increment) {
|
||||
checkIsInMulti();
|
||||
client.hincrByFloat(key, field, increment);
|
||||
String relpy = client.getBulkReply();
|
||||
return (relpy != null ? new Double(relpy) : null);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* This method is deprecated due to bug (scan cursor should be unsigned long)
|
||||
* And will be removed on next major release
|
||||
* @see https://github.com/xetorthio/jedis/issues/531
|
||||
*/
|
||||
public ScanResult<String> scan(int cursor) {
|
||||
return scan(cursor, new ScanParams());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* This method is deprecated due to bug (scan cursor should be unsigned long)
|
||||
* And will be removed on next major release
|
||||
* @see https://github.com/xetorthio/jedis/issues/531
|
||||
*/
|
||||
public ScanResult<String> scan(int cursor, final ScanParams params) {
|
||||
checkIsInMulti();
|
||||
client.scan(cursor, params);
|
||||
List<Object> result = client.getObjectMultiBulkReply();
|
||||
int newcursor = Integer.parseInt(new String((byte[]) result.get(0)));
|
||||
List<String> results = new ArrayList<String>();
|
||||
List<byte[]> rawResults = (List<byte[]>) result.get(1);
|
||||
for (byte[] bs : rawResults) {
|
||||
results.add(SafeEncoder.encode(bs));
|
||||
}
|
||||
return new ScanResult<String>(newcursor, results);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* This method is deprecated due to bug (scan cursor should be unsigned long)
|
||||
* And will be removed on next major release
|
||||
* @see https://github.com/xetorthio/jedis/issues/531
|
||||
*/
|
||||
public ScanResult<Map.Entry<String, String>> hscan(final String key,
|
||||
int cursor) {
|
||||
return hscan(key, cursor, new ScanParams());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* This method is deprecated due to bug (scan cursor should be unsigned long)
|
||||
* And will be removed on next major release
|
||||
* @see https://github.com/xetorthio/jedis/issues/531
|
||||
*/
|
||||
public ScanResult<Map.Entry<String, String>> hscan(final String key,
|
||||
int cursor, final ScanParams params) {
|
||||
checkIsInMulti();
|
||||
client.hscan(key, cursor, params);
|
||||
List<Object> result = client.getObjectMultiBulkReply();
|
||||
int newcursor = Integer.parseInt(new String((byte[]) result.get(0)));
|
||||
List<Map.Entry<String, String>> results = new ArrayList<Map.Entry<String, String>>();
|
||||
List<byte[]> rawResults = (List<byte[]>) result.get(1);
|
||||
Iterator<byte[]> iterator = rawResults.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
results.add(new AbstractMap.SimpleEntry<String, String>(SafeEncoder
|
||||
.encode(iterator.next()), SafeEncoder.encode(iterator
|
||||
.next())));
|
||||
}
|
||||
return new ScanResult<Map.Entry<String, String>>(newcursor, results);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* This method is deprecated due to bug (scan cursor should be unsigned long)
|
||||
* And will be removed on next major release
|
||||
* @see https://github.com/xetorthio/jedis/issues/531
|
||||
*/
|
||||
public ScanResult<String> sscan(final String key, int cursor) {
|
||||
return sscan(key, cursor, new ScanParams());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* This method is deprecated due to bug (scan cursor should be unsigned long)
|
||||
* And will be removed on next major release
|
||||
* @see https://github.com/xetorthio/jedis/issues/531
|
||||
*/
|
||||
public ScanResult<String> sscan(final String key, int cursor,
|
||||
final ScanParams params) {
|
||||
checkIsInMulti();
|
||||
client.sscan(key, cursor, params);
|
||||
List<Object> result = client.getObjectMultiBulkReply();
|
||||
int newcursor = Integer.parseInt(new String((byte[]) result.get(0)));
|
||||
List<String> results = new ArrayList<String>();
|
||||
List<byte[]> rawResults = (List<byte[]>) result.get(1);
|
||||
for (byte[] bs : rawResults) {
|
||||
results.add(SafeEncoder.encode(bs));
|
||||
}
|
||||
return new ScanResult<String>(newcursor, results);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* This method is deprecated due to bug (scan cursor should be unsigned long)
|
||||
* And will be removed on next major release
|
||||
* @see https://github.com/xetorthio/jedis/issues/531
|
||||
*/
|
||||
public ScanResult<Tuple> zscan(final String key, int cursor) {
|
||||
return zscan(key, cursor, new ScanParams());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* This method is deprecated due to bug (scan cursor should be unsigned long)
|
||||
* And will be removed on next major release
|
||||
* @see https://github.com/xetorthio/jedis/issues/531
|
||||
*/
|
||||
public ScanResult<Tuple> zscan(final String key, int cursor,
|
||||
final ScanParams params) {
|
||||
checkIsInMulti();
|
||||
client.zscan(key, cursor, params);
|
||||
List<Object> result = client.getObjectMultiBulkReply();
|
||||
int newcursor = Integer.parseInt(new String((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(SafeEncoder.encode(iterator.next()), Double
|
||||
.valueOf(SafeEncoder.encode(iterator.next()))));
|
||||
}
|
||||
return new ScanResult<Tuple>(newcursor, results);
|
||||
}
|
||||
|
||||
public ScanResult<String> scan(final String cursor) {
|
||||
return scan(cursor, new ScanParams());
|
||||
}
|
||||
|
||||
|
||||
public ScanResult<String> scan(final String cursor, final ScanParams params) {
|
||||
checkIsInMulti();
|
||||
client.scan(cursor, params);
|
||||
@@ -3302,12 +3220,12 @@ public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
}
|
||||
return new ScanResult<String>(newcursor, results);
|
||||
}
|
||||
|
||||
|
||||
public ScanResult<Map.Entry<String, String>> hscan(final String key,
|
||||
final String cursor) {
|
||||
return hscan(key, cursor, new ScanParams());
|
||||
}
|
||||
|
||||
|
||||
public ScanResult<Map.Entry<String, String>> hscan(final String key,
|
||||
final String cursor, final ScanParams params) {
|
||||
checkIsInMulti();
|
||||
@@ -3320,15 +3238,15 @@ public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
while (iterator.hasNext()) {
|
||||
results.add(new AbstractMap.SimpleEntry<String, String>(SafeEncoder
|
||||
.encode(iterator.next()), SafeEncoder.encode(iterator
|
||||
.next())));
|
||||
.next())));
|
||||
}
|
||||
return new ScanResult<Map.Entry<String, String>>(newcursor, results);
|
||||
}
|
||||
|
||||
|
||||
public ScanResult<String> sscan(final String key, final String cursor) {
|
||||
return sscan(key, cursor, new ScanParams());
|
||||
}
|
||||
|
||||
|
||||
public ScanResult<String> sscan(final String key, final String cursor,
|
||||
final ScanParams params) {
|
||||
checkIsInMulti();
|
||||
@@ -3342,11 +3260,11 @@ public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
}
|
||||
return new ScanResult<String>(newcursor, results);
|
||||
}
|
||||
|
||||
|
||||
public ScanResult<Tuple> zscan(final String key, final String cursor) {
|
||||
return zscan(key, cursor, new ScanParams());
|
||||
}
|
||||
|
||||
|
||||
public ScanResult<Tuple> zscan(final String key, final String cursor,
|
||||
final ScanParams params) {
|
||||
checkIsInMulti();
|
||||
@@ -3416,6 +3334,67 @@ public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
client.clusterSetSlotImporting(slot, nodeId);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String clusterSetSlotStable(final int slot) {
|
||||
checkIsInMulti();
|
||||
client.clusterSetSlotStable(slot);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String clusterForget(final String nodeId) {
|
||||
checkIsInMulti();
|
||||
client.clusterForget(nodeId);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String clusterFlushSlots() {
|
||||
checkIsInMulti();
|
||||
client.clusterFlushSlots();
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public Long clusterKeySlot(final String key) {
|
||||
checkIsInMulti();
|
||||
client.clusterKeySlot(key);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public Long clusterCountKeysInSlot(final int slot) {
|
||||
checkIsInMulti();
|
||||
client.clusterCountKeysInSlot(slot);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public String clusterSaveConfig() {
|
||||
checkIsInMulti();
|
||||
client.clusterSaveConfig();
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String clusterReplicate(final String nodeId) {
|
||||
checkIsInMulti();
|
||||
client.clusterReplicate(nodeId);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public List<String> clusterSlaves(final String nodeId) {
|
||||
checkIsInMulti();
|
||||
client.clusterSlaves(nodeId);
|
||||
return client.getMultiBulkReply();
|
||||
}
|
||||
|
||||
public String clusterFailover() {
|
||||
checkIsInMulti();
|
||||
client.clusterFailover();
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> clusterSlots() {
|
||||
checkIsInMulti();
|
||||
client.clusterSlots();
|
||||
return client.getObjectMultiBulkReply();
|
||||
}
|
||||
|
||||
public String asking() {
|
||||
checkIsInMulti();
|
||||
@@ -3438,8 +3417,50 @@ public class Jedis extends BinaryJedis implements JedisCommands,
|
||||
public Map<String, String> pubsubNumSub(String... channels) {
|
||||
checkIsInMulti();
|
||||
client.pubsubNumSub(channels);
|
||||
return BuilderFactory.STRING_MAP
|
||||
return BuilderFactory.PUBSUB_NUMSUB_MAP
|
||||
.build(client.getBinaryMultiBulkReply());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (dataSource != null) {
|
||||
if (client.isBroken()) {
|
||||
this.dataSource.returnBrokenResource(this);
|
||||
} else {
|
||||
this.dataSource.returnResource(this);
|
||||
}
|
||||
} else {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void setDataSource(Pool<Jedis> jedisPool) {
|
||||
this.dataSource = jedisPool;
|
||||
}
|
||||
|
||||
public Long pfadd(final String key, final String... elements) {
|
||||
checkIsInMulti();
|
||||
client.pfadd(key, elements);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public long pfcount(final String key) {
|
||||
checkIsInMulti();
|
||||
client.pfcount(key);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long pfcount(String... keys) {
|
||||
checkIsInMulti();
|
||||
client.pfcount(keys);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public String pfmerge(final String destkey, final String... sourcekeys) {
|
||||
checkIsInMulti();
|
||||
client.pfmerge(destkey, sourcekeys);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user