Introducing IJedis common interface for sharded and non-sharded Jedis
This commit is contained in:
145
src/main/java/redis/clients/jedis/IJedis.java
Normal file
145
src/main/java/redis/clients/jedis/IJedis.java
Normal file
@@ -0,0 +1,145 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Common interface for sharded and non-sharded Jedis
|
||||
*/
|
||||
public interface IJedis {
|
||||
String set(String key, String value);
|
||||
|
||||
String get(String key);
|
||||
|
||||
Integer exists(String key);
|
||||
|
||||
String type(String key);
|
||||
|
||||
Integer expire(String key, int seconds);
|
||||
|
||||
Integer expireAt(String key, long unixTime);
|
||||
|
||||
Integer ttl(String key);
|
||||
|
||||
String getSet(String key, String value);
|
||||
|
||||
Integer setnx(String key, String value);
|
||||
|
||||
String setex(String key, int seconds, String value);
|
||||
|
||||
Integer decrBy(String key, int integer);
|
||||
|
||||
Integer decr(String key);
|
||||
|
||||
Integer incrBy(String key, int integer);
|
||||
|
||||
Integer incr(String key);
|
||||
|
||||
Integer append(String key, String value);
|
||||
|
||||
String substr(String key, int start, int end);
|
||||
|
||||
Integer hset(String key, String field, String value);
|
||||
|
||||
String hget(String key, String field);
|
||||
|
||||
Integer hsetnx(String key, String field, String value);
|
||||
|
||||
String hmset(String key, Map<String, String> hash);
|
||||
|
||||
List<String> hmget(String key, String... fields);
|
||||
|
||||
Integer hincrBy(String key, String field, int value);
|
||||
|
||||
Integer hexists(String key, String field);
|
||||
|
||||
Integer hdel(String key, String field);
|
||||
|
||||
Integer hlen(String key);
|
||||
|
||||
List<String> hkeys(String key);
|
||||
|
||||
List<String> hvals(String key);
|
||||
|
||||
Map<String, String> hgetAll(String key);
|
||||
|
||||
Integer rpush(String key, String string);
|
||||
|
||||
Integer lpush(String key, String string);
|
||||
|
||||
Integer llen(String key);
|
||||
|
||||
List<String> lrange(String key, int start, int end);
|
||||
|
||||
String ltrim(String key, int start, int end);
|
||||
|
||||
String lindex(String key, int index);
|
||||
|
||||
String lset(String key, int index, String value);
|
||||
|
||||
Integer lrem(String key, int count, String value);
|
||||
|
||||
String lpop(String key);
|
||||
|
||||
String rpop(String key);
|
||||
|
||||
Integer sadd(String key, String member);
|
||||
|
||||
Set<String> smembers(String key);
|
||||
|
||||
Integer srem(String key, String member);
|
||||
|
||||
String spop(String key);
|
||||
|
||||
Integer scard(String key);
|
||||
|
||||
Integer sismember(String key, String member);
|
||||
|
||||
String srandmember(String key);
|
||||
|
||||
Integer zadd(String key, double score, String member);
|
||||
|
||||
Set<String> zrange(String key, int start, int end);
|
||||
|
||||
Integer zrem(String key, String member);
|
||||
|
||||
Double zincrby(String key, double score, String member);
|
||||
|
||||
Integer zrank(String key, String member);
|
||||
|
||||
Integer zrevrank(String key, String member);
|
||||
|
||||
Set<String> zrevrange(String key, int start, int end);
|
||||
|
||||
Set<Tuple> zrangeWithScores(String key, int start, int end);
|
||||
|
||||
Set<Tuple> zrevrangeWithScores(String key, int start, int end);
|
||||
|
||||
Integer zcard(String key);
|
||||
|
||||
Double zscore(String key, String member);
|
||||
|
||||
List<String> sort(String key);
|
||||
|
||||
List<String> sort(String key, SortingParams sortingParameters);
|
||||
|
||||
Integer zcount(String key, double min, double max);
|
||||
|
||||
Set<String> zrangeByScore(String key, double min, double max);
|
||||
|
||||
Set<String> zrangeByScore(String key, double min, double max,
|
||||
int offset, int count);
|
||||
|
||||
Set<Tuple> zrangeByScoreWithScores(String key, double min, double max);
|
||||
|
||||
Set<Tuple> zrangeByScoreWithScores(String key, double min,
|
||||
double max, int offset, int count);
|
||||
|
||||
Integer zremrangeByRank(String key, int start, int end);
|
||||
|
||||
Integer zremrangeByScore(String key, double start, double end);
|
||||
|
||||
Integer linsert(String key, Client.LIST_POSITION where, String pivot,
|
||||
String value);
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import java.util.Set;
|
||||
|
||||
import redis.clients.jedis.Client.LIST_POSITION;
|
||||
|
||||
public class Jedis {
|
||||
public class Jedis implements IJedis {
|
||||
private Client client = null;
|
||||
|
||||
public Jedis(String host) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import redis.clients.jedis.Client.LIST_POSITION;
|
||||
import redis.clients.util.Hashing;
|
||||
import redis.clients.util.Sharded;
|
||||
|
||||
public class ShardedJedis extends Sharded<Jedis, JedisShardInfo> {
|
||||
public class ShardedJedis extends Sharded<Jedis, JedisShardInfo> implements IJedis {
|
||||
public ShardedJedis(List<JedisShardInfo> shards) {
|
||||
super(shards);
|
||||
}
|
||||
@@ -28,6 +28,16 @@ public class ShardedJedis extends Sharded<Jedis, JedisShardInfo> {
|
||||
super(shards, algo, keyTagPattern);
|
||||
}
|
||||
|
||||
public void disconnect() throws IOException {
|
||||
for (JedisShardInfo jedis : getAllShards()) {
|
||||
jedis.getResource().disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
protected Jedis create(JedisShardInfo shard) {
|
||||
return new Jedis(shard);
|
||||
}
|
||||
|
||||
public String set(String key, String value) {
|
||||
Jedis j = getShard(key);
|
||||
return j.set(key, value);
|
||||
@@ -355,16 +365,6 @@ public class ShardedJedis extends Sharded<Jedis, JedisShardInfo> {
|
||||
return j.zremrangeByScore(key, start, end);
|
||||
}
|
||||
|
||||
public void disconnect() throws IOException {
|
||||
for (JedisShardInfo jedis : getAllShards()) {
|
||||
jedis.getResource().disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
protected Jedis create(JedisShardInfo shard) {
|
||||
return new Jedis(shard);
|
||||
}
|
||||
|
||||
public Integer linsert(String key, LIST_POSITION where, String pivot,
|
||||
String value) {
|
||||
Jedis j = getShard(key);
|
||||
|
||||
Reference in New Issue
Block a user