Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ZRANGESTORE command #1581

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2059,6 +2059,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 @@ -2119,6 +2129,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 @@ -2130,6 +2130,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 @@ -2325,6 +2335,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 @@ -2985,6 +2985,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