@Override public Long zAdd(byte[] key, Set<Tuple> tuples) { List<Object> params = new ArrayList<Object>(tuples.size()*2+1); params.add(key); for (Tuple entry : tuples) { params.add(BigDecimal.valueOf(entry.getScore()).toPlainString()); params.add(entry.getValue()); } return write(key, StringCodec.INSTANCE, RedisCommands.ZADD, params.toArray()); }
@Override public Long zAdd(byte[] key, Set<Tuple> tuples) { List<Object> params = new ArrayList<Object>(tuples.size()*2+1); params.add(key); for (Tuple entry : tuples) { params.add(BigDecimal.valueOf(entry.getScore()).toPlainString()); params.add(entry.getValue()); } return write(key, StringCodec.INSTANCE, RedisCommands.ZADD, params.toArray()); }
@Override public Long zAdd(byte[] key, Set<Tuple> tuples) { List<Object> params = new ArrayList<Object>(tuples.size()*2+1); params.add(key); for (Tuple entry : tuples) { params.add(BigDecimal.valueOf(entry.getScore()).toPlainString()); params.add(entry.getValue()); } return write(key, StringCodec.INSTANCE, RedisCommands.ZADD, params.toArray()); }
public static List<Object> toObjects(Set<Tuple> tuples) { List<Object> tupleArgs = new ArrayList<>(tuples.size() * 2); for (Tuple tuple : tuples) { tupleArgs.add(tuple.getScore()); tupleArgs.add(tuple.getValue()); } return tupleArgs; }
/** * Constructs a new <code>DefaultStringTuple</code> instance. * * @param tuple * @param valueAsString */ public DefaultStringTuple(Tuple tuple, String valueAsString) { super(tuple.getValue(), tuple.getScore()); this.valueAsString = valueAsString; }
/** * Map a {@link Set} of {@link Tuple} by {@code value} to its {@code score}. * * @param tuples must not be {@literal null}. * @return * @since 2.0 */ public static Map<byte[], Double> toTupleMap(Set<Tuple> tuples) { Assert.notNull(tuples, "Tuple set must not be null!"); Map<byte[], Double> args = new LinkedHashMap<>(tuples.size(), 1); Set<Double> scores = new HashSet<>(tuples.size(), 1); boolean isAtLeastJedis24 = JedisVersionUtil.atLeastJedis24(); for (Tuple tuple : tuples) { if (!isAtLeastJedis24) { if (scores.contains(tuple.getScore())) { throw new UnsupportedOperationException( "Bulk add of multiple elements with the same score is not supported. Add the elements individually."); } scores.add(tuple.getScore()); } args.put(tuple.getValue(), tuple.getScore()); } return args; }
/** * Get elements in {@literal range} from sorted set. * * @param key must not be {@literal null}. * @param range must not be {@literal null}. * @param limit must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/zrangebyscore">Redis Documentation: ZRANGEBYSCORE</a> */ default Flux<ByteBuffer> zRangeByScore(ByteBuffer key, Range<Double> range, Limit limit) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); Assert.notNull(limit, "Limit must not be null!"); return zRangeByScore(Mono.just(ZRangeByScoreCommand.scoresWithin(range).from(key).limitTo(limit))) // .flatMap(CommandResponse::getOutput) // .map(tuple -> ByteBuffer.wrap(tuple.getValue())); }
/** * Get elements in {@literal range} from sorted set in reverse {@literal score} ordering. * * @param key must not be {@literal null}. * @param range must not be {@literal null}. * @param limit must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/zrevrangebyscore">Redis Documentation: ZREVRANGEBYSCORE</a> */ default Flux<ByteBuffer> zRevRangeByScore(ByteBuffer key, Range<Double> range, Limit limit) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); Assert.notNull(limit, "Limit must not be null!"); return zRangeByScore(Mono.just(ZRangeByScoreCommand.reverseScoresWithin(range).from(key).limitTo(limit))) // .flatMap(CommandResponse::getOutput) // .map(tuple -> ByteBuffer.wrap(tuple.getValue())); }
/** * Get elements in {@literal range} from sorted set. * * @param key must not be {@literal null}. * @param range must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/zrangebyscore">Redis Documentation: ZRANGEBYSCORE</a> */ default Flux<ByteBuffer> zRangeByScore(ByteBuffer key, Range<Double> range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); return zRangeByScore(Mono.just(ZRangeByScoreCommand.scoresWithin(range).from(key))) // .flatMap(CommandResponse::getOutput) // .map(tuple -> ByteBuffer.wrap(tuple.getValue())); }
/** * Get elements in {@literal range} from sorted set in reverse {@literal score} ordering. * * @param key must not be {@literal null}. * @param range must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/zrevrangebyscore">Redis Documentation: ZREVRANGEBYSCORE</a> */ default Flux<ByteBuffer> zRevRangeByScore(ByteBuffer key, Range<Double> range) { Assert.notNull(key, "Key must not be null!"); return zRangeByScore(Mono.just(ZRangeByScoreCommand.reverseScoresWithin(range).from(key))) // .flatMap(CommandResponse::getOutput) // .map(tuple -> ByteBuffer.wrap(tuple.getValue())); }
public StringTuple convert(Tuple source) { return new DefaultStringTuple(source, serializer.deserialize(source.getValue())); } }
/** * Constructs a new <code>DefaultStringTuple</code> instance. * * @param tuple * @param valueAsString */ public DefaultStringTuple(Tuple tuple, String valueAsString) { super(tuple.getValue(), tuple.getScore()); this.valueAsString = valueAsString; }
public static List<Object> toObjects(Set<Tuple> tuples) { List<Object> tupleArgs = new ArrayList<>(tuples.size() * 2); for (Tuple tuple : tuples) { tupleArgs.add(tuple.getScore()); tupleArgs.add(tuple.getValue()); } return tupleArgs; }
/** * Get elements in {@literal range} from sorted set. * * @param key must not be {@literal null}. * @param range must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/zrange">Redis Documentation: ZRANGE</a> */ default Flux<ByteBuffer> zRange(ByteBuffer key, Range<Long> range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); return zRange(Mono.just(ZRangeCommand.valuesWithin(range).from(key))) // .flatMap(CommandResponse::getOutput).map(tuple -> ByteBuffer.wrap(tuple.getValue())); }
/** * Get elements in {@literal range} from sorted set in reverse {@literal score} ordering. * * @param key must not be {@literal null}. * @param range must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/zrevrange">Redis Documentation: ZREVRANGE</a> */ default Flux<ByteBuffer> zRevRange(ByteBuffer key, Range<Long> range) { Assert.notNull(key, "Key must not be null!"); return zRange(Mono.just(ZRangeCommand.reverseValuesWithin(range).from(key))).flatMap(CommandResponse::getOutput) .map(tuple -> ByteBuffer.wrap(tuple.getValue())); }
private TypedTuple<V> readTypedTuple(Tuple raw) { return new DefaultTypedTuple<>(readValue(ByteBuffer.wrap(raw.getValue())), raw.getScore()); } }
@SuppressWarnings({ "unchecked", "rawtypes" }) private Set<TypedTuple<V>> convertTupleValues(Set<Tuple> rawValues, @Nullable RedisSerializer valueSerializer) { Set<TypedTuple<V>> set = new LinkedHashSet<>(rawValues.size()); for (Tuple rawValue : rawValues) { Object value = rawValue.getValue(); if (valueSerializer != null) { value = valueSerializer.deserialize(rawValue.getValue()); } set.add(new DefaultTypedTuple(value, rawValue.getScore())); } return set; }
@Override public Long zAdd(byte[] key, Set<Tuple> tuples) { List<Object> params = new ArrayList<Object>(tuples.size()*2+1); params.add(key); for (Tuple entry : tuples) { params.add(BigDecimal.valueOf(entry.getScore()).toPlainString()); params.add(entry.getValue()); } return write(key, StringCodec.INSTANCE, RedisCommands.ZADD, params.toArray()); }