Refine search
/** * Add a {@literal tuples} to a sorted set at {@literal key}, or update their score if it already exists. * * @param key must not be {@literal null}. * @param tuples must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/zadd">Redis Documentation: ZADD</a> */ default Mono<Long> zAdd(ByteBuffer key, Collection<? extends Tuple> tuples) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(tuples, "Tuples must not be null!"); return zAdd(Mono.just(ZAddCommand.tuples(tuples).to(key))).next().map(resp -> resp.getOutput().longValue()); }
/** * Get the size of sorted set with {@literal key}. * * @param key must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/zcard">Redis Documentation: ZCARD</a> */ default Mono<Long> zCard(ByteBuffer key) { Assert.notNull(key, "Key must not be null!"); return zCard(Mono.just(new KeyCommand(key))).next().map(NumericResponse::getOutput); }
/** * Count number of elements within sorted set with scores within {@link Range}. <br /> * <b>NOTE</b> please use {@link Double#NEGATIVE_INFINITY} for {@literal -inf} and {@link Double#POSITIVE_INFINITY} * for {@literal +inf}. * * @param key must not be {@literal null}. * @param range must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/zcount">Redis Documentation: ZCOUNT</a> */ default Mono<Long> zCount(ByteBuffer key, Range<Double> range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); return zCount(Mono.just(ZCountCommand.scoresWithin(range).forKey(key))).next().map(NumericResponse::getOutput); }
/** * 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())); }
/** * 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())); }
@Override public Mono<Long> intersectAndStore(K key, Collection<K> otherKeys, K destKey) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(otherKeys, "Other keys must not be null!"); Assert.notNull(destKey, "Destination key must not be null!"); return createMono(connection -> Flux.fromIterable(getKeys(key, otherKeys)) // .map(this::rawKey) // .collectList() // .flatMap(serialized -> connection.zInterStore(rawKey(destKey), serialized))); }
/** * Get all elements in {@link Range} from the sorted set at {@literal key} in lexicographical ordering. Result is * limited via {@link Limit}. * * @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/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a> */ default Flux<ByteBuffer> zRevRangeByLex(ByteBuffer key, Range<String> 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 zRangeByLex(Mono.just(ZRangeByLexCommand.reverseStringsWithin(range).from(key).limitTo(limit))) .flatMap(CommandResponse::getOutput); }
@Override public Flux<TypedTuple<V>> rangeByScoreWithScores(K key, Range<Double> range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); return createFlux(connection -> connection.zRangeByScoreWithScores(rawKey(key), range).map(this::readTypedTuple)); }
@Override public Flux<V> rangeByScore(K key, Range<Double> range, Limit limit) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); return createFlux(connection -> connection.zRangeByScore(rawKey(key), range, limit).map(this::readValue)); }
@Override public Flux<V> rangeByLex(K key, Range<String> range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); return createFlux(connection -> connection.zRangeByLex(rawKey(key), range).map(this::readValue)); }
@Override public Mono<Long> addAll(K key, Collection<? extends TypedTuple<V>> tuples) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(tuples, "Key must not be null!"); return createMono(connection -> Flux.fromIterable(tuples) // .map(t -> new DefaultTuple(ByteUtils.getBytes(rawValue(t.getValue())), t.getScore())) // .collectList() // .flatMap(serialized -> connection.zAdd(rawKey(key), serialized))); }
/** * Increment the score of element with {@literal value} in sorted set by {@literal increment}. * * @param key must not be {@literal null}. * @param increment must not be {@literal null}. * @param value must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/zincrby">Redis Documentation: ZINCRBY</a> */ default Mono<Double> zIncrBy(ByteBuffer key, Number increment, ByteBuffer value) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(increment, "Increment must not be null!"); Assert.notNull(value, "Value must not be null!"); return zIncrBy(Mono.just(ZIncrByCommand.scoreOf(value).by(increment).storedWithin(key))).next() .map(NumericResponse::getOutput); }
@Override public Flux<TypedTuple<V>> rangeWithScores(K key, Range<Long> range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); return createFlux(connection -> connection.zRangeWithScores(rawKey(key), range).map(this::readTypedTuple)); }
/** * Intersect sorted {@literal sets} by applying {@literal aggregateFunction} and store result in destination * {@literal destinationKey} and apply weights to individual sets. * * @param destinationKey must not be {@literal null}. * @param sets must not be {@literal null}. * @param weights must not be {@literal null}. * @param aggregateFunction can be {@literal null}. * @return * @see <a href="http://redis.io/commands/zinterstore">Redis Documentation: ZINTERSTORE</a> */ default Mono<Long> zInterStore(ByteBuffer destinationKey, List<ByteBuffer> sets, List<Double> weights, @Nullable Aggregate aggregateFunction) { Assert.notNull(destinationKey, "DestinationKey must not be null!"); Assert.notNull(sets, "Sets must not be null!"); return zInterStore(Mono.just( ZInterStoreCommand.sets(sets).aggregateUsing(aggregateFunction).applyWeights(weights).storeAs(destinationKey))) .next().map(NumericResponse::getOutput); }
@Override public Mono<Double> incrementScore(K key, V value, double delta) { Assert.notNull(key, "Key must not be null!"); return createMono(connection -> connection.zIncrBy(rawKey(key), delta, rawValue(value))); }
@Override public Mono<Long> size(K key) { Assert.notNull(key, "Key must not be null!"); return createMono(connection -> connection.zCard(rawKey(key))); }
@Override public Mono<Long> count(K key, Range<Double> range) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(range, "Range must not be null!"); return createMono(connection -> connection.zCount(rawKey(key), range)); }
/** * Intersect sorted {@literal sets} and store result in destination {@literal destinationKey} and apply weights to * individual sets. * * @param destinationKey must not be {@literal null}. * @param sets must not be {@literal null}. * @param weights must not be {@literal null}. * @return * @see <a href="http://redis.io/commands/zinterstore">Redis Documentation: ZINTERSTORE</a> */ default Mono<Long> zInterStore(ByteBuffer destinationKey, List<ByteBuffer> sets, List<Double> weights) { return zInterStore(destinationKey, sets, weights, null); }