Skip to content

Commit

Permalink
Add support for ZRANGESTORE usage with Rank #2202
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Sep 23, 2022
1 parent 672b747 commit 39d2677
Show file tree
Hide file tree
Showing 12 changed files with 359 additions and 53 deletions.
10 changes: 10 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2536,6 +2536,11 @@ public RedisFuture<Long> zrangebyscoreWithScores(ScoredValueStreamingChannel<V>
return dispatch(commandBuilder.zrangebyscoreWithScores(channel, key, range, limit));
}

@Override
public RedisFuture<Long> zrangestore(K dstKey, K srcKey, Range<Long> range) {
return dispatch(commandBuilder.zrangestore(dstKey, srcKey, range, false));
}

@Override
public RedisFuture<Long> zrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit) {
return dispatch(commandBuilder.zrangestorebylex(dstKey, srcKey, range, limit, false));
Expand Down Expand Up @@ -2606,6 +2611,11 @@ public RedisFuture<Long> zrevrangeWithScores(ScoredValueStreamingChannel<V> chan
return dispatch(commandBuilder.zrevrangeWithScores(channel, key, start, stop));
}

@Override
public RedisFuture<Long> zrevrangestore(K dstKey, K srcKey, Range<Long> range) {
return dispatch(commandBuilder.zrangestore(dstKey, srcKey, range, true));
}

@Override
public RedisFuture<Long> zrevrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit) {
return dispatch(commandBuilder.zrangestorebylex(dstKey, srcKey, range, limit, true));
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2609,6 +2609,11 @@ public Mono<Long> zrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel
return createMono(() -> commandBuilder.zrangebyscoreWithScores(channel, key, range, limit));
}

@Override
public Mono<Long> zrangestore(K dstKey, K srcKey, Range<Long> range) {
return createMono(() -> commandBuilder.zrangestore(dstKey, srcKey, range, false));
}

@Override
public Mono<Long> zrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit) {
return createMono(() -> commandBuilder.zrangestorebylex(dstKey, srcKey, range, limit, false));
Expand Down Expand Up @@ -2814,6 +2819,11 @@ public Mono<Long> zrevrangebyscoreWithScores(ScoredValueStreamingChannel<V> chan
return createMono(() -> commandBuilder.zrevrangebyscoreWithScores(channel, key, range, limit));
}

@Override
public Mono<Long> zrevrangestore(K dstKey, K srcKey, Range<Long> range) {
return createMono(() -> commandBuilder.zrangestore(dstKey, srcKey, range, true));
}

@Override
public Mono<Long> zrevrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit) {
return createMono(() -> commandBuilder.zrangestorebylex(dstKey, srcKey, range, limit, true));
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3620,6 +3620,22 @@ Command<K, V, Long> zrangebyscoreWithScores(ScoredValueStreamingChannel<V> chann
return createCommand(ZRANGEBYSCORE, new ScoredValueStreamingOutput<>(codec, channel), args);
}

Command<K, V, Long> zrangestore(K dstKey, K srcKey, Range<Long> range, boolean rev) {
notNullKey(srcKey);
notNullKey(dstKey);
notNullRange(range);

CommandArgs<K, V> args = new CommandArgs<>(codec);
args.addKeys(dstKey, srcKey);

args.add(min(range)).add(max(range));

if (rev) {
args.add(REV);
}
return createCommand(ZRANGESTORE, new IntegerOutput<>(codec), args);
}

Command<K, V, Long> zrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit, boolean rev) {
notNullKey(srcKey);
notNullKey(dstKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,14 +841,27 @@ public interface RedisSortedSetAsyncCommands<K, V> {
*/
RedisFuture<Long> zrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, Range<? extends Number> range, Limit limit);

/**
* Get the specified range of elements in the sorted set stored at {@code srcKey} and stores the result in the
* {@code dstKey} destination key.
*
* @param dstKey the dst key.
* @param srcKey the src key.
* @param range the rank.
* @return the number of elements in the resulting sorted set.
* @since 6.2.1
*/
RedisFuture<Long> zrangestore(K dstKey, K srcKey, Range<Long> range);

/**
* Get the specified range of elements in the sorted set stored at {@code srcKey} and stores the result in the
* {@code dstKey} destination key.
*
* @param dstKey the dst key.
* @param srcKey the src key.
* @param range the lexicographical range.
* @return The number of elements in the resulting sorted set.
* @param limit the limit to apply.
* @return the number of elements in the resulting sorted set.
* @since 6.1
*/
RedisFuture<Long> zrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);
Expand All @@ -860,7 +873,8 @@ public interface RedisSortedSetAsyncCommands<K, V> {
* @param dstKey the dst key.
* @param srcKey the src key.
* @param range the score range.
* @return The number of elements in the resulting sorted set.
* @param limit the limit to apply.
* @return the number of elements in the resulting sorted set.
* @since 6.1
*/
RedisFuture<Long> zrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit);
Expand Down Expand Up @@ -1318,14 +1332,27 @@ public interface RedisSortedSetAsyncCommands<K, V> {
*/
RedisFuture<Long> zrevrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, Range<? extends Number> range, Limit limit);

/**
* Get the specified range of elements ordered from high to low in the sorted set stored at {@code srcKey} and stores the
* result in the {@code dstKey} destination key.
*
* @param dstKey the dst key.
* @param srcKey the src key.
* @param range the rank.
* @return the number of elements in the resulting sorted set.
* @since 6.2.1
*/
RedisFuture<Long> zrevrangestore(K dstKey, K srcKey, Range<Long> range);

/**
* Get the lexicographical range ordered from high to low of elements in the sorted set stored at {@code srcKey} and stores
* the result in the {@code dstKey} destination key.
*
* @param dstKey the src key.
* @param srcKey the dst key.
* @param range the lexicographical range.
* @return The number of elements in the resulting sorted set.
* @param limit the limit to apply.
* @return the number of elements in the resulting sorted set.
* @since 6.1
*/
RedisFuture<Long> zrevrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);
Expand All @@ -1338,7 +1365,8 @@ public interface RedisSortedSetAsyncCommands<K, V> {
*
* @param srcKey the dst key.
* @param range the score range.
* @return The number of elements in the resulting sorted set.
* @param limit the limit to apply.
* @return the number of elements in the resulting sorted set.
* @since 6.1
*/
RedisFuture<Long> zrevrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,14 +863,27 @@ public interface RedisSortedSetReactiveCommands<K, V> {
@Deprecated
Mono<Long> zrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, Range<? extends Number> range, Limit limit);

/**
* Get the specified range of elements in the sorted set stored at {@code srcKey} and stores the result in the
* {@code dstKey} destination key.
*
* @param dstKey the dst key.
* @param srcKey the src key.
* @param range the rank.
* @return the number of elements in the resulting sorted set.
* @since 6.2.1
*/
Mono<Long> zrangestore(K dstKey, K srcKey, Range<Long> range);

/**
* Get the specified range of elements in the sorted set stored at {@code srcKey} and stores the result in the
* {@code dstKey} destination key.
*
* @param dstKey the dst key.
* @param srcKey the src key.
* @param range the lexicographical range.
* @return The number of elements in the resulting sorted set.
* @param limit the limit to apply.
* @return the number of elements in the resulting sorted set.
* @since 6.1
*/
Mono<Long> zrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);
Expand All @@ -882,7 +895,8 @@ public interface RedisSortedSetReactiveCommands<K, V> {
* @param dstKey the dst key.
* @param srcKey the src key.
* @param range the score range.
* @return The number of elements in the resulting sorted set.
* @param limit the limit to apply.
* @return the number of elements in the resulting sorted set.
* @since 6.1
*/
Mono<Long> zrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit);
Expand Down Expand Up @@ -1360,14 +1374,27 @@ public interface RedisSortedSetReactiveCommands<K, V> {
@Deprecated
Mono<Long> zrevrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, Range<? extends Number> range, Limit limit);

