Skip to content

Commit

Permalink
Add support for ZRANGESTORE command #1506
Browse files Browse the repository at this point in the history
Original pull request: #1581.
  • Loading branch information
dengliming authored and mp911de committed Jan 14, 2021
1 parent 2c1fd63 commit fb2d739
Show file tree
Hide file tree
Showing 14 changed files with 421 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2069,6 +2069,16 @@ public RedisFuture<Long> zrangebyscoreWithScores(ScoredValueStreamingChannel<V>
return dispatch(commandBuilder.zrangebyscoreWithScores(channel, key, range, limit));
}

@Override
public RedisFuture<Long> zrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit) {
return dispatch(commandBuilder.zrangestorebylex(dstKey, srcKey, range, limit, false));
}

@Override
public RedisFuture<Long> zrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit) {
return dispatch(commandBuilder.zrangestorebyscore(dstKey, srcKey, range, limit, false));
}

@Override
public RedisFuture<Long> zrank(K key, V member) {
return dispatch(commandBuilder.zrank(key, member));
Expand Down Expand Up @@ -2129,6 +2139,16 @@ public RedisFuture<Long> zrevrangeWithScores(ScoredValueStreamingChannel<V> chan
return dispatch(commandBuilder.zrevrangeWithScores(channel, key, start, stop));
}

@Override
public RedisFuture<Long> zrevrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit) {
return dispatch(commandBuilder.zrangestorebylex(dstKey, srcKey, range, limit, true));
}

@Override
public RedisFuture<Long> zrevrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit) {
return dispatch(commandBuilder.zrangestorebyscore(dstKey, srcKey, range, limit, true));
}

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

@Override
public Mono<Long> zrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit) {
return createMono(() -> commandBuilder.zrangestorebylex(dstKey, srcKey, range, limit, false));
}

@Override
public Mono<Long> zrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit) {
return createMono(() -> commandBuilder.zrangestorebyscore(dstKey, srcKey, range, limit, false));
}

@Override
public Mono<Long> zrank(K key, V member) {
return createMono(() -> commandBuilder.zrank(key, member));
Expand Down Expand Up @@ -2335,6 +2345,16 @@ public Mono<Long> zrevrangebyscoreWithScores(ScoredValueStreamingChannel<V> chan
return createMono(() -> commandBuilder.zrevrangebyscoreWithScores(channel, key, range, limit));
}

@Override
public Mono<Long> zrevrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit) {
return createMono(() -> commandBuilder.zrangestorebylex(dstKey, srcKey, range, limit, true));
}

@Override
public Mono<Long> zrevrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit) {
return createMono(() -> commandBuilder.zrangestorebyscore(dstKey, srcKey, range, limit, true));
}

@Override
public Mono<Long> zrevrank(K key, V member) {
return createMono(() -> commandBuilder.zrevrank(key, member));
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2997,6 +2997,36 @@ Command<K, V, Long> zrangebyscoreWithScores(ScoredValueStreamingChannel<V> chann
return createCommand(ZRANGEBYSCORE, new ScoredValueStreamingOutput<>(codec, channel), args);
}

Command<K, V, Long> zrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit, boolean rev) {
notNullKey(srcKey);
notNullKey(dstKey);
notNullRange(range);
notNullLimit(limit);

CommandArgs<K, V> args = new CommandArgs<>(codec);
args.addKeys(dstKey, srcKey).add(minValue(range)).add(maxValue(range)).add(BYLEX);
if (rev) {
args.add(REV);
}
addLimit(args, limit);
return createCommand(ZRANGESTORE, new IntegerOutput<>(codec), args);
}

Command<K, V, Long> zrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit, boolean rev) {
notNullKey(srcKey);
notNullKey(dstKey);
notNullRange(range);
notNullLimit(limit);

CommandArgs<K, V> args = new CommandArgs<>(codec);
args.addKeys(dstKey, srcKey).add(min(range)).add(max(range)).add(BYSCORE);
if (rev) {
args.add(REV);
}
addLimit(args, limit);
return createCommand(ZRANGESTORE, new IntegerOutput<>(codec), args);
}

Command<K, V, Long> zrank(K key, V member) {
notNullKey(key);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,28 @@ 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 <srcKey> and stores the result in the <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.
* @since 6.2
*/
RedisFuture<Long> zrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);

/**
* Get the specified range of elements in the sorted set stored at <srcKey> and stores the result in the <dstKey> destination key.
*
* @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.
* @since 6.2
*/
RedisFuture<Long> zrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit);

/**
* Determine the index of a member in a sorted set.
*
Expand Down Expand Up @@ -1182,6 +1204,28 @@ public interface RedisSortedSetAsyncCommands<K, V> {
*/
RedisFuture<Long> zrevrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, Range<? extends Number> range, Limit limit);

/**
* Get the lexicographical range ordered from high to low of elements in the sorted set stored at <srcKey> and stores the result in the <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.
* @since 6.2
*/
RedisFuture<Long> zrevrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);

