From 905d98535ec7fc6928913323c89bf58ac2845bad Mon Sep 17 00:00:00 2001 From: sokomishalov Date: Fri, 23 Oct 2020 04:06:31 +0300 Subject: [PATCH] ZUNION/ZINTER commands introduced #1450 --- .../core/AbstractRedisAsyncCommands.java | 48 +++- .../core/AbstractRedisReactiveCommands.java | 48 +++- .../io/lettuce/core/CompositeArgument.java | 2 +- .../io/lettuce/core/RedisCommandBuilder.java | 74 +++++- .../java/io/lettuce/core/ZAggregateArgs.java | 215 ++++++++++++++++++ src/main/java/io/lettuce/core/ZStoreArgs.java | 207 +---------------- .../async/RedisSortedSetAsyncCommands.java | 92 +++++++- .../RedisSortedSetReactiveCommands.java | 92 +++++++- .../core/api/sync/RedisSortedSetCommands.java | 92 +++++++- .../NodeSelectionSortedSetAsyncCommands.java | 92 +++++++- .../sync/NodeSelectionSortedSetCommands.java | 92 +++++++- .../io/lettuce/core/protocol/CommandType.java | 3 +- .../RedisSortedSetCoroutinesCommands.kt | 96 +++++++- .../RedisSortedSetCoroutinesCommandsImpl.kt | 23 +- .../core/api/RedisSortedSetCommands.java | 92 +++++++- .../apigenerator/CompilationUnitFactory.java | 2 +- .../KotlinCompilationUnitFactory.java | 2 +- ...ests.java => ZAggregateArgsUnitTests.java} | 6 +- .../SortedSetCommandIntegrationTests.java | 40 +++- 19 files changed, 1058 insertions(+), 260 deletions(-) create mode 100644 src/main/java/io/lettuce/core/ZAggregateArgs.java rename src/test/java/io/lettuce/core/{ZStoreArgsUnitTests.java => ZAggregateArgsUnitTests.java} (89%) diff --git a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java index c7bce91c51..3be735c0d8 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java @@ -1793,14 +1793,34 @@ public RedisFuture zincrby(K key, double amount, V member) { return dispatch(commandBuilder.zincrby(key, amount, member)); } + @Override + public RedisFuture> zinter(long numkey, K... keys) { + return dispatch(commandBuilder.zinter(numkey, keys)); + } + + @Override + public RedisFuture> zinter(long numkey, ZAggregateArgs aggregateArgs, K... keys) { + return dispatch(commandBuilder.zinter(numkey, aggregateArgs, keys)); + } + + @Override + public RedisFuture>> zinterWithScores(long numkey, K... keys) { + return dispatch(commandBuilder.zinterWithScores(numkey, keys)); + } + + @Override + public RedisFuture>> zinterWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys) { + return dispatch(commandBuilder.zinterWithScores(numkey, aggregateArgs, keys)); + } + @Override public RedisFuture zinterstore(K destination, K... keys) { return dispatch(commandBuilder.zinterstore(destination, keys)); } @Override - public RedisFuture zinterstore(K destination, ZStoreArgs storeArgs, K... keys) { - return dispatch(commandBuilder.zinterstore(destination, storeArgs, keys)); + public RedisFuture zinterstore(K destination, ZAggregateArgs aggregateArgs, K... keys) { + return dispatch(commandBuilder.zinterstore(destination, aggregateArgs, keys)); } @Override @@ -2255,14 +2275,34 @@ public RedisFuture zscore(K key, V member) { return dispatch(commandBuilder.zscore(key, member)); } + @Override + public RedisFuture> zunion(long numkey, K... keys) { + return dispatch(commandBuilder.zunion(numkey, keys)); + } + + @Override + public RedisFuture> zunion(long numkey, ZAggregateArgs aggregateArgs, K... keys) { + return dispatch(commandBuilder.zunion(numkey, aggregateArgs, keys)); + } + + @Override + public RedisFuture>> zunionWithScores(long numkey, K... keys) { + return dispatch(commandBuilder.zunionWithScores(numkey, keys)); + } + + @Override + public RedisFuture>> zunionWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys) { + return dispatch(commandBuilder.zunionWithScores(numkey, aggregateArgs, keys)); + } + @Override public RedisFuture zunionstore(K destination, K... keys) { return dispatch(commandBuilder.zunionstore(destination, keys)); } @Override - public RedisFuture zunionstore(K destination, ZStoreArgs storeArgs, K... keys) { - return dispatch(commandBuilder.zunionstore(destination, storeArgs, keys)); + public RedisFuture zunionstore(K destination, ZAggregateArgs aggregateArgs, K... keys) { + return dispatch(commandBuilder.zunionstore(destination, aggregateArgs, keys)); } private byte[] encodeScript(String script) { diff --git a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java index 2987f77a24..044f9fd192 100644 --- a/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java +++ b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java @@ -1866,14 +1866,34 @@ public Mono zincrby(K key, double amount, V member) { return createMono(() -> commandBuilder.zincrby(key, amount, member)); } + @Override + public Flux zinter(long numkey, K... keys) { + return createDissolvingFlux(() -> commandBuilder.zinter(numkey, keys)); + } + + @Override + public Flux zinter(long numkey, ZAggregateArgs aggregateArgs, K... keys) { + return createDissolvingFlux(() -> commandBuilder.zinter(numkey, aggregateArgs, keys)); + } + + @Override + public Flux> zinterWithScores(long numkey, K... keys) { + return createDissolvingFlux(() -> commandBuilder.zinterWithScores(numkey, keys)); + } + + @Override + public Flux> zinterWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys) { + return createDissolvingFlux(() -> commandBuilder.zinterWithScores(numkey, aggregateArgs, keys)); + } + @Override public Mono zinterstore(K destination, K... keys) { return createMono(() -> commandBuilder.zinterstore(destination, keys)); } @Override - public Mono zinterstore(K destination, ZStoreArgs storeArgs, K... keys) { - return createMono(() -> commandBuilder.zinterstore(destination, storeArgs, keys)); + public Mono zinterstore(K destination, ZAggregateArgs aggregateArgs, K... keys) { + return createMono(() -> commandBuilder.zinterstore(destination, aggregateArgs, keys)); } @Override @@ -2320,14 +2340,34 @@ public Mono zscore(K key, V member) { return createMono(() -> commandBuilder.zscore(key, member)); } + @Override + public Flux zunion(long numkey, K... keys) { + return createDissolvingFlux(() -> commandBuilder.zunion(numkey, keys)); + } + + @Override + public Flux zunion(long numkey, ZAggregateArgs aggregateArgs, K... keys) { + return createDissolvingFlux(() -> commandBuilder.zunion(numkey, aggregateArgs, keys)); + } + + @Override + public Flux> zunionWithScores(long numkey, K... keys) { + return createDissolvingFlux(() -> commandBuilder.zunionWithScores(numkey, keys)); + } + + @Override + public Flux> zunionWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys) { + return createDissolvingFlux(() -> commandBuilder.zunionWithScores(numkey, aggregateArgs, keys)); + } + @Override public Mono zunionstore(K destination, K... keys) { return createMono(() -> commandBuilder.zunionstore(destination, keys)); } @Override - public Mono zunionstore(K destination, ZStoreArgs storeArgs, K... keys) { - return createMono(() -> commandBuilder.zunionstore(destination, storeArgs, keys)); + public Mono zunionstore(K destination, ZAggregateArgs aggregateArgs, K... keys) { + return createMono(() -> commandBuilder.zunionstore(destination, aggregateArgs, keys)); } private byte[] encodeScript(String script) { diff --git a/src/main/java/io/lettuce/core/CompositeArgument.java b/src/main/java/io/lettuce/core/CompositeArgument.java index 9c947ce748..e308e423d9 100644 --- a/src/main/java/io/lettuce/core/CompositeArgument.java +++ b/src/main/java/io/lettuce/core/CompositeArgument.java @@ -29,7 +29,7 @@ * @since 5.0 * @see CommandArgs * @see SetArgs - * @see ZStoreArgs + * @see ZAggregateArgs * @see GeoArgs */ public interface CompositeArgument { diff --git a/src/main/java/io/lettuce/core/RedisCommandBuilder.java b/src/main/java/io/lettuce/core/RedisCommandBuilder.java index f1c637c258..ec9b0f5e70 100644 --- a/src/main/java/io/lettuce/core/RedisCommandBuilder.java +++ b/src/main/java/io/lettuce/core/RedisCommandBuilder.java @@ -2609,19 +2609,49 @@ Command zincrby(K key, double amount, V member) { return createCommand(ZINCRBY, new DoubleOutput<>(codec), args); } + Command> zinter(long numkey, K... keys) { + notEmpty(keys); + + return zinter(numkey, new ZAggregateArgs(), keys); + } + + Command> zinter(long numkey, ZAggregateArgs aggregateArgs, K... keys) { + notEmpty(keys); + + CommandArgs args = new CommandArgs<>(codec); + args.add(numkey).addKeys(keys); + aggregateArgs.build(args); + return createCommand(ZINTER, new ValueListOutput<>(codec), args); + } + + Command>> zinterWithScores(long numkey, K... keys) { + notEmpty(keys); + + return zinterWithScores(numkey, new ZAggregateArgs(), keys); + } + + Command>> zinterWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys) { + notEmpty(keys); + + CommandArgs args = new CommandArgs<>(codec); + args.add(numkey).addKeys(keys).add(WITHSCORES); + aggregateArgs.build(args); + return createCommand(ZINTER, new ScoredValueListOutput<>(codec), args); + } + Command zinterstore(K destination, K... keys) { notEmpty(keys); - return zinterstore(destination, new ZStoreArgs(), keys); + return zinterstore(destination, new ZAggregateArgs(), keys); } - Command zinterstore(K destination, ZStoreArgs storeArgs, K... keys) { + Command zinterstore(K destination, ZAggregateArgs aggregateArgs, K... keys) { LettuceAssert.notNull(destination, "Destination " + MUST_NOT_BE_NULL); - LettuceAssert.notNull(storeArgs, "ZStoreArgs " + MUST_NOT_BE_NULL); + LettuceAssert.notNull(aggregateArgs, "ZStoreArgs " + MUST_NOT_BE_NULL); notEmpty(keys); CommandArgs args = new CommandArgs<>(codec).addKey(destination).add(keys.length).addKeys(keys); - storeArgs.build(args); + aggregateArgs.build(args); return createCommand(ZINTERSTORE, new IntegerOutput<>(codec), args); } @@ -3230,19 +3260,49 @@ Command zscore(K key, V member) { return createCommand(ZSCORE, new DoubleOutput<>(codec), key, member); } + Command> zunion(long numkey, K... keys) { + notEmpty(keys); + + return zunion(numkey, new ZAggregateArgs(), keys); + } + + Command> zunion(long numkey, ZAggregateArgs aggregateArgs, K... keys) { + notEmpty(keys); + + CommandArgs args = new CommandArgs<>(codec); + args.add(numkey).addKeys(keys); + aggregateArgs.build(args); + return createCommand(ZUNION, new ValueListOutput<>(codec), args); + } + + Command>> zunionWithScores(long numkey, K... keys) { + notEmpty(keys); + + return zunionWithScores(numkey, new ZAggregateArgs(), keys); + } + + Command>> zunionWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys) { + notEmpty(keys); + + CommandArgs args = new CommandArgs<>(codec); + args.add(numkey).addKeys(keys).add(WITHSCORES); + aggregateArgs.build(args); + return createCommand(ZUNION, new ScoredValueListOutput<>(codec), args); + } + Command zunionstore(K destination, K... keys) { notEmpty(keys); LettuceAssert.notNull(destination, "Destination " + MUST_NOT_BE_NULL); - return zunionstore(destination, new ZStoreArgs(), keys); + return zunionstore(destination, new ZAggregateArgs(), keys); } - Command zunionstore(K destination, ZStoreArgs storeArgs, K... keys) { + Command zunionstore(K destination, ZAggregateArgs aggregateArgs, K... keys) { notEmpty(keys); CommandArgs args = new CommandArgs<>(codec); args.addKey(destination).add(keys.length).addKeys(keys); - storeArgs.build(args); + aggregateArgs.build(args); return createCommand(ZUNIONSTORE, new IntegerOutput<>(codec), args); } diff --git a/src/main/java/io/lettuce/core/ZAggregateArgs.java b/src/main/java/io/lettuce/core/ZAggregateArgs.java new file mode 100644 index 0000000000..6e815b1dd6 --- /dev/null +++ b/src/main/java/io/lettuce/core/ZAggregateArgs.java @@ -0,0 +1,215 @@ +/* + * Copyright 2011-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.lettuce.core; + +import static io.lettuce.core.protocol.CommandKeyword.*; + +import java.util.ArrayList; +import java.util.List; + +import io.lettuce.core.internal.LettuceAssert; +import io.lettuce.core.protocol.CommandArgs; + +/** + * Argument list builder for the Redis ZUNION, + * ZUNIONSTORE, ZINTER and + * ZINTERSTORE commands. Static import the methods from {@link Builder} and + * chain the method calls: {@code weights(1, 2).max()}. + * + * @author Will Glozer + * @author Xy Ma + * @author Mark Paluch + * @author Mikhael Sokolov + */ +public class ZAggregateArgs implements CompositeArgument { + + private enum Aggregate { + SUM, MIN, MAX + } + + private List weights; + + private Aggregate aggregate; + + /** + * Builder entry points for {@link ScanArgs}. + */ + public static class Builder { + + /** + * Utility constructor. + */ + Builder() { + } + + /** + * Creates new {@link ZAggregateArgs} setting {@literal WEIGHTS} using long. + * + * @return new {@link ZAddArgs} with {@literal WEIGHTS} set. + * @see ZAggregateArgs#weights(long[]) + * @deprecated use {@link #weights(double...)}. + */ + @Deprecated + public static ZAggregateArgs weights(long[] weights) { + return new ZAggregateArgs().weights(toDoubleArray(weights)); + } + + /** + * Creates new {@link ZAggregateArgs} setting {@literal WEIGHTS}. + * + * @return new {@link ZAddArgs} with {@literal WEIGHTS} set. + * @see ZAggregateArgs#weights(double...) + */ + public static ZAggregateArgs weights(double... weights) { + return new ZAggregateArgs().weights(weights); + } + + /** + * Creates new {@link ZAggregateArgs} setting {@literal AGGREGATE SUM}. + * + * @return new {@link ZAddArgs} with {@literal AGGREGATE SUM} set. + * @see ZAggregateArgs#sum() + */ + public static ZAggregateArgs sum() { + return new ZAggregateArgs().sum(); + } + + /** + * Creates new {@link ZAggregateArgs} setting {@literal AGGREGATE MIN}. + * + * @return new {@link ZAddArgs} with {@literal AGGREGATE MIN} set. + * @see ZAggregateArgs#sum() + */ + public static ZAggregateArgs min() { + return new ZAggregateArgs().min(); + } + + /** + * Creates new {@link ZAggregateArgs} setting {@literal AGGREGATE MAX}. + * + * @return new {@link ZAddArgs} with {@literal AGGREGATE MAX} set. + * @see ZAggregateArgs#sum() + */ + public static ZAggregateArgs max() { + return new ZAggregateArgs().max(); + } + + } + + /** + * Specify a multiplication factor for each input sorted set. + * + * @param weights must not be {@code null}. + * @return {@code this} {@link ZAggregateArgs}. + * @deprecated use {@link #weights(double...)} + */ + @Deprecated + public static ZAggregateArgs weights(long[] weights) { + + LettuceAssert.notNull(weights, "Weights must not be null"); + + return new ZAggregateArgs().weights(toDoubleArray(weights)); + } + + /** + * Specify a multiplication factor for each input sorted set. + * + * @param weights must not be {@code null}. + * @return {@code this} {@link ZAggregateArgs}. + */ + public ZAggregateArgs weights(double... weights) { + + LettuceAssert.notNull(weights, "Weights must not be null"); + + this.weights = new ArrayList<>(weights.length); + + for (double weight : weights) { + this.weights.add(weight); + } + return this; + } + + /** + * Aggregate scores of elements existing across multiple sets by summing up. + * + * @return {@code this} {@link ZAggregateArgs}. + */ + public ZAggregateArgs sum() { + + this.aggregate = Aggregate.SUM; + return this; + } + + /** + * Aggregate scores of elements existing across multiple sets by using the lowest score. + * + * @return {@code this} {@link ZAggregateArgs}. + */ + public ZAggregateArgs min() { + + this.aggregate = Aggregate.MIN; + return this; + } + + /** + * Aggregate scores of elements existing across multiple sets by using the highest score. + * + * @return {@code this} {@link ZAggregateArgs}. + */ + public ZAggregateArgs max() { + + this.aggregate = Aggregate.MAX; + return this; + } + + private static double[] toDoubleArray(long[] weights) { + + double result[] = new double[weights.length]; + for (int i = 0; i < weights.length; i++) { + result[i] = weights[i]; + } + return result; + } + + public void build(CommandArgs args) { + + if (weights != null && !weights.isEmpty()) { + + args.add(WEIGHTS); + for (double weight : weights) { + args.add(weight); + } + } + + if (aggregate != null) { + args.add(AGGREGATE); + switch (aggregate) { + case SUM: + args.add(SUM); + break; + case MIN: + args.add(MIN); + break; + case MAX: + args.add(MAX); + break; + default: + throw new IllegalArgumentException("Aggregation " + aggregate + " not supported"); + } + } + } + +} diff --git a/src/main/java/io/lettuce/core/ZStoreArgs.java b/src/main/java/io/lettuce/core/ZStoreArgs.java index 39161faa44..9a718315bd 100644 --- a/src/main/java/io/lettuce/core/ZStoreArgs.java +++ b/src/main/java/io/lettuce/core/ZStoreArgs.java @@ -1,216 +1,23 @@ -/* - * Copyright 2011-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package io.lettuce.core; -import static io.lettuce.core.protocol.CommandKeyword.*; - -import java.util.ArrayList; -import java.util.List; - -import io.lettuce.core.internal.LettuceAssert; -import io.lettuce.core.protocol.CommandArgs; - /** - * Argument list builder for the Redis ZUNIONSTORE and - * ZINTERSTORE commands. Static import the methods from {@link Builder} and - * chain the method calls: {@code weights(1, 2).max()}. - * - *

