博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
redis实现spring-data-redis整合
阅读量:6434 次
发布时间:2019-06-23

本文共 76765 字,大约阅读时间需要 255 分钟。

 博客链接网址:http://www.cnblogs.com/yjmyzz/tag/redis/

redis的知识:

1,利用spring-data-redis整合

项目使用的pom.xml:

按 Ctrl+C 复制代码
按 Ctrl+C 复制代码

除了log部分,只有一个spring core 和 spring-data-redis了

项目文件目录结构:

 

applicationContext.xml:

1,context:property-placeholder 标签用来导入properties文件。从而替换${redis.maxIdle}这样的变量。

2,context:component-scan 是为了在com.x.redis.dao报下的类能够实用spring的注解注入的方式。

3,事实上我们只需要把JedisPoolConfig配数来就好了,接下来就是spring的封装了。所以直接看UserDAOImpl的实现就明白了。

按 Ctrl+C 复制代码
按 Ctrl+C 复制代码

redis.properties:

按 Ctrl+C 复制代码
按 Ctrl+C 复制代码

 

UserDAOImpl:

1,spring对dao层的封装很多用了类似于下面代码的模板方式。

2,RedisTemplate就是spring对redis的一个封装而已。

按 Ctrl+C 复制代码
按 Ctrl+C 复制代码

其他:

User:

按 Ctrl+C 复制代码
按 Ctrl+C 复制代码

测试代码:

public static void main(String[] args) {        ApplicationContext ac =  new ClassPathXmlApplicationContext("classpath:/applicationContext.xml");        UserDAO userDAO = (UserDAO)ac.getBean("userDAO");        User user1 = new User();        user1.setId(1);        user1.setName("obama");        userDAO.saveUser(user1);        User user2 = userDAO.getUser(1);        System.out.println(user2.getName());    }

 

2,不利用spring-data-redis整合

个人觉得这样整合灵活度更大,能够更加明了的完成任务。

pom.xml:

4.0.0
com.d.work
Redis_Templete
1.0-SNAPSHOT
jar
Redis_Templete
http://maven.apache.org
UTF-8
junit
junit
3.8.1
test
redis.clients
jedis
2.1.0
org.springframework
spring-core
3.1.2.RELEASE
org.springframework
spring-beans
3.1.2.RELEASE
org.springframework
spring-context
3.1.2.RELEASE
org.slf4j
slf4j-api
1.6.1
org.slf4j
jcl-over-slf4j
1.6.1
commons-logging
commons-logging
1.1.1
provided
ch.qos.logback
logback-classic
0.9.24
runtime
View Code

目录结构:

data-source.xml

1,context:property-placeholder 和 context:component-scan 前面解释过啦。

2,配置了一个ShardedJedisPool,在jdeis里 还有个JedisPool。这两个的区别:

一个是分片形式,可以连接有主备的redis服务端,一个是单个的。详细后续学习
 
3,因为不使用spring-data-redis的封装,所以自己要自己封装一个

 

RedisDataSource:定义三个方法

public interface RedisDataSource {    public abstract ShardedJedis getRedisClient();    public void returnResource(ShardedJedis shardedJedis);    public void returnResource(ShardedJedis shardedJedis,boolean broken);}

 

实现redisDataSource:

1, 注入配置好的ShardedJedisPool,这三个方法的作用:

 

getRedisClient() : 取得redis的客户端,可以执行命令了。
returnResource(ShardedJedis shardedJedis) : 将资源返还给pool
returnResource(ShardedJedis shardedJedis, boolean broken) : 出现异常后,将资源返还给pool (其实不需要第二个方法)

 

@Repository("redisDataSource")public class RedisDataSourceImpl implements RedisDataSource {    private static final Logger log = LoggerFactory.getLogger(RedisDataSourceImpl.class);    @Autowired    private ShardedJedisPool    shardedJedisPool;    public ShardedJedis getRedisClient() {        try {            ShardedJedis shardJedis = shardedJedisPool.getResource();            return shardJedis;        } catch (Exception e) {            log.error("getRedisClent error", e);        }        return null;    }    public void returnResource(ShardedJedis shardedJedis) {        shardedJedisPool.returnResource(shardedJedis);    }    public void returnResource(ShardedJedis shardedJedis, boolean broken) {        if (broken) {            shardedJedisPool.returnBrokenResource(shardedJedis);        } else {            shardedJedisPool.returnResource(shardedJedis);        }    }}

 

第二层的封装:RedisClientTemplate,例子实现了放值和取值。最后代码提供了全部命令的实现。

代码就是映射性质的又一次调用jedis的方法而已,用了个broken来做标示符,决定返还资源的方式。

这一层的目的主要也是让再上层的调用不需要关心pool中链接的取得和返还问题了。

