Added transactions support
This commit is contained in:
@@ -8,11 +8,10 @@ Jedis is a WORK IN PROGRESS.
|
|||||||
|
|
||||||
## What's still missing?
|
## What's still missing?
|
||||||
- Sorting
|
- Sorting
|
||||||
- Transactions
|
|
||||||
- Publish/Subscribe
|
- Publish/Subscribe
|
||||||
- Persistence control commands
|
- Persistence control commands
|
||||||
- Remote server control commands
|
- Remote server control commands
|
||||||
- The AUTH, SORT, BLPOP, BRPOP, ZRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE commands
|
- The WATCH, UNWATCH, AUTH, SORT, BLPOP, BRPOP, ZRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE commands
|
||||||
|
|
||||||
But stay close because things are going fast and all this will be implemented soon!
|
But stay close because things are going fast and all this will be implemented soon!
|
||||||
|
|
||||||
@@ -24,6 +23,7 @@ But stay close because things are going fast and all this will be implemented so
|
|||||||
- Commands operating on lists (not SORT, BLPOP, BRPOP)
|
- Commands operating on lists (not SORT, BLPOP, BRPOP)
|
||||||
- Commands operating on sets
|
- Commands operating on sets
|
||||||
- Commands operating on sorted sets (not SORT, ZRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE)
|
- Commands operating on sorted sets (not SORT, ZRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE)
|
||||||
|
- Transactions
|
||||||
|
|
||||||
## How do I use it?
|
## How do I use it?
|
||||||
|
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@@ -2,7 +2,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>redis.clients</groupId>
|
<groupId>redis.clients</groupId>
|
||||||
<artifactId>jedis</artifactId>
|
<artifactId>jedis</artifactId>
|
||||||
<version>0.0.7</version>
|
<version>0.0.8</version>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
|
|||||||
@@ -1,97 +1,379 @@
|
|||||||
package redis.clients.jedis;
|
package redis.clients.jedis;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.util.ArrayList;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class Client {
|
public class Client extends Connection {
|
||||||
private String host;
|
|
||||||
private int port = Protocol.DEFAULT_PORT;
|
|
||||||
private Socket socket;
|
|
||||||
private boolean connected = false;
|
|
||||||
private Protocol protocol = new Protocol();
|
|
||||||
private OutputStream outputStream;
|
|
||||||
private InputStream inputStream;
|
|
||||||
|
|
||||||
public Client(String host) {
|
public Client(String host) {
|
||||||
super();
|
super(host);
|
||||||
this.host = host;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Client sendCommand(String name, String... args)
|
|
||||||
throws JedisException {
|
|
||||||
if (!isConnected()) {
|
|
||||||
throw new JedisException("Please connect Jedis before using it.");
|
|
||||||
}
|
|
||||||
protocol.sendCommand(outputStream, name, args);
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Client(String host, int port) {
|
public Client(String host, int port) {
|
||||||
super();
|
super(host, port);
|
||||||
this.host = host;
|
|
||||||
this.port = port;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHost() {
|
public void ping() throws JedisException {
|
||||||
return host;
|
sendCommand("PING");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHost(String host) {
|
public void set(String key, String value) throws JedisException {
|
||||||
this.host = host;
|
sendCommand("SET", key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPort() {
|
public void get(String key) throws JedisException {
|
||||||
return port;
|
sendCommand("GET", key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPort(int port) {
|
public void quit() throws JedisException {
|
||||||
this.port = port;
|
sendCommand("QUIT");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Client() {
|
public void exists(String key) throws JedisException {
|
||||||
|
sendCommand("EXISTS", key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connect() throws UnknownHostException, IOException {
|
public void del(String... keys) throws JedisException {
|
||||||
if (!connected) {
|
sendCommand("DEL", keys);
|
||||||
socket = new Socket(host, port);
|
}
|
||||||
connected = socket.isConnected();
|
|
||||||
outputStream = socket.getOutputStream();
|
public void type(String key) throws JedisException {
|
||||||
inputStream = socket.getInputStream();
|
sendCommand("TYPE", key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void flushDB() throws JedisException {
|
||||||
|
sendCommand("FLUSHDB");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keys(String pattern) throws JedisException {
|
||||||
|
sendCommand("KEYS", pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void randomKey() throws JedisException {
|
||||||
|
sendCommand("RANDOMKEY");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rename(String oldkey, String newkey) throws JedisException {
|
||||||
|
sendCommand("RENAME", oldkey, newkey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void renamenx(String oldkey, String newkey) throws JedisException {
|
||||||
|
sendCommand("RENAMENX", oldkey, newkey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dbSize() throws JedisException {
|
||||||
|
sendCommand("DBSIZE");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void expire(String key, int seconds) throws JedisException {
|
||||||
|
sendCommand("EXPIRE", key, String.valueOf(seconds));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void expireAt(String key, long unixTime) throws JedisException {
|
||||||
|
sendCommand("EXPIREAT", key, String.valueOf(unixTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ttl(String key) throws JedisException {
|
||||||
|
sendCommand("TTL", key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void select(int index) throws JedisException {
|
||||||
|
sendCommand("SELECT", String.valueOf(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void move(String key, int dbIndex) throws JedisException {
|
||||||
|
sendCommand("MOVE", key, String.valueOf(dbIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void flushAll() throws JedisException {
|
||||||
|
sendCommand("FLUSHALL");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getSet(String key, String value) throws JedisException {
|
||||||
|
sendCommand("GETSET", key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mget(String... keys) throws JedisException {
|
||||||
|
sendCommand("MGET", keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setnx(String key, String value) throws JedisException {
|
||||||
|
sendCommand("SETNX", key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setex(String key, int seconds, String value)
|
||||||
|
throws JedisException {
|
||||||
|
sendCommand("SETEX", key, String.valueOf(seconds), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mset(String... keysvalues) throws JedisException {
|
||||||
|
sendCommand("MSET", keysvalues);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void msetnx(String... keysvalues) throws JedisException {
|
||||||
|
sendCommand("MSETNX", keysvalues);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void decrBy(String key, int integer) throws JedisException {
|
||||||
|
sendCommand("DECRBY", key, String.valueOf(integer));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void decr(String key) throws JedisException {
|
||||||
|
sendCommand("DECR", key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void incrBy(String key, int integer) throws JedisException {
|
||||||
|
sendCommand("INCRBY", key, String.valueOf(integer));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void incr(String key) throws JedisException {
|
||||||
|
sendCommand("INCR", key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void append(String key, String value) throws JedisException {
|
||||||
|
sendCommand("APPEND", key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void substr(String key, int start, int end) throws JedisException {
|
||||||
|
sendCommand("SUBSTR", key, String.valueOf(start), String.valueOf(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hset(String key, String field, String value)
|
||||||
|
throws JedisException {
|
||||||
|
sendCommand("HSET", key, field, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hget(String key, String field) throws JedisException {
|
||||||
|
sendCommand("HGET", key, field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hsetnx(String key, String field, String value)
|
||||||
|
throws JedisException {
|
||||||
|
sendCommand("HSETNX", key, field, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hmset(String key, Map<String, String> hash)
|
||||||
|
throws JedisException {
|
||||||
|
List<String> params = new ArrayList<String>();
|
||||||
|
params.add(key);
|
||||||
|
|
||||||
|
for (String field : hash.keySet()) {
|
||||||
|
params.add(field);
|
||||||
|
params.add(hash.get(field));
|
||||||
}
|
}
|
||||||
|
sendCommand("HMSET", params.toArray(new String[params.size()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect() throws IOException {
|
public void hmget(String key, String... fields) throws JedisException {
|
||||||
if (connected) {
|
String[] params = new String[fields.length + 1];
|
||||||
inputStream.close();
|
params[0] = key;
|
||||||
outputStream.close();
|
System.arraycopy(fields, 0, params, 1, fields.length);
|
||||||
if (!socket.isClosed()) {
|
sendCommand("HMGET", params);
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
connected = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isConnected() {
|
public void hincrBy(String key, String field, int value)
|
||||||
return connected;
|
throws JedisException {
|
||||||
|
sendCommand("HINCRBY", key, field, String.valueOf(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getStatusCodeReply() throws JedisException {
|
public void hexists(String key, String field) throws JedisException {
|
||||||
return protocol.getSingleLineReply(inputStream);
|
sendCommand("HEXISTS", key, field);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBulkReply() throws JedisException {
|
public void hdel(String key, String field) throws JedisException {
|
||||||
return protocol.getBulkReply(inputStream);
|
sendCommand("HDEL", key, field);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getIntegerReply() throws JedisException {
|
public void hlen(String key) throws JedisException {
|
||||||
return protocol.getIntegerReply(inputStream);
|
sendCommand("HLEN", key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getMultiBulkReply() throws JedisException {
|
public void hkeys(String key) throws JedisException {
|
||||||
return protocol.getMultiBulkReply(inputStream);
|
sendCommand("HKEYS", key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void hvals(String key) throws JedisException {
|
||||||
|
sendCommand("HVALS", key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hgetAll(String key) throws JedisException {
|
||||||
|
sendCommand("HGETALL", key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rpush(String key, String string) throws JedisException {
|
||||||
|
sendCommand("RPUSH", key, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lpush(String key, String string) throws JedisException {
|
||||||
|
sendCommand("LPUSH", key, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void llen(String key) throws JedisException {
|
||||||
|
sendCommand("LLEN", key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lrange(String key, int start, int end) throws JedisException {
|
||||||
|
sendCommand("LRANGE", key, String.valueOf(start), String.valueOf(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ltrim(String key, int start, int end) throws JedisException {
|
||||||
|
sendCommand("LTRIM", key, String.valueOf(start), String.valueOf(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lindex(String key, int index) throws JedisException {
|
||||||
|
sendCommand("LINDEX", key, String.valueOf(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lset(String key, int index, String value) throws JedisException {
|
||||||
|
sendCommand("LSET", key, String.valueOf(index), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lrem(String key, int count, String value) throws JedisException {
|
||||||
|
sendCommand("LREM", key, String.valueOf(count), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lpop(String key) throws JedisException {
|
||||||
|
sendCommand("LPOP", key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rpop(String key) throws JedisException {
|
||||||
|
sendCommand("RPOP", key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rpoplpush(String srckey, String dstkey) throws JedisException {
|
||||||
|
sendCommand("RPOPLPUSH", srckey, dstkey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sadd(String key, String member) throws JedisException {
|
||||||
|
sendCommand("SADD", key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void smembers(String key) throws JedisException {
|
||||||
|
sendCommand("SMEMBERS", key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void srem(String key, String member) throws JedisException {
|
||||||
|
sendCommand("SREM", key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void spop(String key) throws JedisException {
|
||||||
|
sendCommand("SPOP", key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void smove(String srckey, String dstkey, String member)
|
||||||
|
throws JedisException {
|
||||||
|
sendCommand("SMOVE", srckey, dstkey, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void scard(String key) throws JedisException {
|
||||||
|
sendCommand("SCARD", key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sismember(String key, String member) throws JedisException {
|
||||||
|
sendCommand("SISMEMBER", key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sinter(String... keys) throws JedisException {
|
||||||
|
sendCommand("SINTER", keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sinterstore(String dstkey, String... keys)
|
||||||
|
throws JedisException {
|
||||||
|
String[] params = new String[keys.length + 1];
|
||||||
|
params[0] = dstkey;
|
||||||
|
System.arraycopy(keys, 0, params, 1, keys.length);
|
||||||
|
sendCommand("SINTERSTORE", params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sunion(String... keys) throws JedisException {
|
||||||
|
sendCommand("SUNION", keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sunionstore(String dstkey, String... keys)
|
||||||
|
throws JedisException {
|
||||||
|
String[] params = new String[keys.length + 1];
|
||||||
|
params[0] = dstkey;
|
||||||
|
System.arraycopy(keys, 0, params, 1, keys.length);
|
||||||
|
sendCommand("SUNIONSTORE", params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sdiff(String... keys) throws JedisException {
|
||||||
|
sendCommand("SDIFF", keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sdiffstore(String dstkey, String... keys) throws JedisException {
|
||||||
|
String[] params = new String[keys.length + 1];
|
||||||
|
params[0] = dstkey;
|
||||||
|
System.arraycopy(keys, 0, params, 1, keys.length);
|
||||||
|
sendCommand("SDIFFSTORE", params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void srandmember(String key) throws JedisException {
|
||||||
|
sendCommand("SRANDMEMBER", key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zadd(String key, double score, String member)
|
||||||
|
throws JedisException {
|
||||||
|
sendCommand("ZADD", key, String.valueOf(score), member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrange(String key, int start, int end) throws JedisException {
|
||||||
|
sendCommand("ZRANGE", key, String.valueOf(start), String.valueOf(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrem(String key, String member) throws JedisException {
|
||||||
|
sendCommand("ZREM", key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zincrby(String key, double score, String member)
|
||||||
|
throws JedisException {
|
||||||
|
sendCommand("ZINCRBY", key, String.valueOf(score), member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrank(String key, String member) throws JedisException {
|
||||||
|
sendCommand("ZRANK", key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrevrank(String key, String member) throws JedisException {
|
||||||
|
sendCommand("ZREVRANK", key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrevrange(String key, int start, int end) throws JedisException {
|
||||||
|
sendCommand("ZREVRANGE", key, String.valueOf(start), String
|
||||||
|
.valueOf(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrangeWithScores(String key, int start, int end)
|
||||||
|
throws JedisException {
|
||||||
|
sendCommand("ZRANGE", key, String.valueOf(start), String.valueOf(end),
|
||||||
|
"WITHSCORES");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrevrangeWithScores(String key, int start, int end)
|
||||||
|
throws JedisException {
|
||||||
|
sendCommand("ZREVRANGE", key, String.valueOf(start), String
|
||||||
|
.valueOf(end), "WITHSCORES");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zcard(String key) throws JedisException {
|
||||||
|
sendCommand("ZCARD", key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zscore(String key, String member) throws JedisException {
|
||||||
|
sendCommand("ZSCORE", key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void multi() throws JedisException {
|
||||||
|
sendCommand("MULTI");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void discard() throws JedisException {
|
||||||
|
sendCommand("MULTI");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exec() throws JedisException {
|
||||||
|
sendCommand("EXEC");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
97
src/main/java/redis/clients/jedis/Connection.java
Normal file
97
src/main/java/redis/clients/jedis/Connection.java
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Connection {
|
||||||
|
private String host;
|
||||||
|
private int port = Protocol.DEFAULT_PORT;
|
||||||
|
private Socket socket;
|
||||||
|
private boolean connected = false;
|
||||||
|
private Protocol protocol = new Protocol();
|
||||||
|
private OutputStream outputStream;
|
||||||
|
private InputStream inputStream;
|
||||||
|
|
||||||
|
public Connection(String host) {
|
||||||
|
super();
|
||||||
|
this.host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Connection sendCommand(String name, String... args)
|
||||||
|
throws JedisException {
|
||||||
|
if (!isConnected()) {
|
||||||
|
throw new JedisException("Please connect Jedis before using it.");
|
||||||
|
}
|
||||||
|
protocol.sendCommand(outputStream, name, args);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Connection(String host, int port) {
|
||||||
|
super();
|
||||||
|
this.host = host;
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHost() {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHost(String host) {
|
||||||
|
this.host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPort(int port) {
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Connection() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void connect() throws UnknownHostException, IOException {
|
||||||
|
if (!connected) {
|
||||||
|
socket = new Socket(host, port);
|
||||||
|
connected = socket.isConnected();
|
||||||
|
outputStream = socket.getOutputStream();
|
||||||
|
inputStream = socket.getInputStream();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disconnect() throws IOException {
|
||||||
|
if (connected) {
|
||||||
|
inputStream.close();
|
||||||
|
outputStream.close();
|
||||||
|
if (!socket.isClosed()) {
|
||||||
|
socket.close();
|
||||||
|
}
|
||||||
|
connected = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isConnected() {
|
||||||
|
return connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getStatusCodeReply() throws JedisException {
|
||||||
|
return protocol.getSingleLineReply(inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBulkReply() throws JedisException {
|
||||||
|
return protocol.getBulkReply(inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIntegerReply() throws JedisException {
|
||||||
|
return protocol.getIntegerReply(inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getMultiBulkReply() throws JedisException {
|
||||||
|
return protocol.getMultiBulkReply(inputStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package redis.clients.jedis;
|
package redis.clients.jedis;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.io.IOException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
@@ -8,207 +9,235 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class Jedis extends Client {
|
public class Jedis {
|
||||||
|
private Client client = null;
|
||||||
|
|
||||||
public Jedis(String host) {
|
public Jedis(String host) {
|
||||||
super(host);
|
client = new Client(host);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Jedis(String host, int port) {
|
||||||
|
client = new Client(host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String ping() throws JedisException {
|
public String ping() throws JedisException {
|
||||||
return sendCommand("PING").getStatusCodeReply();
|
client.ping();
|
||||||
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String set(String key, String value) throws JedisException {
|
public String set(String key, String value) throws JedisException {
|
||||||
return sendCommand("SET", key, value).getStatusCodeReply();
|
client.set(key, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String get(String key) throws JedisException {
|
public String get(String key) throws JedisException {
|
||||||
return sendCommand("GET", key).getBulkReply();
|
client.sendCommand("GET", key);
|
||||||
|
return client.getBulkReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void quit() throws JedisException {
|
public void quit() throws JedisException {
|
||||||
sendCommand("QUIT");
|
client.quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int exists(String key) throws JedisException {
|
public int exists(String key) throws JedisException {
|
||||||
return sendCommand("EXISTS", key).getIntegerReply();
|
client.exists(key);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int del(String... keys) throws JedisException {
|
public int del(String... keys) throws JedisException {
|
||||||
return sendCommand("DEL", keys).getIntegerReply();
|
client.del(keys);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String type(String key) throws JedisException {
|
public String type(String key) throws JedisException {
|
||||||
return sendCommand("TYPE", key).getStatusCodeReply();
|
client.type(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String flushDB() throws JedisException {
|
public String flushDB() throws JedisException {
|
||||||
return sendCommand("FLUSHDB").getStatusCodeReply();
|
client.flushDB();
|
||||||
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> keys(String pattern) throws JedisException {
|
public List<String> keys(String pattern) throws JedisException {
|
||||||
return sendCommand("KEYS", pattern).getMultiBulkReply();
|
client.keys(pattern);
|
||||||
|
return client.getMultiBulkReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String randomKey() throws JedisException {
|
public String randomKey() throws JedisException {
|
||||||
return sendCommand("RANDOMKEY").getBulkReply();
|
client.randomKey();
|
||||||
|
return client.getBulkReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String rename(String oldkey, String newkey) throws JedisException {
|
public String rename(String oldkey, String newkey) throws JedisException {
|
||||||
return sendCommand("RENAME", oldkey, newkey).getStatusCodeReply();
|
client.rename(oldkey, newkey);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int renamenx(String oldkey, String newkey) throws JedisException {
|
public int renamenx(String oldkey, String newkey) throws JedisException {
|
||||||
return sendCommand("RENAMENX", oldkey, newkey).getIntegerReply();
|
client.renamenx(oldkey, newkey);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int dbSize() throws JedisException {
|
public int dbSize() throws JedisException {
|
||||||
return sendCommand("DBSIZE").getIntegerReply();
|
client.dbSize();
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int expire(String key, int seconds) throws JedisException {
|
public int expire(String key, int seconds) throws JedisException {
|
||||||
return sendCommand("EXPIRE", key, String.valueOf(seconds))
|
client.expire(key, seconds);
|
||||||
.getIntegerReply();
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int expireAt(String key, long unixTime) throws JedisException {
|
public int expireAt(String key, long unixTime) throws JedisException {
|
||||||
return sendCommand("EXPIREAT", key, String.valueOf(unixTime))
|
client.expireAt(key, unixTime);
|
||||||
.getIntegerReply();
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int ttl(String key) throws JedisException {
|
public int ttl(String key) throws JedisException {
|
||||||
return sendCommand("TTL", key).getIntegerReply();
|
client.ttl(key);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String select(int index) throws JedisException {
|
public String select(int index) throws JedisException {
|
||||||
return sendCommand("SELECT", String.valueOf(index))
|
client.select(index);
|
||||||
.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int move(String key, int dbIndex) throws JedisException {
|
public int move(String key, int dbIndex) throws JedisException {
|
||||||
return sendCommand("MOVE", key, String.valueOf(dbIndex))
|
client.move(key, dbIndex);
|
||||||
.getIntegerReply();
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String flushAll() throws JedisException {
|
public String flushAll() throws JedisException {
|
||||||
return sendCommand("FLUSHALL").getStatusCodeReply();
|
client.flushAll();
|
||||||
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSet(String key, String value) throws JedisException {
|
public String getSet(String key, String value) throws JedisException {
|
||||||
return sendCommand("GETSET", key, value).getBulkReply();
|
client.getSet(key, value);
|
||||||
|
return client.getBulkReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> mget(String... keys) throws JedisException {
|
public List<String> mget(String... keys) throws JedisException {
|
||||||
return sendCommand("MGET", keys).getMultiBulkReply();
|
client.mget(keys);
|
||||||
|
return client.getMultiBulkReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int setnx(String key, String value) throws JedisException {
|
public int setnx(String key, String value) throws JedisException {
|
||||||
return sendCommand("SETNX", key, value).getIntegerReply();
|
client.setnx(key, value);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String setex(String key, int seconds, String value)
|
public String setex(String key, int seconds, String value)
|
||||||
throws JedisException {
|
throws JedisException {
|
||||||
return sendCommand("SETEX", key, String.valueOf(seconds), value)
|
client.setex(key, seconds, value);
|
||||||
.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String mset(String... keysvalues) throws JedisException {
|
public String mset(String... keysvalues) throws JedisException {
|
||||||
return sendCommand("MSET", keysvalues).getStatusCodeReply();
|
client.mset(keysvalues);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int msetnx(String... keysvalues) throws JedisException {
|
public int msetnx(String... keysvalues) throws JedisException {
|
||||||
return sendCommand("MSETNX", keysvalues).getIntegerReply();
|
client.msetnx(keysvalues);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int decrBy(String key, int integer) throws JedisException {
|
public int decrBy(String key, int integer) throws JedisException {
|
||||||
return sendCommand("DECRBY", key, String.valueOf(integer))
|
client.decrBy(key, integer);
|
||||||
.getIntegerReply();
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int decr(String key) throws JedisException {
|
public int decr(String key) throws JedisException {
|
||||||
return sendCommand("DECR", key).getIntegerReply();
|
client.decr(key);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int incrBy(String key, int integer) throws JedisException {
|
public int incrBy(String key, int integer) throws JedisException {
|
||||||
return sendCommand("INCRBY", key, String.valueOf(integer))
|
client.incrBy(key, integer);
|
||||||
.getIntegerReply();
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int incr(String key) throws JedisException {
|
public int incr(String key) throws JedisException {
|
||||||
return sendCommand("INCR", key).getIntegerReply();
|
client.incr(key);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int append(String key, String value) throws JedisException {
|
public int append(String key, String value) throws JedisException {
|
||||||
return sendCommand("APPEND", key, value).getIntegerReply();
|
client.append(key, value);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String substr(String key, int start, int end) throws JedisException {
|
public String substr(String key, int start, int end) throws JedisException {
|
||||||
return sendCommand("SUBSTR", key, String.valueOf(start),
|
client.substr(key, start, end);
|
||||||
String.valueOf(end)).getBulkReply();
|
return client.getBulkReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hset(String key, String field, String value)
|
public int hset(String key, String field, String value)
|
||||||
throws JedisException {
|
throws JedisException {
|
||||||
return sendCommand("HSET", key, field, value).getIntegerReply();
|
client.hset(key, field, value);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String hget(String key, String field) throws JedisException {
|
public String hget(String key, String field) throws JedisException {
|
||||||
return sendCommand("HGET", key, field).getBulkReply();
|
client.hget(key, field);
|
||||||
|
return client.getBulkReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hsetnx(String key, String field, String value)
|
public int hsetnx(String key, String field, String value)
|
||||||
throws JedisException {
|
throws JedisException {
|
||||||
return sendCommand("HSETNX", key, field, value).getIntegerReply();
|
client.hsetnx(key, field, value);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String hmset(String key, Map<String, String> hash)
|
public String hmset(String key, Map<String, String> hash)
|
||||||
throws JedisException {
|
throws JedisException {
|
||||||
List<String> params = new ArrayList<String>();
|
client.hmset(key, hash);
|
||||||
params.add(key);
|
return client.getStatusCodeReply();
|
||||||
|
|
||||||
for (String field : hash.keySet()) {
|
|
||||||
params.add(field);
|
|
||||||
params.add(hash.get(field));
|
|
||||||
}
|
|
||||||
return sendCommand("HMSET", params.toArray(new String[params.size()]))
|
|
||||||
.getStatusCodeReply();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> hmget(String key, String... fields)
|
public List<String> hmget(String key, String... fields)
|
||||||
throws JedisException {
|
throws JedisException {
|
||||||
String[] params = new String[fields.length + 1];
|
client.hmget(key, fields);
|
||||||
params[0] = key;
|
return client.getMultiBulkReply();
|
||||||
System.arraycopy(fields, 0, params, 1, fields.length);
|
|
||||||
return sendCommand("HMGET", params).getMultiBulkReply();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hincrBy(String key, String field, int value)
|
public int hincrBy(String key, String field, int value)
|
||||||
throws JedisException {
|
throws JedisException {
|
||||||
return sendCommand("HINCRBY", key, field, String.valueOf(value))
|
client.hincrBy(key, field, value);
|
||||||
.getIntegerReply();
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hexists(String key, String field) throws JedisException {
|
public int hexists(String key, String field) throws JedisException {
|
||||||
return sendCommand("HEXISTS", key, field).getIntegerReply();
|
client.hexists(key, field);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hdel(String key, String field) throws JedisException {
|
public int hdel(String key, String field) throws JedisException {
|
||||||
return sendCommand("HDEL", key, field).getIntegerReply();
|
client.hdel(key, field);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hlen(String key) throws JedisException {
|
public int hlen(String key) throws JedisException {
|
||||||
return sendCommand("HLEN", key).getIntegerReply();
|
client.hlen(key);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> hkeys(String key) throws JedisException {
|
public List<String> hkeys(String key) throws JedisException {
|
||||||
return sendCommand("HKEYS", key).getMultiBulkReply();
|
client.hkeys(key);
|
||||||
|
return client.getMultiBulkReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> hvals(String key) throws JedisException {
|
public List<String> hvals(String key) throws JedisException {
|
||||||
return sendCommand("HVALS", key).getMultiBulkReply();
|
client.hvals(key);
|
||||||
|
return client.getMultiBulkReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> hgetAll(String key) throws JedisException {
|
public Map<String, String> hgetAll(String key) throws JedisException {
|
||||||
List<String> flatHash = sendCommand("HGETALL", key).getMultiBulkReply();
|
client.hgetAll(key);
|
||||||
|
List<String> flatHash = client.getMultiBulkReply();
|
||||||
Map<String, String> hash = new HashMap<String, String>();
|
Map<String, String> hash = new HashMap<String, String>();
|
||||||
Iterator<String> iterator = flatHash.iterator();
|
Iterator<String> iterator = flatHash.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
@@ -219,169 +248,183 @@ public class Jedis extends Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int rpush(String key, String string) throws JedisException {
|
public int rpush(String key, String string) throws JedisException {
|
||||||
return sendCommand("RPUSH", key, string).getIntegerReply();
|
client.rpush(key, string);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int lpush(String key, String string) throws JedisException {
|
public int lpush(String key, String string) throws JedisException {
|
||||||
return sendCommand("LPUSH", key, string).getIntegerReply();
|
client.lpush(key, string);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int llen(String key) throws JedisException {
|
public int llen(String key) throws JedisException {
|
||||||
return sendCommand("LLEN", key).getIntegerReply();
|
client.llen(key);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> lrange(String key, int start, int end)
|
public List<String> lrange(String key, int start, int end)
|
||||||
throws JedisException {
|
throws JedisException {
|
||||||
return sendCommand("LRANGE", key, String.valueOf(start),
|
client.lrange(key, start, end);
|
||||||
String.valueOf(end)).getMultiBulkReply();
|
return client.getMultiBulkReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String ltrim(String key, int start, int end) throws JedisException {
|
public String ltrim(String key, int start, int end) throws JedisException {
|
||||||
return sendCommand("LTRIM", key, String.valueOf(start),
|
client.ltrim(key, start, end);
|
||||||
String.valueOf(end)).getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String lindex(String key, int index) throws JedisException {
|
public String lindex(String key, int index) throws JedisException {
|
||||||
return sendCommand("LINDEX", key, String.valueOf(index)).getBulkReply();
|
client.lindex(key, index);
|
||||||
|
return client.getBulkReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String lset(String key, int index, String value)
|
public String lset(String key, int index, String value)
|
||||||
throws JedisException {
|
throws JedisException {
|
||||||
return sendCommand("LSET", key, String.valueOf(index), value)
|
client.lset(key, index, value);
|
||||||
.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int lrem(String key, int count, String value) throws JedisException {
|
public int lrem(String key, int count, String value) throws JedisException {
|
||||||
return sendCommand("LREM", key, String.valueOf(count), value)
|
client.lrem(key, count, value);
|
||||||
.getIntegerReply();
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String lpop(String key) throws JedisException {
|
public String lpop(String key) throws JedisException {
|
||||||
return sendCommand("LPOP", key).getBulkReply();
|
client.lpop(key);
|
||||||
|
return client.getBulkReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String rpop(String key) throws JedisException {
|
public String rpop(String key) throws JedisException {
|
||||||
return sendCommand("RPOP", key).getBulkReply();
|
client.rpop(key);
|
||||||
|
return client.getBulkReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String rpoplpush(String srckey, String dstkey) throws JedisException {
|
public String rpoplpush(String srckey, String dstkey) throws JedisException {
|
||||||
return sendCommand("RPOPLPUSH", srckey, dstkey).getBulkReply();
|
client.rpoplpush(srckey, dstkey);
|
||||||
|
return client.getBulkReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int sadd(String key, String member) throws JedisException {
|
public int sadd(String key, String member) throws JedisException {
|
||||||
return sendCommand("SADD", key, member).getIntegerReply();
|
client.sadd(key, member);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> smembers(String key) throws JedisException {
|
public Set<String> smembers(String key) throws JedisException {
|
||||||
List<String> members = sendCommand("SMEMBERS", key).getMultiBulkReply();
|
client.smembers(key);
|
||||||
|
List<String> members = client.getMultiBulkReply();
|
||||||
return new LinkedHashSet<String>(members);
|
return new LinkedHashSet<String>(members);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int srem(String key, String member) throws JedisException {
|
public int srem(String key, String member) throws JedisException {
|
||||||
return sendCommand("SREM", key, member).getIntegerReply();
|
client.srem(key, member);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String spop(String key) throws JedisException {
|
public String spop(String key) throws JedisException {
|
||||||
return sendCommand("SPOP", key).getBulkReply();
|
client.spop(key);
|
||||||
|
return client.getBulkReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int smove(String srckey, String dstkey, String member)
|
public int smove(String srckey, String dstkey, String member)
|
||||||
throws JedisException {
|
throws JedisException {
|
||||||
return sendCommand("SMOVE", srckey, dstkey, member).getIntegerReply();
|
client.smove(srckey, dstkey, member);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int scard(String key) throws JedisException {
|
public int scard(String key) throws JedisException {
|
||||||
return sendCommand("SCARD", key).getIntegerReply();
|
client.scard(key);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int sismember(String key, String member) throws JedisException {
|
public int sismember(String key, String member) throws JedisException {
|
||||||
return sendCommand("SISMEMBER", key, member).getIntegerReply();
|
client.sismember(key, member);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> sinter(String... keys) throws JedisException {
|
public Set<String> sinter(String... keys) throws JedisException {
|
||||||
List<String> members = sendCommand("SINTER", keys).getMultiBulkReply();
|
client.sinter(keys);
|
||||||
|
List<String> members = client.getMultiBulkReply();
|
||||||
return new LinkedHashSet<String>(members);
|
return new LinkedHashSet<String>(members);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int sinterstore(String dstkey, String... keys) throws JedisException {
|
public int sinterstore(String dstkey, String... keys) throws JedisException {
|
||||||
String[] params = new String[keys.length + 1];
|
client.sinterstore(dstkey, keys);
|
||||||
params[0] = dstkey;
|
return client.getIntegerReply();
|
||||||
System.arraycopy(keys, 0, params, 1, keys.length);
|
|
||||||
return sendCommand("SINTERSTORE", params).getIntegerReply();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> sunion(String... keys) throws JedisException {
|
public Set<String> sunion(String... keys) throws JedisException {
|
||||||
List<String> members = sendCommand("SUNION", keys).getMultiBulkReply();
|
client.sunion(keys);
|
||||||
|
List<String> members = client.getMultiBulkReply();
|
||||||
return new LinkedHashSet<String>(members);
|
return new LinkedHashSet<String>(members);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int sunionstore(String dstkey, String... keys) throws JedisException {
|
public int sunionstore(String dstkey, String... keys) throws JedisException {
|
||||||
String[] params = new String[keys.length + 1];
|
client.sunionstore(dstkey, keys);
|
||||||
params[0] = dstkey;
|
return client.getIntegerReply();
|
||||||
System.arraycopy(keys, 0, params, 1, keys.length);
|
|
||||||
return sendCommand("SUNIONSTORE", params).getIntegerReply();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> sdiff(String... keys) throws JedisException {
|
public Set<String> sdiff(String... keys) throws JedisException {
|
||||||
List<String> members = sendCommand("SDIFF", keys).getMultiBulkReply();
|
client.sdiff(keys);
|
||||||
|
List<String> members = client.getMultiBulkReply();
|
||||||
return new LinkedHashSet<String>(members);
|
return new LinkedHashSet<String>(members);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int sdiffstore(String dstkey, String... keys) throws JedisException {
|
public int sdiffstore(String dstkey, String... keys) throws JedisException {
|
||||||
String[] params = new String[keys.length + 1];
|
client.sdiffstore(dstkey, keys);
|
||||||
params[0] = dstkey;
|
return client.getIntegerReply();
|
||||||
System.arraycopy(keys, 0, params, 1, keys.length);
|
|
||||||
return sendCommand("SDIFFSTORE", params).getIntegerReply();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String srandmember(String key) throws JedisException {
|
public String srandmember(String key) throws JedisException {
|
||||||
return sendCommand("SRANDMEMBER", key).getBulkReply();
|
client.srandmember(key);
|
||||||
|
return client.getBulkReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int zadd(String key, double score, String member)
|
public int zadd(String key, double score, String member)
|
||||||
throws JedisException {
|
throws JedisException {
|
||||||
return sendCommand("ZADD", key, String.valueOf(score), member)
|
client.zadd(key, score, member);
|
||||||
.getIntegerReply();
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> zrange(String key, int start, int end)
|
public Set<String> zrange(String key, int start, int end)
|
||||||
throws JedisException {
|
throws JedisException {
|
||||||
List<String> members = sendCommand("ZRANGE", key,
|
client.zrange(key, start, end);
|
||||||
String.valueOf(start), String.valueOf(end)).getMultiBulkReply();
|
List<String> members = client.getMultiBulkReply();
|
||||||
return new LinkedHashSet<String>(members);
|
return new LinkedHashSet<String>(members);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int zrem(String key, String member) throws JedisException {
|
public int zrem(String key, String member) throws JedisException {
|
||||||
return sendCommand("ZREM", key, member).getIntegerReply();
|
client.zrem(key, member);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double zincrby(String key, double score, String member)
|
public double zincrby(String key, double score, String member)
|
||||||
throws JedisException {
|
throws JedisException {
|
||||||
String newscore = sendCommand("ZINCRBY", key, String.valueOf(score),
|
client.zincrby(key, score, member);
|
||||||
member).getBulkReply();
|
String newscore = client.getBulkReply();
|
||||||
return Double.valueOf(newscore);
|
return Double.valueOf(newscore);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int zrank(String key, String member) throws JedisException {
|
public int zrank(String key, String member) throws JedisException {
|
||||||
return sendCommand("ZRANK", key, member).getIntegerReply();
|
client.zrank(key, member);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int zrevrank(String key, String member) throws JedisException {
|
public int zrevrank(String key, String member) throws JedisException {
|
||||||
return sendCommand("ZREVRANK", key, member).getIntegerReply();
|
client.zrevrank(key, member);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> zrevrange(String key, int start, int end)
|
public Set<String> zrevrange(String key, int start, int end)
|
||||||
throws JedisException {
|
throws JedisException {
|
||||||
List<String> members = sendCommand("ZREVRANGE", key,
|
client.zrevrange(key, start, end);
|
||||||
String.valueOf(start), String.valueOf(end)).getMultiBulkReply();
|
List<String> members = client.getMultiBulkReply();
|
||||||
return new LinkedHashSet<String>(members);
|
return new LinkedHashSet<String>(members);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Tuple> zrangeWithScores(String key, int start, int end)
|
public Set<Tuple> zrangeWithScores(String key, int start, int end)
|
||||||
throws JedisException {
|
throws JedisException {
|
||||||
List<String> membersWithScores = sendCommand("ZRANGE", key,
|
client.zrangeWithScores(key, start, end);
|
||||||
String.valueOf(start), String.valueOf(end), "WITHSCORES")
|
List<String> membersWithScores = client.getMultiBulkReply();
|
||||||
.getMultiBulkReply();
|
|
||||||
Set<Tuple> set = new LinkedHashSet<Tuple>();
|
Set<Tuple> set = new LinkedHashSet<Tuple>();
|
||||||
Iterator<String> iterator = membersWithScores.iterator();
|
Iterator<String> iterator = membersWithScores.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
@@ -394,9 +437,8 @@ public class Jedis extends Client {
|
|||||||
|
|
||||||
public Set<Tuple> zrevrangeWithScores(String key, int start, int end)
|
public Set<Tuple> zrevrangeWithScores(String key, int start, int end)
|
||||||
throws JedisException {
|
throws JedisException {
|
||||||
List<String> membersWithScores = sendCommand("ZREVRANGE", key,
|
client.zrevrangeWithScores(key, start, end);
|
||||||
String.valueOf(start), String.valueOf(end), "WITHSCORES")
|
List<String> membersWithScores = client.getMultiBulkReply();
|
||||||
.getMultiBulkReply();
|
|
||||||
Set<Tuple> set = new LinkedHashSet<Tuple>();
|
Set<Tuple> set = new LinkedHashSet<Tuple>();
|
||||||
Iterator<String> iterator = membersWithScores.iterator();
|
Iterator<String> iterator = membersWithScores.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
@@ -408,11 +450,39 @@ public class Jedis extends Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int zcard(String key) throws JedisException {
|
public int zcard(String key) throws JedisException {
|
||||||
return sendCommand("ZCARD", key).getIntegerReply();
|
client.zcard(key);
|
||||||
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double zscore(String key, String member) throws JedisException {
|
public double zscore(String key, String member) throws JedisException {
|
||||||
String score = sendCommand("ZSCORE", key, member).getBulkReply();
|
client.zscore(key, member);
|
||||||
|
String score = client.getBulkReply();
|
||||||
return Double.valueOf(score);
|
return Double.valueOf(score);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Transaction multi() throws JedisException {
|
||||||
|
client.multi();
|
||||||
|
client.getStatusCodeReply();
|
||||||
|
return new Transaction(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void multi(TransactionBlock jedisTransaction) throws JedisException {
|
||||||
|
try {
|
||||||
|
jedisTransaction.setClient(client);
|
||||||
|
client.multi();
|
||||||
|
client.getStatusCodeReply();
|
||||||
|
jedisTransaction.execute();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
client.discard();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void connect() throws UnknownHostException, IOException {
|
||||||
|
client.connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disconnect() throws IOException {
|
||||||
|
client.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
424
src/main/java/redis/clients/jedis/Transaction.java
Normal file
424
src/main/java/redis/clients/jedis/Transaction.java
Normal file
@@ -0,0 +1,424 @@
|
|||||||
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Transaction {
|
||||||
|
protected Client client = null;
|
||||||
|
|
||||||
|
public Transaction() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Transaction(Client client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String ping() throws JedisException {
|
||||||
|
client.ping();
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String set(String key, String value) throws JedisException {
|
||||||
|
client.set(key, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get(String key) throws JedisException {
|
||||||
|
client.sendCommand("GET", key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String exists(String key) throws JedisException {
|
||||||
|
client.exists(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String del(String... keys) throws JedisException {
|
||||||
|
client.del(keys);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String type(String key) throws JedisException {
|
||||||
|
client.type(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String flushDB() throws JedisException {
|
||||||
|
client.flushDB();
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String keys(String pattern) throws JedisException {
|
||||||
|
client.keys(pattern);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String randomKey() throws JedisException {
|
||||||
|
client.randomKey();
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String rename(String oldkey, String newkey) throws JedisException {
|
||||||
|
client.rename(oldkey, newkey);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String renamenx(String oldkey, String newkey) throws JedisException {
|
||||||
|
client.renamenx(oldkey, newkey);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String dbSize() throws JedisException {
|
||||||
|
client.dbSize();
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String expire(String key, int seconds) throws JedisException {
|
||||||
|
client.expire(key, seconds);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String expireAt(String key, long unixTime) throws JedisException {
|
||||||
|
client.expireAt(key, unixTime);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String ttl(String key) throws JedisException {
|
||||||
|
client.ttl(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String select(int index) throws JedisException {
|
||||||
|
client.select(index);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String move(String key, int dbIndex) throws JedisException {
|
||||||
|
client.move(key, dbIndex);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String flushAll() throws JedisException {
|
||||||
|
client.flushAll();
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSet(String key, String value) throws JedisException {
|
||||||
|
client.getSet(key, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String mget(String... keys) throws JedisException {
|
||||||
|
client.mget(keys);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String setnx(String key, String value) throws JedisException {
|
||||||
|
client.setnx(key, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String setex(String key, int seconds, String value)
|
||||||
|
throws JedisException {
|
||||||
|
client.setex(key, seconds, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String mset(String... keysvalues) throws JedisException {
|
||||||
|
client.mset(keysvalues);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String msetnx(String... keysvalues) throws JedisException {
|
||||||
|
client.msetnx(keysvalues);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String decrBy(String key, int integer) throws JedisException {
|
||||||
|
client.decrBy(key, integer);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String decr(String key) throws JedisException {
|
||||||
|
client.decr(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String incrBy(String key, int integer) throws JedisException {
|
||||||
|
client.incrBy(key, integer);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String incr(String key) throws JedisException {
|
||||||
|
client.incr(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String append(String key, String value) throws JedisException {
|
||||||
|
client.append(key, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String substr(String key, int start, int end) throws JedisException {
|
||||||
|
client.substr(key, start, end);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hset(String key, String field, String value)
|
||||||
|
throws JedisException {
|
||||||
|
client.hset(key, field, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hget(String key, String field) throws JedisException {
|
||||||
|
client.hget(key, field);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hsetnx(String key, String field, String value)
|
||||||
|
throws JedisException {
|
||||||
|
client.hsetnx(key, field, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hmset(String key, Map<String, String> hash)
|
||||||
|
throws JedisException {
|
||||||
|
client.hmset(key, hash);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hmget(String key, String... fields) throws JedisException {
|
||||||
|
client.hmget(key, fields);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hincrBy(String key, String field, int value)
|
||||||
|
throws JedisException {
|
||||||
|
client.hincrBy(key, field, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hexists(String key, String field) throws JedisException {
|
||||||
|
client.hexists(key, field);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hdel(String key, String field) throws JedisException {
|
||||||
|
client.hdel(key, field);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hlen(String key) throws JedisException {
|
||||||
|
client.hlen(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hkeys(String key) throws JedisException {
|
||||||
|
client.hkeys(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hvals(String key) throws JedisException {
|
||||||
|
client.hvals(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hgetAll(String key) throws JedisException {
|
||||||
|
client.hgetAll(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String rpush(String key, String string) throws JedisException {
|
||||||
|
client.rpush(key, string);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String lpush(String key, String string) throws JedisException {
|
||||||
|
client.lpush(key, string);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String llen(String key) throws JedisException {
|
||||||
|
client.llen(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String lrange(String key, int start, int end) throws JedisException {
|
||||||
|
client.lrange(key, start, end);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String ltrim(String key, int start, int end) throws JedisException {
|
||||||
|
client.ltrim(key, start, end);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String lindex(String key, int index) throws JedisException {
|
||||||
|
client.lindex(key, index);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String lset(String key, int index, String value)
|
||||||
|
throws JedisException {
|
||||||
|
client.lset(key, index, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String lrem(String key, int count, String value)
|
||||||
|
throws JedisException {
|
||||||
|
client.lrem(key, count, value);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String lpop(String key) throws JedisException {
|
||||||
|
client.lpop(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String rpop(String key) throws JedisException {
|
||||||
|
client.rpop(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String rpoplpush(String srckey, String dstkey) throws JedisException {
|
||||||
|
client.rpoplpush(srckey, dstkey);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sadd(String key, String member) throws JedisException {
|
||||||
|
client.sadd(key, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String smembers(String key) throws JedisException {
|
||||||
|
client.smembers(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String srem(String key, String member) throws JedisException {
|
||||||
|
client.srem(key, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String spop(String key) throws JedisException {
|
||||||
|
client.spop(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String smove(String srckey, String dstkey, String member)
|
||||||
|
throws JedisException {
|
||||||
|
client.smove(srckey, dstkey, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String scard(String key) throws JedisException {
|
||||||
|
client.scard(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sismember(String key, String member) throws JedisException {
|
||||||
|
client.sismember(key, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sinter(String... keys) throws JedisException {
|
||||||
|
client.sinter(keys);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sinterstore(String dstkey, String... keys)
|
||||||
|
throws JedisException {
|
||||||
|
client.sinterstore(dstkey, keys);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sunion(String... keys) throws JedisException {
|
||||||
|
client.sunion(keys);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sunionstore(String dstkey, String... keys)
|
||||||
|
throws JedisException {
|
||||||
|
client.sunionstore(dstkey, keys);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sdiff(String... keys) throws JedisException {
|
||||||
|
client.sdiff(keys);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String sdiffstore(String dstkey, String... keys)
|
||||||
|
throws JedisException {
|
||||||
|
client.sdiffstore(dstkey, keys);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String srandmember(String key) throws JedisException {
|
||||||
|
client.srandmember(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zadd(String key, double score, String member)
|
||||||
|
throws JedisException {
|
||||||
|
client.zadd(key, score, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zrange(String key, int start, int end) throws JedisException {
|
||||||
|
client.zrange(key, start, end);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zrem(String key, String member) throws JedisException {
|
||||||
|
client.zrem(key, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zincrby(String key, double score, String member)
|
||||||
|
throws JedisException {
|
||||||
|
client.zincrby(key, score, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zrank(String key, String member) throws JedisException {
|
||||||
|
client.zrank(key, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zrevrank(String key, String member) throws JedisException {
|
||||||
|
client.zrevrank(key, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zrevrange(String key, int start, int end)
|
||||||
|
throws JedisException {
|
||||||
|
client.zrevrange(key, start, end);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zrangeWithScores(String key, int start, int end)
|
||||||
|
throws JedisException {
|
||||||
|
client.zrangeWithScores(key, start, end);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zrevrangeWithScores(String key, int start, int end)
|
||||||
|
throws JedisException {
|
||||||
|
client.zrevrangeWithScores(key, start, end);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zcard(String key) throws JedisException {
|
||||||
|
client.zcard(key);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String zscore(String key, String member) throws JedisException {
|
||||||
|
client.zscore(key, member);
|
||||||
|
return client.getStatusCodeReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exec() throws JedisException {
|
||||||
|
client.exec();
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/main/java/redis/clients/jedis/TransactionBlock.java
Normal file
16
src/main/java/redis/clients/jedis/TransactionBlock.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
public abstract class TransactionBlock extends Transaction {
|
||||||
|
public TransactionBlock(Client client) {
|
||||||
|
super(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TransactionBlock() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void execute() throws JedisException;
|
||||||
|
|
||||||
|
public void setClient(Client client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
}
|
||||||
51
src/main/java/redis/clients/jedis/Tuple.java
Normal file
51
src/main/java/redis/clients/jedis/Tuple.java
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
public class Tuple {
|
||||||
|
private String element;
|
||||||
|
private double score;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((element == null) ? 0 : element.hashCode());
|
||||||
|
long temp;
|
||||||
|
temp = Double.doubleToLongBits(score);
|
||||||
|
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
Tuple other = (Tuple) obj;
|
||||||
|
if (element == null) {
|
||||||
|
if (other.element != null)
|
||||||
|
return false;
|
||||||
|
} else if (!element.equals(other.element))
|
||||||
|
return false;
|
||||||
|
if (Double.doubleToLongBits(score) != Double
|
||||||
|
.doubleToLongBits(other.score))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tuple(String element, double score) {
|
||||||
|
super();
|
||||||
|
this.element = element;
|
||||||
|
this.score = score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getElement() {
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getScore() {
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,14 +8,14 @@ import org.junit.Assert;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.Client;
|
import redis.clients.jedis.Connection;
|
||||||
|
|
||||||
public class ClientTest extends Assert {
|
public class ConnectionTest extends Assert {
|
||||||
private Client client;
|
private Connection client;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
client = new Client();
|
client = new Connection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@@ -207,7 +207,7 @@ public class ListCommandsTest extends Assert {
|
|||||||
String element = jedis.rpoplpush("foo", "dst");
|
String element = jedis.rpoplpush("foo", "dst");
|
||||||
|
|
||||||
assertEquals("c", element);
|
assertEquals("c", element);
|
||||||
|
|
||||||
List<String> srcExpected = new ArrayList<String>();
|
List<String> srcExpected = new ArrayList<String>();
|
||||||
srcExpected.add("a");
|
srcExpected.add("a");
|
||||||
srcExpected.add("b");
|
srcExpected.add("b");
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package redis.clients.jedis.tests.commands;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.JedisException;
|
||||||
|
import redis.clients.jedis.Transaction;
|
||||||
|
import redis.clients.jedis.TransactionBlock;
|
||||||
|
|
||||||
|
public class TransactionCommandsTest extends Assert {
|
||||||
|
private Jedis jedis;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
jedis = new Jedis("localhost");
|
||||||
|
jedis.connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
jedis.flushDB();
|
||||||
|
jedis.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void multi() throws JedisException {
|
||||||
|
Transaction trans = jedis.multi();
|
||||||
|
|
||||||
|
String status = trans.sadd("foo", "a");
|
||||||
|
assertEquals("QUEUED", status);
|
||||||
|
|
||||||
|
status = trans.sadd("foo", "b");
|
||||||
|
assertEquals("QUEUED", status);
|
||||||
|
|
||||||
|
status = trans.scard("foo");
|
||||||
|
assertEquals("QUEUED", status);
|
||||||
|
|
||||||
|
trans.exec();
|
||||||
|
|
||||||
|
//TODO: check for exec response
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void multiBlock() throws JedisException {
|
||||||
|
jedis.multi(new TransactionBlock() {
|
||||||
|
public void execute() throws JedisException {
|
||||||
|
String status = sadd("foo", "a");
|
||||||
|
assertEquals("QUEUED", status);
|
||||||
|
|
||||||
|
status = sadd("foo", "b");
|
||||||
|
assertEquals("QUEUED", status);
|
||||||
|
|
||||||
|
status = scard("foo");
|
||||||
|
assertEquals("QUEUED", status);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//TODO: check what happens when throwind an exception
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user