redis的配置及使用

一、redis配置

  1、启动redis

  这里使用的是windows版本的redis,直接解压使用就可以了。

   注意1: 当运行redis-server时需要注意的是不同的电脑因为配置问题可能无法双击启动。所以需要通过命令提示符的方式进行启动

  

  这个界面表示redis已经启动,默认配置 redis.host=localhost   redis.port=6379

   2、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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">  

     <context:component-scan base-package="com.zhongwu.redis.dao"/> 

    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxActive" value="50" />
        <property name="maxIdle" value="8" />
        <property name="maxWait" value="1000" />
        <property name="testOnBorrow" value="true"/>
        <property name="testOnReturn" value="true"/>
        <!-- <property name="testWhileIdle" value="true"/> -->
    </bean>

    <bean id="shardedJedisPool" class="redis.clients.jedis.ShardedJedisPool"  scope="singleton">
        <constructor-arg index="0" ref="jedisPoolConfig" />
        <constructor-arg index="1">
            <list>
                <bean class="redis.clients.jedis.JedisShardInfo">
                    <constructor-arg name="host" value="localhost" />
                    <constructor-arg name="port" value="6379" />
                    <constructor-arg name="timeout" value="0" />
                    <constructor-arg name="weight" value="1" />
                </bean>
            </list>
        </constructor-arg>
    </bean>

</beans>

  3、redis使用相关接口方法

  

  RedisDataSource.java

package com.zhongwu.redis.dao;

import redis.clients.jedis.ShardedJedis;

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

  RedisClientTemplate.java

package com.zhongwu.redis.dao.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.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Repository;

import com.zhongwu.redis.dao.RedisDataSource;

import redis.clients.jedis.BinaryClient.LIST_POSITION;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisShardInfo;
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPipeline;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.Tuple;
@Repository("redisClientTemplate")
public class RedisClientTemplate {

        private static final Logger log = LoggerFactory.getLogger(RedisClientTemplate.class);

        @Autowired
        private RedisDataSource     redisDataSource;

        public void disconnect() {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            shardedJedis.disconnect();
        }

        /**
         * 通过配置获取redis连接
         *
         * return
         * */
        public static RedisClientTemplate getRedis(){
            ApplicationContext ac =  new ClassPathXmlApplicationContext("classpath:/META-INF/spring/applicationContext2.xml");
            RedisClientTemplate redisClient = (RedisClientTemplate)ac.getBean("redisClientTemplate");
            return redisClient;
        }

        /**
         * 设置单个值
         *
         * @param key
         * @param value
         * @return
         */
        public String set(String key, String value) {
            String result = null;

            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.set(key, value);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        /**
         * 获取单个值
         *
         * @param key
         * @return
         */
        public String get(String key) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }

