Java 类org.springframework.data.redis.core.ZSetOperations.TypedTuple 实例源码

项目:redis-admin    文件:AbstractOperations.java   
@SuppressWarnings("unchecked")
Set<Tuple> rawTupleValues(Set<TypedTuple<V>> values) {
    if (values == null) {
        return null;
    }
    Set<Tuple> rawTuples = new LinkedHashSet<Tuple>(values.size());
    for (TypedTuple<V> value : values) {
        byte[] rawValue;
        if (valueSerializer() == null && value.getValue() instanceof byte[]) {
            rawValue = (byte[]) value.getValue();
        } else {
            rawValue = valueSerializer().serialize(value.getValue());
        }
        rawTuples.add(new DefaultTuple(rawValue, value.getScore()));
    }
    return rawTuples;
}
项目:redis-admin    文件:DefaultZSetOperations.java   
@Override
public Cursor<TypedTuple<V>> scan(K key, final ScanOptions options) {

    final byte[] rawKey = rawKey(key);
    Cursor<Tuple> cursor = execute(new RedisCallback<Cursor<Tuple>>() {

        @Override
        public Cursor<Tuple> doInRedis(RedisConnection connection) throws DataAccessException {
            connection.select(dbIndex);
            return connection.zScan(rawKey, options);
        }
    }, true);

    return new ConvertingCursor<Tuple, TypedTuple<V>>(cursor, new Converter<Tuple, TypedTuple<V>>() {

        @Override
        public TypedTuple<V> convert(Tuple source) {
            return deserializeTuple(source);
        }
    });
}
项目:redis-admin    文件:RedisDao.java   
public void addZSET(String serverName, int dbIndex, String key,
        double[] scores, String[] members) {
    RedisTemplate<String, Object> redisTemplate = redisTemplateFactory.getRedisTemplate(serverName);
    redisConnectionDbIndex.set(dbIndex);
    Set<TypedTuple<Object>> zset = new HashSet<TypedTuple<Object>>();
    for(int i=0;i<members.length;i++) {
        final Object ob = members[i];
        final double sc = scores[i];
        zset.add(new TypedTuple () {
            private Object v;
            private double score;
            {
                v = ob;
                score = sc;
            }
            @Override
            public int compareTo(Object o) {
                if(o == null) return 1;
                if(o instanceof TypedTuple) {
                    TypedTuple tto = (TypedTuple) o;
                    return this.getScore()-tto.getScore() >= 0?1:-1;
                }
                return 1;
            }
            @Override
            public Object getValue() {
                return v;
            }
            @Override
            public Double getScore() {
                return score;
            }
        });
    }
    redisTemplate.opsForZSet().add(key, zset);
}
项目:redis-admin    文件:DefaultTypedTuple.java   
@Override
public int compareTo(TypedTuple<V> o) {

    if (o == null) {
        return compareTo(Double.valueOf(0));
    }

    return compareTo(o.getScore());
}
项目:redis-admin    文件:AbstractOperations.java   
Set<TypedTuple<V>> deserializeTupleValues(Collection<Tuple> rawValues) {
    if (rawValues == null) {
        return null;
    }
    Set<TypedTuple<V>> set = new LinkedHashSet<TypedTuple<V>>(rawValues.size());
    for (Tuple rawValue : rawValues) {
        set.add(deserializeTuple(rawValue));
    }
    return set;
}
项目:redis-admin    文件:AbstractOperations.java   
@SuppressWarnings({ "unchecked", "rawtypes" })
TypedTuple<V> deserializeTuple(Tuple tuple) {
    Object value = tuple.getValue();
    if (valueSerializer() != null) {
        value = valueSerializer().deserialize(tuple.getValue());
    }
    return new DefaultTypedTuple(value, tuple.getScore());
}
项目:redis-admin    文件:DefaultZSetOperations.java   
public Long add(K key, Set<TypedTuple<V>> tuples) {
    final byte[] rawKey = rawKey(key);
    final Set<Tuple> rawValues = rawTupleValues(tuples);

    return execute(new RedisCallback<Long>() {

        public Long doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.zAdd(rawKey, rawValues);
        }
    }, true);
}
项目:redis-admin    文件:DefaultZSetOperations.java   
public Set<TypedTuple<V>> rangeWithScores(K key, final long start, final long end) {
    final byte[] rawKey = rawKey(key);

    Set<Tuple> rawValues = execute(new RedisCallback<Set<Tuple>>() {

        public Set<Tuple> doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.zRangeWithScores(rawKey, start, end);
        }
    }, true);

    return deserializeTupleValues(rawValues);
}
项目:redis-admin    文件:DefaultZSetOperations.java   
public Set<TypedTuple<V>> reverseRangeWithScores(K key, final long start, final long end) {
    final byte[] rawKey = rawKey(key);

    Set<Tuple> rawValues = execute(new RedisCallback<Set<Tuple>>() {

        public Set<Tuple> doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.zRevRangeWithScores(rawKey, start, end);
        }
    }, true);

    return deserializeTupleValues(rawValues);
}
项目:redis-admin    文件:DefaultZSetOperations.java   
public Set<TypedTuple<V>> rangeByScoreWithScores(K key, final double min, final double max) {
    final byte[] rawKey = rawKey(key);

    Set<Tuple> rawValues = execute(new RedisCallback<Set<Tuple>>() {

        public Set<Tuple> doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.zRangeByScoreWithScores(rawKey, min, max);
        }
    }, true);

    return deserializeTupleValues(rawValues);
}
项目:redis-admin    文件:DefaultZSetOperations.java   
public Set<TypedTuple<V>> rangeByScoreWithScores(K key, final double min, final double max, final long offset,
        final long count) {
    final byte[] rawKey = rawKey(key);

    Set<Tuple> rawValues = execute(new RedisCallback<Set<Tuple>>() {

        public Set<Tuple> doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.zRangeByScoreWithScores(rawKey, min, max, offset, count);
        }
    }, true);

    return deserializeTupleValues(rawValues);
}
项目:redis-admin    文件:DefaultZSetOperations.java   
public Set<TypedTuple<V>> reverseRangeByScoreWithScores(K key, final double min, final double max) {
    final byte[] rawKey = rawKey(key);

    Set<Tuple> rawValues = execute(new RedisCallback<Set<Tuple>>() {

        public Set<Tuple> doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.zRevRangeByScoreWithScores(rawKey, min, max);

        }
    }, true);

    return deserializeTupleValues(rawValues);
}
项目:redis-admin    文件:DefaultZSetOperations.java   
public Set<TypedTuple<V>> reverseRangeByScoreWithScores(K key, final double min, final double max, final long offset,
        final long count) {
    final byte[] rawKey = rawKey(key);

    Set<Tuple> rawValues = execute(new RedisCallback<Set<Tuple>>() {

        public Set<Tuple> doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.zRevRangeByScoreWithScores(rawKey, min, max, offset, count);

        }
    }, true);

    return deserializeTupleValues(rawValues);
}
项目:redis-admin    文件:RValue.java   
public static Object creatZSetValue(Set<TypedTuple<Object>> values) {
    List<RValue> rValues = new ArrayList<RValue>();
    for(TypedTuple<Object> v:values) {
        rValues.add(new RValue(v.getScore(), v.getValue()));
    }
    return rValues;
}
项目:spring-boot-redis-auto-complete    文件:AutocompleteServiceImpl.java   
@Override
public List<AutocompleteData> complete(String word, double min, double max, int offset) {
    Assert.hasLength(word, "Word cannot be empty or null");

    String trimedWord = word.trim();
    int trimedWordLength = trimedWord.length();

    String key = keyRepository.getKey(trimedWord);

    List<AutocompleteData> autocompletes = new ArrayList<>();
    for (int i = trimedWordLength; i < offset; i++) {
        if (autocompletes.size() == offset) break;

        Set<TypedTuple<String>> rangeResultsWithScore = stringRedisTemplate
                .opsForZSet()
                .reverseRangeByScoreWithScores(key + i, min, max, 0, offset);
        if (rangeResultsWithScore.isEmpty()) continue;

        for (TypedTuple<String> typedTuple : rangeResultsWithScore) {
            if (autocompletes.size() == offset) break;

            String value = typedTuple.getValue();
            int minLength = Math.min(value.length(), trimedWordLength);
            if (!value.endsWith(DEFAULT_DELIMITER) || !value.startsWith(trimedWord.substring(0, minLength))) continue;
            autocompletes.add(new AutocompleteData(value.replace(DEFAULT_DELIMITER, ""), typedTuple.getScore().intValue()));
        }
    }
    Collections.sort(autocompletes);
    return autocompletes;
}
项目:redis-admin    文件:RedisDao.java   
public Object getZSET(String serverName, int dbIndex, String key) {
    RedisTemplate<String, Object> redisTemplate = redisTemplateFactory.getRedisTemplate(serverName);
    redisConnectionDbIndex.set(dbIndex);
    Set<TypedTuple<Object>> values = redisTemplate.opsForZSet().rangeWithScores(key, 0, 1000);
    return RValue.creatZSetValue(values);
}
项目:redis-admin    文件:DefaultBoundZSetOperations.java   
public Long add(Set<TypedTuple<V>> tuples) {
    return ops.add(getKey(), tuples);
}
项目:redis-admin    文件:DefaultBoundZSetOperations.java   
public Set<TypedTuple<V>> rangeByScoreWithScores(double min, double max) {
    return ops.rangeByScoreWithScores(getKey(), min, max);
}
项目:redis-admin    文件:DefaultBoundZSetOperations.java   
public Set<TypedTuple<V>> rangeWithScores(long start, long end) {
    return ops.rangeWithScores(getKey(), start, end);
}
项目:redis-admin    文件:DefaultBoundZSetOperations.java   
public Set<TypedTuple<V>> reverseRangeByScoreWithScores(double min, double max) {
    return ops.reverseRangeByScoreWithScores(getKey(), min, max);
}
项目:redis-admin    文件:DefaultBoundZSetOperations.java   
public Set<TypedTuple<V>> reverseRangeWithScores(long start, long end) {
    return ops.reverseRangeWithScores(getKey(), start, end);
}
项目:redis-admin    文件:DefaultBoundZSetOperations.java   
@Override
public Cursor<TypedTuple<V>> scan(ScanOptions options) {
    return ops.scan(getKey(), options);
}
项目:phone    文件:RedisClientSupport.java   
public Long putZSetAll(String key,Set<TypedTuple<Object>> tuples) throws CacheAccessException{
        try {
            return opsForZSet().add(key, tuples);
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            throw new CacheAccessException(ErrorCode.CONNECTION_CACHE_ERROR,e);
        }
    }
