文档章节

【Jedis配置】springSSM + Jedis连接池配置

卯金刀GG
 卯金刀GG
发布于 2018/08/09 19:19
字数 9593
阅读 34
收藏 0

1、使用MAVEN引入使用的包

		<dependency>
			<groupId>redis.clients</groupId>
			<artifactId>jedis</artifactId>
			<version>2.9.0</version>
		</dependency>

2、配置jedis的文件,redis.properties

redis.maxIdle=200
redis.maxTotal=600
redis.maxWaitMillis=30000
redis.testOnBorrow=true
redis.minIdle=1
redis.testOnReturn=true
redis.testWhileIdle=true
redis.masterName=mymaster
redis.host.a=ip1:26379
redis.host.b=ip2:26379
redis.host.c=ip3:26380
redis.password=test

3、配置文件applicationContext-redis.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
	<context:property-placeholder location="classpath:redis.properties" ignore-unresolvable="true"/>
	<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxIdle" value="${redis.maxIdle}" />
        <property name="maxTotal" value="${redis.maxTotal}" />
        <property name="maxWaitMillis" value="${redis.maxWaitMillis}" />
        <property name="testOnBorrow" value="${redis.testOnBorrow}" />
        <property name="minIdle" value="${redis.minIdle}"/>
        <property name="testOnReturn" value="${redis.testOnReturn}"/>
        <property name="testWhileIdle" value="${redis.testWhileIdle}"/>
    </bean>
 
    <bean id="jedisSentinelPool" class="redis.clients.jedis.JedisSentinelPool">
         <constructor-arg name="masterName" value="${redis.masterName}"></constructor-arg>
        <constructor-arg name="sentinels">
            <set>
                <value>${redis.host.a}</value>
                <value>${redis.host.b}</value>
                <value>${redis.host.c}</value>
            </set>
        </constructor-arg>
        <constructor-arg ref="jedisPoolConfig"></constructor-arg>
        <constructor-arg name="password" value="#{'${redis.password}'?:null}"></constructor-arg>
    </bean>

</beans>

4、连接池

package com.longfor.tender.service.inter;

import redis.clients.jedis.Jedis;
/**
 * JedisSentinelPool哨兵连接池
 * 
 * Redis <b>哨兵</b>集群 注意事项:
 * 	1.redis哨兵集群只有2个节点无法正常工作,所以哨兵集群必须部署2个以上节点
 * 	2.使用完连接后必须利用  returnResource() 方法回收资源,详情看方法描述
 * <p>详情摘要:
 * master宕机,s1和s2中只要有1个哨兵认为master宕机就可以还行切换,同时s1和s2中会选举出一个哨兵来执行故障转移
 * 同时这个时候,需要majority,也就是大多数哨兵都是运行的,2个哨兵的majority就是2(2的majority=2,3的majority=2,5的majority=3,4的majority=2),2个哨兵都运行着,就可以允许执行故障转移
 * 但是如果整个M1和S1运行的机器宕机了,那么哨兵只有1个了,此时就没有majority来允许执行故障转移,虽然另外一台机器还有一个R1,但是故障转移不会执行
 * <b>
 * 文献地址:
 * https://blog.csdn.net/qq_25868207/article/details/79147469
 * </b>
 * </p>
 * @author 
 * @date 2018/8/8 
 */
public interface IRedisDataSource {
	public abstract Jedis getRedisClient();
    public void returnResource(Jedis shardedJedis);
    public void returnResource(Jedis shardedJedis,boolean broken);
}

5、使用方法

package com.longfor.tender.service.inter;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
import org.springframework.stereotype.Repository;

import redis.clients.jedis.SortingParams;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.BinaryClient.LIST_POSITION;
 
@Repository
public interface IRedisBaseDao {
 
    public void disconnect();
 
    /**
     * 设置单个值
     *
     * @param key
     * @param value
     * @return
     */
    public String set(String key, String value);
 
    /**
     * 获取单个值
     *
     * @param key
     * @return
     */
    public String get(String key);
 
    public Boolean exists(String key);
 
    public String type(String key);
 
    /**
     * 在某段时间后实现
     *
     * @param key
     * @param unixTime
     * @return
     */
    public Long expire(String key, int seconds);
 
    /**
     * 在某个时间点失效
     *
     * @param key
     * @param unixTime
     * @return
     */
    public Long expireAt(String key, long unixTime);
 
    public Long ttl(String key);
 
    public boolean setbit(String key, long offset, boolean value);
 
    public boolean getbit(String key, long offset);
 
    public long setrange(String key, long offset, String value);
 
    public String getrange(String key, long startOffset, long endOffset);
 
    public String getSet(String key, String value);
 
    public Long setnx(String key, String value);
 
    public String setex(String key, int seconds, String value);
 
    public Long decrBy(String key, long integer);
 
    public Long decr(String key);
 