            boolean broken = false;
            try {
                result = shardedJedis.get(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Boolean exists(String key) {
            Boolean result = false;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.exists(key);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String type(String key) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.type(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        /**
         * 在某段时间后实现
         *
         * @param key
         * @param unixTime
         * @return
         */
        public Long expire(String key, int seconds) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.expire(key, seconds);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        /**
         * 在某个时间点失效
         *
         * @param key
         * @param unixTime
         * @return
         */
        public Long expireAt(String key, long unixTime) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.expireAt(key, unixTime);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long ttl(String key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.ttl(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public boolean setbit(String key, long offset, boolean value) {

            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            boolean result = false;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.setbit(key, offset, value);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public boolean getbit(String key, long offset) {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            boolean result = false;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;

            try {
                result = shardedJedis.getbit(key, offset);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public long setrange(String key, long offset, String value) {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            long result = 0;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.setrange(key, offset, value);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String getrange(String key, long startOffset, long endOffset) {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            String result = null;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.getrange(key, startOffset, endOffset);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String getSet(String key, String value) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.getSet(key, value);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long setnx(String key, String value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.setnx(key, value);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String setex(String key, int seconds, String value) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.setex(key, seconds, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long decrBy(String key, long integer) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.decrBy(key, integer);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long decr(String key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.decr(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long incrBy(String key, long integer) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.incrBy(key, integer);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long incr(String key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.incr(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long append(String key, String value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.append(key, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String substr(String key, int start, int end) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.substr(key, start, end);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long hset(String key, String field, String value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hset(key, field, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String hget(String key, String field) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hget(key, field);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long hsetnx(String key, String field, String value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hsetnx(key, field, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String hmset(String key, Map<String, String> hash) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hmset(key, hash);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public List<String> hmget(String key, String... fields) {
            List<String> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hmget(key, fields);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long hincrBy(String key, String field, long value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hincrBy(key, field, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Boolean hexists(String key, String field) {
            Boolean result = false;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hexists(key, field);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long del(String key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.del(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long hdel(String key, String field) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hdel(key, field);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long hlen(String key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hlen(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<String> hkeys(String key) {
            Set<String> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hkeys(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public List<String> hvals(String key) {
            List<String> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hvals(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Map<String, String> hgetAll(String key) {
            Map<String, String> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.hgetAll(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        // ================list ====== l表示 list或 left, r表示right====================
        public Long rpush(String key, String string) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.rpush(key, string);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long lpush(String key, String string) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.lpush(key, string);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long llen(String key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.llen(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public List<String> lrange(String key, long start, long end) {
            List<String> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.lrange(key, start, end);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String ltrim(String key, long start, long end) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.ltrim(key, start, end);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String lindex(String key, long index) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.lindex(key, index);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String lset(String key, long index, String value) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.lset(key, index, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long lrem(String key, long count, String value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.lrem(key, count, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String lpop(String key) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.lpop(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String rpop(String key) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.rpop(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        //return 1 add a not exist value ,
        //return 0 add a exist value
        public Long sadd(String key, String member) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.sadd(key, member);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<String> smembers(String key) {
            Set<String> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.smembers(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long srem(String key, String member) {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();

            Long result = null;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.srem(key, member);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String spop(String key) {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            String result = null;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.spop(key);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long scard(String key) {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            Long result = null;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.scard(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Boolean sismember(String key, String member) {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            Boolean result = null;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.sismember(key, member);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String srandmember(String key) {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            String result = null;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.srandmember(key);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long zadd(String key, double score, String member) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.zadd(key, score, member);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<String> zrange(String key, int start, int end) {
            Set<String> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.zrange(key, start, end);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long zrem(String key, String member) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.zrem(key, member);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Double zincrby(String key, double score, String member) {
            Double result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zincrby(key, score, member);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long zrank(String key, String member) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrank(key, member);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long zrevrank(String key, String member) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrevrank(key, member);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<String> zrevrange(String key, int start, int end) {
            Set<String> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrevrange(key, start, end);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<Tuple> zrangeWithScores(String key, int start, int end) {
            Set<Tuple> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrangeWithScores(key, start, end);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<Tuple> zrevrangeWithScores(String key, int start, int end) {
            Set<Tuple> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrevrangeWithScores(key, start, end);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long zcard(String key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zcard(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Double zscore(String key, String member) {
            Double result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zscore(key, member);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public List<String> sort(String key) {
            List<String> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.sort(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public List<String> sort(String key, SortingParams sortingParameters) {
            List<String> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.sort(key, sortingParameters);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long zcount(String key, double min, double max) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zcount(key, min, max);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<String> zrangeByScore(String key, double min, double max) {
            Set<String> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrangeByScore(key, min, max);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<String> zrevrangeByScore(String key, double max, double min) {
            Set<String> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrevrangeByScore(key, max, min);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<String> zrangeByScore(String key, double min, double max, int offset, int count) {
            Set<String> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrangeByScore(key, min, max, offset, count);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<String> zrevrangeByScore(String key, double max, double min, int offset, int count) {
            Set<String> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrevrangeByScore(key, max, min, offset, count);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max) {
            Set<Tuple> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrangeByScoreWithScores(key, min, max);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min) {
            Set<Tuple> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrevrangeByScoreWithScores(key, max, min);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max, int offset, int count) {
            Set<Tuple> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrangeByScoreWithScores(key, min, max, offset, count);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count) {
            Set<Tuple> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrevrangeByScoreWithScores(key, max, min, offset, count);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long zremrangeByRank(String key, int start, int end) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zremrangeByRank(key, start, end);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long zremrangeByScore(String key, double start, double end) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zremrangeByScore(key, start, end);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long linsert(String key, LIST_POSITION where, String pivot, String value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.linsert(key, where, pivot, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String set(byte[] key, byte[] value) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.set(key, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public byte[] get(byte[] key) {
            byte[] result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.get(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Boolean exists(byte[] key) {
            Boolean result = false;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.exists(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String type(byte[] key) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.type(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long expire(byte[] key, int seconds) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.expire(key, seconds);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long expireAt(byte[] key, long unixTime) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.expireAt(key, unixTime);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long ttl(byte[] key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.ttl(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public byte[] getSet(byte[] key, byte[] value) {
            byte[] result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.getSet(key, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long setnx(byte[] key, byte[] value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.setnx(key, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String setex(byte[] key, int seconds, byte[] value) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.setex(key, seconds, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long decrBy(byte[] key, long integer) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.decrBy(key, integer);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long decr(byte[] key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.decr(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long incrBy(byte[] key, long integer) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.incrBy(key, integer);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long incr(byte[] key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.incr(key);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long append(byte[] key, byte[] value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.append(key, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public byte[] substr(byte[] key, int start, int end) {
            byte[] result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.substr(key, start, end);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long hset(byte[] key, byte[] field, byte[] value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.hset(key, field, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public byte[] hget(byte[] key, byte[] field) {
            byte[] result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.hget(key, field);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long hsetnx(byte[] key, byte[] field, byte[] value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.hsetnx(key, field, value);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String hmset(byte[] key, Map<byte[], byte[]> hash) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.hmset(key, hash);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public List<byte[]> hmget(byte[] key, byte[]... fields) {
            List<byte[]> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.hmget(key, fields);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long hincrBy(byte[] key, byte[] field, long value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.hincrBy(key, field, value);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Boolean hexists(byte[] key, byte[] field) {
            Boolean result = false;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.hexists(key, field);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long hdel(byte[] key, byte[] field) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.hdel(key, field);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long hlen(byte[] key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.hlen(key);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<byte[]> hkeys(byte[] key) {
            Set<byte[]> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.hkeys(key);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Collection<byte[]> hvals(byte[] key) {
            Collection<byte[]> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.hvals(key);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Map<byte[], byte[]> hgetAll(byte[] key) {
            Map<byte[], byte[]> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.hgetAll(key);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long rpush(byte[] key, byte[] string) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.rpush(key, string);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long lpush(byte[] key, byte[] string) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.lpush(key, string);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long llen(byte[] key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.llen(key);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public List<byte[]> lrange(byte[] key, int start, int end) {
            List<byte[]> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.lrange(key, start, end);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String ltrim(byte[] key, int start, int end) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.ltrim(key, start, end);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public byte[] lindex(byte[] key, int index) {
            byte[] result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.lindex(key, index);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String lset(byte[] key, int index, byte[] value) {
            String result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.lset(key, index, value);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long lrem(byte[] key, int count, byte[] value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.lrem(key, count, value);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public byte[] lpop(byte[] key) {
            byte[] result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.lpop(key);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public byte[] rpop(byte[] key) {
            byte[] result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.rpop(key);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long sadd(byte[] key, byte[] member) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.sadd(key, member);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<byte[]> smembers(byte[] key) {
            Set<byte[]> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.smembers(key);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long srem(byte[] key, byte[] member) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.srem(key, member);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public byte[] spop(byte[] key) {
            byte[] result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.spop(key);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long scard(byte[] key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.scard(key);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Boolean sismember(byte[] key, byte[] member) {
            Boolean result = false;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.sismember(key, member);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public byte[] srandmember(byte[] key) {
            byte[] result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.srandmember(key);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long zadd(byte[] key, double score, byte[] member) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zadd(key, score, member);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<byte[]> zrange(byte[] key, int start, int end) {
            Set<byte[]> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrange(key, start, end);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long zrem(byte[] key, byte[] member) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrem(key, member);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Double zincrby(byte[] key, double score, byte[] member) {
            Double result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zincrby(key, score, member);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long zrank(byte[] key, byte[] member) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrank(key, member);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long zrevrank(byte[] key, byte[] member) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrevrank(key, member);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<byte[]> zrevrange(byte[] key, int start, int end) {
            Set<byte[]> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrevrange(key, start, end);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<Tuple> zrangeWithScores(byte[] key, int start, int end) {
            Set<Tuple> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrangeWithScores(key, start, end);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<Tuple> zrevrangeWithScores(byte[] key, int start, int end) {
            Set<Tuple> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrevrangeWithScores(key, start, end);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long zcard(byte[] key) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zcard(key);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Double zscore(byte[] key, byte[] member) {
            Double result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zscore(key, member);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public List<byte[]> sort(byte[] key) {
            List<byte[]> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.sort(key);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public List<byte[]> sort(byte[] key, SortingParams sortingParameters) {
            List<byte[]> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.sort(key, sortingParameters);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long zcount(byte[] key, double min, double max) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zcount(key, min, max);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<byte[]> zrangeByScore(byte[] key, double min, double max) {
            Set<byte[]> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrangeByScore(key, min, max);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<byte[]> zrangeByScore(byte[] key, double min, double max, int offset, int count) {
            Set<byte[]> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrangeByScore(key, min, max, offset, count);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max) {
            Set<Tuple> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrangeByScoreWithScores(key, min, max);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max, int offset, int count) {
            Set<Tuple> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrangeByScoreWithScores(key, min, max, offset, count);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min) {
            Set<byte[]> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrevrangeByScore(key, max, min);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min, int offset, int count) {
            Set<byte[]> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrevrangeByScore(key, max, min, offset, count);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min) {
            Set<Tuple> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrevrangeByScoreWithScores(key, max, min);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count) {
            Set<Tuple> result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zrevrangeByScoreWithScores(key, max, min, offset, count);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long zremrangeByRank(byte[] key, int start, int end) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zremrangeByRank(key, start, end);

            } catch (Exception e) {

                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long zremrangeByScore(byte[] key, double start, double end) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.zremrangeByScore(key, start, end);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value) {
            Long result = null;
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {

                result = shardedJedis.linsert(key, where, pivot, value);

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public List<Object> pipelined(ShardedJedisPipeline shardedJedisPipeline) {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            List<Object> result = null;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.pipelined(shardedJedisPipeline);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Jedis getShard(byte[] key) {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            Jedis result = null;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.getShard(key);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Jedis getShard(String key) {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            Jedis result = null;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.getShard(key);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public JedisShardInfo getShardInfo(byte[] key) {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            JedisShardInfo result = null;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.getShardInfo(key);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public JedisShardInfo getShardInfo(String key) {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            JedisShardInfo result = null;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.getShardInfo(key);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public String getKeyTag(String key) {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            String result = null;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.getKeyTag(key);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Collection<JedisShardInfo> getAllShardInfo() {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            Collection<JedisShardInfo> result = null;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.getAllShardInfo();

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

        public Collection<Jedis> getAllShards() {
            ShardedJedis shardedJedis = redisDataSource.getRedisClient();
            Collection<Jedis> result = null;
            if (shardedJedis == null) {
                return result;
            }
            boolean broken = false;
            try {
                result = shardedJedis.getAllShards();

            } catch (Exception e) {
                log.error(e.getMessage(), e);
                broken = true;
            } finally {
                redisDataSource.returnResource(shardedJedis, broken);
            }
            return result;
        }

}

RedisClientTemplate.java

  RedisDataSourceImpl.java

package com.zhongwu.redis.dao.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.zhongwu.redis.dao.RedisDataSource;

import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPool;
@Repository("redisDataSource")
public class RedisDataSourceImpl implements RedisDataSource {

     private static final Logger log = LoggerFactory.getLogger(RedisDataSourceImpl.class);

        @Autowired
        private ShardedJedisPool    shardedJedisPool;

        public ShardedJedis getRedisClient() {
            try {
                ShardedJedis shardJedis = shardedJedisPool.getResource();
                return shardJedis;
            } catch (Exception e) {
                log.error("getRedisClent error", e);
            }
            return null;
        }

        public void returnResource(ShardedJedis shardedJedis) {
            shardedJedisPool.returnResource(shardedJedis);
        }

        public void returnResource(ShardedJedis shardedJedis, boolean broken) {
            if (broken) {
                shardedJedisPool.returnBrokenResource(shardedJedis);
            } else {
                shardedJedisPool.returnResource(shardedJedis);
            }
        }

}

  工具类SerializeUtil.java,用于将对象信息序列化存储进redis中

package com.zhongwu.graduation.util;

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

public class SerializeUtil {
    public static byte[] serialize(Object object) {
        ObjectOutputStream oos = null;
        ByteArrayOutputStream baos = null;
        try {
        //序列化
        baos = new ByteArrayOutputStream();
        oos = new ObjectOutputStream(baos);
        oos.writeObject(object);
        byte[] bytes = baos.toByteArray();
        return bytes;
        } catch (Exception e) {

        }
        return null;
        }

        public static Object unserialize(byte[] bytes) {
        ByteArrayInputStream bais = null;
        try {
        //反序列化
        bais = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(bais);
        return ois.readObject();
        } catch (Exception e) {

        }
        return null;
        }
}

ps:redis配置完成

二、redis的使用

  1、java调用

@Test
    public void test2(){
         System.out.println("#################################################################");
         /*RedisClientTemplate redisClient=new RedisClientTemplate();*/
         RedisClientTemplate redisClient = RedisClientTemplate.getRedis();      //存储字符串
           redisClient.set("a", "abc");      //存储map
           Map<String,String> bb = new HashMap<String,String>();
           bb.put("1", "1");
           bb.put("2", "2");
           bb.put("3", "3");
           redisClient.hmset("bb", bb);
           System.out.println(redisClient.get("a"));
           for(String value:redisClient.hvals("bb")){
               System.out.println(value);
           }
           System.out.println(redisClient.hget("bb", "3"));
                 //存储对象
           PlatUser user = new PlatUser();
           user.setUserId("2333");
           user.setLoginName("1111");      //需要对对象序列化之后进行存储
           redisClient.set("user".getBytes(), SerializeUtil.serialize(user));
           PlatUser user2 = (PlatUser)SerializeUtil.unserialize(redisClient.get("user".getBytes()));
           System.out.println(user2.getLoginName());

    }

  2、窗口查看

  keys * :查看redis中全部的键

  

  测试运行前

  

  测试运行后

  

  

时间: 2024-10-12 11:53:59

redis的配置及使用的相关文章

nginx+lua+redis(openresty)配置

nginx+lua+redis(openresty)配置 2014-07-18 11:10 2494人阅读 评论(1) 收藏 举报 方案一: 1.安装lua解释器 wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz (http://luajit.org/download.html) 配置lua Lib和include/luajit-$version目录为环境变量 2.下载ngx_devel_kit和lua-nginx-module https:

Linux下Redis服务器安装配置

说明:操作系统:CentOS1.安装编译工具yum install wget  make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel kernel keyutils  patch perl 2.安装tcl组件包(安装Redis需要tcl支持)cd /usr/local/src #进入软件包存放目录wget  http://downloads.sourceforge.net/tcl/tcl8.6.6-src.tar.gztar 

redis安装配置和使用;tomcat安装和使用

virtualbox主要有下面几种方式(不同版本称法不一样,但实质是一样的): 1.Intelnal Network:利用主机上的所有的虚拟机构建一个虚拟网络 2.NAT:能访问互联网,不能访问主机(或局域网)//通过这个下gcc 3.Host Interface:能访问主机(或局域网),不能访问互联网 修改过后 netstat restart 先确保Linux已安装gcc zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or

Redis主从配置

前言 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API. redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sortedset --有序集合)和hash(哈希类型).这些数据类型都支持push/pop.add/remove及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的.在

Redis 主从配置和参数详解

安装redis 下载redis wget http://download.redis.io/releases/redis-3.0.7.tar.gz 解压redis tar -xvf redis-3.0.7.tar.gz 安装redis cd redis-3.0.7 “有可能需要安装gcc插件:yum install -y gcc ” make “如果make有报错,则执行,没有报错就不需要 make MALLOC=libc ” redis.conf相关参数 1. Redis默认不是以守护进程的方

CentOS下Redis服务器安装配置

http://www.centoscn.com/image-text/config/2014/0712/3285.html 1.安装编译工具 yum install wget  make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel kernel keyutils  patch perl 2.安装tcl组件包(安装Redis需要tcl支持) 下载:http://downloads.sourceforge.net/tcl/tcl8.

Redis——学习之路三(初识redis config配置)

我们先看看config 默认情况下系统是怎么配置的.在命令行中输入 config get *(如图) 默认情况下有61配置信息,每一个命令占两行,第一行为配置名称信息,第二行为配置的具体信息. 我们就从上到下来理解一下这些配置信息中的某些配置: 1.dbfilename是本地持久化存储数据库文件名,默认为dump.rdb.我可以在安装目录文件夹下找到这个文件. 2.requirepass是密码,即连接服务器的密码,默认为空.下面我来设置一个密码然后用带密码的命令连接一遍. 3.msterauth

高性能网站架构设计之缓存篇(3)- Redis的配置

我们说Redis是一个强大的Key-Value存储系统,在前面我们已遇到了两个问题: 1.redis server 启动后,独占进程,能不能修改为后台服务呢? 2.redis server 服务是单线程的,而我的机器是多核的,能不能在同一台机器上开启多个实例更充分的利用 cpu 资源呢?但6379端口已经被前一个实例绑定,肯定会有冲突,那能不能修改默认端口呢? 答案是肯定的,redis 提供了灵活的配置方式,一种可以通过配置文件来配置,另一种你可以在运行时通过 config set 命令来修改配

redis 安装配置学习笔记

redis 安装配置学习笔记 //wget http://download.redis.io/releases/redis-2.8.17.tar.gz 下载最新版本 wget http://download.redis.io/redis-stable.tar.gz 首先必须要有 gcc 与 make apt-get install gcc apt-get install make 1.解压 [email protected]:~# tar -xvf redis-stable.tar.gz 2.测

【转】 Tomcat+redis+nginx配置

为客户开发的一个绩效系统,采用了java web的开发方式,使用了一些spring mvc, mybatis之类的框架.相比于oracle ebs的二次开发,这种开发更加灵活,虽然和ebs集成的时候遇到一些问题,但是最后也都解决了. 在部署的时候,客户要求要能同事承受一两千人在线,相对于客户公司的总人数(七八万人),应该足够了.ebs的二次都是直接部署在oracle ebs的application server上面,之前也没怎么关注过程序的部署.这次采用tomcat部署,考虑到单个tomcat的