Merge branch 'binaryAPI' of git://github.com/yaourt/jedis
Conflicts: src/main/java/redis/clients/jedis/Connection.java src/main/java/redis/clients/jedis/Jedis.java src/main/java/redis/clients/jedis/ShardedJedis.java
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -54,7 +54,7 @@
|
|||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.8.1</version>
|
<version>4.8.1</version>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<scope>compile</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
629
src/main/java/redis/clients/jedis/BinaryClient.java
Normal file
629
src/main/java/redis/clients/jedis/BinaryClient.java
Normal file
@@ -0,0 +1,629 @@
|
|||||||
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
import static redis.clients.jedis.Protocol.toByteArray;
|
||||||
|
import static redis.clients.jedis.Protocol.Command.*;
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.LIMIT;
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.NO;
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.ONE;
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.STORE;
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.WITHSCORES;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Protocol.Command;
|
||||||
|
import redis.clients.jedis.Protocol.Keyword;
|
||||||
|
|
||||||
|
public class BinaryClient extends Connection {
|
||||||
|
public enum LIST_POSITION {
|
||||||
|
BEFORE, AFTER;
|
||||||
|
public final byte[] raw;
|
||||||
|
|
||||||
|
private LIST_POSITION() {
|
||||||
|
raw = name().getBytes(Protocol.UTF8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isInMulti;
|
||||||
|
|
||||||
|
public boolean isInMulti() {
|
||||||
|
return isInMulti;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BinaryClient(final String host) {
|
||||||
|
super(host);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BinaryClient(final String host, final int port) {
|
||||||
|
super(host, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ping() {
|
||||||
|
sendCommand(PING);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(final byte[] key, final byte[] value) {
|
||||||
|
sendCommand(Command.SET, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void get(final byte[] key) {
|
||||||
|
sendCommand(Command.GET, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void quit() {
|
||||||
|
sendCommand(QUIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exists(final byte[] key) {
|
||||||
|
sendCommand(EXISTS, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void del(final byte[]... keys) {
|
||||||
|
sendCommand(DEL, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void type(final byte[] key) {
|
||||||
|
sendCommand(TYPE, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void flushDB() {
|
||||||
|
sendCommand(FLUSHDB);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keys(final byte[] pattern) {
|
||||||
|
sendCommand(KEYS, pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void randomKey() {
|
||||||
|
sendCommand(RANDOMKEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rename(final byte[] oldkey, final byte[] newkey) {
|
||||||
|
sendCommand(RENAME, oldkey, newkey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void renamenx(final byte[] oldkey, final byte[] newkey) {
|
||||||
|
sendCommand(RENAMENX, oldkey, newkey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dbSize() {
|
||||||
|
sendCommand(DBSIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void expire(final byte[] key, final int seconds) {
|
||||||
|
sendCommand(EXPIRE, key, toByteArray(seconds));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void expireAt(final byte[] key, final long unixTime) {
|
||||||
|
sendCommand(EXPIREAT, key, toByteArray(unixTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ttl(final byte[] key) {
|
||||||
|
sendCommand(TTL, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void select(final int index) {
|
||||||
|
sendCommand(SELECT, toByteArray(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void move(final byte[] key, final int dbIndex) {
|
||||||
|
sendCommand(MOVE, key, toByteArray(dbIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void flushAll() {
|
||||||
|
sendCommand(FLUSHALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getSet(final byte[] key, final byte[] value) {
|
||||||
|
sendCommand(GETSET, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mget(final byte[]... keys) {
|
||||||
|
sendCommand(MGET, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setnx(final byte[] key, final byte[] value) {
|
||||||
|
sendCommand(SETNX, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setex(final byte[] key, final int seconds, final byte[] value) {
|
||||||
|
sendCommand(SETEX, key, toByteArray(seconds), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mset(final byte[]... keysvalues) {
|
||||||
|
sendCommand(MSET, keysvalues);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void msetnx(final byte[]... keysvalues) {
|
||||||
|
sendCommand(MSETNX, keysvalues);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void decrBy(final byte[] key, final int integer) {
|
||||||
|
sendCommand(DECRBY, key, toByteArray(integer));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void decr(final byte[] key) {
|
||||||
|
sendCommand(DECR, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void incrBy(final byte[] key, final int integer) {
|
||||||
|
sendCommand(INCRBY, key, toByteArray(integer));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void incr(final byte[] key) {
|
||||||
|
sendCommand(INCR, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void append(final byte[] key, final byte[] value) {
|
||||||
|
sendCommand(APPEND, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void substr(final byte[] key, final int start, final int end) {
|
||||||
|
sendCommand(SUBSTR, key, toByteArray(start), toByteArray(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hset(final byte[] key, final byte[] field, final byte[] value) {
|
||||||
|
sendCommand(HSET, key, field, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hget(final byte[] key, final byte[] field) {
|
||||||
|
sendCommand(HGET, key, field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hsetnx(final byte[] key, final byte[] field, final byte[] value) {
|
||||||
|
sendCommand(HSETNX, key, field, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hmset(final byte[] key, final Map<byte[], byte[]> hash) {
|
||||||
|
final List<byte[]> params = new ArrayList<byte[]>();
|
||||||
|
params.add(key);
|
||||||
|
|
||||||
|
for (final byte[] field : hash.keySet()) {
|
||||||
|
params.add(field);
|
||||||
|
params.add(hash.get(field));
|
||||||
|
}
|
||||||
|
sendCommand(HMSET, params.toArray(new byte[params.size()][]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hmget(final byte[] key, final byte[]... fields) {
|
||||||
|
final byte[][] params = new byte[fields.length + 1][];
|
||||||
|
params[0] = key;
|
||||||
|
System.arraycopy(fields, 0, params, 1, fields.length);
|
||||||
|
sendCommand(HMGET, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hincrBy(final byte[] key, final byte[] field, final int value) {
|
||||||
|
sendCommand(HINCRBY, key, field, toByteArray(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hexists(final byte[] key, final byte[] field) {
|
||||||
|
sendCommand(HEXISTS, key, field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hdel(final byte[] key, final byte[] field) {
|
||||||
|
sendCommand(HDEL, key, field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hlen(final byte[] key) {
|
||||||
|
sendCommand(HLEN, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hkeys(final byte[] key) {
|
||||||
|
sendCommand(HKEYS, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hvals(final byte[] key) {
|
||||||
|
sendCommand(HVALS, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hgetAll(final byte[] key) {
|
||||||
|
sendCommand(HGETALL, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rpush(final byte[] key, final byte[] string) {
|
||||||
|
sendCommand(RPUSH, key, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lpush(final byte[] key, final byte[] string) {
|
||||||
|
sendCommand(LPUSH, key, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void llen(final byte[] key) {
|
||||||
|
sendCommand(LLEN, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lrange(final byte[] key, final int start, final int end) {
|
||||||
|
sendCommand(LRANGE, key, toByteArray(start), toByteArray(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ltrim(final byte[] key, final int start, final int end) {
|
||||||
|
sendCommand(LTRIM, key, toByteArray(start), toByteArray(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lindex(final byte[] key, final int index) {
|
||||||
|
sendCommand(LINDEX, key, toByteArray(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lset(final byte[] key, final int index, final byte[] value) {
|
||||||
|
sendCommand(LSET, key, toByteArray(index), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lrem(final byte[] key, int count, final byte[] value) {
|
||||||
|
sendCommand(LREM, key, toByteArray(count), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lpop(final byte[] key) {
|
||||||
|
sendCommand(LPOP, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rpop(final byte[] key) {
|
||||||
|
sendCommand(RPOP, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rpoplpush(final byte[] srckey, final byte[] dstkey) {
|
||||||
|
sendCommand(RPOPLPUSH, srckey, dstkey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sadd(final byte[] key, final byte[] member) {
|
||||||
|
sendCommand(SADD, key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void smembers(final byte[] key) {
|
||||||
|
sendCommand(SMEMBERS, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void srem(final byte[] key, final byte[] member) {
|
||||||
|
sendCommand(SREM, key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void spop(final byte[] key) {
|
||||||
|
sendCommand(SPOP, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void smove(final byte[] srckey, final byte[] dstkey,
|
||||||
|
final byte[] member) {
|
||||||
|
sendCommand(SMOVE, srckey, dstkey, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void scard(final byte[] key) {
|
||||||
|
sendCommand(SCARD, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sismember(final byte[] key, final byte[] member) {
|
||||||
|
sendCommand(SISMEMBER, key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sinter(final byte[]... keys) {
|
||||||
|
sendCommand(SINTER, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sinterstore(final byte[] dstkey, final byte[]... keys) {
|
||||||
|
final byte[][] params = new byte[keys.length + 1][];
|
||||||
|
params[0] = dstkey;
|
||||||
|
System.arraycopy(keys, 0, params, 1, keys.length);
|
||||||
|
sendCommand(SINTERSTORE, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sunion(final byte[]... keys) {
|
||||||
|
sendCommand(SUNION, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sunionstore(final byte[] dstkey, final byte[]... keys) {
|
||||||
|
byte[][] params = new byte[keys.length + 1][];
|
||||||
|
params[0] = dstkey;
|
||||||
|
System.arraycopy(keys, 0, params, 1, keys.length);
|
||||||
|
sendCommand(SUNIONSTORE, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sdiff(final byte[]... keys) {
|
||||||
|
sendCommand(SDIFF, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sdiffstore(final byte[] dstkey, final byte[]... keys) {
|
||||||
|
byte[][] params = new byte[keys.length + 1][];
|
||||||
|
params[0] = dstkey;
|
||||||
|
System.arraycopy(keys, 0, params, 1, keys.length);
|
||||||
|
sendCommand(SDIFFSTORE, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void srandmember(final byte[] key) {
|
||||||
|
sendCommand(SRANDMEMBER, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zadd(final byte[] key, final double score, final byte[] member) {
|
||||||
|
sendCommand(ZADD, key, toByteArray(score), member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrange(final byte[] key, final int start, final int end) {
|
||||||
|
sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrem(final byte[] key, final byte[] member) {
|
||||||
|
sendCommand(ZREM, key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zincrby(final byte[] key, final double score,
|
||||||
|
final byte[] member) {
|
||||||
|
sendCommand(ZINCRBY, key, toByteArray(score), member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrank(final byte[] key, final byte[] member) {
|
||||||
|
sendCommand(ZRANK, key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrevrank(final byte[] key, final byte[] member) {
|
||||||
|
sendCommand(ZREVRANK, key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrevrange(final byte[] key, final int start, final int end) {
|
||||||
|
sendCommand(ZREVRANGE, key, toByteArray(start), toByteArray(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrangeWithScores(final byte[] key, final int start,
|
||||||
|
final int end) {
|
||||||
|
sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end),
|
||||||
|
WITHSCORES.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrevrangeWithScores(final byte[] key, final int start,
|
||||||
|
final int end) {
|
||||||
|
sendCommand(ZREVRANGE, key, toByteArray(start), toByteArray(end),
|
||||||
|
WITHSCORES.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zcard(final byte[] key) {
|
||||||
|
sendCommand(ZCARD, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zscore(final byte[] key, final byte[] member) {
|
||||||
|
sendCommand(ZSCORE, key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void multi() {
|
||||||
|
sendCommand(MULTI);
|
||||||
|
isInMulti = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void discard() {
|
||||||
|
sendCommand(DISCARD);
|
||||||
|
isInMulti = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exec() {
|
||||||
|
sendCommand(EXEC);
|
||||||
|
isInMulti = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void watch(final byte[] key) {
|
||||||
|
sendCommand(WATCH, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unwatch() {
|
||||||
|
sendCommand(UNWATCH);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sort(final byte[] key) {
|
||||||
|
sendCommand(SORT, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sort(final byte[] key, final SortingParams sortingParameters) {
|
||||||
|
final List<byte[]> args = new ArrayList<byte[]>();
|
||||||
|
args.add(key);
|
||||||
|
args.addAll(sortingParameters.getParams());
|
||||||
|
sendCommand(SORT, args.toArray(new byte[args.size()][]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void blpop(final byte[][] args) {
|
||||||
|
sendCommand(BLPOP, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sort(final byte[] key, final SortingParams sortingParameters,
|
||||||
|
final byte[] dstkey) {
|
||||||
|
final List<byte[]> args = new ArrayList<byte[]>();
|
||||||
|
args.add(key);
|
||||||
|
args.addAll(sortingParameters.getParams());
|
||||||
|
args.add(STORE.raw);
|
||||||
|
args.add(dstkey);
|
||||||
|
sendCommand(SORT, args.toArray(new byte[args.size()][]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sort(final byte[] key, final byte[] dstkey) {
|
||||||
|
sendCommand(SORT, key, STORE.raw, dstkey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void brpop(final byte[][] args) {
|
||||||
|
sendCommand(BRPOP, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void auth(final String password) {
|
||||||
|
sendCommand(AUTH, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void subscribe(final String... channels) {
|
||||||
|
sendCommand(SUBSCRIBE, channels);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void publish(final String channel, final String message) {
|
||||||
|
sendCommand(PUBLISH, channel, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsubscribe() {
|
||||||
|
sendCommand(UNSUBSCRIBE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsubscribe(final String... channels) {
|
||||||
|
sendCommand(UNSUBSCRIBE, channels);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void psubscribe(final String[] patterns) {
|
||||||
|
sendCommand(PSUBSCRIBE, patterns);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void punsubscribe() {
|
||||||
|
sendCommand(PUNSUBSCRIBE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void punsubscribe(final String... patterns) {
|
||||||
|
sendCommand(PUNSUBSCRIBE, patterns);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zcount(final byte[] key, final double min, final double max) {
|
||||||
|
sendCommand(ZCOUNT, key, toByteArray(min), toByteArray(max));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrangeByScore(final byte[] key, final double min,
|
||||||
|
final double max) {
|
||||||
|
sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrangeByScore(final byte[] key, final byte[] min,
|
||||||
|
final byte[] max) {
|
||||||
|
sendCommand(ZRANGEBYSCORE, key, min, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrangeByScore(final byte[] key, final double min,
|
||||||
|
final double max, final int offset, int count) {
|
||||||
|
sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max),
|
||||||
|
LIMIT.raw, toByteArray(offset), toByteArray(count));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrangeByScoreWithScores(final byte[] key, final double min,
|
||||||
|
final double max) {
|
||||||
|
sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max),
|
||||||
|
WITHSCORES.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrangeByScoreWithScores(final byte[] key, final double min,
|
||||||
|
final double max, final int offset, final int count) {
|
||||||
|
sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max),
|
||||||
|
LIMIT.raw, toByteArray(offset), toByteArray(count),
|
||||||
|
WITHSCORES.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zremrangeByRank(final byte[] key, final int start, final int end) {
|
||||||
|
sendCommand(ZREMRANGEBYRANK, key, toByteArray(start), toByteArray(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zremrangeByScore(final byte[] key, final double start,
|
||||||
|
final double end) {
|
||||||
|
sendCommand(ZREMRANGEBYSCORE, key, toByteArray(start), toByteArray(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zunionstore(final byte[] dstkey, final byte[]... sets) {
|
||||||
|
final byte[][] params = new byte[sets.length + 2][];
|
||||||
|
params[0] = dstkey;
|
||||||
|
params[1] = toByteArray(sets.length);
|
||||||
|
System.arraycopy(sets, 0, params, 2, sets.length);
|
||||||
|
sendCommand(ZUNIONSTORE, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zunionstore(final byte[] dstkey, final ZParams params,
|
||||||
|
final byte[]... sets) {
|
||||||
|
final List<byte[]> args = new ArrayList<byte[]>();
|
||||||
|
args.add(dstkey);
|
||||||
|
args.add(Protocol.toByteArray(sets.length));
|
||||||
|
for (final byte[] set : sets) {
|
||||||
|
args.add(set);
|
||||||
|
}
|
||||||
|
args.addAll(params.getParams());
|
||||||
|
sendCommand(ZUNIONSTORE, args.toArray(new byte[args.size()][]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zinterstore(final byte[] dstkey, final byte[]... sets) {
|
||||||
|
final byte[][] params = new byte[sets.length + 2][];
|
||||||
|
params[0] = dstkey;
|
||||||
|
params[1] = Protocol.toByteArray(sets.length);
|
||||||
|
System.arraycopy(sets, 0, params, 2, sets.length);
|
||||||
|
sendCommand(ZINTERSTORE, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zinterstore(final byte[] dstkey, final ZParams params,
|
||||||
|
final byte[]... sets) {
|
||||||
|
final List<byte[]> args = new ArrayList<byte[]>();
|
||||||
|
args.add(dstkey);
|
||||||
|
args.add(Protocol.toByteArray(sets.length));
|
||||||
|
for (final byte[] set : sets) {
|
||||||
|
args.add(set);
|
||||||
|
}
|
||||||
|
args.addAll(params.getParams());
|
||||||
|
sendCommand(ZINTERSTORE, args.toArray(new byte[args.size()][]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
sendCommand(SAVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bgsave() {
|
||||||
|
sendCommand(BGSAVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bgrewriteaof() {
|
||||||
|
sendCommand(BGREWRITEAOF);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lastsave() {
|
||||||
|
sendCommand(LASTSAVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void shutdown() {
|
||||||
|
sendCommand(SHUTDOWN);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void info() {
|
||||||
|
sendCommand(INFO);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void monitor() {
|
||||||
|
sendCommand(MONITOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void slaveof(final String host, final int port) {
|
||||||
|
sendCommand(SLAVEOF, host, String.valueOf(port));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void slaveofNoOne() {
|
||||||
|
sendCommand(SLAVEOF, NO.raw, ONE.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void configGet(final String pattern) {
|
||||||
|
sendCommand(CONFIG, Keyword.GET.name(), pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void configSet(final String parameter, final String value) {
|
||||||
|
sendCommand(CONFIG, Keyword.SET.name(), parameter, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void strlen(final byte[] key) {
|
||||||
|
sendCommand(STRLEN, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sync() {
|
||||||
|
sendCommand(SYNC);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lpushx(final byte[] key, final byte[] string) {
|
||||||
|
sendCommand(LPUSHX, key, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void persist(final byte[] key) {
|
||||||
|
sendCommand(PERSIST, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rpushx(final byte[] key, final byte[] string) {
|
||||||
|
sendCommand(RPUSHX, key, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void echo(final byte[] string) {
|
||||||
|
sendCommand(ECHO, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void linsert(final byte[] key, final LIST_POSITION where,
|
||||||
|
final byte[] pivot, final byte[] value) {
|
||||||
|
sendCommand(LINSERT, key, where.raw, pivot, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void debug(final DebugParams params) {
|
||||||
|
sendCommand(DEBUG, params.getCommand());
|
||||||
|
}
|
||||||
|
}
|
||||||
2877
src/main/java/redis/clients/jedis/BinaryJedis.java
Normal file
2877
src/main/java/redis/clients/jedis/BinaryJedis.java
Normal file
File diff suppressed because it is too large
Load Diff
159
src/main/java/redis/clients/jedis/BinaryJedisCommands.java
Normal file
159
src/main/java/redis/clients/jedis/BinaryJedisCommands.java
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common interface for sharded and non-sharded BinaryJedis
|
||||||
|
*/
|
||||||
|
public interface BinaryJedisCommands {
|
||||||
|
String set(byte[] key, byte[] value);
|
||||||
|
|
||||||
|
byte[] get(byte[] key);
|
||||||
|
|
||||||
|
Integer exists(byte[] key);
|
||||||
|
|
||||||
|
String type(byte[] key);
|
||||||
|
|
||||||
|
Integer expire(byte[] key, int seconds);
|
||||||
|
|
||||||
|
Integer expireAt(byte[] key, long unixTime);
|
||||||
|
|
||||||
|
Integer ttl(byte[] key);
|
||||||
|
|
||||||
|
byte[] getSet(byte[] key, byte[] value);
|
||||||
|
|
||||||
|
Integer setnx(byte[] key, byte[] value);
|
||||||
|
|
||||||
|
String setex(byte[] key, int seconds, byte[] value);
|
||||||
|
|
||||||
|
Integer decrBy(byte[] key, int integer);
|
||||||
|
|
||||||
|
Integer decr(byte[] key);
|
||||||
|
|
||||||
|
Integer incrBy(byte[] key, int integer);
|
||||||
|
|
||||||
|
Integer incr(byte[] key);
|
||||||
|
|
||||||
|
Integer append(byte[] key, byte[] value);
|
||||||
|
|
||||||
|
byte[] substr(byte[] key, int start, int end);
|
||||||
|
|
||||||
|
Integer hset(byte[] key, byte[] field, byte[] value);
|
||||||
|
|
||||||
|
byte[] hget(byte[] key, byte[] field);
|
||||||
|
|
||||||
|
Integer hsetnx(byte[] key, byte[] field, byte[] value);
|
||||||
|
|
||||||
|
String hmset(byte[] key, Map<byte[], byte[]> hash);
|
||||||
|
|
||||||
|
List<byte[]> hmget(byte[] key, byte[]... fields);
|
||||||
|
|
||||||
|
Integer hincrBy(byte[] key, byte[] field, int value);
|
||||||
|
|
||||||
|
Integer hexists(byte[] key, byte[] field);
|
||||||
|
|
||||||
|
Integer hdel(byte[] key, byte[] field);
|
||||||
|
|
||||||
|
Integer hlen(byte[] key);
|
||||||
|
|
||||||
|
Set<byte[]> hkeys(byte[] key);
|
||||||
|
|
||||||
|
Collection<byte[]> hvals(byte[] key);
|
||||||
|
|
||||||
|
Map<byte[], byte[]> hgetAll(byte[] key);
|
||||||
|
|
||||||
|
Integer rpush(byte[] key, byte[] string);
|
||||||
|
|
||||||
|
Integer lpush(byte[] key, byte[] string);
|
||||||
|
|
||||||
|
Integer llen(byte[] key);
|
||||||
|
|
||||||
|
List<byte[]> lrange(byte[] key, int start, int end);
|
||||||
|
|
||||||
|
String ltrim(byte[] key, int start, int end);
|
||||||
|
|
||||||
|
byte[] lindex(byte[] key, int index);
|
||||||
|
|
||||||
|
String lset(byte[] key, int index, byte[] value);
|
||||||
|
|
||||||
|
Integer lrem(byte[] key, int count, byte[] value);
|
||||||
|
|
||||||
|
byte[] lpop(byte[] key);
|
||||||
|
|
||||||
|
byte[] rpop(byte[] key);
|
||||||
|
|
||||||
|
Integer sadd(byte[] key, byte[] member);
|
||||||
|
|
||||||
|
Set<byte[]> smembers(byte[] key);
|
||||||
|
|
||||||
|
Integer srem(byte[] key, byte[] member);
|
||||||
|
|
||||||
|
byte[] spop(byte[] key);
|
||||||
|
|
||||||
|
Integer scard(byte[] key);
|
||||||
|
|
||||||
|
Integer sismember(byte[] key, byte[] member);
|
||||||
|
|
||||||
|
byte[] srandmember(byte[] key);
|
||||||
|
|
||||||
|
Integer zadd(byte[] key, double score, byte[] member);
|
||||||
|
|
||||||
|
Set<byte[]> zrange(byte[] key, int start, int end);
|
||||||
|
|
||||||
|
Integer zrem(byte[] key, byte[] member);
|
||||||
|
|
||||||
|
Double zincrby(byte[] key, double score, byte[] member);
|
||||||
|
|
||||||
|
Integer zrank(byte[] key, byte[] member);
|
||||||
|
|
||||||
|
Integer zrevrank(byte[] key, byte[] member);
|
||||||
|
|
||||||
|
Set<byte[]> zrevrange(byte[] key, int start, int end);
|
||||||
|
|
||||||
|
Set<Tuple> zrangeWithScores(byte[] key, int start, int end);
|
||||||
|
|
||||||
|
Set<Tuple> zrevrangeWithScores(byte[] key, int start, int end);
|
||||||
|
|
||||||
|
Integer zcard(byte[] key);
|
||||||
|
|
||||||
|
Double zscore(byte[] key, byte[] member);
|
||||||
|
|
||||||
|
List<byte[]> sort(byte[] key);
|
||||||
|
|
||||||
|
List<byte[]> sort(byte[] key, SortingParams sortingParameters);
|
||||||
|
|
||||||
|
Integer zcount(byte[] key, double min, double max);
|
||||||
|
|
||||||
|
Set<byte[]> zrangeByScore(byte[] key, double min, double max);
|
||||||
|
|
||||||
|
Set<byte[]> zrangeByScore(
|
||||||
|
byte[] key,
|
||||||
|
double min,
|
||||||
|
double max,
|
||||||
|
int offset,
|
||||||
|
int count);
|
||||||
|
|
||||||
|
Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max);
|
||||||
|
|
||||||
|
Set<Tuple> zrangeByScoreWithScores(
|
||||||
|
byte[] key,
|
||||||
|
double min,
|
||||||
|
double max,
|
||||||
|
int offset,
|
||||||
|
int count);
|
||||||
|
|
||||||
|
Integer zremrangeByRank(byte[] key, int start, int end);
|
||||||
|
|
||||||
|
Integer zremrangeByScore(byte[] key, double start, double end);
|
||||||
|
|
||||||
|
Integer linsert(
|
||||||
|
byte[] key,
|
||||||
|
LIST_POSITION where,
|
||||||
|
byte[] pivot,
|
||||||
|
byte[] value);
|
||||||
|
}
|
||||||
381
src/main/java/redis/clients/jedis/BinaryShardedJedis.java
Normal file
381
src/main/java/redis/clients/jedis/BinaryShardedJedis.java
Normal file
@@ -0,0 +1,381 @@
|
|||||||
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||||
|
import redis.clients.util.Hashing;
|
||||||
|
import redis.clients.util.Sharded;
|
||||||
|
|
||||||
|
public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
|
||||||
|
implements BinaryJedisCommands {
|
||||||
|
public BinaryShardedJedis(List<JedisShardInfo> shards) {
|
||||||
|
super(shards);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BinaryShardedJedis(List<JedisShardInfo> shards, Hashing algo) {
|
||||||
|
super(shards, algo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BinaryShardedJedis(List<JedisShardInfo> shards, Pattern keyTagPattern) {
|
||||||
|
super(shards, keyTagPattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BinaryShardedJedis(List<JedisShardInfo> shards, Hashing algo,
|
||||||
|
Pattern keyTagPattern) {
|
||||||
|
super(shards, algo, keyTagPattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disconnect() throws IOException {
|
||||||
|
for (JedisShardInfo jedis : getAllShards()) {
|
||||||
|
jedis.getResource().disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Jedis create(JedisShardInfo shard) {
|
||||||
|
return new Jedis(shard);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String set(byte[] key, byte[] value) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.set(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] get(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer exists(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.exists(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String type(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.type(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer expire(byte[] key, int seconds) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.expire(key, seconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer expireAt(byte[] key, long unixTime) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.expireAt(key, unixTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer ttl(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.ttl(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getSet(byte[] key, byte[] value) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.getSet(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer setnx(byte[] key, byte[] value) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.setnx(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String setex(byte[] key, int seconds, byte[] value) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.setex(key, seconds, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer decrBy(byte[] key, int integer) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.decrBy(key, integer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer decr(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.decr(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer incrBy(byte[] key, int integer) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.incrBy(key, integer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer incr(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.incr(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer append(byte[] key, byte[] value) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.append(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] substr(byte[] key, int start, int end) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.substr(key, start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer hset(byte[] key, byte[] field, byte[] value) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.hset(key, field, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] hget(byte[] key, byte[] field) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.hget(key, field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer hsetnx(byte[] key, byte[] field, byte[] value) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.hsetnx(key, field, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hmset(byte[] key, Map<byte[], byte[]> hash) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.hmset(key, hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<byte[]> hmget(byte[] key, byte[]... fields) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.hmget(key, fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer hincrBy(byte[] key, byte[] field, int value) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.hincrBy(key, field, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer hexists(byte[] key, byte[] field) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.hexists(key, field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer hdel(byte[] key, byte[] field) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.hdel(key, field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer hlen(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.hlen(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<byte[]> hkeys(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.hkeys(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<byte[]> hvals(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.hvals(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<byte[], byte[]> hgetAll(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.hgetAll(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer rpush(byte[] key, byte[] string) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.rpush(key, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer lpush(byte[] key, byte[] string) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.lpush(key, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer llen(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.llen(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<byte[]> lrange(byte[] key, int start, int end) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.lrange(key, start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String ltrim(byte[] key, int start, int end) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.ltrim(key, start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] lindex(byte[] key, int index) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.lindex(key, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String lset(byte[] key, int index, byte[] value) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.lset(key, index, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer lrem(byte[] key, int count, byte[] value) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.lrem(key, count, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] lpop(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.lpop(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] rpop(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.rpop(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer sadd(byte[] key, byte[] member) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.sadd(key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<byte[]> smembers(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.smembers(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer srem(byte[] key, byte[] member) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.srem(key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] spop(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.spop(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer scard(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.scard(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer sismember(byte[] key, byte[] member) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.sismember(key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] srandmember(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.srandmember(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer zadd(byte[] key, double score, byte[] member) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zadd(key, score, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<byte[]> zrange(byte[] key, int start, int end) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zrange(key, start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer zrem(byte[] key, byte[] member) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zrem(key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double zincrby(byte[] key, double score, byte[] member) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zincrby(key, score, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer zrank(byte[] key, byte[] member) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zrank(key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer zrevrank(byte[] key, byte[] member) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zrevrank(key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<byte[]> zrevrange(byte[] key, int start, int end) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zrevrange(key, start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Tuple> zrangeWithScores(byte[] key, int start, int end) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zrangeWithScores(key, start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Tuple> zrevrangeWithScores(byte[] key, int start, int end) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zrevrangeWithScores(key, start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer zcard(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zcard(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double zscore(byte[] key, byte[] member) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zscore(key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<byte[]> sort(byte[] key) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.sort(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<byte[]> sort(byte[] key, SortingParams sortingParameters) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.sort(key, sortingParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer zcount(byte[] key, double min, double max) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zcount(key, min, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<byte[]> zrangeByScore(byte[] key, double min, double max) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zrangeByScore(key, min, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<byte[]> zrangeByScore(byte[] key, double min, double max,
|
||||||
|
int offset, int count) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zrangeByScore(key, min, max, offset, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zrangeByScoreWithScores(key, min, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min,
|
||||||
|
double max, int offset, int count) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer zremrangeByRank(byte[] key, int start, int end) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zremrangeByRank(key, start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer zremrangeByScore(byte[] key, double start, double end) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.zremrangeByScore(key, start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer linsert(byte[] key, LIST_POSITION where, byte[] pivot,
|
||||||
|
byte[] value) {
|
||||||
|
Jedis j = getShard(key);
|
||||||
|
return j.linsert(key, where, pivot, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Object> pipelined(ShardedJedisPipeline shardedJedisPipeline) {
|
||||||
|
shardedJedisPipeline.setShardedJedis(this);
|
||||||
|
shardedJedisPipeline.execute();
|
||||||
|
return shardedJedisPipeline.getResults();
|
||||||
|
}
|
||||||
|
}
|
||||||
430
src/main/java/redis/clients/jedis/BinaryTransaction.java
Normal file
430
src/main/java/redis/clients/jedis/BinaryTransaction.java
Normal file
@@ -0,0 +1,430 @@
|
|||||||
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class BinaryTransaction {
|
||||||
|
protected Client client = null;
|
||||||
|
|
||||||
|
public BinaryTransaction() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public BinaryTransaction(final Client client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String ping() {
|
||||||
|
client.ping();
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String set(final byte[] key, final byte[] value) {
|
||||||
|
client.set(key, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get(final byte[] key) {
|
||||||
|
client.get(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String exists(final byte[] key) {
|
||||||
|
client.exists(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String del(final byte[]... keys) {
|
||||||
|
client.del(keys);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String type(final byte[] key) {
|
||||||
|
client.type(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String flushDB() {
|
||||||
|
client.flushDB();
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String keys(final byte[] pattern) {
|
||||||
|
client.keys(pattern);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] randomBinaryKey() {
|
||||||
|
client.randomKey();
|
||||||
|
return client.getBinaryBulkReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String rename(final byte[] oldkey, final byte[] newkey) {
|
||||||
|
client.rename(oldkey, newkey);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String renamenx(final byte[] oldkey, final byte[] newkey) {
|
||||||
|
client.renamenx(oldkey, newkey);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String dbSize() {
|
||||||
|
client.dbSize();
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String expire(final byte[] key, final int seconds) {
|
||||||
|
client.expire(key, seconds);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String expireAt(final byte[] key, final long unixTime) {
|
||||||
|
client.expireAt(key, unixTime);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String ttl(final byte[] key) {
|
||||||
|
client.ttl(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String select(final int index) {
|
||||||
|
client.select(index);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String move(final byte[] key, final int dbIndex) {
|
||||||
|
client.move(key, dbIndex);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String flushAll() {
|
||||||
|
client.flushAll();
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSet(final byte[] key, final byte[] value) {
|
||||||
|
client.getSet(key, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String mget(final byte[]... keys) {
|
||||||
|
client.mget(keys);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String setnx(final byte[] key, final byte[] value) {
|
||||||
|
client.setnx(key, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String setex(final byte[] key, final int seconds, final byte[] value) {
|
||||||
|
client.setex(key, seconds, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String mset(final byte[]... keysvalues) {
|
||||||
|
client.mset(keysvalues);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String msetnx(final byte[]... keysvalues) {
|
||||||
|
client.msetnx(keysvalues);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String decrBy(final byte[] key, final int integer) {
|
||||||
|
client.decrBy(key, integer);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String decr(final byte[] key) {
|
||||||
|
client.decr(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String incrBy(final byte[] key, final int integer) {
|
||||||
|
client.incrBy(key, integer);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String incr(final byte[] key) {
|
||||||
|
client.incr(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String append(final byte[] key, final byte[] value) {
|
||||||
|
client.append(key, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String substr(final byte[] key, final int start, final int end) {
|
||||||
|
client.substr(key, start, end);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hset(final byte[] key, final byte[] field, final byte[] value) {
|
||||||
|
client.hset(key, field, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hget(final byte[] key, final byte[] field) {
|
||||||
|
client.hget(key, field);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hsetnx(final byte[] key, final byte[] field,
|
||||||
|
final byte[] value) {
|
||||||
|
client.hsetnx(key, field, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hmset(final byte[] key, final Map<byte[], byte[]> hash) {
|
||||||
|
client.hmset(key, hash);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hmget(final byte[] key, final byte[]... fields) {
|
||||||
|
client.hmget(key, fields);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hincrBy(final byte[] key, final byte[] field, final int value) {
|
||||||
|
client.hincrBy(key, field, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hexists(final byte[] key, final byte[] field) {
|
||||||
|
client.hexists(key, field);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hdel(final byte[] key, final byte[] field) {
|
||||||
|
client.hdel(key, field);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hlen(final byte[] key) {
|
||||||
|
client.hlen(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hkeys(final byte[] key) {
|
||||||
|
client.hkeys(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hvals(final byte[] key) {
|
||||||
|
client.hvals(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hgetAll(final byte[] key) {
|
||||||
|
client.hgetAll(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String rpush(final byte[] key, final byte[] string) {
|
||||||
|
client.rpush(key, string);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String lpush(final byte[] key, final byte[] string) {
|
||||||
|
client.lpush(key, string);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String llen(final byte[] key) {
|
||||||
|
client.llen(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String lrange(final byte[] key, final int start, final int end) {
|
||||||
|
client.lrange(key, start, end);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String ltrim(final byte[] key, final int start, final int end) {
|
||||||
|
client.ltrim(key, start, end);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String lindex(final byte[] key, final int index) {
|
||||||
|
client.lindex(key, index);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String lset(final byte[] key, final int index, final byte[] value) {
|
||||||
|
client.lset(key, index, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String lrem(final byte[] key, final int count, final byte[] value) {
|
||||||
|
client.lrem(key, count, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String lpop(final byte[] key) {
|
||||||
|
client.lpop(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String rpop(final byte[] key) {
|
||||||
|
client.rpop(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String rpoplpush(final byte[] srckey, final byte[] dstkey) {
|
||||||
|
client.rpoplpush(srckey, dstkey);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sadd(final byte[] key, final byte[] member) {
|
||||||
|
client.sadd(key, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String smembers(final byte[] key) {
|
||||||
|
client.smembers(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String srem(final byte[] key, final byte[] member) {
|
||||||
|
client.srem(key, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String spop(final byte[] key) {
|
||||||
|
client.spop(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String smove(final byte[] srckey, final byte[] dstkey,
|
||||||
|
final byte[] member) {
|
||||||
|
client.smove(srckey, dstkey, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String scard(final byte[] key) {
|
||||||
|
client.scard(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sismember(final byte[] key, final byte[] member) {
|
||||||
|
client.sismember(key, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sinter(final byte[]... keys) {
|
||||||
|
client.sinter(keys);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sinterstore(final byte[] dstkey, final byte[]... keys) {
|
||||||
|
client.sinterstore(dstkey, keys);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sunion(final byte[]... keys) {
|
||||||
|
client.sunion(keys);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sunionstore(final byte[] dstkey, final byte[]... keys) {
|
||||||
|
client.sunionstore(dstkey, keys);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sdiff(final byte[]... keys) {
|
||||||
|
client.sdiff(keys);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sdiffstore(final byte[] dstkey, final byte[]... keys) {
|
||||||
|
client.sdiffstore(dstkey, keys);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String srandmember(final byte[] key) {
|
||||||
|
client.srandmember(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zadd(final byte[] key, final double score, final byte[] member) {
|
||||||
|
client.zadd(key, score, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zrange(final byte[] key, final int start, final int end) {
|
||||||
|
client.zrange(key, start, end);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zrem(final byte[] key, final byte[] member) {
|
||||||
|
client.zrem(key, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zincrby(final byte[] key, final double score,
|
||||||
|
final byte[] member) {
|
||||||
|
client.zincrby(key, score, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zrank(final byte[] key, final byte[] member) {
|
||||||
|
client.zrank(key, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zrevrank(final byte[] key, final byte[] member) {
|
||||||
|
client.zrevrank(key, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zrevrange(final byte[] key, final int start, final int end) {
|
||||||
|
client.zrevrange(key, start, end);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zrangeWithScores(final byte[] key, final int start,
|
||||||
|
final int end) {
|
||||||
|
client.zrangeWithScores(key, start, end);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zrevrangeWithScores(final byte[] key, final int start,
|
||||||
|
final int end) {
|
||||||
|
client.zrevrangeWithScores(key, start, end);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zcard(final byte[] key) {
|
||||||
|
client.zcard(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zscore(final byte[] key, final byte[] member) {
|
||||||
|
client.zscore(key, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Object> exec() {
|
||||||
|
client.exec();
|
||||||
|
|
||||||
|
return client.getObjectMultiBulkReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sort(final byte[] key) {
|
||||||
|
client.sort(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sort(final byte[] key, final SortingParams sortingParameters) {
|
||||||
|
client.sort(key, sortingParameters);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void discard() {
|
||||||
|
client.discard();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,607 +1,502 @@
|
|||||||
package redis.clients.jedis;
|
package redis.clients.jedis;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
public class Client extends Connection {
|
public class Client extends BinaryClient {
|
||||||
public enum LIST_POSITION {
|
public Client(final String host) {
|
||||||
BEFORE, AFTER
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isInMulti;
|
|
||||||
|
|
||||||
public boolean isInMulti() {
|
|
||||||
return isInMulti;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Client(String host) {
|
|
||||||
super(host);
|
super(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Client(String host, int port) {
|
public Client(final String host, final int port) {
|
||||||
super(host, port);
|
super(host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ping() {
|
public void set(final String key, final String value) {
|
||||||
sendCommand("PING");
|
set(key.getBytes(Protocol.UTF8), value.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(String key, String value) {
|
public void get(final String key) {
|
||||||
sendCommand("SET", key, value);
|
get(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void get(String key) {
|
public void exists(final String key) {
|
||||||
sendCommand("GET", key);
|
exists(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void quit() {
|
public void del(final String... keys) {
|
||||||
sendCommand("QUIT");
|
final byte[][] bkeys = new byte[keys.length][];
|
||||||
|
for (int i = 0; i < keys.length; i++) {
|
||||||
|
bkeys[i] = keys[i].getBytes(Protocol.UTF8);
|
||||||
}
|
}
|
||||||
|
del(bkeys);
|
||||||
public void exists(String key) {
|
|
||||||
sendCommand("EXISTS", key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void del(String... keys) {
|
|
||||||
sendCommand("DEL", keys);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void type(String key) {
|
|
||||||
sendCommand("TYPE", key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void flushDB() {
|
|
||||||
sendCommand("FLUSHDB");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void keys(String pattern) {
|
|
||||||
sendCommand("KEYS", pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void randomKey() {
|
|
||||||
sendCommand("RANDOMKEY");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void rename(String oldkey, String newkey) {
|
|
||||||
sendCommand("RENAME", oldkey, newkey);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void renamenx(String oldkey, String newkey) {
|
|
||||||
sendCommand("RENAMENX", oldkey, newkey);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void dbSize() {
|
|
||||||
sendCommand("DBSIZE");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void expire(String key, int seconds) {
|
|
||||||
sendCommand("EXPIRE", key, String.valueOf(seconds));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void expireAt(String key, long unixTime) {
|
|
||||||
sendCommand("EXPIREAT", key, String.valueOf(unixTime));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ttl(String key) {
|
|
||||||
sendCommand("TTL", key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void select(int index) {
|
|
||||||
sendCommand("SELECT", String.valueOf(index));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void move(String key, int dbIndex) {
|
public void type(final String key) {
|
||||||
sendCommand("MOVE", key, String.valueOf(dbIndex));
|
type(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flushAll() {
|
public void keys(final String pattern) {
|
||||||
sendCommand("FLUSHALL");
|
keys(pattern.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getSet(String key, String value) {
|
public void rename(final String oldkey, final String newkey) {
|
||||||
sendCommand("GETSET", key, value);
|
rename(oldkey.getBytes(Protocol.UTF8), newkey.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mget(String... keys) {
|
public void renamenx(final String oldkey, final String newkey) {
|
||||||
sendCommand("MGET", keys);
|
renamenx(oldkey.getBytes(Protocol.UTF8), newkey.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setnx(String key, String value) {
|
public void expire(final String key, final int seconds) {
|
||||||
sendCommand("SETNX", key, value);
|
expire(key.getBytes(Protocol.UTF8), seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setex(String key, int seconds, String value) {
|
public void expireAt(final String key, final long unixTime) {
|
||||||
sendCommand("SETEX", key, String.valueOf(seconds), value);
|
expireAt(key.getBytes(Protocol.UTF8), unixTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mset(String... keysvalues) {
|
public void ttl(final String key) {
|
||||||
sendCommand("MSET", keysvalues);
|
ttl(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void msetnx(String... keysvalues) {
|
public void move(final String key, final int dbIndex) {
|
||||||
sendCommand("MSETNX", keysvalues);
|
move(key.getBytes(Protocol.UTF8), dbIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void decrBy(String key, int integer) {
|
public void getSet(final String key, final String value) {
|
||||||
sendCommand("DECRBY", key, String.valueOf(integer));
|
getSet(key.getBytes(Protocol.UTF8), value.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void decr(String key) {
|
public void mget(final String... keys) {
|
||||||
sendCommand("DECR", key);
|
final byte[][] bkeys = new byte[keys.length][];
|
||||||
|
for (int i = 0; i < bkeys.length; i++) {
|
||||||
|
bkeys[i] = keys[i].getBytes(Protocol.UTF8);
|
||||||
}
|
}
|
||||||
|
mget(bkeys);
|
||||||
public void incrBy(String key, int integer) {
|
|
||||||
sendCommand("INCRBY", key, String.valueOf(integer));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void incr(String key) {
|
public void setnx(final String key, final String value) {
|
||||||
sendCommand("INCR", key);
|
setnx(key.getBytes(Protocol.UTF8), value.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void append(String key, String value) {
|
public void setex(final String key, final int seconds, final String value) {
|
||||||
sendCommand("APPEND", key, value);
|
setex(key.getBytes(Protocol.UTF8), seconds, value
|
||||||
|
.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void substr(String key, int start, int end) {
|
public void mset(final String... keysvalues) {
|
||||||
sendCommand("SUBSTR", key, String.valueOf(start), String.valueOf(end));
|
final byte[][] bkeysvalues = new byte[keysvalues.length][];
|
||||||
|
for (int i = 0; i < keysvalues.length; i++) {
|
||||||
|
bkeysvalues[i] = keysvalues[i].getBytes(Protocol.UTF8);
|
||||||
}
|
}
|
||||||
|
mset(bkeysvalues);
|
||||||
public void hset(String key, String field, String value) {
|
|
||||||
sendCommand("HSET", key, field, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hget(String key, String field) {
|
public void msetnx(final String... keysvalues) {
|
||||||
sendCommand("HGET", key, field);
|
final byte[][] bkeysvalues = new byte[keysvalues.length][];
|
||||||
|
for (int i = 0; i < keysvalues.length; i++) {
|
||||||
|
bkeysvalues[i] = keysvalues[i].getBytes(Protocol.UTF8);
|
||||||
}
|
}
|
||||||
|
msetnx(bkeysvalues);
|
||||||
public void hsetnx(String key, String field, String value) {
|
|
||||||
sendCommand("HSETNX", key, field, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hmset(String key, Map<String, String> hash) {
|
public void decrBy(final String key, final int integer) {
|
||||||
List<String> params = new ArrayList<String>();
|
decrBy(key.getBytes(Protocol.UTF8), integer);
|
||||||
params.add(key);
|
|
||||||
|
|
||||||
for (String field : hash.keySet()) {
|
|
||||||
params.add(field);
|
|
||||||
params.add(hash.get(field));
|
|
||||||
}
|
|
||||||
sendCommand("HMSET", params.toArray(new String[params.size()]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hmget(String key, String... fields) {
|
public void decr(final String key) {
|
||||||
String[] params = new String[fields.length + 1];
|
decr(key.getBytes(Protocol.UTF8));
|
||||||
params[0] = key;
|
|
||||||
System.arraycopy(fields, 0, params, 1, fields.length);
|
|
||||||
sendCommand("HMGET", params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hincrBy(String key, String field, int value) {
|
public void incrBy(final String key, final int integer) {
|
||||||
sendCommand("HINCRBY", key, field, String.valueOf(value));
|
incrBy(key.getBytes(Protocol.UTF8), integer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hexists(String key, String field) {
|
public void incr(final String key) {
|
||||||
sendCommand("HEXISTS", key, field);
|
incr(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hdel(String key, String field) {
|
public void append(final String key, final String value) {
|
||||||
sendCommand("HDEL", key, field);
|
append(key.getBytes(Protocol.UTF8), value.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hlen(String key) {
|
public void substr(final String key, final int start, final int end) {
|
||||||
sendCommand("HLEN", key);
|
substr(key.getBytes(Protocol.UTF8), start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hkeys(String key) {
|
public void hset(final String key, final String field, final String value) {
|
||||||
sendCommand("HKEYS", key);
|
hset(key.getBytes(Protocol.UTF8), field.getBytes(Protocol.UTF8), value
|
||||||
|
.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hvals(String key) {
|
public void hget(final String key, final String field) {
|
||||||
sendCommand("HVALS", key);
|
hget(key.getBytes(Protocol.UTF8), field.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hgetAll(String key) {
|
public void hsetnx(final String key, final String field, final String value) {
|
||||||
sendCommand("HGETALL", key);
|
hsetnx(key.getBytes(Protocol.UTF8), field.getBytes(Protocol.UTF8),
|
||||||
|
value.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rpush(String key, String string) {
|
public void hmset(final String key, final Map<String, String> hash) {
|
||||||
sendCommand("RPUSH", key, string);
|
final Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>(hash
|
||||||
|
.size());
|
||||||
|
for (final Entry<String, String> entry : hash.entrySet()) {
|
||||||
|
bhash.put(entry.getKey().getBytes(Protocol.UTF8), entry.getValue()
|
||||||
|
.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
hmset(key.getBytes(Protocol.UTF8), bhash);
|
||||||
public void lpush(String key, String string) {
|
|
||||||
sendCommand("LPUSH", key, string);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void llen(String key) {
|
public void hmget(final String key, final String... fields) {
|
||||||
sendCommand("LLEN", key);
|
final byte[][] bfields = new byte[fields.length][];
|
||||||
|
for (int i = 0; i < bfields.length; i++) {
|
||||||
|
bfields[i] = fields[i].getBytes(Protocol.UTF8);
|
||||||
}
|
}
|
||||||
|
hmget(key.getBytes(Protocol.UTF8), bfields);
|
||||||
public void lrange(String key, int start, int end) {
|
|
||||||
sendCommand("LRANGE", key, String.valueOf(start), String.valueOf(end));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ltrim(String key, int start, int end) {
|
public void hincrBy(final String key, final String field, final int value) {
|
||||||
sendCommand("LTRIM", key, String.valueOf(start), String.valueOf(end));
|
hincrBy(key.getBytes(Protocol.UTF8), field.getBytes(Protocol.UTF8),
|
||||||
|
value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void lindex(String key, int index) {
|
public void hexists(final String key, final String field) {
|
||||||
sendCommand("LINDEX", key, String.valueOf(index));
|
hexists(key.getBytes(Protocol.UTF8), field.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void lset(String key, int index, String value) {
|
public void hdel(final String key, final String field) {
|
||||||
sendCommand("LSET", key, String.valueOf(index), value);
|
hdel(key.getBytes(Protocol.UTF8), field.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void lrem(String key, int count, String value) {
|
public void hlen(final String key) {
|
||||||
sendCommand("LREM", key, String.valueOf(count), value);
|
hlen(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void lpop(String key) {
|
public void hkeys(final String key) {
|
||||||
sendCommand("LPOP", key);
|
hkeys(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rpop(String key) {
|
public void hvals(final String key) {
|
||||||
sendCommand("RPOP", key);
|
hvals(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rpoplpush(String srckey, String dstkey) {
|
public void hgetAll(final String key) {
|
||||||
sendCommand("RPOPLPUSH", srckey, dstkey);
|
hgetAll(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sadd(String key, String member) {
|
public void rpush(final String key, final String string) {
|
||||||
sendCommand("SADD", key, member);
|
rpush(key.getBytes(Protocol.UTF8), string.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void smembers(String key) {
|
public void lpush(final String key, final String string) {
|
||||||
sendCommand("SMEMBERS", key);
|
lpush(key.getBytes(Protocol.UTF8), string.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void srem(String key, String member) {
|
public void llen(final String key) {
|
||||||
sendCommand("SREM", key, member);
|
llen(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void spop(String key) {
|
public void lrange(final String key, final int start, final int end) {
|
||||||
sendCommand("SPOP", key);
|
lrange(key.getBytes(Protocol.UTF8), start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void smove(String srckey, String dstkey, String member) {
|
public void ltrim(final String key, final int start, final int end) {
|
||||||
sendCommand("SMOVE", srckey, dstkey, member);
|
ltrim(key.getBytes(Protocol.UTF8), start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scard(String key) {
|
public void lindex(final String key, final int index) {
|
||||||
sendCommand("SCARD", key);
|
lindex(key.getBytes(Protocol.UTF8), index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sismember(String key, String member) {
|
public void lset(final String key, final int index, final String value) {
|
||||||
sendCommand("SISMEMBER", key, member);
|
lset(key.getBytes(Protocol.UTF8), index, value.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sinter(String... keys) {
|
public void lrem(final String key, int count, final String value) {
|
||||||
sendCommand("SINTER", keys);
|
lrem(key.getBytes(Protocol.UTF8), count, value.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sinterstore(String dstkey, String... keys) {
|
public void lpop(final String key) {
|
||||||
String[] params = new String[keys.length + 1];
|
lpop(key.getBytes(Protocol.UTF8));
|
||||||
params[0] = dstkey;
|
|
||||||
System.arraycopy(keys, 0, params, 1, keys.length);
|
|
||||||
sendCommand("SINTERSTORE", params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sunion(String... keys) {
|
public void rpop(final String key) {
|
||||||
sendCommand("SUNION", keys);
|
rpop(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sunionstore(String dstkey, String... keys) {
|
public void rpoplpush(final String srckey, final String dstkey) {
|
||||||
String[] params = new String[keys.length + 1];
|
rpoplpush(srckey.getBytes(Protocol.UTF8), dstkey
|
||||||
params[0] = dstkey;
|
.getBytes(Protocol.UTF8));
|
||||||
System.arraycopy(keys, 0, params, 1, keys.length);
|
|
||||||
sendCommand("SUNIONSTORE", params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sdiff(String... keys) {
|
public void sadd(final String key, final String member) {
|
||||||
sendCommand("SDIFF", keys);
|
sadd(key.getBytes(Protocol.UTF8), member.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sdiffstore(String dstkey, String... keys) {
|
public void smembers(final String key) {
|
||||||
String[] params = new String[keys.length + 1];
|
smembers(key.getBytes(Protocol.UTF8));
|
||||||
params[0] = dstkey;
|
|
||||||
System.arraycopy(keys, 0, params, 1, keys.length);
|
|
||||||
sendCommand("SDIFFSTORE", params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void srandmember(String key) {
|
public void srem(final String key, final String member) {
|
||||||
sendCommand("SRANDMEMBER", key);
|
srem(key.getBytes(Protocol.UTF8), member.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zadd(String key, double score, String member) {
|
public void spop(final String key) {
|
||||||
sendCommand("ZADD", key, String.valueOf(score), member);
|
spop(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zrange(String key, int start, int end) {
|
public void smove(final String srckey, final String dstkey,
|
||||||
sendCommand("ZRANGE", key, String.valueOf(start), String.valueOf(end));
|
final String member) {
|
||||||
|
smove(srckey.getBytes(Protocol.UTF8), dstkey.getBytes(Protocol.UTF8),
|
||||||
|
member.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zrem(String key, String member) {
|
public void scard(final String key) {
|
||||||
sendCommand("ZREM", key, member);
|
scard(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zincrby(String key, double score, String member) {
|
public void sismember(final String key, final String member) {
|
||||||
sendCommand("ZINCRBY", key, String.valueOf(score), member);
|
sismember(key.getBytes(Protocol.UTF8), member.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zrank(String key, String member) {
|
public void sinter(final String... keys) {
|
||||||
sendCommand("ZRANK", key, member);
|
final byte[][] bkeys = new byte[keys.length][];
|
||||||
|
for (int i = 0; i < bkeys.length; i++) {
|
||||||
|
bkeys[i] = keys[i].getBytes(Protocol.UTF8);
|
||||||
}
|
}
|
||||||
|
sinter(bkeys);
|
||||||
public void zrevrank(String key, String member) {
|
|
||||||
sendCommand("ZREVRANK", key, member);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zrevrange(String key, int start, int end) {
|
public void sinterstore(final String dstkey, final String... keys) {
|
||||||
sendCommand("ZREVRANGE", key, String.valueOf(start), String
|
final byte[][] bkeys = new byte[keys.length][];
|
||||||
.valueOf(end));
|
for (int i = 0; i < bkeys.length; i++) {
|
||||||
|
bkeys[i] = keys[i].getBytes(Protocol.UTF8);
|
||||||
}
|
}
|
||||||
|
sinterstore(dstkey.getBytes(Protocol.UTF8), bkeys);
|
||||||
public void zrangeWithScores(String key, int start, int end) {
|
|
||||||
sendCommand("ZRANGE", key, String.valueOf(start), String.valueOf(end),
|
|
||||||
"WITHSCORES");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zrevrangeWithScores(String key, int start, int end) {
|
public void sunion(final String... keys) {
|
||||||
sendCommand("ZREVRANGE", key, String.valueOf(start), String
|
final byte[][] bkeys = new byte[keys.length][];
|
||||||
.valueOf(end), "WITHSCORES");
|
for (int i = 0; i < bkeys.length; i++) {
|
||||||
|
bkeys[i] = keys[i].getBytes(Protocol.UTF8);
|
||||||
}
|
}
|
||||||
|
sunion(bkeys);
|
||||||
public void zcard(String key) {
|
|
||||||
sendCommand("ZCARD", key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zscore(String key, String member) {
|
public void sunionstore(final String dstkey, final String... keys) {
|
||||||
sendCommand("ZSCORE", key, member);
|
final byte[][] bkeys = new byte[keys.length][];
|
||||||
|
for (int i = 0; i < bkeys.length; i++) {
|
||||||
|
bkeys[i] = keys[i].getBytes(Protocol.UTF8);
|
||||||
}
|
}
|
||||||
|
sunionstore(dstkey.getBytes(Protocol.UTF8), bkeys);
|
||||||
public void multi() {
|
|
||||||
sendCommand("MULTI");
|
|
||||||
isInMulti = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void discard() {
|
public void sdiff(final String... keys) {
|
||||||
sendCommand("DISCARD");
|
final byte[][] bkeys = new byte[keys.length][];
|
||||||
isInMulti = false;
|
for (int i = 0; i < bkeys.length; i++) {
|
||||||
|
bkeys[i] = keys[i].getBytes(Protocol.UTF8);
|
||||||
}
|
}
|
||||||
|
sdiff(bkeys);
|
||||||
public void exec() {
|
|
||||||
sendCommand("EXEC");
|
|
||||||
isInMulti = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void watch(String key) {
|
public void sdiffstore(final String dstkey, final String... keys) {
|
||||||
sendCommand("WATCH", key);
|
final byte[][] bkeys = new byte[keys.length][];
|
||||||
|
for (int i = 0; i < bkeys.length; i++) {
|
||||||
|
bkeys[i] = keys[i].getBytes(Protocol.UTF8);
|
||||||
}
|
}
|
||||||
|
sdiffstore(dstkey.getBytes(Protocol.UTF8), bkeys);
|
||||||
public void unwatch() {
|
|
||||||
sendCommand("UNWATCH");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sort(String key) {
|
public void srandmember(final String key) {
|
||||||
sendCommand("SORT", key);
|
srandmember(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sort(String key, SortingParams sortingParameters) {
|
public void zadd(final String key, final double score, final String member) {
|
||||||
List<String> args = new ArrayList<String>();
|
zadd(key.getBytes(Protocol.UTF8), score, member.getBytes(Protocol.UTF8));
|
||||||
args.add(key);
|
|
||||||
args.addAll(sortingParameters.getParams());
|
|
||||||
sendCommand("SORT", args.toArray(new String[args.size()]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void blpop(String[] args) {
|
public void zrange(final String key, final int start, final int end) {
|
||||||
sendCommand("BLPOP", args);
|
zrange(key.getBytes(Protocol.UTF8), start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sort(String key, SortingParams sortingParameters, String dstkey) {
|
public void zrem(final String key, final String member) {
|
||||||
List<String> args = new ArrayList<String>();
|
zrem(key.getBytes(Protocol.UTF8), member.getBytes(Protocol.UTF8));
|
||||||
args.add(key);
|
|
||||||
args.addAll(sortingParameters.getParams());
|
|
||||||
args.add("STORE");
|
|
||||||
args.add(dstkey);
|
|
||||||
sendCommand("SORT", args.toArray(new String[args.size()]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sort(String key, String dstkey) {
|
public void zincrby(final String key, final double score,
|
||||||
sendCommand("SORT", key, "STORE", dstkey);
|
final String member) {
|
||||||
|
zincrby(key.getBytes(Protocol.UTF8), score, member
|
||||||
|
.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void brpop(String[] args) {
|
public void zrank(final String key, final String member) {
|
||||||
sendCommand("BRPOP", args);
|
zrank(key.getBytes(Protocol.UTF8), member.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void auth(String password) {
|
public void zrevrank(final String key, final String member) {
|
||||||
sendCommand("AUTH", password);
|
zrevrank(key.getBytes(Protocol.UTF8), member.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void subscribe(String... channels) {
|
public void zrevrange(final String key, final int start, final int end) {
|
||||||
sendCommand("SUBSCRIBE", channels);
|
zrevrange(key.getBytes(Protocol.UTF8), start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void publish(String channel, String message) {
|
public void zrangeWithScores(final String key, final int start,
|
||||||
sendCommand("PUBLISH", channel, message);
|
final int end) {
|
||||||
|
zrangeWithScores(key.getBytes(Protocol.UTF8), start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unsubscribe() {
|
public void zrevrangeWithScores(final String key, final int start,
|
||||||
sendCommand("UNSUBSCRIBE");
|
final int end) {
|
||||||
|
zrevrangeWithScores(key.getBytes(Protocol.UTF8), start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unsubscribe(String... channels) {
|
public void zcard(final String key) {
|
||||||
sendCommand("UNSUBSCRIBE", channels);
|
zcard(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void psubscribe(String[] patterns) {
|
public void zscore(final String key, final String member) {
|
||||||
sendCommand("PSUBSCRIBE", patterns);
|
zscore(key.getBytes(Protocol.UTF8), member.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void punsubscribe() {
|
public void watch(final String key) {
|
||||||
sendCommand("PUNSUBSCRIBE");
|
watch(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void punsubscribe(String... patterns) {
|
public void sort(final String key) {
|
||||||
sendCommand("PUNSUBSCRIBE", patterns);
|
sort(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zcount(String key, double min, double max) {
|
public void sort(final String key, final SortingParams sortingParameters) {
|
||||||
sendCommand("ZCOUNT", key, String.valueOf(min), String.valueOf(max));
|
sort(key.getBytes(Protocol.UTF8), sortingParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zrangeByScore(String key, double min, double max) {
|
public void blpop(final String[] args) {
|
||||||
sendCommand("ZRANGEBYSCORE", key, String.valueOf(min), String
|
final byte[][] bargs = new byte[args.length][];
|
||||||
.valueOf(max));
|
for (int i = 0; i < bargs.length; i++) {
|
||||||
|
bargs[i] = args[i].getBytes(Protocol.UTF8);
|
||||||
}
|
}
|
||||||
|
blpop(bargs);
|
||||||
public void zrangeByScore(String key, String min, String max) {
|
|
||||||
sendCommand("ZRANGEBYSCORE", key, min, max);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void zrangeByScore(String key, double min, double max, int offset,
|
|
||||||
int count) {
|
|
||||||
sendCommand("ZRANGEBYSCORE", key, String.valueOf(min), String
|
|
||||||
.valueOf(max), "LIMIT", String.valueOf(offset), String
|
|
||||||
.valueOf(count));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zrangeByScoreWithScores(String key, double min, double max) {
|
public void sort(final String key, final SortingParams sortingParameters,
|
||||||
sendCommand("ZRANGEBYSCORE", key, String.valueOf(min), String
|
final String dstkey) {
|
||||||
.valueOf(max), "WITHSCORES");
|
sort(key.getBytes(Protocol.UTF8), sortingParameters, dstkey
|
||||||
|
.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zrangeByScoreWithScores(String key, double min, double max,
|
public void sort(final String key, final String dstkey) {
|
||||||
int offset, int count) {
|
sort(key.getBytes(Protocol.UTF8), dstkey.getBytes(Protocol.UTF8));
|
||||||
sendCommand("ZRANGEBYSCORE", key, String.valueOf(min), String
|
|
||||||
.valueOf(max), "LIMIT", String.valueOf(offset), String
|
|
||||||
.valueOf(count), "WITHSCORES");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zremrangeByRank(String key, int start, int end) {
|
public void brpop(final String[] args) {
|
||||||
sendCommand("ZREMRANGEBYRANK", key, String.valueOf(start), String
|
final byte[][] bargs = new byte[args.length][];
|
||||||
.valueOf(end));
|
for (int i = 0; i < bargs.length; i++) {
|
||||||
|
bargs[i] = args[i].getBytes(Protocol.UTF8);
|
||||||
}
|
}
|
||||||
|
brpop(bargs);
|
||||||
public void zremrangeByScore(String key, double start, double end) {
|
|
||||||
sendCommand("ZREMRANGEBYSCORE", key, String.valueOf(start), String
|
|
||||||
.valueOf(end));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void zunionstore(String dstkey, String... sets) {
|
|
||||||
String[] params = new String[sets.length + 2];
|
|
||||||
params[0] = dstkey;
|
|
||||||
params[1] = String.valueOf(sets.length);
|
|
||||||
System.arraycopy(sets, 0, params, 2, sets.length);
|
|
||||||
sendCommand("ZUNIONSTORE", params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zunionstore(String dstkey, ZParams params, String... sets) {
|
public void zcount(final String key, final double min, final double max) {
|
||||||
List<String> args = new ArrayList<String>();
|
zcount(key.getBytes(Protocol.UTF8), min, max);
|
||||||
args.add(dstkey);
|
|
||||||
args.add(String.valueOf(sets.length));
|
|
||||||
for (String set : sets) {
|
|
||||||
args.add(set);
|
|
||||||
}
|
|
||||||
args.addAll(params.getParams());
|
|
||||||
sendCommand("ZUNIONSTORE", args.toArray(new String[args.size()]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zinterstore(String dstkey, String... sets) {
|
public void zrangeByScore(final String key, final double min,
|
||||||
String[] params = new String[sets.length + 2];
|
final double max) {
|
||||||
params[0] = dstkey;
|
zrangeByScore(key.getBytes(Protocol.UTF8), min, max);
|
||||||
params[1] = String.valueOf(sets.length);
|
|
||||||
System.arraycopy(sets, 0, params, 2, sets.length);
|
|
||||||
sendCommand("ZINTERSTORE", params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zinterstore(String dstkey, ZParams params, String... sets) {
|
public void zrangeByScore(final String key, final String min,
|
||||||
List<String> args = new ArrayList<String>();
|
final String max) {
|
||||||
args.add(dstkey);
|
zrangeByScore(key.getBytes(Protocol.UTF8), min.getBytes(Protocol.UTF8),
|
||||||
args.add(String.valueOf(sets.length));
|
max.getBytes(Protocol.UTF8));
|
||||||
for (String set : sets) {
|
|
||||||
args.add(set);
|
|
||||||
}
|
|
||||||
args.addAll(params.getParams());
|
|
||||||
sendCommand("ZINTERSTORE", args.toArray(new String[args.size()]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void zrangeByScore(final String key, final double min,
|
||||||
sendCommand("SAVE");
|
final double max, final int offset, int count) {
|
||||||
|
zrangeByScore(key.getBytes(Protocol.UTF8), min, max, offset, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bgsave() {
|
public void zrangeByScoreWithScores(final String key, final double min,
|
||||||
sendCommand("BGSAVE");
|
final double max) {
|
||||||
|
zrangeByScoreWithScores(key.getBytes(Protocol.UTF8), min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bgrewriteaof() {
|
public void zrangeByScoreWithScores(final String key, final double min,
|
||||||
sendCommand("BGREWRITEAOF");
|
final double max, final int offset, final int count) {
|
||||||
|
zrangeByScoreWithScores(key.getBytes(Protocol.UTF8), min, max, offset,
|
||||||
|
count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void lastsave() {
|
public void zremrangeByRank(final String key, final int start, final int end) {
|
||||||
sendCommand("LASTSAVE");
|
zremrangeByRank(key.getBytes(Protocol.UTF8), start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public void zremrangeByScore(final String key, final double start,
|
||||||
sendCommand("SHUTDOWN");
|
final double end) {
|
||||||
|
zremrangeByScore(key.getBytes(Protocol.UTF8), start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void info() {
|
public void zunionstore(final String dstkey, final String... sets) {
|
||||||
sendCommand("INFO");
|
final byte[][] bsets = new byte[sets.length][];
|
||||||
|
for (int i = 0; i < bsets.length; i++) {
|
||||||
|
bsets[i] = sets[i].getBytes(Protocol.UTF8);
|
||||||
}
|
}
|
||||||
|
zunionstore(dstkey.getBytes(Protocol.UTF8), bsets);
|
||||||
public void monitor() {
|
|
||||||
sendCommand("MONITOR");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void slaveof(String host, int port) {
|
public void zunionstore(final String dstkey, final ZParams params,
|
||||||
sendCommand("SLAVEOF", host, String.valueOf(port));
|
final String... sets) {
|
||||||
|
final byte[][] bsets = new byte[sets.length][];
|
||||||
|
for (int i = 0; i < bsets.length; i++) {
|
||||||
|
bsets[i] = sets[i].getBytes(Protocol.UTF8);
|
||||||
}
|
}
|
||||||
|
zunionstore(dstkey.getBytes(Protocol.UTF8), params, bsets);
|
||||||
public void slaveofNoOne() {
|
|
||||||
sendCommand("SLAVEOF", "no", "one");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void configGet(String pattern) {
|
public void zinterstore(final String dstkey, final String... sets) {
|
||||||
sendCommand("CONFIG", "GET", pattern);
|
final byte[][] bsets = new byte[sets.length][];
|
||||||
|
for (int i = 0; i < bsets.length; i++) {
|
||||||
|
bsets[i] = sets[i].getBytes(Protocol.UTF8);
|
||||||
}
|
}
|
||||||
|
zinterstore(dstkey.getBytes(Protocol.UTF8), bsets);
|
||||||
public void configSet(String parameter, String value) {
|
|
||||||
sendCommand("CONFIG", "SET", parameter, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void strlen(String key) {
|
public void zinterstore(final String dstkey, final ZParams params,
|
||||||
sendCommand("STRLEN", key);
|
final String... sets) {
|
||||||
|
final byte[][] bsets = new byte[sets.length][];
|
||||||
|
for (int i = 0; i < bsets.length; i++) {
|
||||||
|
bsets[i] = sets[i].getBytes(Protocol.UTF8);
|
||||||
}
|
}
|
||||||
|
zinterstore(dstkey.getBytes(Protocol.UTF8), params, bsets);
|
||||||
public void sync() {
|
|
||||||
sendCommand("SYNC");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void lpushx(String key, String string) {
|
public void strlen(final String key) {
|
||||||
sendCommand("LPUSHX", key, string);
|
strlen(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void persist(String key) {
|
public void lpushx(final String key, final String string) {
|
||||||
sendCommand("PERSIST", key);
|
lpushx(key.getBytes(Protocol.UTF8), string.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rpushx(String key, String string) {
|
public void persist(final String key) {
|
||||||
sendCommand("RPUSHX", key, string);
|
persist(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void echo(String string) {
|
public void rpushx(final String key, final String string) {
|
||||||
sendCommand("ECHO", string);
|
rpushx(key.getBytes(Protocol.UTF8), string.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void linsert(String key, LIST_POSITION where, String pivot,
|
public void echo(final String string) {
|
||||||
String value) {
|
echo(string.getBytes(Protocol.UTF8));
|
||||||
sendCommand("LINSERT", key, where.toString(), pivot, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void debug(DebugParams params) {
|
public void linsert(final String key, final LIST_POSITION where,
|
||||||
sendCommand("DEBUG", params.getCommand());
|
final String pivot, final String value) {
|
||||||
|
linsert(key.getBytes(Protocol.UTF8), where, pivot
|
||||||
|
.getBytes(Protocol.UTF8), value.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ import java.net.UnknownHostException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Protocol.Command;
|
||||||
import redis.clients.util.RedisInputStream;
|
import redis.clients.util.RedisInputStream;
|
||||||
import redis.clients.util.RedisOutputStream;
|
import redis.clients.util.RedisOutputStream;
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ public class Connection {
|
|||||||
return timeout;
|
return timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTimeout(int timeout) {
|
public void setTimeout(final int timeout) {
|
||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,18 +45,46 @@ public class Connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Connection(String host) {
|
public Connection(final String host) {
|
||||||
super();
|
super();
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Connection sendCommand(String name, String... args) {
|
protected Connection sendCommand(final Command cmd, final String... args) {
|
||||||
protocol.sendCommand(outputStream, name, args);
|
final byte[][] bargs = new byte[args.length][];
|
||||||
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
bargs[i] = args[i].getBytes(Protocol.UTF8);
|
||||||
|
}
|
||||||
|
return sendCommand(cmd, bargs);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Connection sendCommand(final Command cmd, final byte[]... args) {
|
||||||
|
try {
|
||||||
|
connect();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
throw new JedisException("Could not connect to redis-server", e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new JedisException("Could not connect to redis-server", e);
|
||||||
|
}
|
||||||
|
protocol.sendCommand(outputStream, cmd, args);
|
||||||
pipelinedCommands++;
|
pipelinedCommands++;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Connection(String host, int port) {
|
protected Connection sendCommand(final Command cmd) {
|
||||||
|
try {
|
||||||
|
connect();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
throw new JedisException("Could not connect to redis-server", e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new JedisException("Could not connect to redis-server", e);
|
||||||
|
}
|
||||||
|
protocol.sendCommand(outputStream, cmd, new byte[0][]);
|
||||||
|
pipelinedCommands++;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Connection(final String host, final int port) {
|
||||||
super();
|
super();
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
@@ -65,7 +94,7 @@ public class Connection {
|
|||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHost(String host) {
|
public void setHost(final String host) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +102,7 @@ public class Connection {
|
|||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPort(int port) {
|
public void setPort(final int port) {
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,12 +140,26 @@ public class Connection {
|
|||||||
|
|
||||||
protected String getStatusCodeReply() {
|
protected String getStatusCodeReply() {
|
||||||
pipelinedCommands--;
|
pipelinedCommands--;
|
||||||
return (String) protocol.read(inputStream);
|
final byte[] resp = (byte[]) protocol.read(inputStream);
|
||||||
|
if (null == resp) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return new String(resp, Protocol.UTF8);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBulkReply() {
|
public String getBulkReply() {
|
||||||
|
final byte[] result = getBinaryBulkReply();
|
||||||
|
if (null != result) {
|
||||||
|
return new String(result, Protocol.UTF8);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getBinaryBulkReply() {
|
||||||
pipelinedCommands--;
|
pipelinedCommands--;
|
||||||
return (String) protocol.read(inputStream);
|
return (byte[]) protocol.read(inputStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getIntegerReply() {
|
public Integer getIntegerReply() {
|
||||||
@@ -124,10 +167,26 @@ public class Connection {
|
|||||||
return (Integer) protocol.read(inputStream);
|
return (Integer) protocol.read(inputStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public List<String> getMultiBulkReply() {
|
public List<String> getMultiBulkReply() {
|
||||||
|
final List<byte[]> bresult = getBinaryMultiBulkReply();
|
||||||
|
if (null == bresult) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final ArrayList<String> result = new ArrayList<String>(bresult.size());
|
||||||
|
for (final byte[] barray : bresult) {
|
||||||
|
if (barray == null) {
|
||||||
|
result.add(null);
|
||||||
|
} else {
|
||||||
|
result.add(new String(barray, Protocol.UTF8));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public List<byte[]> getBinaryMultiBulkReply() {
|
||||||
pipelinedCommands--;
|
pipelinedCommands--;
|
||||||
return (List<String>) protocol.read(inputStream);
|
return (List<byte[]>) protocol.read(inputStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,6 @@
|
|||||||
package redis.clients.jedis;
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -58,9 +59,9 @@ public interface JedisCommands {
|
|||||||
|
|
||||||
Integer hlen(String key);
|
Integer hlen(String key);
|
||||||
|
|
||||||
List<String> hkeys(String key);
|
Set<String> hkeys(String key);
|
||||||
|
|
||||||
List<String> hvals(String key);
|
Collection<String> hvals(String key);
|
||||||
|
|
||||||
Map<String, String> hgetAll(String key);
|
Map<String, String> hgetAll(String key);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package redis.clients.jedis;
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.*;
|
||||||
|
|
||||||
public abstract class JedisPubSub {
|
public abstract class JedisPubSub {
|
||||||
private int subscribedChannels = 0;
|
private int subscribedChannels = 0;
|
||||||
private Client client;
|
private Client client;
|
||||||
@@ -62,26 +65,78 @@ public abstract class JedisPubSub {
|
|||||||
private void process(Client client) {
|
private void process(Client client) {
|
||||||
do {
|
do {
|
||||||
List<Object> reply = client.getObjectMultiBulkReply();
|
List<Object> reply = client.getObjectMultiBulkReply();
|
||||||
if (reply.get(0).equals("subscribe")) {
|
final Object firstObj = reply.get(0);
|
||||||
|
if (!(firstObj instanceof byte[])) {
|
||||||
|
throw
|
||||||
|
new JedisException("Unknown message type: "+ firstObj);
|
||||||
|
}
|
||||||
|
final byte[] resp = (byte[]) firstObj;
|
||||||
|
if(Arrays.equals(SUBSCRIBE.raw, resp)) {
|
||||||
subscribedChannels = ((Integer) reply.get(2)).intValue();
|
subscribedChannels = ((Integer) reply.get(2)).intValue();
|
||||||
onSubscribe((String) reply.get(1), subscribedChannels);
|
final byte[] bchannel = (byte[]) reply.get(1);
|
||||||
} else if (reply.get(0).equals("unsubscribe")) {
|
final String strchannel =
|
||||||
|
(bchannel == null) ?
|
||||||
|
null :
|
||||||
|
new String(bchannel, Protocol.UTF8);
|
||||||
|
onSubscribe(strchannel, subscribedChannels);
|
||||||
|
} else if (Arrays.equals(UNSUBSCRIBE.raw, resp)) {
|
||||||
subscribedChannels = ((Integer) reply.get(2)).intValue();
|
subscribedChannels = ((Integer) reply.get(2)).intValue();
|
||||||
onUnsubscribe((String) reply.get(1), subscribedChannels);
|
final byte[] bchannel = (byte[]) reply.get(1);
|
||||||
} else if (reply.get(0).equals("message")) {
|
final String strchannel =
|
||||||
onMessage((String) reply.get(1), (String) reply.get(2));
|
(bchannel == null) ?
|
||||||
} else if (reply.get(0).equals("pmessage")) {
|
null :
|
||||||
onPMessage((String) reply.get(1), (String) reply.get(2),
|
new String(bchannel, Protocol.UTF8);
|
||||||
(String) reply.get(3));
|
onUnsubscribe(strchannel, subscribedChannels);
|
||||||
} else if (reply.get(0).equals("psubscribe")) {
|
} else if (Arrays.equals(MESSAGE.raw, resp)) {
|
||||||
|
final byte[] bchannel = (byte[]) reply.get(1);
|
||||||
|
final byte[] bmesg = (byte[]) reply.get(2);
|
||||||
|
final String strchannel =
|
||||||
|
(bchannel == null) ?
|
||||||
|
null :
|
||||||
|
new String(bchannel, Protocol.UTF8);
|
||||||
|
final String strmesg =
|
||||||
|
(bmesg == null) ?
|
||||||
|
null :
|
||||||
|
new String(bmesg, Protocol.UTF8);
|
||||||
|
onMessage(strchannel, strmesg);
|
||||||
|
} else if (Arrays.equals(PMESSAGE.raw, resp)) {
|
||||||
|
final byte[] bpattern = (byte[]) reply.get(1);
|
||||||
|
final byte[] bchannel = (byte[]) reply.get(2);
|
||||||
|
final byte[] bmesg = (byte[]) reply.get(3);
|
||||||
|
final String strpattern =
|
||||||
|
(bpattern == null) ?
|
||||||
|
null :
|
||||||
|
new String(bpattern, Protocol.UTF8);
|
||||||
|
final String strchannel =
|
||||||
|
(bchannel == null) ?
|
||||||
|
null :
|
||||||
|
new String(bchannel, Protocol.UTF8);
|
||||||
|
final String strmesg =
|
||||||
|
(bmesg == null) ?
|
||||||
|
null :
|
||||||
|
new String(bmesg, Protocol.UTF8);
|
||||||
|
onPMessage(
|
||||||
|
strpattern,
|
||||||
|
strchannel,
|
||||||
|
strmesg);
|
||||||
|
} else if (Arrays.equals(PSUBSCRIBE.raw, resp)) {
|
||||||
subscribedChannels = ((Integer) reply.get(2)).intValue();
|
subscribedChannels = ((Integer) reply.get(2)).intValue();
|
||||||
onPSubscribe((String) reply.get(1), subscribedChannels);
|
final byte[] bpattern = (byte[]) reply.get(1);
|
||||||
} else if (reply.get(0).equals("punsubscribe")) {
|
final String strpattern =
|
||||||
|
(bpattern == null) ?
|
||||||
|
null :
|
||||||
|
new String(bpattern, Protocol.UTF8);
|
||||||
|
onPSubscribe(strpattern, subscribedChannels);
|
||||||
|
} else if (Arrays.equals(PUNSUBSCRIBE.raw, resp)) {
|
||||||
subscribedChannels = ((Integer) reply.get(2)).intValue();
|
subscribedChannels = ((Integer) reply.get(2)).intValue();
|
||||||
onPUnsubscribe((String) reply.get(1), subscribedChannels);
|
final byte[] bpattern = (byte[]) reply.get(1);
|
||||||
|
final String strpattern =
|
||||||
|
(bpattern == null) ?
|
||||||
|
null :
|
||||||
|
new String(bpattern, Protocol.UTF8);
|
||||||
|
onPUnsubscribe(strpattern, subscribedChannels);
|
||||||
} else {
|
} else {
|
||||||
throw new JedisException("Unknown message type: "
|
throw new JedisException("Unknown message type: "+ firstObj);
|
||||||
+ reply.get(0));
|
|
||||||
}
|
}
|
||||||
} while (isSubscribed());
|
} while (isSubscribed());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,41 +1,45 @@
|
|||||||
package redis.clients.jedis;
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import redis.clients.util.RedisInputStream;
|
import redis.clients.util.RedisInputStream;
|
||||||
import redis.clients.util.RedisOutputStream;
|
import redis.clients.util.RedisOutputStream;
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static redis.clients.util.RedisOutputStream.CHARSET;
|
|
||||||
|
|
||||||
public final class Protocol {
|
public final class Protocol {
|
||||||
|
|
||||||
public static final int DEFAULT_PORT = 6379;
|
public static final int DEFAULT_PORT = 6379;
|
||||||
|
|
||||||
|
public static final Charset UTF8 = Charset.forName("UTF-8");
|
||||||
|
|
||||||
public static final byte DOLLAR_BYTE = '$';
|
public static final byte DOLLAR_BYTE = '$';
|
||||||
public static final byte ASTERISK_BYTE = '*';
|
public static final byte ASTERISK_BYTE = '*';
|
||||||
public static final byte PLUS_BYTE = '+';
|
public static final byte PLUS_BYTE = '+';
|
||||||
public static final byte MINUS_BYTE = '-';
|
public static final byte MINUS_BYTE = '-';
|
||||||
public static final byte COLON_BYTE = ':';
|
public static final byte COLON_BYTE = ':';
|
||||||
|
|
||||||
public void sendCommand(RedisOutputStream os, String name, String... args) {
|
public void sendCommand(final RedisOutputStream os, final Command command,
|
||||||
|
final byte[]... args) {
|
||||||
|
sendCommand(os, command.raw, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendCommand(final RedisOutputStream os, final byte[] command,
|
||||||
|
final byte[]... args) {
|
||||||
try {
|
try {
|
||||||
os.write(ASTERISK_BYTE);
|
os.write(ASTERISK_BYTE);
|
||||||
os.writeIntCrLf(args.length + 1);
|
os.writeIntCrLf(args.length + 1);
|
||||||
os.write(DOLLAR_BYTE);
|
os.write(DOLLAR_BYTE);
|
||||||
os.writeIntCrLf(name.length());
|
os.writeIntCrLf(command.length);
|
||||||
os.writeAsciiCrLf(name);
|
os.write(command);
|
||||||
|
os.writeCrLf();
|
||||||
|
|
||||||
for (String str : args) {
|
for (final byte[] arg : args) {
|
||||||
os.write(DOLLAR_BYTE);
|
os.write(DOLLAR_BYTE);
|
||||||
final int size = RedisOutputStream.utf8Length(str);
|
os.writeIntCrLf(arg.length);
|
||||||
os.writeIntCrLf(size);
|
os.write(arg);
|
||||||
if (size == str.length())
|
os.writeCrLf();
|
||||||
os.writeAsciiCrLf(str);
|
|
||||||
else {
|
|
||||||
os.writeUtf8CrLf(str);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
os.flush();
|
os.flush();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -43,12 +47,12 @@ public final class Protocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processError(RedisInputStream is) {
|
private void processError(final RedisInputStream is) {
|
||||||
String message = is.readLine();
|
String message = is.readLine();
|
||||||
throw new JedisException(message);
|
throw new JedisException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object process(RedisInputStream is) {
|
private Object process(final RedisInputStream is) {
|
||||||
try {
|
try {
|
||||||
byte b = is.readByte();
|
byte b = is.readByte();
|
||||||
if (b == MINUS_BYTE) {
|
if (b == MINUS_BYTE) {
|
||||||
@@ -70,11 +74,11 @@ public final class Protocol {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String processStatusCodeReply(RedisInputStream is) {
|
private byte[] processStatusCodeReply(final RedisInputStream is) {
|
||||||
return is.readLine();
|
return is.readLine().getBytes(UTF8);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String processBulkReply(RedisInputStream is) {
|
private byte[] processBulkReply(final RedisInputStream is) {
|
||||||
int len = Integer.parseInt(is.readLine());
|
int len = Integer.parseInt(is.readLine());
|
||||||
if (len == -1) {
|
if (len == -1) {
|
||||||
return null;
|
return null;
|
||||||
@@ -92,15 +96,15 @@ public final class Protocol {
|
|||||||
throw new JedisException(e);
|
throw new JedisException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new String(read, CHARSET);
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Integer processInteger(RedisInputStream is) {
|
private Integer processInteger(final RedisInputStream is) {
|
||||||
String num = is.readLine();
|
String num = is.readLine();
|
||||||
return Integer.valueOf(num);
|
return Integer.valueOf(num);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Object> processMultiBulkReply(RedisInputStream is) {
|
private List<Object> processMultiBulkReply(final RedisInputStream is) {
|
||||||
int num = Integer.parseInt(is.readLine());
|
int num = Integer.parseInt(is.readLine());
|
||||||
if (num == -1) {
|
if (num == -1) {
|
||||||
return null;
|
return null;
|
||||||
@@ -112,7 +116,39 @@ public final class Protocol {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object read(RedisInputStream is) {
|
public Object read(final RedisInputStream is) {
|
||||||
return process(is);
|
return process(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final byte[] toByteArray(final int value) {
|
||||||
|
return String.valueOf(value).getBytes(Protocol.UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final byte[] toByteArray(final long value) {
|
||||||
|
return String.valueOf(value).getBytes(Protocol.UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final byte[] toByteArray(final double value) {
|
||||||
|
return String.valueOf(value).getBytes(Protocol.UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
|
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, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG;
|
||||||
|
|
||||||
|
public final byte[] raw;
|
||||||
|
|
||||||
|
Command() {
|
||||||
|
raw = this.name().getBytes(UTF8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
public final byte[] raw;
|
||||||
|
|
||||||
|
Keyword() {
|
||||||
|
raw = this.name().toLowerCase().getBytes(UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,16 @@
|
|||||||
package redis.clients.jedis;
|
package redis.clients.jedis;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import redis.clients.jedis.Client.LIST_POSITION;
|
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||||
import redis.clients.util.Hashing;
|
import redis.clients.util.Hashing;
|
||||||
import redis.clients.util.Sharded;
|
|
||||||
|
|
||||||
public class ShardedJedis extends Sharded<Jedis, JedisShardInfo> implements
|
public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||||
JedisCommands {
|
|
||||||
public ShardedJedis(List<JedisShardInfo> shards) {
|
public ShardedJedis(List<JedisShardInfo> shards) {
|
||||||
super(shards);
|
super(shards);
|
||||||
}
|
}
|
||||||
@@ -161,12 +160,12 @@ public class ShardedJedis extends Sharded<Jedis, JedisShardInfo> implements
|
|||||||
return j.hlen(key);
|
return j.hlen(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> hkeys(String key) {
|
public Set<String> hkeys(String key) {
|
||||||
Jedis j = getShard(key);
|
Jedis j = getShard(key);
|
||||||
return j.hkeys(key);
|
return j.hkeys(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> hvals(String key) {
|
public Collection<String> hvals(String key) {
|
||||||
Jedis j = getShard(key);
|
Jedis j = getShard(key);
|
||||||
return j.hvals(key);
|
return j.hvals(key);
|
||||||
}
|
}
|
||||||
@@ -368,10 +367,4 @@ public class ShardedJedis extends Sharded<Jedis, JedisShardInfo> implements
|
|||||||
Jedis j = getShard(key);
|
Jedis j = getShard(key);
|
||||||
return j.linsert(key, where, pivot, value);
|
return j.linsert(key, where, pivot, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Object> pipelined(ShardedJedisPipeline shardedJedisPipeline) {
|
|
||||||
shardedJedisPipeline.setShardedJedis(this);
|
|
||||||
shardedJedisPipeline.execute();
|
|
||||||
return shardedJedisPipeline.getResults();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import redis.clients.jedis.Client.LIST_POSITION;
|
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||||
|
|
||||||
public abstract class ShardedJedisPipeline {
|
public abstract class ShardedJedisPipeline {
|
||||||
private ShardedJedis jedis;
|
private BinaryShardedJedis jedis;
|
||||||
private List<FutureResult> results = new ArrayList<FutureResult>();
|
private List<FutureResult> results = new ArrayList<FutureResult>();
|
||||||
|
|
||||||
private class FutureResult {
|
private class FutureResult {
|
||||||
@@ -22,7 +22,7 @@ public abstract class ShardedJedisPipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShardedJedis(ShardedJedis jedis) {
|
public void setShardedJedis(BinaryShardedJedis jedis) {
|
||||||
this.jedis = jedis;
|
this.jedis = jedis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.*;
|
||||||
/**
|
/**
|
||||||
* Builder Class for {@link Jedis#sort(String, SortingParams) SORT} Parameters.
|
* Builder Class for {@link Jedis#sort(String, SortingParams) SORT} Parameters.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class SortingParams {
|
public class SortingParams {
|
||||||
private List<String> params = new ArrayList<String>();
|
private List<byte[]> params = new ArrayList<byte[]>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort by weight in keys.
|
* Sort by weight in keys.
|
||||||
@@ -25,8 +25,25 @@ public class SortingParams {
|
|||||||
* @param pattern
|
* @param pattern
|
||||||
* @return the SortingParams Object
|
* @return the SortingParams Object
|
||||||
*/
|
*/
|
||||||
public SortingParams by(String pattern) {
|
public SortingParams by(final String pattern) {
|
||||||
params.add("BY");
|
return by(pattern.getBytes(Protocol.UTF8));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort by weight in keys.
|
||||||
|
* <p>
|
||||||
|
* Takes a pattern that is used in order to generate the key names of the
|
||||||
|
* weights used for sorting. Weight key names are obtained substituting the
|
||||||
|
* first occurrence of * with the actual value of the elements on the list.
|
||||||
|
* <p>
|
||||||
|
* The pattern for a normal key/value pair is "keyname*" and for a value in
|
||||||
|
* a hash "keyname*->fieldname".
|
||||||
|
*
|
||||||
|
* @param pattern
|
||||||
|
* @return the SortingParams Object
|
||||||
|
*/
|
||||||
|
public SortingParams by(final byte[] pattern) {
|
||||||
|
params.add(BY.raw);
|
||||||
params.add(pattern);
|
params.add(pattern);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -40,11 +57,12 @@ public class SortingParams {
|
|||||||
* @return the SortingParams Object
|
* @return the SortingParams Object
|
||||||
*/
|
*/
|
||||||
public SortingParams nosort() {
|
public SortingParams nosort() {
|
||||||
params.add("BY nosort");
|
params.add(BY.raw);
|
||||||
|
params.add(NOSORT.raw);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<String> getParams() {
|
public Collection<byte[]> getParams() {
|
||||||
return Collections.unmodifiableCollection(params);
|
return Collections.unmodifiableCollection(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +72,7 @@ public class SortingParams {
|
|||||||
* @return the sortingParams Object
|
* @return the sortingParams Object
|
||||||
*/
|
*/
|
||||||
public SortingParams desc() {
|
public SortingParams desc() {
|
||||||
params.add("DESC");
|
params.add(DESC.raw);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +82,7 @@ public class SortingParams {
|
|||||||
* @return the SortingParams Object
|
* @return the SortingParams Object
|
||||||
*/
|
*/
|
||||||
public SortingParams asc() {
|
public SortingParams asc() {
|
||||||
params.add("ASC");
|
params.add(ASC.raw);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,10 +94,10 @@ public class SortingParams {
|
|||||||
* @param count
|
* @param count
|
||||||
* @return the SortingParams Object
|
* @return the SortingParams Object
|
||||||
*/
|
*/
|
||||||
public SortingParams limit(int start, int count) {
|
public SortingParams limit(final int start, final int count) {
|
||||||
params.add("LIMIT");
|
params.add(LIMIT.raw);
|
||||||
params.add(String.valueOf(start));
|
params.add(Protocol.toByteArray(start));
|
||||||
params.add(String.valueOf(count));
|
params.add(Protocol.toByteArray(count));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +108,7 @@ public class SortingParams {
|
|||||||
* @return the SortingParams Object
|
* @return the SortingParams Object
|
||||||
*/
|
*/
|
||||||
public SortingParams alpha() {
|
public SortingParams alpha() {
|
||||||
params.add("ALPHA");
|
params.add(ALPHA.raw);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,8 +128,31 @@ public class SortingParams {
|
|||||||
* @return the SortingParams Object
|
* @return the SortingParams Object
|
||||||
*/
|
*/
|
||||||
public SortingParams get(String... patterns) {
|
public SortingParams get(String... patterns) {
|
||||||
for (String pattern : patterns) {
|
for (final String pattern : patterns) {
|
||||||
params.add("GET");
|
params.add(GET.raw);
|
||||||
|
params.add(pattern.getBytes(Protocol.UTF8));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieving external keys from the result of the search.
|
||||||
|
* <p>
|
||||||
|
* Takes a pattern that is used in order to generate the key names of the
|
||||||
|
* result of sorting. The key names are obtained substituting the first
|
||||||
|
* occurrence of * with the actual value of the elements on the list.
|
||||||
|
* <p>
|
||||||
|
* The pattern for a normal key/value pair is "keyname*" and for a value in
|
||||||
|
* a hash "keyname*->fieldname".
|
||||||
|
* <p>
|
||||||
|
* To get the list itself use the char # as pattern.
|
||||||
|
*
|
||||||
|
* @param patterns
|
||||||
|
* @return the SortingParams Object
|
||||||
|
*/
|
||||||
|
public SortingParams get(byte[]... patterns) {
|
||||||
|
for (final byte[] pattern : patterns) {
|
||||||
|
params.add(GET.raw);
|
||||||
params.add(pattern);
|
params.add(pattern);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -1,425 +1,392 @@
|
|||||||
package redis.clients.jedis;
|
package redis.clients.jedis;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class Transaction {
|
public class Transaction extends BinaryTransaction {
|
||||||
protected Client client = null;
|
|
||||||
|
|
||||||
public Transaction() {
|
public Transaction() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Transaction(Client client) {
|
public Transaction(final Client client) {
|
||||||
this.client = client;
|
super(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String ping() {
|
public String set(final String key, final String value) {
|
||||||
client.ping();
|
|
||||||
return client.getStatusCodeReply();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String set(String key, String value) {
|
|
||||||
client.set(key, value);
|
client.set(key, value);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String get(String key) {
|
public String get(final String key) {
|
||||||
client.sendCommand("GET", key);
|
client.get(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String exists(String key) {
|
public String exists(final String key) {
|
||||||
client.exists(key);
|
client.exists(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String del(String... keys) {
|
public String del(final String... keys) {
|
||||||
client.del(keys);
|
client.del(keys);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String type(String key) {
|
public String type(final String key) {
|
||||||
client.type(key);
|
client.type(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String flushDB() {
|
public String keys(final String pattern) {
|
||||||
client.flushDB();
|
|
||||||
return client.getStatusCodeReply();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String keys(String pattern) {
|
|
||||||
client.keys(pattern);
|
client.keys(pattern);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String randomKey() {
|
public String randomKey() {
|
||||||
client.randomKey();
|
client.randomKey();
|
||||||
return client.getStatusCodeReply();
|
return client.getBulkReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String rename(String oldkey, String newkey) {
|
public String rename(final String oldkey, final String newkey) {
|
||||||
client.rename(oldkey, newkey);
|
client.rename(oldkey, newkey);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String renamenx(String oldkey, String newkey) {
|
public String renamenx(final String oldkey, final String newkey) {
|
||||||
client.renamenx(oldkey, newkey);
|
client.renamenx(oldkey, newkey);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String dbSize() {
|
public String expire(final String key, final int seconds) {
|
||||||
client.dbSize();
|
|
||||||
return client.getStatusCodeReply();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String expire(String key, int seconds) {
|
|
||||||
client.expire(key, seconds);
|
client.expire(key, seconds);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String expireAt(String key, long unixTime) {
|
public String expireAt(final String key, final long unixTime) {
|
||||||
client.expireAt(key, unixTime);
|
client.expireAt(key, unixTime);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String ttl(String key) {
|
public String ttl(final String key) {
|
||||||
client.ttl(key);
|
client.ttl(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String select(int index) {
|
public String move(final String key, final int dbIndex) {
|
||||||
client.select(index);
|
|
||||||
return client.getStatusCodeReply();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String move(String key, int dbIndex) {
|
|
||||||
client.move(key, dbIndex);
|
client.move(key, dbIndex);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String flushAll() {
|
public String getSet(final String key, final String value) {
|
||||||
client.flushAll();
|
|
||||||
return client.getStatusCodeReply();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSet(String key, String value) {
|
|
||||||
client.getSet(key, value);
|
client.getSet(key, value);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String mget(String... keys) {
|
public String mget(final String... keys) {
|
||||||
client.mget(keys);
|
client.mget(keys);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String setnx(String key, String value) {
|
public String setnx(final String key, final String value) {
|
||||||
client.setnx(key, value);
|
client.setnx(key, value);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String setex(String key, int seconds, String value) {
|
public String setex(final String key, final int seconds, final String value) {
|
||||||
client.setex(key, seconds, value);
|
client.setex(key, seconds, value);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String mset(String... keysvalues) {
|
public String mset(final String... keysvalues) {
|
||||||
client.mset(keysvalues);
|
client.mset(keysvalues);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String msetnx(String... keysvalues) {
|
public String msetnx(final String... keysvalues) {
|
||||||
client.msetnx(keysvalues);
|
client.msetnx(keysvalues);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String decrBy(String key, int integer) {
|
public String decrBy(final String key, final int integer) {
|
||||||
client.decrBy(key, integer);
|
client.decrBy(key, integer);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String decr(String key) {
|
public String decr(final String key) {
|
||||||
client.decr(key);
|
client.decr(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String incrBy(String key, int integer) {
|
public String incrBy(final String key, final int integer) {
|
||||||
client.incrBy(key, integer);
|
client.incrBy(key, integer);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String incr(String key) {
|
public String incr(final String key) {
|
||||||
client.incr(key);
|
client.incr(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String append(String key, String value) {
|
public String append(final String key, final String value) {
|
||||||
client.append(key, value);
|
client.append(key, value);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String substr(String key, int start, int end) {
|
public String substr(final String key, final int start, final int end) {
|
||||||
client.substr(key, start, end);
|
client.substr(key, start, end);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String hset(String key, String field, String value) {
|
public String hset(final String key, final String field, final String value) {
|
||||||
client.hset(key, field, value);
|
client.hset(key, field, value);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String hget(String key, String field) {
|
public String hget(final String key, final String field) {
|
||||||
client.hget(key, field);
|
client.hget(key, field);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String hsetnx(String key, String field, String value) {
|
public String hsetnx(final String key, final String field,
|
||||||
|
final String value) {
|
||||||
client.hsetnx(key, field, value);
|
client.hsetnx(key, field, value);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String hmset(String key, Map<String, String> hash) {
|
public String hmset(final String key, final Map<String, String> hash) {
|
||||||
client.hmset(key, hash);
|
client.hmset(key, hash);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String hmget(String key, String... fields) {
|
public String hmget(final String key, final String... fields) {
|
||||||
client.hmget(key, fields);
|
client.hmget(key, fields);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String hincrBy(String key, String field, int value) {
|
public String hincrBy(final String key, final String field, final int value) {
|
||||||
client.hincrBy(key, field, value);
|
client.hincrBy(key, field, value);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String hexists(String key, String field) {
|
public String hexists(final String key, final String field) {
|
||||||
client.hexists(key, field);
|
client.hexists(key, field);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String hdel(String key, String field) {
|
public String hdel(final String key, final String field) {
|
||||||
client.hdel(key, field);
|
client.hdel(key, field);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String hlen(String key) {
|
public String hlen(final String key) {
|
||||||
client.hlen(key);
|
client.hlen(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String hkeys(String key) {
|
public String hkeys(final String key) {
|
||||||
client.hkeys(key);
|
client.hkeys(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String hvals(String key) {
|
public String hvals(final String key) {
|
||||||
client.hvals(key);
|
client.hvals(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String hgetAll(String key) {
|
public String hgetAll(final String key) {
|
||||||
client.hgetAll(key);
|
client.hgetAll(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String rpush(String key, String string) {
|
public String rpush(final String key, final String string) {
|
||||||
client.rpush(key, string);
|
client.rpush(key, string);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String lpush(String key, String string) {
|
public String lpush(final String key, final String string) {
|
||||||
client.lpush(key, string);
|
client.lpush(key, string);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String llen(String key) {
|
public String llen(final String key) {
|
||||||
client.llen(key);
|
client.llen(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String lrange(String key, int start, int end) {
|
public String lrange(final String key, final int start, final int end) {
|
||||||
client.lrange(key, start, end);
|
client.lrange(key, start, end);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String ltrim(String key, int start, int end) {
|
public String ltrim(String key, final int start, final int end) {
|
||||||
client.ltrim(key, start, end);
|
client.ltrim(key, start, end);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String lindex(String key, int index) {
|
public String lindex(final String key, final int index) {
|
||||||
client.lindex(key, index);
|
client.lindex(key, index);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String lset(String key, int index, String value) {
|
public String lset(final String key, final int index, final String value) {
|
||||||
client.lset(key, index, value);
|
client.lset(key, index, value);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String lrem(String key, int count, String value) {
|
public String lrem(final String key, final int count, final String value) {
|
||||||
client.lrem(key, count, value);
|
client.lrem(key, count, value);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String lpop(String key) {
|
public String lpop(final String key) {
|
||||||
client.lpop(key);
|
client.lpop(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String rpop(String key) {
|
public String rpop(final String key) {
|
||||||
client.rpop(key);
|
client.rpop(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String rpoplpush(String srckey, String dstkey) {
|
public String rpoplpush(final String srckey, final String dstkey) {
|
||||||
client.rpoplpush(srckey, dstkey);
|
client.rpoplpush(srckey, dstkey);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sadd(String key, String member) {
|
public String sadd(final String key, final String member) {
|
||||||
client.sadd(key, member);
|
client.sadd(key, member);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String smembers(String key) {
|
public String smembers(final String key) {
|
||||||
client.smembers(key);
|
client.smembers(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String srem(String key, String member) {
|
public String srem(final String key, final String member) {
|
||||||
client.srem(key, member);
|
client.srem(key, member);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String spop(String key) {
|
public String spop(final String key) {
|
||||||
client.spop(key);
|
client.spop(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String smove(String srckey, String dstkey, String member) {
|
public String smove(final String srckey, final String dstkey,
|
||||||
|
final String member) {
|
||||||
client.smove(srckey, dstkey, member);
|
client.smove(srckey, dstkey, member);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String scard(String key) {
|
public String scard(final String key) {
|
||||||
client.scard(key);
|
client.scard(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sismember(String key, String member) {
|
public String sismember(final String key, final String member) {
|
||||||
client.sismember(key, member);
|
client.sismember(key, member);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sinter(String... keys) {
|
public String sinter(final String... keys) {
|
||||||
client.sinter(keys);
|
client.sinter(keys);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sinterstore(String dstkey, String... keys) {
|
public String sinterstore(final String dstkey, final String... keys) {
|
||||||
client.sinterstore(dstkey, keys);
|
client.sinterstore(dstkey, keys);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sunion(String... keys) {
|
public String sunion(final String... keys) {
|
||||||
client.sunion(keys);
|
client.sunion(keys);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sunionstore(String dstkey, String... keys) {
|
public String sunionstore(final String dstkey, final String... keys) {
|
||||||
client.sunionstore(dstkey, keys);
|
client.sunionstore(dstkey, keys);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sdiff(String... keys) {
|
public String sdiff(final String... keys) {
|
||||||
client.sdiff(keys);
|
client.sdiff(keys);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sdiffstore(String dstkey, String... keys) {
|
public String sdiffstore(final String dstkey, final String... keys) {
|
||||||
client.sdiffstore(dstkey, keys);
|
client.sdiffstore(dstkey, keys);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String srandmember(String key) {
|
public String srandmember(final String key) {
|
||||||
client.srandmember(key);
|
client.srandmember(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String zadd(String key, double score, String member) {
|
public String zadd(final String key, final double score, final String member) {
|
||||||
client.zadd(key, score, member);
|
client.zadd(key, score, member);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String zrange(String key, int start, int end) {
|
public String zrange(final String key, final int start, final int end) {
|
||||||
client.zrange(key, start, end);
|
client.zrange(key, start, end);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String zrem(String key, String member) {
|
public String zrem(final String key, final String member) {
|
||||||
client.zrem(key, member);
|
client.zrem(key, member);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String zincrby(String key, double score, String member) {
|
public String zincrby(final String key, final double score,
|
||||||
|
final String member) {
|
||||||
client.zincrby(key, score, member);
|
client.zincrby(key, score, member);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String zrank(String key, String member) {
|
public String zrank(final String key, final String member) {
|
||||||
client.zrank(key, member);
|
client.zrank(key, member);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String zrevrank(String key, String member) {
|
public String zrevrank(final String key, final String member) {
|
||||||
client.zrevrank(key, member);
|
client.zrevrank(key, member);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String zrevrange(String key, int start, int end) {
|
public String zrevrange(final String key, final int start, final int end) {
|
||||||
client.zrevrange(key, start, end);
|
client.zrevrange(key, start, end);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String zrangeWithScores(String key, int start, int end) {
|
public String zrangeWithScores(final String key, final int start,
|
||||||
|
final int end) {
|
||||||
client.zrangeWithScores(key, start, end);
|
client.zrangeWithScores(key, start, end);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String zrevrangeWithScores(String key, int start, int end) {
|
public String zrevrangeWithScores(final String key, final int start,
|
||||||
|
final int end) {
|
||||||
client.zrevrangeWithScores(key, start, end);
|
client.zrevrangeWithScores(key, start, end);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String zcard(String key) {
|
public String zcard(final String key) {
|
||||||
client.zcard(key);
|
client.zcard(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String zscore(String key, String member) {
|
public String zscore(final String key, final String member) {
|
||||||
client.zscore(key, member);
|
client.zscore(key, member);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Object> exec() {
|
public String sort(final String key) {
|
||||||
client.exec();
|
|
||||||
|
|
||||||
return client.getObjectMultiBulkReply();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String sort(String key) {
|
|
||||||
client.sort(key);
|
client.sort(key);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sort(String key, SortingParams sortingParameters) {
|
public String sort(final String key, final SortingParams sortingParameters) {
|
||||||
client.sort(key, sortingParameters);
|
client.sort(key, sortingParameters);
|
||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void discard() {
|
|
||||||
client.discard();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,21 @@
|
|||||||
package redis.clients.jedis;
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class Tuple {
|
public class Tuple {
|
||||||
private String element;
|
private byte[] element;
|
||||||
private Double score;
|
private Double score;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + ((element == null) ? 0 : element.hashCode());
|
result = prime * result;
|
||||||
|
if (null != element) {
|
||||||
|
for(final byte b : element) {
|
||||||
|
result = prime * result + b;
|
||||||
|
}
|
||||||
|
}
|
||||||
long temp;
|
long temp;
|
||||||
temp = Double.doubleToLongBits(score);
|
temp = Double.doubleToLongBits(score);
|
||||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||||
@@ -27,7 +34,7 @@ public class Tuple {
|
|||||||
if (element == null) {
|
if (element == null) {
|
||||||
if (other.element != null)
|
if (other.element != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!element.equals(other.element))
|
} else if (!Arrays.equals(element, other.element))
|
||||||
return false;
|
return false;
|
||||||
if (Double.doubleToLongBits(score) != Double
|
if (Double.doubleToLongBits(score) != Double
|
||||||
.doubleToLongBits(other.score))
|
.doubleToLongBits(other.score))
|
||||||
@@ -36,16 +43,34 @@ public class Tuple {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Tuple(String element, Double score) {
|
public Tuple(String element, Double score) {
|
||||||
|
super();
|
||||||
|
this.element = element.getBytes(Protocol.UTF8);
|
||||||
|
this.score = score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tuple(byte[] element, Double score) {
|
||||||
super();
|
super();
|
||||||
this.element = element;
|
this.element = element;
|
||||||
this.score = score;
|
this.score = score;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getElement() {
|
public String getElement() {
|
||||||
|
if(null != element) {
|
||||||
|
return new String(element, Protocol.UTF8);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getBinaryElement() {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getScore() {
|
public double getScore() {
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return '['+Arrays.toString(element)+','+score+']';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,29 +5,36 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.*;
|
||||||
|
|
||||||
public class ZParams {
|
public class ZParams {
|
||||||
public enum Aggregate {
|
public enum Aggregate {
|
||||||
SUM, MIN, MAX
|
SUM, MIN, MAX;
|
||||||
|
|
||||||
|
public final byte[] raw;
|
||||||
|
Aggregate() {
|
||||||
|
raw = name().getBytes(Protocol.UTF8);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> params = new ArrayList<String>();
|
private List<byte[]> params = new ArrayList<byte[]>();
|
||||||
|
|
||||||
public ZParams weights(int... weights) {
|
public ZParams weights(final int... weights) {
|
||||||
params.add("WEIGHTS");
|
params.add(WEIGHTS.raw);
|
||||||
for (int weight : weights) {
|
for (final int weight : weights) {
|
||||||
params.add(String.valueOf(weight));
|
params.add(Protocol.toByteArray(weight));
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<String> getParams() {
|
public Collection<byte[]> getParams() {
|
||||||
return Collections.unmodifiableCollection(params);
|
return Collections.unmodifiableCollection(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZParams aggregate(Aggregate aggregate) {
|
public ZParams aggregate(final Aggregate aggregate) {
|
||||||
params.add("AGGREGATE");
|
params.add(AGGREGATE.raw);
|
||||||
params.add(aggregate.name());
|
params.add(aggregate.raw);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package redis.clients.util;
|
|||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Protocol;
|
||||||
|
|
||||||
public interface Hashing {
|
public interface Hashing {
|
||||||
public static final Hashing MURMUR_HASH = new MurmurHash();
|
public static final Hashing MURMUR_HASH = new MurmurHash();
|
||||||
|
|
||||||
@@ -10,6 +12,10 @@ public interface Hashing {
|
|||||||
private MessageDigest md5 = null; // avoid recurring construction
|
private MessageDigest md5 = null; // avoid recurring construction
|
||||||
|
|
||||||
public long hash(String key) {
|
public long hash(String key) {
|
||||||
|
return hash(key.getBytes(Protocol.UTF8));
|
||||||
|
}
|
||||||
|
|
||||||
|
public long hash(byte[] key) {
|
||||||
if (md5 == null) {
|
if (md5 == null) {
|
||||||
try {
|
try {
|
||||||
md5 = MessageDigest.getInstance("MD5");
|
md5 = MessageDigest.getInstance("MD5");
|
||||||
@@ -20,7 +26,7 @@ public interface Hashing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
md5.reset();
|
md5.reset();
|
||||||
md5.update(key.getBytes());
|
md5.update(key);
|
||||||
byte[] bKey = md5.digest();
|
byte[] bKey = md5.digest();
|
||||||
long res = ((long) (bKey[3] & 0xFF) << 24)
|
long res = ((long) (bKey[3] & 0xFF) << 24)
|
||||||
| ((long) (bKey[2] & 0xFF) << 16)
|
| ((long) (bKey[2] & 0xFF) << 16)
|
||||||
@@ -30,4 +36,5 @@ public interface Hashing {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public long hash(String key);
|
public long hash(String key);
|
||||||
|
public long hash(byte[] key);
|
||||||
}
|
}
|
||||||
148
src/main/java/redis/clients/util/JedisByteHashMap.java
Normal file
148
src/main/java/redis/clients/util/JedisByteHashMap.java
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
package redis.clients.util;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class JedisByteHashMap implements Map<byte[], byte[]>, Cloneable,
|
||||||
|
Serializable {
|
||||||
|
private static final long serialVersionUID = -6971431362627219416L;
|
||||||
|
private Map<ByteArrayWrapper, byte[]> internalMap = new HashMap<ByteArrayWrapper, byte[]>();
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
internalMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsKey(Object key) {
|
||||||
|
if (key instanceof byte[])
|
||||||
|
return internalMap.containsKey(new ByteArrayWrapper((byte[]) key));
|
||||||
|
return internalMap.containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsValue(Object value) {
|
||||||
|
return internalMap.containsValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<java.util.Map.Entry<byte[], byte[]>> entrySet() {
|
||||||
|
Iterator<java.util.Map.Entry<ByteArrayWrapper, byte[]>> iterator = internalMap
|
||||||
|
.entrySet().iterator();
|
||||||
|
HashSet<Entry<byte[], byte[]>> hashSet = new HashSet<java.util.Map.Entry<byte[], byte[]>>();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Entry<ByteArrayWrapper, byte[]> entry = iterator.next();
|
||||||
|
hashSet.add(new JedisByteEntry(entry.getKey().data, entry
|
||||||
|
.getValue()));
|
||||||
|
}
|
||||||
|
return hashSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] get(Object key) {
|
||||||
|
if (key instanceof byte[])
|
||||||
|
return internalMap.get(new ByteArrayWrapper((byte[]) key));
|
||||||
|
return internalMap.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return internalMap.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<byte[]> keySet() {
|
||||||
|
Set<byte[]> keySet = new HashSet<byte[]>();
|
||||||
|
Iterator<ByteArrayWrapper> iterator = internalMap.keySet().iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
keySet.add(iterator.next().data);
|
||||||
|
}
|
||||||
|
return keySet;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] put(byte[] key, byte[] value) {
|
||||||
|
return internalMap.put(new ByteArrayWrapper(key), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void putAll(Map<? extends byte[], ? extends byte[]> m) {
|
||||||
|
Iterator<?> iterator = m.entrySet().iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Entry<? extends byte[], ? extends byte[]> next = (Entry<? extends byte[], ? extends byte[]>) iterator
|
||||||
|
.next();
|
||||||
|
internalMap.put(new ByteArrayWrapper(next.getKey()), next
|
||||||
|
.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] remove(Object key) {
|
||||||
|
if (key instanceof byte[])
|
||||||
|
return internalMap.remove(new ByteArrayWrapper((byte[]) key));
|
||||||
|
return internalMap.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return internalMap.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<byte[]> values() {
|
||||||
|
return internalMap.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class ByteArrayWrapper {
|
||||||
|
private final byte[] data;
|
||||||
|
|
||||||
|
public ByteArrayWrapper(byte[] data) {
|
||||||
|
if (data == null) {
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if (!(other instanceof ByteArrayWrapper)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Arrays.equals(data, ((ByteArrayWrapper) other).data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Arrays.hashCode(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class JedisByteEntry implements Entry<byte[], byte[]> {
|
||||||
|
private byte[] value;
|
||||||
|
private byte[] key;
|
||||||
|
|
||||||
|
public JedisByteEntry(byte[] key, byte[] value) {
|
||||||
|
this.key = key;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getKey() {
|
||||||
|
return this.key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] getValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] setValue(byte[] value) {
|
||||||
|
this.value = value;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,6 +20,8 @@ package redis.clients.util;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Protocol;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a very fast, non-cryptographic hash suitable for general hash-based
|
* This is a very fast, non-cryptographic hash suitable for general hash-based
|
||||||
* lookup. See http://murmurhash.googlepages.com/ for more details.
|
* lookup. See http://murmurhash.googlepages.com/ for more details.
|
||||||
@@ -156,7 +158,11 @@ public class MurmurHash implements Hashing {
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long hash(byte[] key) {
|
||||||
|
return hash64A(key, 0x1234ABCD);
|
||||||
|
}
|
||||||
|
|
||||||
public long hash(String key) {
|
public long hash(String key) {
|
||||||
return hash64A(key.getBytes(), 0x1234ABCD);
|
return hash(key.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package redis.clients.util;
|
package redis.clients.util;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.Charset;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class implements a buffered output stream without synchronization
|
* The class implements a buffered output stream without synchronization
|
||||||
@@ -12,13 +11,12 @@ public final class RedisOutputStream extends FilterOutputStream {
|
|||||||
protected final byte buf[];
|
protected final byte buf[];
|
||||||
|
|
||||||
protected int count;
|
protected int count;
|
||||||
public static final Charset CHARSET = Charset.forName("UTF-8");
|
|
||||||
|
|
||||||
public RedisOutputStream(OutputStream out) {
|
public RedisOutputStream(final OutputStream out) {
|
||||||
this(out, 8192);
|
this(out, 8192);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RedisOutputStream(OutputStream out, int size) {
|
public RedisOutputStream(final OutputStream out, final int size) {
|
||||||
super(out);
|
super(out);
|
||||||
if (size <= 0) {
|
if (size <= 0) {
|
||||||
throw new IllegalArgumentException("Buffer size <= 0");
|
throw new IllegalArgumentException("Buffer size <= 0");
|
||||||
@@ -33,14 +31,18 @@ public final class RedisOutputStream extends FilterOutputStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(int b) throws IOException {
|
public void write(final byte b) throws IOException {
|
||||||
buf[count++] = (byte) b;
|
buf[count++] = b;
|
||||||
if (count == buf.length) {
|
if (count == buf.length) {
|
||||||
flushBuffer();
|
flushBuffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(byte b[], int off, int len) throws IOException {
|
public void write(final byte[] b) throws IOException {
|
||||||
|
write(b, 0, b.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(final byte b[], final int off, final int len) throws IOException {
|
||||||
if (len >= buf.length) {
|
if (len >= buf.length) {
|
||||||
flushBuffer();
|
flushBuffer();
|
||||||
out.write(b, off, len);
|
out.write(b, off, len);
|
||||||
@@ -54,7 +56,7 @@ public final class RedisOutputStream extends FilterOutputStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeAsciiCrLf(String in) throws IOException {
|
public void writeAsciiCrLf(final String in) throws IOException {
|
||||||
final int size = in.length();
|
final int size = in.length();
|
||||||
|
|
||||||
for (int i = 0; i != size; ++i) {
|
for (int i = 0; i != size; ++i) {
|
||||||
@@ -67,11 +69,11 @@ public final class RedisOutputStream extends FilterOutputStream {
|
|||||||
writeCrLf();
|
writeCrLf();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSurrogate(char ch) {
|
public static boolean isSurrogate(final char ch) {
|
||||||
return ch >= Character.MIN_SURROGATE && ch <= Character.MAX_SURROGATE;
|
return ch >= Character.MIN_SURROGATE && ch <= Character.MAX_SURROGATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int utf8Length (String str) {
|
public static int utf8Length (final String str) {
|
||||||
int strLen = str.length(), utfLen = 0;
|
int strLen = str.length(), utfLen = 0;
|
||||||
for(int i = 0; i != strLen; ++i) {
|
for(int i = 0; i != strLen; ++i) {
|
||||||
char c = str.charAt(i);
|
char c = str.charAt(i);
|
||||||
@@ -98,7 +100,7 @@ public final class RedisOutputStream extends FilterOutputStream {
|
|||||||
buf[count++] = '\n';
|
buf[count++] = '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeUtf8CrLf(String str) throws IOException {
|
public void writeUtf8CrLf(final String str) throws IOException {
|
||||||
int strLen = str.length();
|
int strLen = str.length();
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|||||||
@@ -69,8 +69,17 @@ public class Sharded<R, S extends ShardInfo<R>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public R getShard(byte[] key) {
|
||||||
|
return nodes
|
||||||
|
.floorEntry(algo.hash(key))
|
||||||
|
.getValue()
|
||||||
|
.getResource();
|
||||||
|
}
|
||||||
|
|
||||||
public R getShard(String key) {
|
public R getShard(String key) {
|
||||||
return nodes.floorEntry(algo.hash(getKeyTag(key))).getValue()
|
return nodes
|
||||||
|
.floorEntry(algo.hash(getKeyTag(key)))
|
||||||
|
.getValue()
|
||||||
.getResource();
|
.getResource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import java.io.BufferedInputStream;
|
|||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -13,9 +12,7 @@ import java.util.Set;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Protocol.Command;
|
||||||
import redis.clients.jedis.JedisPubSub;
|
|
||||||
import redis.clients.jedis.Transaction;
|
|
||||||
|
|
||||||
public class JedisNewCommandsCheckTest extends Assert {
|
public class JedisNewCommandsCheckTest extends Assert {
|
||||||
@Test
|
@Test
|
||||||
@@ -36,22 +33,27 @@ public class JedisNewCommandsCheckTest extends Assert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Set<String> getImplementedCommands() {
|
private Set<String> getImplementedCommands() {
|
||||||
Method[] methods = Jedis.class.getDeclaredMethods();
|
// Method[] methods = Jedis.class.getDeclaredMethods();
|
||||||
|
// Set<String> implementedCommands = new HashSet<String>();
|
||||||
|
// for (Method method : methods) {
|
||||||
|
// implementedCommands.add(method.getName().trim().toLowerCase());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// methods = JedisPubSub.class.getDeclaredMethods();
|
||||||
|
// for (Method method : methods) {
|
||||||
|
// implementedCommands.add(method.getName().trim().toLowerCase());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// methods = Transaction.class.getDeclaredMethods();
|
||||||
|
// for (Method method : methods) {
|
||||||
|
// implementedCommands.add(method.getName().trim().toLowerCase());
|
||||||
|
// }
|
||||||
|
// implementedCommands.add("config");
|
||||||
|
// return implementedCommands;
|
||||||
Set<String> implementedCommands = new HashSet<String>();
|
Set<String> implementedCommands = new HashSet<String>();
|
||||||
for (Method method : methods) {
|
for (Command cmd : Command.values()) {
|
||||||
implementedCommands.add(method.getName().trim().toLowerCase());
|
implementedCommands.add(cmd.name().toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
methods = JedisPubSub.class.getDeclaredMethods();
|
|
||||||
for (Method method : methods) {
|
|
||||||
implementedCommands.add(method.getName().trim().toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
methods = Transaction.class.getDeclaredMethods();
|
|
||||||
for (Method method : methods) {
|
|
||||||
implementedCommands.add(method.getName().trim().toLowerCase());
|
|
||||||
}
|
|
||||||
implementedCommands.add("config");
|
|
||||||
return implementedCommands;
|
return implementedCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import redis.clients.jedis.Jedis;
|
|||||||
import redis.clients.jedis.JedisShardInfo;
|
import redis.clients.jedis.JedisShardInfo;
|
||||||
import redis.clients.jedis.Protocol;
|
import redis.clients.jedis.Protocol;
|
||||||
import redis.clients.jedis.tests.commands.JedisCommandTestBase;
|
import redis.clients.jedis.tests.commands.JedisCommandTestBase;
|
||||||
import redis.clients.util.RedisOutputStream;
|
|
||||||
|
|
||||||
public class JedisTest extends JedisCommandTestBase {
|
public class JedisTest extends JedisCommandTestBase {
|
||||||
@Test
|
@Test
|
||||||
@@ -26,7 +25,7 @@ public class JedisTest extends JedisCommandTestBase {
|
|||||||
bigdata[b] = (byte) ((byte) b % 255);
|
bigdata[b] = (byte) ((byte) b % 255);
|
||||||
}
|
}
|
||||||
Map<String, String> hash = new HashMap<String, String>();
|
Map<String, String> hash = new HashMap<String, String>();
|
||||||
hash.put("data", new String(bigdata, RedisOutputStream.CHARSET));
|
hash.put("data", new String(bigdata, Protocol.UTF8));
|
||||||
|
|
||||||
String status = jedis.hmset("foo", hash);
|
String status = jedis.hmset("foo", hash);
|
||||||
assertEquals("OK", status);
|
assertEquals("OK", status);
|
||||||
|
|||||||
25
src/test/java/redis/clients/jedis/tests/JedisTestBase.java
Normal file
25
src/test/java/redis/clients/jedis/tests/JedisTestBase.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package redis.clients.jedis.tests;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
public abstract class JedisTestBase extends Assert {
|
||||||
|
protected void assertEquals(List<byte[]> expected, List<byte[]> actual) {
|
||||||
|
assertEquals(expected.size(), actual.size());
|
||||||
|
for (int n = 0; n < expected.size(); n++) {
|
||||||
|
assertArrayEquals(expected.get(n), actual.get(n));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void assertEquals(Set<byte[]> expected, Set<byte[]> actual) {
|
||||||
|
assertEquals(expected.size(), actual.size());
|
||||||
|
Iterator<byte[]> iterator = expected.iterator();
|
||||||
|
Iterator<byte[]> iterator2 = actual.iterator();
|
||||||
|
while (iterator.hasNext() || iterator2.hasNext()) {
|
||||||
|
assertArrayEquals(iterator.next(), iterator2.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,13 +4,14 @@ import java.io.IOException;
|
|||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.JedisPipeline;
|
import redis.clients.jedis.JedisPipeline;
|
||||||
|
import redis.clients.jedis.Protocol;
|
||||||
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
||||||
|
|
||||||
public class PipeliningTest extends Assert {
|
public class PipeliningTest extends Assert {
|
||||||
@@ -36,7 +37,7 @@ public class PipeliningTest extends Assert {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assertEquals(2, results.size());
|
assertEquals(2, results.size());
|
||||||
assertEquals("OK", results.get(0));
|
assertArrayEquals("OK".getBytes(Protocol.UTF8), (byte[])results.get(0));
|
||||||
assertEquals("bar", results.get(1));
|
assertArrayEquals("bar".getBytes(Protocol.UTF8), (byte[])results.get(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,15 +9,13 @@ import java.io.PipedOutputStream;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.Protocol;
|
import redis.clients.jedis.Protocol;
|
||||||
import redis.clients.util.RedisInputStream;
|
import redis.clients.util.RedisInputStream;
|
||||||
import redis.clients.util.RedisOutputStream;
|
import redis.clients.util.RedisOutputStream;
|
||||||
|
|
||||||
public class ProtocolTest extends Assert {
|
public class ProtocolTest extends JedisTestBase {
|
||||||
@Test
|
@Test
|
||||||
public void buildACommand() throws IOException {
|
public void buildACommand() throws IOException {
|
||||||
PipedInputStream pis = new PipedInputStream();
|
PipedInputStream pis = new PipedInputStream();
|
||||||
@@ -25,7 +23,8 @@ public class ProtocolTest extends Assert {
|
|||||||
PipedOutputStream pos = new PipedOutputStream(pis);
|
PipedOutputStream pos = new PipedOutputStream(pis);
|
||||||
|
|
||||||
Protocol protocol = new Protocol();
|
Protocol protocol = new Protocol();
|
||||||
protocol.sendCommand(new RedisOutputStream(pos), "GET", "SOMEKEY");
|
protocol.sendCommand(new RedisOutputStream(pos), Protocol.Command.GET,
|
||||||
|
"SOMEKEY".getBytes(Protocol.UTF8));
|
||||||
|
|
||||||
pos.close();
|
pos.close();
|
||||||
String expectedCommand = "*2\r\n$3\r\nGET\r\n$7\r\nSOMEKEY\r\n";
|
String expectedCommand = "*2\r\n$3\r\nGET\r\n$7\r\nSOMEKEY\r\n";
|
||||||
@@ -43,8 +42,8 @@ public class ProtocolTest extends Assert {
|
|||||||
public void bulkReply() {
|
public void bulkReply() {
|
||||||
InputStream is = new ByteArrayInputStream("$6\r\nfoobar\r\n".getBytes());
|
InputStream is = new ByteArrayInputStream("$6\r\nfoobar\r\n".getBytes());
|
||||||
Protocol protocol = new Protocol();
|
Protocol protocol = new Protocol();
|
||||||
String response = (String) protocol.read(new RedisInputStream(is));
|
byte[] response = (byte[]) protocol.read(new RedisInputStream(is));
|
||||||
assertEquals("foobar", response);
|
assertArrayEquals("foobar".getBytes(Protocol.UTF8), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -52,8 +51,9 @@ public class ProtocolTest extends Assert {
|
|||||||
FragmentedByteArrayInputStream fis = new FragmentedByteArrayInputStream(
|
FragmentedByteArrayInputStream fis = new FragmentedByteArrayInputStream(
|
||||||
"$30\r\n012345678901234567890123456789\r\n".getBytes());
|
"$30\r\n012345678901234567890123456789\r\n".getBytes());
|
||||||
Protocol protocol = new Protocol();
|
Protocol protocol = new Protocol();
|
||||||
String response = (String) protocol.read(new RedisInputStream(fis));
|
byte[] response = (byte[]) protocol.read(new RedisInputStream(fis));
|
||||||
assertEquals("012345678901234567890123456789", response);
|
assertArrayEquals("012345678901234567890123456789"
|
||||||
|
.getBytes(Protocol.UTF8), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -68,8 +68,8 @@ public class ProtocolTest extends Assert {
|
|||||||
public void singleLineReply() {
|
public void singleLineReply() {
|
||||||
InputStream is = new ByteArrayInputStream("+OK\r\n".getBytes());
|
InputStream is = new ByteArrayInputStream("+OK\r\n".getBytes());
|
||||||
Protocol protocol = new Protocol();
|
Protocol protocol = new Protocol();
|
||||||
String response = (String) protocol.read(new RedisInputStream(is));
|
byte[] response = (byte[]) protocol.read(new RedisInputStream(is));
|
||||||
assertEquals("OK", response);
|
assertArrayEquals("OK".getBytes(Protocol.UTF8), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -87,32 +87,15 @@ public class ProtocolTest extends Assert {
|
|||||||
"*4\r\n$3\r\nfoo\r\n$3\r\nbar\r\n$5\r\nHello\r\n$5\r\nWorld\r\n"
|
"*4\r\n$3\r\nfoo\r\n$3\r\nbar\r\n$5\r\nHello\r\n$5\r\nWorld\r\n"
|
||||||
.getBytes());
|
.getBytes());
|
||||||
Protocol protocol = new Protocol();
|
Protocol protocol = new Protocol();
|
||||||
List<String> response = (List<String>) (List<?>) protocol
|
List<byte[]> response = (List<byte[]>) protocol
|
||||||
.read(new RedisInputStream(is));
|
.read(new RedisInputStream(is));
|
||||||
List<String> expected = new ArrayList<String>();
|
List<byte[]> expected = new ArrayList<byte[]>();
|
||||||
expected.add("foo");
|
expected.add("foo".getBytes(Protocol.UTF8));
|
||||||
expected.add("bar");
|
expected.add("bar".getBytes(Protocol.UTF8));
|
||||||
expected.add("Hello");
|
expected.add("Hello".getBytes(Protocol.UTF8));
|
||||||
expected.add("World");
|
expected.add("World".getBytes(Protocol.UTF8));
|
||||||
|
|
||||||
assertEquals(expected, response);
|
assertEquals(expected, response);
|
||||||
|
|
||||||
is = new ByteArrayInputStream(
|
|
||||||
"*4\r\n$3\r\nfoo\r\n+OK\r\n:1000\r\n*2\r\n$3\r\nfoo\r\n$3\r\nbar"
|
|
||||||
.getBytes());
|
|
||||||
protocol = new Protocol();
|
|
||||||
List<Object> response2 = (List<Object>) protocol
|
|
||||||
.read(new RedisInputStream(is));
|
|
||||||
List<Object> expected2 = new ArrayList<Object>();
|
|
||||||
expected2.add("foo");
|
|
||||||
expected2.add("OK");
|
|
||||||
expected2.add(1000);
|
|
||||||
List<Object> sub = new ArrayList<Object>();
|
|
||||||
sub.add("foo");
|
|
||||||
sub.add("bar");
|
|
||||||
expected2.add(sub);
|
|
||||||
|
|
||||||
assertEquals(expected2, response2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class ShardedJedisPoolTest extends Assert {
|
|||||||
@Test
|
@Test
|
||||||
public void checkConnectionWithDefaultPort() throws TimeoutException {
|
public void checkConnectionWithDefaultPort() throws TimeoutException {
|
||||||
ShardedJedisPool pool = new ShardedJedisPool(shards);
|
ShardedJedisPool pool = new ShardedJedisPool(shards);
|
||||||
pool.setResourcesNumber(10);
|
pool.setResourcesNumber(1);
|
||||||
pool.init();
|
pool.init();
|
||||||
|
|
||||||
ShardedJedis jedis = pool.getResource(200);
|
ShardedJedis jedis = pool.getResource(200);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.JedisShardInfo;
|
import redis.clients.jedis.JedisShardInfo;
|
||||||
|
import redis.clients.jedis.Protocol;
|
||||||
import redis.clients.jedis.ShardedJedis;
|
import redis.clients.jedis.ShardedJedis;
|
||||||
import redis.clients.jedis.ShardedJedisPipeline;
|
import redis.clients.jedis.ShardedJedisPipeline;
|
||||||
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
||||||
@@ -141,7 +142,12 @@ public class ShardedJedisTest extends Assert {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
assertEquals("a", results.get(0));
|
List<Object> expected = new ArrayList<Object>(2);
|
||||||
assertEquals("b", results.get(1));
|
expected.add("a".getBytes(Protocol.UTF8));
|
||||||
|
expected.add("b".getBytes(Protocol.UTF8));
|
||||||
|
|
||||||
|
assertEquals(2, results.size());
|
||||||
|
assertArrayEquals("a".getBytes(Protocol.UTF8), (byte[]) results.get(0));
|
||||||
|
assertArrayEquals("b".getBytes(Protocol.UTF8), (byte[]) results.get(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,28 @@
|
|||||||
package redis.clients.jedis.tests.commands;
|
package redis.clients.jedis.tests.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.JedisException;
|
import redis.clients.jedis.JedisException;
|
||||||
|
import redis.clients.jedis.Protocol;
|
||||||
|
|
||||||
public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||||
|
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||||
|
final byte[] bfoo1 = { 0x01, 0x02, 0x03, 0x04, 0x0A };
|
||||||
|
final byte[] bfoo2 = { 0x01, 0x02, 0x03, 0x04, 0x0B };
|
||||||
|
final byte[] bfoo3 = { 0x01, 0x02, 0x03, 0x04, 0x0C };
|
||||||
|
final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
|
||||||
|
final byte[] bbar1 = { 0x05, 0x06, 0x07, 0x08, 0x0A };
|
||||||
|
final byte[] bbar2 = { 0x05, 0x06, 0x07, 0x08, 0x0B };
|
||||||
|
final byte[] bbar3 = { 0x05, 0x06, 0x07, 0x08, 0x0C };
|
||||||
|
|
||||||
|
final byte[] bfoobar = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
|
||||||
|
final byte[] bfoostar = { 0x01, 0x02, 0x03, 0x04, '*' };
|
||||||
|
final byte[] bbarstar = { 0x05, 0x06, 0x07, 0x08, '*' };
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ping() {
|
public void ping() {
|
||||||
String status = jedis.ping();
|
String status = jedis.ping();
|
||||||
@@ -19,14 +34,26 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
String status = jedis.set("foo", "bar");
|
String status = jedis.set("foo", "bar");
|
||||||
assertEquals("OK", status);
|
assertEquals("OK", status);
|
||||||
|
|
||||||
|
status = jedis.set(bfoo, bbar);
|
||||||
|
assertEquals("OK", status);
|
||||||
|
|
||||||
int reply = jedis.exists("foo");
|
int reply = jedis.exists("foo");
|
||||||
assertEquals(1, reply);
|
assertEquals(1, reply);
|
||||||
|
|
||||||
|
reply = jedis.exists(bfoo);
|
||||||
|
assertEquals(1, reply);
|
||||||
|
|
||||||
reply = jedis.del("foo");
|
reply = jedis.del("foo");
|
||||||
assertEquals(1, reply);
|
assertEquals(1, reply);
|
||||||
|
|
||||||
|
reply = jedis.del(bfoo);
|
||||||
|
assertEquals(1, reply);
|
||||||
|
|
||||||
reply = jedis.exists("foo");
|
reply = jedis.exists("foo");
|
||||||
assertEquals(0, reply);
|
assertEquals(0, reply);
|
||||||
|
|
||||||
|
reply = jedis.exists(bfoo);
|
||||||
|
assertEquals(0, reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -52,6 +79,29 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
reply = jedis.del("foo1", "foo2");
|
reply = jedis.del("foo1", "foo2");
|
||||||
assertEquals(0, reply);
|
assertEquals(0, reply);
|
||||||
|
|
||||||
|
// Binary ...
|
||||||
|
jedis.set(bfoo1, bbar1);
|
||||||
|
jedis.set(bfoo2, bbar2);
|
||||||
|
jedis.set(bfoo3, bbar3);
|
||||||
|
|
||||||
|
reply = jedis.del(bfoo1, bfoo2, bfoo3);
|
||||||
|
assertEquals(3, reply);
|
||||||
|
|
||||||
|
reply = jedis.exists(bfoo1);
|
||||||
|
assertEquals(0, reply);
|
||||||
|
reply = jedis.exists(bfoo2);
|
||||||
|
assertEquals(0, reply);
|
||||||
|
reply = jedis.exists(bfoo3);
|
||||||
|
assertEquals(0, reply);
|
||||||
|
|
||||||
|
jedis.set(bfoo1, bbar1);
|
||||||
|
|
||||||
|
reply = jedis.del(bfoo1, bfoo2);
|
||||||
|
assertEquals(1, reply);
|
||||||
|
|
||||||
|
reply = jedis.del(bfoo1, bfoo2);
|
||||||
|
assertEquals(0, reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -59,6 +109,11 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
jedis.set("foo", "bar");
|
jedis.set("foo", "bar");
|
||||||
String status = jedis.type("foo");
|
String status = jedis.type("foo");
|
||||||
assertEquals("string", status);
|
assertEquals("string", status);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.set(bfoo, bbar);
|
||||||
|
status = jedis.type(bfoo);
|
||||||
|
assertEquals("string", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -66,16 +121,29 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
jedis.set("foo", "bar");
|
jedis.set("foo", "bar");
|
||||||
jedis.set("foobar", "bar");
|
jedis.set("foobar", "bar");
|
||||||
|
|
||||||
List<String> keys = jedis.keys("foo*");
|
Set<String> keys = jedis.keys("foo*");
|
||||||
List<String> expected = new ArrayList<String>();
|
Set<String> expected = new HashSet<String>();
|
||||||
expected.add("foo");
|
expected.add("foo");
|
||||||
expected.add("foobar");
|
expected.add("foobar");
|
||||||
assertEquals(expected, keys);
|
assertEquals(expected, keys);
|
||||||
|
|
||||||
expected = new ArrayList<String>();
|
expected = new HashSet<String>();
|
||||||
keys = jedis.keys("bar*");
|
keys = jedis.keys("bar*");
|
||||||
|
|
||||||
assertEquals(expected, keys);
|
assertEquals(expected, keys);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.set(bfoo, bbar);
|
||||||
|
jedis.set(bfoobar, bbar);
|
||||||
|
|
||||||
|
Set<byte[]> bkeys = jedis.keys(bfoostar);
|
||||||
|
assertEquals(2, bkeys.size());
|
||||||
|
assertTrue(setContains(bkeys, bfoo));
|
||||||
|
assertTrue(setContains(bkeys, bfoobar));
|
||||||
|
|
||||||
|
bkeys = jedis.keys(bbarstar);
|
||||||
|
|
||||||
|
assertEquals(0, bkeys.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -90,6 +158,22 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
String randomkey = jedis.randomKey();
|
String randomkey = jedis.randomKey();
|
||||||
assertTrue(randomkey.equals("foo") || randomkey.equals("bar"));
|
assertTrue(randomkey.equals("foo") || randomkey.equals("bar"));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.del("foo");
|
||||||
|
jedis.del("bar");
|
||||||
|
assertEquals(null, jedis.randomKey());
|
||||||
|
|
||||||
|
jedis.set(bfoo, bbar);
|
||||||
|
|
||||||
|
assertArrayEquals(bfoo, jedis.randomBinaryKey());
|
||||||
|
|
||||||
|
jedis.set(bbar, bfoo);
|
||||||
|
|
||||||
|
byte[] randomBkey = jedis.randomBinaryKey();
|
||||||
|
assertTrue(Arrays.equals(randomBkey, bfoo)
|
||||||
|
|| Arrays.equals(randomBkey, bbar));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -103,12 +187,36 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
value = jedis.get("bar");
|
value = jedis.get("bar");
|
||||||
assertEquals("bar", value);
|
assertEquals("bar", value);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.set(bfoo, bbar);
|
||||||
|
String bstatus = jedis.rename(bfoo, bbar);
|
||||||
|
assertEquals("OK", bstatus);
|
||||||
|
|
||||||
|
byte[] bvalue = jedis.get(bfoo);
|
||||||
|
assertEquals(null, bvalue);
|
||||||
|
|
||||||
|
bvalue = jedis.get(bbar);
|
||||||
|
assertArrayEquals(bbar, bvalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JedisException.class)
|
@Test
|
||||||
public void renameOldAndNewAreTheSame() {
|
public void renameOldAndNewAreTheSame() {
|
||||||
|
try {
|
||||||
jedis.set("foo", "bar");
|
jedis.set("foo", "bar");
|
||||||
jedis.rename("foo", "foo");
|
jedis.rename("foo", "foo");
|
||||||
|
fail("JedisException expected");
|
||||||
|
} catch (final JedisException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
try {
|
||||||
|
jedis.set(bfoo, bbar);
|
||||||
|
jedis.rename(bfoo, bfoo);
|
||||||
|
fail("JedisException expected");
|
||||||
|
} catch (final JedisException e) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -120,6 +228,16 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
jedis.set("foo", "bar");
|
jedis.set("foo", "bar");
|
||||||
status = jedis.renamenx("foo", "bar");
|
status = jedis.renamenx("foo", "bar");
|
||||||
assertEquals(0, status);
|
assertEquals(0, status);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.set(bfoo, bbar);
|
||||||
|
int bstatus = jedis.renamenx(bfoo, bbar);
|
||||||
|
assertEquals(1, bstatus);
|
||||||
|
|
||||||
|
jedis.set(bfoo, bbar);
|
||||||
|
bstatus = jedis.renamenx(bfoo, bbar);
|
||||||
|
assertEquals(0, bstatus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -130,6 +248,11 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
jedis.set("foo", "bar");
|
jedis.set("foo", "bar");
|
||||||
size = jedis.dbSize();
|
size = jedis.dbSize();
|
||||||
assertEquals(1, size);
|
assertEquals(1, size);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.set(bfoo, bbar);
|
||||||
|
size = jedis.dbSize();
|
||||||
|
assertEquals(2, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -140,6 +263,15 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
jedis.set("foo", "bar");
|
jedis.set("foo", "bar");
|
||||||
status = jedis.expire("foo", 20);
|
status = jedis.expire("foo", 20);
|
||||||
assertEquals(1, status);
|
assertEquals(1, status);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
int bstatus = jedis.expire(bfoo, 20);
|
||||||
|
assertEquals(0, bstatus);
|
||||||
|
|
||||||
|
jedis.set(bfoo, bbar);
|
||||||
|
bstatus = jedis.expire(bfoo, 20);
|
||||||
|
assertEquals(1, bstatus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -153,6 +285,16 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
unixTime = (System.currentTimeMillis() / 1000L) + 20;
|
unixTime = (System.currentTimeMillis() / 1000L) + 20;
|
||||||
status = jedis.expireAt("foo", unixTime);
|
status = jedis.expireAt("foo", unixTime);
|
||||||
assertEquals(1, status);
|
assertEquals(1, status);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
int bstatus = jedis.expireAt(bfoo, unixTime);
|
||||||
|
assertEquals(0, bstatus);
|
||||||
|
|
||||||
|
jedis.set(bfoo, bbar);
|
||||||
|
unixTime = (System.currentTimeMillis() / 1000L) + 20;
|
||||||
|
bstatus = jedis.expireAt(bfoo, unixTime);
|
||||||
|
assertEquals(1, bstatus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -167,6 +309,19 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
jedis.expire("foo", 20);
|
jedis.expire("foo", 20);
|
||||||
ttl = jedis.ttl("foo");
|
ttl = jedis.ttl("foo");
|
||||||
assertTrue(ttl >= 0 && ttl <= 20);
|
assertTrue(ttl >= 0 && ttl <= 20);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
int bttl = jedis.ttl(bfoo);
|
||||||
|
assertEquals(-1, bttl);
|
||||||
|
|
||||||
|
jedis.set(bfoo, bbar);
|
||||||
|
bttl = jedis.ttl(bfoo);
|
||||||
|
assertEquals(-1, bttl);
|
||||||
|
|
||||||
|
jedis.expire(bfoo, 20);
|
||||||
|
bttl = jedis.ttl(bfoo);
|
||||||
|
assertTrue(bttl >= 0 && bttl <= 20);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -178,6 +333,14 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
status = jedis.select(0);
|
status = jedis.select(0);
|
||||||
assertEquals("OK", status);
|
assertEquals("OK", status);
|
||||||
assertEquals("bar", jedis.get("foo"));
|
assertEquals("bar", jedis.get("foo"));
|
||||||
|
// Binary
|
||||||
|
jedis.set(bfoo, bbar);
|
||||||
|
String bstatus = jedis.select(1);
|
||||||
|
assertEquals("OK", bstatus);
|
||||||
|
assertEquals(null, jedis.get(bfoo));
|
||||||
|
bstatus = jedis.select(0);
|
||||||
|
assertEquals("OK", bstatus);
|
||||||
|
assertArrayEquals(bbar, jedis.get(bfoo));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -192,6 +355,20 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
jedis.select(1);
|
jedis.select(1);
|
||||||
assertEquals("bar", jedis.get("foo"));
|
assertEquals("bar", jedis.get("foo"));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.select(0);
|
||||||
|
int bstatus = jedis.move(bfoo, 1);
|
||||||
|
assertEquals(0, bstatus);
|
||||||
|
|
||||||
|
jedis.set(bfoo, bbar);
|
||||||
|
bstatus = jedis.move(bfoo, 1);
|
||||||
|
assertEquals(1, bstatus);
|
||||||
|
assertEquals(null, jedis.get(bfoo));
|
||||||
|
|
||||||
|
jedis.select(1);
|
||||||
|
assertArrayEquals(bbar, jedis.get(bfoo));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -205,6 +382,20 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(0, jedis.dbSize().intValue());
|
assertEquals(0, jedis.dbSize().intValue());
|
||||||
jedis.select(1);
|
jedis.select(1);
|
||||||
assertEquals(1, jedis.dbSize().intValue());
|
assertEquals(1, jedis.dbSize().intValue());
|
||||||
|
jedis.del("bar");
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.select(0);
|
||||||
|
jedis.set(bfoo, bbar);
|
||||||
|
assertEquals(1, jedis.dbSize().intValue());
|
||||||
|
jedis.set(bbar, bfoo);
|
||||||
|
jedis.move(bbar, 1);
|
||||||
|
String bstatus = jedis.flushDB();
|
||||||
|
assertEquals("OK", bstatus);
|
||||||
|
assertEquals(0, jedis.dbSize().intValue());
|
||||||
|
jedis.select(1);
|
||||||
|
assertEquals(1, jedis.dbSize().intValue());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -218,6 +409,19 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(0, jedis.dbSize().intValue());
|
assertEquals(0, jedis.dbSize().intValue());
|
||||||
jedis.select(1);
|
jedis.select(1);
|
||||||
assertEquals(0, jedis.dbSize().intValue());
|
assertEquals(0, jedis.dbSize().intValue());
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.select(0);
|
||||||
|
jedis.set(bfoo, bbar);
|
||||||
|
assertEquals(1, jedis.dbSize().intValue());
|
||||||
|
jedis.set(bbar, bfoo);
|
||||||
|
jedis.move(bbar, 1);
|
||||||
|
String bstatus = jedis.flushAll();
|
||||||
|
assertEquals("OK", bstatus);
|
||||||
|
assertEquals(0, jedis.dbSize().intValue());
|
||||||
|
jedis.select(1);
|
||||||
|
assertEquals(0, jedis.dbSize().intValue());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -227,12 +431,24 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
|||||||
int status = jedis.persist("foo");
|
int status = jedis.persist("foo");
|
||||||
assertEquals(1, status);
|
assertEquals(1, status);
|
||||||
assertEquals(-1, jedis.ttl("foo").intValue());
|
assertEquals(-1, jedis.ttl("foo").intValue());
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.setex(bfoo, 60 * 60, bbar);
|
||||||
|
assertTrue(jedis.ttl(bfoo) > 0);
|
||||||
|
int bstatus = jedis.persist(bfoo);
|
||||||
|
assertEquals(1, bstatus);
|
||||||
|
assertEquals(-1, jedis.ttl(bfoo).intValue());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void echo() {
|
public void echo() {
|
||||||
String result = jedis.echo("hello world");
|
String result = jedis.echo("hello world");
|
||||||
assertEquals("hello world", result);
|
assertEquals("hello world", result);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
byte[] bresult = jedis.echo("hello world".getBytes(Protocol.UTF8));
|
||||||
|
assertArrayEquals("hello world".getBytes(Protocol.UTF8), bresult);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,214 @@
|
|||||||
|
package redis.clients.jedis.tests.commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import redis.clients.jedis.JedisException;
|
||||||
|
import redis.clients.jedis.Protocol.Keyword;
|
||||||
|
|
||||||
|
public class BinaryValuesCommandsTest extends JedisCommandTestBase {
|
||||||
|
byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||||
|
byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
|
||||||
|
byte[] binaryValue;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void startUp() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
for (int n = 0; n < 1000; n++) {
|
||||||
|
sb.append("A");
|
||||||
|
}
|
||||||
|
|
||||||
|
binaryValue = sb.toString().getBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setAndGet() {
|
||||||
|
String status = jedis.set(bfoo, binaryValue);
|
||||||
|
assertTrue(Keyword.OK.name().equalsIgnoreCase(status));
|
||||||
|
|
||||||
|
byte[] value = jedis.get(bfoo);
|
||||||
|
assertTrue(Arrays.equals(binaryValue, value));
|
||||||
|
|
||||||
|
assertNull(jedis.get(bbar));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSet() {
|
||||||
|
byte[] value = jedis.getSet(bfoo, binaryValue);
|
||||||
|
assertNull(value);
|
||||||
|
value = jedis.get(bfoo);
|
||||||
|
assertTrue(Arrays.equals(binaryValue, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mget() {
|
||||||
|
List<byte[]> values = jedis.mget(bfoo, bbar);
|
||||||
|
List<byte[]> expected = new ArrayList<byte[]>();
|
||||||
|
expected.add(null);
|
||||||
|
expected.add(null);
|
||||||
|
|
||||||
|
assertEquals(expected, values);
|
||||||
|
|
||||||
|
jedis.set(bfoo, binaryValue);
|
||||||
|
|
||||||
|
expected = new ArrayList<byte[]>();
|
||||||
|
expected.add(binaryValue);
|
||||||
|
expected.add(null);
|
||||||
|
values = jedis.mget(bfoo, bbar);
|
||||||
|
|
||||||
|
assertEquals(expected, values);
|
||||||
|
|
||||||
|
jedis.set(bbar, bfoo);
|
||||||
|
|
||||||
|
expected = new ArrayList<byte[]>();
|
||||||
|
expected.add(binaryValue);
|
||||||
|
expected.add(bfoo);
|
||||||
|
values = jedis.mget(bfoo, bbar);
|
||||||
|
|
||||||
|
assertEquals(expected, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setnx() {
|
||||||
|
int status = jedis.setnx(bfoo, binaryValue);
|
||||||
|
assertEquals(1, status);
|
||||||
|
assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo)));
|
||||||
|
|
||||||
|
status = jedis.setnx(bfoo, bbar);
|
||||||
|
assertEquals(0, status);
|
||||||
|
assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setex() {
|
||||||
|
String status = jedis.setex(bfoo, 20, binaryValue);
|
||||||
|
assertEquals(Keyword.OK.name(), status);
|
||||||
|
int ttl = jedis.ttl(bfoo);
|
||||||
|
assertTrue(ttl > 0 && ttl <= 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mset() {
|
||||||
|
String status = jedis.mset(bfoo, binaryValue, bbar, bfoo);
|
||||||
|
assertEquals(Keyword.OK.name(), status);
|
||||||
|
assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo)));
|
||||||
|
assertTrue(Arrays.equals(bfoo, jedis.get(bbar)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void msetnx() {
|
||||||
|
int status = jedis.msetnx(bfoo, binaryValue, bbar, bfoo);
|
||||||
|
assertEquals(1, status);
|
||||||
|
assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo)));
|
||||||
|
assertTrue(Arrays.equals(bfoo, jedis.get(bbar)));
|
||||||
|
|
||||||
|
status = jedis.msetnx(bfoo, bbar, "bar2".getBytes(), "foo2".getBytes());
|
||||||
|
assertEquals(0, status);
|
||||||
|
assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo)));
|
||||||
|
assertTrue(Arrays.equals(bfoo, jedis.get(bbar)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = JedisException.class)
|
||||||
|
public void incrWrongValue() {
|
||||||
|
jedis.set(bfoo, binaryValue);
|
||||||
|
jedis.incr(bfoo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void incr() {
|
||||||
|
int value = jedis.incr(bfoo);
|
||||||
|
assertEquals(1, value);
|
||||||
|
value = jedis.incr(bfoo);
|
||||||
|
assertEquals(2, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = JedisException.class)
|
||||||
|
public void incrByWrongValue() {
|
||||||
|
jedis.set(bfoo, binaryValue);
|
||||||
|
jedis.incrBy(bfoo, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void incrBy() {
|
||||||
|
int value = jedis.incrBy(bfoo, 2);
|
||||||
|
assertEquals(2, value);
|
||||||
|
value = jedis.incrBy(bfoo, 2);
|
||||||
|
assertEquals(4, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = JedisException.class)
|
||||||
|
public void decrWrongValue() {
|
||||||
|
jedis.set(bfoo, binaryValue);
|
||||||
|
jedis.decr(bfoo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void decr() {
|
||||||
|
int value = jedis.decr(bfoo);
|
||||||
|
assertEquals(-1, value);
|
||||||
|
value = jedis.decr(bfoo);
|
||||||
|
assertEquals(-2, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = JedisException.class)
|
||||||
|
public void decrByWrongValue() {
|
||||||
|
jedis.set(bfoo, binaryValue);
|
||||||
|
jedis.decrBy(bfoo, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void decrBy() {
|
||||||
|
int value = jedis.decrBy(bfoo, 2);
|
||||||
|
assertEquals(-2, value);
|
||||||
|
value = jedis.decrBy(bfoo, 2);
|
||||||
|
assertEquals(-4, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void append() {
|
||||||
|
byte[] first512 = new byte[512];
|
||||||
|
System.arraycopy(binaryValue, 0, first512, 0, 512);
|
||||||
|
int value = jedis.append(bfoo, first512);
|
||||||
|
assertEquals(512, value);
|
||||||
|
assertTrue(Arrays.equals(first512, jedis.get(bfoo)));
|
||||||
|
|
||||||
|
byte[] rest = new byte[binaryValue.length - 512];
|
||||||
|
System.arraycopy(binaryValue, 512, rest, 0, binaryValue.length - 512);
|
||||||
|
value = jedis.append(bfoo, rest);
|
||||||
|
assertEquals(binaryValue.length, value);
|
||||||
|
|
||||||
|
assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void substr() {
|
||||||
|
jedis.set(bfoo, binaryValue);
|
||||||
|
|
||||||
|
byte[] first512 = new byte[512];
|
||||||
|
System.arraycopy(binaryValue, 0, first512, 0, 512);
|
||||||
|
byte[] rfirst512 = jedis.substr(bfoo, 0, 511);
|
||||||
|
assertTrue(Arrays.equals(first512, rfirst512));
|
||||||
|
|
||||||
|
byte[] last512 = new byte[512];
|
||||||
|
System
|
||||||
|
.arraycopy(binaryValue, binaryValue.length - 512, last512, 0,
|
||||||
|
512);
|
||||||
|
assertTrue(Arrays.equals(last512, jedis.substr(bfoo, -512, -1)));
|
||||||
|
|
||||||
|
assertTrue(Arrays.equals(binaryValue, jedis.substr(bfoo, 0, -1)));
|
||||||
|
|
||||||
|
assertTrue(Arrays.equals(last512, jedis.substr(bfoo,
|
||||||
|
binaryValue.length - 512, 100000)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void strlen() {
|
||||||
|
jedis.set(bfoo, binaryValue);
|
||||||
|
assertEquals(binaryValue.length, jedis.strlen(bfoo).intValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,8 +21,9 @@ public class ControlCommandsTest extends JedisCommandTestBase {
|
|||||||
String status = jedis.bgsave();
|
String status = jedis.bgsave();
|
||||||
assertEquals("Background saving started", status);
|
assertEquals("Background saving started", status);
|
||||||
} catch (JedisException e) {
|
} catch (JedisException e) {
|
||||||
assertEquals("ERR Background save already in progress", e
|
assertTrue(
|
||||||
.getMessage());
|
"ERR Background save already in progress"
|
||||||
|
.equalsIgnoreCase(e.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,18 +3,31 @@ package redis.clients.jedis.tests.commands;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class HashesCommandsTest extends JedisCommandTestBase {
|
public class HashesCommandsTest extends JedisCommandTestBase {
|
||||||
|
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||||
|
final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
|
||||||
|
final byte[] bcar = { 0x09, 0x0A, 0x0B, 0x0C };
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void hset() {
|
public void hset() {
|
||||||
int status = jedis.hset("foo", "bar", "car");
|
int status = jedis.hset("foo", "bar", "car");
|
||||||
assertEquals(1, status);
|
assertEquals(1, status);
|
||||||
status = jedis.hset("foo", "bar", "foo");
|
status = jedis.hset("foo", "bar", "foo");
|
||||||
assertEquals(0, status);
|
assertEquals(0, status);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
int bstatus = jedis.hset(bfoo, bbar, bcar);
|
||||||
|
assertEquals(1, bstatus);
|
||||||
|
bstatus = jedis.hset(bfoo, bbar, bfoo);
|
||||||
|
assertEquals(0, bstatus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -23,6 +36,12 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(null, jedis.hget("bar", "foo"));
|
assertEquals(null, jedis.hget("bar", "foo"));
|
||||||
assertEquals(null, jedis.hget("foo", "car"));
|
assertEquals(null, jedis.hget("foo", "car"));
|
||||||
assertEquals("car", jedis.hget("foo", "bar"));
|
assertEquals("car", jedis.hget("foo", "bar"));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.hset(bfoo, bbar, bcar);
|
||||||
|
assertEquals(null, jedis.hget(bbar, bfoo));
|
||||||
|
assertEquals(null, jedis.hget(bfoo, bcar));
|
||||||
|
assertArrayEquals(bcar, jedis.hget(bfoo, bbar));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -38,6 +57,20 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
|||||||
status = jedis.hsetnx("foo", "car", "bar");
|
status = jedis.hsetnx("foo", "car", "bar");
|
||||||
assertEquals(1, status);
|
assertEquals(1, status);
|
||||||
assertEquals("bar", jedis.hget("foo", "car"));
|
assertEquals("bar", jedis.hget("foo", "car"));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
int bstatus = jedis.hsetnx(bfoo, bbar, bcar);
|
||||||
|
assertEquals(1, bstatus);
|
||||||
|
assertArrayEquals(bcar, jedis.hget(bfoo, bbar));
|
||||||
|
|
||||||
|
bstatus = jedis.hsetnx(bfoo, bbar, bfoo);
|
||||||
|
assertEquals(0, bstatus);
|
||||||
|
assertArrayEquals(bcar, jedis.hget(bfoo, bbar));
|
||||||
|
|
||||||
|
bstatus = jedis.hsetnx(bfoo, bcar, bbar);
|
||||||
|
assertEquals(1, bstatus);
|
||||||
|
assertArrayEquals(bbar, jedis.hget(bfoo, bcar));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -49,6 +82,16 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals("OK", status);
|
assertEquals("OK", status);
|
||||||
assertEquals("car", jedis.hget("foo", "bar"));
|
assertEquals("car", jedis.hget("foo", "bar"));
|
||||||
assertEquals("bar", jedis.hget("foo", "car"));
|
assertEquals("bar", jedis.hget("foo", "car"));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>();
|
||||||
|
bhash.put(bbar, bcar);
|
||||||
|
bhash.put(bcar, bbar);
|
||||||
|
String bstatus = jedis.hmset(bfoo, bhash);
|
||||||
|
assertEquals("OK", bstatus);
|
||||||
|
assertArrayEquals(bcar, jedis.hget(bfoo, bbar));
|
||||||
|
assertArrayEquals(bbar, jedis.hget(bfoo, bcar));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -65,6 +108,20 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add(null);
|
expected.add(null);
|
||||||
|
|
||||||
assertEquals(expected, values);
|
assertEquals(expected, values);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>();
|
||||||
|
bhash.put(bbar, bcar);
|
||||||
|
bhash.put(bcar, bbar);
|
||||||
|
jedis.hmset(bfoo, bhash);
|
||||||
|
|
||||||
|
List<byte[]> bvalues = jedis.hmget(bfoo, bbar, bcar, bfoo);
|
||||||
|
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||||
|
bexpected.add(bcar);
|
||||||
|
bexpected.add(bbar);
|
||||||
|
bexpected.add(null);
|
||||||
|
|
||||||
|
assertEquals(bexpected, bvalues);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -75,6 +132,15 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(0, value);
|
assertEquals(0, value);
|
||||||
value = jedis.hincrBy("foo", "bar", -10);
|
value = jedis.hincrBy("foo", "bar", -10);
|
||||||
assertEquals(-10, value);
|
assertEquals(-10, value);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
int bvalue = jedis.hincrBy(bfoo, bbar, 1);
|
||||||
|
assertEquals(1, bvalue);
|
||||||
|
bvalue = jedis.hincrBy(bfoo, bbar, -1);
|
||||||
|
assertEquals(0, bvalue);
|
||||||
|
bvalue = jedis.hincrBy(bfoo, bbar, -10);
|
||||||
|
assertEquals(-10, bvalue);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -87,6 +153,17 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(0, jedis.hexists("bar", "foo").intValue());
|
assertEquals(0, jedis.hexists("bar", "foo").intValue());
|
||||||
assertEquals(0, jedis.hexists("foo", "foo").intValue());
|
assertEquals(0, jedis.hexists("foo", "foo").intValue());
|
||||||
assertEquals(1, jedis.hexists("foo", "bar").intValue());
|
assertEquals(1, jedis.hexists("foo", "bar").intValue());
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>();
|
||||||
|
bhash.put(bbar, bcar);
|
||||||
|
bhash.put(bcar, bbar);
|
||||||
|
jedis.hmset(bfoo, bhash);
|
||||||
|
|
||||||
|
assertEquals(0, jedis.hexists(bbar, bfoo).intValue());
|
||||||
|
assertEquals(0, jedis.hexists(bfoo, bfoo).intValue());
|
||||||
|
assertEquals(1, jedis.hexists(bfoo, bbar).intValue());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -100,6 +177,18 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(0, jedis.hdel("foo", "foo").intValue());
|
assertEquals(0, jedis.hdel("foo", "foo").intValue());
|
||||||
assertEquals(1, jedis.hdel("foo", "bar").intValue());
|
assertEquals(1, jedis.hdel("foo", "bar").intValue());
|
||||||
assertEquals(null, jedis.hget("foo", "bar"));
|
assertEquals(null, jedis.hget("foo", "bar"));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>();
|
||||||
|
bhash.put(bbar, bcar);
|
||||||
|
bhash.put(bcar, bbar);
|
||||||
|
jedis.hmset(bfoo, bhash);
|
||||||
|
|
||||||
|
assertEquals(0, jedis.hdel(bbar, bfoo).intValue());
|
||||||
|
assertEquals(0, jedis.hdel(bfoo, bfoo).intValue());
|
||||||
|
assertEquals(1, jedis.hdel(bfoo, bbar).intValue());
|
||||||
|
assertEquals(null, jedis.hget(bfoo, bbar));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -111,6 +200,16 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
assertEquals(0, jedis.hlen("bar").intValue());
|
assertEquals(0, jedis.hlen("bar").intValue());
|
||||||
assertEquals(2, jedis.hlen("foo").intValue());
|
assertEquals(2, jedis.hlen("foo").intValue());
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>();
|
||||||
|
bhash.put(bbar, bcar);
|
||||||
|
bhash.put(bcar, bbar);
|
||||||
|
jedis.hmset(bfoo, bhash);
|
||||||
|
|
||||||
|
assertEquals(0, jedis.hlen(bbar).intValue());
|
||||||
|
assertEquals(2, jedis.hlen(bfoo).intValue());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -120,11 +219,23 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
|||||||
hash.put("car", "bar");
|
hash.put("car", "bar");
|
||||||
jedis.hmset("foo", hash);
|
jedis.hmset("foo", hash);
|
||||||
|
|
||||||
List<String> keys = jedis.hkeys("foo");
|
Set<String> keys = jedis.hkeys("foo");
|
||||||
List<String> expected = new ArrayList<String>();
|
Set<String> expected = new LinkedHashSet<String>();
|
||||||
expected.add("bar");
|
expected.add("bar");
|
||||||
expected.add("car");
|
expected.add("car");
|
||||||
assertEquals(expected, keys);
|
assertEquals(expected, keys);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
Map<byte[], byte[]> bhash = new LinkedHashMap<byte[], byte[]>();
|
||||||
|
bhash.put(bbar, bcar);
|
||||||
|
bhash.put(bcar, bbar);
|
||||||
|
jedis.hmset(bfoo, bhash);
|
||||||
|
|
||||||
|
Set<byte[]> bkeys = jedis.hkeys(bfoo);
|
||||||
|
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||||
|
bexpected.add(bbar);
|
||||||
|
bexpected.add(bcar);
|
||||||
|
assertEquals(bexpected, bkeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -135,10 +246,21 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
|||||||
jedis.hmset("foo", hash);
|
jedis.hmset("foo", hash);
|
||||||
|
|
||||||
List<String> vals = jedis.hvals("foo");
|
List<String> vals = jedis.hvals("foo");
|
||||||
List<String> expected = new ArrayList<String>();
|
assertEquals(2, vals.size());
|
||||||
expected.add("car");
|
assertTrue(vals.contains("bar"));
|
||||||
expected.add("bar");
|
assertTrue(vals.contains("car"));
|
||||||
assertEquals(expected, vals);
|
|
||||||
|
// Binary
|
||||||
|
Map<byte[], byte[]> bhash = new LinkedHashMap<byte[], byte[]>();
|
||||||
|
bhash.put(bbar, bcar);
|
||||||
|
bhash.put(bcar, bbar);
|
||||||
|
jedis.hmset(bfoo, bhash);
|
||||||
|
|
||||||
|
List<byte[]> bvals = jedis.hvals(bfoo);
|
||||||
|
|
||||||
|
assertEquals(2, bvals.size());
|
||||||
|
assertTrue(arrayContains(bvals, bbar));
|
||||||
|
assertTrue(arrayContains(bvals, bcar));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -149,9 +271,19 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
|||||||
jedis.hmset("foo", h);
|
jedis.hmset("foo", h);
|
||||||
|
|
||||||
Map<String, String> hash = jedis.hgetAll("foo");
|
Map<String, String> hash = jedis.hgetAll("foo");
|
||||||
Map<String, String> expected = new HashMap<String, String>();
|
assertEquals(2, hash.size());
|
||||||
expected.put("bar", "car");
|
assertEquals("car", hash.get("bar"));
|
||||||
expected.put("car", "bar");
|
assertEquals("bar", hash.get("car"));
|
||||||
assertEquals(expected, hash);
|
|
||||||
|
// Binary
|
||||||
|
Map<byte[], byte[]> bh = new HashMap<byte[], byte[]>();
|
||||||
|
bh.put(bbar, bcar);
|
||||||
|
bh.put(bcar, bbar);
|
||||||
|
jedis.hmset(bfoo, bh);
|
||||||
|
Map<byte[], byte[]> bhash = jedis.hgetAll(bfoo);
|
||||||
|
|
||||||
|
assertEquals(2, bhash.size());
|
||||||
|
assertArrayEquals(bcar, bhash.get(bbar));
|
||||||
|
assertArrayEquals(bbar, bhash.get(bcar));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,19 @@ package redis.clients.jedis.tests.commands;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.Iterator;
|
||||||
import junit.framework.Assert;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.tests.HostAndPortUtil;
|
import redis.clients.jedis.tests.HostAndPortUtil;
|
||||||
|
import redis.clients.jedis.tests.JedisTestBase;
|
||||||
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
||||||
|
|
||||||
public abstract class JedisCommandTestBase extends Assert {
|
public abstract class JedisCommandTestBase extends JedisTestBase {
|
||||||
protected static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0);
|
protected static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0);
|
||||||
|
|
||||||
protected Jedis jedis;
|
protected Jedis jedis;
|
||||||
@@ -41,4 +43,44 @@ public abstract class JedisCommandTestBase extends Assert {
|
|||||||
j.flushAll();
|
j.flushAll();
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void assertEquals(List<byte[]> expected, List<byte[]> actual) {
|
||||||
|
assertEquals(expected.size(), actual.size());
|
||||||
|
for (int n = 0; n < expected.size(); n++) {
|
||||||
|
assertArrayEquals(expected.get(n), actual.get(n));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void assertEquals(Set<byte[]> expected, Set<byte[]> actual) {
|
||||||
|
assertEquals(expected.size(), actual.size());
|
||||||
|
Iterator<byte[]> iterator = expected.iterator();
|
||||||
|
Iterator<byte[]> iterator2 = actual.iterator();
|
||||||
|
while (iterator.hasNext() || iterator2.hasNext()) {
|
||||||
|
assertArrayEquals(iterator.next(), iterator2.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean arrayContains(List<byte[]> array, byte[] expected) {
|
||||||
|
for (byte[] a : array) {
|
||||||
|
try {
|
||||||
|
assertArrayEquals(a, expected);
|
||||||
|
return true;
|
||||||
|
} catch (AssertionError e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean setContains(Set<byte[]> set, byte[] expected) {
|
||||||
|
for (byte[] a : set) {
|
||||||
|
try {
|
||||||
|
assertArrayEquals(a, expected);
|
||||||
|
return true;
|
||||||
|
} catch (AssertionError e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -10,12 +10,32 @@ import redis.clients.jedis.Jedis;
|
|||||||
import redis.clients.jedis.JedisException;
|
import redis.clients.jedis.JedisException;
|
||||||
|
|
||||||
public class ListCommandsTest extends JedisCommandTestBase {
|
public class ListCommandsTest extends JedisCommandTestBase {
|
||||||
|
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||||
|
final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
|
||||||
|
final byte[] bcar = { 0x09, 0x0A, 0x0B, 0x0C };
|
||||||
|
final byte[] bA = { 0x0A };
|
||||||
|
final byte[] bB = { 0x0B };
|
||||||
|
final byte[] bC = { 0x0C };
|
||||||
|
final byte[] b1 = { 0x01 };
|
||||||
|
final byte[] b2 = { 0x02 };
|
||||||
|
final byte[] b3 = { 0x03 };
|
||||||
|
final byte[] bhello = { 0x04, 0x02 };
|
||||||
|
final byte[] bx = { 0x02, 0x04 };
|
||||||
|
final byte[] bdst = { 0x11, 0x12, 0x13, 0x14 };
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void rpush() {
|
public void rpush() {
|
||||||
int size = jedis.rpush("foo", "bar");
|
int size = jedis.rpush("foo", "bar");
|
||||||
assertEquals(1, size);
|
assertEquals(1, size);
|
||||||
size = jedis.rpush("foo", "foo");
|
size = jedis.rpush("foo", "foo");
|
||||||
assertEquals(2, size);
|
assertEquals(2, size);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
int bsize = jedis.rpush(bfoo, bbar);
|
||||||
|
assertEquals(1, bsize);
|
||||||
|
bsize = jedis.rpush(bfoo, bfoo);
|
||||||
|
assertEquals(2, bsize);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -24,6 +44,13 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(1, size);
|
assertEquals(1, size);
|
||||||
size = jedis.lpush("foo", "foo");
|
size = jedis.lpush("foo", "foo");
|
||||||
assertEquals(2, size);
|
assertEquals(2, size);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
int bsize = jedis.lpush(bfoo, bbar);
|
||||||
|
assertEquals(1, bsize);
|
||||||
|
bsize = jedis.lpush(bfoo, bfoo);
|
||||||
|
assertEquals(2, bsize);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -32,12 +59,32 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
|||||||
jedis.lpush("foo", "bar");
|
jedis.lpush("foo", "bar");
|
||||||
jedis.lpush("foo", "car");
|
jedis.lpush("foo", "car");
|
||||||
assertEquals(2, jedis.llen("foo").intValue());
|
assertEquals(2, jedis.llen("foo").intValue());
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
assertEquals(0, jedis.llen(bfoo).intValue());
|
||||||
|
jedis.lpush(bfoo, bbar);
|
||||||
|
jedis.lpush(bfoo, bcar);
|
||||||
|
assertEquals(2, jedis.llen(bfoo).intValue());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JedisException.class)
|
@Test
|
||||||
public void llenNotOnList() {
|
public void llenNotOnList() {
|
||||||
|
try {
|
||||||
jedis.set("foo", "bar");
|
jedis.set("foo", "bar");
|
||||||
jedis.llen("foo");
|
jedis.llen("foo");
|
||||||
|
fail("JedisException expected");
|
||||||
|
} catch (final JedisException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
try {
|
||||||
|
jedis.set(bfoo, bbar);
|
||||||
|
jedis.llen(bfoo);
|
||||||
|
fail("JedisException expected");
|
||||||
|
} catch (final JedisException e) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -67,6 +114,34 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
|||||||
expected = new ArrayList<String>();
|
expected = new ArrayList<String>();
|
||||||
range = jedis.lrange("foo", 2, 1);
|
range = jedis.lrange("foo", 2, 1);
|
||||||
assertEquals(expected, range);
|
assertEquals(expected, range);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.rpush(bfoo, bA);
|
||||||
|
jedis.rpush(bfoo, bB);
|
||||||
|
jedis.rpush(bfoo, bC);
|
||||||
|
|
||||||
|
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||||
|
bexpected.add(bA);
|
||||||
|
bexpected.add(bB);
|
||||||
|
bexpected.add(bC);
|
||||||
|
|
||||||
|
List<byte[]> brange = jedis.lrange(bfoo, 0, 2);
|
||||||
|
assertEquals(bexpected, brange);
|
||||||
|
|
||||||
|
brange = jedis.lrange(bfoo, 0, 20);
|
||||||
|
assertEquals(bexpected, brange);
|
||||||
|
|
||||||
|
bexpected = new ArrayList<byte[]>();
|
||||||
|
bexpected.add(bB);
|
||||||
|
bexpected.add(bC);
|
||||||
|
|
||||||
|
brange = jedis.lrange(bfoo, 1, 2);
|
||||||
|
assertEquals(bexpected, brange);
|
||||||
|
|
||||||
|
bexpected = new ArrayList<byte[]>();
|
||||||
|
brange = jedis.lrange(bfoo, 2, 1);
|
||||||
|
assertEquals(bexpected, brange);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -83,6 +158,21 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals("OK", status);
|
assertEquals("OK", status);
|
||||||
assertEquals(2, jedis.llen("foo").intValue());
|
assertEquals(2, jedis.llen("foo").intValue());
|
||||||
assertEquals(expected, jedis.lrange("foo", 0, 100));
|
assertEquals(expected, jedis.lrange("foo", 0, 100));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.lpush(bfoo, b1);
|
||||||
|
jedis.lpush(bfoo, b2);
|
||||||
|
jedis.lpush(bfoo, b3);
|
||||||
|
String bstatus = jedis.ltrim(bfoo, 0, 1);
|
||||||
|
|
||||||
|
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||||
|
bexpected.add(b3);
|
||||||
|
bexpected.add(b2);
|
||||||
|
|
||||||
|
assertEquals("OK", bstatus);
|
||||||
|
assertEquals(2, jedis.llen(bfoo).intValue());
|
||||||
|
assertEquals(bexpected, jedis.lrange(bfoo, 0, 100));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -100,6 +190,21 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
assertEquals("OK", status);
|
assertEquals("OK", status);
|
||||||
assertEquals(expected, jedis.lrange("foo", 0, 100));
|
assertEquals(expected, jedis.lrange("foo", 0, 100));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.lpush(bfoo, b1);
|
||||||
|
jedis.lpush(bfoo, b2);
|
||||||
|
jedis.lpush(bfoo, b3);
|
||||||
|
|
||||||
|
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||||
|
bexpected.add(b3);
|
||||||
|
bexpected.add(bbar);
|
||||||
|
bexpected.add(b1);
|
||||||
|
|
||||||
|
String bstatus = jedis.lset(bfoo, 1, bbar);
|
||||||
|
|
||||||
|
assertEquals("OK", bstatus);
|
||||||
|
assertEquals(bexpected, jedis.lrange(bfoo, 0, 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -110,6 +215,15 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
assertEquals("3", jedis.lindex("foo", 0));
|
assertEquals("3", jedis.lindex("foo", 0));
|
||||||
assertEquals(null, jedis.lindex("foo", 100));
|
assertEquals(null, jedis.lindex("foo", 100));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.lpush(bfoo, b1);
|
||||||
|
jedis.lpush(bfoo, b2);
|
||||||
|
jedis.lpush(bfoo, b3);
|
||||||
|
|
||||||
|
assertArrayEquals(b3, jedis.lindex(bfoo, 0));
|
||||||
|
assertEquals(null, jedis.lindex(bfoo, 100));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -134,6 +248,29 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(2, count);
|
assertEquals(2, count);
|
||||||
assertEquals(expected, jedis.lrange("foo", 0, 1000));
|
assertEquals(expected, jedis.lrange("foo", 0, 1000));
|
||||||
assertEquals(0, jedis.lrem("bar", 100, "foo").intValue());
|
assertEquals(0, jedis.lrem("bar", 100, "foo").intValue());
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.lpush(bfoo, bhello);
|
||||||
|
jedis.lpush(bfoo, bhello);
|
||||||
|
jedis.lpush(bfoo, bx);
|
||||||
|
jedis.lpush(bfoo, bhello);
|
||||||
|
jedis.lpush(bfoo, bC);
|
||||||
|
jedis.lpush(bfoo, bB);
|
||||||
|
jedis.lpush(bfoo, bA);
|
||||||
|
|
||||||
|
int bcount = jedis.lrem(bfoo, -2, bhello);
|
||||||
|
|
||||||
|
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||||
|
bexpected.add(bA);
|
||||||
|
bexpected.add(bB);
|
||||||
|
bexpected.add(bC);
|
||||||
|
bexpected.add(bhello);
|
||||||
|
bexpected.add(bx);
|
||||||
|
|
||||||
|
assertEquals(2, bcount);
|
||||||
|
assertEquals(bexpected, jedis.lrange(bfoo, 0, 1000));
|
||||||
|
assertEquals(0, jedis.lrem(bbar, 100, bfoo).intValue());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -155,6 +292,26 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
element = jedis.lpop("foo");
|
element = jedis.lpop("foo");
|
||||||
assertEquals(null, element);
|
assertEquals(null, element);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.rpush(bfoo, bA);
|
||||||
|
jedis.rpush(bfoo, bB);
|
||||||
|
jedis.rpush(bfoo, bC);
|
||||||
|
|
||||||
|
byte[] belement = jedis.lpop(bfoo);
|
||||||
|
assertArrayEquals(bA, belement);
|
||||||
|
|
||||||
|
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||||
|
bexpected.add(bB);
|
||||||
|
bexpected.add(bC);
|
||||||
|
|
||||||
|
assertEquals(bexpected, jedis.lrange(bfoo, 0, 1000));
|
||||||
|
jedis.lpop(bfoo);
|
||||||
|
jedis.lpop(bfoo);
|
||||||
|
|
||||||
|
belement = jedis.lpop(bfoo);
|
||||||
|
assertEquals(null, belement);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -176,6 +333,26 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
element = jedis.rpop("foo");
|
element = jedis.rpop("foo");
|
||||||
assertEquals(null, element);
|
assertEquals(null, element);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.rpush(bfoo, bA);
|
||||||
|
jedis.rpush(bfoo, bB);
|
||||||
|
jedis.rpush(bfoo, bC);
|
||||||
|
|
||||||
|
byte[] belement = jedis.rpop(bfoo);
|
||||||
|
assertArrayEquals(bC, belement);
|
||||||
|
|
||||||
|
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||||
|
bexpected.add(bA);
|
||||||
|
bexpected.add(bB);
|
||||||
|
|
||||||
|
assertEquals(bexpected, jedis.lrange(bfoo, 0, 1000));
|
||||||
|
jedis.rpop(bfoo);
|
||||||
|
jedis.rpop(bfoo);
|
||||||
|
|
||||||
|
belement = jedis.rpop(bfoo);
|
||||||
|
assertEquals(null, belement);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -202,6 +379,31 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
assertEquals(srcExpected, jedis.lrange("foo", 0, 1000));
|
assertEquals(srcExpected, jedis.lrange("foo", 0, 1000));
|
||||||
assertEquals(dstExpected, jedis.lrange("dst", 0, 1000));
|
assertEquals(dstExpected, jedis.lrange("dst", 0, 1000));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.rpush(bfoo, bA);
|
||||||
|
jedis.rpush(bfoo, bB);
|
||||||
|
jedis.rpush(bfoo, bC);
|
||||||
|
|
||||||
|
jedis.rpush(bdst, bfoo);
|
||||||
|
jedis.rpush(bdst, bbar);
|
||||||
|
|
||||||
|
byte[] belement = jedis.rpoplpush(bfoo, bdst);
|
||||||
|
|
||||||
|
assertArrayEquals(bC, belement);
|
||||||
|
|
||||||
|
List<byte[]> bsrcExpected = new ArrayList<byte[]>();
|
||||||
|
bsrcExpected.add(bA);
|
||||||
|
bsrcExpected.add(bB);
|
||||||
|
|
||||||
|
List<byte[]> bdstExpected = new ArrayList<byte[]>();
|
||||||
|
bdstExpected.add(bC);
|
||||||
|
bdstExpected.add(bfoo);
|
||||||
|
bdstExpected.add(bbar);
|
||||||
|
|
||||||
|
assertEquals(bsrcExpected, jedis.lrange(bfoo, 0, 1000));
|
||||||
|
assertEquals(bdstExpected, jedis.lrange(bdst, 0, 1000));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -226,6 +428,29 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(2, result.size());
|
assertEquals(2, result.size());
|
||||||
assertEquals("foo", result.get(0));
|
assertEquals("foo", result.get(0));
|
||||||
assertEquals("bar", result.get(1));
|
assertEquals("bar", result.get(1));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
List<byte[]> bresult = jedis.blpop(1, bfoo);
|
||||||
|
assertNull(bresult);
|
||||||
|
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Jedis j = createJedis();
|
||||||
|
j.lpush(bfoo, bbar);
|
||||||
|
j.disconnect();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
fail(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
bresult = jedis.blpop(1, bfoo);
|
||||||
|
assertNotNull(bresult);
|
||||||
|
assertEquals(2, bresult.size());
|
||||||
|
assertArrayEquals(bfoo, bresult.get(0));
|
||||||
|
assertArrayEquals(bbar, bresult.get(1));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -250,6 +475,29 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(2, result.size());
|
assertEquals(2, result.size());
|
||||||
assertEquals("foo", result.get(0));
|
assertEquals("foo", result.get(0));
|
||||||
assertEquals("bar", result.get(1));
|
assertEquals("bar", result.get(1));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
List<byte[]> bresult = jedis.brpop(1, bfoo);
|
||||||
|
assertNull(bresult);
|
||||||
|
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Jedis j = createJedis();
|
||||||
|
j.lpush(bfoo, bbar);
|
||||||
|
j.disconnect();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
fail(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
bresult = jedis.brpop(1, bfoo);
|
||||||
|
assertNotNull(bresult);
|
||||||
|
assertEquals(2, bresult.size());
|
||||||
|
assertArrayEquals(bfoo, bresult.get(0));
|
||||||
|
assertArrayEquals(bbar, bresult.get(1));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -260,6 +508,15 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
|||||||
jedis.lpush("foo", "a");
|
jedis.lpush("foo", "a");
|
||||||
status = jedis.lpushx("foo", "b");
|
status = jedis.lpushx("foo", "b");
|
||||||
assertEquals(2, status);
|
assertEquals(2, status);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
int bstatus = jedis.lpushx(bfoo, bbar);
|
||||||
|
assertEquals(0, bstatus);
|
||||||
|
|
||||||
|
jedis.lpush(bfoo, bA);
|
||||||
|
bstatus = jedis.lpushx(bfoo, bB);
|
||||||
|
assertEquals(2, bstatus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -270,6 +527,14 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
|||||||
jedis.lpush("foo", "a");
|
jedis.lpush("foo", "a");
|
||||||
status = jedis.rpushx("foo", "b");
|
status = jedis.rpushx("foo", "b");
|
||||||
assertEquals(2, status);
|
assertEquals(2, status);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
int bstatus = jedis.rpushx(bfoo, bbar);
|
||||||
|
assertEquals(0, bstatus);
|
||||||
|
|
||||||
|
jedis.lpush(bfoo, bA);
|
||||||
|
bstatus = jedis.rpushx(bfoo, bB);
|
||||||
|
assertEquals(2, bstatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -292,5 +557,25 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
|||||||
status = jedis
|
status = jedis
|
||||||
.linsert("foo", Client.LIST_POSITION.BEFORE, "bar", "car");
|
.linsert("foo", Client.LIST_POSITION.BEFORE, "bar", "car");
|
||||||
assertEquals(-1, status);
|
assertEquals(-1, status);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
int bstatus = jedis.linsert(bfoo, Client.LIST_POSITION.BEFORE, bbar,
|
||||||
|
bcar);
|
||||||
|
assertEquals(0, bstatus);
|
||||||
|
|
||||||
|
jedis.lpush(bfoo, bA);
|
||||||
|
bstatus = jedis.linsert(bfoo, Client.LIST_POSITION.AFTER, bA, bB);
|
||||||
|
assertEquals(2, bstatus);
|
||||||
|
|
||||||
|
List<byte[]> bactual = jedis.lrange(bfoo, 0, 100);
|
||||||
|
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||||
|
bexpected.add(bA);
|
||||||
|
bexpected.add(bB);
|
||||||
|
|
||||||
|
assertEquals(bexpected, bactual);
|
||||||
|
|
||||||
|
bstatus = jedis.linsert(bfoo, Client.LIST_POSITION.BEFORE, bbar, bcar);
|
||||||
|
assertEquals(-1, bstatus);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,21 @@
|
|||||||
package redis.clients.jedis.tests.commands;
|
package redis.clients.jedis.tests.commands;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class SetCommandsTest extends JedisCommandTestBase {
|
public class SetCommandsTest extends JedisCommandTestBase {
|
||||||
|
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||||
|
final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
|
||||||
|
final byte[] bcar = { 0x09, 0x0A, 0x0B, 0x0C };
|
||||||
|
final byte[] ba = { 0x0A };
|
||||||
|
final byte[] bb = { 0x0B };
|
||||||
|
final byte[] bc = { 0x0C };
|
||||||
|
final byte[] bd = { 0x0D };
|
||||||
|
final byte[] bx = { 0x42 };
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sadd() {
|
public void sadd() {
|
||||||
int status = jedis.sadd("foo", "a");
|
int status = jedis.sadd("foo", "a");
|
||||||
@@ -13,6 +23,13 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
status = jedis.sadd("foo", "a");
|
status = jedis.sadd("foo", "a");
|
||||||
assertEquals(0, status);
|
assertEquals(0, status);
|
||||||
|
|
||||||
|
int bstatus = jedis.sadd(bfoo, ba);
|
||||||
|
assertEquals(1, bstatus);
|
||||||
|
|
||||||
|
bstatus = jedis.sadd(bfoo, ba);
|
||||||
|
assertEquals(0, bstatus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -27,6 +44,18 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
|||||||
Set<String> members = jedis.smembers("foo");
|
Set<String> members = jedis.smembers("foo");
|
||||||
|
|
||||||
assertEquals(expected, members);
|
assertEquals(expected, members);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.sadd(bfoo, ba);
|
||||||
|
jedis.sadd(bfoo, bb);
|
||||||
|
|
||||||
|
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||||
|
bexpected.add(bb);
|
||||||
|
bexpected.add(ba);
|
||||||
|
|
||||||
|
Set<byte[]> bmembers = jedis.smembers(bfoo);
|
||||||
|
|
||||||
|
assertEquals(bexpected, bmembers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -45,6 +74,24 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
|||||||
status = jedis.srem("foo", "bar");
|
status = jedis.srem("foo", "bar");
|
||||||
|
|
||||||
assertEquals(0, status);
|
assertEquals(0, status);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
|
||||||
|
jedis.sadd(bfoo, ba);
|
||||||
|
jedis.sadd(bfoo, bb);
|
||||||
|
|
||||||
|
int bstatus = jedis.srem(bfoo, ba);
|
||||||
|
|
||||||
|
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||||
|
bexpected.add(bb);
|
||||||
|
|
||||||
|
assertEquals(1, bstatus);
|
||||||
|
assertEquals(bexpected, jedis.smembers(bfoo));
|
||||||
|
|
||||||
|
bstatus = jedis.srem(bfoo, bbar);
|
||||||
|
|
||||||
|
assertEquals(0, bstatus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -59,6 +106,19 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
member = jedis.spop("bar");
|
member = jedis.spop("bar");
|
||||||
assertNull(member);
|
assertNull(member);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.sadd(bfoo, ba);
|
||||||
|
jedis.sadd(bfoo, bb);
|
||||||
|
|
||||||
|
byte[] bmember = jedis.spop(bfoo);
|
||||||
|
|
||||||
|
assertTrue(Arrays.equals(ba, bmember) || Arrays.equals(bb, bmember));
|
||||||
|
assertEquals(1, jedis.smembers(bfoo).size());
|
||||||
|
|
||||||
|
bmember = jedis.spop(bbar);
|
||||||
|
assertNull(bmember);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -82,7 +142,31 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(expectedDst, jedis.smembers("bar"));
|
assertEquals(expectedDst, jedis.smembers("bar"));
|
||||||
|
|
||||||
status = jedis.smove("foo", "bar", "a");
|
status = jedis.smove("foo", "bar", "a");
|
||||||
|
|
||||||
assertEquals(status, 0);
|
assertEquals(status, 0);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.sadd(bfoo, ba);
|
||||||
|
jedis.sadd(bfoo, bb);
|
||||||
|
|
||||||
|
jedis.sadd(bbar, bc);
|
||||||
|
|
||||||
|
int bstatus = jedis.smove(bfoo, bbar, ba);
|
||||||
|
|
||||||
|
Set<byte[]> bexpectedSrc = new LinkedHashSet<byte[]>();
|
||||||
|
bexpectedSrc.add(bb);
|
||||||
|
|
||||||
|
Set<byte[]> bexpectedDst = new LinkedHashSet<byte[]>();
|
||||||
|
bexpectedDst.add(bc);
|
||||||
|
bexpectedDst.add(ba);
|
||||||
|
|
||||||
|
assertEquals(bstatus, 1);
|
||||||
|
assertEquals(bexpectedSrc, jedis.smembers(bfoo));
|
||||||
|
assertEquals(bexpectedDst, jedis.smembers(bbar));
|
||||||
|
|
||||||
|
bstatus = jedis.smove(bfoo, bbar, ba);
|
||||||
|
assertEquals(bstatus, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -96,6 +180,18 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
card = jedis.scard("bar");
|
card = jedis.scard("bar");
|
||||||
assertEquals(0, card);
|
assertEquals(0, card);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.sadd(bfoo, ba);
|
||||||
|
jedis.sadd(bfoo, bb);
|
||||||
|
|
||||||
|
int bcard = jedis.scard(bfoo);
|
||||||
|
|
||||||
|
assertEquals(2, bcard);
|
||||||
|
|
||||||
|
bcard = jedis.scard(bbar);
|
||||||
|
assertEquals(0, bcard);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -108,6 +204,17 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
status = jedis.sismember("foo", "c");
|
status = jedis.sismember("foo", "c");
|
||||||
assertEquals(0, status);
|
assertEquals(0, status);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.sadd(bfoo, ba);
|
||||||
|
jedis.sadd(bfoo, bb);
|
||||||
|
|
||||||
|
int bstatus = jedis.sismember(bfoo, ba);
|
||||||
|
assertEquals(1, bstatus);
|
||||||
|
|
||||||
|
bstatus = jedis.sismember(bfoo, bc);
|
||||||
|
assertEquals(0, bstatus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -123,6 +230,19 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
Set<String> intersection = jedis.sinter("foo", "bar");
|
Set<String> intersection = jedis.sinter("foo", "bar");
|
||||||
assertEquals(expected, intersection);
|
assertEquals(expected, intersection);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.sadd(bfoo, ba);
|
||||||
|
jedis.sadd(bfoo, bb);
|
||||||
|
|
||||||
|
jedis.sadd(bbar, bb);
|
||||||
|
jedis.sadd(bbar, bc);
|
||||||
|
|
||||||
|
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||||
|
bexpected.add(bb);
|
||||||
|
|
||||||
|
Set<byte[]> bintersection = jedis.sinter(bfoo, bbar);
|
||||||
|
assertEquals(bexpected, bintersection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -140,6 +260,22 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(1, status);
|
assertEquals(1, status);
|
||||||
|
|
||||||
assertEquals(expected, jedis.smembers("car"));
|
assertEquals(expected, jedis.smembers("car"));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.sadd(bfoo, ba);
|
||||||
|
jedis.sadd(bfoo, bb);
|
||||||
|
|
||||||
|
jedis.sadd(bbar, bb);
|
||||||
|
jedis.sadd(bbar, bc);
|
||||||
|
|
||||||
|
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||||
|
bexpected.add(bb);
|
||||||
|
|
||||||
|
int bstatus = jedis.sinterstore(bcar, bfoo, bbar);
|
||||||
|
assertEquals(1, bstatus);
|
||||||
|
|
||||||
|
assertEquals(bexpected, jedis.smembers(bcar));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -157,6 +293,22 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
Set<String> union = jedis.sunion("foo", "bar");
|
Set<String> union = jedis.sunion("foo", "bar");
|
||||||
assertEquals(expected, union);
|
assertEquals(expected, union);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.sadd(bfoo, ba);
|
||||||
|
jedis.sadd(bfoo, bb);
|
||||||
|
|
||||||
|
jedis.sadd(bbar, bb);
|
||||||
|
jedis.sadd(bbar, bc);
|
||||||
|
|
||||||
|
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||||
|
bexpected.add(bb);
|
||||||
|
bexpected.add(bc);
|
||||||
|
bexpected.add(ba);
|
||||||
|
|
||||||
|
Set<byte[]> bunion = jedis.sunion(bfoo, bbar);
|
||||||
|
assertEquals(bexpected, bunion);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -176,6 +328,24 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(3, status);
|
assertEquals(3, status);
|
||||||
|
|
||||||
assertEquals(expected, jedis.smembers("car"));
|
assertEquals(expected, jedis.smembers("car"));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.sadd(bfoo, ba);
|
||||||
|
jedis.sadd(bfoo, bb);
|
||||||
|
|
||||||
|
jedis.sadd(bbar, bb);
|
||||||
|
jedis.sadd(bbar, bc);
|
||||||
|
|
||||||
|
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||||
|
bexpected.add(bb);
|
||||||
|
bexpected.add(bc);
|
||||||
|
bexpected.add(ba);
|
||||||
|
|
||||||
|
int bstatus = jedis.sunionstore(bcar, bfoo, bbar);
|
||||||
|
assertEquals(3, bstatus);
|
||||||
|
|
||||||
|
assertEquals(bexpected, jedis.smembers(bcar));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -196,6 +366,25 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
Set<String> diff = jedis.sdiff("foo", "bar", "car");
|
Set<String> diff = jedis.sdiff("foo", "bar", "car");
|
||||||
assertEquals(expected, diff);
|
assertEquals(expected, diff);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.sadd(bfoo, bx);
|
||||||
|
jedis.sadd(bfoo, ba);
|
||||||
|
jedis.sadd(bfoo, bb);
|
||||||
|
jedis.sadd(bfoo, bc);
|
||||||
|
|
||||||
|
jedis.sadd(bbar, bc);
|
||||||
|
|
||||||
|
jedis.sadd(bcar, ba);
|
||||||
|
jedis.sadd(bcar, bd);
|
||||||
|
|
||||||
|
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||||
|
bexpected.add(bb);
|
||||||
|
bexpected.add(bx);
|
||||||
|
|
||||||
|
Set<byte[]> bdiff = jedis.sdiff(bfoo, bbar, bcar);
|
||||||
|
assertEquals(bexpected, bdiff);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -217,6 +406,26 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
|||||||
int status = jedis.sdiffstore("tar", "foo", "bar", "car");
|
int status = jedis.sdiffstore("tar", "foo", "bar", "car");
|
||||||
assertEquals(2, status);
|
assertEquals(2, status);
|
||||||
assertEquals(expected, jedis.smembers("car"));
|
assertEquals(expected, jedis.smembers("car"));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.sadd(bfoo, bx);
|
||||||
|
jedis.sadd(bfoo, ba);
|
||||||
|
jedis.sadd(bfoo, bb);
|
||||||
|
jedis.sadd(bfoo, bc);
|
||||||
|
|
||||||
|
jedis.sadd(bbar, bc);
|
||||||
|
|
||||||
|
jedis.sadd(bcar, ba);
|
||||||
|
jedis.sadd(bcar, bd);
|
||||||
|
|
||||||
|
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||||
|
bexpected.add(bd);
|
||||||
|
bexpected.add(ba);
|
||||||
|
|
||||||
|
int bstatus = jedis.sdiffstore("tar".getBytes(), bfoo, bbar, bcar);
|
||||||
|
assertEquals(2, bstatus);
|
||||||
|
assertEquals(bexpected, jedis.smembers(bcar));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -231,6 +440,19 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
member = jedis.srandmember("bar");
|
member = jedis.srandmember("bar");
|
||||||
assertNull(member);
|
assertNull(member);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.sadd(bfoo, ba);
|
||||||
|
jedis.sadd(bfoo, bb);
|
||||||
|
|
||||||
|
byte[] bmember = jedis.srandmember(bfoo);
|
||||||
|
|
||||||
|
assertTrue(Arrays.equals(ba, bmember) || Arrays.equals(bb, bmember));
|
||||||
|
assertEquals(2, jedis.smembers(bfoo).size());
|
||||||
|
|
||||||
|
bmember = jedis.srandmember(bbar);
|
||||||
|
assertNull(bmember);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,18 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Protocol;
|
||||||
import redis.clients.jedis.Tuple;
|
import redis.clients.jedis.Tuple;
|
||||||
import redis.clients.jedis.ZParams;
|
import redis.clients.jedis.ZParams;
|
||||||
|
|
||||||
public class SortedSetCommandsTest extends JedisCommandTestBase {
|
public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||||
|
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||||
|
final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
|
||||||
|
final byte[] bcar = { 0x09, 0x0A, 0x0B, 0x0C };
|
||||||
|
final byte[] ba = { 0x0A };
|
||||||
|
final byte[] bb = { 0x0B };
|
||||||
|
final byte[] bc = { 0x0C };
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void zadd() {
|
public void zadd() {
|
||||||
int status = jedis.zadd("foo", 1d, "a");
|
int status = jedis.zadd("foo", 1d, "a");
|
||||||
@@ -22,6 +30,20 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
status = jedis.zadd("foo", 2d, "a");
|
status = jedis.zadd("foo", 2d, "a");
|
||||||
assertEquals(0, status);
|
assertEquals(0, status);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
int bstatus = jedis.zadd(bfoo, 1d, ba);
|
||||||
|
assertEquals(1, bstatus);
|
||||||
|
|
||||||
|
bstatus = jedis.zadd(bfoo, 10d, bb);
|
||||||
|
assertEquals(1, bstatus);
|
||||||
|
|
||||||
|
bstatus = jedis.zadd(bfoo, 0.1d, bc);
|
||||||
|
assertEquals(1, bstatus);
|
||||||
|
|
||||||
|
bstatus = jedis.zadd(bfoo, 2d, ba);
|
||||||
|
assertEquals(0, bstatus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -41,6 +63,24 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add("b");
|
expected.add("b");
|
||||||
range = jedis.zrange("foo", 0, 100);
|
range = jedis.zrange("foo", 0, 100);
|
||||||
assertEquals(expected, range);
|
assertEquals(expected, range);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.zadd(bfoo, 1d, ba);
|
||||||
|
jedis.zadd(bfoo, 10d, bb);
|
||||||
|
jedis.zadd(bfoo, 0.1d, bc);
|
||||||
|
jedis.zadd(bfoo, 2d, ba);
|
||||||
|
|
||||||
|
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||||
|
bexpected.add(bc);
|
||||||
|
bexpected.add(ba);
|
||||||
|
|
||||||
|
Set<byte[]> brange = jedis.zrange(bfoo, 0, 1);
|
||||||
|
assertEquals(bexpected, brange);
|
||||||
|
|
||||||
|
bexpected.add(bb);
|
||||||
|
brange = jedis.zrange(bfoo, 0, 100);
|
||||||
|
assertEquals(bexpected, brange);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -60,6 +100,24 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add("c");
|
expected.add("c");
|
||||||
range = jedis.zrevrange("foo", 0, 100);
|
range = jedis.zrevrange("foo", 0, 100);
|
||||||
assertEquals(expected, range);
|
assertEquals(expected, range);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.zadd(bfoo, 1d, ba);
|
||||||
|
jedis.zadd(bfoo, 10d, bb);
|
||||||
|
jedis.zadd(bfoo, 0.1d, bc);
|
||||||
|
jedis.zadd(bfoo, 2d, ba);
|
||||||
|
|
||||||
|
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||||
|
bexpected.add(bb);
|
||||||
|
bexpected.add(ba);
|
||||||
|
|
||||||
|
Set<byte[]> brange = jedis.zrevrange(bfoo, 0, 1);
|
||||||
|
assertEquals(bexpected, brange);
|
||||||
|
|
||||||
|
bexpected.add(bc);
|
||||||
|
brange = jedis.zrevrange(bfoo, 0, 100);
|
||||||
|
assertEquals(bexpected, brange);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -78,6 +136,23 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
status = jedis.zrem("foo", "bar");
|
status = jedis.zrem("foo", "bar");
|
||||||
|
|
||||||
assertEquals(0, status);
|
assertEquals(0, status);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.zadd(bfoo, 1d, ba);
|
||||||
|
jedis.zadd(bfoo, 2d, bb);
|
||||||
|
|
||||||
|
int bstatus = jedis.zrem(bfoo, ba);
|
||||||
|
|
||||||
|
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||||
|
bexpected.add(bb);
|
||||||
|
|
||||||
|
assertEquals(1, bstatus);
|
||||||
|
assertEquals(bexpected, jedis.zrange(bfoo, 0, 100));
|
||||||
|
|
||||||
|
bstatus = jedis.zrem(bfoo, bbar);
|
||||||
|
|
||||||
|
assertEquals(0, bstatus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -91,8 +166,22 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add("a");
|
expected.add("a");
|
||||||
expected.add("b");
|
expected.add("b");
|
||||||
|
|
||||||
assertEquals(3d, score);
|
assertEquals(3d, score, 0);
|
||||||
assertEquals(expected, jedis.zrange("foo", 0, 100));
|
assertEquals(expected, jedis.zrange("foo", 0, 100));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.zadd(bfoo, 1d, ba);
|
||||||
|
jedis.zadd(bfoo, 2d, bb);
|
||||||
|
|
||||||
|
double bscore = jedis.zincrby(bfoo, 2d, ba);
|
||||||
|
|
||||||
|
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||||
|
bexpected.add(bb);
|
||||||
|
bexpected.add(ba);
|
||||||
|
|
||||||
|
assertEquals(3d, bscore, 0);
|
||||||
|
assertEquals(bexpected, jedis.zrange(bfoo, 0, 100));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -108,6 +197,20 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
rank = jedis.zrank("car", "b");
|
rank = jedis.zrank("car", "b");
|
||||||
assertNull(rank);
|
assertNull(rank);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.zadd(bfoo, 1d, ba);
|
||||||
|
jedis.zadd(bfoo, 2d, bb);
|
||||||
|
|
||||||
|
Integer brank = jedis.zrank(bfoo, ba);
|
||||||
|
assertEquals(0, brank.intValue());
|
||||||
|
|
||||||
|
brank = jedis.zrank(bfoo, bb);
|
||||||
|
assertEquals(1, brank.intValue());
|
||||||
|
|
||||||
|
brank = jedis.zrank(bcar, bb);
|
||||||
|
assertNull(brank);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -120,6 +223,17 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
rank = jedis.zrevrank("foo", "b");
|
rank = jedis.zrevrank("foo", "b");
|
||||||
assertEquals(0, rank);
|
assertEquals(0, rank);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.zadd(bfoo, 1d, ba);
|
||||||
|
jedis.zadd(bfoo, 2d, bb);
|
||||||
|
|
||||||
|
int brank = jedis.zrevrank(bfoo, ba);
|
||||||
|
assertEquals(1, brank);
|
||||||
|
|
||||||
|
brank = jedis.zrevrank(bfoo, bb);
|
||||||
|
assertEquals(0, brank);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -139,6 +253,24 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add(new Tuple("b", 10d));
|
expected.add(new Tuple("b", 10d));
|
||||||
range = jedis.zrangeWithScores("foo", 0, 100);
|
range = jedis.zrangeWithScores("foo", 0, 100);
|
||||||
assertEquals(expected, range);
|
assertEquals(expected, range);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.zadd(bfoo, 1d, ba);
|
||||||
|
jedis.zadd(bfoo, 10d, bb);
|
||||||
|
jedis.zadd(bfoo, 0.1d, bc);
|
||||||
|
jedis.zadd(bfoo, 2d, ba);
|
||||||
|
|
||||||
|
Set<Tuple> bexpected = new LinkedHashSet<Tuple>();
|
||||||
|
bexpected.add(new Tuple(bc, 0.1d));
|
||||||
|
bexpected.add(new Tuple(ba, 2d));
|
||||||
|
|
||||||
|
Set<Tuple> brange = jedis.zrangeWithScores(bfoo, 0, 1);
|
||||||
|
assertEquals(bexpected, brange);
|
||||||
|
|
||||||
|
bexpected.add(new Tuple(bb, 10d));
|
||||||
|
brange = jedis.zrangeWithScores(bfoo, 0, 100);
|
||||||
|
assertEquals(bexpected, brange);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -158,6 +290,24 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add(new Tuple("c", 0.1d));
|
expected.add(new Tuple("c", 0.1d));
|
||||||
range = jedis.zrevrangeWithScores("foo", 0, 100);
|
range = jedis.zrevrangeWithScores("foo", 0, 100);
|
||||||
assertEquals(expected, range);
|
assertEquals(expected, range);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.zadd(bfoo, 1d, ba);
|
||||||
|
jedis.zadd(bfoo, 10d, bb);
|
||||||
|
jedis.zadd(bfoo, 0.1d, bc);
|
||||||
|
jedis.zadd(bfoo, 2d, ba);
|
||||||
|
|
||||||
|
Set<Tuple> bexpected = new LinkedHashSet<Tuple>();
|
||||||
|
bexpected.add(new Tuple(bb, 10d));
|
||||||
|
bexpected.add(new Tuple(ba, 2d));
|
||||||
|
|
||||||
|
Set<Tuple> brange = jedis.zrevrangeWithScores(bfoo, 0, 1);
|
||||||
|
assertEquals(bexpected, brange);
|
||||||
|
|
||||||
|
bexpected.add(new Tuple(bc, 0.1d));
|
||||||
|
brange = jedis.zrevrangeWithScores(bfoo, 0, 100);
|
||||||
|
assertEquals(bexpected, brange);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -169,6 +319,16 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
int size = jedis.zcard("foo");
|
int size = jedis.zcard("foo");
|
||||||
assertEquals(3, size);
|
assertEquals(3, size);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.zadd(bfoo, 1d, ba);
|
||||||
|
jedis.zadd(bfoo, 10d, bb);
|
||||||
|
jedis.zadd(bfoo, 0.1d, bc);
|
||||||
|
jedis.zadd(bfoo, 2d, ba);
|
||||||
|
|
||||||
|
int bsize = jedis.zcard(bfoo);
|
||||||
|
assertEquals(3, bsize);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -179,13 +339,29 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
jedis.zadd("foo", 2d, "a");
|
jedis.zadd("foo", 2d, "a");
|
||||||
|
|
||||||
Double score = jedis.zscore("foo", "b");
|
Double score = jedis.zscore("foo", "b");
|
||||||
assertEquals(10d, score);
|
assertEquals((Double) 10d, score);
|
||||||
|
|
||||||
score = jedis.zscore("foo", "c");
|
score = jedis.zscore("foo", "c");
|
||||||
assertEquals(0.1d, score);
|
assertEquals((Double) 0.1d, score);
|
||||||
|
|
||||||
score = jedis.zscore("foo", "s");
|
score = jedis.zscore("foo", "s");
|
||||||
assertNull(score);
|
assertNull(score);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.zadd(bfoo, 1d, ba);
|
||||||
|
jedis.zadd(bfoo, 10d, bb);
|
||||||
|
jedis.zadd(bfoo, 0.1d, bc);
|
||||||
|
jedis.zadd(bfoo, 2d, ba);
|
||||||
|
|
||||||
|
Double bscore = jedis.zscore(bfoo, bb);
|
||||||
|
assertEquals((Double) 10d, bscore);
|
||||||
|
|
||||||
|
bscore = jedis.zscore(bfoo, bc);
|
||||||
|
assertEquals((Double) 0.1d, bscore);
|
||||||
|
|
||||||
|
bscore = jedis.zscore(bfoo, "s".getBytes(Protocol.UTF8));
|
||||||
|
assertNull(bscore);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -198,6 +374,17 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
int result = jedis.zcount("foo", 0.01d, 2.1d);
|
int result = jedis.zcount("foo", 0.01d, 2.1d);
|
||||||
|
|
||||||
assertEquals(2, result);
|
assertEquals(2, result);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.zadd(bfoo, 1d, ba);
|
||||||
|
jedis.zadd(bfoo, 10d, bb);
|
||||||
|
jedis.zadd(bfoo, 0.1d, bc);
|
||||||
|
jedis.zadd(bfoo, 2d, ba);
|
||||||
|
|
||||||
|
int bresult = jedis.zcount(bfoo, 0.01d, 2.1d);
|
||||||
|
|
||||||
|
assertEquals(2, bresult);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -230,6 +417,38 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add("a");
|
expected.add("a");
|
||||||
|
|
||||||
assertEquals(expected, range);
|
assertEquals(expected, range);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.zadd(bfoo, 1d, ba);
|
||||||
|
jedis.zadd(bfoo, 10d, bb);
|
||||||
|
jedis.zadd(bfoo, 0.1d, bc);
|
||||||
|
jedis.zadd(bfoo, 2d, ba);
|
||||||
|
|
||||||
|
Set<byte[]> brange = jedis.zrangeByScore(bfoo, 0d, 2d);
|
||||||
|
|
||||||
|
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||||
|
bexpected.add(bc);
|
||||||
|
bexpected.add(ba);
|
||||||
|
|
||||||
|
assertEquals(bexpected, brange);
|
||||||
|
|
||||||
|
brange = jedis.zrangeByScore(bfoo, 0d, 2d, 0, 1);
|
||||||
|
|
||||||
|
bexpected = new LinkedHashSet<byte[]>();
|
||||||
|
bexpected.add(bc);
|
||||||
|
|
||||||
|
assertEquals(bexpected, brange);
|
||||||
|
|
||||||
|
brange = jedis.zrangeByScore(bfoo, 0d, 2d, 1, 1);
|
||||||
|
Set<byte[]> brange2 = jedis.zrangeByScore(bfoo, "-inf"
|
||||||
|
.getBytes(Protocol.UTF8), "(2".getBytes(Protocol.UTF8));
|
||||||
|
assertEquals(bexpected, brange2);
|
||||||
|
|
||||||
|
bexpected = new LinkedHashSet<byte[]>();
|
||||||
|
bexpected.add(ba);
|
||||||
|
|
||||||
|
assertEquals(bexpected, brange);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -260,6 +479,36 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add(new Tuple("a", 2d));
|
expected.add(new Tuple("a", 2d));
|
||||||
|
|
||||||
assertEquals(expected, range);
|
assertEquals(expected, range);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
|
||||||
|
jedis.zadd(bfoo, 1d, ba);
|
||||||
|
jedis.zadd(bfoo, 10d, bb);
|
||||||
|
jedis.zadd(bfoo, 0.1d, bc);
|
||||||
|
jedis.zadd(bfoo, 2d, ba);
|
||||||
|
|
||||||
|
Set<Tuple> brange = jedis.zrangeByScoreWithScores(bfoo, 0d, 2d);
|
||||||
|
|
||||||
|
Set<Tuple> bexpected = new LinkedHashSet<Tuple>();
|
||||||
|
bexpected.add(new Tuple(bc, 0.1d));
|
||||||
|
bexpected.add(new Tuple(ba, 2d));
|
||||||
|
|
||||||
|
assertEquals(bexpected, brange);
|
||||||
|
|
||||||
|
brange = jedis.zrangeByScoreWithScores(bfoo, 0d, 2d, 0, 1);
|
||||||
|
|
||||||
|
bexpected = new LinkedHashSet<Tuple>();
|
||||||
|
bexpected.add(new Tuple(bc, 0.1d));
|
||||||
|
|
||||||
|
assertEquals(bexpected, brange);
|
||||||
|
|
||||||
|
brange = jedis.zrangeByScoreWithScores(bfoo, 0d, 2d, 1, 1);
|
||||||
|
|
||||||
|
bexpected = new LinkedHashSet<Tuple>();
|
||||||
|
bexpected.add(new Tuple(ba, 2d));
|
||||||
|
|
||||||
|
assertEquals(bexpected, brange);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -278,6 +527,23 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add("b");
|
expected.add("b");
|
||||||
|
|
||||||
assertEquals(expected, jedis.zrange("foo", 0, 100));
|
assertEquals(expected, jedis.zrange("foo", 0, 100));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.zadd(bfoo, 1d, ba);
|
||||||
|
jedis.zadd(bfoo, 10d, bb);
|
||||||
|
jedis.zadd(bfoo, 0.1d, bc);
|
||||||
|
jedis.zadd(bfoo, 2d, ba);
|
||||||
|
|
||||||
|
int bresult = jedis.zremrangeByRank(bfoo, 0, 0);
|
||||||
|
|
||||||
|
assertEquals(1, bresult);
|
||||||
|
|
||||||
|
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||||
|
bexpected.add(ba);
|
||||||
|
bexpected.add(bb);
|
||||||
|
|
||||||
|
assertEquals(bexpected, jedis.zrange(bfoo, 0, 100));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -295,6 +561,21 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add("b");
|
expected.add("b");
|
||||||
|
|
||||||
assertEquals(expected, jedis.zrange("foo", 0, 100));
|
assertEquals(expected, jedis.zrange("foo", 0, 100));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.zadd(bfoo, 1d, ba);
|
||||||
|
jedis.zadd(bfoo, 10d, bb);
|
||||||
|
jedis.zadd(bfoo, 0.1d, bc);
|
||||||
|
jedis.zadd(bfoo, 2d, ba);
|
||||||
|
|
||||||
|
int bresult = jedis.zremrangeByScore(bfoo, 0, 2);
|
||||||
|
|
||||||
|
assertEquals(2, bresult);
|
||||||
|
|
||||||
|
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||||
|
bexpected.add(bb);
|
||||||
|
|
||||||
|
assertEquals(bexpected, jedis.zrange(bfoo, 0, 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -313,6 +594,24 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add(new Tuple("a", new Double(3)));
|
expected.add(new Tuple("a", new Double(3)));
|
||||||
|
|
||||||
assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100));
|
assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.zadd(bfoo, 1, ba);
|
||||||
|
jedis.zadd(bfoo, 2, bb);
|
||||||
|
jedis.zadd(bbar, 2, ba);
|
||||||
|
jedis.zadd(bbar, 2, bb);
|
||||||
|
|
||||||
|
int bresult = jedis.zunionstore("dst".getBytes(Protocol.UTF8), bfoo,
|
||||||
|
bbar);
|
||||||
|
|
||||||
|
assertEquals(2, bresult);
|
||||||
|
|
||||||
|
Set<Tuple> bexpected = new LinkedHashSet<Tuple>();
|
||||||
|
bexpected.add(new Tuple(bb, new Double(4)));
|
||||||
|
bexpected.add(new Tuple(ba, new Double(3)));
|
||||||
|
|
||||||
|
assertEquals(bexpected, jedis.zrangeWithScores("dst"
|
||||||
|
.getBytes(Protocol.UTF8), 0, 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -334,6 +633,27 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add(new Tuple("a", new Double(6)));
|
expected.add(new Tuple("a", new Double(6)));
|
||||||
|
|
||||||
assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100));
|
assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.zadd(bfoo, 1, ba);
|
||||||
|
jedis.zadd(bfoo, 2, bb);
|
||||||
|
jedis.zadd(bbar, 2, ba);
|
||||||
|
jedis.zadd(bbar, 2, bb);
|
||||||
|
|
||||||
|
ZParams bparams = new ZParams();
|
||||||
|
bparams.weights(2, 2);
|
||||||
|
bparams.aggregate(ZParams.Aggregate.SUM);
|
||||||
|
int bresult = jedis.zunionstore("dst".getBytes(Protocol.UTF8), bparams,
|
||||||
|
bfoo, bbar);
|
||||||
|
|
||||||
|
assertEquals(2, bresult);
|
||||||
|
|
||||||
|
Set<Tuple> bexpected = new LinkedHashSet<Tuple>();
|
||||||
|
bexpected.add(new Tuple(bb, new Double(8)));
|
||||||
|
bexpected.add(new Tuple(ba, new Double(6)));
|
||||||
|
|
||||||
|
assertEquals(bexpected, jedis.zrangeWithScores("dst"
|
||||||
|
.getBytes(Protocol.UTF8), 0, 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -350,6 +670,22 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add(new Tuple("a", new Double(3)));
|
expected.add(new Tuple("a", new Double(3)));
|
||||||
|
|
||||||
assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100));
|
assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.zadd(bfoo, 1, ba);
|
||||||
|
jedis.zadd(bfoo, 2, bb);
|
||||||
|
jedis.zadd(bbar, 2, ba);
|
||||||
|
|
||||||
|
int bresult = jedis.zinterstore("dst".getBytes(Protocol.UTF8), bfoo,
|
||||||
|
bbar);
|
||||||
|
|
||||||
|
assertEquals(1, bresult);
|
||||||
|
|
||||||
|
Set<Tuple> bexpected = new LinkedHashSet<Tuple>();
|
||||||
|
bexpected.add(new Tuple(ba, new Double(3)));
|
||||||
|
|
||||||
|
assertEquals(bexpected, jedis.zrangeWithScores("dst"
|
||||||
|
.getBytes(Protocol.UTF8), 0, 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -369,5 +705,24 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add(new Tuple("a", new Double(6)));
|
expected.add(new Tuple("a", new Double(6)));
|
||||||
|
|
||||||
assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100));
|
assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.zadd(bfoo, 1, ba);
|
||||||
|
jedis.zadd(bfoo, 2, bb);
|
||||||
|
jedis.zadd(bbar, 2, ba);
|
||||||
|
|
||||||
|
ZParams bparams = new ZParams();
|
||||||
|
bparams.weights(2, 2);
|
||||||
|
bparams.aggregate(ZParams.Aggregate.SUM);
|
||||||
|
int bresult = jedis.zinterstore("dst".getBytes(Protocol.UTF8), bparams,
|
||||||
|
bfoo, bbar);
|
||||||
|
|
||||||
|
assertEquals(1, bresult);
|
||||||
|
|
||||||
|
Set<Tuple> bexpected = new LinkedHashSet<Tuple>();
|
||||||
|
bexpected.add(new Tuple(ba, new Double(6)));
|
||||||
|
|
||||||
|
assertEquals(bexpected, jedis.zrangeWithScores("dst"
|
||||||
|
.getBytes(Protocol.UTF8), 0, 100));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,21 @@ import org.junit.Test;
|
|||||||
import redis.clients.jedis.SortingParams;
|
import redis.clients.jedis.SortingParams;
|
||||||
|
|
||||||
public class SortingCommandsTest extends JedisCommandTestBase {
|
public class SortingCommandsTest extends JedisCommandTestBase {
|
||||||
|
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||||
|
final byte[] bbar1 = { 0x05, 0x06, 0x07, 0x08, '1' };
|
||||||
|
final byte[] bbar2 = { 0x05, 0x06, 0x07, 0x08, '2' };
|
||||||
|
final byte[] bbar3 = { 0x05, 0x06, 0x07, 0x08, '3' };
|
||||||
|
final byte[] bbar10 = { 0x05, 0x06, 0x07, 0x08, '1', '0' };
|
||||||
|
final byte[] bbarstar = { 0x05, 0x06, 0x07, 0x08, '*' };
|
||||||
|
final byte[] bcar1 = { 0x0A, 0x0B, 0x0C, 0x0D, '1' };
|
||||||
|
final byte[] bcar2 = { 0x0A, 0x0B, 0x0C, 0x0D, '2' };
|
||||||
|
final byte[] bcar10 = { 0x0A, 0x0B, 0x0C, 0x0D, '1', '0' };
|
||||||
|
final byte[] bcarstar = { 0x0A, 0x0B, 0x0C, 0x0D, '*' };
|
||||||
|
final byte[] b1 = { '1' };
|
||||||
|
final byte[] b2 = { '2' };
|
||||||
|
final byte[] b3 = { '3' };
|
||||||
|
final byte[] b10 = { '1', '0' };
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sort() {
|
public void sort() {
|
||||||
jedis.lpush("foo", "3");
|
jedis.lpush("foo", "3");
|
||||||
@@ -22,6 +37,20 @@ public class SortingCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add("3");
|
expected.add("3");
|
||||||
|
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.lpush(bfoo, b3);
|
||||||
|
jedis.lpush(bfoo, b2);
|
||||||
|
jedis.lpush(bfoo, b1);
|
||||||
|
|
||||||
|
List<byte[]> bresult = jedis.sort(bfoo);
|
||||||
|
|
||||||
|
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||||
|
bexpected.add(b1);
|
||||||
|
bexpected.add(b2);
|
||||||
|
bexpected.add(b3);
|
||||||
|
|
||||||
|
assertEquals(bexpected, bresult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -45,6 +74,28 @@ public class SortingCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add("1");
|
expected.add("1");
|
||||||
|
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.lpush(bfoo, b2);
|
||||||
|
jedis.lpush(bfoo, b3);
|
||||||
|
jedis.lpush(bfoo, b1);
|
||||||
|
|
||||||
|
jedis.set(bbar1, b3);
|
||||||
|
jedis.set(bbar2, b2);
|
||||||
|
jedis.set(bbar3, b1);
|
||||||
|
|
||||||
|
SortingParams bsp = new SortingParams();
|
||||||
|
bsp.by(bbarstar);
|
||||||
|
|
||||||
|
List<byte[]> bresult = jedis.sort(bfoo, bsp);
|
||||||
|
|
||||||
|
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||||
|
bexpected.add(b3);
|
||||||
|
bexpected.add(b2);
|
||||||
|
bexpected.add(b1);
|
||||||
|
|
||||||
|
assertEquals(bexpected, bresult);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -64,6 +115,23 @@ public class SortingCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add("1");
|
expected.add("1");
|
||||||
|
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.lpush(bfoo, b3);
|
||||||
|
jedis.lpush(bfoo, b2);
|
||||||
|
jedis.lpush(bfoo, b1);
|
||||||
|
|
||||||
|
SortingParams bsp = new SortingParams();
|
||||||
|
bsp.desc();
|
||||||
|
|
||||||
|
List<byte[]> bresult = jedis.sort(bfoo, bsp);
|
||||||
|
|
||||||
|
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||||
|
bexpected.add(b3);
|
||||||
|
bexpected.add(b2);
|
||||||
|
bexpected.add(b1);
|
||||||
|
|
||||||
|
assertEquals(bexpected, bresult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -83,6 +151,24 @@ public class SortingCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add("3");
|
expected.add("3");
|
||||||
|
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.rpush(bfoo, new byte[] { (byte) '4' });
|
||||||
|
jedis.rpush(bfoo, new byte[] { (byte) '3' });
|
||||||
|
jedis.rpush(bfoo, new byte[] { (byte) '2' });
|
||||||
|
jedis.rpush(bfoo, new byte[] { (byte) '1' });
|
||||||
|
|
||||||
|
SortingParams bsp = new SortingParams();
|
||||||
|
bsp.limit(0, 3);
|
||||||
|
|
||||||
|
List<byte[]> bresult = jedis.sort(bfoo, bsp);
|
||||||
|
|
||||||
|
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||||
|
bexpected.add(b1);
|
||||||
|
bexpected.add(b2);
|
||||||
|
bexpected.add(b3);
|
||||||
|
|
||||||
|
assertEquals(bexpected, bresult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -102,6 +188,23 @@ public class SortingCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add("2");
|
expected.add("2");
|
||||||
|
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.lpush(bfoo, b1);
|
||||||
|
jedis.lpush(bfoo, b2);
|
||||||
|
jedis.lpush(bfoo, b10);
|
||||||
|
|
||||||
|
SortingParams bsp = new SortingParams();
|
||||||
|
bsp.alpha();
|
||||||
|
|
||||||
|
List<byte[]> bresult = jedis.sort(bfoo, bsp);
|
||||||
|
|
||||||
|
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||||
|
bexpected.add(b1);
|
||||||
|
bexpected.add(b10);
|
||||||
|
bexpected.add(b2);
|
||||||
|
|
||||||
|
assertEquals(bexpected, bresult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -132,6 +235,34 @@ public class SortingCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add("bar10");
|
expected.add("bar10");
|
||||||
|
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.lpush(bfoo, b1);
|
||||||
|
jedis.lpush(bfoo, b2);
|
||||||
|
jedis.lpush(bfoo, b10);
|
||||||
|
|
||||||
|
jedis.set(bbar1, bbar1);
|
||||||
|
jedis.set(bbar2, bbar2);
|
||||||
|
jedis.set(bbar10, bbar10);
|
||||||
|
|
||||||
|
jedis.set(bcar1, bcar1);
|
||||||
|
jedis.set(bcar2, bcar2);
|
||||||
|
jedis.set(bcar10, bcar10);
|
||||||
|
|
||||||
|
SortingParams bsp = new SortingParams();
|
||||||
|
bsp.get(bcarstar, bbarstar);
|
||||||
|
|
||||||
|
List<byte[]> bresult = jedis.sort(bfoo, bsp);
|
||||||
|
|
||||||
|
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||||
|
bexpected.add(bcar1);
|
||||||
|
bexpected.add(bbar1);
|
||||||
|
bexpected.add(bcar2);
|
||||||
|
bexpected.add(bbar2);
|
||||||
|
bexpected.add(bcar10);
|
||||||
|
bexpected.add(bbar10);
|
||||||
|
|
||||||
|
assertEquals(bexpected, bresult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -149,6 +280,22 @@ public class SortingCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
assertEquals(3, result);
|
assertEquals(3, result);
|
||||||
assertEquals(expected, jedis.lrange("result", 0, 1000));
|
assertEquals(expected, jedis.lrange("result", 0, 1000));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.lpush(bfoo, b1);
|
||||||
|
jedis.lpush(bfoo, b2);
|
||||||
|
jedis.lpush(bfoo, b10);
|
||||||
|
|
||||||
|
byte[] bkresult = new byte[] { 0X09, 0x0A, 0x0B, 0x0C };
|
||||||
|
int bresult = jedis.sort(bfoo, bkresult);
|
||||||
|
|
||||||
|
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||||
|
bexpected.add(b1);
|
||||||
|
bexpected.add(b2);
|
||||||
|
bexpected.add(b10);
|
||||||
|
|
||||||
|
assertEquals(3, bresult);
|
||||||
|
assertEquals(bexpected, jedis.lrange(bkresult, 0, 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ package redis.clients.jedis.tests.commands;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -10,11 +11,21 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.JedisException;
|
import redis.clients.jedis.JedisException;
|
||||||
|
import redis.clients.jedis.Protocol;
|
||||||
import redis.clients.jedis.Transaction;
|
import redis.clients.jedis.Transaction;
|
||||||
import redis.clients.jedis.TransactionBlock;
|
import redis.clients.jedis.TransactionBlock;
|
||||||
|
import redis.clients.jedis.Protocol.Keyword;
|
||||||
|
|
||||||
public class TransactionCommandsTest extends JedisCommandTestBase {
|
public class TransactionCommandsTest extends JedisCommandTestBase {
|
||||||
|
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||||
|
final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
|
||||||
|
final byte[] ba = { 0x0A };
|
||||||
|
final byte[] bb = { 0x0B };
|
||||||
|
|
||||||
|
final byte[] bmykey = { 0x42, 0x02, 0x03, 0x04 };
|
||||||
|
|
||||||
Jedis nj;
|
Jedis nj;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
@@ -30,13 +41,13 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
|||||||
Transaction trans = jedis.multi();
|
Transaction trans = jedis.multi();
|
||||||
|
|
||||||
String status = trans.sadd("foo", "a");
|
String status = trans.sadd("foo", "a");
|
||||||
assertEquals("QUEUED", status);
|
assertEquals(Keyword.QUEUED.name(), status);
|
||||||
|
|
||||||
status = trans.sadd("foo", "b");
|
status = trans.sadd("foo", "b");
|
||||||
assertEquals("QUEUED", status);
|
assertEquals(Keyword.QUEUED.name(), status);
|
||||||
|
|
||||||
status = trans.scard("foo");
|
status = trans.scard("foo");
|
||||||
assertEquals("QUEUED", status);
|
assertEquals(Keyword.QUEUED.name(), status);
|
||||||
|
|
||||||
List<Object> response = trans.exec();
|
List<Object> response = trans.exec();
|
||||||
|
|
||||||
@@ -45,6 +56,27 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add(1);
|
expected.add(1);
|
||||||
expected.add(2);
|
expected.add(2);
|
||||||
assertEquals(expected, response);
|
assertEquals(expected, response);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
trans = jedis.multi();
|
||||||
|
|
||||||
|
status = trans.sadd(bfoo, ba);
|
||||||
|
assertEquals(Keyword.QUEUED.name(), status);
|
||||||
|
|
||||||
|
status = trans.sadd(bfoo, bb);
|
||||||
|
assertEquals(Keyword.QUEUED.name(), status);
|
||||||
|
|
||||||
|
status = trans.scard(bfoo);
|
||||||
|
assertEquals(Keyword.QUEUED.name(), status);
|
||||||
|
|
||||||
|
response = trans.exec();
|
||||||
|
|
||||||
|
expected = new ArrayList<Object>();
|
||||||
|
expected.add(1);
|
||||||
|
expected.add(1);
|
||||||
|
expected.add(2);
|
||||||
|
assertEquals(expected, response);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -52,13 +84,13 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
|||||||
List<Object> response = jedis.multi(new TransactionBlock() {
|
List<Object> response = jedis.multi(new TransactionBlock() {
|
||||||
public void execute() {
|
public void execute() {
|
||||||
String status = sadd("foo", "a");
|
String status = sadd("foo", "a");
|
||||||
assertEquals("QUEUED", status);
|
assertEquals(Keyword.QUEUED.name(), status);
|
||||||
|
|
||||||
status = sadd("foo", "b");
|
status = sadd("foo", "b");
|
||||||
assertEquals("QUEUED", status);
|
assertEquals(Keyword.QUEUED.name(), status);
|
||||||
|
|
||||||
status = scard("foo");
|
status = scard("foo");
|
||||||
assertEquals("QUEUED", status);
|
assertEquals(Keyword.QUEUED.name(), status);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -67,6 +99,27 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
|||||||
expected.add(1);
|
expected.add(1);
|
||||||
expected.add(2);
|
expected.add(2);
|
||||||
assertEquals(expected, response);
|
assertEquals(expected, response);
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
response = jedis.multi(new TransactionBlock() {
|
||||||
|
public void execute() {
|
||||||
|
String status = sadd(bfoo, ba);
|
||||||
|
assertEquals(Keyword.QUEUED.name(), status);
|
||||||
|
|
||||||
|
status = sadd(bfoo, bb);
|
||||||
|
assertEquals(Keyword.QUEUED.name(), status);
|
||||||
|
|
||||||
|
status = scard(bfoo);
|
||||||
|
assertEquals(Keyword.QUEUED.name(), status);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expected = new ArrayList<Object>();
|
||||||
|
expected.add(1);
|
||||||
|
expected.add(1);
|
||||||
|
expected.add(2);
|
||||||
|
assertEquals(expected, response);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -83,6 +136,20 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
|||||||
List<Object> resp = t.exec();
|
List<Object> resp = t.exec();
|
||||||
assertEquals(null, resp);
|
assertEquals(null, resp);
|
||||||
assertEquals("bar", jedis.get("mykey"));
|
assertEquals("bar", jedis.get("mykey"));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.watch(bmykey);
|
||||||
|
t = jedis.multi();
|
||||||
|
|
||||||
|
nj.connect();
|
||||||
|
nj.auth("foobared");
|
||||||
|
nj.set(bmykey, bbar);
|
||||||
|
nj.disconnect();
|
||||||
|
|
||||||
|
t.set(bmykey, bfoo);
|
||||||
|
resp = t.exec();
|
||||||
|
assertEquals(null, resp);
|
||||||
|
assertTrue(Arrays.equals(bbar, jedis.get(bmykey)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -101,9 +168,28 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
t.set("mykey", val);
|
t.set("mykey", val);
|
||||||
List<Object> resp = t.exec();
|
List<Object> resp = t.exec();
|
||||||
List<Object> expected = new ArrayList<Object>();
|
assertEquals(1, resp.size());
|
||||||
expected.add("OK");
|
assertArrayEquals(Keyword.OK.name().getBytes(Protocol.UTF8),
|
||||||
assertEquals(expected, resp);
|
(byte[]) resp.get(0));
|
||||||
|
|
||||||
|
// Binary
|
||||||
|
jedis.watch(bmykey);
|
||||||
|
byte[] bval = jedis.get(bmykey);
|
||||||
|
bval = bfoo;
|
||||||
|
status = jedis.unwatch();
|
||||||
|
assertEquals(Keyword.OK.name(), status);
|
||||||
|
t = jedis.multi();
|
||||||
|
|
||||||
|
nj.connect();
|
||||||
|
nj.auth("foobared");
|
||||||
|
nj.set(bmykey, bbar);
|
||||||
|
nj.disconnect();
|
||||||
|
|
||||||
|
t.set(bmykey, bval);
|
||||||
|
resp = t.exec();
|
||||||
|
assertEquals(1, resp.size());
|
||||||
|
assertArrayEquals(Keyword.OK.name().getBytes(Protocol.UTF8),
|
||||||
|
(byte[]) resp.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JedisException.class)
|
@Test(expected = JedisException.class)
|
||||||
|
|||||||
BIN
src/test/resources/MySimpson.png
Normal file
BIN
src/test/resources/MySimpson.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
Reference in New Issue
Block a user