New exception management. Less exceptions... assume everything works

This commit is contained in:
Jonathan Leibiusky
2010-08-04 20:15:08 -03:00
parent b58ae0692c
commit 1df234153b
19 changed files with 399 additions and 454 deletions

View File

@@ -14,147 +14,143 @@ public class Client extends Connection {
super(host, port);
}
public void ping() throws JedisException {
public void ping() {
sendCommand("PING");
}
public void set(String key, String value) throws JedisException {
public void set(String key, String value) {
sendCommand("SET", key, value);
}
public void get(String key) throws JedisException {
public void get(String key) {
sendCommand("GET", key);
}
public void quit() throws JedisException {
public void quit() {
sendCommand("QUIT");
}
public void exists(String key) throws JedisException {
public void exists(String key) {
sendCommand("EXISTS", key);
}
public void del(String... keys) throws JedisException {
public void del(String... keys) {
sendCommand("DEL", keys);
}
public void type(String key) throws JedisException {
public void type(String key) {
sendCommand("TYPE", key);
}
public void flushDB() throws JedisException {
public void flushDB() {
sendCommand("FLUSHDB");
}
public void keys(String pattern) throws JedisException {
public void keys(String pattern) {
sendCommand("KEYS", pattern);
}
public void randomKey() throws JedisException {
public void randomKey() {
sendCommand("RANDOMKEY");
}
public void rename(String oldkey, String newkey) throws JedisException {
public void rename(String oldkey, String newkey) {
sendCommand("RENAME", oldkey, newkey);
}
public void renamenx(String oldkey, String newkey) throws JedisException {
public void renamenx(String oldkey, String newkey) {
sendCommand("RENAMENX", oldkey, newkey);
}
public void dbSize() throws JedisException {
public void dbSize() {
sendCommand("DBSIZE");
}
public void expire(String key, int seconds) throws JedisException {
public void expire(String key, int seconds) {
sendCommand("EXPIRE", key, String.valueOf(seconds));
}
public void expireAt(String key, long unixTime) throws JedisException {
public void expireAt(String key, long unixTime) {
sendCommand("EXPIREAT", key, String.valueOf(unixTime));
}
public void ttl(String key) throws JedisException {
public void ttl(String key) {
sendCommand("TTL", key);
}
public void select(int index) throws JedisException {
public void select(int index) {
sendCommand("SELECT", String.valueOf(index));
}
public void move(String key, int dbIndex) throws JedisException {
public void move(String key, int dbIndex) {
sendCommand("MOVE", key, String.valueOf(dbIndex));
}
public void flushAll() throws JedisException {
public void flushAll() {
sendCommand("FLUSHALL");
}
public void getSet(String key, String value) throws JedisException {
public void getSet(String key, String value) {
sendCommand("GETSET", key, value);
}
public void mget(String... keys) throws JedisException {
public void mget(String... keys) {
sendCommand("MGET", keys);
}
public void setnx(String key, String value) throws JedisException {
public void setnx(String key, String value) {
sendCommand("SETNX", key, value);
}
public void setex(String key, int seconds, String value)
throws JedisException {
public void setex(String key, int seconds, String value) {
sendCommand("SETEX", key, String.valueOf(seconds), value);
}
public void mset(String... keysvalues) throws JedisException {
public void mset(String... keysvalues) {
sendCommand("MSET", keysvalues);
}
public void msetnx(String... keysvalues) throws JedisException {
public void msetnx(String... keysvalues) {
sendCommand("MSETNX", keysvalues);
}
public void decrBy(String key, int integer) throws JedisException {
public void decrBy(String key, int integer) {
sendCommand("DECRBY", key, String.valueOf(integer));
}
public void decr(String key) throws JedisException {
public void decr(String key) {
sendCommand("DECR", key);
}
public void incrBy(String key, int integer) throws JedisException {
public void incrBy(String key, int integer) {
sendCommand("INCRBY", key, String.valueOf(integer));
}
public void incr(String key) throws JedisException {
public void incr(String key) {
sendCommand("INCR", key);
}
public void append(String key, String value) throws JedisException {
public void append(String key, String value) {
sendCommand("APPEND", key, value);
}
public void substr(String key, int start, int end) throws JedisException {
public void substr(String key, int start, int end) {
sendCommand("SUBSTR", key, String.valueOf(start), String.valueOf(end));
}
public void hset(String key, String field, String value)
throws JedisException {
public void hset(String key, String field, String value) {
sendCommand("HSET", key, field, value);
}
public void hget(String key, String field) throws JedisException {
public void hget(String key, String field) {
sendCommand("HGET", key, field);
}
public void hsetnx(String key, String field, String value)
throws JedisException {
public void hsetnx(String key, String field, String value) {
sendCommand("HSETNX", key, field, value);
}
public void hmset(String key, Map<String, String> hash)
throws JedisException {
public void hmset(String key, Map<String, String> hash) {
List<String> params = new ArrayList<String>();
params.add(key);
@@ -165,243 +161,233 @@ public class Client extends Connection {
sendCommand("HMSET", params.toArray(new String[params.size()]));
}
public void hmget(String key, String... fields) throws JedisException {
public void hmget(String key, String... fields) {
String[] params = new String[fields.length + 1];
params[0] = key;
System.arraycopy(fields, 0, params, 1, fields.length);
sendCommand("HMGET", params);
}
public void hincrBy(String key, String field, int value)
throws JedisException {
public void hincrBy(String key, String field, int value) {
sendCommand("HINCRBY", key, field, String.valueOf(value));
}
public void hexists(String key, String field) throws JedisException {
public void hexists(String key, String field) {
sendCommand("HEXISTS", key, field);
}
public void hdel(String key, String field) throws JedisException {
public void hdel(String key, String field) {
sendCommand("HDEL", key, field);
}
public void hlen(String key) throws JedisException {
public void hlen(String key) {
sendCommand("HLEN", key);
}
public void hkeys(String key) throws JedisException {
public void hkeys(String key) {
sendCommand("HKEYS", key);
}
public void hvals(String key) throws JedisException {
public void hvals(String key) {
sendCommand("HVALS", key);
}
public void hgetAll(String key) throws JedisException {
public void hgetAll(String key) {
sendCommand("HGETALL", key);
}
public void rpush(String key, String string) throws JedisException {
public void rpush(String key, String string) {
sendCommand("RPUSH", key, string);
}
public void lpush(String key, String string) throws JedisException {
public void lpush(String key, String string) {
sendCommand("LPUSH", key, string);
}
public void llen(String key) throws JedisException {
public void llen(String key) {
sendCommand("LLEN", key);
}
public void lrange(String key, int start, int end) throws JedisException {
public void lrange(String key, int start, int end) {
sendCommand("LRANGE", key, String.valueOf(start), String.valueOf(end));
}
public void ltrim(String key, int start, int end) throws JedisException {
public void ltrim(String key, int start, int end) {
sendCommand("LTRIM", key, String.valueOf(start), String.valueOf(end));
}
public void lindex(String key, int index) throws JedisException {
public void lindex(String key, int index) {
sendCommand("LINDEX", key, String.valueOf(index));
}
public void lset(String key, int index, String value) throws JedisException {
public void lset(String key, int index, String value) {
sendCommand("LSET", key, String.valueOf(index), value);
}
public void lrem(String key, int count, String value) throws JedisException {
public void lrem(String key, int count, String value) {
sendCommand("LREM", key, String.valueOf(count), value);
}
public void lpop(String key) throws JedisException {
public void lpop(String key) {
sendCommand("LPOP", key);
}
public void rpop(String key) throws JedisException {
public void rpop(String key) {
sendCommand("RPOP", key);
}
public void rpoplpush(String srckey, String dstkey) throws JedisException {
public void rpoplpush(String srckey, String dstkey) {
sendCommand("RPOPLPUSH", srckey, dstkey);
}
public void sadd(String key, String member) throws JedisException {
public void sadd(String key, String member) {
sendCommand("SADD", key, member);
}
public void smembers(String key) throws JedisException {
public void smembers(String key) {
sendCommand("SMEMBERS", key);
}
public void srem(String key, String member) throws JedisException {
public void srem(String key, String member) {
sendCommand("SREM", key, member);
}
public void spop(String key) throws JedisException {
public void spop(String key) {
sendCommand("SPOP", key);
}
public void smove(String srckey, String dstkey, String member)
throws JedisException {
public void smove(String srckey, String dstkey, String member) {
sendCommand("SMOVE", srckey, dstkey, member);
}
public void scard(String key) throws JedisException {
public void scard(String key) {
sendCommand("SCARD", key);
}
public void sismember(String key, String member) throws JedisException {
public void sismember(String key, String member) {
sendCommand("SISMEMBER", key, member);
}
public void sinter(String... keys) throws JedisException {
public void sinter(String... keys) {
sendCommand("SINTER", keys);
}
public void sinterstore(String dstkey, String... keys)
throws JedisException {
public void sinterstore(String dstkey, String... keys) {
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 {
public void sunion(String... keys) {
sendCommand("SUNION", keys);
}
public void sunionstore(String dstkey, String... keys)
throws JedisException {
public void sunionstore(String dstkey, String... keys) {
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 {
public void sdiff(String... keys) {
sendCommand("SDIFF", keys);
}
public void sdiffstore(String dstkey, String... keys) throws JedisException {
public void sdiffstore(String dstkey, String... keys) {
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 {
public void srandmember(String key) {
sendCommand("SRANDMEMBER", key);
}
public void zadd(String key, double score, String member)
throws JedisException {
public void zadd(String key, double score, String member) {
sendCommand("ZADD", key, String.valueOf(score), member);
}
public void zrange(String key, int start, int end) throws JedisException {
public void zrange(String key, int start, int end) {
sendCommand("ZRANGE", key, String.valueOf(start), String.valueOf(end));
}
public void zrem(String key, String member) throws JedisException {
public void zrem(String key, String member) {
sendCommand("ZREM", key, member);
}
public void zincrby(String key, double score, String member)
throws JedisException {
public void zincrby(String key, double score, String member) {
sendCommand("ZINCRBY", key, String.valueOf(score), member);
}
public void zrank(String key, String member) throws JedisException {
public void zrank(String key, String member) {
sendCommand("ZRANK", key, member);
}
public void zrevrank(String key, String member) throws JedisException {
public void zrevrank(String key, String member) {
sendCommand("ZREVRANK", key, member);
}
public void zrevrange(String key, int start, int end) throws JedisException {
public void zrevrange(String key, int start, int end) {
sendCommand("ZREVRANGE", key, String.valueOf(start), String
.valueOf(end));
}
public void zrangeWithScores(String key, int start, int end)
throws JedisException {
public void zrangeWithScores(String key, int start, int end) {
sendCommand("ZRANGE", key, String.valueOf(start), String.valueOf(end),
"WITHSCORES");
}
public void zrevrangeWithScores(String key, int start, int end)
throws JedisException {
public void zrevrangeWithScores(String key, int start, int end) {
sendCommand("ZREVRANGE", key, String.valueOf(start), String
.valueOf(end), "WITHSCORES");
}
public void zcard(String key) throws JedisException {
public void zcard(String key) {
sendCommand("ZCARD", key);
}
public void zscore(String key, String member) throws JedisException {
public void zscore(String key, String member) {
sendCommand("ZSCORE", key, member);
}
public void multi() throws JedisException {
public void multi() {
sendCommand("MULTI");
}
public void discard() throws JedisException {
public void discard() {
sendCommand("MULTI");
}
public void exec() throws JedisException {
public void exec() {
sendCommand("EXEC");
}
public void watch(String key) throws JedisException {
public void watch(String key) {
sendCommand("WATCH", key);
}
public void unwatch() throws JedisException {
public void unwatch() {
sendCommand("UNWATCH");
}
public void sort(String key) throws JedisException {
public void sort(String key) {
sendCommand("SORT", key);
}
public void sort(String key, SortingParams sortingParameters)
throws JedisException {
public void sort(String key, SortingParams sortingParameters) {
List<String> args = new ArrayList<String>();
args.add(key);
args.addAll(sortingParameters.getParams());
sendCommand("SORT", args.toArray(new String[args.size()]));
}
public void blpop(String[] args) throws JedisException {
public void blpop(String[] args) {
sendCommand("BLPOP", args);
}
public void sort(String key, SortingParams sortingParameters, String dstkey)
throws JedisException {
public void sort(String key, SortingParams sortingParameters, String dstkey) {
List<String> args = new ArrayList<String>();
args.add(key);
args.addAll(sortingParameters.getParams());
@@ -410,15 +396,15 @@ public class Client extends Connection {
sendCommand("SORT", args.toArray(new String[args.size()]));
}
public void sort(String key, String dstkey) throws JedisException {
public void sort(String key, String dstkey) {
sendCommand("SORT", key, "STORE", dstkey);
}
public void brpop(String[] args) throws JedisException {
public void brpop(String[] args) {
sendCommand("BRPOP", args);
}
public void auth(String password) throws JedisException {
public void auth(String password) {
sendCommand("AUTH", password);
}
}

View File

@@ -21,8 +21,7 @@ public class Connection {
this.host = host;
}
protected Connection sendCommand(String name, String... args)
throws JedisException {
protected Connection sendCommand(String name, String... args) {
if (!isConnected()) {
throw new JedisException("Please connect Jedis before using it.");
}
@@ -79,24 +78,24 @@ public class Connection {
return connected;
}
protected String getStatusCodeReply() throws JedisException {
protected String getStatusCodeReply() {
return protocol.getStatusCodeReply(inputStream);
}
public String getBulkReply() throws JedisException {
public String getBulkReply() {
return protocol.getBulkReply(inputStream);
}
public int getIntegerReply() throws JedisException {
public int getIntegerReply() {
return protocol.getIntegerReply(inputStream);
}
@SuppressWarnings("unchecked")
public List<String> getMultiBulkReply() throws JedisException {
public List<String> getMultiBulkReply() {
return (List<String>) (List<?>) protocol.getMultiBulkReply(inputStream);
}
public List<Object> getObjectMultiBulkReply() throws JedisException {
public List<Object> getObjectMultiBulkReply() {
return protocol.getMultiBulkReply(inputStream);
}

View File

@@ -21,222 +21,216 @@ public class Jedis {
client = new Client(host, port);
}
public String ping() throws JedisException {
public String ping() {
client.ping();
return client.getStatusCodeReply();
}
public String set(String key, String value) throws JedisException {
public String set(String key, String value) {
client.set(key, value);
return client.getStatusCodeReply();
}
public String get(String key) throws JedisException {
public String get(String key) {
client.sendCommand("GET", key);
return client.getBulkReply();
}
public void quit() throws JedisException {
public void quit() {
client.quit();
}
public int exists(String key) throws JedisException {
public int exists(String key) {
client.exists(key);
return client.getIntegerReply();
}
public int del(String... keys) throws JedisException {
public int del(String... keys) {
client.del(keys);
return client.getIntegerReply();
}
public String type(String key) throws JedisException {
public String type(String key) {
client.type(key);
return client.getStatusCodeReply();
}
public String flushDB() throws JedisException {
public String flushDB() {
client.flushDB();
return client.getStatusCodeReply();
}
public List<String> keys(String pattern) throws JedisException {
public List<String> keys(String pattern) {
client.keys(pattern);
return client.getMultiBulkReply();
}
public String randomKey() throws JedisException {
public String randomKey() {
client.randomKey();
return client.getBulkReply();
}
public String rename(String oldkey, String newkey) throws JedisException {
public String rename(String oldkey, String newkey) {
client.rename(oldkey, newkey);
return client.getStatusCodeReply();
}
public int renamenx(String oldkey, String newkey) throws JedisException {
public int renamenx(String oldkey, String newkey) {
client.renamenx(oldkey, newkey);
return client.getIntegerReply();
}
public int dbSize() throws JedisException {
public int dbSize() {
client.dbSize();
return client.getIntegerReply();
}
public int expire(String key, int seconds) throws JedisException {
public int expire(String key, int seconds) {
client.expire(key, seconds);
return client.getIntegerReply();
}
public int expireAt(String key, long unixTime) throws JedisException {
public int expireAt(String key, long unixTime) {
client.expireAt(key, unixTime);
return client.getIntegerReply();
}
public int ttl(String key) throws JedisException {
public int ttl(String key) {
client.ttl(key);
return client.getIntegerReply();
}
public String select(int index) throws JedisException {
public String select(int index) {
client.select(index);
return client.getStatusCodeReply();
}
public int move(String key, int dbIndex) throws JedisException {
public int move(String key, int dbIndex) {
client.move(key, dbIndex);
return client.getIntegerReply();
}
public String flushAll() throws JedisException {
public String flushAll() {
client.flushAll();
return client.getStatusCodeReply();
}
public String getSet(String key, String value) throws JedisException {
public String getSet(String key, String value) {
client.getSet(key, value);
return client.getBulkReply();
}
public List<String> mget(String... keys) throws JedisException {
public List<String> mget(String... keys) {
client.mget(keys);
return client.getMultiBulkReply();
}
public int setnx(String key, String value) throws JedisException {
public int setnx(String key, String value) {
client.setnx(key, value);
return client.getIntegerReply();
}
public String setex(String key, int seconds, String value)
throws JedisException {
public String setex(String key, int seconds, String value) {
client.setex(key, seconds, value);
return client.getStatusCodeReply();
}
public String mset(String... keysvalues) throws JedisException {
public String mset(String... keysvalues) {
client.mset(keysvalues);
return client.getStatusCodeReply();
}
public int msetnx(String... keysvalues) throws JedisException {
public int msetnx(String... keysvalues) {
client.msetnx(keysvalues);
return client.getIntegerReply();
}
public int decrBy(String key, int integer) throws JedisException {
public int decrBy(String key, int integer) {
client.decrBy(key, integer);
return client.getIntegerReply();
}
public int decr(String key) throws JedisException {
public int decr(String key) {
client.decr(key);
return client.getIntegerReply();
}
public int incrBy(String key, int integer) throws JedisException {
public int incrBy(String key, int integer) {
client.incrBy(key, integer);
return client.getIntegerReply();
}
public int incr(String key) throws JedisException {
public int incr(String key) {
client.incr(key);
return client.getIntegerReply();
}
public int append(String key, String value) throws JedisException {
public int append(String key, String value) {
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) {
client.substr(key, start, end);
return client.getBulkReply();
}
public int hset(String key, String field, String value)
throws JedisException {
public int hset(String key, String field, String value) {
client.hset(key, field, value);
return client.getIntegerReply();
}
public String hget(String key, String field) throws JedisException {
public String hget(String key, String field) {
client.hget(key, field);
return client.getBulkReply();
}
public int hsetnx(String key, String field, String value)
throws JedisException {
public int hsetnx(String key, String field, String value) {
client.hsetnx(key, field, value);
return client.getIntegerReply();
}
public String hmset(String key, Map<String, String> hash)
throws JedisException {
public String hmset(String key, Map<String, String> hash) {
client.hmset(key, hash);
return client.getStatusCodeReply();
}
public List<String> hmget(String key, String... fields)
throws JedisException {
public List<String> hmget(String key, String... fields) {
client.hmget(key, fields);
return client.getMultiBulkReply();
}
public int hincrBy(String key, String field, int value)
throws JedisException {
public int hincrBy(String key, String field, int value) {
client.hincrBy(key, field, value);
return client.getIntegerReply();
}
public int hexists(String key, String field) throws JedisException {
public int hexists(String key, String field) {
client.hexists(key, field);
return client.getIntegerReply();
}
public int hdel(String key, String field) throws JedisException {
public int hdel(String key, String field) {
client.hdel(key, field);
return client.getIntegerReply();
}
public int hlen(String key) throws JedisException {
public int hlen(String key) {
client.hlen(key);
return client.getIntegerReply();
}
public List<String> hkeys(String key) throws JedisException {
public List<String> hkeys(String key) {
client.hkeys(key);
return client.getMultiBulkReply();
}
public List<String> hvals(String key) throws JedisException {
public List<String> hvals(String key) {
client.hvals(key);
return client.getMultiBulkReply();
}
public Map<String, String> hgetAll(String key) throws JedisException {
public Map<String, String> hgetAll(String key) {
client.hgetAll(key);
List<String> flatHash = client.getMultiBulkReply();
Map<String, String> hash = new HashMap<String, String>();
@@ -248,182 +242,174 @@ public class Jedis {
return hash;
}
public int rpush(String key, String string) throws JedisException {
public int rpush(String key, String string) {
client.rpush(key, string);
return client.getIntegerReply();
}
public int lpush(String key, String string) throws JedisException {
public int lpush(String key, String string) {
client.lpush(key, string);
return client.getIntegerReply();
}
public int llen(String key) throws JedisException {
public int llen(String key) {
client.llen(key);
return client.getIntegerReply();
}
public List<String> lrange(String key, int start, int end)
throws JedisException {
public List<String> lrange(String key, int start, int end) {
client.lrange(key, start, end);
return client.getMultiBulkReply();
}
public String ltrim(String key, int start, int end) throws JedisException {
public String ltrim(String key, int start, int end) {
client.ltrim(key, start, end);
return client.getStatusCodeReply();
}
public String lindex(String key, int index) throws JedisException {
public String lindex(String key, int index) {
client.lindex(key, index);
return client.getBulkReply();
}
public String lset(String key, int index, String value)
throws JedisException {
public String lset(String key, int index, String value) {
client.lset(key, index, value);
return client.getStatusCodeReply();
}
public int lrem(String key, int count, String value) throws JedisException {
public int lrem(String key, int count, String value) {
client.lrem(key, count, value);
return client.getIntegerReply();
}
public String lpop(String key) throws JedisException {
public String lpop(String key) {
client.lpop(key);
return client.getBulkReply();
}
public String rpop(String key) throws JedisException {
public String rpop(String key) {
client.rpop(key);
return client.getBulkReply();
}
public String rpoplpush(String srckey, String dstkey) throws JedisException {
public String rpoplpush(String srckey, String dstkey) {
client.rpoplpush(srckey, dstkey);
return client.getBulkReply();
}
public int sadd(String key, String member) throws JedisException {
public int sadd(String key, String member) {
client.sadd(key, member);
return client.getIntegerReply();
}
public Set<String> smembers(String key) throws JedisException {
public Set<String> smembers(String key) {
client.smembers(key);
List<String> members = client.getMultiBulkReply();
return new LinkedHashSet<String>(members);
}
public int srem(String key, String member) throws JedisException {
public int srem(String key, String member) {
client.srem(key, member);
return client.getIntegerReply();
}
public String spop(String key) throws JedisException {
public String spop(String key) {
client.spop(key);
return client.getBulkReply();
}
public int smove(String srckey, String dstkey, String member)
throws JedisException {
public int smove(String srckey, String dstkey, String member) {
client.smove(srckey, dstkey, member);
return client.getIntegerReply();
}
public int scard(String key) throws JedisException {
public int scard(String key) {
client.scard(key);
return client.getIntegerReply();
}
public int sismember(String key, String member) throws JedisException {
public int sismember(String key, String member) {
client.sismember(key, member);
return client.getIntegerReply();
}
public Set<String> sinter(String... keys) throws JedisException {
public Set<String> sinter(String... keys) {
client.sinter(keys);
List<String> members = client.getMultiBulkReply();
return new LinkedHashSet<String>(members);
}
public int sinterstore(String dstkey, String... keys) throws JedisException {
public int sinterstore(String dstkey, String... keys) {
client.sinterstore(dstkey, keys);
return client.getIntegerReply();
}
public Set<String> sunion(String... keys) throws JedisException {
public Set<String> sunion(String... keys) {
client.sunion(keys);
List<String> members = client.getMultiBulkReply();
return new LinkedHashSet<String>(members);
}
public int sunionstore(String dstkey, String... keys) throws JedisException {
public int sunionstore(String dstkey, String... keys) {
client.sunionstore(dstkey, keys);
return client.getIntegerReply();
}
public Set<String> sdiff(String... keys) throws JedisException {
public Set<String> sdiff(String... keys) {
client.sdiff(keys);
List<String> members = client.getMultiBulkReply();
return new LinkedHashSet<String>(members);
}
public int sdiffstore(String dstkey, String... keys) throws JedisException {
public int sdiffstore(String dstkey, String... keys) {
client.sdiffstore(dstkey, keys);
return client.getIntegerReply();
}
public String srandmember(String key) throws JedisException {
public String srandmember(String key) {
client.srandmember(key);
return client.getBulkReply();
}
public int zadd(String key, double score, String member)
throws JedisException {
public int zadd(String key, double score, String member) {
client.zadd(key, score, member);
return client.getIntegerReply();
}
public Set<String> zrange(String key, int start, int end)
throws JedisException {
public Set<String> zrange(String key, int start, int end) {
client.zrange(key, start, end);
List<String> members = client.getMultiBulkReply();
return new LinkedHashSet<String>(members);
}
public int zrem(String key, String member) throws JedisException {
public int zrem(String key, String member) {
client.zrem(key, member);
return client.getIntegerReply();
}
public double zincrby(String key, double score, String member)
throws JedisException {
public double zincrby(String key, double score, String member) {
client.zincrby(key, score, member);
String newscore = client.getBulkReply();
return Double.valueOf(newscore);
}
public int zrank(String key, String member) throws JedisException {
public int zrank(String key, String member) {
client.zrank(key, member);
return client.getIntegerReply();
}
public int zrevrank(String key, String member) throws JedisException {
public int zrevrank(String key, String member) {
client.zrevrank(key, member);
return client.getIntegerReply();
}
public Set<String> zrevrange(String key, int start, int end)
throws JedisException {
public Set<String> zrevrange(String key, int start, int end) {
client.zrevrange(key, start, end);
List<String> members = client.getMultiBulkReply();
return new LinkedHashSet<String>(members);
}
public Set<Tuple> zrangeWithScores(String key, int start, int end)
throws JedisException {
public Set<Tuple> zrangeWithScores(String key, int start, int end) {
client.zrangeWithScores(key, start, end);
List<String> membersWithScores = client.getMultiBulkReply();
Set<Tuple> set = new LinkedHashSet<Tuple>();
@@ -436,8 +422,7 @@ public class Jedis {
return set;
}
public Set<Tuple> zrevrangeWithScores(String key, int start, int end)
throws JedisException {
public Set<Tuple> zrevrangeWithScores(String key, int start, int end) {
client.zrevrangeWithScores(key, start, end);
List<String> membersWithScores = client.getMultiBulkReply();
Set<Tuple> set = new LinkedHashSet<Tuple>();
@@ -450,25 +435,24 @@ public class Jedis {
return set;
}
public int zcard(String key) throws JedisException {
public int zcard(String key) {
client.zcard(key);
return client.getIntegerReply();
}
public double zscore(String key, String member) throws JedisException {
public double zscore(String key, String member) {
client.zscore(key, member);
String score = client.getBulkReply();
return Double.valueOf(score);
}
public Transaction multi() throws JedisException {
public Transaction multi() {
client.multi();
client.getStatusCodeReply();
return new Transaction(client);
}
public List<Object> multi(TransactionBlock jedisTransaction)
throws JedisException {
public List<Object> multi(TransactionBlock jedisTransaction) {
try {
jedisTransaction.setClient(client);
multi();
@@ -487,29 +471,27 @@ public class Jedis {
client.disconnect();
}
public String watch(String key) throws JedisException {
public String watch(String key) {
client.watch(key);
return client.getStatusCodeReply();
}
public String unwatch() throws JedisException {
public String unwatch() {
client.unwatch();
return client.getStatusCodeReply();
}
public List<String> sort(String key) throws JedisException {
public List<String> sort(String key) {
client.sort(key);
return client.getMultiBulkReply();
}
public List<String> sort(String key, SortingParams sortingParameters)
throws JedisException {
public List<String> sort(String key, SortingParams sortingParameters) {
client.sort(key, sortingParameters);
return client.getMultiBulkReply();
}
public List<String> blpop(int timeout, String... keys)
throws JedisException {
public List<String> blpop(int timeout, String... keys) {
List<String> args = new ArrayList<String>();
for (String arg : keys) {
args.add(arg);
@@ -520,19 +502,17 @@ public class Jedis {
return client.getMultiBulkReply();
}
public int sort(String key, SortingParams sortingParameters, String dstkey)
throws JedisException {
public int sort(String key, SortingParams sortingParameters, String dstkey) {
client.sort(key, sortingParameters, dstkey);
return client.getIntegerReply();
}
public int sort(String key, String dstkey) throws JedisException {
public int sort(String key, String dstkey) {
client.sort(key, dstkey);
return client.getIntegerReply();
}
public List<String> brpop(int timeout, String... keys)
throws JedisException {
public List<String> brpop(int timeout, String... keys) {
List<String> args = new ArrayList<String>();
for (String arg : keys) {
args.add(arg);
@@ -543,7 +523,7 @@ public class Jedis {
return client.getMultiBulkReply();
}
public String auth(String password) throws JedisException {
public String auth(String password) {
client.auth(password);
return client.getStatusCodeReply();
}

View File

@@ -1,6 +1,8 @@
package redis.clients.jedis;
public class JedisException extends Exception {
import java.io.IOException;
public class JedisException extends RuntimeException {
/**
*
*/
@@ -9,4 +11,8 @@ public class JedisException extends Exception {
public JedisException(String message) {
super(message);
}
public JedisException(IOException e) {
super(e);
}
}

View File

@@ -32,11 +32,11 @@ public class Protocol {
try {
os.write(builder.toString().getBytes());
} catch (IOException e) {
// TODO don't know what to do here!
throw new JedisException(e);
}
}
public void processError(InputStream is) throws JedisException {
public void processError(InputStream is) {
String message = readLine(is);
throw new JedisException(message);
}
@@ -60,27 +60,27 @@ public class Protocol {
}
}
} catch (IOException e) {
// TODO Dont know what to do here!
throw new JedisException(e);
}
return sb.toString();
}
public String getBulkReply(InputStream is) throws JedisException {
public String getBulkReply(InputStream is) {
Object reply = process(is);
return (String) reply;
}
public String getStatusCodeReply(InputStream is) throws JedisException {
public String getStatusCodeReply(InputStream is) {
Object reply = process(is);
return (String) reply;
}
public int getIntegerReply(InputStream is) throws JedisException {
public int getIntegerReply(InputStream is) {
Object reply = process(is);
return (Integer) reply;
}
private Object process(InputStream is) throws JedisException {
private Object process(InputStream is) {
try {
byte b = (byte) is.read();
if (b == MINUS_BYTE) {
@@ -95,8 +95,7 @@ public class Protocol {
return processStatusCodeReply(is);
}
} catch (IOException e) {
// TODO check what to do here
throw new JedisException(e.getMessage());
throw new JedisException(e);
}
return null;
}
@@ -107,16 +106,20 @@ public class Protocol {
return ret;
}
private Object processBulkReply(InputStream is) throws IOException {
private Object processBulkReply(InputStream is) {
int len = Integer.parseInt(readLine(is));
if (len == -1) {
return null;
}
byte[] read = new byte[len];
is.read(read);
// read 2 more bytes for the command delimiter
is.read();
is.read();
try {
is.read(read);
// read 2 more bytes for the command delimiter
is.read();
is.read();
} catch (IOException e) {
throw new JedisException(e);
}
return new String(read);
}
@@ -128,7 +131,7 @@ public class Protocol {
return ret;
}
private Object processMultiBulkReply(InputStream is) throws JedisException {
private Object processMultiBulkReply(InputStream is) {
int num = Integer.parseInt(readLine(is));
if (num == -1) {
return null;
@@ -141,7 +144,7 @@ public class Protocol {
}
@SuppressWarnings("unchecked")
public List<Object> getMultiBulkReply(InputStream is) throws JedisException {
public List<Object> getMultiBulkReply(InputStream is) {
Object reply = process(is);
List<Object> ret = (List<Object>) reply;
return ret;

View File

@@ -13,413 +13,397 @@ public class Transaction {
this.client = client;
}
public String ping() throws JedisException {
public String ping() {
client.ping();
return client.getStatusCodeReply();
}
public String set(String key, String value) throws JedisException {
public String set(String key, String value) {
client.set(key, value);
return client.getStatusCodeReply();
}
public String get(String key) throws JedisException {
public String get(String key) {
client.sendCommand("GET", key);
return client.getStatusCodeReply();
}
public String exists(String key) throws JedisException {
public String exists(String key) {
client.exists(key);
return client.getStatusCodeReply();
}
public String del(String... keys) throws JedisException {
public String del(String... keys) {
client.del(keys);
return client.getStatusCodeReply();
}
public String type(String key) throws JedisException {
public String type(String key) {
client.type(key);
return client.getStatusCodeReply();
}
public String flushDB() throws JedisException {
public String flushDB() {
client.flushDB();
return client.getStatusCodeReply();
}
public String keys(String pattern) throws JedisException {
public String keys(String pattern) {
client.keys(pattern);
return client.getStatusCodeReply();
}
public String randomKey() throws JedisException {
public String randomKey() {
client.randomKey();
return client.getStatusCodeReply();
}
public String rename(String oldkey, String newkey) throws JedisException {
public String rename(String oldkey, String newkey) {
client.rename(oldkey, newkey);
return client.getStatusCodeReply();
}
public String renamenx(String oldkey, String newkey) throws JedisException {
public String renamenx(String oldkey, String newkey) {
client.renamenx(oldkey, newkey);
return client.getStatusCodeReply();
}
public String dbSize() throws JedisException {
public String dbSize() {
client.dbSize();
return client.getStatusCodeReply();
}
public String expire(String key, int seconds) throws JedisException {
public String expire(String key, int seconds) {
client.expire(key, seconds);
return client.getStatusCodeReply();
}
public String expireAt(String key, long unixTime) throws JedisException {
public String expireAt(String key, long unixTime) {
client.expireAt(key, unixTime);
return client.getStatusCodeReply();
}
public String ttl(String key) throws JedisException {
public String ttl(String key) {
client.ttl(key);
return client.getStatusCodeReply();
}
public String select(int index) throws JedisException {
public String select(int index) {
client.select(index);
return client.getStatusCodeReply();
}
public String move(String key, int dbIndex) throws JedisException {
public String move(String key, int dbIndex) {
client.move(key, dbIndex);
return client.getStatusCodeReply();
}
public String flushAll() throws JedisException {
public String flushAll() {
client.flushAll();
return client.getStatusCodeReply();
}
public String getSet(String key, String value) throws JedisException {
public String getSet(String key, String value) {
client.getSet(key, value);
return client.getStatusCodeReply();
}
public String mget(String... keys) throws JedisException {
public String mget(String... keys) {
client.mget(keys);
return client.getStatusCodeReply();
}
public String setnx(String key, String value) throws JedisException {
public String setnx(String key, String value) {
client.setnx(key, value);
return client.getStatusCodeReply();
}
public String setex(String key, int seconds, String value)
throws JedisException {
public String setex(String key, int seconds, String value) {
client.setex(key, seconds, value);
return client.getStatusCodeReply();
}
public String mset(String... keysvalues) throws JedisException {
public String mset(String... keysvalues) {
client.mset(keysvalues);
return client.getStatusCodeReply();
}
public String msetnx(String... keysvalues) throws JedisException {
public String msetnx(String... keysvalues) {
client.msetnx(keysvalues);
return client.getStatusCodeReply();
}
public String decrBy(String key, int integer) throws JedisException {
public String decrBy(String key, int integer) {
client.decrBy(key, integer);
return client.getStatusCodeReply();
}
public String decr(String key) throws JedisException {
public String decr(String key) {
client.decr(key);
return client.getStatusCodeReply();
}
public String incrBy(String key, int integer) throws JedisException {
public String incrBy(String key, int integer) {
client.incrBy(key, integer);
return client.getStatusCodeReply();
}
public String incr(String key) throws JedisException {
public String incr(String key) {
client.incr(key);
return client.getStatusCodeReply();
}
public String append(String key, String value) throws JedisException {
public String append(String key, String value) {
client.append(key, value);
return client.getStatusCodeReply();
}
public String substr(String key, int start, int end) throws JedisException {
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)
throws JedisException {
public String hset(String key, String field, String value) {
client.hset(key, field, value);
return client.getStatusCodeReply();
}
public String hget(String key, String field) throws JedisException {
public String hget(String key, String field) {
client.hget(key, field);
return client.getStatusCodeReply();
}
public String hsetnx(String key, String field, String value)
throws JedisException {
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)
throws JedisException {
public String hmset(String key, Map<String, String> hash) {
client.hmset(key, hash);
return client.getStatusCodeReply();
}
public String hmget(String key, String... fields) throws JedisException {
public String hmget(String key, String... fields) {
client.hmget(key, fields);
return client.getStatusCodeReply();
}
public String hincrBy(String key, String field, int value)
throws JedisException {
public String hincrBy(String key, String field, int value) {
client.hincrBy(key, field, value);
return client.getStatusCodeReply();
}
public String hexists(String key, String field) throws JedisException {
public String hexists(String key, String field) {
client.hexists(key, field);
return client.getStatusCodeReply();
}
public String hdel(String key, String field) throws JedisException {
public String hdel(String key, String field) {
client.hdel(key, field);
return client.getStatusCodeReply();
}
public String hlen(String key) throws JedisException {
public String hlen(String key) {
client.hlen(key);
return client.getStatusCodeReply();
}
public String hkeys(String key) throws JedisException {
public String hkeys(String key) {
client.hkeys(key);
return client.getStatusCodeReply();
}
public String hvals(String key) throws JedisException {
public String hvals(String key) {
client.hvals(key);
return client.getStatusCodeReply();
}
public String hgetAll(String key) throws JedisException {
public String hgetAll(String key) {
client.hgetAll(key);
return client.getStatusCodeReply();
}
public String rpush(String key, String string) throws JedisException {
public String rpush(String key, String string) {
client.rpush(key, string);
return client.getStatusCodeReply();
}
public String lpush(String key, String string) throws JedisException {
public String lpush(String key, String string) {
client.lpush(key, string);
return client.getStatusCodeReply();
}
public String llen(String key) throws JedisException {
public String llen(String key) {
client.llen(key);
return client.getStatusCodeReply();
}
public String lrange(String key, int start, int end) throws JedisException {
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) throws JedisException {
public String ltrim(String key, int start, int end) {
client.ltrim(key, start, end);
return client.getStatusCodeReply();
}
public String lindex(String key, int index) throws JedisException {
public String lindex(String key, int index) {
client.lindex(key, index);
return client.getStatusCodeReply();
}
public String lset(String key, int index, String value)
throws JedisException {
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)
throws JedisException {
public String lrem(String key, int count, String value) {
client.lrem(key, count, value);
return client.getStatusCodeReply();
}
public String lpop(String key) throws JedisException {
public String lpop(String key) {
client.lpop(key);
return client.getStatusCodeReply();
}
public String rpop(String key) throws JedisException {
public String rpop(String key) {
client.rpop(key);
return client.getStatusCodeReply();
}
public String rpoplpush(String srckey, String dstkey) throws JedisException {
public String rpoplpush(String srckey, String dstkey) {
client.rpoplpush(srckey, dstkey);
return client.getStatusCodeReply();
}
public String sadd(String key, String member) throws JedisException {
public String sadd(String key, String member) {
client.sadd(key, member);
return client.getStatusCodeReply();
}
public String smembers(String key) throws JedisException {
public String smembers(String key) {
client.smembers(key);
return client.getStatusCodeReply();
}
public String srem(String key, String member) throws JedisException {
public String srem(String key, String member) {
client.srem(key, member);
return client.getStatusCodeReply();
}
public String spop(String key) throws JedisException {
public String spop(String key) {
client.spop(key);
return client.getStatusCodeReply();
}
public String smove(String srckey, String dstkey, String member)
throws JedisException {
public String smove(String srckey, String dstkey, String member) {
client.smove(srckey, dstkey, member);
return client.getStatusCodeReply();
}
public String scard(String key) throws JedisException {
public String scard(String key) {
client.scard(key);
return client.getStatusCodeReply();
}
public String sismember(String key, String member) throws JedisException {
public String sismember(String key, String member) {
client.sismember(key, member);
return client.getStatusCodeReply();
}
public String sinter(String... keys) throws JedisException {
public String sinter(String... keys) {
client.sinter(keys);
return client.getStatusCodeReply();
}
public String sinterstore(String dstkey, String... keys)
throws JedisException {
public String sinterstore(String dstkey, String... keys) {
client.sinterstore(dstkey, keys);
return client.getStatusCodeReply();
}
public String sunion(String... keys) throws JedisException {
public String sunion(String... keys) {
client.sunion(keys);
return client.getStatusCodeReply();
}
public String sunionstore(String dstkey, String... keys)
throws JedisException {
public String sunionstore(String dstkey, String... keys) {
client.sunionstore(dstkey, keys);
return client.getStatusCodeReply();
}
public String sdiff(String... keys) throws JedisException {
public String sdiff(String... keys) {
client.sdiff(keys);
return client.getStatusCodeReply();
}
public String sdiffstore(String dstkey, String... keys)
throws JedisException {
public String sdiffstore(String dstkey, String... keys) {
client.sdiffstore(dstkey, keys);
return client.getStatusCodeReply();
}
public String srandmember(String key) throws JedisException {
public String srandmember(String key) {
client.srandmember(key);
return client.getStatusCodeReply();
}
public String zadd(String key, double score, String member)
throws JedisException {
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) throws JedisException {
public String zrange(String key, int start, int end) {
client.zrange(key, start, end);
return client.getStatusCodeReply();
}
public String zrem(String key, String member) throws JedisException {
public String zrem(String key, String member) {
client.zrem(key, member);
return client.getStatusCodeReply();
}
public String zincrby(String key, double score, String member)
throws JedisException {
public String zincrby(String key, double score, String member) {
client.zincrby(key, score, member);
return client.getStatusCodeReply();
}
public String zrank(String key, String member) throws JedisException {
public String zrank(String key, String member) {
client.zrank(key, member);
return client.getStatusCodeReply();
}
public String zrevrank(String key, String member) throws JedisException {
public String zrevrank(String key, String member) {
client.zrevrank(key, member);
return client.getStatusCodeReply();
}
public String zrevrange(String key, int start, int end)
throws JedisException {
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)
throws JedisException {
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)
throws JedisException {
public String zrevrangeWithScores(String key, int start, int end) {
client.zrevrangeWithScores(key, start, end);
return client.getStatusCodeReply();
}
public String zcard(String key) throws JedisException {
public String zcard(String key) {
client.zcard(key);
return client.getStatusCodeReply();
}
public String zscore(String key, String member) throws JedisException {
public String zscore(String key, String member) {
client.zscore(key, member);
return client.getStatusCodeReply();
}
public List<Object> exec() throws JedisException {
public List<Object> exec() {
client.exec();
return client.getObjectMultiBulkReply();
}