public List<String> zQueryByRank(String cacheKey, long startIndex, long endIndex, 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.zrange(cacheKey, startIndex, endIndex); } else { valueSet = jedis.zrevrange(cacheKey, startIndex, endIndex); } valueList = new ArrayList<String>(valueSet); } catch (Exception e) { throw e; } finally { if (jedis != null) { jedisPool.returnResource(jedis); } } return valueList; }
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; }