    public Long incrBy(String key, long integer);
 
    public Long incr(String key);
 
    public Long append(String key, String value);
 
    public String substr(String key, int start, int end);
 
    public Long hset(String key, String field, String value);
 
    public String hget(String key, String field);
 
    public Long hsetnx(String key, String field, String value);
 
    public String hmset(String key, Map<String, String> hash);
 
    public List<String> hmget(String key, String... fields);
 
    public Long hincrBy(String key, String field, long value);
 
    public Boolean hexists(String key, String field);
 
    public Long del(String key);
 
    public Long hdel(String key, String field);
 
    public Long hlen(String key);
 
    public Set<String> hkeys(String key);
 
    public List<String> hvals(String key);
 
    public Map<String, String> hgetAll(String key);
 
    // ================list ====== l表示 list或 left, r表示right====================
    public Long rpush(String key, String string);
 
    public Long lpush(String key, String string);
 
    public Long llen(String key);
 
    public List<String> lrange(String key, long start, long end);
 
    public String ltrim(String key, long start, long end);
 
    public String lindex(String key, long index);
 
    public String lset(String key, long index, String value);
 
    public Long lrem(String key, long count, String value);
 
    public String lpop(String key);
 
    public String rpop(String key);
 
    //return 1 add a not exist value ,
    //return 0 add a exist value
    public Long sadd(String key, String member);
 
    public Set<String> smembers(String key);
 
    public Long srem(String key, String member);
 
    public String spop(String key);
 
    public Long scard(String key);
 
    public Boolean sismember(String key, String member);
 
    public String srandmember(String key);
 
    public Long zadd(String key, double score, String member);
 
    public Set<String> zrange(String key, int start, int end);
 
    public Long zrem(String key, String member);
 
    public Double zincrby(String key, double score, String member);
 
    public Long zrank(String key, String member);
 
    public Long zrevrank(String key, String member);
 
    public Set<String> zrevrange(String key, int start, int end);
 
    public Set<Tuple> zrangeWithScores(String key, int start, int end);
 
    public Set<Tuple> zrevrangeWithScores(String key, int start, int end);
 
    public Long zcard(String key);
 
    public Double zscore(String key, String member);
 
    public List<String> sort(String key);
 
    public List<String> sort(String key, SortingParams sortingParameters);
 
    public Long zcount(String key, double min, double max);
 
    public Set<String> zrangeByScore(String key, double min, double max);
 
    public Set<String> zrevrangeByScore(String key, double max, double min);
 
    public Set<String> zrangeByScore(String key, double min, double max, int offset, int count);
 
    public Set<String> zrevrangeByScore(String key, double max, double min, int offset, int count);
 
