add SCAN, HSCAN, SSCAN and ZSCAN
This commit is contained in:
@@ -1100,4 +1100,35 @@ public class BinaryClient extends Connection {
|
|||||||
public void hincrByFloat(final byte[] key, final byte[] field, double increment) {
|
public void hincrByFloat(final byte[] key, final byte[] field, double increment) {
|
||||||
sendCommand(HINCRBYFLOAT, key, field, toByteArray(increment));
|
sendCommand(HINCRBYFLOAT, key, field, toByteArray(increment));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void scan(int cursor, final ScanParams params) {
|
||||||
|
final List<byte[]> args = new ArrayList<byte[]>();
|
||||||
|
args.add(toByteArray(cursor));
|
||||||
|
args.addAll(params.getParams());
|
||||||
|
sendCommand(SCAN, args.toArray(new byte[args.size()][]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hscan(final byte[] key, int cursor, final ScanParams params) {
|
||||||
|
final List<byte[]> args = new ArrayList<byte[]>();
|
||||||
|
args.add(key);
|
||||||
|
args.add(toByteArray(cursor));
|
||||||
|
args.addAll(params.getParams());
|
||||||
|
sendCommand(HSCAN, args.toArray(new byte[args.size()][]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sscan(final byte[] key, int cursor, final ScanParams params) {
|
||||||
|
final List<byte[]> args = new ArrayList<byte[]>();
|
||||||
|
args.add(key);
|
||||||
|
args.add(toByteArray(cursor));
|
||||||
|
args.addAll(params.getParams());
|
||||||
|
sendCommand(SSCAN, args.toArray(new byte[args.size()][]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zscan(final byte[] key, int cursor, final ScanParams params) {
|
||||||
|
final List<byte[]> args = new ArrayList<byte[]>();
|
||||||
|
args.add(key);
|
||||||
|
args.add(toByteArray(cursor));
|
||||||
|
args.addAll(params.getParams());
|
||||||
|
sendCommand(ZSCAN, args.toArray(new byte[args.size()][]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import java.util.Map;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import static redis.clients.jedis.Protocol.toByteArray;
|
import static redis.clients.jedis.Protocol.toByteArray;
|
||||||
|
import static redis.clients.jedis.Protocol.Command.HSCAN;
|
||||||
|
|
||||||
public class Client extends BinaryClient implements Commands {
|
public class Client extends BinaryClient implements Commands {
|
||||||
public Client(final String host) {
|
public Client(final String host) {
|
||||||
@@ -807,4 +808,16 @@ public class Client extends BinaryClient implements Commands {
|
|||||||
public void hincrByFloat(final String key, final String field, double increment) {
|
public void hincrByFloat(final String key, final String field, double increment) {
|
||||||
hincrByFloat(SafeEncoder.encode(key), SafeEncoder.encode(field), increment);
|
hincrByFloat(SafeEncoder.encode(key), SafeEncoder.encode(field), increment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void hscan(final String key, int cursor, final ScanParams params) {
|
||||||
|
hscan(SafeEncoder.encode(key), cursor, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sscan(final String key, int cursor, final ScanParams params) {
|
||||||
|
sscan(SafeEncoder.encode(key), cursor, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zscan(final String key, int cursor, final ScanParams params) {
|
||||||
|
zscan(SafeEncoder.encode(key), cursor, params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -295,4 +295,12 @@ public interface Commands {
|
|||||||
public void bitcount(final String key, long start, long end);
|
public void bitcount(final String key, long start, long end);
|
||||||
|
|
||||||
public void bitop(BitOP op, final String destKey, String... srcKeys);
|
public void bitop(BitOP op, final String destKey, String... srcKeys);
|
||||||
|
|
||||||
|
public void scan(int cursor, final ScanParams params);
|
||||||
|
|
||||||
|
public void hscan(final String key, int cursor, final ScanParams params);
|
||||||
|
|
||||||
|
public void sscan(final String key, int cursor, final ScanParams params);
|
||||||
|
|
||||||
|
public void zscan(final String key, int cursor, final ScanParams params);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
package redis.clients.jedis;
|
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.Set;
|
||||||
|
|
||||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||||
import redis.clients.util.SafeEncoder;
|
import redis.clients.util.SafeEncoder;
|
||||||
import redis.clients.util.Slowlog;
|
import redis.clients.util.Slowlog;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommands, AdvancedJedisCommands, ScriptingCommands {
|
public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommands, AdvancedJedisCommands, ScriptingCommands {
|
||||||
public Jedis(final String host) {
|
public Jedis(final String host) {
|
||||||
super(host);
|
super(host);
|
||||||
@@ -3076,4 +3083,74 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
|||||||
String relpy = client.getBulkReply();
|
String relpy = client.getBulkReply();
|
||||||
return (relpy != null ? new Double(relpy) : null);
|
return (relpy != null ? new Double(relpy) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ScanResult<String> scan(int cursor) {
|
||||||
|
return scan(cursor, new ScanParams());
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScanResult<Map.Entry<String, String>> hscan(final String key, int cursor) {
|
||||||
|
return hscan(key, cursor, new ScanParams());
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScanResult<String> sscan(final String key, int cursor) {
|
||||||
|
return sscan(key, cursor, new ScanParams());
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScanResult<Tuple> zscan(final String key, int cursor) {
|
||||||
|
return zscan(key, cursor, new ScanParams());
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -211,4 +211,10 @@ public interface
|
|||||||
Long bitcount(final String key);
|
Long bitcount(final String key);
|
||||||
|
|
||||||
Long bitcount(final String key, long start, long end);
|
Long bitcount(final String key, long start, long end);
|
||||||
|
|
||||||
|
ScanResult<Map.Entry<String, String>> hscan(final String key, int cursor);
|
||||||
|
|
||||||
|
ScanResult<String> sscan(final String key, int cursor);
|
||||||
|
|
||||||
|
ScanResult<Tuple> zscan(final String key, int cursor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package redis.clients.jedis;
|
|||||||
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface MultiKeyCommands {
|
public interface MultiKeyCommands {
|
||||||
@@ -70,4 +71,6 @@ public interface MultiKeyCommands {
|
|||||||
String randomKey();
|
String randomKey();
|
||||||
|
|
||||||
Long bitop(BitOP op, final String destKey, String... srcKeys);
|
Long bitop(BitOP op, final String destKey, String... srcKeys);
|
||||||
|
|
||||||
|
ScanResult<String> scan(int cursor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ public final class Protocol {
|
|||||||
|
|
||||||
public static enum Command {
|
public static enum Command {
|
||||||
PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, SENTINEL,
|
PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, SENTINEL,
|
||||||
DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL, INCRBYFLOAT, PSETEX, CLIENT, TIME, MIGRATE, HINCRBYFLOAT;
|
DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL, INCRBYFLOAT, PSETEX, CLIENT, TIME, MIGRATE, HINCRBYFLOAT, SCAN, HSCAN, SSCAN, ZSCAN;
|
||||||
|
|
||||||
public final byte[] raw;
|
public final byte[] raw;
|
||||||
|
|
||||||
@@ -169,7 +169,7 @@ public final class Protocol {
|
|||||||
|
|
||||||
public static enum Keyword {
|
public static enum Keyword {
|
||||||
AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT, RESET, FLUSH, EXISTS, LOAD, KILL, LEN, REFCOUNT, ENCODING, IDLETIME, AND, OR, XOR, NOT,
|
AGGREGATE, ALPHA, ASC, BY, DESC, GET, LIMIT, MESSAGE, NO, NOSORT, PMESSAGE, PSUBSCRIBE, PUNSUBSCRIBE, OK, ONE, QUEUED, SET, STORE, SUBSCRIBE, UNSUBSCRIBE, WEIGHTS, WITHSCORES, RESETSTAT, RESET, FLUSH, EXISTS, LOAD, KILL, LEN, REFCOUNT, ENCODING, IDLETIME, AND, OR, XOR, NOT,
|
||||||
GETNAME, SETNAME,LIST;
|
GETNAME, SETNAME,LIST, MATCH, COUNT;
|
||||||
public final byte[] raw;
|
public final byte[] raw;
|
||||||
|
|
||||||
Keyword() {
|
Keyword() {
|
||||||
|
|||||||
29
src/main/java/redis/clients/jedis/ScanParams.java
Normal file
29
src/main/java/redis/clients/jedis/ScanParams.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.COUNT;
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.MATCH;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import redis.clients.util.SafeEncoder;
|
||||||
|
|
||||||
|
public class ScanParams {
|
||||||
|
private List<byte[]> params = new ArrayList<byte[]>();
|
||||||
|
|
||||||
|
public void match(final String pattern) {
|
||||||
|
params.add(MATCH.raw);
|
||||||
|
params.add(SafeEncoder.encode(pattern));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void count(final int count) {
|
||||||
|
params.add(COUNT.raw);
|
||||||
|
params.add(Protocol.toByteArray(count));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<byte[]> getParams() {
|
||||||
|
return Collections.unmodifiableCollection(params);
|
||||||
|
}
|
||||||
|
}
|
||||||
21
src/main/java/redis/clients/jedis/ScanResult.java
Normal file
21
src/main/java/redis/clients/jedis/ScanResult.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ScanResult<T> {
|
||||||
|
private int cursor;
|
||||||
|
private List<T> results;
|
||||||
|
|
||||||
|
public ScanResult(int cursor, List<T> results) {
|
||||||
|
this.cursor = cursor;
|
||||||
|
this.results = results;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCursor() {
|
||||||
|
return cursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> getResult() {
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import redis.clients.util.Hashing;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@@ -522,5 +523,18 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
|||||||
return j.bitcount(key, start, end);
|
return j.bitcount(key, start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ScanResult<Entry<String, String>> hscan(String key, int cursor) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.hscan(key, cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScanResult<String> sscan(String key, int cursor) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.sscan(key, cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScanResult<Tuple> zscan(String key, int cursor) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zscan(key, cursor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import redis.clients.jedis.ScanParams;
|
||||||
|
import redis.clients.jedis.ScanResult;
|
||||||
import redis.clients.jedis.exceptions.JedisDataException;
|
import redis.clients.jedis.exceptions.JedisDataException;
|
||||||
import redis.clients.util.SafeEncoder;
|
import redis.clients.util.SafeEncoder;
|
||||||
|
|
||||||
@@ -503,4 +505,42 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
assertTrue(pttl >= 0 && pttl <= 20000);
|
assertTrue(pttl >= 0 && pttl <= 20000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void scan() {
|
||||||
|
jedis.set("b", "b");
|
||||||
|
jedis.set("a", "a");
|
||||||
|
|
||||||
|
ScanResult<String> result = jedis.scan(0);
|
||||||
|
|
||||||
|
assertEquals(0, result.getCursor());
|
||||||
|
assertFalse(result.getResult().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void scanMatch() {
|
||||||
|
ScanParams params = new ScanParams();
|
||||||
|
params.match("a*");
|
||||||
|
|
||||||
|
jedis.set("b", "b");
|
||||||
|
jedis.set("a", "a");
|
||||||
|
jedis.set("aa", "aa");
|
||||||
|
ScanResult<String> result = jedis.scan(0, params);
|
||||||
|
|
||||||
|
assertEquals(0, result.getCursor());
|
||||||
|
assertFalse(result.getResult().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void scanCount() {
|
||||||
|
ScanParams params = new ScanParams();
|
||||||
|
params.count(2);
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
jedis.set("a" + i, "a" + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScanResult<String> result = jedis.scan(0, params);
|
||||||
|
|
||||||
|
assertFalse(result.getResult().isEmpty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import redis.clients.jedis.ScanParams;
|
||||||
|
import redis.clients.jedis.ScanResult;
|
||||||
|
|
||||||
public class HashesCommandsTest extends JedisCommandTestBase {
|
public class HashesCommandsTest extends JedisCommandTestBase {
|
||||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||||
final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
|
final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
|
||||||
@@ -286,4 +289,43 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
|||||||
assertArrayEquals(bcar, bhash.get(bbar));
|
assertArrayEquals(bcar, bhash.get(bbar));
|
||||||
assertArrayEquals(bbar, bhash.get(bcar));
|
assertArrayEquals(bbar, bhash.get(bcar));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hscan() {
|
||||||
|
jedis.hset("foo", "b", "b");
|
||||||
|
jedis.hset("foo", "a", "a");
|
||||||
|
|
||||||
|
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo", 0);
|
||||||
|
|
||||||
|
assertEquals(0, result.getCursor());
|
||||||
|
assertFalse(result.getResult().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hscanMatch() {
|
||||||
|
ScanParams params = new ScanParams();
|
||||||
|
params.match("a*");
|
||||||
|
|
||||||
|
jedis.hset("foo", "b", "b");
|
||||||
|
jedis.hset("foo", "a", "a");
|
||||||
|
jedis.hset("foo", "aa", "aa");
|
||||||
|
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo", 0, params);
|
||||||
|
|
||||||
|
assertEquals(0, result.getCursor());
|
||||||
|
assertFalse(result.getResult().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hscanCount() {
|
||||||
|
ScanParams params = new ScanParams();
|
||||||
|
params.count(2);
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
jedis.hset("foo", "a" + i, "a" + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo", 0, params);
|
||||||
|
|
||||||
|
assertFalse(result.getResult().isEmpty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,14 @@ package redis.clients.jedis.tests.commands;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import redis.clients.jedis.ScanParams;
|
||||||
|
import redis.clients.jedis.ScanResult;
|
||||||
|
|
||||||
public class SetCommandsTest extends JedisCommandTestBase {
|
public class SetCommandsTest extends JedisCommandTestBase {
|
||||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||||
final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
|
final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
|
||||||
@@ -448,7 +452,40 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
bmember = jedis.srandmember(bbar);
|
bmember = jedis.srandmember(bbar);
|
||||||
assertNull(bmember);
|
assertNull(bmember);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sscan() {
|
||||||
|
jedis.sadd("foo", "a", "b");
|
||||||
|
|
||||||
|
ScanResult<String> result = jedis.sscan("foo", 0);
|
||||||
|
|
||||||
|
assertEquals(0, result.getCursor());
|
||||||
|
assertFalse(result.getResult().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sscanMatch() {
|
||||||
|
ScanParams params = new ScanParams();
|
||||||
|
params.match("a*");
|
||||||
|
|
||||||
|
jedis.sadd("foo", "b", "a", "aa");
|
||||||
|
ScanResult<String> result = jedis.sscan("foo", 0, params);
|
||||||
|
|
||||||
|
assertEquals(0, result.getCursor());
|
||||||
|
assertFalse(result.getResult().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sscanCount() {
|
||||||
|
ScanParams params = new ScanParams();
|
||||||
|
params.count(2);
|
||||||
|
|
||||||
|
jedis.sadd("foo", "a1", "a2", "a3", "a4", "a5");
|
||||||
|
|
||||||
|
ScanResult<String> result = jedis.sscan("foo", 0, params);
|
||||||
|
|
||||||
|
assertFalse(result.getResult().isEmpty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,8 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import redis.clients.jedis.ScanParams;
|
||||||
|
import redis.clients.jedis.ScanResult;
|
||||||
import redis.clients.jedis.Tuple;
|
import redis.clients.jedis.Tuple;
|
||||||
import redis.clients.jedis.ZParams;
|
import redis.clients.jedis.ZParams;
|
||||||
import redis.clients.util.SafeEncoder;
|
import redis.clients.util.SafeEncoder;
|
||||||
@@ -885,4 +887,46 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(1, t2.compareTo(t1));
|
assertEquals(1, t2.compareTo(t1));
|
||||||
assertEquals(0, t2.compareTo(t2));
|
assertEquals(0, t2.compareTo(t2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void zscan() {
|
||||||
|
jedis.zadd("foo", 1, "a");
|
||||||
|
jedis.zadd("foo", 2, "b");
|
||||||
|
|
||||||
|
ScanResult<Tuple> result = jedis.zscan("foo", 0);
|
||||||
|
|
||||||
|
assertEquals(0, result.getCursor());
|
||||||
|
assertFalse(result.getResult().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void zscanMatch() {
|
||||||
|
ScanParams params = new ScanParams();
|
||||||
|
params.match("a*");
|
||||||
|
|
||||||
|
jedis.zadd("foo", 2, "b");
|
||||||
|
jedis.zadd("foo", 1, "a");
|
||||||
|
jedis.zadd("foo", 11, "aa");
|
||||||
|
ScanResult<Tuple> result = jedis.zscan("foo", 0, params);
|
||||||
|
|
||||||
|
assertEquals(0, result.getCursor());
|
||||||
|
assertFalse(result.getResult().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void zscanCount() {
|
||||||
|
ScanParams params = new ScanParams();
|
||||||
|
params.count(2);
|
||||||
|
|
||||||
|
jedis.zadd("foo", 1, "a1");
|
||||||
|
jedis.zadd("foo", 2, "a2");
|
||||||
|
jedis.zadd("foo", 3, "a3");
|
||||||
|
jedis.zadd("foo", 4, "a4");
|
||||||
|
jedis.zadd("foo", 5, "a5");
|
||||||
|
|
||||||
|
ScanResult<Tuple> result = jedis.zscan("foo", 0, params);
|
||||||
|
|
||||||
|
assertFalse(result.getResult().isEmpty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user