/**
* Get the specified range of elements ordered from high to low in the sorted set stored at {@code srcKey} and stores the
* result in the {@code dstKey} destination key.
*
* @param dstKey the dst key.
* @param srcKey the src key.
* @param range the rank.
* @return the number of elements in the resulting sorted set.
* @since 6.2.1
*/
Mono<Long> zrevrangestore(K dstKey, K srcKey, Range<Long> range);

/**
* Get the lexicographical range ordered from high to low of elements in the sorted set stored at {@code srcKey} and stores
* the result in the {@code dstKey} destination key.
*
* @param dstKey the src key.
* @param srcKey the dst key.
* @param range the lexicographical range.
* @return The number of elements in the resulting sorted set.
* @param limit the limit to apply.
* @return the number of elements in the resulting sorted set.
* @since 6.1
*/
Mono<Long> zrevrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);
Expand All @@ -1380,7 +1407,8 @@ public interface RedisSortedSetReactiveCommands<K, V> {
*
* @param srcKey the dst key.
* @param range the score range.
* @return The number of elements in the resulting sorted set.
* @param limit the limit to apply.
* @return the number of elements in the resulting sorted set.
* @since 6.1
*/
Mono<Long> zrevrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit);
Expand Down
36 changes: 32 additions & 4 deletions src/main/java/io/lettuce/core/api/sync/RedisSortedSetCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -841,14 +841,27 @@ public interface RedisSortedSetCommands<K, V> {
*/
Long zrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, Range<? extends Number> range, Limit limit);

/**
* Get the specified range of elements in the sorted set stored at {@code srcKey} and stores the result in the
* {@code dstKey} destination key.
*
* @param dstKey the dst key.
* @param srcKey the src key.
* @param range the rank.
* @return the number of elements in the resulting sorted set.
* @since 6.2.1
*/
Long zrangestore(K dstKey, K srcKey, Range<Long> range);