    public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max);
 
    public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min);
 
    public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max, int offset, int count);
 
    public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count);
 
    public Long zremrangeByRank(String key, int start, int end);
 
    public Long zremrangeByScore(String key, double start, double end);
 
    public Long linsert(String key, LIST_POSITION where, String pivot, String value);
 
    public String set(byte[] key, byte[] value);
 
    public byte[] get(byte[] key);
 
    public Boolean exists(byte[] key);
 
    public String type(byte[] key);
 
    public Long expire(byte[] key, int seconds);
 
    public Long expireAt(byte[] key, long unixTime);
 
    public Long ttl(byte[] key);
 
    public byte[] getSet(byte[] key, byte[] value);
 
    public Long setnx(byte[] key, byte[] value);
 
    public String setex(byte[] key, int seconds, byte[] value);
 
    public Long decrBy(byte[] key, long integer);
 
    public Long decr(byte[] key);
 
    public Long incrBy(byte[] key, long integer);
 
    public Long incr(byte[] key);
 
    public Long append(byte[] key, byte[] value);
 
    public byte[] substr(byte[] key, int start, int end);
 
    public Long hset(byte[] key, byte[] field, byte[] value);
 
    public byte[] hget(byte[] key, byte[] field);
 
    public Long hsetnx(byte[] key, byte[] field, byte[] value);
 
    public String hmset(byte[] key, Map<byte[], byte[]> hash);
 
    public List<byte[]> hmget(byte[] key, byte[]... fields);
 
    public Long hincrBy(byte[] key, byte[] field, long value);
 
    public Boolean hexists(byte[] key, byte[] field);
 
    public Long hdel(byte[] key, byte[] field);
 
    public Long hlen(byte[] key);
 
    public Set<byte[]> hkeys(byte[] key);
 
    public Collection<byte[]> hvals(byte[] key);
 
    public Map<byte[], byte[]> hgetAll(byte[] key);
 
    public Long rpush(byte[] key, byte[] string);
 
    public Long lpush(byte[] key, byte[] string);
 
    public Long llen(byte[] key);
 
    public List<byte[]> lrange(byte[] key, int start, int end);
 
    public String ltrim(byte[] key, int start, int end);
 
    public byte[] lindex(byte[] key, int index);
 
    public String lset(byte[] key, int index, byte[] value);
 
    public Long lrem(byte[] key, int count, byte[] value);
 
    public byte[] lpop(byte[] key);
 
    public byte[] rpop(byte[] key);
 
    public Long sadd(byte[] key, byte[] member);
 
    public Set<byte[]> smembers(byte[] key);
 
    public Long srem(byte[] key, byte[] member);
 
    public byte[] spop(byte[] key);
 
    public Long scard(byte[] key);
 
    public Boolean sismember(byte[] key, byte[] member);
 
    public byte[] srandmember(byte[] key);
 
    public Long zadd(byte[] key, double score, byte[] member);
 
    public Set<byte[]> zrange(byte[] key, int start, int end);
 
    public Long zrem(byte[] key, byte[] member);
 
    public Double zincrby(byte[] key, double score, byte[] member);
 
    public Long zrank(byte[] key, byte[] member);
 
    public Long zrevrank(byte[] key, byte[] member);
 
    public Set<byte[]> zrevrange(byte[] key, int start, int end);
 
    public Set<Tuple> zrangeWithScores(byte[] key, int start, int end);
 
    public Set<Tuple> zrevrangeWithScores(byte[] key, int start, int end);
 
    public Long zcard(byte[] key);
 
    public Double zscore(byte[] key, byte[] member);
 
    public List<byte[]> sort(byte[] key);
 
    public List<byte[]> sort(byte[] key, SortingParams sortingParameters);
 
    public Long zcount(byte[] key, double min, double max);
 
    public Set<byte[]> zrangeByScore(byte[] key, double min, double max);
 
    public Set<byte[]> zrangeByScore(byte[] key, double min, double max, int offset, int count);
 
    public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max);
 
    public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max, int offset, int count);
 
    public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min);
 
    public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min, int offset, int count);
 
    public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min);
 
    public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count);
 
    public Long zremrangeByRank(byte[] key, int start, int end);
 
    public Long zremrangeByScore(byte[] key, double start, double end);
 
    public Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value);
 
    /*public List<Object> pipelined(ShardedJedisPipeline shardedJedisPipeline);
    public Jedis getShard(byte[] key);
    public Jedis getShard(String key);
    public JedisShardInfo getShardInfo(byte[] key);
    public JedisShardInfo getShardInfo(String key);
    public String getKeyTag(String key);
    public Collection<JedisShardInfo> getAllShardInfo();
    public Collection<Jedis> getAllShards();*/
 
}

6、实现类

package com.longfor.tender.service.impl;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.longfor.tender.service.inter.IRedisBaseDao;
import com.longfor.tender.service.inter.IRedisDataSource;

import redis.clients.jedis.BinaryClient.LIST_POSITION;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.Tuple;
 
@Repository
public class RedisBaseDaoImpl implements IRedisBaseDao {
 
    private static final Logger log = LoggerFactory.getLogger(RedisBaseDaoImpl.class);
 
    @Autowired
    private IRedisDataSource redisDataSource;
 
