diff --git a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java index 80bcf03099..4e32ca24b6 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java @@ -2069,6 +2069,16 @@ public RedisFuture zrangebyscoreWithScores(ScoredValueStreamingChannel return dispatch(commandBuilder.zrangebyscoreWithScores(channel, key, range, limit)); } + @Override + public RedisFuture zrangestorebylex(K dstKey, K srcKey, Range range, Limit limit) { + return dispatch(commandBuilder.zrangestorebylex(dstKey, srcKey, range, limit, false)); + } + + @Override + public RedisFuture zrangestorebyscore(K dstKey, K srcKey, Range range, Limit limit) { + return dispatch(commandBuilder.zrangestorebyscore(dstKey, srcKey, range, limit, false)); + } + @Override public RedisFuture zrank(K key, V member) { return dispatch(commandBuilder.zrank(key, member)); @@ -2129,6 +2139,16 @@ public RedisFuture zrevrangeWithScores(ScoredValueStreamingChannel chan return dispatch(commandBuilder.zrevrangeWithScores(channel, key, start, stop)); } + @Override + public RedisFuture zrevrangestorebylex(K dstKey, K srcKey, Range range, Limit limit) { + return dispatch(commandBuilder.zrangestorebylex(dstKey, srcKey, range, limit, true)); + } + + @Override + public RedisFuture zrevrangestorebyscore(K dstKey, K srcKey, Range range, Limit limit) { + return dispatch(commandBuilder.zrangestorebyscore(dstKey, srcKey, range, limit, true)); + } + @Override public RedisFuture> zrevrangebylex(K key, Range range) { return dispatch(commandBuilder.zrevrangebylex(key, range, Limit.unlimited())); diff --git a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java index 8371961b30..ee53d566fb 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java @@ -2140,6 +2140,16 @@ public Mono zrangebyscoreWithScores(ScoredValueStreamingChannel channel return createMono(() -> commandBuilder.zrangebyscoreWithScores(channel, key, range, limit)); } + @Override + public Mono zrangestorebylex(K dstKey, K srcKey, Range range, Limit limit) { + return createMono(() -> commandBuilder.zrangestorebylex(dstKey, srcKey, range, limit, false)); + } + + @Override + public Mono zrangestorebyscore(K dstKey, K srcKey, Range range, Limit limit) { + return createMono(() -> commandBuilder.zrangestorebyscore(dstKey, srcKey, range, limit, false)); + } + @Override public Mono zrank(K key, V member) { return createMono(() -> commandBuilder.zrank(key, member)); @@ -2335,6 +2345,16 @@ public Mono zrevrangebyscoreWithScores(ScoredValueStreamingChannel chan return createMono(() -> commandBuilder.zrevrangebyscoreWithScores(channel, key, range, limit)); } + @Override + public Mono zrevrangestorebylex(K dstKey, K srcKey, Range range, Limit limit) { + return createMono(() -> commandBuilder.zrangestorebylex(dstKey, srcKey, range, limit, true)); + } + + @Override + public Mono zrevrangestorebyscore(K dstKey, K srcKey, Range range, Limit limit) { + return createMono(() -> commandBuilder.zrangestorebyscore(dstKey, srcKey, range, limit, true)); + } + @Override public Mono zrevrank(K key, V member) { return createMono(() -> commandBuilder.zrevrank(key, member)); diff --git a/src/main/java/io/lettuce/core/RedisCommandBuilder.java b/src/main/java/io/lettuce/core/RedisCommandBuilder.java index 9d5de2f8a6..3703011b99 100644 --- a/src/main/java/io/lettuce/core/RedisCommandBuilder.java +++ b/src/main/java/io/lettuce/core/RedisCommandBuilder.java @@ -2997,6 +2997,36 @@ Command zrangebyscoreWithScores(ScoredValueStreamingChannel chann return createCommand(ZRANGEBYSCORE, new ScoredValueStreamingOutput<>(codec, channel), args); } + Command zrangestorebylex(K dstKey, K srcKey, Range range, Limit limit, boolean rev) { + notNullKey(srcKey); + notNullKey(dstKey); + notNullRange(range); + notNullLimit(limit); + + CommandArgs 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 zrangestorebyscore(K dstKey, K srcKey, Range range, Limit limit, boolean rev) { + notNullKey(srcKey); + notNullKey(dstKey); + notNullRange(range); + notNullLimit(limit); + + CommandArgs 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 zrank(K key, V member) { notNullKey(key); diff --git a/src/main/java/io/lettuce/core/api/async/RedisSortedSetAsyncCommands.java b/src/main/java/io/lettuce/core/api/async/RedisSortedSetAsyncCommands.java index 7ba55a1844..97addadbb1 100644 --- a/src/main/java/io/lettuce/core/api/async/RedisSortedSetAsyncCommands.java +++ b/src/main/java/io/lettuce/core/api/async/RedisSortedSetAsyncCommands.java @@ -729,6 +729,28 @@ public interface RedisSortedSetAsyncCommands { */ RedisFuture zrangebyscoreWithScores(ScoredValueStreamingChannel channel, K key, Range range, Limit limit); + /** + * Get the specified range of elements in the sorted set stored at and stores the result in the 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 zrangestorebylex(K dstKey, K srcKey, Range range, Limit limit); + + /** + * Get the specified range of elements in the sorted set stored at and stores the result in the 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 zrangestorebyscore(K dstKey, K srcKey, Range range, Limit limit); + /** * Determine the index of a member in a sorted set. * @@ -1182,6 +1204,28 @@ public interface RedisSortedSetAsyncCommands { */ RedisFuture zrevrangebyscoreWithScores(ScoredValueStreamingChannel channel, K key, Range range, Limit limit); + /** + * Get the lexicographical range ordered from high to low of elements in the sorted set stored at and stores the result in the 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 zrevrangestorebylex(K dstKey, K srcKey, Range range, Limit limit); + + /** + * Get the specified range of elements in the sorted set stored at with scores ordered from high to low and stores the result in the 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 zrevrangestorebyscore(K dstKey, K srcKey, Range range, Limit limit); + /** * Determine the index of a member in a sorted set, with scores ordered from high to low. * diff --git a/src/main/java/io/lettuce/core/api/reactive/RedisSortedSetReactiveCommands.java b/src/main/java/io/lettuce/core/api/reactive/RedisSortedSetReactiveCommands.java index 05de2e3408..35d5785c80 100644 --- a/src/main/java/io/lettuce/core/api/reactive/RedisSortedSetReactiveCommands.java +++ b/src/main/java/io/lettuce/core/api/reactive/RedisSortedSetReactiveCommands.java @@ -751,6 +751,28 @@ public interface RedisSortedSetReactiveCommands { @Deprecated Mono zrangebyscoreWithScores(ScoredValueStreamingChannel channel, K key, Range range, Limit limit); + /** + * Get the specified range of elements in the sorted set stored at and stores the result in the 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 zrangestorebylex(K dstKey, K srcKey, Range range, Limit limit); + + /** + * Get the specified range of elements in the sorted set stored at and stores the result in the 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 zrangestorebyscore(K dstKey, K srcKey, Range range, Limit limit); + /** * Determine the index of a member in a sorted set. * @@ -1224,6 +1246,28 @@ public interface RedisSortedSetReactiveCommands { @Deprecated Mono zrevrangebyscoreWithScores(ScoredValueStreamingChannel channel, K key, Range range, Limit limit); + /** + * Get the lexicographical range ordered from high to low of elements in the sorted set stored at and stores the result in the 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 zrevrangestorebylex(K dstKey, K srcKey, Range range, Limit limit); + + /** + * Get the specified range of elements in the sorted set stored at with scores ordered from high to low and stores the result in the 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 zrevrangestorebyscore(K dstKey, K srcKey, Range range, Limit limit); + /** * Determine the index of a member in a sorted set, with scores ordered from high to low. * diff --git a/src/main/java/io/lettuce/core/api/sync/RedisSortedSetCommands.java b/src/main/java/io/lettuce/core/api/sync/RedisSortedSetCommands.java index 89c4a2b73f..8ced4eaa6a 100644 --- a/src/main/java/io/lettuce/core/api/sync/RedisSortedSetCommands.java +++ b/src/main/java/io/lettuce/core/api/sync/RedisSortedSetCommands.java @@ -729,6 +729,28 @@ public interface RedisSortedSetCommands { */ Long zrangebyscoreWithScores(ScoredValueStreamingChannel channel, K key, Range range, Limit limit); + /** + * Get the specified range of elements in the sorted set stored at and stores the result in the 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 range, Limit limit); + + /** + * Get the specified range of elements in the sorted set stored at and stores the result in the 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 range, Limit limit); + /** * Determine the index of a member in a sorted set. * @@ -1182,6 +1204,28 @@ public interface RedisSortedSetCommands { */ Long zrevrangebyscoreWithScores(ScoredValueStreamingChannel channel, K key, Range range, Limit limit); + /** + * Get the lexicographical range ordered from high to low of elements in the sorted set stored at and stores the result in the 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 range, Limit limit); + + /** + * Get the specified range of elements in the sorted set stored at with scores ordered from high to low and stores the result in the 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 range, Limit limit); + /** * Determine the index of a member in a sorted set, with scores ordered from high to low. * diff --git a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionSortedSetAsyncCommands.java b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionSortedSetAsyncCommands.java index 1c7c13545a..97a71e3ea9 100644 --- a/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionSortedSetAsyncCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/async/NodeSelectionSortedSetAsyncCommands.java @@ -729,6 +729,28 @@ public interface NodeSelectionSortedSetAsyncCommands { */ AsyncExecutions zrangebyscoreWithScores(ScoredValueStreamingChannel channel, K key, Range range, Limit limit); + /** + * Get the specified range of elements in the sorted set stored at and stores the result in the 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 zrangestorebylex(K dstKey, K srcKey, Range range, Limit limit); + + /** + * Get the specified range of elements in the sorted set stored at and stores the result in the 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 zrangestorebyscore(K dstKey, K srcKey, Range range, Limit limit); + /** * Determine the index of a member in a sorted set. * @@ -1182,6 +1204,28 @@ public interface NodeSelectionSortedSetAsyncCommands { */ AsyncExecutions zrevrangebyscoreWithScores(ScoredValueStreamingChannel channel, K key, Range range, Limit limit); + /** + * Get the lexicographical range ordered from high to low of elements in the sorted set stored at and stores the result in the 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 zrevrangestorebylex(K dstKey, K srcKey, Range range, Limit limit); + + /** + * Get the specified range of elements in the sorted set stored at with scores ordered from high to low and stores the result in the 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 zrevrangestorebyscore(K dstKey, K srcKey, Range range, Limit limit); + /** * Determine the index of a member in a sorted set, with scores ordered from high to low. * diff --git a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionSortedSetCommands.java b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionSortedSetCommands.java index 167a16a5e9..5efc8d01a2 100644 --- a/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionSortedSetCommands.java +++ b/src/main/java/io/lettuce/core/cluster/api/sync/NodeSelectionSortedSetCommands.java @@ -729,6 +729,28 @@ public interface NodeSelectionSortedSetCommands { */ Executions zrangebyscoreWithScores(ScoredValueStreamingChannel channel, K key, Range range, Limit limit); + /** + * Get the specified range of elements in the sorted set stored at and stores the result in the 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 zrangestorebylex(K dstKey, K srcKey, Range range, Limit limit); + + /** + * Get the specified range of elements in the sorted set stored at and stores the result in the 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 zrangestorebyscore(K dstKey, K srcKey, Range range, Limit limit); + /** * Determine the index of a member in a sorted set. * @@ -1182,6 +1204,28 @@ public interface NodeSelectionSortedSetCommands { */ Executions zrevrangebyscoreWithScores(ScoredValueStreamingChannel channel, K key, Range range, Limit limit); + /** + * Get the lexicographical range ordered from high to low of elements in the sorted set stored at and stores the result in the 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 zrevrangestorebylex(K dstKey, K srcKey, Range range, Limit limit); + + /** + * Get the specified range of elements in the sorted set stored at with scores ordered from high to low and stores the result in the 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 zrevrangestorebyscore(K dstKey, K srcKey, Range range, Limit limit); + /** * Determine the index of a member in a sorted set, with scores ordered from high to low. * diff --git a/src/main/java/io/lettuce/core/protocol/CommandKeyword.java b/src/main/java/io/lettuce/core/protocol/CommandKeyword.java index e2a4f74bbc..b52566bd85 100644 --- a/src/main/java/io/lettuce/core/protocol/CommandKeyword.java +++ b/src/main/java/io/lettuce/core/protocol/CommandKeyword.java @@ -29,7 +29,7 @@ public enum CommandKeyword implements ProtocolKeyword { ADDR, ADDSLOTS, AFTER, AGGREGATE, ALPHA, AND, ASK, ASC, ASYNC, BEFORE, BLOCK, BUMPEPOCH, - BY, CACHING, CHANNELS, COPY, COUNT, COUNTKEYSINSLOT, CONSUMERS, CREATE, DB, DELSLOTS, DESC, SOFT, HARD, ENCODING, + BY, BYLEX, BYSCORE, CACHING, CHANNELS, COPY, COUNT, COUNTKEYSINSLOT, CONSUMERS, CREATE, DB, DELSLOTS, DESC, SOFT, HARD, ENCODING, FAILOVER, FORGET, FLUSH, FORCE, FLUSHSLOTS, GETNAME, GETKEYSINSLOT, GETREDIR, GROUP, GROUPS, HTSTATS, ID, IDLE, @@ -37,7 +37,7 @@ public enum CommandKeyword implements ProtocolKeyword { MAX, MAXLEN, MEET, MIN, MOVED, NO, NOACK, NODE, NODES, NOMKSTREAM, NOSAVE, NOT, NUMSUB, NUMPAT, OFF, ON, ONE, OR, PAUSE, - REFCOUNT, REMOVE, RELOAD, REPLACE, REPLICATE, RESET, + REFCOUNT, REMOVE, RELOAD, REPLACE, REPLICATE, REV, RESET, RESETSTAT, RESTART, RETRYCOUNT, REWRITE, RIGHT, SAVECONFIG, SDSLEN, SETNAME, SETSLOT, SLOTS, STABLE, diff --git a/src/main/java/io/lettuce/core/protocol/CommandType.java b/src/main/java/io/lettuce/core/protocol/CommandType.java index f80272f0be..c9a7046522 100644 --- a/src/main/java/io/lettuce/core/protocol/CommandType.java +++ b/src/main/java/io/lettuce/core/protocol/CommandType.java @@ -78,7 +78,7 @@ public enum CommandType implements ProtocolKeyword { // Sorted Set - BZPOPMIN, BZPOPMAX, ZADD, ZCARD, ZCOUNT, ZINCRBY, ZINTER, ZINTERSTORE, ZLEXCOUNT, ZMSCORE, ZPOPMIN, ZPOPMAX, ZRANGE, ZRANGEBYSCORE, ZRANK, ZREM, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZREVRANGE, ZREVRANGEBYLEX, ZREVRANGEBYSCORE, ZREVRANK, ZSCAN, ZSCORE, ZUNION, ZUNIONSTORE, ZREMRANGEBYLEX, ZRANGEBYLEX, + BZPOPMIN, BZPOPMAX, ZADD, ZCARD, ZCOUNT, ZINCRBY, ZINTER, ZINTERSTORE, ZLEXCOUNT, ZMSCORE, ZPOPMIN, ZPOPMAX, ZRANGE, ZRANGEBYSCORE, ZRANGESTORE, ZRANK, ZREM, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZREVRANGE, ZREVRANGEBYLEX, ZREVRANGEBYSCORE, ZREVRANK, ZSCAN, ZSCORE, ZUNION, ZUNIONSTORE, ZREMRANGEBYLEX, ZRANGEBYLEX, // Scripting diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSortedSetCoroutinesCommands.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSortedSetCoroutinesCommands.kt index b21bf6049c..645cd59be7 100644 --- a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSortedSetCoroutinesCommands.kt +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSortedSetCoroutinesCommands.kt @@ -385,6 +385,28 @@ interface RedisSortedSetCoroutinesCommands { */ fun zrangebyscoreWithScores(key: K, range: Range, limit: Limit): Flow> + /** + * Get the specified range of elements in the sorted set stored at and stores the result in the 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 + */ + suspend fun zrangestorebylex(dstKey: K, srcKey: K, range: Range, limit: Limit): Long? + + /** + * Get the specified range of elements in the sorted set stored at and stores the result in the 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 + */ + suspend fun zrangestorebyscore(dstKey: K, srcKey: K, range: Range, limit: Limit): Long? + /** * Determine the index of a member in a sorted set. * @@ -519,6 +541,28 @@ interface RedisSortedSetCoroutinesCommands { */ fun zrevrangebyscoreWithScores(key: K, range: Range, limit: Limit): Flow> + /** + * Get the lexicographical range ordered from high to low of elements in the sorted set stored at and stores the result in the 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. + * @since 6.2 + */ + suspend fun zrevrangestorebylex(dstKey: K, srcKey: K, range: Range, limit: Limit): Long? + + /** + * Get the specified range of elements in the sorted set stored at with scores ordered from high to low and stores the result in the destination key. + * + * @param dstKey the src key. + * @param srcKey the dst key. + * @param range the score range. + * @return The number of elements in the resulting sorted set. + * @since 6.2 + */ + suspend fun zrevrangestorebyscore(dstKey: K, srcKey: K, range: Range, limit: Limit): Long? + /** * Determine the index of a member in a sorted set, with scores ordered from high to low. * diff --git a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSortedSetCoroutinesCommandsImpl.kt b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSortedSetCoroutinesCommandsImpl.kt index e3f0a6b7f2..ba1368a30a 100644 --- a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSortedSetCoroutinesCommandsImpl.kt +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSortedSetCoroutinesCommandsImpl.kt @@ -112,6 +112,10 @@ internal class RedisSortedSetCoroutinesCommandsImpl(internal v override fun zrangebyscoreWithScores(key: K, range: Range, limit: Limit): Flow> = ops.zrangebyscoreWithScores(key, range, limit).asFlow() + override suspend fun zrangestorebylex(dstKey: K, srcKey: K, range: Range, limit: Limit): Long? = ops.zrangestorebylex(dstKey, srcKey, range, limit).awaitFirstOrNull() + + override suspend fun zrangestorebyscore(dstKey: K, srcKey: K, range: Range, limit: Limit): Long? = ops.zrangestorebyscore(dstKey, srcKey, range, limit).awaitFirstOrNull() + override suspend fun zrank(key: K, member: V): Long? = ops.zrank(key, member).awaitFirstOrNull() override suspend fun zrem(key: K, vararg members: V): Long? = ops.zrem(key, *members).awaitFirstOrNull() @@ -138,6 +142,10 @@ internal class RedisSortedSetCoroutinesCommandsImpl(internal v override fun zrevrangebyscoreWithScores(key: K, range: Range, limit: Limit): Flow> = ops.zrevrangebyscoreWithScores(key, range, limit).asFlow() + override suspend fun zrevrangestorebylex(dstKey: K, srcKey: K, range: Range, limit: Limit): Long? = ops.zrevrangestorebylex(dstKey, srcKey, range, limit).awaitFirstOrNull() + + override suspend fun zrevrangestorebyscore(dstKey: K, srcKey: K, range: Range, limit: Limit): Long? = ops.zrevrangestorebyscore(dstKey, srcKey, range, limit).awaitFirstOrNull() + override suspend fun zrevrank(key: K, member: V): Long? = ops.zrevrank(key, member).awaitFirstOrNull() override suspend fun zscan(key: K): ScoredValueScanCursor? = ops.zscan(key).awaitFirstOrNull() diff --git a/src/main/templates/io/lettuce/core/api/RedisSortedSetCommands.java b/src/main/templates/io/lettuce/core/api/RedisSortedSetCommands.java index d34c1e6869..2fbbe43e63 100644 --- a/src/main/templates/io/lettuce/core/api/RedisSortedSetCommands.java +++ b/src/main/templates/io/lettuce/core/api/RedisSortedSetCommands.java @@ -730,6 +730,28 @@ Long zrangebyscoreWithScores(ScoredValueStreamingChannel channel, K key, Stri */ Long zrangebyscoreWithScores(ScoredValueStreamingChannel channel, K key, Range range, Limit limit); + /** + * Get the specified range of elements in the sorted set stored at and stores the result in the 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 range, Limit limit); + + /** + * Get the specified range of elements in the sorted set stored at and stores the result in the 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 range, Limit limit); + /** * Determine the index of a member in a sorted set. * @@ -1185,6 +1207,28 @@ Long zrevrangebyscoreWithScores(ScoredValueStreamingChannel channel, K key, S */ Long zrevrangebyscoreWithScores(ScoredValueStreamingChannel channel, K key, Range range, Limit limit); + /** + * Get the lexicographical range ordered from high to low of elements in the sorted set stored at and stores the result in the 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. + * @since 6.2 + */ + Long zrevrangestorebylex(K dstKey, K srcKey, Range range, Limit limit); + + /** + * Get the specified range of elements in the sorted set stored at with scores ordered from high to low and stores the result in the destination key. + * + * @param dstKey the src key. + * @param srcKey the dst 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 range, Limit limit); + /** * Determine the index of a member in a sorted set, with scores ordered from high to low. * diff --git a/src/test/java/io/lettuce/core/commands/SortedSetCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/SortedSetCommandIntegrationTests.java index 6538408f64..6945e6411c 100644 --- a/src/test/java/io/lettuce/core/commands/SortedSetCommandIntegrationTests.java +++ b/src/test/java/io/lettuce/core/commands/SortedSetCommandIntegrationTests.java @@ -418,6 +418,22 @@ void zrangebyscoreWithScoresStreaming() { } + @Test + @EnabledOnCommand("ZRANGESTORE") // Redis 6.2 + void zrangestorebylex() { + redis.zadd(key, 1.0, "a", 2.0, "b", 3.0, "c", 4.0, "d"); + assertThat(redis.zrangestorebylex("key1", key, Range.create("a", "b"), Limit.create(0, 4))).isEqualTo(2); + assertThat(redis.zrange("key1", 0, 2)). isEqualTo(list("a", "b")); + } + + @Test + @EnabledOnCommand("ZRANGESTORE") // Redis 6.2 + void zrangestorebyscore() { + redis.zadd(key, 1.0, "a", 2.0, "b", 3.0, "c", 4.0, "d"); + assertThat(redis.zrangestorebyscore("key1", key, Range.create(0, 2), Limit.create(0, 2))).isEqualTo(2); + assertThat(redis.zrange("key1", 0, 2)).isEqualTo(list("a", "b")); + } + @Test void zrank() { assertThat(redis.zrank(key, "a")).isNull(); @@ -615,6 +631,22 @@ void zrevrank() { assertThat(redis.zrevrank(key, "a")).isEqualTo(2); } + @Test + @EnabledOnCommand("ZRANGESTORE") // Redis 6.2 + void zrevrangestorebylex() { + redis.zadd(key, 1.0, "a", 2.0, "b", 3.0, "c", 4.0, "d"); + assertThat(redis.zrevrangestorebylex("key1", key, Range.create("c", "-"), Limit.create(0, 4))).isEqualTo(3); + assertThat(redis.zrange("key1", 0, 2)). isEqualTo(list("a", "b", "c")); + } + + @Test + @EnabledOnCommand("ZRANGESTORE") // Redis 6.2 + void zrevrangestorebyscore() { + redis.zadd(key, 1.0, "a", 2.0, "b", 3.0, "c", 4.0, "d"); + assertThat(redis.zrevrangestorebyscore("key1", key, Range.from(Boundary.including(2), Boundary.excluding(1)), Limit.create(0, 2))).isEqualTo(1); + assertThat(redis.zrange("key1", 0, 2)).isEqualTo(list("b")); + } + @Test void zscore() { assertThat(redis.zscore(key, "a")).isNull();