Skip to content

Instantly share code, notes, and snippets.

@enryold
Last active July 5, 2018 17:45
Show Gist options
  • Save enryold/76d5cc9f909a6ed96fffe13c6842785c to your computer and use it in GitHub Desktop.
Save enryold/76d5cc9f909a6ed96fffe13c6842785c to your computer and use it in GitHub Desktop.
Wrapper class for Jedis/JedisCluster as common class to use same interface methods.
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import java.util.Optional;
import java.util.function.Function;
@FunctionalInterface
public interface IJedisCommand<T> {
Optional<T> execute(JedisPool pool, Function<Jedis, T> function);
}
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import java.util.Optional;
import java.util.function.Function;
public class JedisCommand<T> implements IJedisCommand<T> {
@Override
public Optional<T> execute(JedisPool pool, Function<Jedis, T> function) {
try(Jedis jedis = pool.getResource())
{
return Optional.ofNullable(function.apply(jedis));
}
catch(Exception e)
{
e.printStackTrace();
return Optional.empty();
}
}
}
import redis.clients.jedis.*;
import redis.clients.jedis.params.geo.GeoRadiusParam;
import redis.clients.jedis.params.sortedset.ZAddParams;
import redis.clients.jedis.params.sortedset.ZIncrByParams;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
public class JedisWrapper implements JedisCommands, MultiKeyCommands, MultiKeyJedisClusterCommands {
JedisPool jedisPool;
JedisCluster jedisCluster;
public JedisWrapper(JedisPool jedisPool)
{
this.jedisPool = jedisPool;
}
public JedisWrapper(JedisCluster jedisCluster)
{
this.jedisCluster = jedisCluster;
}
private Optional<Jedis> getJedis()
{
if(this.jedisPool == null)
return Optional.empty();
try(Jedis jedis = jedisPool.getResource())
{
return Optional.of(jedis);
}
catch (Exception e)
{
e.printStackTrace();
return Optional.empty();
}
}
private Optional<JedisCluster> getJedisCuster()
{
return Optional.ofNullable(jedisCluster);
}
public void flushAll()
{
if((jedisCluster == null))
getJedis().ifPresent(BinaryJedis::flushAll);
else
getJedisCuster().ifPresent(BinaryJedisCluster::flushAll);
}
@Override
public String set(String key, String value) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.set(key, value)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.set(key, value)).orElse(null);
}
@Override
public String set(String key, String value, String nxxx, String expx, long time) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.set(key, value, nxxx, expx, time)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.set(key, value, nxxx, expx, time)).orElse(null);
}
@Override
public String set(String key, String value, String nxxx) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.set(key, value, nxxx)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.set(key, value, nxxx)).orElse(null);
}
@Override
public String get(String key) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.get(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.get(key)).orElse(null);
}
@Override
public Boolean exists(String key) {
if((jedisCluster == null))
return new JedisCommand<Boolean>().execute(jedisPool, jedis -> jedis.exists(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.exists(key)).orElse(null);
}
@Override
public Long persist(String key) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.persist(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.persist(key)).orElse(null);
}
@Override
public String type(String key) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.type(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.type(key)).orElse(null);
}
@Override
public Long expire(String key, int seconds) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.expire(key, seconds)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.expire(key, seconds)).orElse(null);
}
@Override
public Long pexpire(String key, long milliseconds) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.pexpire(key, milliseconds)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.pexpire(key, milliseconds)).orElse(null);
}
@Override
public Long expireAt(String key, long unixTime) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.expireAt(key, unixTime)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.expireAt(key, unixTime)).orElse(null);
}
@Override
public Long pexpireAt(String key, long millisecondsTimestamp) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.pexpireAt(key, millisecondsTimestamp)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.pexpireAt(key, millisecondsTimestamp)).orElse(null);
}
@Override
public Long ttl(String key) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.ttl(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.ttl(key)).orElse(null);
}
@Override
public Long pttl(String key) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.pttl(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.pttl(key)).orElse(null);
}
@Override
public Boolean setbit(String key, long offset, boolean value) {
if((jedisCluster == null))
return new JedisCommand<Boolean>().execute(jedisPool, jedis -> jedis.setbit(key, offset, value)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.setbit(key, offset, value)).orElse(null);
}
@Override
public Boolean setbit(String key, long offset, String value) {
if((jedisCluster == null))
return new JedisCommand<Boolean>().execute(jedisPool, jedis -> jedis.setbit(key, offset, value)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.setbit(key, offset, value)).orElse(null);
}
@Override
public Boolean getbit(String key, long offset) {
if((jedisCluster == null))
return new JedisCommand<Boolean>().execute(jedisPool, jedis -> jedis.getbit(key, offset)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.getbit(key, offset)).orElse(null);
}
@Override
public Long setrange(String key, long offset, String value) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.setrange(key, offset, value)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.setrange(key, offset, value)).orElse(null);
}
@Override
public String getrange(String key, long startOffset, long endOffset) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.getrange(key, startOffset, endOffset)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.getrange(key, startOffset, endOffset)).orElse(null);
}
@Override
public String getSet(String key, String value) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.getSet(key, value)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.getSet(key, value)).orElse(null);
}
@Override
public Long setnx(String key, String value) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.setnx(key, value)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.setnx(key, value)).orElse(null);
}
@Override
public String setex(String key, int seconds, String value) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.setex(key, seconds, value)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.setex(key, seconds, value)).orElse(null);
}
@Override
public String psetex(String key, long milliseconds, String value) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.psetex(key, milliseconds, value)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.psetex(key, milliseconds, value)).orElse(null);
}
@Override
public Long decrBy(String key, long integer) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.decrBy(key, integer)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.decrBy(key, integer)).orElse(null);
}
@Override
public Long decr(String key) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.decr(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.decr(key)).orElse(null);
}
@Override
public Long incrBy(String key, long integer) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.incrBy(key, integer)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.incrBy(key, integer)).orElse(null);
}
@Override
public Double incrByFloat(String key, double value) {
if((jedisCluster == null))
return new JedisCommand<Double>().execute(jedisPool, jedis -> jedis.incrByFloat(key, value)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.incrByFloat(key, value)).orElse(null);
}
@Override
public Long incr(String key) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.incr(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.incr(key)).orElse(null);
}
@Override
public Long append(String key, String value) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.append(key, value)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.append(key, value)).orElse(null);
}
@Override
public String substr(String key, int start, int end) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.substr(key, start, end)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.substr(key, start, end)).orElse(null);
}
@Override
public Long hset(String key, String field, String value) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.hset(key, field, value)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.hset(key, field, value)).orElse(null);
}
@Override
public String hget(String key, String field) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.hget(key, field)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.hget(key, field)).orElse(null);
}
@Override
public Long hsetnx(String key, String field, String value) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.hsetnx(key, field, value)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.hsetnx(key, field, value)).orElse(null);
}
@Override
public String hmset(String key, Map<String, String> hash) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.hmset(key, hash)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.hmset(key, hash)).orElse(null);
}
@Override
public List<String> hmget(String key, String... fields) {
if((jedisCluster == null))
return new JedisCommand<List<String>>().execute(jedisPool, jedis -> jedis.hmget(key, fields)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.hmget(key, fields)).orElse(null);
}
@Override
public Long hincrBy(String key, String field, long value) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.hincrBy(key, field, value)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.hincrBy(key, field, value)).orElse(null);
}
@Override
public Double hincrByFloat(String key, String field, double value) {
if((jedisCluster == null))
return new JedisCommand<Double>().execute(jedisPool, jedis -> jedis.hincrByFloat(key, field, value)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.hincrByFloat(key, field, value)).orElse(null);
}
@Override
public Boolean hexists(String key, String field) {
if((jedisCluster == null))
return new JedisCommand<Boolean>().execute(jedisPool, jedis -> jedis.hexists(key, field)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.hexists(key, field)).orElse(null);
}
@Override
public Long hdel(String key, String... field) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.hdel(key, field)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.hdel(key, field)).orElse(null);
}
@Override
public Long hlen(String key) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.hlen(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.hlen(key)).orElse(null);
}
@Override
public Set<String> hkeys(String key) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.hkeys(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.hkeys(key)).orElse(null);
}
@Override
public List<String> hvals(String key) {
if((jedisCluster == null))
return new JedisCommand<List<String>>().execute(jedisPool, jedis -> jedis.hvals(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.hvals(key)).orElse(null);
}
@Override
public Map<String, String> hgetAll(String key) {
if((jedisCluster == null))
return new JedisCommand<Map<String, String>>().execute(jedisPool, jedis -> jedis.hgetAll(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.hgetAll(key)).orElse(null);
}
@Override
public Long rpush(String key, String... string) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.rpush(key, string)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.rpush(key)).orElse(null);
}
@Override
public Long lpush(String key, String... string) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.lpush(key, string)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.lpush(key)).orElse(null);
}
@Override
public Long llen(String key) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.llen(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.llen(key)).orElse(null);
}
@Override
public List<String> lrange(String key, long start, long end) {
if((jedisCluster == null))
return new JedisCommand<List<String>>().execute(jedisPool, jedis -> jedis.lrange(key, start, end)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.lrange(key, start, end)).orElse(null);
}
@Override
public String ltrim(String key, long start, long end) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.ltrim(key, start, end)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.ltrim(key, start, end)).orElse(null);
}
@Override
public String lindex(String key, long index) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.lindex(key, index)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.lindex(key, index)).orElse(null);
}
@Override
public String lset(String key, long index, String value) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.lset(key, index, value)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.lset(key, index, value)).orElse(null);
}
@Override
public Long lrem(String key, long count, String value) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.lrem(key, count, value)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.lrem(key, count, value)).orElse(null);
}
@Override
public String lpop(String key) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.lpop(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.lpop(key)).orElse(null);
}
@Override
public String rpop(String key) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.rpop(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.rpop(key)).orElse(null);
}
@Override
public Long sadd(String key, String... member) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.sadd(key, member)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.sadd(key, member)).orElse(null);
}
@Override
public Set<String> smembers(String key) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.smembers(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.smembers(key)).orElse(null);
}
@Override
public Long srem(String key, String... member) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.srem(key, member)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.srem(key, member)).orElse(null);
}
@Override
public String spop(String key) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.spop(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.spop(key)).orElse(null);
}
@Override
public Set<String> spop(String key, long count) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.spop(key, count)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.spop(key, count)).orElse(null);
}
@Override
public Long scard(String key) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.scard(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.scard(key)).orElse(null);
}
@Override
public Boolean sismember(String key, String member) {
if((jedisCluster == null))
return new JedisCommand<Boolean>().execute(jedisPool, jedis -> jedis.sismember(key, member)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.sismember(key, member)).orElse(null);
}
@Override
public String srandmember(String key) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.srandmember(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.srandmember(key)).orElse(null);
}
@Override
public List<String> srandmember(String key, int count) {
if((jedisCluster == null))
return new JedisCommand<List<String>>().execute(jedisPool, jedis -> jedis.srandmember(key, count)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.srandmember(key, count)).orElse(null);
}
@Override
public Long strlen(String key) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.strlen(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.strlen(key)).orElse(null);
}
@Override
public Long zadd(String key, double score, String member) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zadd(key, score, member)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zadd(key, score, member)).orElse(null);
}
@Override
public Long zadd(String key, double score, String member, ZAddParams params) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zadd(key, score, member, params)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zadd(key, score, member, params)).orElse(null);
}
@Override
public Long zadd(String key, Map<String, Double> scoreMembers) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zadd(key, scoreMembers)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zadd(key, scoreMembers)).orElse(null);
}
@Override
public Long zadd(String key, Map<String, Double> scoreMembers, ZAddParams params) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zadd(key, scoreMembers, params)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zadd(key, scoreMembers, params)).orElse(null);
}
@Override
public Set<String> zrange(String key, long start, long end) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.zrange(key, start, end)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrange(key, start, end)).orElse(null);
}
@Override
public Long zrem(String key, String... member) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zrem(key, member)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrem(key, member)).orElse(null);
}
@Override
public Double zincrby(String key, double score, String member) {
if((jedisCluster == null))
return new JedisCommand<Double>().execute(jedisPool, jedis -> jedis.zincrby(key, score, member)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zincrby(key, score, member)).orElse(null);
}
@Override
public Double zincrby(String key, double score, String member, ZIncrByParams params) {
if((jedisCluster == null))
return new JedisCommand<Double>().execute(jedisPool, jedis -> jedis.zincrby(key, score, member, params)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zincrby(key, score, member, params)).orElse(null);
}
@Override
public Long zrank(String key, String member) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zrank(key, member)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrank(key, member)).orElse(null);
}
@Override
public Long zrevrank(String key, String member) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zrevrank(key, member)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrevrank(key, member)).orElse(null);
}
@Override
public Set<String> zrevrange(String key, long start, long end) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.zrevrange(key, start, end)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrevrange(key, start, end)).orElse(null);
}
@Override
public Set<Tuple> zrangeWithScores(String key, long start, long end) {
if((jedisCluster == null))
return new JedisCommand<Set<Tuple>>().execute(jedisPool, jedis -> jedis.zrangeWithScores(key, start, end)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrangeWithScores(key, start, end)).orElse(null);
}
@Override
public Set<Tuple> zrevrangeWithScores(String key, long start, long end) {
if((jedisCluster == null))
return new JedisCommand<Set<Tuple>>().execute(jedisPool, jedis -> jedis.zrevrangeWithScores(key, start, end)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrevrangeWithScores(key, start, end)).orElse(null);
}
@Override
public Long zcard(String key) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zcard(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zcard(key)).orElse(null);
}
@Override
public Double zscore(String key, String member) {
if((jedisCluster == null))
return new JedisCommand<Double>().execute(jedisPool, jedis -> jedis.zscore(key, member)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zscore(key, member)).orElse(null);
}
@Override
public List<String> sort(String key) {
if((jedisCluster == null))
return new JedisCommand<List<String>>().execute(jedisPool, jedis -> jedis.sort(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.sort(key)).orElse(null);
}
@Override
public List<String> sort(String key, SortingParams sortingParameters) {
if((jedisCluster == null))
return new JedisCommand<List<String>>().execute(jedisPool, jedis -> jedis.sort(key, sortingParameters)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.sort(key, sortingParameters)).orElse(null);
}
@Override
public Long zcount(String key, double min, double max) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zcount(key, min, max)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zcount(key, min, max)).orElse(null);
}
@Override
public Long zcount(String key, String min, String max) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zcount(key, min, max)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zcount(key, min, max)).orElse(null);
}
@Override
public Set<String> zrangeByScore(String key, double min, double max) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.zrangeByScore(key, min, max)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrangeByScore(key, min, max)).orElse(null);
}
@Override
public Set<String> zrangeByScore(String key, String min, String max) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.zrangeByScore(key, min, max)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrangeByScore(key, min, max)).orElse(null);
}
@Override
public Set<String> zrevrangeByScore(String key, double max, double min) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.zrangeByScore(key, min, max)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrangeByScore(key, min, max)).orElse(null);
}
@Override
public Set<String> zrangeByScore(String key, double min, double max, int offset, int count) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.zrangeByScore(key, min, max, offset, count)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrangeByScore(key, min, max, offset, count)).orElse(null);
}
@Override
public Set<String> zrevrangeByScore(String key, String max, String min) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.zrevrangeByScore(key, min, max)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrevrangeByScore(key, min, max)).orElse(null);
}
@Override
public Set<String> zrangeByScore(String key, String min, String max, int offset, int count) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.zrangeByScore(key, min, max, offset, count)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrangeByScore(key, min, max, offset, count)).orElse(null);
}
@Override
public Set<String> zrevrangeByScore(String key, double max, double min, int offset, int count) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.zrevrangeByScore(key, min, max, offset, count)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrevrangeByScore(key, min, max, offset, count)).orElse(null);
}
@Override
public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max) {
if((jedisCluster == null))
return new JedisCommand<Set<Tuple>>().execute(jedisPool, jedis -> jedis.zrangeByScoreWithScores(key, min, max)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrangeByScoreWithScores(key, min, max)).orElse(null);
}
@Override
public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min) {
if((jedisCluster == null))
return new JedisCommand<Set<Tuple>>().execute(jedisPool, jedis -> jedis.zrevrangeByScoreWithScores(key, min, max)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrevrangeByScoreWithScores(key, min, max)).orElse(null);
}
@Override
public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max, int offset, int count) {
if((jedisCluster == null))
return new JedisCommand<Set<Tuple>>().execute(jedisPool, jedis -> jedis.zrangeByScoreWithScores(key, min, max, offset, count)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrangeByScoreWithScores(key, min, max, offset, count)).orElse(null);
}
@Override
public Set<String> zrevrangeByScore(String key, String max, String min, int offset, int count) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.zrevrangeByScore(key, min, max, offset, count)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrevrangeByScore(key, min, max, offset, count)).orElse(null);
}
@Override
public Set<Tuple> zrangeByScoreWithScores(String key, String min, String max) {
if((jedisCluster == null))
return new JedisCommand<Set<Tuple>>().execute(jedisPool, jedis -> jedis.zrangeByScoreWithScores(key, min, max)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrangeByScoreWithScores(key, min, max)).orElse(null);
}
@Override
public Set<Tuple> zrevrangeByScoreWithScores(String key, String max, String min) {
if((jedisCluster == null))
return new JedisCommand<Set<Tuple>>().execute(jedisPool, jedis -> jedis.zrevrangeByScoreWithScores(key, min, max)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrevrangeByScoreWithScores(key, min, max)).orElse(null);
}
@Override
public Set<Tuple> zrangeByScoreWithScores(String key, String min, String max, int offset, int count) {
if((jedisCluster == null))
return new JedisCommand<Set<Tuple>>().execute(jedisPool, jedis -> jedis.zrangeByScoreWithScores(key, min, max, offset, count)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrangeByScoreWithScores(key, min, max, offset, count)).orElse(null);
}
@Override
public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count) {
if((jedisCluster == null))
return new JedisCommand<Set<Tuple>>().execute(jedisPool, jedis -> jedis.zrevrangeByScoreWithScores(key, min, max, offset, count)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrevrangeByScoreWithScores(key, min, max, offset, count)).orElse(null);
}
@Override
public Set<Tuple> zrevrangeByScoreWithScores(String key, String max, String min, int offset, int count) {
if((jedisCluster == null))
return new JedisCommand<Set<Tuple>>().execute(jedisPool, jedis -> jedis.zrevrangeByScoreWithScores(key, min, max, offset, count)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrevrangeByScoreWithScores(key, min, max, offset, count)).orElse(null);
}
@Override
public Long zremrangeByRank(String key, long start, long end) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zremrangeByRank(key, start, end)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zremrangeByRank(key, start, end)).orElse(null);
}
@Override
public Long zremrangeByScore(String key, double start, double end) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zremrangeByScore(key, start, end)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zremrangeByScore(key, start, end)).orElse(null);
}
@Override
public Long zremrangeByScore(String key, String start, String end) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zremrangeByScore(key, start, end)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zremrangeByScore(key, start, end)).orElse(null);
}
@Override
public Long zlexcount(String key, String min, String max) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zlexcount(key, min, max)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zlexcount(key, min, max)).orElse(null);
}
@Override
public Set<String> zrangeByLex(String key, String min, String max) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.zrangeByLex(key, min, max)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrangeByLex(key, min, max)).orElse(null);
}
@Override
public Set<String> zrangeByLex(String key, String min, String max, int offset, int count) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.zrangeByLex(key, min, max, offset, count)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrangeByLex(key, min, max, offset, count)).orElse(null);
}
@Override
public Set<String> zrevrangeByLex(String key, String max, String min) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.zrevrangeByLex(key, min, max)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrevrangeByLex(key, min, max)).orElse(null);
}
@Override
public Set<String> zrevrangeByLex(String key, String max, String min, int offset, int count) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.zrevrangeByLex(key, min, max, offset, count)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zrevrangeByLex(key, min, max, offset, count)).orElse(null);
}
@Override
public Long zremrangeByLex(String key, String min, String max) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zremrangeByLex(key, min, max)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zremrangeByLex(key, min, max)).orElse(null);
}
@Override
public Long linsert(String key, BinaryClient.LIST_POSITION where, String pivot, String value) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.linsert(key, where, pivot, value)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.linsert(key, where, pivot, value)).orElse(null);
}
@Override
public Long lpushx(String key, String... string) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.lpushx(key, string)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.lpushx(key, string)).orElse(null);
}
@Override
public Long rpushx(String key, String... string) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.rpushx(key, string)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.rpushx(key, string)).orElse(null);
}
@Override
public List<String> blpop(String arg) {
if((jedisCluster == null))
return new JedisCommand<List<String>>().execute(jedisPool, jedis -> jedis.blpop(arg)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.blpop(arg)).orElse(null);
}
@Override
public List<String> blpop(int timeout, String key) {
if((jedisCluster == null))
return new JedisCommand<List<String>>().execute(jedisPool, jedis -> jedis.blpop(timeout, key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.blpop(timeout, key)).orElse(null);
}
@Override
public List<String> brpop(String arg) {
if((jedisCluster == null))
return new JedisCommand<List<String>>().execute(jedisPool, jedis -> jedis.brpop(arg)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.brpop(arg)).orElse(null);
}
@Override
public List<String> brpop(int timeout, String key) {
if((jedisCluster == null))
return new JedisCommand<List<String>>().execute(jedisPool, jedis -> jedis.brpop(timeout, key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.brpop(timeout, key)).orElse(null);
}
@Override
public Long del(String key) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.del(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.del(key)).orElse(null);
}
@Override
public String echo(String string) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.echo(string)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.echo(string)).orElse(null);
}
@Override
public Long move(String key, int dbIndex) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.move(key, dbIndex)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.move(key, dbIndex)).orElse(null);
}
@Override
public Long bitcount(String key) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.bitcount(key)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.bitcount(key)).orElse(null);
}
@Override
public Long bitcount(String key, long start, long end) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.bitcount(key, start, end)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.bitcount(key, start, end)).orElse(null);
}
@Override
public Long bitpos(String key, boolean value) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.bitpos(key, value)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.bitpos(key, value)).orElse(null);
}
@Override
public Long bitpos(String key, boolean value, BitPosParams params) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.bitpos(key, value, params)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.bitpos(key, value, params)).orElse(null);
}
@Override
public ScanResult<Map.Entry<String, String>> hscan(String key, int cursor) {
if((jedisCluster == null))
return new JedisCommand<ScanResult<Map.Entry<String, String>>>().execute(jedisPool, jedis -> jedis.hscan(key, cursor)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.hscan(key, cursor)).orElse(null);
}
@Override
public ScanResult<String> sscan(String key, int cursor) {
if((jedisCluster == null))
return new JedisCommand<ScanResult<String>>().execute(jedisPool, jedis -> jedis.sscan(key, cursor)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.sscan(key, cursor)).orElse(null);
}
@Override
public ScanResult<Tuple> zscan(String key, int cursor) {
if((jedisCluster == null))
return new JedisCommand<ScanResult<Tuple>>().execute(jedisPool, jedis -> jedis.zscan(key, cursor)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zscan(key, cursor)).orElse(null);
}
@Override
public ScanResult<Map.Entry<String, String>> hscan(String key, String cursor) {
if((jedisCluster == null))
return new JedisCommand<ScanResult<Map.Entry<String, String>>>().execute(jedisPool, jedis -> jedis.hscan(key, cursor)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.hscan(key, cursor)).orElse(null);
}
@Override
public ScanResult<Map.Entry<String, String>> hscan(String key, String cursor, ScanParams params) {
if((jedisCluster == null))
return new JedisCommand<ScanResult<Map.Entry<String, String>>>().execute(jedisPool, jedis -> jedis.hscan(key, cursor, params)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.hscan(key, cursor,params)).orElse(null);
}
@Override
public ScanResult<String> sscan(String key, String cursor) {
if((jedisCluster == null))
return new JedisCommand<ScanResult<String>>().execute(jedisPool, jedis -> jedis.sscan(key, cursor)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.sscan(key, cursor)).orElse(null);
}
@Override
public ScanResult<String> sscan(String key, String cursor, ScanParams params) {
if((jedisCluster == null))
return new JedisCommand<ScanResult<String>>().execute(jedisPool, jedis -> jedis.sscan(key, cursor, params)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.sscan(key, cursor, params)).orElse(null);
}
@Override
public ScanResult<Tuple> zscan(String key, String cursor) {
if((jedisCluster == null))
return new JedisCommand<ScanResult<Tuple>>().execute(jedisPool, jedis -> jedis.zscan(key, cursor)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zscan(key, cursor)).orElse(null);
}
@Override
public ScanResult<Tuple> zscan(String key, String cursor, ScanParams params) {
if((jedisCluster == null))
return new JedisCommand<ScanResult<Tuple>>().execute(jedisPool, jedis -> jedis.zscan(key, cursor, params)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zscan(key, cursor, params)).orElse(null);
}
@Override
public Long pfadd(String key, String... elements) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.pfadd(key, elements)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.pfadd(key, elements)).orElse(null);
}
@Override
public long pfcount(String key) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.pfcount(key)).orElse(0L);
else
return getJedisCuster().map(jedis -> jedis.pfcount(key)).orElse(0L);
}
@Override
public Long geoadd(String key, double longitude, double latitude, String member) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.geoadd(key, longitude, latitude, member)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.geoadd(key, longitude, latitude, member)).orElse(null);
}
@Override
public Long geoadd(String key, Map<String, GeoCoordinate> memberCoordinateMap) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.geoadd(key, memberCoordinateMap)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.geoadd(key, memberCoordinateMap)).orElse(null);
}
@Override
public Double geodist(String key, String member1, String member2) {
if((jedisCluster == null))
return new JedisCommand<Double>().execute(jedisPool, jedis -> jedis.geodist(key, member1, member2)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.geodist(key, member1, member2)).orElse(null);
}
@Override
public Double geodist(String key, String member1, String member2, GeoUnit unit) {
if((jedisCluster == null))
return new JedisCommand<Double>().execute(jedisPool, jedis -> jedis.geodist(key, member1, member2, unit)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.geodist(key, member1, member2, unit)).orElse(null);
}
@Override
public List<String> geohash(String key, String... members) {
if((jedisCluster == null))
return new JedisCommand<List<String>>().execute(jedisPool, jedis -> jedis.geohash(key, members)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.geohash(key, members)).orElse(null);
}
@Override
public List<GeoCoordinate> geopos(String key, String... members) {
if((jedisCluster == null))
return new JedisCommand<List<GeoCoordinate>>().execute(jedisPool, jedis -> jedis.geopos(key, members)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.geopos(key, members)).orElse(null);
}
@Override
public List<GeoRadiusResponse> georadius(String key, double longitude, double latitude, double radius, GeoUnit unit) {
if((jedisCluster == null))
return new JedisCommand<List<GeoRadiusResponse> >().execute(jedisPool, jedis -> jedis.georadius(key, longitude, latitude, radius, unit)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.georadius(key, longitude, latitude, radius, unit)).orElse(null);
}
@Override
public List<GeoRadiusResponse> georadius(String key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) {
if((jedisCluster == null))
return new JedisCommand<List<GeoRadiusResponse> >().execute(jedisPool, jedis -> jedis.georadius(key, longitude, latitude, radius, unit, param)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.georadius(key, longitude, latitude, radius, unit, param)).orElse(null);
}
@Override
public List<GeoRadiusResponse> georadiusByMember(String key, String member, double radius, GeoUnit unit) {
if((jedisCluster == null))
return new JedisCommand<List<GeoRadiusResponse> >().execute(jedisPool, jedis -> jedis.georadiusByMember(key, member, radius, unit)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.georadiusByMember(key, member, radius, unit)).orElse(null);
}
@Override
public List<GeoRadiusResponse> georadiusByMember(String key, String member, double radius, GeoUnit unit, GeoRadiusParam param) {
if((jedisCluster == null))
return new JedisCommand<List<GeoRadiusResponse> >().execute(jedisPool, jedis -> jedis.georadiusByMember(key, member, radius, unit, param)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.georadiusByMember(key, member, radius, unit, param)).orElse(null);
}
@Override
public Long del(String... keys) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.del(keys)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.del(keys)).orElse(null);
}
@Override
public Long exists(String... keys) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.exists(keys)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.exists(keys)).orElse(null);
}
@Override
public List<String> blpop(int timeout, String... keys) {
if((jedisCluster == null))
return new JedisCommand<List<String>>().execute(jedisPool, jedis -> jedis.blpop(timeout, keys)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.blpop(timeout, keys)).orElse(null);
}
@Override
public List<String> brpop(int timeout, String... keys) {
if((jedisCluster == null))
return new JedisCommand<List<String>>().execute(jedisPool, jedis -> jedis.brpop(timeout, keys)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.brpop(timeout, keys)).orElse(null);
}
@Override
public List<String> blpop(String... args) {
if((jedisCluster == null))
return new JedisCommand<List<String>>().execute(jedisPool, jedis -> jedis.blpop(args)).orElse(null);
else
return null;
}
@Override
public List<String> brpop(String... args) {
if((jedisCluster == null))
return new JedisCommand<List<String>>().execute(jedisPool, jedis -> jedis.brpop(args)).orElse(null);
else
return null;
}
@Override
public Set<String> keys(String pattern) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.keys(pattern)).orElse(null);
else
return null;
}
@Override
public List<String> mget(String... keys) {
if((jedisCluster == null))
return new JedisCommand<List<String>>().execute(jedisPool, jedis -> jedis.mget(keys)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.mget(keys)).orElse(null);
}
@Override
public String mset(String... keysvalues) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.mset(keysvalues)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.mset(keysvalues)).orElse(null);
}
@Override
public Long msetnx(String... keysvalues) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.msetnx(keysvalues)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.msetnx(keysvalues)).orElse(null);
}
@Override
public String rename(String oldkey, String newkey) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.rename(oldkey, newkey)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.rename(oldkey, newkey)).orElse(null);
}
@Override
public Long renamenx(String oldkey, String newkey) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.renamenx(oldkey, newkey)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.renamenx(oldkey, newkey)).orElse(null);
}
@Override
public String rpoplpush(String srckey, String dstkey) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.rpoplpush(srckey, dstkey)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.rpoplpush(srckey, dstkey)).orElse(null);
}
@Override
public Set<String> sdiff(String... keys) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.sdiff(keys)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.sdiff(keys)).orElse(null);
}
@Override
public Long sdiffstore(String dstkey, String... keys) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.sdiffstore(dstkey, keys)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.sdiffstore(dstkey, keys)).orElse(null);
}
@Override
public Set<String> sinter(String... keys) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.sinter(keys)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.sinter(keys)).orElse(null);
}
@Override
public Long sinterstore(String dstkey, String... keys) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.sinterstore(dstkey, keys)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.sinterstore(dstkey, keys)).orElse(null);
}
@Override
public Long smove(String srckey, String dstkey, String member) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.smove(srckey, dstkey, member)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.smove(srckey, dstkey, member)).orElse(null);
}
@Override
public Long sort(String key, SortingParams sortingParameters, String dstkey) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.sort(key, sortingParameters, dstkey)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.sort(key, sortingParameters, dstkey)).orElse(null);
}
@Override
public Long sort(String key, String dstkey) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.sort(key, dstkey)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.sort(key, dstkey)).orElse(null);
}
@Override
public Set<String> sunion(String... keys) {
if((jedisCluster == null))
return new JedisCommand<Set<String>>().execute(jedisPool, jedis -> jedis.sunion(keys)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.sunion(keys)).orElse(null);
}
@Override
public Long sunionstore(String dstkey, String... keys) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.sunionstore(dstkey, keys)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.sunionstore(dstkey, keys)).orElse(null);
}
@Override
public String watch(String... keys) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.watch(keys)).orElse(null);
else
return null;
}
@Override
public String unwatch() {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.unwatch()).orElse(null);
else
return null;
}
@Override
public Long zinterstore(String dstkey, String... sets) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zinterstore(dstkey, sets)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zinterstore(dstkey, sets)).orElse(null);
}
@Override
public Long zinterstore(String dstkey, ZParams params, String... sets) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zinterstore(dstkey, params, sets)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zinterstore(dstkey, params, sets)).orElse(null);
}
@Override
public Long zunionstore(String dstkey, String... sets) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zunionstore(dstkey, sets)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zunionstore(dstkey, sets)).orElse(null);
}
@Override
public Long zunionstore(String dstkey, ZParams params, String... sets) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.zunionstore(dstkey, params, sets)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.zunionstore(dstkey, params, sets)).orElse(null);
}
@Override
public String brpoplpush(String source, String destination, int timeout) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.brpoplpush(source, destination, timeout)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.brpoplpush(source, destination, timeout)).orElse(null);
}
@Override
public Long publish(String channel, String message) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.publish(channel, message)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.publish(channel, message)).orElse(null);
}
@Override
public void subscribe(JedisPubSub jedisPubSub, String... channels) {
if((jedisCluster == null))
getJedis().ifPresent(jedis -> jedis.subscribe(jedisPubSub, channels));
else
getJedisCuster().ifPresent(jedis -> jedis.subscribe(jedisPubSub, channels));
}
@Override
public void psubscribe(JedisPubSub jedisPubSub, String... patterns) {
if((jedisCluster == null))
getJedis().ifPresent(jedis -> jedis.psubscribe(jedisPubSub, patterns));
else
getJedisCuster().ifPresent(jedis -> jedis.psubscribe(jedisPubSub, patterns));
}
@Override
public String randomKey() {
if((jedisCluster == null))
return getJedis().map(Jedis::randomKey).orElse(null);
else
return null;
}
@Override
public Long bitop(BitOP op, String destKey, String... srcKeys) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.bitop(op, destKey, srcKeys)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.bitop(op, destKey, srcKeys)).orElse(null);
}
@Override
public ScanResult<String> scan(int cursor) {
if((jedisCluster == null))
return new JedisCommand<ScanResult<String>>().execute(jedisPool, jedis -> jedis.scan(cursor)).orElse(null);
else
return null;
}
@Override
public ScanResult<String> scan(String cursor) {
if((jedisCluster == null))
return new JedisCommand<ScanResult<String>>().execute(jedisPool, jedis -> jedis.scan(cursor)).orElse(null);
else
return null;
}
@Override
public ScanResult<String> scan(String cursor, ScanParams params) {
if((jedisCluster == null))
return new JedisCommand<ScanResult<String>>().execute(jedisPool, jedis -> jedis.scan(cursor, params)).orElse(null);
else
return null;
}
@Override
public String pfmerge(String destkey, String... sourcekeys) {
if((jedisCluster == null))
return new JedisCommand<String>().execute(jedisPool, jedis -> jedis.pfmerge(destkey, sourcekeys)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.pfmerge(destkey, sourcekeys)).orElse(null);
}
@Override
public long pfcount(String... keys) {
if((jedisCluster == null))
return new JedisCommand<Long>().execute(jedisPool, jedis -> jedis.pfcount(keys)).orElse(null);
else
return getJedisCuster().map(jedis -> jedis.pfcount(keys)).orElse(null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment