Java Code Examples for redis.clients.jedis.Jedis#zrangeWithScores()

The following examples show how to use redis.clients.jedis.Jedis#zrangeWithScores() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JedisUtil.java    From scaffold-cloud with MIT License 6 votes vote down vote up
/**
 * 获取所有sorted set中的成员以及分值
 *
 * @param key 键值
 * @return 排序的map
 */
public static LinkedHashMap<String, Double> zgetAll(String key) {
    LinkedHashMap<String, Double> result = null;
    Jedis jedis = null;
    try {
        jedis = getResource();
        result = new LinkedHashMap<>();
        Set<Tuple> sortedSet = jedis.zrangeWithScores(key, 0, -1);
        for (Tuple tuple : sortedSet) {
            result.put(tuple.getElement(), tuple.getScore());
        }
    } catch (Exception e) {
        logger.warn("zrangeWithScores {} = {}", key, e);
    } finally {
        close(jedis);
    }
    return result;
}
 
Example 2
Source File: JedisUtil.java    From scaffold-cloud with MIT License 6 votes vote down vote up
/**
 * 获取所有sorted set中的排名第一的成员
 *
 * @param key 键值
 * @return 排序的map
 */
public static LinkedHashMap<String, Double> zgetFirst(String key) {
    LinkedHashMap<String, Double> result = null;
    Jedis jedis = null;
    try {
        jedis = getResource();
        result = new LinkedHashMap<>();
        Set<Tuple> sortedSet = jedis.zrangeWithScores(key, 0, 0);
        for (Tuple tuple : sortedSet) {
            result.put(tuple.getElement(), tuple.getScore());
        }
    } catch (Exception e) {
        logger.warn("zrangeWithScores {} = {}", key, e);
    } finally {
        close(jedis);
    }
    return result;
}
 
Example 3
Source File: JedisUtil.java    From scaffold-cloud with MIT License 5 votes vote down vote up
/**
 * 获取sortedset中的 索引范围的
 *
 * @param key
 * @param start
 * @param end
 * @return
 */
public static Set<Tuple> zrangeWithScore(String key, Long start, Long end) {
    Set<Tuple> result = null;
    Jedis jedis = null;
    try {
        jedis = getResource();
        result = jedis.zrangeWithScores(key, start, end);
    } catch (Exception e) {
        logger.warn("zrangeWithScore key = {}, start = {}, end = {}", key, start, end, e);
    } finally {
        close(jedis);
    }
    return result;
}
 
Example 4
Source File: Main.java    From JavaBase with MIT License 4 votes vote down vote up
private void transferZSet(String key, Jedis originJedis, Jedis targetJedis) {
  Set<Tuple> tuples = originJedis.zrangeWithScores(key, 0, -1);
  Map<String, Double> collect = tuples.stream()
      .collect(Collectors.toMap(Tuple::getElement, Tuple::getScore));
  targetJedis.zadd(key, collect);
}
 
Example 5
Source File: DefaultRedis.java    From craft-atom with MIT License 4 votes vote down vote up
private Map<String, Double> zrangewithscores0(Jedis j, String key, long start, long stop) {
	Set<Tuple> set = j.zrangeWithScores(key, start, stop);
	Map<String, Double> map = convert4zrangewithscores(set);
	return map;
}