redis通用工具类

6 篇文章 0 订阅
  1. 转自:http://blog.csdn.net/qq7342272/article/details/49299787
  2. public class RedisUtil {  
  3.     private static final Logger LOGGER = Logger.getLogger(RedisUtil.class);  
  4.     private static JedisPool pool = null;  
  5.   
  6.     private static RedisUtil ru = new RedisUtil();  
  7.      
  8.     private RedisUtil() {  
  9.         if (pool == null) {  
  10.             String ip = InitListener.getValue("redis.ip""192.168.116.207");  
  11.             int port = Integer.parseInt(InitListener.getValue("redis.port""5379"));  
  12.             JedisPoolConfig config = new JedisPoolConfig();  
  13.             // 控制一个pool可分配多少个jedis实例,通过pool.getResource()来获取;  
  14.             // 如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)。  
  15.             config.setMaxTotal(10000);  
  16.             // 控制一个pool最多有多少个状态为idle(空闲的)的jedis实例。  
  17.             config.setMaxIdle(2000);  
  18.             // 表示当borrow(引入)一个jedis实例时,最大的等待时间,如果超过等待时间,则直接抛出JedisConnectionException;  
  19.             config.setMaxWaitMillis(1000 * 100);  
  20.             config.setTestOnBorrow(true);  
  21.             pool = new JedisPool(config, ip, port, 100000);  
  22.         }  
  23.           
  24.     }  
  25.   
  26.     /** 
  27.      * <p>通过key获取储存在redis中的value</p> 
  28.      * <p>并释放连接</p> 
  29.      * @param key 
  30.      * @return 成功返回value 失败返回null 
  31.      */  
  32.     public String get(String key){  
  33.         Jedis jedis = null;  
  34.         String value = null;  
  35.         try {  
  36.             jedis = pool.getResource();  
  37.             value = jedis.get(key);  
  38.         } catch (Exception e) {  
  39.               
  40.             LOGGER.error(e.getMessage());  
  41.         } finally {  
  42.             returnResource(pool, jedis);  
  43.         }  
  44.         return value;  
  45.     }  
  46.   
  47.     /** 
  48.      * <p>向redis存入key和value,并释放连接资源</p> 
  49.      * <p>如果key已经存在 则覆盖</p> 
  50.      * @param key 
  51.      * @param value 
  52.      * @return 成功 返回OK 失败返回 0 
  53.      */  
  54.     public String set(String key,String value){  
  55.         Jedis jedis = null;  
  56.         try {  
  57.             jedis = pool.getResource();  
  58.             return jedis.set(key, value);  
  59.         } catch (Exception e) {  
  60.               
  61.             LOGGER.error(e.getMessage());  
  62.             return "0";  
  63.         } finally {  
  64.             returnResource(pool, jedis);  
  65.         }  
  66.     }  
  67.   
  68.   
  69.     /** 
  70.      * <p>删除指定的key,也可以传入一个包含key的数组</p> 
  71.      * @param keys 一个key  也可以使 string 数组 
  72.      * @return 返回删除成功的个数 
  73.      */  
  74.     public Long del(String...keys){  
  75.         Jedis jedis = null;  
  76.         try {  
  77.             jedis = pool.getResource();  
  78.             return jedis.del(keys);  
  79.         } catch (Exception e) {  
  80.               
  81.             LOGGER.error(e.getMessage());  
  82.             return 0L;  
  83.         } finally {  
  84.             returnResource(pool, jedis);  
  85.         }  
  86.     }  
  87.   
  88.     /** 
  89.      * <p>通过key向指定的value值追加值</p> 
  90.      * @param key 
  91.      * @param str 
  92.      * @return 成功返回 添加后value的长度 失败 返回 添加的 value 的长度  异常返回0L 
  93.      */  
  94.     public Long append(String key ,String str){  
  95.         Jedis jedis = null;  
  96.         Long res = null;  
  97.         try {  
  98.             jedis = pool.getResource();  
  99.             res = jedis.append(key, str);  
  100.         } catch (Exception e) {  
  101.               
  102.             LOGGER.error(e.getMessage());  
  103.             return 0L;  
  104.         } finally {  
  105.             returnResource(pool, jedis);  
  106.         }  
  107.         return res;  
  108.     }  
  109.   
  110.     /** 
  111.      * <p>判断key是否存在</p> 
  112.      * @param key 
  113.      * @return true OR false 
  114.      */  
  115.     public Boolean exists(String key){  
  116.         Jedis jedis = null;  
  117.         try {  
  118.             jedis = pool.getResource();  
  119.             return jedis.exists(key);  
  120.         } catch (Exception e) {  
  121.               
  122.             LOGGER.error(e.getMessage());  
  123.             return false;  
  124.         } finally {  
  125.             returnResource(pool, jedis);  
  126.         }  
  127.     }  
  128.   
  129.     /** 
  130.      * <p>设置key value,如果key已经存在则返回0,nx==> not exist</p> 
  131.      * @param key 
  132.      * @param value 
  133.      * @return 成功返回1 如果存在 和 发生异常 返回 0 
  134.      */  
  135.     public Long setnx(String key ,String value){  
  136.         Jedis jedis = null;  
  137.         try {  
  138.             jedis = pool.getResource();  
  139.             return jedis.setnx(key, value);  
  140.         } catch (Exception e) {  
  141.               
  142.             LOGGER.error(e.getMessage());  
  143.             return 0L;  
  144.         } finally {  
  145.             returnResource(pool, jedis);  
  146.         }  
  147.     }  
  148.   
  149.     /** 
  150.      * <p>设置key value并制定这个键值的有效期</p> 
  151.      * @param key 
  152.      * @param value 
  153.      * @param seconds 单位:秒 
  154.      * @return 成功返回OK 失败和异常返回null 
  155.      */  
  156.     public String setex(String key,String value,int seconds){  
  157.         Jedis jedis = null;  
  158.         String res = null;  
  159.         try {  
  160.             jedis = pool.getResource();  
  161.             res = jedis.setex(key, seconds, value);  
  162.         } catch (Exception e) {  
  163.               
  164.             LOGGER.error(e.getMessage());  
  165.         } finally {  
  166.             returnResource(pool, jedis);  
  167.         }  
  168.         return res;  
  169.     }  
  170.   
  171.   
  172.     /** 
  173.      * <p>通过key 和offset 从指定的位置开始将原先value替换</p> 
  174.      * <p>下标从0开始,offset表示从offset下标开始替换</p> 
  175.      * <p>如果替换的字符串长度过小则会这样</p> 
  176.      * <p>example:</p> 
  177.      * <p>value : bigsea@zto.cn</p> 
  178.      * <p>str : abc </p> 
  179.      * <P>从下标7开始替换  则结果为</p> 
  180.      * <p>RES : bigsea.abc.cn</p> 
  181.      * @param key 
  182.      * @param str 
  183.      * @param offset 下标位置 
  184.      * @return 返回替换后  value 的长度 
  185.      */  
  186.     public Long setrange(String key,String str,int offset){  
  187.         Jedis jedis = null;  
  188.         try {  
  189.             jedis = pool.getResource();  
  190.             return jedis.setrange(key, offset, str);  
  191.         } catch (Exception e) {  
  192.               
  193.             LOGGER.error(e.getMessage());  
  194.             return 0L;  
  195.         } finally {  
  196.             returnResource(pool, jedis);  
  197.         }  
  198.     }  
  199.   
  200.   
  201.   
  202.     /** 
  203.      * <p>通过批量的key获取批量的value</p> 
  204.      * @param keys string数组 也可以是一个key 
  205.      * @return 成功返回value的集合, 失败返回null的集合 ,异常返回空 
  206.      */  
  207.     public List<String> mget(String...keys){  
  208.         Jedis jedis = null;  
  209.         List<String> values = null;  
  210.         try {  
  211.             jedis = pool.getResource();  
  212.             values = jedis.mget(keys);  
  213.         } catch (Exception e) {  
  214.               
  215.             LOGGER.error(e.getMessage());  
  216.         } finally {  
  217.             returnResource(pool, jedis);  
  218.         }  
  219.         return values;  
  220.     }  
  221.   
  222.     /** 
  223.      * <p>批量的设置key:value,可以一个</p> 
  224.      * <p>example:</p> 
  225.      * <p>  obj.mset(new String[]{"key2","value1","key2","value2"})</p> 
  226.      * @param keysvalues 
  227.      * @return 成功返回OK 失败 异常 返回 null 
  228.      * 
  229.      */  
  230.     public String mset(String...keysvalues){  
  231.         Jedis jedis = null;  
  232.         String res = null;  
  233.         try {  
  234.             jedis = pool.getResource();  
  235.             res = jedis.mset(keysvalues);  
  236.         } catch (Exception e) {  
  237.               
  238.             LOGGER.error(e.getMessage());  
  239.         } finally {  
  240.             returnResource(pool, jedis);  
  241.         }  
  242.         return res;  
  243.     }  
  244.   
  245.     /** 
  246.      * <p>批量的设置key:value,可以一个,如果key已经存在则会失败,操作会回滚</p> 
  247.      * <p>example:</p> 
  248.      * <p>  obj.msetnx(new String[]{"key2","value1","key2","value2"})</p> 
  249.      * @param keysvalues 
  250.      * @return 成功返回1 失败返回0 
  251.      */  
  252.     public Long msetnx(String...keysvalues){  
  253.         Jedis jedis = null;  
  254.         Long res = 0L;  
  255.         try {  
  256.             jedis = pool.getResource();  
  257.             res =jedis.msetnx(keysvalues);  
  258.         } catch (Exception e) {  
  259.               
  260.             LOGGER.error(e.getMessage());  
  261.         } finally {  
  262.             returnResource(pool, jedis);  
  263.         }  
  264.         return res;  
  265.     }  
  266.   
  267.     /** 
  268.      * <p>设置key的值,并返回一个旧值</p> 
  269.      * @param key 
  270.      * @param value 
  271.      * @return 旧值 如果key不存在 则返回null 
  272.      */  
  273.     public String getset(String key,String value){  
  274.         Jedis jedis = null;  
  275.         String res = null;  
  276.         try {  
  277.             jedis = pool.getResource();  
  278.             res = jedis.getSet(key, value);  
  279.         } catch (Exception e) {  
  280.               
  281.             LOGGER.error(e.getMessage());  
  282.         } finally {  
  283.             returnResource(pool, jedis);  
  284.         }  
  285.         return res;  
  286.     }  
  287.   
  288.     /** 
  289.      * <p>通过下标 和key 获取指定下标位置的 value</p> 
  290.      * @param key 
  291.      * @param startOffset 开始位置 从0 开始 负数表示从右边开始截取 
  292.      * @param endOffset 
  293.      * @return 如果没有返回null 
  294.      */  
  295.     public String getrange(String key, int startOffset ,int endOffset){  
  296.         Jedis jedis = null;  
  297.         String res = null;  
  298.         try {  
  299.             jedis = pool.getResource();  
  300.             res = jedis.getrange(key, startOffset, endOffset);  
  301.         } catch (Exception e) {  
  302.               
  303.             LOGGER.error(e.getMessage());  
  304.         } finally {  
  305.             returnResource(pool, jedis);  
  306.         }  
  307.         return res;  
  308.     }  
  309.   
  310.     /** 
  311.      * <p>通过key 对value进行加值+1操作,当value不是int类型时会返回错误,当key不存在是则value为1</p> 
  312.      * @param key 
  313.      * @return 加值后的结果 
  314.      */  
  315.     public Long incr(String key){  
  316.         Jedis jedis = null;  
  317.         Long res = null;  
  318.         try {  
  319.             jedis = pool.getResource();  
  320.             res = jedis.incr(key);  
  321.         } catch (Exception e) {  
  322.               
  323.             LOGGER.error(e.getMessage());  
  324.         } finally {  
  325.             returnResource(pool, jedis);  
  326.         }  
  327.         return res;  
  328.     }  
  329.   
  330.     /** 
  331.      * <p>通过key给指定的value加值,如果key不存在,则这是value为该值</p> 
  332.      * @param key 
  333.      * @param integer 
  334.      * @return 
  335.      */  
  336.     public Long incrBy(String key,Long integer){  
  337.         Jedis jedis = null;  
  338.         Long res = null;  
  339.         try {  
  340.             jedis = pool.getResource();  
  341.             res = jedis.incrBy(key, integer);  
  342.         } catch (Exception e) {  
  343.               
  344.             LOGGER.error(e.getMessage());  
  345.         } finally {  
  346.             returnResource(pool, jedis);  
  347.         }  
  348.         return res;  
  349.     }  
  350.   
  351.     /** 
  352.      * <p>对key的值做减减操作,如果key不存在,则设置key为-1</p> 
  353.      * @param key 
  354.      * @return 
  355.      */  
  356.     public Long decr(String key) {  
  357.         Jedis jedis = null;  
  358.         Long res = null;  
  359.         try {  
  360.             jedis = pool.getResource();  
  361.             res = jedis.decr(key);  
  362.         } catch (Exception e) {  
  363.               
  364.             LOGGER.error(e.getMessage());  
  365.         } finally {  
  366.             returnResource(pool, jedis);  
  367.         }  
  368.         return res;  
  369.     }  
  370.   
  371.     /** 
  372.      * <p>减去指定的值</p> 
  373.      * @param key 
  374.      * @param integer 
  375.      * @return 
  376.      */  
  377.     public Long decrBy(String key,Long integer){  
  378.         Jedis jedis = null;  
  379.         Long res = null;  
  380.         try {  
  381.             jedis = pool.getResource();  
  382.             res = jedis.decrBy(key, integer);  
  383.         } catch (Exception e) {  
  384.               
  385.             LOGGER.error(e.getMessage());  
  386.         } finally {  
  387.             returnResource(pool, jedis);  
  388.         }  
  389.         return res;  
  390.     }  
  391.   
  392.     /** 
  393.      * <p>通过key获取value值的长度</p> 
  394.      * @param key 
  395.      * @return 失败返回null 
  396.      */  
  397.     public Long serlen(String key){  
  398.         Jedis jedis = null;  
  399.         Long res = null;  
  400.         try {  
  401.             jedis = pool.getResource();  
  402.             res = jedis.strlen(key);  
  403.         } catch (Exception e) {  
  404.               
  405.             LOGGER.error(e.getMessage());  
  406.         } finally {  
  407.             returnResource(pool, jedis);  
  408.         }  
  409.         return res;  
  410.     }  
  411.   
  412.     /** 
  413.      * <p>通过key给field设置指定的值,如果key不存在,则先创建</p> 
  414.      * @param key 
  415.      * @param field 字段 
  416.      * @param value 
  417.      * @return 如果存在返回0 异常返回null 
  418.      */  
  419.     public Long hset(String key,String field,String value) {  
  420.         Jedis jedis = null;  
  421.         Long res = null;  
  422.         try {  
  423.             jedis = pool.getResource();  
  424.             res = jedis.hset(key, field, value);  
  425.         } catch (Exception e) {  
  426.               
  427.             LOGGER.error(e.getMessage());  
  428.         } finally {  
  429.             returnResource(pool, jedis);  
  430.         }  
  431.         return res;  
  432.     }  
  433.   
  434.     /** 
  435.      * <p>通过key给field设置指定的值,如果key不存在则先创建,如果field已经存在,返回0</p> 
  436.      * @param key 
  437.      * @param field 
  438.      * @param value 
  439.      * @return 
  440.      */  
  441.     public Long hsetnx(String key,String field,String value){  
  442.         Jedis jedis = null;  
  443.         Long res = null;  
  444.         try {  
  445.             jedis = pool.getResource();  
  446.             res = jedis.hsetnx(key, field, value);  
  447.         } catch (Exception e) {  
  448.               
  449.             LOGGER.error(e.getMessage());  
  450.         } finally {  
  451.             returnResource(pool, jedis);  
  452.         }  
  453.         return res;  
  454.     }  
  455.   
  456.     /** 
  457.      * <p>通过key同时设置 hash的多个field</p> 
  458.      * @param key 
  459.      * @param hash 
  460.      * @return 返回OK 异常返回null 
  461.      */  
  462.     public String hmset(String key,Map<String, String> hash){  
  463.         Jedis jedis = null;  
  464.         String res = null;  
  465.         try {  
  466.             jedis = pool.getResource();  
  467.             res = jedis.hmset(key, hash);  
  468.         } catch (Exception e) {  
  469.               
  470.             LOGGER.error(e.getMessage());  
  471.         } finally {  
  472.             returnResource(pool, jedis);  
  473.         }  
  474.         return res;  
  475.     }  
  476.   
  477.     /** 
  478.      * <p>通过key 和 field 获取指定的 value</p> 
  479.      * @param key 
  480.      * @param field 
  481.      * @return 没有返回null 
  482.      */  
  483.     public String hget(String key, String field){  
  484.         Jedis jedis = null;  
  485.         String res = null;  
  486.         try {  
  487.             jedis = pool.getResource();  
  488.             res = jedis.hget(key, field);  
  489.         } catch (Exception e) {  
  490.               
  491.             LOGGER.error(e.getMessage());  
  492.         } finally {  
  493.             returnResource(pool, jedis);  
  494.         }  
  495.         return res;  
  496.     }  
  497.   
  498.     /** 
  499.      * <p>通过key 和 fields 获取指定的value 如果没有对应的value则返回null</p> 
  500.      * @param key 
  501.      * @param fields 可以使 一个String 也可以是 String数组 
  502.      * @return 
  503.      */  
  504.     public List<String> hmget(String key,String...fields){  
  505.         Jedis jedis = null;  
  506.         List<String> res = null;  
  507.         try {  
  508.             jedis = pool.getResource();  
  509.             res = jedis.hmget(key, fields);  
  510.         } catch (Exception e) {  
  511.               
  512.             LOGGER.error(e.getMessage());  
  513.         } finally {  
  514.             returnResource(pool, jedis);  
  515.         }  
  516.         return res;  
  517.     }  
  518.   
  519.     /** 
  520.      * <p>通过key给指定的field的value加上给定的值</p> 
  521.      * @param key 
  522.      * @param field 
  523.      * @param value 
  524.      * @return 
  525.      */  
  526.     public Long hincrby(String key ,String field ,Long value){  
  527.         Jedis jedis = null;  
  528.         Long res = null;  
  529.         try {  
  530.             jedis = pool.getResource();  
  531.             res = jedis.hincrBy(key, field, value);  
  532.         } catch (Exception e) {  
  533.               
  534.             LOGGER.error(e.getMessage());  
  535.         } finally {  
  536.             returnResource(pool, jedis);  
  537.         }  
  538.         return res;  
  539.     }  
  540.   
  541.     /** 
  542.      * <p>通过key和field判断是否有指定的value存在</p> 
  543.      * @param key 
  544.      * @param field 
  545.      * @return 
  546.      */  
  547.     public Boolean hexists(String key , String field){  
  548.         Jedis jedis = null;  
  549.         Boolean res = false;  
  550.         try {  
  551.             jedis = pool.getResource();  
  552.             res = jedis.hexists(key, field);  
  553.         } catch (Exception e) {  
  554.               
  555.             LOGGER.error(e.getMessage());  
  556.         } finally {  
  557.             returnResource(pool, jedis);  
  558.         }  
  559.         return res;  
  560.     }  
  561.   
  562.     /** 
  563.      * <p>通过key返回field的数量</p> 
  564.      * @param key 
  565.      * @return 
  566.      */  
  567.     public Long hlen(String key){  
  568.         Jedis jedis = null;  
  569.         Long res = null;  
  570.         try {  
  571.             jedis = pool.getResource();  
  572.             res = jedis.hlen(key);  
  573.         } catch (Exception e) {  
  574.               
  575.             LOGGER.error(e.getMessage());  
  576.         } finally {  
  577.             returnResource(pool, jedis);  
  578.         }  
  579.         return res;  
  580.   
  581.     }  
  582.   
  583.     /** 
  584.      * <p>通过key 删除指定的 field </p> 
  585.      * @param key 
  586.      * @param fields 可以是 一个 field 也可以是 一个数组 
  587.      * @return 
  588.      */  
  589.     public Long hdel(String key ,String...fields){  
  590.         Jedis jedis = null;  
  591.         Long res = null;  
  592.         try {  
  593.             jedis = pool.getResource();  
  594.             res = jedis.hdel(key, fields);  
  595.         } catch (Exception e) {  
  596.               
  597.             LOGGER.error(e.getMessage());  
  598.         } finally {  
  599.             returnResource(pool, jedis);  
  600.         }  
  601.         return res;  
  602.     }  
  603.   
  604.     /** 
  605.      * <p>通过key返回所有的field</p> 
  606.      * @param key 
  607.      * @return 
  608.      */  
  609.     public Set<String> hkeys(String key){  
  610.         Jedis jedis = null;  
  611.         Set<String> res = null;  
  612.         try {  
  613.             jedis = pool.getResource();  
  614.             res = jedis.hkeys(key);  
  615.         } catch (Exception e) {  
  616.               
  617.             LOGGER.error(e.getMessage());  
  618.         } finally {  
  619.             returnResource(pool, jedis);  
  620.         }  
  621.         return res;  
  622.     }  
  623.   
  624.     /** 
  625.      * <p>通过key返回所有和key有关的value</p> 
  626.      * @param key 
  627.      * @return 
  628.      */  
  629.     public List<String> hvals(String key){  
  630.         Jedis jedis = null;  
  631.         List<String> res = null;  
  632.         try {  
  633.             jedis = pool.getResource();  
  634.             res = jedis.hvals(key);  
  635.         } catch (Exception e) {  
  636.               
  637.             LOGGER.error(e.getMessage());  
  638.         } finally {  
  639.             returnResource(pool, jedis);  
  640.         }  
  641.         return res;  
  642.     }  
  643.   
  644.     /** 
  645.      * <p>通过key获取所有的field和value</p> 
  646.      * @param key 
  647.      * @return 
  648.      */  
  649.     public Map<String, String> hgetall(String key){  
  650.         Jedis jedis = null;  
  651.         Map<String, String> res = null;  
  652.         try {  
  653.             jedis = pool.getResource();  
  654.             res = jedis.hgetAll(key);  
  655.         } catch (Exception e) {  
  656.             // TODO  
  657.         } finally {  
  658.             returnResource(pool, jedis);  
  659.         }  
  660.         return res;  
  661.     }  
  662.   
  663.     /** 
  664.      * <p>通过key向list头部添加字符串</p> 
  665.      * @param key 
  666.      * @param strs 可以使一个string 也可以使string数组 
  667.      * @return 返回list的value个数 
  668.      */  
  669.     public Long lpush(String key ,String...strs){  
  670.         Jedis jedis = null;  
  671.         Long res = null;  
  672.         try {  
  673.             jedis = pool.getResource();  
  674.             res = jedis.lpush(key, strs);  
  675.         } catch (Exception e) {  
  676.               
  677.             LOGGER.error(e.getMessage());  
  678.         } finally {  
  679.             returnResource(pool, jedis);  
  680.         }  
  681.         return res;  
  682.     }  
  683.   
  684.     /** 
  685.      * <p>通过key向list尾部添加字符串</p> 
  686.      * @param key 
  687.      * @param strs 可以使一个string 也可以使string数组 
  688.      * @return 返回list的value个数 
  689.      */  
  690.     public Long rpush(String key ,String...strs){  
  691.         Jedis jedis = null;  
  692.         Long res = null;  
  693.         try {  
  694.             jedis = pool.getResource();  
  695.             res = jedis.rpush(key, strs);  
  696.         } catch (Exception e) {  
  697.               
  698.             LOGGER.error(e.getMessage());  
  699.         } finally {  
  700.             returnResource(pool, jedis);  
  701.         }  
  702.         return res;  
  703.     }  
  704.   
  705.     /** 
  706.      * <p>通过key在list指定的位置之前或者之后 添加字符串元素</p> 
  707.      * @param key 
  708.      * @param where LIST_POSITION枚举类型 
  709.      * @param pivot list里面的value 
  710.      * @param value 添加的value 
  711.      * @return 
  712.      */  
  713.     public Long linsert(String key, LIST_POSITION where,  
  714.                         String pivot, String value){  
  715.         Jedis jedis = null;  
  716.         Long res = null;  
  717.         try {  
  718.             jedis = pool.getResource();  
  719.             res = jedis.linsert(key, where, pivot, value);  
  720.         } catch (Exception e) {  
  721.               
  722.             LOGGER.error(e.getMessage());  
  723.         } finally {  
  724.             returnResource(pool, jedis);  
  725.         }  
  726.         return res;  
  727.     }  
  728.   
  729.     /** 
  730.      * <p>通过key设置list指定下标位置的value</p> 
  731.      * <p>如果下标超过list里面value的个数则报错</p> 
  732.      * @param key 
  733.      * @param index 从0开始 
  734.      * @param value 
  735.      * @return 成功返回OK 
  736.      */  
  737.     public String lset(String key ,Long index, String value){  
  738.         Jedis jedis = null;  
  739.         String res = null;  
  740.         try {  
  741.             jedis = pool.getResource();  
  742.             res = jedis.lset(key, index, value);  
  743.         } catch (Exception e) {  
  744.               
  745.             LOGGER.error(e.getMessage());  
  746.         } finally {  
  747.             returnResource(pool, jedis);  
  748.         }  
  749.         return res;  
  750.     }  
  751.   
  752.     /** 
  753.      * <p>通过key从对应的list中删除指定的count个 和 value相同的元素</p> 
  754.      * @param key 
  755.      * @param count 当count为0时删除全部 
  756.      * @param value 
  757.      * @return 返回被删除的个数 
  758.      */  
  759.     public Long lrem(String key,long count,String value){  
  760.         Jedis jedis = null;  
  761.         Long res = null;  
  762.         try {  
  763.             jedis = pool.getResource();  
  764.             res = jedis.lrem(key, count, value);  
  765.         } catch (Exception e) {  
  766.               
  767.             LOGGER.error(e.getMessage());  
  768.         } finally {  
  769.             returnResource(pool, jedis);  
  770.         }  
  771.         return res;  
  772.     }  
  773.   
  774.     /** 
  775.      * <p>通过key保留list中从strat下标开始到end下标结束的value值</p> 
  776.      * @param key 
  777.      * @param start 
  778.      * @param end 
  779.      * @return 成功返回OK 
  780.      */  
  781.     public String ltrim(String key ,long start ,long end){  
  782.         Jedis jedis = null;  
  783.         String res = null;  
  784.         try {  
  785.             jedis = pool.getResource();  
  786.             res = jedis.ltrim(key, start, end);  
  787.         } catch (Exception e) {  
  788.               
  789.             LOGGER.error(e.getMessage());  
  790.         } finally {  
  791.             returnResource(pool, jedis);  
  792.         }  
  793.         return res;  
  794.     }  
  795.   
  796.     /** 
  797.      * <p>通过key从list的头部删除一个value,并返回该value</p> 
  798.      * @param key 
  799.      * @return 
  800.      */  
  801.     synchronized public String lpop(String key){  
  802.         Jedis jedis = null;  
  803.         String res = null;  
  804.         try {  
  805.             jedis = pool.getResource();  
  806.             res = jedis.lpop(key);  
  807.         } catch (Exception e) {  
  808.               
  809.             LOGGER.error(e.getMessage());  
  810.         } finally {  
  811.             returnResource(pool, jedis);  
  812.         }  
  813.         return res;  
  814.     }  
  815.   
  816.     /** 
  817.      * <p>通过key从list尾部删除一个value,并返回该元素</p> 
  818.      * @param key 
  819.      * @return 
  820.      */  
  821.     synchronized public String rpop(String key){  
  822.         Jedis jedis = null;  
  823.         String res = null;  
  824.         try {  
  825.             jedis = pool.getResource();  
  826.             res = jedis.rpop(key);  
  827.         } catch (Exception e) {  
  828.               
  829.             LOGGER.error(e.getMessage());  
  830.         } finally {  
  831.             returnResource(pool, jedis);  
  832.         }  
  833.         return res;  
  834.     }  
  835.   
  836.     /** 
  837.      * <p>通过key从一个list的尾部删除一个value并添加到另一个list的头部,并返回该value</p> 
  838.      * <p>如果第一个list为空或者不存在则返回null</p> 
  839.      * @param srckey 
  840.      * @param dstkey 
  841.      * @return 
  842.      */  
  843.     public String rpoplpush(String srckey, String dstkey){  
  844.         Jedis jedis = null;  
  845.         String res = null;  
  846.         try {  
  847.             jedis = pool.getResource();  
  848.             res = jedis.rpoplpush(srckey, dstkey);  
  849.         } catch (Exception e) {  
  850.               
  851.             LOGGER.error(e.getMessage());  
  852.         } finally {  
  853.             returnResource(pool, jedis);  
  854.         }  
  855.         return res;  
  856.     }  
  857.   
  858.     /** 
  859.      * <p>通过key获取list中指定下标位置的value</p> 
  860.      * @param key 
  861.      * @param index 
  862.      * @return 如果没有返回null 
  863.      */  
  864.     public String lindex(String key,long index){  
  865.         Jedis jedis = null;  
  866.         String res = null;  
  867.         try {  
  868.             jedis = pool.getResource();  
  869.             res = jedis.lindex(key, index);  
  870.         } catch (Exception e) {  
  871.               
  872.             LOGGER.error(e.getMessage());  
  873.         } finally {  
  874.             returnResource(pool, jedis);  
  875.         }  
  876.         return res;  
  877.     }  
  878.   
  879.     /** 
  880.      * <p>通过key返回list的长度</p> 
  881.      * @param key 
  882.      * @return 
  883.      */  
  884.     public Long llen(String key){  
  885.         Jedis jedis = null;  
  886.         Long res = null;  
  887.         try {  
  888.             jedis = pool.getResource();  
  889.             res = jedis.llen(key);  
  890.         } catch (Exception e) {  
  891.               
  892.             LOGGER.error(e.getMessage());  
  893.         } finally {  
  894.             returnResource(pool, jedis);  
  895.         }  
  896.         return res;  
  897.     }  
  898.   
  899.     /** 
  900.      * <p>通过key获取list指定下标位置的value</p> 
  901.      * <p>如果start 为 0 end 为 -1 则返回全部的list中的value</p> 
  902.      * @param key 
  903.      * @param start 
  904.      * @param end 
  905.      * @return 
  906.      */  
  907.     public List<String> lrange(String key,long start,long end){  
  908.         Jedis jedis = null;  
  909.         List<String> res = null;  
  910.         try {  
  911.             jedis = pool.getResource();  
  912.             res = jedis.lrange(key, start, end);  
  913.         } catch (Exception e) {  
  914.               
  915.             LOGGER.error(e.getMessage());  
  916.         } finally {  
  917.             returnResource(pool, jedis);  
  918.         }  
  919.         return res;  
  920.     }  
  921.   
  922.     /** 
  923.      * <p>通过key向指定的set中添加value</p> 
  924.      * @param key 
  925.      * @param members 可以是一个String 也可以是一个String数组 
  926.      * @return 添加成功的个数 
  927.      */  
  928.     public Long sadd(String key,String...members){  
  929.         Jedis jedis = null;  
  930.         Long res = null;  
  931.         try {  
  932.             jedis = pool.getResource();  
  933.             res = jedis.sadd(key, members);  
  934.         } catch (Exception e) {  
  935.               
  936.             LOGGER.error(e.getMessage());  
  937.         } finally {  
  938.             returnResource(pool, jedis);  
  939.         }  
  940.         return res;  
  941.     }  
  942.   
  943.     /** 
  944.      * <p>通过key删除set中对应的value值</p> 
  945.      * @param key 
  946.      * @param members 可以是一个String 也可以是一个String数组 
  947.      * @return 删除的个数 
  948.      */  
  949.     public Long srem(String key,String...members){  
  950.         Jedis jedis = null;  
  951.         Long res = null;  
  952.         try {  
  953.             jedis = pool.getResource();  
  954.             res = jedis.srem(key, members);  
  955.         } catch (Exception e) {  
  956.               
  957.             LOGGER.error(e.getMessage());  
  958.         } finally {  
  959.             returnResource(pool, jedis);  
  960.         }  
  961.         return res;  
  962.     }  
  963.   
  964.     /** 
  965.      * <p>通过key随机删除一个set中的value并返回该值</p> 
  966.      * @param key 
  967.      * @return 
  968.      */  
  969.     public String spop(String key){  
  970.         Jedis jedis = null;  
  971.         String res = null;  
  972.         try {  
  973.             jedis = pool.getResource();  
  974.             res = jedis.spop(key);  
  975.         } catch (Exception e) {  
  976.               
  977.             LOGGER.error(e.getMessage());  
  978.         } finally {  
  979.             returnResource(pool, jedis);  
  980.         }  
  981.         return res;  
  982.     }  
  983.   
  984.     /** 
  985.      * <p>通过key获取set中的差集</p> 
  986.      * <p>以第一个set为标准</p> 
  987.      * @param keys 可以使一个string 则返回set中所有的value 也可以是string数组 
  988.      * @return 
  989.      */  
  990.     public Set<String> sdiff(String...keys){  
  991.         Jedis jedis = null;  
  992.         Set<String> res = null;  
  993.         try {  
  994.             jedis = pool.getResource();  
  995.             res = jedis.sdiff(keys);  
  996.         } catch (Exception e) {  
  997.               
  998.             LOGGER.error(e.getMessage());  
  999.         } finally {  
  1000.             returnResource(pool, jedis);  
  1001.         }  
  1002.         return res;  
  1003.     }  
  1004.   
  1005.     /** 
  1006.      * <p>通过key获取set中的差集并存入到另一个key中</p> 
  1007.      * <p>以第一个set为标准</p> 
  1008.      * @param dstkey 差集存入的key 
  1009.      * @param keys 可以使一个string 则返回set中所有的value 也可以是string数组 
  1010.      * @return 
  1011.      */  
  1012.     public Long sdiffstore(String dstkey,String... keys){  
  1013.         Jedis jedis = null;  
  1014.         Long res = null;  
  1015.         try {  
  1016.             jedis = pool.getResource();  
  1017.             res = jedis.sdiffstore(dstkey, keys);  
  1018.         } catch (Exception e) {  
  1019.               
  1020.             LOGGER.error(e.getMessage());  
  1021.         } finally {  
  1022.             returnResource(pool, jedis);  
  1023.         }  
  1024.         return res;  
  1025.     }  
  1026.   
  1027.     /** 
  1028.      * <p>通过key获取指定set中的交集</p> 
  1029.      * @param keys 可以使一个string 也可以是一个string数组 
  1030.      * @return 
  1031.      */  
  1032.     public Set<String> sinter(String...keys){  
  1033.         Jedis jedis = null;  
  1034.         Set<String> res = null;  
  1035.         try {  
  1036.             jedis = pool.getResource();  
  1037.             res = jedis.sinter(keys);  
  1038.         } catch (Exception e) {  
  1039.               
  1040.             LOGGER.error(e.getMessage());  
  1041.         } finally {  
  1042.             returnResource(pool, jedis);  
  1043.         }  
  1044.         return res;  
  1045.     }  
  1046.   
  1047.     /** 
  1048.      * <p>通过key获取指定set中的交集 并将结果存入新的set中</p> 
  1049.      * @param dstkey 
  1050.      * @param keys 可以使一个string 也可以是一个string数组 
  1051.      * @return 
  1052.      */  
  1053.     public Long sinterstore(String dstkey,String...keys){  
  1054.         Jedis jedis = null;  
  1055.         Long res = null;  
  1056.         try {  
  1057.             jedis = pool.getResource();  
  1058.             res = jedis.sinterstore(dstkey, keys);  
  1059.         } catch (Exception e) {  
  1060.               
  1061.             LOGGER.error(e.getMessage());  
  1062.         } finally {  
  1063.             returnResource(pool, jedis);  
  1064.         }  
  1065.         return res;  
  1066.     }  
  1067.   
  1068.     /** 
  1069.      * <p>通过key返回所有set的并集</p> 
  1070.      * @param keys 可以使一个string 也可以是一个string数组 
  1071.      * @return 
  1072.      */  
  1073.     public Set<String> sunion(String... keys){  
  1074.         Jedis jedis = null;  
  1075.         Set<String> res = null;  
  1076.         try {  
  1077.             jedis = pool.getResource();  
  1078.             res = jedis.sunion(keys);  
  1079.         } catch (Exception e) {  
  1080.               
  1081.             LOGGER.error(e.getMessage());  
  1082.         } finally {  
  1083.             returnResource(pool, jedis);  
  1084.         }  
  1085.         return res;  
  1086.     }  
  1087.   
  1088.     /** 
  1089.      * <p>通过key返回所有set的并集,并存入到新的set中</p> 
  1090.      * @param dstkey 
  1091.      * @param keys 可以使一个string 也可以是一个string数组 
  1092.      * @return 
  1093.      */  
  1094.     public Long sunionstore(String dstkey,String...keys){  
  1095.         Jedis jedis = null;  
  1096.         Long res = null;  
  1097.         try {  
  1098.             jedis = pool.getResource();  
  1099.             res = jedis.sunionstore(dstkey, keys);  
  1100.         } catch (Exception e) {  
  1101.               
  1102.             LOGGER.error(e.getMessage());  
  1103.         } finally {  
  1104.             returnResource(pool, jedis);  
  1105.         }  
  1106.         return res;  
  1107.     }  
  1108.   
  1109.     /** 
  1110.      * <p>通过key将set中的value移除并添加到第二个set中</p> 
  1111.      * @param srckey 需要移除的 
  1112.      * @param dstkey 添加的 
  1113.      * @param member set中的value 
  1114.      * @return 
  1115.      */  
  1116.     public Long smove(String srckey, String dstkey, String member){  
  1117.         Jedis jedis = null;  
  1118.         Long res = null;  
  1119.         try {  
  1120.             jedis = pool.getResource();  
  1121.             res = jedis.smove(srckey, dstkey, member);  
  1122.         } catch (Exception e) {  
  1123.               
  1124.             LOGGER.error(e.getMessage());  
  1125.         } finally {  
  1126.             returnResource(pool, jedis);  
  1127.         }  
  1128.         return res;  
  1129.     }  
  1130.   
  1131.     /** 
  1132.      * <p>通过key获取set中value的个数</p> 
  1133.      * @param key 
  1134.      * @return 
  1135.      */  
  1136.     public Long scard(String key){  
  1137.         Jedis jedis = null;  
  1138.         Long res = null;  
  1139.         try {  
  1140.             jedis = pool.getResource();  
  1141.             res = jedis.scard(key);  
  1142.         } catch (Exception e) {  
  1143.               
  1144.             LOGGER.error(e.getMessage());  
  1145.         } finally {  
  1146.             returnResource(pool, jedis);  
  1147.         }  
  1148.         return res;  
  1149.     }  
  1150.   
  1151.     /** 
  1152.      * <p>通过key判断value是否是set中的元素</p> 
  1153.      * @param key 
  1154.      * @param member 
  1155.      * @return 
  1156.      */  
  1157.     public Boolean sismember(String key,String member){  
  1158.         Jedis jedis = null;  
  1159.         Boolean res = null;  
  1160.         try {  
  1161.             jedis = pool.getResource();  
  1162.             res = jedis.sismember(key, member);  
  1163.         } catch (Exception e) {  
  1164.               
  1165.             LOGGER.error(e.getMessage());  
  1166.         } finally {  
  1167.             returnResource(pool, jedis);  
  1168.         }  
  1169.         return res;  
  1170.     }  
  1171.   
  1172.     /** 
  1173.      * <p>通过key获取set中随机的value,不删除元素</p> 
  1174.      * @param key 
  1175.      * @return 
  1176.      */  
  1177.     public String srandmember(String key){  
  1178.         Jedis jedis = null;  
  1179.         String res = null;  
  1180.         try {  
  1181.             jedis = pool.getResource();  
  1182.             res = jedis.srandmember(key);  
  1183.         } catch (Exception e) {  
  1184.               
  1185.             LOGGER.error(e.getMessage());  
  1186.         } finally {  
  1187.             returnResource(pool, jedis);  
  1188.         }  
  1189.         return res;  
  1190.     }  
  1191.   
  1192.     /** 
  1193.      * <p>通过key获取set中所有的value</p> 
  1194.      * @param key 
  1195.      * @return 
  1196.      */  
  1197.     public Set<String> smembers(String key){  
  1198.         Jedis jedis = null;  
  1199.         Set<String> res = null;  
  1200.         try {  
  1201.             jedis = pool.getResource();  
  1202.             res = jedis.smembers(key);  
  1203.         } catch (Exception e) {  
  1204.               
  1205.             LOGGER.error(e.getMessage());  
  1206.         } finally {  
  1207.             returnResource(pool, jedis);  
  1208.         }  
  1209.         return res;  
  1210.     }  
  1211.   
  1212.   
  1213.     /** 
  1214.      * <p>通过key向zset中添加value,score,其中score就是用来排序的</p> 
  1215.      * <p>如果该value已经存在则根据score更新元素</p> 
  1216.      * @param key 
  1217.      * @param score 
  1218.      * @param member 
  1219.      * @return 
  1220.      */  
  1221.     public Long zadd(String key,double score,String member){  
  1222.         Jedis jedis = null;  
  1223.         Long res = null;  
  1224.         try {  
  1225.             jedis = pool.getResource();  
  1226.             res = jedis.zadd(key, score, member);  
  1227.         } catch (Exception e) {  
  1228.               
  1229.             LOGGER.error(e.getMessage());  
  1230.         } finally {  
  1231.             returnResource(pool, jedis);  
  1232.         }  
  1233.         return res;  
  1234.     }  
  1235.   
  1236.     /** 
  1237.      * <p>通过key删除在zset中指定的value</p> 
  1238.      * @param key 
  1239.      * @param members 可以使一个string 也可以是一个string数组 
  1240.      * @return 
  1241.      */  
  1242.     public Long zrem(String key,String...members){  
  1243.         Jedis jedis = null;  
  1244.         Long res = null;  
  1245.         try {  
  1246.             jedis = pool.getResource();  
  1247.             res = jedis.zrem(key, members);  
  1248.         } catch (Exception e) {  
  1249.               
  1250.             LOGGER.error(e.getMessage());  
  1251.         } finally {  
  1252.             returnResource(pool, jedis);  
  1253.         }  
  1254.         return res;  
  1255.     }  
  1256.   
  1257.     /** 
  1258.      * <p>通过key增加该zset中value的score的值</p> 
  1259.      * @param key 
  1260.      * @param score 
  1261.      * @param member 
  1262.      * @return 
  1263.      */  
  1264.     public Double zincrby(String key ,double score ,String member){  
  1265.         Jedis jedis = null;  
  1266.         Double res = null;  
  1267.         try {  
  1268.             jedis = pool.getResource();  
  1269.             res = jedis.zincrby(key, score, member);  
  1270.         } catch (Exception e) {  
  1271.               
  1272.             LOGGER.error(e.getMessage());  
  1273.         } finally {  
  1274.             returnResource(pool, jedis);  
  1275.         }  
  1276.         return res;  
  1277.     }  
  1278.   
  1279.     /** 
  1280.      * <p>通过key返回zset中value的排名</p> 
  1281.      * <p>下标从小到大排序</p> 
  1282.      * @param key 
  1283.      * @param member 
  1284.      * @return 
  1285.      */  
  1286.     public Long zrank(String key,String member){  
  1287.         Jedis jedis = null;  
  1288.         Long res = null;  
  1289.         try {  
  1290.             jedis = pool.getResource();  
  1291.             res = jedis.zrank(key, member);  
  1292.         } catch (Exception e) {  
  1293.               
  1294.             LOGGER.error(e.getMessage());  
  1295.         } finally {  
  1296.             returnResource(pool, jedis);  
  1297.         }  
  1298.         return res;  
  1299.     }  
  1300.   
  1301.     /** 
  1302.      * <p>通过key返回zset中value的排名</p> 
  1303.      * <p>下标从大到小排序</p> 
  1304.      * @param key 
  1305.      * @param member 
  1306.      * @return 
  1307.      */  
  1308.     public Long zrevrank(String key,String member){  
  1309.         Jedis jedis = null;  
  1310.         Long res = null;  
  1311.         try {  
  1312.             jedis = pool.getResource();  
  1313.             res = jedis.zrevrank(key, member);  
  1314.         } catch (Exception e) {  
  1315.               
  1316.             LOGGER.error(e.getMessage());  
  1317.         } finally {  
  1318.             returnResource(pool, jedis);  
  1319.         }  
  1320.         return res;  
  1321.     }  
  1322.   
  1323.     /** 
  1324.      * <p>通过key将获取score从start到end中zset的value</p> 
  1325.      * <p>socre从大到小排序</p> 
  1326.      * <p>当start为0 end为-1时返回全部</p> 
  1327.      * @param key 
  1328.      * @param start 
  1329.      * @param end 
  1330.      * @return 
  1331.      */  
  1332.     public Set<String> zrevrange(String key ,long start ,long end){  
  1333.         Jedis jedis = null;  
  1334.         Set<String> res = null;  
  1335.         try {  
  1336.             jedis = pool.getResource();  
  1337.             res = jedis.zrevrange(key, start, end);  
  1338.         } catch (Exception e) {  
  1339.               
  1340.             LOGGER.error(e.getMessage());  
  1341.         } finally {  
  1342.             returnResource(pool, jedis);  
  1343.         }  
  1344.         return res;  
  1345.     }  
  1346.   
  1347.     /** 
  1348.      * <p>通过key返回指定score内zset中的value</p> 
  1349.      * @param key 
  1350.      * @param max 
  1351.      * @param min 
  1352.      * @return 
  1353.      */  
  1354.     public Set<String> zrangebyscore(String key,String max,String min){  
  1355.         Jedis jedis = null;  
  1356.         Set<String> res = null;  
  1357.         try {  
  1358.             jedis = pool.getResource();  
  1359.             res = jedis.zrevrangeByScore(key, max, min);  
  1360.         } catch (Exception e) {  
  1361.               
  1362.             LOGGER.error(e.getMessage());  
  1363.         } finally {  
  1364.             returnResource(pool, jedis);  
  1365.         }  
  1366.         return res;  
  1367.     }  
  1368.   
  1369.     /** 
  1370.      * <p>通过key返回指定score内zset中的value</p> 
  1371.      * @param key 
  1372.      * @param max 
  1373.      * @param min 
  1374.      * @return 
  1375.      */  
  1376.     public Set<String> zrangeByScore(String key ,double max,double min){  
  1377.         Jedis jedis = null;  
  1378.         Set<String> res = null;  
  1379.         try {  
  1380.             jedis = pool.getResource();  
  1381.             res = jedis.zrevrangeByScore(key,max,min);  
  1382.         } catch (Exception e) {  
  1383.               
  1384.             LOGGER.error(e.getMessage());  
  1385.         } finally {  
  1386.             returnResource(pool, jedis);  
  1387.         }  
  1388.         return res;  
  1389.     }  
  1390.   
  1391.     /** 
  1392.      * <p>返回指定区间内zset中value的数量</p> 
  1393.      * @param key 
  1394.      * @param min 
  1395.      * @param max 
  1396.      * @return 
  1397.      */  
  1398.     public Long zcount(String key,String min,String max){  
  1399.         Jedis jedis = null;  
  1400.         Long res = null;  
  1401.         try {  
  1402.             jedis = pool.getResource();  
  1403.             res = jedis.zcount(key, min, max);  
  1404.         } catch (Exception e) {  
  1405.               
  1406.             LOGGER.error(e.getMessage());  
  1407.         } finally {  
  1408.             returnResource(pool, jedis);  
  1409.         }  
  1410.         return res;  
  1411.     }  
  1412.   
  1413.     /** 
  1414.      * <p>通过key返回zset中的value个数</p> 
  1415.      * @param key 
  1416.      * @return 
  1417.      */  
  1418.     public Long zcard(String key){  
  1419.         Jedis jedis = null;  
  1420.         Long res = null;  
  1421.         try {  
  1422.             jedis = pool.getResource();  
  1423.             res = jedis.zcard(key);  
  1424.         } catch (Exception e) {  
  1425.               
  1426.             LOGGER.error(e.getMessage());  
  1427.         } finally {  
  1428.             returnResource(pool, jedis);  
  1429.         }  
  1430.         return res;  
  1431.     }  
  1432.   
  1433.     /** 
  1434.      * <p>通过key获取zset中value的score值</p> 
  1435.      * @param key 
  1436.      * @param member 
  1437.      * @return 
  1438.      */  
  1439.     public Double zscore(String key,String member){  
  1440.         Jedis jedis = null;  
  1441.         Double res = null;  
  1442.         try {  
  1443.             jedis = pool.getResource();  
  1444.             res = jedis.zscore(key, member);  
  1445.         } catch (Exception e) {  
  1446.               
  1447.             LOGGER.error(e.getMessage());  
  1448.         } finally {  
  1449.             returnResource(pool, jedis);  
  1450.         }  
  1451.         return res;  
  1452.     }  
  1453.   
  1454.     /** 
  1455.      * <p>通过key删除给定区间内的元素</p> 
  1456.      * @param key 
  1457.      * @param start 
  1458.      * @param end 
  1459.      * @return 
  1460.      */  
  1461.     public Long zremrangeByRank(String key ,long start, long end){  
  1462.         Jedis jedis = null;  
  1463.         Long res = null;  
  1464.         try {  
  1465.             jedis = pool.getResource();  
  1466.             res = jedis.zremrangeByRank(key, start, end);  
  1467.         } catch (Exception e) {  
  1468.               
  1469.             LOGGER.error(e.getMessage());  
  1470.         } finally {  
  1471.             returnResource(pool, jedis);  
  1472.         }  
  1473.         return res;  
  1474.     }  
  1475.   
  1476.     /** 
  1477.      * <p>通过key删除指定score内的元素</p> 
  1478.      * @param key 
  1479.      * @param start 
  1480.      * @param end 
  1481.      * @return 
  1482.      */  
  1483.     public Long zremrangeByScore(String key,double start,double end){  
  1484.         Jedis jedis = null;  
  1485.         Long res = null;  
  1486.         try {  
  1487.             jedis = pool.getResource();  
  1488.             res = jedis.zremrangeByScore(key, start, end);  
  1489.         } catch (Exception e) {  
  1490.               
  1491.             LOGGER.error(e.getMessage());  
  1492.         } finally {  
  1493.             returnResource(pool, jedis);  
  1494.         }  
  1495.         return res;  
  1496.     }  
  1497.     /** 
  1498.      * <p>返回满足pattern表达式的所有key</p> 
  1499.      * <p>keys(*)</p> 
  1500.      * <p>返回所有的key</p> 
  1501.      * @param pattern 
  1502.      * @return 
  1503.      */  
  1504.     public Set<String> keys(String pattern){  
  1505.         Jedis jedis = null;  
  1506.         Set<String> res = null;  
  1507.         try {  
  1508.             jedis = pool.getResource();  
  1509.             res = jedis.keys(pattern);  
  1510.         } catch (Exception e) {  
  1511.               
  1512.             LOGGER.error(e.getMessage());  
  1513.         } finally {  
  1514.             returnResource(pool, jedis);  
  1515.         }  
  1516.         return res;  
  1517.     }  
  1518.   
  1519.     /** 
  1520.      * <p>通过key判断值得类型</p> 
  1521.      * @param key 
  1522.      * @return 
  1523.      */  
  1524.     public String type(String key){  
  1525.         Jedis jedis = null;  
  1526.         String res = null;  
  1527.         try {  
  1528.             jedis = pool.getResource();  
  1529.             res = jedis.type(key);  
  1530.         } catch (Exception e) {  
  1531.               
  1532.             LOGGER.error(e.getMessage());  
  1533.         } finally {  
  1534.             returnResource(pool, jedis);  
  1535.         }  
  1536.         return res;  
  1537.     }  
  1538.   
  1539.     /** 
  1540.      * 返还到连接池 
  1541.      * 
  1542.      * @param pool 
  1543.      * @param jedis 
  1544.      */  
  1545.     public static void returnResource(JedisPool pool, Jedis jedis) {  
  1546.         if (jedis != null) {  
  1547.             pool.returnResource(jedis);  
  1548.         }  
  1549.     }  
  1550.   
  1551.     public static RedisUtil getRu() {  
  1552.         return ru;  
  1553.     }  
  1554.   
  1555.     public static void setRu(RedisUtil ru) {  
  1556.         RedisUtil.ru = ru;  
  1557.     }  
  1558. }  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值