/**
* Get the specified range of elements in the sorted set stored at <srcKey> with scores ordered from high to low and stores the result in the <dstKey> destination key.
*
* @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.
* @since 6.2
*/
RedisFuture<Long> zrevrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit);

/**
* Determine the index of a member in a sorted set, with scores ordered from high to low.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,28 @@ 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 <srcKey> and stores the result in the <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.
* @since 6.2
*/
Mono<Long> zrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);

/**
* Get the specified range of elements in the sorted set stored at <srcKey> and stores the result in the <dstKey> destination key.
*
* @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.
* @since 6.2
*/
Mono<Long> zrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit);

/**
* Determine the index of a member in a sorted set.
*
Expand Down Expand Up @@ -1224,6 +1246,28 @@ public interface RedisSortedSetReactiveCommands<K, V> {
@Deprecated
Mono<Long> zrevrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, Range<? extends Number> range, Limit limit);

/**
* Get the lexicographical range ordered from high to low of elements in the sorted set stored at <srcKey> and stores the result in the <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.
* @since 6.2
*/
Mono<Long> zrevrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);

/**
* Get the specified range of elements in the sorted set stored at <srcKey> with scores ordered from high to low and stores the result in the <dstKey> destination key.
*
* @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.
* @since 6.2
*/
Mono<Long> zrevrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit);

/**
* Determine the index of a member in a sorted set, with scores ordered from high to low.
*
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/io/lettuce/core/api/sync/RedisSortedSetCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,28 @@ 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 <srcKey> and stores the result in the <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.
* @since 6.2
*/
Long zrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);

/**
* Get the specified range of elements in the sorted set stored at <srcKey> and stores the result in the <dstKey> destination key.
*
* @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.
* @since 6.2
*/
Long zrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit);

/**
* Determine the index of a member in a sorted set.
*
Expand Down Expand Up @@ -1182,6 +1204,28 @@ public interface RedisSortedSetCommands<K, V> {
*/
Long zrevrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, Range<? extends Number> range, Limit limit);

/**
* Get the lexicographical range ordered from high to low of elements in the sorted set stored at <srcKey> and stores the result in the <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.
* @since 6.2
*/
Long zrevrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);

/**
* Get the specified range of elements in the sorted set stored at <srcKey> with scores ordered from high to low and stores the result in the <dstKey> destination key.
*
* @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.
* @since 6.2
*/
Long zrevrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit);

/**
* Determine the index of a member in a sorted set, with scores ordered from high to low.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,28 @@ 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 <srcKey> and stores the result in the <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.
* @since 6.2
*/
AsyncExecutions<Long> zrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);

/**
* Get the specified range of elements in the sorted set stored at <srcKey> and stores the result in the <dstKey> destination key.
*
* @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.
* @since 6.2
*/
AsyncExecutions<Long> zrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit);

/**
* Determine the index of a member in a sorted set.
*
Expand Down Expand Up @@ -1182,6 +1204,28 @@ public interface NodeSelectionSortedSetAsyncCommands<K, V> {
*/
AsyncExecutions<Long> zrevrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, Range<? extends Number> range, Limit limit);

/**
* Get the lexicographical range ordered from high to low of elements in the sorted set stored at <srcKey> and stores the result in the <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.
* @since 6.2
*/
AsyncExecutions<Long> zrevrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);

/**
* Get the specified range of elements in the sorted set stored at <srcKey> with scores ordered from high to low and stores the result in the <dstKey> destination key.
*
* @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.
* @since 6.2
*/
AsyncExecutions<Long> zrevrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit);

/**
* Determine the index of a member in a sorted set, with scores ordered from high to low.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,28 @@ public interface NodeSelectionSortedSetCommands<K, V> {
*/
Executions<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 <srcKey> and stores the result in the <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.
* @since 6.2
*/
Executions<Long> zrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);

/**
* Get the specified range of elements in the sorted set stored at <srcKey> and stores the result in the <dstKey> destination key.
*
* @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.
* @since 6.2
*/
Executions<Long> zrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit);

/**
* Determine the index of a member in a sorted set.
*
Expand Down Expand Up @@ -1182,6 +1204,28 @@ public interface NodeSelectionSortedSetCommands<K, V> {
*/
Executions<Long> zrevrangebyscoreWithScores(ScoredValueStreamingChannel<V> channel, K key, Range<? extends Number> range, Limit limit);

/**
* Get the lexicographical range ordered from high to low of elements in the sorted set stored at <srcKey> and stores the result in the <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.
* @since 6.2
*/
Executions<Long> zrevrangestorebylex(K dstKey, K srcKey, Range<? extends V> range, Limit limit);

/**
* Get the specified range of elements in the sorted set stored at <srcKey> with scores ordered from high to low and stores the result in the <dstKey> destination key.
*
* @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.
* @since 6.2
*/
Executions<Long> zrevrangestorebyscore(K dstKey, K srcKey, Range<? extends Number> range, Limit limit);

/**
* Determine the index of a member in a sorted set, with scores ordered from high to low.
*
Expand Down
Loading

0 comments on commit fb2d739

Please sign in to comment.