コード例 #1
0
ファイル: RedisTemplate.java プロジェクト: wufuwei/dubbox
 /**
  * 获得排序集合
  *
  * @param key
  * @param startScore
  * @param endScore
  * @param orderByDesc
  * @return
  */
 public Set<String> getSoredSet(String key, long startScore, long endScore, boolean orderByDesc) {
   ShardedJedis shardedJedis = null;
   try {
     shardedJedis = slaveShardedJedisPool.getResource();
     if (orderByDesc) {
       return shardedJedis.zrevrangeByScore(key, endScore, startScore);
     } else {
       return shardedJedis.zrangeByScore(key, startScore, endScore);
     }
   } catch (Exception ex) {
     logger.error("getSoredSet error.", ex);
   } finally {
     returnResource(shardedJedis);
   }
   return null;
 }
コード例 #2
0
 public List<String> zQueryByScore(String cacheKey, double minScore, double maxScore, Order order)
     throws Exception {
   ShardedJedis jedis = null;
   List<String> valueList = null;
   try {
     jedis = jedisPool.getResource();
     Set<String> valueSet = null;
     if (order.equals(Order.Asc)) {
       valueSet = jedis.zrangeByScore(cacheKey, minScore, maxScore);
     } else {
       valueSet = jedis.zrevrangeByScore(cacheKey, maxScore, minScore);
     }
     valueList = new ArrayList<String>(valueSet);
   } catch (Exception e) {
     throw e;
   } finally {
     if (jedis != null) {
       jedisPool.returnResource(jedis);
     }
   }
   return valueList;
 }