<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Redis客戶端Java服務接口封裝

              最近在學習Redis并集成到Spring中去,發現Spring的RedisTemplate并不好用,還沒有MongoTemplate好用。
      而且發現Jedis和ShardedJedis的方法非常多,覆蓋了Redis幾乎所有操作,但是沒有注釋,也沒有異常處理,也沒有資源回收,所以我就對這兩個類進行了再次封裝,對照著Redis官網的中文API加上了中文注釋,并對接口方法進行了分類,加入了異常處理和資源回收。
              我在虛擬機上裝的是redis-3.0.6,基本Spring-4.1.7、jedis-2.8.0、spring-data-redis-1.6.2開發的并測試通過,我是封裝的靜態類,大家如果不想用靜態類可以直接把所有的static全部替換掉就可以了,異常處理也是,可以根據自己的需要直接批量替換,非常的方便。因為Redis的操作命令非常的多,所以封裝接口和加注釋的工作量也很大,都是用業余時間完成的,希望對大家有用。
              最后面有一些沒有加注釋的方法是我在網上看到的,不知道是做什么的,如果有知道的朋友希望能告訴我,我好把注釋都加上去。


      package redis;
      
      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 redis.clients.jedis.BinaryClient.LIST_POSITION;
      import redis.clients.jedis.Jedis;
      import redis.clients.jedis.JedisPool;
      import redis.clients.jedis.JedisShardInfo;
      import redis.clients.jedis.ShardedJedis;
      import redis.clients.jedis.ShardedJedisPipeline;
      import redis.clients.jedis.ShardedJedisPool;
      import redis.clients.jedis.SortingParams;
      import redis.clients.jedis.Tuple;
      
      /**
       * Redis客戶端操作工具類<br>
       * 
       * JedisPool連一臺Redis;ShardedJedisPool連Redis集群,通過一致性哈希算法決定把數據存到哪臺上
       * 
       * @author bianj
       * @version 1.0.0 2016年1月21日
       */
      public class RedisClientTemplate {
          private static final Logger LOGGER = LoggerFactory.getLogger(RedisClientTemplate.class);
      
          /** 支持Redis集群的切片鏈接池 */
          private static ShardedJedisPool shardedJedisPool;
      
          /** 支持單臺Redis的非切片鏈接池 */
          private static JedisPool jedisPool;
      
          /**
           * 用于Spring注入ShardedJedisPool
           * 
           * @param shardedJedisPool
           */
          public void setShardedJedisPool(ShardedJedisPool shardedJedisPool) {
              RedisClientTemplate.shardedJedisPool = shardedJedisPool;
          }
      
          /**
           * 用于Spring注入JedisPool
           * 
           * @param jedisPool
           */
          public void setJedisPool(JedisPool jedisPool) {
              RedisClientTemplate.jedisPool = jedisPool;
          }
      
          /**
           * 從ShardedJedisPool中獲取ShardedJedis
           * 
           * @return ShardedJedis
           */
          public static ShardedJedis getShardedJedis() {
              return shardedJedisPool.getResource();
          }
      
          /**
           * 從JedisPool中獲取Jedis
           * 
           * @return Jedis
           */
          public static Jedis getJedis() {
              return jedisPool.getResource();
          }
      
          /** =============================操作Redis服務器的方法============================= */
      
          /**
           * 使用客戶端向 當前Redis服務器發送一個 PING ,如果服務器運作正常的話,會返回一個 PONG。
           * 通常用于測試與服務器的連接是否仍然生效,或者用于測量延遲值。
           * 
           * @return result 如果連接正常就返回一個 PONG ,否則返回一個連接錯誤。
           */
          public static String ping() {
              String result = null;
      
              Jedis jedis = getJedis();
              if (jedis == null) {
                  return result;
              }
      
              try {
                  result = jedis.ping();
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  jedis.close();
              }
      
              return result;
          }
      
          /**
           * 切換到當前Redis指定的數據庫,數據庫索引號index用數字值指定,以0作為起始索引值。默認使用0號數據庫。
           * 
           * @param index
           *            數據庫索引號
           * @return result OK
           */
          public static String select(int index) {
              String result = null;
      
              Jedis jedis = getJedis();
              if (jedis == null) {
                  return result;
              }
      
              try {
                  result = jedis.select(index);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  jedis.close();
              }
      
              return result;
          }
      
          /**
           * 清空當前數據庫中的所有key。
           * 
           * @return result OK
           */
          public static String flushDB() {
              String result = null;
      
              Jedis jedis = getJedis();
              if (jedis == null) {
                  return result;
              }
      
              try {
                  result = jedis.flushDB();
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  jedis.close();
              }
      
              return result;
          }
      
          /**
           * 清空整個當前 Redis 服務器的數據(刪除所有數據庫的所有 key )。
           * 
           * @return result OK
           */
          public static String flushAll() {
              String result = null;
      
              Jedis jedis = getJedis();
              if (jedis == null) {
                  return result;
              }
      
              try {
                  result = jedis.flushAll();
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  jedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回當前數據庫的 key 的數量。
           * 
           * @return result 當前數據庫的 key 的數量。
           */
          public static Long dbSize() {
              Long result = null;
      
              Jedis jedis = getJedis();
              if (jedis == null) {
                  return result;
              }
      
              try {
                  result = jedis.dbSize();
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  jedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回所有連接到當前服務器的客戶端信息和統計數據。
           * 返回參數詳情見:http://redisdoc.com/server/client_list.html
           * 
           * @return result 客戶端信息和統計數據。
           */
          public static String clientList() {
              String result = null;
      
              Jedis jedis = getJedis();
              if (jedis == null) {
                  return result;
              }
      
              try {
                  result = jedis.clientList();
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  jedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回關于 當前Redis 服務器的各種信息和統計數值。 <br>
           * 返回參數詳情見:http://redisdoc.com/server/info.html
           * 
           * @return result 服務器信息。
           */
          public static String info() {
              String result = null;
      
              Jedis jedis = getJedis();
              if (jedis == null) {
                  return result;
              }
      
              try {
                  result = jedis.info();
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  jedis.close();
              }
      
              return result;
          }
      
          /** ===============================操作Key的方法=============================== */
      
          /**
           * 查找當前數據庫中所有符合給定模式 pattern 的 key 。 <br>
           * KEYS * 匹配數據庫中所有 key 。 <br>
           * KEYS h?llo 匹配 hello , hallo 和 hxllo 等。 <br>
           * KEYS h*llo 匹配 hllo 和 heeeeello 等。 <br>
           * KEYS h[ae]llo 匹配 hello 和 hallo ,但不匹配 hillo 。 <br>
           * 特殊符號用 \ 隔開<br>
           * 
           * 注意:KEYS 的速度非常快,但在一個大的數據庫中使用它仍然可能造成性能問題,如果你需要從一個數據集中查找特定的 key, 你最好還是用
           * Redis 的集合結構(set)來代替。
           * 
           * @param pattern
           *            符合給定模式的 key 列表。
           */
          public static Set<String> keys(String pattern) {
              Set<String> result = null;
      
              Jedis jedis = getJedis();
              if (jedis == null) {
                  return result;
              }
      
              try {
                  result = jedis.keys(pattern);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  jedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回 key 所儲存的值的類型。
           * 
           * @param key
           * @return none(key不存在)、string(字符串)、list(列表)、set(集合)、zset(有序集)、hash(哈希表)
           */
          public static String type(String key) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.type(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回 key 所儲存的值的類型。
           * 
           * @param key
           * @return none(key不存在)、string(字符串)、list(列表)、set(集合)、zset(有序集)、hash(哈希表)
           */
          public static String type(byte[] key) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.type(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 為給定 key 設置生存時間,當 key 過期時(生存時間為 0 ),它會被自動刪除。
           * 
           * @param key
           * @param seconds
           *            以秒為單位的時間
           * @return result 設置成功返回 1 。 當 key 不存在或者不能為 key 設置生存時間時(比如在低于 2.1.3 版本的
           *         Redis 中你嘗試更新 key 的生存時間),返回 0 。
           */
          public static Long expire(String key, int seconds) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.expire(key, seconds);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 為給定 key 設置生存時間,當 key 過期時(生存時間為 0 ),它會被自動刪除。
           * 
           * @param key
           * @param seconds
           *            以秒為單位的時間
           * @return result 設置成功返回 1 。 當 key 不存在或者不能為 key 設置生存時間時(比如在低于 2.1.3 版本的
           *         Redis 中你嘗試更新 key 的生存時間),返回 0 。
           */
          public static Long expire(byte[] key, int seconds) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.expire(key, seconds);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * EXPIREAT 的作用和 EXPIRE 類似,都用于為 key 設置生存時間。 不同在于 EXPIREAT 命令接受的時間參數是 UNIX
           * 時間戳(unix timestamp)。 它是距歷元(即格林威治標準時間 1970 年 1 月 1 日的 00:00:00,格里高利歷)的偏移量。
           * 
           * @param key
           * @param unixTime
           *            UNIX時間戳
           * @return result 如果生存時間設置成功,返回 1 。 當 key 不存在或沒辦法設置生存時間,返回 0 。
           */
          public static Long expireAt(String key, long unixTime) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.expireAt(key, unixTime);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * EXPIREAT 的作用和 EXPIRE 類似,都用于為 key 設置生存時間。 不同在于 EXPIREAT 命令接受的時間參數是 UNIX
           * 時間戳(unix timestamp)。 它是距歷元(即格林威治標準時間 1970 年 1 月 1 日的 00:00:00,格里高利歷)的偏移量。
           * 
           * @param key
           * @param unixTime
           *            UNIX時間戳
           * @return result 如果生存時間設置成功,返回 1 。 當 key 不存在或沒辦法設置生存時間,返回 0 。
           */
          public static Long expireAt(byte[] key, long unixTime) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.expireAt(key, unixTime);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 以秒為單位,返回給定 key 的剩余生存時間(TTL, time to live)。
           * 
           * @param key
           * @return result 當 key 不存在時,返回 -2 。 當 key 存在但沒有設置剩余生存時間時,返回 -1 。
           *         否則,以秒為單位,返回 key 的剩余生存時間。
           */
          public static Long ttl(String key) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.ttl(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 以秒為單位,返回給定 key 的剩余生存時間(TTL, time to live)。
           * 
           * @param key
           * @return result 當 key 不存在時,返回 -2 。 當 key 存在但沒有設置剩余生存時間時,返回 -1 。
           *         否則,以秒為單位,返回 key 的剩余生存時間。
           */
          public static Long ttl(byte[] key) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.ttl(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 移除當前數據庫中給定 key 的生存時間,將這個 key 從『易失的』(帶生存時間 key )轉換成『持久的』(一個不帶生存時間、永不過期的
           * key )。
           * 
           * @param key
           * @return result 當生存時間移除成功時,返回 1 . 如果 key 不存在或 key 沒有設置生存時間,返回 0 。
           */
          public static Long persist(String key) {
              Long result = null;
      
              Jedis jedis = getJedis();
              if (jedis == null) {
                  return result;
              }
      
              try {
                  result = jedis.persist(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  jedis.close();
              }
      
              return result;
          }
      
          /**
           * 移除當前數據庫中給定 key 的生存時間,將這個 key 從『易失的』(帶生存時間 key )轉換成『持久的』(一個不帶生存時間、永不過期的
           * key )。
           * 
           * @param key
           * @return result 當生存時間移除成功時,返回 1 . 如果 key 不存在或 key 沒有設置生存時間,返回 0 。
           */
          public static Long persist(byte[] key) {
              Long result = null;
      
              Jedis jedis = getJedis();
              if (jedis == null) {
                  return result;
              }
      
              try {
                  result = jedis.persist(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  jedis.close();
              }
      
              return result;
          }
      
          /**
           * 刪除當前數據庫中給定的一個或多個 key 。不存在的 key 會被忽略。
           * 
           * @param keys
           * @return result 被刪除 key 的數量。
           */
          public static Long del(String... keys) {
              Long result = null;
      
              Jedis jedis = getJedis();
              if (jedis == null) {
                  return result;
              }
      
              try {
                  result = jedis.del(keys);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  jedis.close();
              }
      
              return result;
          }
      
          /**
           * 刪除當前數據庫中給定的一個或多個 key 。不存在的 key 會被忽略。
           * 
           * @param keys
           * @return result 被刪除 key 的數量。
           */
          public static Long del(byte[]... keys) {
              Long result = null;
      
              Jedis jedis = getJedis();
              if (jedis == null) {
                  return result;
              }
      
              try {
                  result = jedis.del(keys);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  jedis.close();
              }
      
              return result;
          }
      
          /**
           * 刪除集群環境中給定的一個key 。不存在的 key 會被忽略。
           * 
           * @param key
           * @return result 被刪除 key 的數量。
           */
          public static Long del(String key) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.del(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 刪除集群環境中給定的一個key 。不存在的 key 會被忽略。
           * 
           * @param key
           * @return result 被刪除 key 的數量。
           */
          public static Long del(byte[] key) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.del(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 檢查給定 key 是否存在。
           * 
           * @param key
           * @return result 若 key 存在,返回 1 ,否則返回 0 。
           */
          public static Boolean exists(String key) {
              Boolean result = false;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.exists(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 檢查給定 key 是否存在。
           * 
           * @param key
           * @return result 若 key 存在,返回 1 ,否則返回 0 。
           */
          public static Boolean exists(byte[] key) {
              Boolean result = false;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.exists(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 將當前數據庫的 key 移動到給定的數據庫 db 當中。 <br>
           * 如果當前數據庫(源數據庫)和給定數據庫(目標數據庫)有相同名字的給定 key ,或者 key 不存在于當前數據庫,那么 MOVE 沒有任何效果。
           * 
           * @param key
           * @param dbIndex
           *            數據庫索引號
           * @return result 移動成功返回 1 ,失敗則返回 0 。
           */
          public static Long move(String key, int dbIndex) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.move(key, dbIndex);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回或保存給定列表、集合、有序集合 key 中經過排序的元素。排序默認以數字作為對象,值被解釋為雙精度浮點數,然后進行比較。
           * 
           * @param key
           * @return result 返回列表形式的排序結果
           */
          public static List<String> sort(String key) {
              List<String> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.sort(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回或保存給定列表、集合、有序集合 key 中經過排序的元素。排序默認以數字作為對象,值被解釋為雙精度浮點數,然后進行比較。<br>
           * 最簡單的 SORT 使用方法是 SORT key 和 SORT key DESC <br>
           * 因為 SORT 命令默認排序對象為數字, 當需要對字符串進行排序時, 需要顯式地在 SORT 命令之后添加 ALPHA 修飾符<br>
           * 排序之后返回元素的數量可以通過 LIMIT 修飾符進行限制, 修飾符接受 offset(要跳過的元素數量) 和 count(跳過 offset
           * 個指定的元素之后,要返回多少個對象) 兩個參數<br>
           * 
           * 參考:http://redisdoc.com/key/sort.html
           * 
           * @param key
           * @param sortingParameters
           *            排序參數
           * @return result 返回列表形式的排序結果
           */
          public static List<String> sort(String key, SortingParams sortingParameters) {
              List<String> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.sort(key, sortingParameters);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /** ========================對存儲結構為String(字符串)類型的操作======================== */
      
          /**
           * 將字符串值 value 關聯到 key 。如果 key 已經持有其他值, SET 就覆寫舊值,無視類型。
           * 
           * @param key
           * @param value
           * @return result SET在設置操作成功完成時,才返回 OK ,如果設置操作未執行,那么命令返回空批量回復(NULL Bulk
           *         Reply)。
           */
          public static String set(String key, String value) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  // result = shardedJedis.set(SafeEncoder.encode(key),
                  // SafeEncoder.encode(value));
                  result = shardedJedis.set(key, value);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 將字符串值 value 關聯到 key 。如果 key 已經持有其他值, SET 就覆寫舊值,無視類型。<br>
           * EX second :設置鍵的過期時間為 second 秒。 SET key value EX second 效果等同于 SETEX key
           * second value 。<br>
           * PX millisecond :設置鍵的過期時間為 millisecond 毫秒。 SET key value PX millisecond
           * 效果等同于 PSETEX key millisecond value 。<br>
           * NX :只在鍵不存在時,才對鍵進行設置操作。 SET key value NX 效果等同于 SETNX key value 。<br>
           * XX :只在鍵已經存在時,才對鍵進行設置操作。
           * 
           * @param key
           * @param value
           * @param value
           *            nxxx 參數
           * @return result SET在設置操作成功完成時,才返回 OK ,如果設置操作未執行,那么命令返回空批量回復(NULL Bulk
           *         Reply)。
           */
          public static String set(String key, String value, String nxxx) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.set(key, value, nxxx);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 將 key 的值設為 value ,當且僅當 key 不存在。 <br>
           * 若給定的 key 已經存在,則 SETNX 不做任何動作。
           * 
           * @param key
           * @param value
           *            值
           * @return 設置成功,返回 1 ; 設置失敗,返回 0 。
           */
          public static Long setnx(String key, String value) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.setnx(key, value);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 將 key 的值設為 value ,當且僅當 key 不存在。 <br>
           * 若給定的 key 已經存在,則 SETNX 不做任何動作。
           * 
           * @param key
           * @param value
           *            值
           * @return 設置成功,返回 1 ; 設置失敗,返回 0 。
           */
          public static Long setnx(byte[] key, byte[] value) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.setnx(key, value);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回 key 所關聯的字符串值。GET 只能用于處理字符串值。
           * 
           * @param key
           * @return result 當 key 不存在時,返回 nil ,否則,返回 key 的值。 如果 key 不是字符串類型,那么返回一個錯誤。
           */
          public static String get(String key) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.get(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回當前數據庫中所有(一個或多個)給定 key 的值。 <br>
           * 如果給定的 key 里面,有某個 key 不存在,那么這個 key 返回特殊值 nil 。因此,該命令永不失敗。
           * 
           * @param keys
           * @return 一個包含所有給定 key 的值的列表。
           */
          public static List<String> mget(String... keys) {
              List<String> result = null;
      
              Jedis jedis = getJedis();
              if (jedis == null) {
                  return result;
              }
      
              try {
                  result = jedis.mget(keys);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  jedis.close();
              }
      
              return result;
          }
      
          /**
           * 在當前數據庫中同時設置一個或多個 key-value 對。 <br>
           * 如果某個給定 key 已經存在,那么 MSET 會用新值覆蓋原來的舊值,如果這不是你所希望的效果,請考慮使用 MSETNX 命令:它只會在所有給定
           * key 都不存在的情況下進行設置操作。
           * 
           * @param keys
           * @return 總是返回 OK (因為 MSET 不可能失敗)
           */
          public static String mset(String... keysvalues) {
              String result = null;
      
              Jedis jedis = getJedis();
              if (jedis == null) {
                  return result;
              }
      
              try {
                  result = jedis.mset(keysvalues);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  jedis.close();
              }
      
              return result;
          }
      
          /**
           * 在當前數據庫中同時設置一個或多個 key-value 對,當且僅當所有給定 key 都不存在。 <br>
           * 即使只有一個給定 key 已存在, MSETNX 也會拒絕執行所有給定 key 的設置操作。
           * 
           * @param keys
           * @return 當所有 key 都成功設置,返回 1 。 如果所有給定 key 都設置失敗(至少有一個 key 已經存在),那么返回 0 。
           */
          public static Long msetnx(String... keysvalues) {
              Long result = null;
      
              Jedis jedis = getJedis();
              if (jedis == null) {
                  return result;
              }
      
              try {
                  result = jedis.msetnx(keysvalues);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  jedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回 key 所儲存的字符串值的長度。 當 key 儲存的不是字符串值時,返回一個錯誤。
           * 
           * @param keys
           * @return 字符串值的長度。 當 key 不存在時,返回 0 。
           */
          public static Long strlen(String key) {
              Long result = null;
      
              Jedis jedis = getJedis();
              if (jedis == null) {
                  return result;
              }
      
              try {
                  result = jedis.strlen(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  jedis.close();
              }
      
              return result;
          }
      
          /**
           * 將給定 key 的值設為 value ,并返回 key 的舊值(old value)。
           * 
           * @param key
           * @param value
           * @return 返回給定 key 的舊值。 當 key 沒有舊值時,也即是, key 不存在時,返回 nil 。
           */
          public static String getSet(String key, String value) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.getSet(key, value);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 將給定 key 的值設為 value ,并返回 key 的舊值(old value)。
           * 
           * @param key
           * @param value
           * @return 返回給定 key 的舊值。 當 key 沒有舊值時,也即是, key 不存在時,返回 nil 。
           */
          public static byte[] getSet(byte[] key, byte[] value) {
              byte[] result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.getSet(key, value);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 對 key 所儲存的字符串值,設置或清除指定偏移量上的位(bit)。
           * 
           * @param key
           * @param offset
           *            偏移量,offset參數必須大于或等于 0 ,小于 2^32 (bit 映射被限制在 512 MB 之內)。
           * @param value
           *            位的設置或清除取決于 value 參數,可以是 0 也可以是 1 。
           * @return result 指定偏移量原來儲存的位。
           */
          public static boolean setbit(String key, long offset, boolean value) {
              boolean result = false;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.setbit(key, offset, value);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 對 key 所儲存的字符串值,獲取指定偏移量上的位(bit)。
           * 
           * @param key
           * @param offset
           *            偏移量
           * @return result 指定偏移量原來儲存的位。
           */
          public static boolean getbit(String key, long offset) {
              boolean result = false;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.getbit(key, offset);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 用 value 參數覆寫(overwrite)給定 key 所儲存的字符串值,從偏移量 offset 開始。<br>
           * 例:String str="hello world";<br>
           * 對str操作后setrange(key,6,Redis),str="hello Redis";<br>
           * 不存在的 key 當作空白字符串處理:<br>
           * redis> SETRANGE empty_string 5 "Redis!" # 對不存在的 key 使用 SETRANGE <br>
           * redis> GET empty_string # 空白處被"\x00"填充
           * 
           * @param key
           * @param offset
           *            偏移量
           * @param value
           *            值
           * @return result 被修改之后,字符串的長度。
           */
          public static Long setrange(String key, long offset, String value) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.setrange(key, offset, value);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回 key 中字符串值的子字符串,字符串的截取范圍由 start 和 end 兩個偏移量決定(包括 start 和 end 在內)。<br>
           * 負數偏移量表示從字符串最后開始計數, -1 表示最后一個字符, -2 表示倒數第二個,以此類推。
           * 
           * @param key
           * @param startOffset
           *            開始位置(包含)
           * @param endOffset
           *            結束位置(包含)
           * @return result 截取得出的子字符串。
           */
          public static String getrange(String key, long startOffset, long endOffset) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.getrange(key, startOffset, endOffset);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回 key 中字符串值的子字符串,字符串的截取范圍由 start 和 end 兩個偏移量決定(包括 start 和 end 在內)。<br>
           * 負數偏移量表示從字符串最后開始計數, -1 表示最后一個字符, -2 表示倒數第二個,以此類推。
           * 
           * @param key
           * @param start
           *            開始位置(包含)
           * @param end
           *            結束位置(包含)
           * @return result 截取得出的子字符串。
           */
          public static String substr(String key, int start, int end) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.substr(key, start, end);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 將值 value 關聯到 key ,并將 key 的生存時間設為 seconds (以秒為單位)。<br>
           * 如果 key 已經存在, SETEX 命令將覆寫舊值。
           * 
           * @param key
           * @param seconds
           *            過期時間,以秒為單位
           * @param value
           *            值
           * @return result 設置成功時返回 OK 。 當 seconds 參數不合法時,返回一個錯誤。
           */
          public static String setex(String key, int seconds, String value) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.setex(key, seconds, value);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 將值 value 關聯到 key ,并將 key 的生存時間設為 seconds (以秒為單位)。 <br>
           * 如果 key 已經存在, SETEX 命令將覆寫舊值。
           * 
           * @param key
           * @param seconds
           *            過期時間,以秒為單位
           * @param value
           *            值
           * @return result 設置成功時返回 OK 。 當 seconds 參數不合法時,返回一個錯誤。
           */
          public static String setex(byte[] key, int seconds, byte[] value) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.setex(key, seconds, value);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 將key對應的value減去指定的值,只有value可以轉為數字時該方法才可用。 <br>
           * 如果 key 不存在,那么 key 的值會先被初始化為 0 ,然后再執行 DECRBY 操作。
           * 
           * @param key
           * @param integer
           *            要減去的值
           * @return 減去之后的值
           */
          public static Long decrBy(String key, long integer) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.decrBy(key, integer);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 將key對應的value減去指定的值,只有value可以轉為數字時該方法才可用。<br>
           * 如果 key 不存在,那么 key 的值會先被初始化為 0 ,然后再執行 DECRBY 操作。
           * 
           * @param key
           * @param integer
           *            要減去的值
           * @return 減去之后的值
           */
          public static Long decrBy(byte[] key, long integer) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.decrBy(key, integer);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 將 key 中儲存的數字值減一。 如果 key 不存在,那么 key 的值會先被初始化為 0 ,然后再執行 DECR 操作。
           * 
           * @param key
           * @return result 執行 DECR 命令之后 key 的值。
           */
          public static Long decr(String key) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.decr(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 將 key 所儲存的值加上增量 integer 。 如果 key 不存在,那么 key 的值會先被初始化為 0 ,然后再執行 INCRBY 命令。
           * 
           * @param key
           * @param integer
           *            要增加的值
           * @return result 加上 integer 之后, key 的值。
           */
          public static Long incrBy(String key, long integer) {
              Long result = null;
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.incrBy(key, integer);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 將 key 中儲存的數字值增一。 如果 key 不存在,那么 key 的值會先被初始化為 0 ,然后再執行 INCR 操作。
           * 
           * @param key
           * @return result 執行 INCR 命令之后 key 的值。
           */
          public static Long incr(String key) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.incr(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 如果 key 已經存在并且是一個字符串, APPEND 命令將 value 追加到 key 原來的值的末尾。 <br>
           * 如果 key 不存在, APPEND 就簡單地將給定 key 設為 value ,就像執行 SET key value 一樣。
           * 
           * @param key
           * @param value
           * @return result 追加 value 之后, key 中字符串的長度。
           */
          public static Long append(String key, String value) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.append(key, value);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /** ========================對存儲結構為Hash(哈希表)類型的操作======================== */
      
          /**
           * 將哈希表 key 中的域 field 的值設為 value 。
           * 
           * @param key
           * @param field
           *            域
           * @param value
           *            值
           * @return result 如果 field 是哈希表中的一個新建域,并且值設置成功,返回 1 。 如果哈希表中域 field
           *         已經存在且舊值已被新值覆蓋,返回 0 。
           */
          public static Long hset(String key, String field, String value) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.hset(key, field, value);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 將哈希表 key 中的域 field 的值設置為 value ,當且僅當域 field 不存在。 <br>
           * 若域 field 已經存在,該操作無效。 如果 key 不存在,一個新哈希表被創建并執行 HSETNX 命令。
           * 
           * @param key
           * @param field
           *            域
           * @param value
           *            值
           * @return result 設置成功,返回 1 。 如果給定域已經存在且沒有操作被執行,返回 0 。
           */
          public static Long hsetnx(String key, String field, String value) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.hsetnx(key, field, value);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 同時將多個 field-value (域-值)對設置到哈希表 key 中。 此命令會覆蓋哈希表中已存在的域。如果 key
           * 不存在,一個空哈希表被創建并執行 HMSET 操作。
           * 
           * @param key
           * @param hash
           * @return result 如果命令執行成功,返回 OK 。 當 key 不是哈希表(hash)類型時,返回一個錯誤。
           */
          public static String hmset(String key, Map<String, String> hash) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.hmset(key, hash);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回哈希表 key 中給定域 field 的值。
           * 
           * @param key
           * @param field
           *            域
           * @return result 給定域的值。 當給定域不存在或是給定 key 不存在時,返回 nil 。
           */
          public static String hget(String key, String field) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.hget(key, field);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回哈希表 key 中,一個或多個給定域的值。 如果給定的域不存在于哈希表,那么返回一個 nil 值。
           * 
           * @param key
           * @param fields
           *            域列表
           * @return result 一個包含多個給定域的關聯值的表,表值的排列順序和給定域參數的請求順序一樣。
           */
          public static List<String> hmget(String key, String... fields) {
              List<String> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.hmget(key, fields);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 為哈希表 key 中的域 field 的值加上增量 value 。增量也可以為負數,相當于對給定域進行減法操作。
           * 
           * @param key
           * @param field
           *            域
           * @param value
           * @return result 執行 HINCRBY 命令之后,哈希表 key 中域 field 的值。
           */
          public static Long hincrBy(String key, String field, long value) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.hincrBy(key, field, value);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 查看哈希表 key 中,給定域 field 是否存在。
           * 
           * @param key
           * @param field
           *            域
           * @return result 如果哈希表含有給定域,返回 1 。 如果哈希表不含有給定域,或 key 不存在,返回 0 。
           */
          public static Boolean hexists(String key, String field) {
              Boolean result = false;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.hexists(key, field);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 刪除哈希表 key 中的一個或多個指定域,不存在的域將被忽略。
           * 
           * @param key
           * @param field
           *            域
           * @return result 被成功移除的域的數量,不包括被忽略的域。
           */
          public static Long hdel(String key, String field) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.hdel(key, field);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回哈希表 key 中域的數量。
           * 
           * @param key
           * @return result 哈希表中域的數量。 當 key 不存在時,返回 0 。
           */
          public static Long hlen(String key) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.hlen(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回哈希表 key 中的所有域。
           * 
           * @param key
           * @return result 一個包含哈希表中所有域的表。 當 key 不存在時,返回一個空表。
           */
          public static Set<String> hkeys(String key) {
              Set<String> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.hkeys(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回哈希表 key 中所有域的值。
           * 
           * @param key
           * @return result 一個包含哈希表中所有值的表。 當 key 不存在時,返回一個空表。
           */
          public static List<String> hvals(String key) {
              List<String> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.hvals(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回哈希表 key 中,所有的域和值。 <br>
           * 在返回值里,緊跟每個域名(field name)之后是域的值(value),所以返回值的長度是哈希表大小的兩倍。
           * 
           * @param key
           * @return result 以列表形式返回哈希表的域和域的值。 若 key 不存在,返回空列表。
           */
          public static Map<String, String> hgetAll(String key) {
              Map<String, String> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.hgetAll(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
              return result;
          }
      
          /** ========================對存儲結構為List(列表)類型的操作======================== */
      
          /**
           * 將一個或多個值 value 插入到列表 key 的表尾(最右邊)。 如果有多個 value 值,那么各個 value
           * 值按從左到右的順序依次插入到表尾:比如對一個空列表 mylist 執行 RPUSH mylist a b c ,得出的結果列表為 a b c
           * ,等同于執行命令 RPUSH mylist a 、 RPUSH mylist b 、 RPUSH mylist c 。 <br>
           * 如果 key 不存在,一個空列表會被創建并執行 RPUSH 操作。 <br>
           * 當 key 存在但不是列表類型時,返回一個錯誤。
           * 
           * @param key
           * @param string
           *            一個或多個string值
           * @return result 執行 RPUSH 操作后,表的長度。
           */
          public static Long rpush(String key, String... string) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.rpush(key, string);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 將值 value 插入到列表 key 的表尾,當且僅當 key 存在并且是一個列表。 <br>
           * 和 RPUSH 命令相反,當 key 不存在時, RPUSHX 命令什么也不做。
           * 
           * @param key
           * @param string
           *            一個或多個string值
           * @return result RPUSHX 命令執行之后,表的長度。
           */
          public static Long rpushx(String key, String... string) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.rpushx(key, string);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 將一個或多個值 value 插入到列表 key 的表頭 如果有多個 value 值,那么各個 value 值按從左到右的順序依次插入到表頭:
           * 比如說,對空列表 mylist 執行命令 LPUSH mylist a b c ,列表的值將是 c b a ,這等同于原子性地執行 LPUSH
           * mylist a 、 LPUSH mylist b 和 LPUSH mylist c 三個命令。<br>
           * 如果 key 不存在,一個空列表會被創建并執行 LPUSH 操作。 <br>
           * 當 key 存在但不是列表類型時,返回一個錯誤。
           * 
           * @param key
           * @param string
           *            一個或多個string值
           * @return result 執行 LPUSH 命令后,列表的長度。
           */
          public static Long lpush(String key, String... string) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.lpush(key, string);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 將值 value 插入到列表 key 的表頭,當且僅當 key 存在并且是一個列表。<br>
           * 和 LPUSH 命令相反,當 key 不存在時, LPUSHX 命令什么也不做。
           * 
           * @param key
           * @param string
           *            一個或多個string值
           * @return result 執行 LPUSHX 命令后,列表的長度。
           */
          public static Long lpushx(String key, String... string) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.lpushx(key, string);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回列表 key 的長度。<br>
           * 如果 key 不存在,則 key 被解釋為一個空列表,返回 0 .<br>
           * 如果 key 不是列表類型,返回一個錯誤。
           * 
           * @param key
           * @return result 列表 key 的長度。
           */
          public static Long llen(String key) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.llen(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回列表 key 中指定區間內的元素,區間以偏移量 start 和 stop 指定。<br>
           * 下標(index)參數 start 和 stop 都以 0 為底,也就是說,以 0 表示列表的第一個元素,以 1 表示列表的第二個元素,以此類推。<br>
           * 你也可以使用負數下標,以 -1 表示列表的最后一個元素, -2 表示列表的倒數第二個元素,以此類推。<br>
           * 超出范圍的下標值不會引起錯誤。
           * 
           * @param key
           * @param start
           *            開始位置
           * @param end
           *            結束如果為負數,則尾部開始計算
           * @return result 一個列表,包含指定區間內的元素。
           */
          public static List<String> lrange(String key, long start, long end) {
              List<String> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.lrange(key, start, end);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 對一個列表進行修剪(trim),就是說,讓列表只保留指定區間內的元素,不在指定區間之內的元素都將被刪除。<br>
           * 下標(index)參數 start 和 stop 都以 0 為底,也就是說,以 0 表示列表的第一個元素,以 1 表示列表的第二個元素,以此類推。<br>
           * 你也可以使用負數下標,以 -1 表示列表的最后一個元素, -2 表示列表的倒數第二個元素,以此類推。<br>
           * 當 key 不是列表類型時,返回一個錯誤。<br>
           * 超出范圍的下標值不會引起錯誤。
           * 
           * @param key
           * @param start
           *            開始位置
           * @param end
           *            結束位置,則尾部開始計算
           * @return result 命令執行成功時,返回 ok 。
           */
          public static String ltrim(String key, long start, long end) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.ltrim(key, start, end);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回列表 key 中,下標為 index 的元素。<br>
           * 下標(index)參數 start 和 stop 都以 0 為底,也就是說,以 0 表示列表的第一個元素,以 1 表示列表的第二個元素,以此類推。<br>
           * 你也可以使用負數下標,以 -1 表示列表的最后一個元素, -2 表示列表的倒數第二個元素,以此類推。<br>
           * 如果 key 不是列表類型,返回一個錯誤。
           * 
           * @param key
           * @param index
           *            下標
           * @return result 列表中下標為 index 的元素。 如果 index 參數的值不在列表的區間范圍內,返回 nil 。
           */
          public static String lindex(String key, long index) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.lindex(key, index);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 將列表 key 下標為 index 的元素的值設置為 value 。<br>
           * 當 index 參數超出范圍,或對一個空列表( key 不存在)進行 LSET 時,返回一個錯誤。<br>
           * 關于列表下標的更多信息,請參考 LINDEX 命令。
           * 
           * @param key
           * @param index
           *            下標
           * @param value
           *            值
           * @return result 操作成功返回 ok ,否則返回錯誤信息。
           */
          public static String lset(String key, long index, String value) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.lset(key, index, value);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 根據參數 count 的值,移除列表中與參數 value 相等的元素。<br>
           * count 的值可以是以下幾種:<br>
           * count > 0 : 從表頭開始向表尾搜索,移除與 value 相等的元素,數量為 count 。<br>
           * count < 0 : 從表尾開始向表頭搜索,移除與 value 相等的元素,數量為 count 的絕對值。<br>
           * count = 0 : 移除表中所有與 value 相等的值。
           * 
           * @param key
           * @param count
           *            要刪除的數量,如果為負數則從List的尾部檢查并刪除符合的記錄
           * @param value
           *            要匹配刪除的值
           * @return result 被移除元素的數量。 因為不存在的 key 被視作空表(empty list),所以當 key 不存在時, LREM
           *         命令總是返回 0 。
           */
          public static Long lrem(String key, long count, String value) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.lrem(key, count, value);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 移除并返回列表 key 的頭元素。
           * 
           * @param key
           * @return result 列表的頭元素。 當 key 不存在時,返回 nil 。
           */
          public static String lpop(String key) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.lpop(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 移除并返回列表 key 的尾元素。
           * 
           * @param key
           * @return result 列表的尾元素。 當 key 不存在時,返回 nil 。
           */
          public static String rpop(String key) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.rpop(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 將值 value 插入到列表 key 當中,位于值 pivot 之前或之后。<br>
           * 當 pivot 不存在于列表 key 時,不執行任何操作。<br>
           * 當 key 不存在時, key 被視為空列表,不執行任何操作。<br>
           * 如果 key 不是列表類型,返回一個錯誤。
           * 
           * @param key
           * @param where
           *            前面插入或后面插入
           * @param pivot
           *            相對位置的內容
           * @param value
           *            插入的內容
           * @return result 如果命令執行成功,返回插入操作完成之后,列表的長度。 如果沒有找到 pivot ,返回 -1 。 如果 key
           *         不存在或為空列表,返回 0 。
           */
          public static Long linsert(String key, LIST_POSITION where, String pivot, String value) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.linsert(key, where, pivot, value);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /** ========================對存儲結構為Set(集合)類型的操作======================== */
      
          /**
           * 將一個或多個 member 元素加入到集合 key 當中,已經存在于集合的 member 元素將被忽略。<br>
           * 假如 key 不存在,則創建一個只包含 member 元素作成員的集合。<br>
           * 當 key 不是集合類型時,返回一個錯誤。
           * 
           * @param key
           * @param member
           *            元素
           * @return result 被添加到集合中的新元素的數量,不包括被忽略的元素。
           */
          public static Long sadd(String key, String... member) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.sadd(key, member);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回集合 key 中的所有成員。 不存在的 key 被視為空集合。
           * 
           * @param key
           * @return result 集合中的所有成員。
           */
          public static Set<String> smembers(String key) {
              Set<String> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.smembers(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 移除集合 key 中的一個或多個 member 元素,不存在的 member 元素會被忽略。
           * 
           * 當 key 不是集合類型,返回一個錯誤。
           * 
           * @param key
           * @param member
           *            元素
           * @return result 被成功移除的元素的數量,不包括被忽略的元素。
           */
          public static Long srem(String key, String member) {
              ShardedJedis shardedJedis = getShardedJedis();
      
              Long result = null;
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.srem(key, member);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
      
              } finally {
                  shardedJedis.close();
              }
              return result;
          }
      
          /**
           * 移除并返回集合中的一個隨機元素。<br>
           * 如果只想獲取一個隨機元素,但不想該元素從集合中被移除的話,可以使用 SRANDMEMBER 命令。
           * 
           * @param key
           * @return result 被移除的隨機元素。 當 key 不存在或 key 是空集時,返回 nil 。
           */
          public static String spop(String key) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.spop(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回集合中的一個隨機元素。
           * 
           * @param key
           * @return result 返回一個元素;如果集合為空,返回 nil 。
           */
          public static String srandmember(String key) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.srandmember(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回集合中的count個隨機元素。<br>
           * 如果 count 為正數,且小于集合基數,那么命令返回一個包含 count 個元素的數組,數組中的元素各不相同。如果 count
           * 大于等于集合基數,那么返回整個集合。<br>
           * 如果 count 為負數,那么命令返回一個數組,數組中的元素可能會重復出現多次,而數組的長度為 count 的絕對值。
           * 
           * @param key
           * @param count
           *            元素個數
           * @return result 返回一個數組;如果集合為空,返回空數組。
           */
          public static List<String> srandmember(String key, int count) {
              List<String> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.srandmember(key, count);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回集合 key 的基數(集合中元素的數量)。
           * 
           * @param key
           * @return result 集合的基數。 當 key 不存在時,返回 0 。
           */
          public static Long scard(String key) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.scard(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 判斷 member 元素是否集合 key 的成員。
           * 
           * @param key
           * @param member
           *            元素
           * @return result 如果member元素是集合的成員,返回 1。如果 member元素不是集合的成員,或 key不存在,返回 0。
           */
          public static Boolean sismember(String key, String member) {
              Boolean result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.sismember(key, member);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /** ====================對存儲結構為SortedSet(有序集合)類型的操作==================== */
      
          /**
           * 將一個或多個 member 元素及其 score 值加入到有序集 key 當中。<br>
           * 如果某個 member 已經是有序集的成員,那么更新這個 member 的 score 值,并通過重新插入這個 member 元素,來保證該
           * member 在正確的位置上。<br>
           * score 值可以是整數值或雙精度浮點數。<br>
           * 如果 key 不存在,則創建一個空的有序集并執行 ZADD 操作。
           * 
           * @param key
           * @param score
           * @param member
           *            成員
           * @return result 被成功添加的新成員的數量,不包括那些被更新的、已經存在的成員。
           */
          public static Long zadd(String key, double score, String member) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zadd(key, score, member);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回有序集 key 中,指定區間內的成員。 其中成員的位置按 score 值遞增(從小到大)來排序。<br>
           * 下標參數 start 和 stop 都以 0 為底,也就是說,以 0 表示有序集第一個成員,以 1 表示有序集第二個成員,以此類推。<br>
           * 你也可以使用負數下標,以 -1 表示最后一個成員, -2 表示倒數第二個成員,以此類推。<br>
           * 超出范圍的下標并不會引起錯誤。
           * 
           * @param key
           * @param start
           *            開始位置
           * @param end
           *            結束位置
           * @return result 指定區間內,帶有 score 值(可選)的有序集成員的列表。
           */
          public static Set<String> zrange(String key, int start, int end) {
              Set<String> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zrange(key, start, end);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回有序集 key 中,指定區間內的成員。 其中成員的位置按 score 值遞減(從大到小)來排列。<br>
           * 下標參數 start 和 stop 都以 0 為底,也就是說,以 0 表示有序集第一個成員,以 1 表示有序集第二個成員,以此類推。<br>
           * 你也可以使用負數下標,以 -1 表示最后一個成員, -2 表示倒數第二個成員,以此類推。<br>
           * 超出范圍的下標并不會引起錯誤。
           * 
           * @param key
           * @param start
           *            開始位置
           * @param end
           *            結束位置
           * @return result 指定區間內,帶有 score 值(可選)的有序集成員的列表。
           */
          public static Set<String> zrevrange(String key, int start, int end) {
              Set<String> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zrevrange(key, start, end);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 移除有序集 key 中的一個或多個成員,不存在的成員將被忽略。 當 key 存在但不是有序集類型時,返回一個錯誤。
           * 
           * @param key
           * @param member
           *            成員
           * @return result 被成功移除的成員的數量,不包括被忽略的成員。
           */
          public static Long zrem(String key, String... member) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zrem(key, member);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 為有序集 key 的成員 member 的 score 值加上增量 。<br>
           * 當 key 不存在,或 member 不是 key 的成員時, ZINCRBY key increment member 等同于 ZADD key
           * increment member 。<br>
           * 當 key 不是有序集類型時,返回一個錯誤。
           * 
           * @param key
           * @param score
           *            score 值可以是整數值或雙精度浮點數。
           * @param member
           *            成員
           * @return result member成員的新 score 值,以字符串形式表示。
           */
          public static Double zincrby(String key, double score, String member) {
              Double result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zincrby(key, score, member);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回有序集 key 中成員 member 的排名。其中有序集成員按 score 值遞增(從小到大)順序排列。<br>
           * 排名以 0 為底,也就是說, score 值最小的成員排名為 0 。
           * 
           * @param key
           * @param member
           *            成員
           * @return result 如果 member 是有序集 key 的成員,返回 member 的排名。 如果 member 不是有序集 key
           *         的成員,返回 nil 。
           */
          public static Long zrank(String key, String member) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zrank(key, member);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回有序集 key 中成員 member 的排名。其中有序集成員按 score 值遞減(從大到小)排序。<br>
           * 排名以 0 為底,也就是說, score 值最大的成員排名為 0 。
           * 
           * @param key
           * @param member
           *            成員
           * @return result 如果 member 是有序集 key 的成員,返回 member 的排名。 如果 member 不是有序集 key
           *         的成員,返回 nil 。
           */
          public static Long zrevrank(String key, String member) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zrevrank(key, member);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回有序集 key 的基數。
           * 
           * @param key
           * @return result 當 key 存在且是有序集類型時,返回有序集的基數。 當 key 不存在時,返回 0 。
           */
          public static Long zcard(String key) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zcard(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回有序集 key 中,成員 member 的 score 值。<br>
           * 如果 member 元素不是有序集 key 的成員,或 key 不存在,返回 nil 。
           * 
           * @param key
           * @param member
           *            成員
           * @return result member 成員的 score 值,以字符串形式表示。
           */
          public static Double zscore(String key, String member) {
              Double result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zscore(key, member);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回有序集 key 中,所有 score 值介于 min 和 max 之間(包括等于 min 或 max )的成員。有序集成員按 score
           * 值遞增(從小到大)次序排列。
           * 
           * @param key
           * @param min
           *            最小分值
           * @param max
           *            最大分值
           * @return result 指定區間內,帶有 score 值(可選)的有序集成員的列表。
           */
          public static Set<String> zrangeByScore(String key, double min, double max) {
              Set<String> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zrangeByScore(key, min, max);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回有序集 key 中,所有 score 值介于 min 和 max 之間(包括等于 min 或 max )的成員。有序集成員按 score
           * 值遞增(從小到大)次序排列。<br>
           * 可選的 LIMIT 參數指定返回結果的數量及區間(就像SQL中的 SELECT LIMIT offset, count ),注意當 offset
           * 很大時,定位 offset 的操作可能需要遍歷整個有序集,此過程最壞復雜度為 O(N) 時間。
           * 
           * @param key
           * @param min
           *            最小分值
           * @param max
           *            最大分值
           * @param offset
           *            要跳過的元素數量
           * @param count
           *            跳過offset個指定的元素之后,要返回多少個對象
           * @return result 指定區間內,帶有 score 值(可選)的有序集成員的列表。
           */
          public static Set<String> zrangeByScore(String key, double min, double max, int offset, int count) {
              Set<String> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zrangeByScore(key, min, max, offset, count);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回有序集 key 中, score 值在 min 和 max 之間(默認包括 score 值等于 min 或 max )的成員的數量。
           * 
           * @param key
           * @param min
           *            最小分值
           * @param max
           *            最大分值
           * @return result score 值在 min 和 max 之間的成員的數量。
           */
          public static Long zcount(String key, double min, double max) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zcount(key, min, max);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回有序集 key 中, score 值介于 max 和 min 之間(默認包括等于 max 或 min )的所有的成員。有序集成員按 score
           * 值遞減(從大到小)的次序排列。
           * 
           * @param key
           * @param min
           *            最小分值
           * @param max
           *            最大分值
           * @return result 指定區間內,帶有 score 值(可選)的有序集成員的列表。
           */
          public static Set<String> zrevrangeByScore(String key, double max, double min) {
              Set<String> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zrevrangeByScore(key, max, min);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 返回有序集 key 中, score 值介于 max 和 min 之間(默認包括等于 max 或 min )的所有的成員。有序集成員按 score
           * 值遞減(從大到小)的次序排列。
           * 
           * @param key
           * @param min
           *            最小分值
           * @param max
           *            最大分值
           * @param offset
           *            要跳過的元素數量
           * @param count
           *            跳過offset個指定的元素之后,要返回多少個對象
           * @return result 指定區間內,帶有 score 值(可選)的有序集成員的列表。
           */
          public static Set<String> zrevrangeByScore(String key, double max, double min, int offset, int count) {
              Set<String> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zrevrangeByScore(key, max, min, offset, count);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 移除有序集 key 中,指定排名(rank)區間內的所有成員。<br>
           * 區間分別以下標參數 start 和 stop 指出,包含 start 和 stop 在內。<br>
           * 下標參數 start 和 stop 都以 0 為底,也就是說,以 0 表示有序集第一個成員,以 1 表示有序集第二個成員,以此類推。<br>
           * 你也可以使用負數下標,以 -1 表示最后一個成員, -2 表示倒數第二個成員,以此類推。
           * 
           * @param key
           * @param start
           *            開始位置
           * @param end
           *            結束位置
           * @return result 被移除成員的數量。
           */
          public static Long zremrangeByRank(String key, int start, int end) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zremrangeByRank(key, start, end);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /**
           * 移除有序集 key 中,所有 score 值介于 min 和 max 之間(包括等于 min 或 max )的成員。
           * 
           * @param key
           * @param start
           *            開始分值
           * @param end
           *            結束分值
           * @return result 被移除成員的數量。
           */
          public static Long zremrangeByScore(String key, double start, double end) {
              Long result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zremrangeByScore(key, start, end);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          /** ===============================其它方法=============================== */
      
          public static Set<Tuple> zrangeWithScores(String key, int start, int end) {
              Set<Tuple> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zrangeWithScores(key, start, end);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          public static Set<Tuple> zrevrangeWithScores(String key, int start, int end) {
              Set<Tuple> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zrevrangeWithScores(key, start, end);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          public static Set<Tuple> zrangeByScoreWithScores(String key, double min, double max) {
              Set<Tuple> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zrangeByScoreWithScores(key, min, max);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          public static Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min) {
              Set<Tuple> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zrevrangeByScoreWithScores(key, max, min);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          public static Set<Tuple> zrangeByScoreWithScores(String key, double min, double max, int offset, int count) {
              Set<Tuple> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zrangeByScoreWithScores(key, min, max, offset, count);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          public static Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count) {
              Set<Tuple> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.zrevrangeByScoreWithScores(key, max, min, offset, count);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          public static Jedis getShard(String key) {
              Jedis result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.getShard(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          public static JedisShardInfo getShardInfo(String key) {
              JedisShardInfo result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.getShardInfo(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          public static String getKeyTag(String key) {
              String result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.getKeyTag(key);
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          public static Collection<JedisShardInfo> getAllShardInfo() {
              Collection<JedisShardInfo> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.getAllShardInfo();
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          public static Collection<Jedis> getAllShards() {
              Collection<Jedis> result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.getAllShards();
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
          public static ShardedJedisPipeline pipelined() {
              ShardedJedisPipeline result = null;
      
              ShardedJedis shardedJedis = getShardedJedis();
              if (shardedJedis == null) {
                  return result;
              }
      
              try {
                  result = shardedJedis.pipelined();
              } catch (Exception e) {
                  LOGGER.error(e.getMessage(), e);
              } finally {
                  shardedJedis.close();
              }
      
              return result;
          }
      
      }


      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:context="http://www.springframework.org/schema/context"
          xmlns:aop="http://www.springframework.org/schema/aop"
          xmlns:tx="http://www.springframework.org/schema/tx"
          xmlns:util="http://www.springframework.org/schema/util"
          xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd"
          default-lazy-init="true">
          <!-- 用于配置Redis -->
          
          <util:map id="redisConfig">
              <entry key="host" value="10.5.4.146"/>
              <entry key="port" value="6379"/>
              <entry key="password" value=""/>
              <entry key="timeout" value="1500"/>
          </util:map>
          
          <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
              <property name="maxIdle" value="1500"/>
              <property name="testOnBorrow" value="true"/>
              <property name="testOnReturn" value="true"/>
          </bean>
          
          <bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
              <property name="poolConfig" ref="jedisPoolConfig"/>
              <property name="hostName" value="#{redisConfig.host}"/>
              <property name="port" value="#{redisConfig.port}"/>
              <property name="password" value="#{redisConfig.password}"/>
              <property name="timeout" value="#{redisConfig.timeout}"/>
          </bean>
          
          <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
              <property name="connectionFactory" ref="connectionFactory" />
          </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="#{redisConfig.host}"/>
                          <constructor-arg name="port" value="#{redisConfig.port}"/>
                          <constructor-arg name="timeout" value="#{redisConfig.timeout}"/>
                      </bean>
                  </list>
              </constructor-arg>
          </bean>
      
          <bean id="jedisPool" class="redis.clients.jedis.JedisPool" scope="singleton">
              <constructor-arg ref="jedisPoolConfig"/>
              <constructor-arg value="#{redisConfig.host}"/>
              <constructor-arg value="#{redisConfig.port}" type="int"/>
              <constructor-arg name="timeout" value="#{redisConfig.timeout}" type="int"/>
          </bean>
          
          <bean class="redis.RedisClientTemplate" lazy-init="false">
              <property name="shardedJedisPool" ref="shardedJedisPool"/>
              <property name="jedisPool" ref="jedisPool"/>
          </bean>
          
      </beans>



      ??
      posted @ 2016-03-03 20:00  vipbooks  閱讀(333)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 国产95在线 | 欧美| 亚洲国产日韩一区三区| 极品美女自拍偷精品视频| 免费无码又爽又刺激网站直播| 在线看国产精品自拍内射| 亚洲AV成人片不卡无码| 人人妻人人澡人人爽不卡视频| 99er热精品视频| 丰满无码人妻热妇无码区| www插插插无码免费视频网站| 婷婷色香五月综合缴缴情香蕉| 国产精欧美一区二区三区| 婷婷久久香蕉五月综合加勒比| 日韩精品中文字幕第二页| 亚洲人精品午夜射精日韩| 欧美日韩高清在线观看| 国产欧洲欧洲久美女久久| 在线看免费无码av天堂| 久久99精品久久久久麻豆| 日韩免费码中文在线观看| 亚洲精品成人片在线观看精品字幕| 久久久久国色av免费观看性色 | 秋霞人妻无码中文字幕| 中文字幕久久国产精品| 日韩中文字幕v亚洲中文字幕| 亚洲色大成网站WWW尤物| 国产二区三区不卡免费| 国产 麻豆 日韩 欧美 久久| 国产福利永久在线视频无毒不卡| 在线观看AV永久免费| 中国极品少妇videossexhd| 亚洲区日韩精品中文字幕| 亚洲精品中文字幕一二三| 精品国产成人三级在线观看| 鹿泉市| 人妻少妇精品无码专区二区| 亚洲性美女一区二区三区| 最新亚洲人成无码网站欣赏网| 亚洲av成人在线一区| 国产精品无码无片在线观看3d| 成人国产精品中文字幕|