项目:phone    文件:RedisClientSupport.java   
public Set<TypedTuple<Object>> getZSet(String key,long start,long end) throws CacheAccessException{
        try {
            return opsForZSet().rangeWithScores(key, start, end);
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            throw new CacheAccessException(ErrorCode.CONNECTION_CACHE_ERROR,e);
        }
    }
项目:phone    文件:RedisClientSupport.java   
public Set<TypedTuple<Object>> getZSetReverse(String key,long start,long end) throws CacheAccessException{
        try {
            return opsForZSet().reverseRangeWithScores(key, start, end);
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            throw new CacheAccessException(ErrorCode.CONNECTION_CACHE_ERROR,e);
        }
    }
项目:phone    文件:RedisClientSupport.java   
public Set<TypedTuple<Object>> getZSetByScore(String key,double min,double max) throws CacheAccessException{
        try {
            return opsForZSet().rangeByScoreWithScores(key, min, max);
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            throw new CacheAccessException(ErrorCode.CONNECTION_CACHE_ERROR,e);
        }
    }
项目:phone    文件:RedisClientSupport.java   
public Set<TypedTuple<Object>> getZSetByScoreReverse(String key,double min,double max) throws CacheAccessException{
        try {
            return opsForZSet().reverseRangeByScoreWithScores(key, min, max);
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            throw new CacheAccessException(ErrorCode.CONNECTION_CACHE_ERROR,e);
        }
    }