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:
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();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,7 @@ import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import redis.clients.jedis.Protocol.Command;
|
||||
import redis.clients.util.RedisInputStream;
|
||||
import redis.clients.util.RedisOutputStream;
|
||||
|
||||
@@ -24,7 +25,7 @@ public class Connection {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(int timeout) {
|
||||
public void setTimeout(final int timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
@@ -44,18 +45,46 @@ public class Connection {
|
||||
}
|
||||
}
|
||||
|
||||
public Connection(String host) {
|
||||
public Connection(final String host) {
|
||||
super();
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
protected Connection sendCommand(String name, String... args) {
|
||||
protocol.sendCommand(outputStream, name, args);
|
||||
protected Connection sendCommand(final Command cmd, final String... 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++;
|
||||
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();
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
@@ -65,7 +94,7 @@ public class Connection {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
public void setHost(final String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
@@ -73,7 +102,7 @@ public class Connection {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
public void setPort(final int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
@@ -111,12 +140,26 @@ public class Connection {
|
||||
|
||||
protected String getStatusCodeReply() {
|
||||
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() {
|
||||
final byte[] result = getBinaryBulkReply();
|
||||
if (null != result) {
|
||||
return new String(result, Protocol.UTF8);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getBinaryBulkReply() {
|
||||
pipelinedCommands--;
|
||||
return (String) protocol.read(inputStream);
|
||||
return (byte[]) protocol.read(inputStream);
|
||||
}
|
||||
|
||||
public Integer getIntegerReply() {
|
||||
@@ -124,10 +167,26 @@ public class Connection {
|
||||
return (Integer) protocol.read(inputStream);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
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--;
|
||||
return (List<String>) protocol.read(inputStream);
|
||||
return (List<byte[]>) protocol.read(inputStream);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,6 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -58,9 +59,9 @@ public interface JedisCommands {
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static redis.clients.jedis.Protocol.Keyword.*;
|
||||
|
||||
public abstract class JedisPubSub {
|
||||
private int subscribedChannels = 0;
|
||||
private Client client;
|
||||
@@ -62,26 +65,78 @@ public abstract class JedisPubSub {
|
||||
private void process(Client client) {
|
||||
do {
|
||||
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();
|
||||
onSubscribe((String) reply.get(1), subscribedChannels);
|
||||
} else if (reply.get(0).equals("unsubscribe")) {
|
||||
final byte[] bchannel = (byte[]) reply.get(1);
|
||||
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();
|
||||
onUnsubscribe((String) reply.get(1), subscribedChannels);
|
||||
} else if (reply.get(0).equals("message")) {
|
||||
onMessage((String) reply.get(1), (String) reply.get(2));
|
||||
} else if (reply.get(0).equals("pmessage")) {
|
||||
onPMessage((String) reply.get(1), (String) reply.get(2),
|
||||
(String) reply.get(3));
|
||||
} else if (reply.get(0).equals("psubscribe")) {
|
||||
final byte[] bchannel = (byte[]) reply.get(1);
|
||||
final String strchannel =
|
||||
(bchannel == null) ?
|
||||
null :
|
||||
new String(bchannel, Protocol.UTF8);
|
||||
onUnsubscribe(strchannel, subscribedChannels);
|
||||
} 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();
|
||||
onPSubscribe((String) reply.get(1), subscribedChannels);
|
||||
} else if (reply.get(0).equals("punsubscribe")) {
|
||||
final byte[] bpattern = (byte[]) reply.get(1);
|
||||
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();
|
||||
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 {
|
||||
throw new JedisException("Unknown message type: "
|
||||
+ reply.get(0));
|
||||
throw new JedisException("Unknown message type: "+ firstObj);
|
||||
}
|
||||
} while (isSubscribed());
|
||||
}
|
||||
|
||||
@@ -1,41 +1,45 @@
|
||||
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.RedisOutputStream;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static redis.clients.util.RedisOutputStream.CHARSET;
|
||||
|
||||
public final class Protocol {
|
||||
|
||||
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 ASTERISK_BYTE = '*';
|
||||
public static final byte PLUS_BYTE = '+';
|
||||
public static final byte MINUS_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 {
|
||||
os.write(ASTERISK_BYTE);
|
||||
os.writeIntCrLf(args.length + 1);
|
||||
os.write(DOLLAR_BYTE);
|
||||
os.writeIntCrLf(name.length());
|
||||
os.writeAsciiCrLf(name);
|
||||
os.writeIntCrLf(command.length);
|
||||
os.write(command);
|
||||
os.writeCrLf();
|
||||
|
||||
for (String str : args) {
|
||||
for (final byte[] arg : args) {
|
||||
os.write(DOLLAR_BYTE);
|
||||
final int size = RedisOutputStream.utf8Length(str);
|
||||
os.writeIntCrLf(size);
|
||||
if (size == str.length())
|
||||
os.writeAsciiCrLf(str);
|
||||
else {
|
||||
os.writeUtf8CrLf(str);
|
||||
}
|
||||
os.writeIntCrLf(arg.length);
|
||||
os.write(arg);
|
||||
os.writeCrLf();
|
||||
}
|
||||
os.flush();
|
||||
} 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();
|
||||
throw new JedisException(message);
|
||||
}
|
||||
|
||||
private Object process(RedisInputStream is) {
|
||||
private Object process(final RedisInputStream is) {
|
||||
try {
|
||||
byte b = is.readByte();
|
||||
if (b == MINUS_BYTE) {
|
||||
@@ -70,11 +74,11 @@ public final class Protocol {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String processStatusCodeReply(RedisInputStream is) {
|
||||
return is.readLine();
|
||||
private byte[] processStatusCodeReply(final RedisInputStream is) {
|
||||
return is.readLine().getBytes(UTF8);
|
||||
}
|
||||
|
||||
private String processBulkReply(RedisInputStream is) {
|
||||
private byte[] processBulkReply(final RedisInputStream is) {
|
||||
int len = Integer.parseInt(is.readLine());
|
||||
if (len == -1) {
|
||||
return null;
|
||||
@@ -92,15 +96,15 @@ public final class Protocol {
|
||||
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();
|
||||
return Integer.valueOf(num);
|
||||
}
|
||||
|
||||
private List<Object> processMultiBulkReply(RedisInputStream is) {
|
||||
private List<Object> processMultiBulkReply(final RedisInputStream is) {
|
||||
int num = Integer.parseInt(is.readLine());
|
||||
if (num == -1) {
|
||||
return null;
|
||||
@@ -112,7 +116,39 @@ public final class Protocol {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Object read(RedisInputStream is) {
|
||||
public Object read(final RedisInputStream 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;
|
||||
|
||||
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.Client.LIST_POSITION;
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.util.Hashing;
|
||||
import redis.clients.util.Sharded;
|
||||
|
||||
public class ShardedJedis extends Sharded<Jedis, JedisShardInfo> implements
|
||||
JedisCommands {
|
||||
public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||
public ShardedJedis(List<JedisShardInfo> shards) {
|
||||
super(shards);
|
||||
}
|
||||
@@ -161,12 +160,12 @@ public class ShardedJedis extends Sharded<Jedis, JedisShardInfo> implements
|
||||
return j.hlen(key);
|
||||
}
|
||||
|
||||
public List<String> hkeys(String key) {
|
||||
public Set<String> hkeys(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hkeys(key);
|
||||
}
|
||||
|
||||
public List<String> hvals(String key) {
|
||||
public Collection<String> hvals(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hvals(key);
|
||||
}
|
||||
@@ -368,10 +367,4 @@ public class ShardedJedis extends Sharded<Jedis, JedisShardInfo> implements
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import redis.clients.jedis.Client.LIST_POSITION;
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
|
||||
public abstract class ShardedJedisPipeline {
|
||||
private ShardedJedis jedis;
|
||||
private BinaryShardedJedis jedis;
|
||||
private List<FutureResult> results = new ArrayList<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;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static redis.clients.jedis.Protocol.Keyword.*;
|
||||
/**
|
||||
* Builder Class for {@link Jedis#sort(String, SortingParams) SORT} Parameters.
|
||||
*
|
||||
*/
|
||||
public class SortingParams {
|
||||
private List<String> params = new ArrayList<String>();
|
||||
private List<byte[]> params = new ArrayList<byte[]>();
|
||||
|
||||
/**
|
||||
* Sort by weight in keys.
|
||||
@@ -25,8 +25,25 @@ public class SortingParams {
|
||||
* @param pattern
|
||||
* @return the SortingParams Object
|
||||
*/
|
||||
public SortingParams by(String pattern) {
|
||||
params.add("BY");
|
||||
public SortingParams by(final String pattern) {
|
||||
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);
|
||||
return this;
|
||||
}
|
||||
@@ -40,11 +57,12 @@ public class SortingParams {
|
||||
* @return the SortingParams Object
|
||||
*/
|
||||
public SortingParams nosort() {
|
||||
params.add("BY nosort");
|
||||
params.add(BY.raw);
|
||||
params.add(NOSORT.raw);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Collection<String> getParams() {
|
||||
public Collection<byte[]> getParams() {
|
||||
return Collections.unmodifiableCollection(params);
|
||||
}
|
||||
|
||||
@@ -54,7 +72,7 @@ public class SortingParams {
|
||||
* @return the sortingParams Object
|
||||
*/
|
||||
public SortingParams desc() {
|
||||
params.add("DESC");
|
||||
params.add(DESC.raw);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -64,7 +82,7 @@ public class SortingParams {
|
||||
* @return the SortingParams Object
|
||||
*/
|
||||
public SortingParams asc() {
|
||||
params.add("ASC");
|
||||
params.add(ASC.raw);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -76,10 +94,10 @@ public class SortingParams {
|
||||
* @param count
|
||||
* @return the SortingParams Object
|
||||
*/
|
||||
public SortingParams limit(int start, int count) {
|
||||
params.add("LIMIT");
|
||||
params.add(String.valueOf(start));
|
||||
params.add(String.valueOf(count));
|
||||
public SortingParams limit(final int start, final int count) {
|
||||
params.add(LIMIT.raw);
|
||||
params.add(Protocol.toByteArray(start));
|
||||
params.add(Protocol.toByteArray(count));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -90,7 +108,7 @@ public class SortingParams {
|
||||
* @return the SortingParams Object
|
||||
*/
|
||||
public SortingParams alpha() {
|
||||
params.add("ALPHA");
|
||||
params.add(ALPHA.raw);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -110,8 +128,31 @@ public class SortingParams {
|
||||
* @return the SortingParams Object
|
||||
*/
|
||||
public SortingParams get(String... patterns) {
|
||||
for (String pattern : patterns) {
|
||||
params.add("GET");
|
||||
for (final String pattern : patterns) {
|
||||
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);
|
||||
}
|
||||
return this;
|
||||
|
||||
@@ -1,425 +1,392 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Transaction {
|
||||
protected Client client = null;
|
||||
|
||||
public Transaction() {
|
||||
}
|
||||
|
||||
public Transaction(Client client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public String ping() {
|
||||
client.ping();
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String set(String key, String value) {
|
||||
client.set(key, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String get(String key) {
|
||||
client.sendCommand("GET", key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String exists(String key) {
|
||||
client.exists(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String del(String... keys) {
|
||||
client.del(keys);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String type(String key) {
|
||||
client.type(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String flushDB() {
|
||||
client.flushDB();
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String keys(String pattern) {
|
||||
client.keys(pattern);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String randomKey() {
|
||||
client.randomKey();
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String rename(String oldkey, String newkey) {
|
||||
client.rename(oldkey, newkey);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String renamenx(String oldkey, String newkey) {
|
||||
client.renamenx(oldkey, newkey);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String dbSize() {
|
||||
client.dbSize();
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String expire(String key, int seconds) {
|
||||
client.expire(key, seconds);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String expireAt(String key, long unixTime) {
|
||||
client.expireAt(key, unixTime);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String ttl(String key) {
|
||||
client.ttl(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String select(int index) {
|
||||
client.select(index);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String move(String key, int dbIndex) {
|
||||
client.move(key, dbIndex);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String flushAll() {
|
||||
client.flushAll();
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String getSet(String key, String value) {
|
||||
client.getSet(key, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String mget(String... keys) {
|
||||
client.mget(keys);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String setnx(String key, String value) {
|
||||
client.setnx(key, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String setex(String key, int seconds, String value) {
|
||||
client.setex(key, seconds, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String mset(String... keysvalues) {
|
||||
client.mset(keysvalues);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String msetnx(String... keysvalues) {
|
||||
client.msetnx(keysvalues);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String decrBy(String key, int integer) {
|
||||
client.decrBy(key, integer);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String decr(String key) {
|
||||
client.decr(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String incrBy(String key, int integer) {
|
||||
client.incrBy(key, integer);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String incr(String key) {
|
||||
client.incr(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String append(String key, String value) {
|
||||
client.append(key, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String substr(String key, int start, int end) {
|
||||
client.substr(key, start, end);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hset(String key, String field, String value) {
|
||||
client.hset(key, field, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hget(String key, String field) {
|
||||
client.hget(key, field);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hsetnx(String key, String field, String value) {
|
||||
client.hsetnx(key, field, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hmset(String key, Map<String, String> hash) {
|
||||
client.hmset(key, hash);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hmget(String key, String... fields) {
|
||||
client.hmget(key, fields);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hincrBy(String key, String field, int value) {
|
||||
client.hincrBy(key, field, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hexists(String key, String field) {
|
||||
client.hexists(key, field);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hdel(String key, String field) {
|
||||
client.hdel(key, field);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hlen(String key) {
|
||||
client.hlen(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hkeys(String key) {
|
||||
client.hkeys(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hvals(String key) {
|
||||
client.hvals(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hgetAll(String key) {
|
||||
client.hgetAll(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String rpush(String key, String string) {
|
||||
client.rpush(key, string);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String lpush(String key, String string) {
|
||||
client.lpush(key, string);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String llen(String key) {
|
||||
client.llen(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String lrange(String key, int start, int end) {
|
||||
client.lrange(key, start, end);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String ltrim(String key, int start, int end) {
|
||||
client.ltrim(key, start, end);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String lindex(String key, int index) {
|
||||
client.lindex(key, index);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String lset(String key, int index, String value) {
|
||||
client.lset(key, index, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String lrem(String key, int count, String value) {
|
||||
client.lrem(key, count, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String lpop(String key) {
|
||||
client.lpop(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String rpop(String key) {
|
||||
client.rpop(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String rpoplpush(String srckey, String dstkey) {
|
||||
client.rpoplpush(srckey, dstkey);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sadd(String key, String member) {
|
||||
client.sadd(key, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String smembers(String key) {
|
||||
client.smembers(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String srem(String key, String member) {
|
||||
client.srem(key, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String spop(String key) {
|
||||
client.spop(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String smove(String srckey, String dstkey, String member) {
|
||||
client.smove(srckey, dstkey, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String scard(String key) {
|
||||
client.scard(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sismember(String key, String member) {
|
||||
client.sismember(key, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sinter(String... keys) {
|
||||
client.sinter(keys);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sinterstore(String dstkey, String... keys) {
|
||||
client.sinterstore(dstkey, keys);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sunion(String... keys) {
|
||||
client.sunion(keys);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sunionstore(String dstkey, String... keys) {
|
||||
client.sunionstore(dstkey, keys);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sdiff(String... keys) {
|
||||
client.sdiff(keys);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sdiffstore(String dstkey, String... keys) {
|
||||
client.sdiffstore(dstkey, keys);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String srandmember(String key) {
|
||||
client.srandmember(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zadd(String key, double score, String member) {
|
||||
client.zadd(key, score, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zrange(String key, int start, int end) {
|
||||
client.zrange(key, start, end);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zrem(String key, String member) {
|
||||
client.zrem(key, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zincrby(String key, double score, String member) {
|
||||
client.zincrby(key, score, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zrank(String key, String member) {
|
||||
client.zrank(key, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zrevrank(String key, String member) {
|
||||
client.zrevrank(key, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zrevrange(String key, int start, int end) {
|
||||
client.zrevrange(key, start, end);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zrangeWithScores(String key, int start, int end) {
|
||||
client.zrangeWithScores(key, start, end);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zrevrangeWithScores(String key, int start, int end) {
|
||||
client.zrevrangeWithScores(key, start, end);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zcard(String key) {
|
||||
client.zcard(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zscore(String key, String member) {
|
||||
client.zscore(key, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public List<Object> exec() {
|
||||
client.exec();
|
||||
|
||||
return client.getObjectMultiBulkReply();
|
||||
}
|
||||
|
||||
public String sort(String key) {
|
||||
client.sort(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sort(String key, SortingParams sortingParameters) {
|
||||
client.sort(key, sortingParameters);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public void discard() {
|
||||
client.discard();
|
||||
}
|
||||
public class Transaction extends BinaryTransaction {
|
||||
public Transaction() {
|
||||
}
|
||||
|
||||
public Transaction(final Client client) {
|
||||
super(client);
|
||||
}
|
||||
|
||||
public String set(final String key, final String value) {
|
||||
client.set(key, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String get(final String key) {
|
||||
client.get(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String exists(final String key) {
|
||||
client.exists(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String del(final String... keys) {
|
||||
client.del(keys);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String type(final String key) {
|
||||
client.type(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String keys(final String pattern) {
|
||||
client.keys(pattern);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String randomKey() {
|
||||
client.randomKey();
|
||||
return client.getBulkReply();
|
||||
}
|
||||
|
||||
public String rename(final String oldkey, final String newkey) {
|
||||
client.rename(oldkey, newkey);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String renamenx(final String oldkey, final String newkey) {
|
||||
client.renamenx(oldkey, newkey);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String expire(final String key, final int seconds) {
|
||||
client.expire(key, seconds);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String expireAt(final String key, final long unixTime) {
|
||||
client.expireAt(key, unixTime);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String ttl(final String key) {
|
||||
client.ttl(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String move(final String key, final int dbIndex) {
|
||||
client.move(key, dbIndex);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String getSet(final String key, final String value) {
|
||||
client.getSet(key, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String mget(final String... keys) {
|
||||
client.mget(keys);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String setnx(final String key, final String value) {
|
||||
client.setnx(key, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String setex(final String key, final int seconds, final String value) {
|
||||
client.setex(key, seconds, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String mset(final String... keysvalues) {
|
||||
client.mset(keysvalues);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String msetnx(final String... keysvalues) {
|
||||
client.msetnx(keysvalues);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String decrBy(final String key, final int integer) {
|
||||
client.decrBy(key, integer);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String decr(final String key) {
|
||||
client.decr(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String incrBy(final String key, final int integer) {
|
||||
client.incrBy(key, integer);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String incr(final String key) {
|
||||
client.incr(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String append(final String key, final String value) {
|
||||
client.append(key, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String substr(final String key, final int start, final int end) {
|
||||
client.substr(key, start, end);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hset(final String key, final String field, final String value) {
|
||||
client.hset(key, field, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hget(final String key, final String field) {
|
||||
client.hget(key, field);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hsetnx(final String key, final String field,
|
||||
final String value) {
|
||||
client.hsetnx(key, field, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hmset(final String key, final Map<String, String> hash) {
|
||||
client.hmset(key, hash);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hmget(final String key, final String... fields) {
|
||||
client.hmget(key, fields);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hincrBy(final String key, final String field, final int value) {
|
||||
client.hincrBy(key, field, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hexists(final String key, final String field) {
|
||||
client.hexists(key, field);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hdel(final String key, final String field) {
|
||||
client.hdel(key, field);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hlen(final String key) {
|
||||
client.hlen(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hkeys(final String key) {
|
||||
client.hkeys(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hvals(final String key) {
|
||||
client.hvals(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String hgetAll(final String key) {
|
||||
client.hgetAll(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String rpush(final String key, final String string) {
|
||||
client.rpush(key, string);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String lpush(final String key, final String string) {
|
||||
client.lpush(key, string);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String llen(final String key) {
|
||||
client.llen(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String lrange(final String key, final int start, final int end) {
|
||||
client.lrange(key, start, end);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String ltrim(String key, final int start, final int end) {
|
||||
client.ltrim(key, start, end);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String lindex(final String key, final int index) {
|
||||
client.lindex(key, index);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String lset(final String key, final int index, final String value) {
|
||||
client.lset(key, index, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String lrem(final String key, final int count, final String value) {
|
||||
client.lrem(key, count, value);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String lpop(final String key) {
|
||||
client.lpop(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String rpop(final String key) {
|
||||
client.rpop(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String rpoplpush(final String srckey, final String dstkey) {
|
||||
client.rpoplpush(srckey, dstkey);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sadd(final String key, final String member) {
|
||||
client.sadd(key, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String smembers(final String key) {
|
||||
client.smembers(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String srem(final String key, final String member) {
|
||||
client.srem(key, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String spop(final String key) {
|
||||
client.spop(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String smove(final String srckey, final String dstkey,
|
||||
final String member) {
|
||||
client.smove(srckey, dstkey, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String scard(final String key) {
|
||||
client.scard(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sismember(final String key, final String member) {
|
||||
client.sismember(key, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sinter(final String... keys) {
|
||||
client.sinter(keys);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sinterstore(final String dstkey, final String... keys) {
|
||||
client.sinterstore(dstkey, keys);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sunion(final String... keys) {
|
||||
client.sunion(keys);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sunionstore(final String dstkey, final String... keys) {
|
||||
client.sunionstore(dstkey, keys);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sdiff(final String... keys) {
|
||||
client.sdiff(keys);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sdiffstore(final String dstkey, final String... keys) {
|
||||
client.sdiffstore(dstkey, keys);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String srandmember(final String key) {
|
||||
client.srandmember(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zadd(final String key, final double score, final String member) {
|
||||
client.zadd(key, score, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zrange(final String key, final int start, final int end) {
|
||||
client.zrange(key, start, end);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zrem(final String key, final String member) {
|
||||
client.zrem(key, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zincrby(final String key, final double score,
|
||||
final String member) {
|
||||
client.zincrby(key, score, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zrank(final String key, final String member) {
|
||||
client.zrank(key, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zrevrank(final String key, final String member) {
|
||||
client.zrevrank(key, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zrevrange(final String key, final int start, final int end) {
|
||||
client.zrevrange(key, start, end);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zrangeWithScores(final String key, final int start,
|
||||
final int end) {
|
||||
client.zrangeWithScores(key, start, end);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zrevrangeWithScores(final String key, final int start,
|
||||
final int end) {
|
||||
client.zrevrangeWithScores(key, start, end);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zcard(final String key) {
|
||||
client.zcard(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String zscore(final String key, final String member) {
|
||||
client.zscore(key, member);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sort(final String key) {
|
||||
client.sort(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
public String sort(final String key, final SortingParams sortingParameters) {
|
||||
client.sort(key, sortingParameters);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,21 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Tuple {
|
||||
private String element;
|
||||
private byte[] element;
|
||||
private Double score;
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
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;
|
||||
temp = Double.doubleToLongBits(score);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
@@ -27,7 +34,7 @@ public class Tuple {
|
||||
if (element == null) {
|
||||
if (other.element != null)
|
||||
return false;
|
||||
} else if (!element.equals(other.element))
|
||||
} else if (!Arrays.equals(element, other.element))
|
||||
return false;
|
||||
if (Double.doubleToLongBits(score) != Double
|
||||
.doubleToLongBits(other.score))
|
||||
@@ -37,15 +44,33 @@ public class Tuple {
|
||||
|
||||
public Tuple(String element, Double score) {
|
||||
super();
|
||||
this.element = element;
|
||||
this.element = element.getBytes(Protocol.UTF8);
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public Tuple(byte[] element, Double score) {
|
||||
super();
|
||||
this.element = element;
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public String getElement() {
|
||||
return element;
|
||||
if(null != element) {
|
||||
return new String(element, Protocol.UTF8);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getBinaryElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
public double getScore() {
|
||||
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.List;
|
||||
|
||||
import static redis.clients.jedis.Protocol.Keyword.*;
|
||||
|
||||
public class ZParams {
|
||||
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) {
|
||||
params.add("WEIGHTS");
|
||||
for (int weight : weights) {
|
||||
params.add(String.valueOf(weight));
|
||||
public ZParams weights(final int... weights) {
|
||||
params.add(WEIGHTS.raw);
|
||||
for (final int weight : weights) {
|
||||
params.add(Protocol.toByteArray(weight));
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Collection<String> getParams() {
|
||||
return Collections.unmodifiableCollection(params);
|
||||
public Collection<byte[]> getParams() {
|
||||
return Collections.unmodifiableCollection(params);
|
||||
}
|
||||
|
||||
public ZParams aggregate(Aggregate aggregate) {
|
||||
params.add("AGGREGATE");
|
||||
params.add(aggregate.name());
|
||||
public ZParams aggregate(final Aggregate aggregate) {
|
||||
params.add(AGGREGATE.raw);
|
||||
params.add(aggregate.raw);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user