@Repository("redisClientTemplate")public class RedisClientTemplate {    private static final Logger log = LoggerFactory.getLogger(RedisClientTemplate.class);    @Autowired    private RedisDataSource     redisDataSource;    public void disconnect() {        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        shardedJedis.disconnect();    }    /**     * 设置单个值     *      * @param key     * @param value     * @return     */    public String set(String key, String value) {        String result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.set(key, value);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    /**     * 获取单个值     *      * @param key     * @return     */    public String get(String key) {        String result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.get(key);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }}

测试代码:

public static void main(String[] args) {        ApplicationContext ac =  new ClassPathXmlApplicationContext("classpath:/data-source.xml");        RedisClientTemplate redisClient = (RedisClientTemplate)ac.getBean("redisClientTemplate");        redisClient.set("a", "abc");        System.out.println(redisClient.get("a"));    }

附上RedisClientTemplate全部实现:

@Repository("redisClientTemplate")public class RedisClientTemplate {    private static final Logger log = LoggerFactory.getLogger(RedisClientTemplate.class);    @Autowired    private RedisDataSource     redisDataSource;    public void disconnect() {        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        shardedJedis.disconnect();    }    /**     * 设置单个值     *      * @param key     * @param value     * @return     */    public String set(String key, String value) {        String result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.set(key, value);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    /**     * 获取单个值     *      * @param key     * @return     */    public String get(String key) {        String result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.get(key);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public Boolean exists(String key) {        Boolean result = false;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.exists(key);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public String type(String key) {        String result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.type(key);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    /**     * 在某段时间后实现     *      * @param key     * @param unixTime     * @return     */    public Long expire(String key, int seconds) {        Long result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.expire(key, seconds);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    /**     * 在某个时间点失效     *      * @param key     * @param unixTime     * @return     */    public Long expireAt(String key, long unixTime) {        Long result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.expireAt(key, unixTime);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public Long ttl(String key) {        Long result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.ttl(key);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public boolean setbit(String key, long offset, boolean value) {        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        boolean result = false;        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.setbit(key, offset, value);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public boolean getbit(String key, long offset) {        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        boolean result = false;        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.getbit(key, offset);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public long setrange(String key, long offset, String value) {        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        long result = 0;        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.setrange(key, offset, value);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public String getrange(String key, long startOffset, long endOffset) {        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        String result = null;        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.getrange(key, startOffset, endOffset);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public String getSet(String key, String value) {        String result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.getSet(key, value);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public Long setnx(String key, String value) {        Long result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.setnx(key, value);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public String setex(String key, int seconds, String value) {        String result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.setex(key, seconds, value);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public Long decrBy(String key, long integer) {        Long result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.decrBy(key, integer);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public Long decr(String key) {        Long result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.decr(key);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public Long incrBy(String key, long integer) {        Long result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.incrBy(key, integer);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public Long incr(String key) {        Long result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.incr(key);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public Long append(String key, String value) {        Long result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.append(key, value);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public String substr(String key, int start, int end) {        String result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.substr(key, start, end);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public Long hset(String key, String field, String value) {        Long result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.hset(key, field, value);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public String hget(String key, String field) {        String result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.hget(key, field);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public Long hsetnx(String key, String field, String value) {        Long result = null;        ShardedJedis shardedJedis = redisDataSource.getRedisClient();        if (shardedJedis == null) {            return result;        }        boolean broken = false;        try {            result = shardedJedis.hsetnx(key, field, value);        } catch (Exception e) {            log.error(e.getMessage(), e);            broken = true;        } finally {            redisDataSource.returnResource(shardedJedis, broken);        }        return result;    }    public String hmset(String key, Map
hash) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hmset(key, hash); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public List
hmget(String key, String... fields) { List
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hmget(key, fields); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long hincrBy(String key, String field, long value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hincrBy(key, field, value); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Boolean hexists(String key, String field) { Boolean result = false; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hexists(key, field); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long del(String key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.del(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long hdel(String key, String field) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hdel(key, field); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long hlen(String key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hlen(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
hkeys(String key) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hkeys(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public List
hvals(String key) { List
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hvals(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Map
hgetAll(String key) { Map
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hgetAll(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } // ================list ====== l表示 list或 left, r表示right==================== public Long rpush(String key, String string) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.rpush(key, string); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long lpush(String key, String string) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lpush(key, string); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long llen(String key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.llen(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public List
lrange(String key, long start, long end) { List
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lrange(key, start, end); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public String ltrim(String key, long start, long end) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.ltrim(key, start, end); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public String lindex(String key, long index) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lindex(key, index); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public String lset(String key, long index, String value) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lset(key, index, value); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long lrem(String key, long count, String value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lrem(key, count, value); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public String lpop(String key) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lpop(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public String rpop(String key) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.rpop(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } //return 1 add a not exist value , //return 0 add a exist value public Long sadd(String key, String member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.sadd(key, member); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
smembers(String key) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.smembers(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long srem(String key, String member) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); Long result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.srem(key, member); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public String spop(String key) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); String result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.spop(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long scard(String key) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); Long result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.scard(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Boolean sismember(String key, String member) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); Boolean result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.sismember(key, member); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public String srandmember(String key) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); String result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.srandmember(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long zadd(String key, double score, String member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zadd(key, score, member); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrange(String key, int start, int end) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrange(key, start, end); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long zrem(String key, String member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrem(key, member); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Double zincrby(String key, double score, String member) { Double result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zincrby(key, score, member); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long zrank(String key, String member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrank(key, member); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long zrevrank(String key, String member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrank(key, member); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrevrange(String key, int start, int end) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrange(key, start, end); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrangeWithScores(String key, int start, int end) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeWithScores(key, start, end); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrevrangeWithScores(String key, int start, int end) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeWithScores(key, start, end); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long zcard(String key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zcard(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Double zscore(String key, String member) { Double result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zscore(key, member); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public List
sort(String key) { List
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.sort(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public List
sort(String key, SortingParams sortingParameters) { List
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.sort(key, sortingParameters); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long zcount(String key, double min, double max) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zcount(key, min, max); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrangeByScore(String key, double min, double max) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeByScore(key, min, max); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrevrangeByScore(String key, double max, double min) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeByScore(key, max, min); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrangeByScore(String key, double min, double max, int offset, int count) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeByScore(key, min, max, offset, count); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrevrangeByScore(String key, double max, double min, int offset, int count) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeByScore(key, max, min, offset, count); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrangeByScoreWithScores(String key, double min, double max) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeByScoreWithScores(key, min, max); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrevrangeByScoreWithScores(String key, double max, double min) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeByScoreWithScores(key, max, min); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrangeByScoreWithScores(String key, double min, double max, int offset, int count) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeByScoreWithScores(key, min, max, offset, count); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeByScoreWithScores(key, max, min, offset, count); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long zremrangeByRank(String key, int start, int end) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zremrangeByRank(key, start, end); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long zremrangeByScore(String key, double start, double end) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zremrangeByScore(key, start, end); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long linsert(String key, LIST_POSITION where, String pivot, String value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.linsert(key, where, pivot, value); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public String set(byte[] key, byte[] value) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.set(key, value); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public byte[] get(byte[] key) { byte[] result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.get(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Boolean exists(byte[] key) { Boolean result = false; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.exists(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public String type(byte[] key) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.type(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long expire(byte[] key, int seconds) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.expire(key, seconds); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long expireAt(byte[] key, long unixTime) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.expireAt(key, unixTime); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long ttl(byte[] key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.ttl(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public byte[] getSet(byte[] key, byte[] value) { byte[] result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.getSet(key, value); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long setnx(byte[] key, byte[] value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.setnx(key, value); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public String setex(byte[] key, int seconds, byte[] value) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.setex(key, seconds, value); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long decrBy(byte[] key, long integer) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.decrBy(key, integer); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long decr(byte[] key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.decr(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long incrBy(byte[] key, long integer) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.incrBy(key, integer); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long incr(byte[] key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.incr(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long append(byte[] key, byte[] value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.append(key, value); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public byte[] substr(byte[] key, int start, int end) { byte[] result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.substr(key, start, end); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long hset(byte[] key, byte[] field, byte[] value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hset(key, field, value); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public byte[] hget(byte[] key, byte[] field) { byte[] result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hget(key, field); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long hsetnx(byte[] key, byte[] field, byte[] value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hsetnx(key, field, value); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public String hmset(byte[] key, Map
hash) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hmset(key, hash); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public List
hmget(byte[] key, byte[]... fields) { List
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hmget(key, fields); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long hincrBy(byte[] key, byte[] field, long value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hincrBy(key, field, value); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Boolean hexists(byte[] key, byte[] field) { Boolean result = false; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hexists(key, field); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long hdel(byte[] key, byte[] field) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hdel(key, field); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long hlen(byte[] key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hlen(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
hkeys(byte[] key) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hkeys(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Collection
hvals(byte[] key) { Collection
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hvals(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Map
hgetAll(byte[] key) { Map
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hgetAll(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long rpush(byte[] key, byte[] string) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.rpush(key, string); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long lpush(byte[] key, byte[] string) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lpush(key, string); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long llen(byte[] key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.llen(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public List
lrange(byte[] key, int start, int end) { List
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lrange(key, start, end); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public String ltrim(byte[] key, int start, int end) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.ltrim(key, start, end); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public byte[] lindex(byte[] key, int index) { byte[] result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lindex(key, index); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public String lset(byte[] key, int index, byte[] value) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lset(key, index, value); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long lrem(byte[] key, int count, byte[] value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lrem(key, count, value); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public byte[] lpop(byte[] key) { byte[] result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lpop(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public byte[] rpop(byte[] key) { byte[] result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.rpop(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long sadd(byte[] key, byte[] member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.sadd(key, member); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
smembers(byte[] key) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.smembers(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long srem(byte[] key, byte[] member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.srem(key, member); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public byte[] spop(byte[] key) { byte[] result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.spop(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long scard(byte[] key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.scard(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Boolean sismember(byte[] key, byte[] member) { Boolean result = false; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.sismember(key, member); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public byte[] srandmember(byte[] key) { byte[] result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.srandmember(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long zadd(byte[] key, double score, byte[] member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zadd(key, score, member); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrange(byte[] key, int start, int end) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrange(key, start, end); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long zrem(byte[] key, byte[] member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrem(key, member); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Double zincrby(byte[] key, double score, byte[] member) { Double result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zincrby(key, score, member); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long zrank(byte[] key, byte[] member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrank(key, member); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long zrevrank(byte[] key, byte[] member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrank(key, member); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrevrange(byte[] key, int start, int end) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrange(key, start, end); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrangeWithScores(byte[] key, int start, int end) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeWithScores(key, start, end); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrevrangeWithScores(byte[] key, int start, int end) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeWithScores(key, start, end); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long zcard(byte[] key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zcard(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Double zscore(byte[] key, byte[] member) { Double result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zscore(key, member); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public List
sort(byte[] key) { List
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.sort(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public List
sort(byte[] key, SortingParams sortingParameters) { List
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.sort(key, sortingParameters); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long zcount(byte[] key, double min, double max) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zcount(key, min, max); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrangeByScore(byte[] key, double min, double max) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeByScore(key, min, max); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrangeByScore(byte[] key, double min, double max, int offset, int count) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeByScore(key, min, max, offset, count); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrangeByScoreWithScores(byte[] key, double min, double max) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeByScoreWithScores(key, min, max); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrangeByScoreWithScores(byte[] key, double min, double max, int offset, int count) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeByScoreWithScores(key, min, max, offset, count); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrevrangeByScore(byte[] key, double max, double min) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeByScore(key, max, min); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrevrangeByScore(byte[] key, double max, double min, int offset, int count) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeByScore(key, max, min, offset, count); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrevrangeByScoreWithScores(byte[] key, double max, double min) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeByScoreWithScores(key, max, min); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Set
zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count) { Set
result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeByScoreWithScores(key, max, min, offset, count); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long zremrangeByRank(byte[] key, int start, int end) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zremrangeByRank(key, start, end); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long zremrangeByScore(byte[] key, double start, double end) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zremrangeByScore(key, start, end); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.linsert(key, where, pivot, value); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public List
pipelined(ShardedJedisPipeline shardedJedisPipeline) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); List result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.pipelined(shardedJedisPipeline); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Jedis getShard(byte[] key) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); Jedis result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.getShard(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Jedis getShard(String key) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); Jedis result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.getShard(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public JedisShardInfo getShardInfo(byte[] key) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); JedisShardInfo result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.getShardInfo(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public JedisShardInfo getShardInfo(String key) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); JedisShardInfo result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.getShardInfo(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public String getKeyTag(String key) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); String result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.getKeyTag(key); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Collection
getAllShardInfo() { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); Collection
result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.getAllShardInfo(); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } public Collection
getAllShards() { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); Collection
result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.getAllShards(); } catch (Exception e) { log.error(e.getMessage(), e); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; }}
View Code

 

转载于:https://www.cnblogs.com/zhangtan/p/5765801.html

你可能感兴趣的文章
concurrent包
查看>>
在Linux下调试Python代码的各种方法
查看>>
centos7塔建MQ服务器
查看>>
Peer authentication failed for user
查看>>
超强的.NET图像工具包VintaSoftImaging.NET SDK更新至v8.6丨75折优惠
查看>>
阿里云上Kubernetes集群联邦
查看>>
洛谷2219:[HAOI2007]修筑绿化带——题解
查看>>
监控webservice信息
查看>>
a标签中href=""的几种用法(转)
查看>>
python
查看>>
ubuntu 常用生产环境部署配置测试调优
查看>>
【JS】//将中文逗号转换为英文逗号
查看>>
在VS2012中实现Ext JS的智能提示太简单了
查看>>
Extnet Direct 提交后台事件文件下载设置
查看>>
邻接矩阵与二叉排序树
查看>>
CSS选择器
查看>>
购物车练习
查看>>
js实现在表格中删除和添加一行
查看>>
SOCKET简单爬虫实现代码和使用方法
查看>>
跨域解决方案汇总
查看>>