    public void disconnect() {
        Jedis jedis = redisDataSource.getRedisClient();
        jedis.disconnect();
    }
    /**
     * 设置对象    
     * 未完成的方法,因为用不着。
     * @author 杨帅  
     * @param key
     * @param value
     * @return
     */
//    public String setObject(String key, Object value) {
//        String result = null;
// 
//        Jedis jedis = redisDataSource.getRedisClient();
//        if (jedis == null) {
//            return result;
//        }
//        boolean broken = false;
//        try {
//        	if(value instanceof List<?>){
//        		result = jedis.(key, value);
//        	}
//            
//        } catch (Exception e) {
//            log.error(e.getMessage(), e);
//            broken = true;
//        } finally {
//            redisDataSource.returnResource(jedis, broken);
//        }
//        return result;
//    }
    /**
     * 设置单个值
     *
     * @param key
     * @param value
     * @return
     */
    public String set(String key, String value) {
        String result = null;
 
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.set(key, value);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    /**
     * 获取单个值
     *
     * @param key
     * @return
     */
    public String get(String key) {
        String result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
 
        boolean broken = false;
        try {
            result = jedis.get(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
    /**
     * 查看某个key是否存在
     * @param key
     * @return 
     */
    public Boolean exists(String key) {
        Boolean result = false;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.exists(key);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
	 /**
	  * Redis Type 命令用于返回 key 所储存的值的类型
	  * @return none (key不存在) string (字符串) list (列表) set (集合) zset (有序集) hash (哈希表)
	  */
    public String type(String key) {
        String result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.type(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    /**
     * 在某段时间后实现
     *
     * @param key
     * @param unixTime
     * @return
     */
    public Long expire(String key, int seconds) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.expire(key, seconds);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    /**
     * 在某个时间点失效
     *
     * @param key
     * @param unixTime
     * @return
     */
    public Long expireAt(String key, long unixTime) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.expireAt(key, unixTime);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long ttl(String key) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.ttl(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public boolean setbit(String key, long offset, boolean value) {
 
        Jedis jedis = redisDataSource.getRedisClient();
        boolean result = false;
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.setbit(key, offset, value);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public boolean getbit(String key, long offset) {
        Jedis jedis = redisDataSource.getRedisClient();
        boolean result = false;
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
 
        try {
            result = jedis.getbit(key, offset);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public long setrange(String key, long offset, String value) {
        Jedis jedis = redisDataSource.getRedisClient();
        long result = 0;
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.setrange(key, offset, value);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String getrange(String key, long startOffset, long endOffset) {
        Jedis jedis = redisDataSource.getRedisClient();
        String result = null;
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.getrange(key, startOffset, endOffset);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String getSet(String key, String value) {
        String result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.getSet(key, value);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long setnx(String key, String value) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.setnx(key, value);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String setex(String key, int seconds, String value) {
        String result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.setex(key, seconds, value);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long decrBy(String key, long integer) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.decrBy(key, integer);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long decr(String key) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.decr(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long incrBy(String key, long integer) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.incrBy(key, integer);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long incr(String key) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.incr(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long append(String key, String value) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.append(key, value);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String substr(String key, int start, int end) {
        String result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.substr(key, start, end);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long hset(String key, String field, String value) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.hset(key, field, value);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String hget(String key, String field) {
        String result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.hget(key, field);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long hsetnx(String key, String field, String value) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.hsetnx(key, field, value);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String hmset(String key, Map<String, String> hash) {
        String result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.hmset(key, hash);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public List<String> hmget(String key, String... fields) {
        List<String> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.hmget(key, fields);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long hincrBy(String key, String field, long value) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.hincrBy(key, field, value);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Boolean hexists(String key, String field) {
        Boolean result = false;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.hexists(key, field);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long del(String key) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.del(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long hdel(String key, String field) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.hdel(key, field);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long hlen(String key) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.hlen(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<String> hkeys(String key) {
        Set<String> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.hkeys(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public List<String> hvals(String key) {
        List<String> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.hvals(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Map<String, String> hgetAll(String key) {
        Map<String, String> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.hgetAll(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    // ================list ====== l表示 list或 left, r表示right====================
    public Long rpush(String key, String string) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.rpush(key, string);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long lpush(String key, String string) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.lpush(key, string);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long llen(String key) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.llen(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public List<String> lrange(String key, long start, long end) {
        List<String> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.lrange(key, start, end);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String ltrim(String key, long start, long end) {
        String result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.ltrim(key, start, end);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String lindex(String key, long index) {
        String result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.lindex(key, index);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String lset(String key, long index, String value) {
        String result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.lset(key, index, value);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long lrem(String key, long count, String value) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.lrem(key, count, value);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String lpop(String key) {
        String result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.lpop(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String rpop(String key) {
        String result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.rpop(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, 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;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.sadd(key, member);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<String> smembers(String key) {
        Set<String> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.smembers(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long srem(String key, String member) {
        Jedis jedis = redisDataSource.getRedisClient();
 
        Long result = null;
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.srem(key, member);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String spop(String key) {
        Jedis jedis = redisDataSource.getRedisClient();
        String result = null;
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.spop(key);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long scard(String key) {
        Jedis jedis = redisDataSource.getRedisClient();
        Long result = null;
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.scard(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Boolean sismember(String key, String member) {
        Jedis jedis = redisDataSource.getRedisClient();
        Boolean result = null;
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.sismember(key, member);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String srandmember(String key) {
        Jedis jedis = redisDataSource.getRedisClient();
        String result = null;
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.srandmember(key);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long zadd(String key, double score, String member) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.zadd(key, score, member);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<String> zrange(String key, int start, int end) {
        Set<String> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.zrange(key, start, end);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long zrem(String key, String member) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.zrem(key, member);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Double zincrby(String key, double score, String member) {
        Double result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zincrby(key, score, member);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long zrank(String key, String member) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrank(key, member);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long zrevrank(String key, String member) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrevrank(key, member);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<String> zrevrange(String key, int start, int end) {
        Set<String> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrevrange(key, start, end);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<Tuple> zrangeWithScores(String key, int start, int end) {
        Set<Tuple> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrangeWithScores(key, start, end);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<Tuple> zrevrangeWithScores(String key, int start, int end) {
        Set<Tuple> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrevrangeWithScores(key, start, end);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long zcard(String key) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zcard(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Double zscore(String key, String member) {
        Double result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zscore(key, member);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public List<String> sort(String key) {
        List<String> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.sort(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public List<String> sort(String key, SortingParams sortingParameters) {
        List<String> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.sort(key, sortingParameters);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long zcount(String key, double min, double max) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zcount(key, min, max);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<String> zrangeByScore(String key, double min, double max) {
        Set<String> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrangeByScore(key, min, max);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<String> zrevrangeByScore(String key, double max, double min) {
        Set<String> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrevrangeByScore(key, max, min);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<String> zrangeByScore(String key, double min, double max, int offset, int count) {
        Set<String> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrangeByScore(key, min, max, offset, count);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<String> zrevrangeByScore(String key, double max, double min, int offset, int count) {
        Set<String> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrevrangeByScore(key, max, min, offset, count);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max) {
        Set<Tuple> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrangeByScoreWithScores(key, min, max);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min) {
        Set<Tuple> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrevrangeByScoreWithScores(key, max, min);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max, int offset, int count) {
        Set<Tuple> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrangeByScoreWithScores(key, min, max, offset, count);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count) {
        Set<Tuple> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrevrangeByScoreWithScores(key, max, min, offset, count);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long zremrangeByRank(String key, int start, int end) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zremrangeByRank(key, start, end);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long zremrangeByScore(String key, double start, double end) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zremrangeByScore(key, start, end);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long linsert(String key, LIST_POSITION where, String pivot, String value) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.linsert(key, where, pivot, value);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String set(byte[] key, byte[] value) {
        String result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.set(key, value);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public byte[] get(byte[] key) {
        byte[] result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.get(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Boolean exists(byte[] key) {
        Boolean result = false;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.exists(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String type(byte[] key) {
        String result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.type(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long expire(byte[] key, int seconds) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.expire(key, seconds);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long expireAt(byte[] key, long unixTime) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.expireAt(key, unixTime);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long ttl(byte[] key) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.ttl(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public byte[] getSet(byte[] key, byte[] value) {
        byte[] result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.getSet(key, value);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long setnx(byte[] key, byte[] value) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.setnx(key, value);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String setex(byte[] key, int seconds, byte[] value) {
        String result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.setex(key, seconds, value);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long decrBy(byte[] key, long integer) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.decrBy(key, integer);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long decr(byte[] key) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.decr(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long incrBy(byte[] key, long integer) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.incrBy(key, integer);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long incr(byte[] key) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.incr(key);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long append(byte[] key, byte[] value) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.append(key, value);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public byte[] substr(byte[] key, int start, int end) {
        byte[] result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.substr(key, start, end);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long hset(byte[] key, byte[] field, byte[] value) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.hset(key, field, value);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public byte[] hget(byte[] key, byte[] field) {
        byte[] result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.hget(key, field);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long hsetnx(byte[] key, byte[] field, byte[] value) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.hsetnx(key, field, value);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String hmset(byte[] key, Map<byte[], byte[]> hash) {
        String result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.hmset(key, hash);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public List<byte[]> hmget(byte[] key, byte[]... fields) {
        List<byte[]> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.hmget(key, fields);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long hincrBy(byte[] key, byte[] field, long value) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.hincrBy(key, field, value);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Boolean hexists(byte[] key, byte[] field) {
        Boolean result = false;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.hexists(key, field);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long hdel(byte[] key, byte[] field) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.hdel(key, field);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long hlen(byte[] key) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.hlen(key);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<byte[]> hkeys(byte[] key) {
        Set<byte[]> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.hkeys(key);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Collection<byte[]> hvals(byte[] key) {
        Collection<byte[]> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.hvals(key);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Map<byte[], byte[]> hgetAll(byte[] key) {
        Map<byte[], byte[]> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.hgetAll(key);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long rpush(byte[] key, byte[] string) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.rpush(key, string);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long lpush(byte[] key, byte[] string) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.lpush(key, string);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long llen(byte[] key) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.llen(key);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public List<byte[]> lrange(byte[] key, int start, int end) {
        List<byte[]> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.lrange(key, start, end);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String ltrim(byte[] key, int start, int end) {
        String result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.ltrim(key, start, end);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public byte[] lindex(byte[] key, int index) {
        byte[] result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.lindex(key, index);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public String lset(byte[] key, int index, byte[] value) {
        String result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.lset(key, index, value);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long lrem(byte[] key, int count, byte[] value) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.lrem(key, count, value);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public byte[] lpop(byte[] key) {
        byte[] result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.lpop(key);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public byte[] rpop(byte[] key) {
        byte[] result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.rpop(key);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long sadd(byte[] key, byte[] member) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.sadd(key, member);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<byte[]> smembers(byte[] key) {
        Set<byte[]> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.smembers(key);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long srem(byte[] key, byte[] member) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.srem(key, member);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public byte[] spop(byte[] key) {
        byte[] result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.spop(key);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long scard(byte[] key) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.scard(key);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Boolean sismember(byte[] key, byte[] member) {
        Boolean result = false;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.sismember(key, member);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public byte[] srandmember(byte[] key) {
        byte[] result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.srandmember(key);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long zadd(byte[] key, double score, byte[] member) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zadd(key, score, member);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<byte[]> zrange(byte[] key, int start, int end) {
        Set<byte[]> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrange(key, start, end);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long zrem(byte[] key, byte[] member) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrem(key, member);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Double zincrby(byte[] key, double score, byte[] member) {
        Double result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zincrby(key, score, member);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long zrank(byte[] key, byte[] member) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrank(key, member);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long zrevrank(byte[] key, byte[] member) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrevrank(key, member);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<byte[]> zrevrange(byte[] key, int start, int end) {
        Set<byte[]> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrevrange(key, start, end);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<Tuple> zrangeWithScores(byte[] key, int start, int end) {
        Set<Tuple> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrangeWithScores(key, start, end);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<Tuple> zrevrangeWithScores(byte[] key, int start, int end) {
        Set<Tuple> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrevrangeWithScores(key, start, end);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long zcard(byte[] key) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zcard(key);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Double zscore(byte[] key, byte[] member) {
        Double result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zscore(key, member);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public List<byte[]> sort(byte[] key) {
        List<byte[]> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.sort(key);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public List<byte[]> sort(byte[] key, SortingParams sortingParameters) {
        List<byte[]> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.sort(key, sortingParameters);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long zcount(byte[] key, double min, double max) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zcount(key, min, max);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<byte[]> zrangeByScore(byte[] key, double min, double max) {
        Set<byte[]> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrangeByScore(key, min, max);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<byte[]> zrangeByScore(byte[] key, double min, double max, int offset, int count) {
        Set<byte[]> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrangeByScore(key, min, max, offset, count);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max) {
        Set<Tuple> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrangeByScoreWithScores(key, min, max);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max, int offset, int count) {
        Set<Tuple> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrangeByScoreWithScores(key, min, max, offset, count);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min) {
        Set<byte[]> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrevrangeByScore(key, max, min);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min, int offset, int count) {
        Set<byte[]> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrevrangeByScore(key, max, min, offset, count);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min) {
        Set<Tuple> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrevrangeByScoreWithScores(key, max, min);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count) {
        Set<Tuple> result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zrevrangeByScoreWithScores(key, max, min, offset, count);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long zremrangeByRank(byte[] key, int start, int end) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zremrangeByRank(key, start, end);
 
        } catch (Exception e) {
 
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long zremrangeByScore(byte[] key, double start, double end) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.zremrangeByScore(key, start, end);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    public Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value) {
        Long result = null;
        Jedis jedis = redisDataSource.getRedisClient();
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
 
            result = jedis.linsert(key, where, pivot, value);
 
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
 
    /*@SuppressWarnings("deprecation")
    public List<Object> pipelined(ShardedJedisPipeline shardedJedisPipeline) {
        Jedis jedis = redisDataSource.getRedisClient();
        List<Object> result = null;
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.pipelined(shardedJedisPipeline);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
    public Jedis getShard(byte[] key) {
        Jedis jedis = redisDataSource.getRedisClient();
        Jedis result = null;
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.getShard(key);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
    public Jedis getShard(String key) {
        Jedis jedis = redisDataSource.getRedisClient();
        Jedis result = null;
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.getShard(key);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
    public JedisShardInfo getShardInfo(byte[] key) {
        Jedis jedis = redisDataSource.getRedisClient();
        JedisShardInfo result = null;
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.getShardInfo(key);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
    public JedisShardInfo getShardInfo(String key) {
        Jedis jedis = redisDataSource.getRedisClient();
        JedisShardInfo result = null;
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.getShardInfo(key);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
    public String getKeyTag(String key) {
        Jedis jedis = redisDataSource.getRedisClient();
        String result = null;
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.getKeyTag(key);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
    public Collection<JedisShardInfo> getAllShardInfo() {
        Jedis jedis = redisDataSource.getRedisClient();
        Collection<JedisShardInfo> result = null;
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.getAllShardInfo();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }
    public Collection<Jedis> getAllShards() {
        Jedis jedis = redisDataSource.getRedisClient();
        Collection<Jedis> result = null;
        if (jedis == null) {
            return result;
        }
        boolean broken = false;
        try {
            result = jedis.getAllShards();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            broken = true;
        } finally {
            redisDataSource.returnResource(jedis, broken);
        }
        return result;
    }*/
 


}

7、实现

package com.longfor.tender.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.longfor.tender.service.inter.IRedisDataSource;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisSentinelPool;
/**
 * JedisSentinelPool哨兵连接池
 * <p>注意事项:资源回收</p>
 * @author 
 * @date 2018/8/8 
 */
@Service
@Repository("iRedisDataSource")
public class RedisDataSourceImpl implements IRedisDataSource {

	private static final Logger log = LoggerFactory.getLogger(RedisDataSourceImpl.class);
	 
    @Autowired
    private JedisSentinelPool jedisSentinelPool;
    /**
     * 从redis连接池获取连接
     */
    public Jedis getRedisClient() {
        try {
            Jedis shardJedis = jedisSentinelPool.getResource();
            return shardJedis;
        } catch (Exception e) {
            log.error("getRedisClent error", e);
        }
        return null;
    }
   /** 
    * 问题描述:
    * 分布式服务采用redis作为分布式锁实现,采用了jedispool作为连接池管理链接,当高并发大批量进行服务调用之后,redis开始出现异常,
    *  大致为: classCastException:[B cann't cast long ........................    timeout等信息,服务不得不回滚。
    * 通过对问题代码分析,可能是由于多线程在从redispool 里获取jedis资源的时候,由于获取的链接可能发生了异常,导致这个链接在returnResource时,
    * 没有被正确的回收,导致资源被耗尽,出现timeout的问题,同时,由于出现问题的链接,回收时,资源没有别初始化完全,
    * 导致在多线程的情况下,在同一个链接中(jedis对象)发生了数据共享的问题,这也就导致了出现类转换异常这样的错误。
	* 解决办法: 
	* 1.通过对returnResoure代码的分析发现,还有一个方法是专门处理这种链接情况的returnBrokeResoure,这两个方法要同时对jedis实例进行捕获异常情况与回收资源,
	* 2.也可以使用 close 来回收jedis资源。 
	*/
    public void returnResource(Jedis shardedJedis) {
 //   	jedisSentinelPool.returnResource(shardedJedis);
        shardedJedis.close();
    }
 
    public void returnResource(Jedis shardedJedis, boolean broken) {
        if (broken) {
//            jedisSentinelPool.returnBrokenResource(shardedJedis);
            shardedJedis.close();
        } else {
//            jedisSentinelPool.returnResource(shardedJedis);
            shardedJedis.close();
        }
    }

}

8、测试

package jedis;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisSentinelPool;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring/applicationContext-redis.xml")
public class JedisTest extends AbstractJUnit4SpringContextTests {
	@Resource
	private JedisSentinelPool jedisSentinelPool;

	@Test
	public void basicOpTest() {
		Jedis jedis = null;
		try{
			jedis = jedisSentinelPool.getResource();
		}catch(Exception e){
			e.printStackTrace();
		}finally {
			jedis.close();
		}
		jedis.set("name1", "啊啊啊啊");
		jedis.set("city1", "啊啊啊啊");
		String name = jedis.get("name1").toString();
		String city = jedis.get("city1").toString();
		
		System.out.println("frank:"+name +"&beijing:"+city);
		
		jedis.del("name1");
		Boolean result = jedis.exists("name1");
		
		System.out.println("nameResult:"+result);
		
		result = jedis.exists("city1");
		
		System.out.println("cityResult:"+result);
		jedis.close();
	}
}

 

收工,欢迎测试!

2018年8月15日 更新

edis存储对象与对象序列化详解

为什么要实现序列化接口

   当一个类实现了Serializable接口(该接口仅为标记接口,不包含任何方法定义),表示该类可以序列化.序列化的目的是将一个实现了Serializable接口的对象转换成一个字节序列,可以。 把该字节序列保存起来(例如:保存在一个文件里),以后可以随时将该字节序列恢复为原来的对象。甚至可以将该字节序列放到其他计算机上或者通过网络传输到其他计算机上恢复,只要该计 算机平台存在相应的类就可以正常恢复为原来的对象。 实现:要序列化一个对象,先要创建某些OutputStream对象,然后将其封装在一个ObjectOutputStream对象内,再调用writeObject()方法即可序列化一个对象;反序列化也类似。
注意:使用对象流写入到文件是不仅要保证该对象是序列化的,而且该对象的成员对象也必须是序列化的

关于Serializable接口的类中的serialVersionUID:
serialVersionUID是long类型的。在Eclipse中有两种生成方式:
默认的是1L:
private static final long serialVersionUID = 1L;
另外一个则是根据类名、接口名、成员方法以及属性等生成一个64位的哈希字段:
private static final long serialVersionUID = 3969438177161438988L;
serialVersionUID主要是为了解决对象反序列化的兼容性问题
如果没有提供serialVersionUID,对象序列化后存到硬盘上之后,再增加或减少类的filed。这样,当反序列化时,就会出现Exception,造成不兼容问题。
但当serialVersionUID相同时,它就会将不一样的field以type的缺省值反序列化。这样就可以避开不兼容问题了。

以上方式只能恢复成Java对象,如果想要恢复成其他对象(如C++对象),那就要将Java对象转换为XML格式,这样可以使其被各种平台和各种语言使用。可以使用随JDK一起发布的javax.xam.*类库,或者使用开源XOM类库(可以从www.xom.nu下载并获得文档)。

 

package Object1;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import bean.Person;
import redis.clients.jedis.Jedis;

public class SerializeUtil {
    public static void main(String [] args){   
        //存对象
        Person p=new Person();  //peson类记得实现序列化接口 Serializable
        p.setAge(20);
        p.setName("姚波");
        p.setId(1);
        jedis.set("person".getBytes(), serialize(p));
        byte[] byt=jedis.get("person".getBytes());
        Object obj=unserizlize(byt);
        if(obj instanceof Person){
            System.out.println(obj);
        }
    }
    
    //序列化 
    public static byte [] serialize(Object obj){
        ObjectOutputStream obi=null;
        ByteArrayOutputStream bai=null;
        try {
            bai=new ByteArrayOutputStream();
            obi=new ObjectOutputStream(bai);
            obi.writeObject(obj);
            byte[] byt=bai.toByteArray();
            return byt;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    
    //反序列化
    public static Object unserizlize(byte[] byt){
        ObjectInputStream oii=null;
        ByteArrayInputStream bis=null;
        bis=new ByteArrayInputStream(byt);
        try {
            oii=new ObjectInputStream(bis);
            Object obj=oii.readObject();
            return obj;
        } catch (Exception e) {
            
            e.printStackTrace();
        }
    
        
        return null;
    }
}

 

© 著作权归作者所有

卯金刀GG
粉丝 26
博文 265
码字总数 72868
作品 0
昌平
程序员
私信 提问
jedis池的介绍及使用

一、jedis池的介绍 相信大家都用过线程池或者是jdbc的连接池,使用池可以减少系统在使用所需对象时创建对象的开销,从而提高系统性能和效率。jedis池也是如此,那么我们该如何使用jedis池呢?...

杀神之疯子
2017/06/02
0
0
【Redis】- 客户端 Jedis

Redis 常用客户端: Redission、Jedis jedis 简介 redis的Java客户端,可访问、操作Redis Jedis工具类: Redis 配置 基础测试类:

ZeroneLove
02/23
43
0
SpringBoot整合Redis Lettuce

最近在准备集成的基础框架使用Spring Boot2搭建,其中Redis的支持不仅仅是丰富了它的API,更是替换掉底层Jedis的依赖,取而代之换成了Lettuce(生菜) jedis跟lettuce的区别 Lettuce 和 Jedis ...

lemonLove
2018/12/12
1K
0
Redis客户端常见异常分析

一.无法从连接池获取到连接 JedisPool中的Jedis对象个数是有限的,默认是8个。这里假设使用的默认配置,如果有8个Jedis对象被占用,并且没有归还,如果调用者还要从JedisPool中借用Jedis,就...

杀神之疯子
2017/06/02
0
0
Redis客户端常见异常分析

一.无法从连接池获取到连接 JedisPool中的Jedis对象个数是有限的,默认是8个。这里假设使用的默认配置,如果有8个Jedis对象被占用,并且没有归还,如果调用者还要从JedisPool中借用Jedis,就...

xpttxsok
2016/11/30
150
0

没有更多内容

加载失败,请刷新页面

加载更多

如何编写高质量的 JS 函数(1) -- 敲山震虎篇

本文首发于 vivo互联网技术 微信公众号 链接:https://mp.weixin.qq.com/s/7lCK9cHmunvYlbm7Xi7JxQ 作者:杨昆 一千个读者,有一千个哈姆雷特。 此系列文章将会从函数的执行机制、鲁棒性、函...

vivo互联网技术
43分钟前
5
0
学会这5个Excel技巧,让你拒绝加班

在网上,随处都可以看到Excel技巧,估计已看腻了吧?但下面5个Excel技巧会让你相见恨晚。关键的是它们个个还很实用 图一 技巧1:快速删除边框 有时当我们处理数据需要去掉边框,按Ctrl+Shif...

干货趣分享
今天
11
0
JS基础-该如何理解原型、原型链?

JS的原型、原型链一直是比较难理解的内容,不少初学者甚至有一定经验的老鸟都不一定能完全说清楚,更多的"很可能"是一知半解,而这部分内容又是JS的核心内容,想要技术进阶的话肯定不能对这个...

OBKoro1
今天
9
0
高防CDN的出现是为了解决网站的哪些问题?

高防CDN是为了更好的服务网络而出现的,是通过高防DNS来实现的。高防CDN是通过智能化的系统判断来路,再反馈给用户,可以减轻用户使用过程的复杂程度。通过智能DNS解析,能让网站访问者连接到...

云漫网络Ruan
今天
15
0
OSChina 周一乱弹 —— 熟悉的味道,难道这就是恋爱的感觉

Osc乱弹歌单(2019)请戳(这里) 【今日歌曲】 @xiaoshiyue :好久没分享歌了分享张碧晨的单曲《今后我与自己流浪》 《今后我与自己流浪》- 张碧晨 手机党少年们想听歌,请使劲儿戳(这里)...

小小编辑
今天
3.3K
25

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部