/**
* Get the specified range of elements in the sorted set stored at {@code srcKey} and stores the result in the
* {@code dstKey} destination key.
*
* @param dstKey the dst key.
* @param srcKey the src key.
* @param range the lexicographical range.
* @return The number of elements in the resulting sorted set.
* @param limit the limit to apply.
* @return the number of elements in the resulting sorted set.
* @since 6.1
*/
Long zrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);
Expand All @@ -860,7 +873,8 @@ public interface RedisSortedSetCommands<K, V> {
* @param dstKey the dst key.
* @param srcKey the src key.
* @param range the score range.
* @return The number of elements in the resulting sorted set.
* @param limit the limit to apply.
* @return the number of elements in the resulting sorted set.
* @since 6.1
*/
Long zrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit);
Expand Down Expand Up @@ -1318,14 +1332,27 @@ public interface RedisSortedSetCommands<K, V> {
*/
Long zrevrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, Range<? extends Number> range, Limit limit);

/**
* Get the specified range of elements ordered from high to low in the sorted set stored at {@code srcKey} and stores the
* result in the {@code dstKey} destination key.
*
* @param dstKey the dst key.
* @param srcKey the src key.
* @param range the rank.
* @return the number of elements in the resulting sorted set.
* @since 6.2.1
*/
Long zrevrangestore(K dstKey, K srcKey, Range<Long> range);

/**
* Get the lexicographical range ordered from high to low of elements in the sorted set stored at {@code srcKey} and stores
* the result in the {@code dstKey} destination key.
*
* @param dstKey the src key.
* @param srcKey the dst key.
* @param range the lexicographical range.
* @return The number of elements in the resulting sorted set.
* @param limit the limit to apply.
* @return the number of elements in the resulting sorted set.
* @since 6.1
*/
Long zrevrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);
Expand All @@ -1338,7 +1365,8 @@ public interface RedisSortedSetCommands<K, V> {
*
* @param srcKey the dst key.
* @param range the score range.
* @return The number of elements in the resulting sorted set.
* @param limit the limit to apply.
* @return the number of elements in the resulting sorted set.
* @since 6.1
*/
Long zrevrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,14 +841,27 @@ public interface NodeSelectionSortedSetAsyncCommands<K, V> {
*/
AsyncExecutions<Long> zrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, Range<? extends Number> range, Limit limit);

/**
* Get the specified range of elements in the sorted set stored at {@code srcKey} and stores the result in the
* {@code dstKey} destination key.
*
* @param dstKey the dst key.
* @param srcKey the src key.
* @param range the rank.
* @return the number of elements in the resulting sorted set.
* @since 6.2.1
*/
AsyncExecutions<Long> zrangestore(K dstKey, K srcKey, Range<Long> range);

/**
* Get the specified range of elements in the sorted set stored at {@code srcKey} and stores the result in the
* {@code dstKey} destination key.
*
* @param dstKey the dst key.
* @param srcKey the src key.
* @param range the lexicographical range.
* @return The number of elements in the resulting sorted set.
* @param limit the limit to apply.
* @return the number of elements in the resulting sorted set.
* @since 6.1
*/
AsyncExecutions<Long> zrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);
Expand All @@ -860,7 +873,8 @@ public interface NodeSelectionSortedSetAsyncCommands<K, V> {
* @param dstKey the dst key.
* @param srcKey the src key.
* @param range the score range.
* @return The number of elements in the resulting sorted set.
* @param limit the limit to apply.
* @return the number of elements in the resulting sorted set.
* @since 6.1
*/
AsyncExecutions<Long> zrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit);
Expand Down Expand Up @@ -1318,14 +1332,27 @@ public interface NodeSelectionSortedSetAsyncCommands<K, V> {
*/
AsyncExecutions<Long> zrevrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, Range<? extends Number> range, Limit limit);

/**
* Get the specified range of elements ordered from high to low in the sorted set stored at {@code srcKey} and stores the
* result in the {@code dstKey} destination key.
*
* @param dstKey the dst key.
* @param srcKey the src key.
* @param range the rank.
* @return the number of elements in the resulting sorted set.
* @since 6.2.1
*/
AsyncExecutions<Long> zrevrangestore(K dstKey, K srcKey, Range<Long> range);

/**
* Get the lexicographical range ordered from high to low of elements in the sorted set stored at {@code srcKey} and stores
* the result in the {@code dstKey} destination key.
*
* @param dstKey the src key.
* @param srcKey the dst key.
* @param range the lexicographical range.
* @return The number of elements in the resulting sorted set.
* @param limit the limit to apply.
* @return the number of elements in the resulting sorted set.
* @since 6.1
*/
AsyncExecutions<Long> zrevrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);
Expand All @@ -1338,7 +1365,8 @@ public interface NodeSelectionSortedSetAsyncCommands<K, V> {
*
* @param srcKey the dst key.
* @param range the score range.
* @return The number of elements in the resulting sorted set.
* @param limit the limit to apply.
* @return the number of elements in the resulting sorted set.
* @since 6.1
*/
AsyncExecutions<Long> zrevrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit);
Expand Down
Loading

0 comments on commit 39d2677

Please sign in to comment.