- * {@link ZAddArgs} is a mutable object and instances should be used only once to avoid shared mutable state. + * Argument list builder for the Redis ZUNIONSTORE + * and ZINTERSTORE commands. + * Static import the methods from {@link Builder} an chain the method calls: {@code weights(1, 2).max()}. * * @author Will Glozer * @author Xy Ma * @author Mark Paluch + * @author Mikhael Sokolov */ -public class ZStoreArgs implements CompositeArgument { +public class ZStoreArgs extends ZAggregateArgs { - private enum Aggregate { - SUM, MIN, MAX - } - - private List weights; - - private Aggregate aggregate; - - /** - * Builder entry points for {@link ScanArgs}. - */ - public static class Builder { + public static class Builder extends ZAggregateArgs.Builder { /** * Utility constructor. */ - private Builder() { - } - - /** - * Creates new {@link ZStoreArgs} setting {@literal WEIGHTS} using long. - * - * @return new {@link ZAddArgs} with {@literal WEIGHTS} set. - * @see ZStoreArgs#weights(long[]) - * @deprecated use {@link #weights(double...)}. - */ - @Deprecated - public static ZStoreArgs weights(long[] weights) { - return new ZStoreArgs().weights(toDoubleArray(weights)); - } - - /** - * Creates new {@link ZStoreArgs} setting {@literal WEIGHTS}. - * - * @return new {@link ZAddArgs} with {@literal WEIGHTS} set. - * @see ZStoreArgs#weights(double...) - */ - public static ZStoreArgs weights(double... weights) { - return new ZStoreArgs().weights(weights); - } - - /** - * Creates new {@link ZStoreArgs} setting {@literal AGGREGATE SUM}. - * - * @return new {@link ZAddArgs} with {@literal AGGREGATE SUM} set. - * @see ZStoreArgs#sum() - */ - public static ZStoreArgs sum() { - return new ZStoreArgs().sum(); - } - - /** - * Creates new {@link ZStoreArgs} setting {@literal AGGREGATE MIN}. - * - * @return new {@link ZAddArgs} with {@literal AGGREGATE MIN} set. - * @see ZStoreArgs#sum() - */ - public static ZStoreArgs min() { - return new ZStoreArgs().min(); - } - - /** - * Creates new {@link ZStoreArgs} setting {@literal AGGREGATE MAX}. - * - * @return new {@link ZAddArgs} with {@literal AGGREGATE MAX} set. - * @see ZStoreArgs#sum() - */ - public static ZStoreArgs max() { - return new ZStoreArgs().max(); + Builder() { } - - } - - /** - * Specify a multiplication factor for each input sorted set. - * - * @param weights must not be {@code null}. - * @return {@code this} {@link ZStoreArgs}. - * @deprecated use {@link #weights(double...)} - */ - @Deprecated - public static ZStoreArgs weights(long[] weights) { - - LettuceAssert.notNull(weights, "Weights must not be null"); - - return new ZStoreArgs().weights(toDoubleArray(weights)); - } - - /** - * Specify a multiplication factor for each input sorted set. - * - * @param weights must not be {@code null}. - * @return {@code this} {@link ZStoreArgs}. - */ - public ZStoreArgs weights(double... weights) { - - LettuceAssert.notNull(weights, "Weights must not be null"); - - this.weights = new ArrayList<>(weights.length); - - for (double weight : weights) { - this.weights.add(weight); - } - return this; - } - - /** - * Aggregate scores of elements existing across multiple sets by summing up. - * - * @return {@code this} {@link ZStoreArgs}. - */ - public ZStoreArgs sum() { - - this.aggregate = Aggregate.SUM; - return this; - } - - /** - * Aggregate scores of elements existing across multiple sets by using the lowest score. - * - * @return {@code this} {@link ZStoreArgs}. - */ - public ZStoreArgs min() { - - this.aggregate = Aggregate.MIN; - return this; - } - - /** - * Aggregate scores of elements existing across multiple sets by using the highest score. - * - * @return {@code this} {@link ZStoreArgs}. - */ - public ZStoreArgs max() { - - this.aggregate = Aggregate.MAX; - return this; - } - - private static double[] toDoubleArray(long[] weights) { - - double result[] = new double[weights.length]; - for (int i = 0; i < weights.length; i++) { - result[i] = weights[i]; - } - return result; } - - public void build(CommandArgs args) { - - if (weights != null && !weights.isEmpty()) { - - args.add(WEIGHTS); - for (double weight : weights) { - args.add(weight); - } - } - - if (aggregate != null) { - args.add(AGGREGATE); - switch (aggregate) { - case SUM: - args.add(SUM); - break; - case MIN: - args.add(MIN); - break; - case MAX: - args.add(MAX); - break; - default: - throw new IllegalArgumentException("Aggregation " + aggregate + " not supported"); - } - } - } - } 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 fdc283126b..2db50757f4 100644 --- a/src/main/java/io/lettuce/core/api/async/RedisSortedSetAsyncCommands.java +++ b/src/main/java/io/lettuce/core/api/async/RedisSortedSetAsyncCommands.java @@ -209,6 +209,48 @@ public interface RedisSortedSetAsyncCommands { */ RedisFuture zincrby(K key, double amount, V member); + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + RedisFuture> zinter(long numkey, K... keys); + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + RedisFuture> zinter(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + RedisFuture>> zinterWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + RedisFuture>> zinterWithScores(long numkey, K... keys); + /** * Intersect multiple sorted sets and store the resulting sorted set in a new key. * @@ -222,11 +264,11 @@ public interface RedisSortedSetAsyncCommands { * Intersect multiple sorted sets and store the resulting sorted set in a new key. * * @param destination the destination. - * @param storeArgs the storeArgs. + * @param aggregateArgs the aggregateArgs. * @param keys the keys. * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. */ - RedisFuture zinterstore(K destination, ZStoreArgs storeArgs, K... keys); + RedisFuture zinterstore(K destination, ZAggregateArgs aggregateArgs, K... keys); /** * Count the number of members in a sorted set between a given lexicographical range. @@ -1240,6 +1282,48 @@ public interface RedisSortedSetAsyncCommands { */ RedisFuture zscore(K key, V member); + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + RedisFuture> zunion(long numkey, K... keys); + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + RedisFuture> zunion(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + RedisFuture>> zunionWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + RedisFuture>> zunionWithScores(long numkey, K... keys); + /** * Add multiple sorted sets and store the resulting sorted set in a new key. * @@ -1253,9 +1337,9 @@ public interface RedisSortedSetAsyncCommands { * Add multiple sorted sets and store the resulting sorted set in a new key. * * @param destination the destination. - * @param storeArgs the storeArgs. + * @param aggregateArgs the aggregateArgs. * @param keys the keys. * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. */ - RedisFuture zunionstore(K destination, ZStoreArgs storeArgs, K... keys); + RedisFuture zunionstore(K destination, ZAggregateArgs aggregateArgs, K... keys); } 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 dc2b1e5843..b4a5f0b9ca 100644 --- a/src/main/java/io/lettuce/core/api/reactive/RedisSortedSetReactiveCommands.java +++ b/src/main/java/io/lettuce/core/api/reactive/RedisSortedSetReactiveCommands.java @@ -211,6 +211,48 @@ public interface RedisSortedSetReactiveCommands { */ Mono zincrby(K key, double amount, V member); + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return V array-reply list of elements. + * @since 6.1 + */ + Flux zinter(long numkey, K... keys); + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return V array-reply list of elements. + * @since 6.1 + */ + Flux zinter(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return V array-reply list of scored values. + * @since 6.1 + */ + Flux> zinterWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return V array-reply list of scored values. + * @since 6.1 + */ + Flux> zinterWithScores(long numkey, K... keys); + /** * Intersect multiple sorted sets and store the resulting sorted set in a new key. * @@ -224,11 +266,11 @@ public interface RedisSortedSetReactiveCommands { * Intersect multiple sorted sets and store the resulting sorted set in a new key. * * @param destination the destination. - * @param storeArgs the storeArgs. + * @param aggregateArgs the aggregateArgs. * @param keys the keys. * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. */ - Mono zinterstore(K destination, ZStoreArgs storeArgs, K... keys); + Mono zinterstore(K destination, ZAggregateArgs aggregateArgs, K... keys); /** * Count the number of members in a sorted set between a given lexicographical range. @@ -1290,6 +1332,48 @@ public interface RedisSortedSetReactiveCommands { */ Mono zscore(K key, V member); + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return V array-reply list of elements. + * @since 6.1 + */ + Flux zunion(long numkey, K... keys); + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return V array-reply list of elements. + * @since 6.1 + */ + Flux zunion(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return V array-reply list of scored values. + * @since 6.1 + */ + Flux> zunionWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return V array-reply list of scored values. + * @since 6.1 + */ + Flux> zunionWithScores(long numkey, K... keys); + /** * Add multiple sorted sets and store the resulting sorted set in a new key. * @@ -1303,9 +1387,9 @@ public interface RedisSortedSetReactiveCommands { * Add multiple sorted sets and store the resulting sorted set in a new key. * * @param destination the destination. - * @param storeArgs the storeArgs. + * @param aggregateArgs the aggregateArgs. * @param keys the keys. * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. */ - Mono zunionstore(K destination, ZStoreArgs storeArgs, K... keys); + Mono zunionstore(K destination, ZAggregateArgs aggregateArgs, K... keys); } 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 981b4d2837..69cba318e8 100644 --- a/src/main/java/io/lettuce/core/api/sync/RedisSortedSetCommands.java +++ b/src/main/java/io/lettuce/core/api/sync/RedisSortedSetCommands.java @@ -209,6 +209,48 @@ public interface RedisSortedSetCommands { */ Double zincrby(K key, double amount, V member); + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + List zinter(long numkey, K... keys); + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + List zinter(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + List> zinterWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + List> zinterWithScores(long numkey, K... keys); + /** * Intersect multiple sorted sets and store the resulting sorted set in a new key. * @@ -222,11 +264,11 @@ public interface RedisSortedSetCommands { * Intersect multiple sorted sets and store the resulting sorted set in a new key. * * @param destination the destination. - * @param storeArgs the storeArgs. + * @param aggregateArgs the aggregateArgs. * @param keys the keys. * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. */ - Long zinterstore(K destination, ZStoreArgs storeArgs, K... keys); + Long zinterstore(K destination, ZAggregateArgs aggregateArgs, K... keys); /** * Count the number of members in a sorted set between a given lexicographical range. @@ -1240,6 +1282,48 @@ public interface RedisSortedSetCommands { */ Double zscore(K key, V member); + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + List zunion(long numkey, K... keys); + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + List zunion(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + List> zunionWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + List> zunionWithScores(long numkey, K... keys); + /** * Add multiple sorted sets and store the resulting sorted set in a new key. * @@ -1253,9 +1337,9 @@ public interface RedisSortedSetCommands { * Add multiple sorted sets and store the resulting sorted set in a new key. * * @param destination the destination. - * @param storeArgs the storeArgs. + * @param aggregateArgs the aggregateArgs. * @param keys the keys. * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. */ - Long zunionstore(K destination, ZStoreArgs storeArgs, K... keys); + Long zunionstore(K destination, ZAggregateArgs aggregateArgs, K... keys); } 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 a8367589cc..bbc2296b5b 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 @@ -209,6 +209,48 @@ public interface NodeSelectionSortedSetAsyncCommands { */ AsyncExecutions zincrby(K key, double amount, V member); + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + AsyncExecutions> zinter(long numkey, K... keys); + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + AsyncExecutions> zinter(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + AsyncExecutions>> zinterWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + AsyncExecutions>> zinterWithScores(long numkey, K... keys); + /** * Intersect multiple sorted sets and store the resulting sorted set in a new key. * @@ -222,11 +264,11 @@ public interface NodeSelectionSortedSetAsyncCommands { * Intersect multiple sorted sets and store the resulting sorted set in a new key. * * @param destination the destination. - * @param storeArgs the storeArgs. + * @param aggregateArgs the aggregateArgs. * @param keys the keys. * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. */ - AsyncExecutions zinterstore(K destination, ZStoreArgs storeArgs, K... keys); + AsyncExecutions zinterstore(K destination, ZAggregateArgs aggregateArgs, K... keys); /** * Count the number of members in a sorted set between a given lexicographical range. @@ -1240,6 +1282,48 @@ public interface NodeSelectionSortedSetAsyncCommands { */ AsyncExecutions zscore(K key, V member); + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + AsyncExecutions> zunion(long numkey, K... keys); + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + AsyncExecutions> zunion(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + AsyncExecutions>> zunionWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + AsyncExecutions>> zunionWithScores(long numkey, K... keys); + /** * Add multiple sorted sets and store the resulting sorted set in a new key. * @@ -1253,9 +1337,9 @@ public interface NodeSelectionSortedSetAsyncCommands { * Add multiple sorted sets and store the resulting sorted set in a new key. * * @param destination the destination. - * @param storeArgs the storeArgs. + * @param aggregateArgs the aggregateArgs. * @param keys the keys. * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. */ - AsyncExecutions zunionstore(K destination, ZStoreArgs storeArgs, K... keys); + AsyncExecutions zunionstore(K destination, ZAggregateArgs aggregateArgs, K... keys); } 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 5c6484ac53..8521633874 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 @@ -209,6 +209,48 @@ public interface NodeSelectionSortedSetCommands { */ Executions zincrby(K key, double amount, V member); + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + Executions> zinter(long numkey, K... keys); + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + Executions> zinter(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + Executions>> zinterWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + Executions>> zinterWithScores(long numkey, K... keys); + /** * Intersect multiple sorted sets and store the resulting sorted set in a new key. * @@ -222,11 +264,11 @@ public interface NodeSelectionSortedSetCommands { * Intersect multiple sorted sets and store the resulting sorted set in a new key. * * @param destination the destination. - * @param storeArgs the storeArgs. + * @param aggregateArgs the aggregateArgs. * @param keys the keys. * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. */ - Executions zinterstore(K destination, ZStoreArgs storeArgs, K... keys); + Executions zinterstore(K destination, ZAggregateArgs aggregateArgs, K... keys); /** * Count the number of members in a sorted set between a given lexicographical range. @@ -1240,6 +1282,48 @@ public interface NodeSelectionSortedSetCommands { */ Executions zscore(K key, V member); + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + Executions> zunion(long numkey, K... keys); + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + Executions> zunion(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + Executions>> zunionWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + Executions>> zunionWithScores(long numkey, K... keys); + /** * Add multiple sorted sets and store the resulting sorted set in a new key. * @@ -1253,9 +1337,9 @@ public interface NodeSelectionSortedSetCommands { * Add multiple sorted sets and store the resulting sorted set in a new key. * * @param destination the destination. - * @param storeArgs the storeArgs. + * @param aggregateArgs the aggregateArgs. * @param keys the keys. * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. */ - Executions zunionstore(K destination, ZStoreArgs storeArgs, K... keys); + Executions zunionstore(K destination, ZAggregateArgs aggregateArgs, K... keys); } diff --git a/src/main/java/io/lettuce/core/protocol/CommandType.java b/src/main/java/io/lettuce/core/protocol/CommandType.java index ca9e42509e..2d816d3e9d 100644 --- a/src/main/java/io/lettuce/core/protocol/CommandType.java +++ b/src/main/java/io/lettuce/core/protocol/CommandType.java @@ -24,6 +24,7 @@ * @author Mark Paluch * @author Zhang Jessey * @author dengliming + * @author Mikhael Sokolov */ public enum CommandType implements ProtocolKeyword { @@ -77,7 +78,7 @@ public enum CommandType implements ProtocolKeyword { // Sorted Set - BZPOPMIN, BZPOPMAX, ZADD, ZCARD, ZCOUNT, ZINCRBY, ZINTERSTORE, ZLEXCOUNT, ZMSCORE, ZPOPMIN, ZPOPMAX, ZRANGE, ZRANGEBYSCORE, ZRANK, ZREM, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZREVRANGE, ZREVRANGEBYLEX, ZREVRANGEBYSCORE, ZREVRANK, ZSCAN, ZSCORE, ZUNIONSTORE, ZREMRANGEBYLEX, ZRANGEBYLEX, + 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, // 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 2a4b10be4f..82657b508a 100644 --- a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSortedSetCoroutinesCommands.kt +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSortedSetCoroutinesCommands.kt @@ -184,6 +184,48 @@ interface RedisSortedSetCoroutinesCommands { */ suspend fun zincrby(key: K, amount: Double, member: V): Double? + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List array-reply list of elements. + * @since 6.1 + */ + fun zinter(numkey: Long, vararg keys: K): Flow + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List array-reply list of elements. + * @since 6.1 + */ + fun zinter(numkey: Long, aggregateArgs: ZAggregateArgs, vararg keys: K): Flow + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List array-reply list of scored values. + * @since 6.1 + */ + fun zinterWithScores(numkey: Long, aggregateArgs: ZAggregateArgs, vararg keys: K): Flow> + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List array-reply list of scored values. + * @since 6.1 + */ + fun zinterWithScores(numkey: Long, vararg keys: K): Flow> + /** * Intersect multiple sorted sets and store the resulting sorted set in a new key. * @@ -197,11 +239,11 @@ interface RedisSortedSetCoroutinesCommands { * Intersect multiple sorted sets and store the resulting sorted set in a new key. * * @param destination the destination. - * @param storeArgs the storeArgs. + * @param aggregateArgs the aggregateArgs. * @param keys the keys. * @return Long integer-reply the number of elements in the resulting sorted set at `destination`. */ - suspend fun zinterstore(destination: K, storeArgs: ZStoreArgs, vararg keys: K): Long? + suspend fun zinterstore(destination: K, aggregateArgs: ZAggregateArgs, vararg keys: K): Long? /** * Count the number of members in a sorted set between a given lexicographical range. @@ -218,10 +260,10 @@ interface RedisSortedSetCoroutinesCommands { * * @param key the key. * @param members the member type: value. - * @return List<Double> array-reply list of scores or nil associated with the specified member values. + * @return List array-reply list of scores or nil associated with the specified member values. * @since 6.1 */ - suspend fun zmscore(key: K, vararg members: V): List + suspend fun zmscore(key: K, vararg members: V): List /** * Removes and returns up to count members with the lowest scores in the sorted set stored at key. @@ -534,6 +576,48 @@ interface RedisSortedSetCoroutinesCommands { */ suspend fun zscore(key: K, member: V): Double? + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List array-reply list of elements. + * @since 6.1 + */ + fun zunion(numkey: Long, vararg keys: K): Flow + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List array-reply list of elements. + * @since 6.1 + */ + fun zunion(numkey: Long, aggregateArgs: ZAggregateArgs, vararg keys: K): Flow + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List array-reply list of scored values. + * @since 6.1 + */ + fun zunionWithScores(numkey: Long, aggregateArgs: ZAggregateArgs, vararg keys: K): Flow> + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List array-reply list of scored values. + * @since 6.1 + */ + fun zunionWithScores(numkey: Long, vararg keys: K): Flow> + /** * Add multiple sorted sets and store the resulting sorted set in a new key. * @@ -547,11 +631,11 @@ interface RedisSortedSetCoroutinesCommands { * Add multiple sorted sets and store the resulting sorted set in a new key. * * @param destination the destination. - * @param storeArgs the storeArgs. + * @param aggregateArgs the aggregateArgs. * @param keys the keys. * @return Long integer-reply the number of elements in the resulting sorted set at `destination`. */ - suspend fun zunionstore(destination: K, storeArgs: ZStoreArgs, vararg keys: K): Long? + suspend fun zunionstore(destination: K, aggregateArgs: ZAggregateArgs, vararg keys: K): Long? } 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 3d81d12f59..23fdcb85c3 100644 --- a/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSortedSetCoroutinesCommandsImpl.kt +++ b/src/main/kotlin/io/lettuce/core/api/coroutines/RedisSortedSetCoroutinesCommandsImpl.kt @@ -62,13 +62,21 @@ internal class RedisSortedSetCoroutinesCommandsImpl(internal v override suspend fun zincrby(key: K, amount: Double, member: V): Double? = ops.zincrby(key, amount, member).awaitFirstOrNull() + override fun zinter(numkey: Long, vararg keys: K): Flow = ops.zinter(numkey, *keys).asFlow() + + override fun zinter(numkey: Long, aggregateArgs: ZAggregateArgs, vararg keys: K): Flow = ops.zinter(numkey, aggregateArgs, *keys).asFlow() + + override fun zinterWithScores(numkey: Long, vararg keys: K): Flow> = ops.zinterWithScores(numkey, *keys).asFlow() + + override fun zinterWithScores(numkey: Long, aggregateArgs: ZAggregateArgs, vararg keys: K): Flow> = ops.zinterWithScores(numkey, aggregateArgs, *keys).asFlow() + override suspend fun zinterstore(destination: K, vararg keys: K): Long? = ops.zinterstore(destination, *keys).awaitFirstOrNull() - override suspend fun zinterstore(destination: K, storeArgs: ZStoreArgs, vararg keys: K): Long? = ops.zinterstore(destination, storeArgs, *keys).awaitFirstOrNull() + override suspend fun zinterstore(destination: K, aggregateArgs: ZAggregateArgs, vararg keys: K): Long? = ops.zinterstore(destination, aggregateArgs, *keys).awaitFirstOrNull() override suspend fun zlexcount(key: K, range: Range): Long? = ops.zlexcount(key, range).awaitFirstOrNull() - override suspend fun zmscore(key: K, vararg members: V): List = ops.zmscore(key, *members).awaitFirstOrNull().orEmpty() + override suspend fun zmscore(key: K, vararg members: V): List = ops.zmscore(key, *members).awaitFirstOrNull().orEmpty() override suspend fun zpopmin(key: K): ScoredValue? = ops.zpopmin(key).awaitFirstOrNull() @@ -132,9 +140,16 @@ internal class RedisSortedSetCoroutinesCommandsImpl(internal v override suspend fun zscore(key: K, member: V): Double? = ops.zscore(key, member).awaitFirstOrNull() - override suspend fun zunionstore(destination: K, vararg keys: K): Long? = ops.zunionstore(destination, *keys).awaitFirstOrNull() + override fun zunion(numkey: Long, vararg keys: K): Flow = ops.zunion(numkey, *keys).asFlow() - override suspend fun zunionstore(destination: K, storeArgs: ZStoreArgs, vararg keys: K): Long? = ops.zunionstore(destination, storeArgs, *keys).awaitFirstOrNull() + override fun zunion(numkey: Long, aggregateArgs: ZAggregateArgs, vararg keys: K): Flow = ops.zunion(numkey, aggregateArgs, *keys).asFlow() + + override fun zunionWithScores(numkey: Long, vararg keys: K): Flow> = ops.zunionWithScores(numkey, *keys).asFlow() + + override fun zunionWithScores(numkey: Long, aggregateArgs: ZAggregateArgs, vararg keys: K): Flow> = ops.zunionWithScores(numkey, aggregateArgs, *keys).asFlow() + + override suspend fun zunionstore(destination: K, vararg keys: K): Long? = ops.zunionstore(destination, *keys).awaitFirstOrNull() + override suspend fun zunionstore(destination: K, aggregateArgs: ZAggregateArgs, vararg keys: K): Long? = ops.zunionstore(destination, aggregateArgs, *keys).awaitFirstOrNull() } diff --git a/src/main/templates/io/lettuce/core/api/RedisSortedSetCommands.java b/src/main/templates/io/lettuce/core/api/RedisSortedSetCommands.java index d40a134e3a..be9dee6df3 100644 --- a/src/main/templates/io/lettuce/core/api/RedisSortedSetCommands.java +++ b/src/main/templates/io/lettuce/core/api/RedisSortedSetCommands.java @@ -208,6 +208,48 @@ public interface RedisSortedSetCommands { */ Double zincrby(K key, double amount, V member); + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + List zinter(long numkey, K... keys); + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + List zinter(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + List> zinterWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Intersect multiple sorted sets and returns the resulting sorted. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + List> zinterWithScores(long numkey, K... keys); + /** * Intersect multiple sorted sets and store the resulting sorted set in a new key. * @@ -221,11 +263,11 @@ public interface RedisSortedSetCommands { * Intersect multiple sorted sets and store the resulting sorted set in a new key. * * @param destination the destination. - * @param storeArgs the storeArgs. + * @param aggregateArgs the aggregateArgs. * @param keys the keys. * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. */ - Long zinterstore(K destination, ZStoreArgs storeArgs, K... keys); + Long zinterstore(K destination, ZAggregateArgs aggregateArgs, K... keys); /** * Count the number of members in a sorted set between a given lexicographical range. @@ -1244,6 +1286,48 @@ Long zrevrangebyscoreWithScores(ScoredValueStreamingChannel channel, K key, S */ Double zscore(K key, V member); + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + List zunion(long numkey, K... keys); + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of elements. + * @since 6.1 + */ + List zunion(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param aggregateArgs the aggregateArgs. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + List> zunionWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys); + + /** + * Add multiple sorted sets and returns the resulting sorted set. + * + * @param numkey the numeric key. + * @param keys the keys. + * @return List<V> array-reply list of scored values. + * @since 6.1 + */ + List> zunionWithScores(long numkey, K... keys); + /** * Add multiple sorted sets and store the resulting sorted set in a new key. * @@ -1257,10 +1341,10 @@ Long zrevrangebyscoreWithScores(ScoredValueStreamingChannel channel, K key, S * Add multiple sorted sets and store the resulting sorted set in a new key. * * @param destination the destination. - * @param storeArgs the storeArgs. + * @param aggregateArgs the aggregateArgs. * @param keys the keys. * @return Long integer-reply the number of elements in the resulting sorted set at {@code destination}. */ - Long zunionstore(K destination, ZStoreArgs storeArgs, K... keys); + Long zunionstore(K destination, ZAggregateArgs aggregateArgs, K... keys); } diff --git a/src/test/java/io/lettuce/apigenerator/CompilationUnitFactory.java b/src/test/java/io/lettuce/apigenerator/CompilationUnitFactory.java index 9fc06414f7..e58df93b6a 100644 --- a/src/test/java/io/lettuce/apigenerator/CompilationUnitFactory.java +++ b/src/test/java/io/lettuce/apigenerator/CompilationUnitFactory.java @@ -75,7 +75,7 @@ public CompilationUnitFactory(File templateFile, File sources, String targetPack Predicate methodFilter, Supplier> importSupplier, Consumer typeMutator, Function methodCommentMutator) { this(templateFile, sources, targetPackage, targetName, typeDocFunction, methodReturnTypeFunction, methodDeclaration -> { - }, methodFilter, importSupplier, typeMutator, (m, c) -> methodCommentMutator.apply(c)); + }, methodFilter, importSupplier, typeMutator, (m, c) -> methodCommentMutator != null ? methodCommentMutator.apply(c) : c); } diff --git a/src/test/java/io/lettuce/apigenerator/KotlinCompilationUnitFactory.java b/src/test/java/io/lettuce/apigenerator/KotlinCompilationUnitFactory.java index 835e1c537d..40a0347a17 100644 --- a/src/test/java/io/lettuce/apigenerator/KotlinCompilationUnitFactory.java +++ b/src/test/java/io/lettuce/apigenerator/KotlinCompilationUnitFactory.java @@ -52,7 +52,7 @@ class KotlinCompilationUnitFactory { private static final Set SKIP_IMPORTS = LettuceSets.unmodifiableSet("java.util.List", "java.util.Set", "java.util.Map"); - private static final Set FLOW_METHODS = LettuceSets.unmodifiableSet("keys", "geohash", "georadius", "georadiusbymember", "hgetall", "hmget", "hkeys", "hvals", "sort", "zpopmin", "zpopmax", "zrange", "zrangebylex", "zrangebyscore", "zrangeWithScores", "zrangebyscoreWithScores", "zrevrange", "zrevrangeWithScores", "zrevrangebylex", "zrevrangebyscore", "zrevrangebyscore", "zrevrangebyscoreWithScores", "mget", "sdiff", "sinter", "smembers", "srandmember", "sunion", "xclaim", "xpending", "xrange", "xread", "xreadgroup", "xrevrange", "smismember"); + private static final Set FLOW_METHODS = LettuceSets.unmodifiableSet("keys", "geohash", "georadius", "georadiusbymember", "hgetall", "hmget", "hkeys", "hvals", "sort", "zpopmin", "zpopmax", "zrange", "zrangebylex", "zrangebyscore", "zrangeWithScores", "zrangebyscoreWithScores", "zunion", "zunionWithScores","zinter", "zinterWithScores", "zrevrange", "zrevrangeWithScores", "zrevrangebylex", "zrevrangebyscore", "zrevrangebyscore", "zrevrangebyscoreWithScores", "mget", "sdiff", "sinter", "smembers", "srandmember", "sunion", "xclaim", "xpending", "xrange", "xread", "xreadgroup", "xrevrange", "smismember"); private static final Set NON_SUSPENDABLE_METHODS = LettuceSets.unmodifiableSet("isOpen", "flushCommands", "setAutoFlushCommands"); private static final Set NON_NULLABLE_RESULT_METHODS = LettuceSets.unmodifiableSet("discard", "multi", "exec", diff --git a/src/test/java/io/lettuce/core/ZStoreArgsUnitTests.java b/src/test/java/io/lettuce/core/ZAggregateArgsUnitTests.java similarity index 89% rename from src/test/java/io/lettuce/core/ZStoreArgsUnitTests.java rename to src/test/java/io/lettuce/core/ZAggregateArgsUnitTests.java index 389ba07d8a..4208d2aef0 100644 --- a/src/test/java/io/lettuce/core/ZStoreArgsUnitTests.java +++ b/src/test/java/io/lettuce/core/ZAggregateArgsUnitTests.java @@ -25,13 +25,13 @@ /** * @author Mark Paluch */ -class ZStoreArgsUnitTests { +class ZAggregateArgsUnitTests { @Test void shouldRenderWeights() { CommandArgs args = new CommandArgs<>(StringCodec.UTF8); - ZStoreArgs.Builder.weights(1, 2, 3).build(args); + ZAggregateArgs.Builder.weights(1, 2, 3).build(args); assertThat(args.toString()).contains("WEIGHTS"); } @@ -40,7 +40,7 @@ void shouldRenderWeights() { void shouldOmitWeights() { CommandArgs args = new CommandArgs<>(StringCodec.UTF8); - ZStoreArgs.Builder.weights().build(args); + ZAggregateArgs.Builder.weights().build(args); assertThat(args.toString()).doesNotContain("WEIGHTS"); } diff --git a/src/test/java/io/lettuce/core/commands/SortedSetCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/SortedSetCommandIntegrationTests.java index f1d06364b8..88a12792d9 100644 --- a/src/test/java/io/lettuce/core/commands/SortedSetCommandIntegrationTests.java +++ b/src/test/java/io/lettuce/core/commands/SortedSetCommandIntegrationTests.java @@ -16,10 +16,10 @@ package io.lettuce.core.commands; import static io.lettuce.core.Range.Boundary.including; -import static io.lettuce.core.ZStoreArgs.Builder.max; -import static io.lettuce.core.ZStoreArgs.Builder.min; -import static io.lettuce.core.ZStoreArgs.Builder.sum; -import static io.lettuce.core.ZStoreArgs.Builder.weights; +import static io.lettuce.core.ZAggregateArgs.Builder.max; +import static io.lettuce.core.ZAggregateArgs.Builder.min; +import static io.lettuce.core.ZAggregateArgs.Builder.sum; +import static io.lettuce.core.ZAggregateArgs.Builder.weights; import static java.lang.Double.NEGATIVE_INFINITY; import static java.lang.Double.POSITIVE_INFINITY; import static org.assertj.core.api.Assertions.assertThat; @@ -832,6 +832,38 @@ void zremrangebylex() { } + @Test + @EnabledOnCommand("ZUNION") // Redis 6.2 + void zunion() { + String zset1 = "zset1"; + String zset2 = "zset2"; + + assertThat(redis.zadd(zset1, 1.0, "a")).isEqualTo(1); + assertThat(redis.zadd(zset1, 2.0, "b")).isEqualTo(1); + assertThat(redis.zadd(zset2, 1.0, "a")).isEqualTo(1); + assertThat(redis.zadd(zset2, 2.0, "b")).isEqualTo(1); + assertThat(redis.zadd(zset2, 3.0, "c")).isEqualTo(1); + + assertThat(redis.zunion(2, zset1, zset2)).isEqualTo(list("a", "c", "b")); + assertThat(redis.zunionWithScores(2, zset1, zset2)).isEqualTo(svlist(sv(2.0, "a"), sv(3.0, "c"), sv(4.0, "b"))); + } + + @Test + @EnabledOnCommand("ZINTER") // Redis 6.2 + void zinter() { + String zset1 = "zset1"; + String zset2 = "zset2"; + + assertThat(redis.zadd(zset1, 1.0, "a")).isEqualTo(1); + assertThat(redis.zadd(zset1, 2.0, "b")).isEqualTo(1); + assertThat(redis.zadd(zset2, 1.0, "a")).isEqualTo(1); + assertThat(redis.zadd(zset2, 2.0, "b")).isEqualTo(1); + assertThat(redis.zadd(zset2, 3.0, "c")).isEqualTo(1); + + assertThat(redis.zinter(2, zset1, zset2)).isEqualTo(list("a", "b")); + assertThat(redis.zinterWithScores(2, zset1, zset2)).isEqualTo(svlist(sv(2.0, "a"), sv(4.0, "b"))); + } + void setup100KeyValues(Set expect) { for (int i = 0; i < 100; i++) { redis.zadd(key + 1, i, value + i);