From 80ba3f29525e49fd310aef951621a8364c501e4e Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Thu, 11 Nov 2021 09:38:03 +0300 Subject: [PATCH] Feature - countIntersection() method added to RScoredSortedSet object. #3942 --- .../org/redisson/RedissonScoredSortedSet.java | 28 +++++++++++++++++++ .../org/redisson/api/RScoredSortedSet.java | 21 ++++++++++++++ .../redisson/api/RScoredSortedSetAsync.java | 21 ++++++++++++++ .../api/RScoredSortedSetReactive.java | 21 ++++++++++++++ .../org/redisson/api/RScoredSortedSetRx.java | 21 ++++++++++++++ .../client/protocol/RedisCommands.java | 1 + 6 files changed, 113 insertions(+) diff --git a/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java b/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java index 2f37fc0bc..9acfc1733 100644 --- a/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java +++ b/redisson/src/main/java/org/redisson/RedissonScoredSortedSet.java @@ -943,6 +943,34 @@ public class RedissonScoredSortedSet extends RedissonExpirable implements RSc return commandExecutor.writeAsync(getRawName(), codec, RedisCommands.ZINTER, args.toArray()); } + @Override + public Integer countIntersection(String... names) { + return get(countIntersectionAsync(names)); + } + + @Override + public Integer countIntersection(int limit, String... names) { + return get(countIntersectionAsync(limit, names)); + } + + @Override + public RFuture countIntersectionAsync(String... names) { + return countIntersectionAsync(0, names); + } + + @Override + public RFuture countIntersectionAsync(int limit, String... names) { + List args = new ArrayList<>(names.length + 1); + args.add(getRawName()); + args.add(names.length); + args.addAll(Arrays.asList(names)); + if (limit > 0) { + args.add("LIMIT"); + args.add(limit); + } + return commandExecutor.writeAsync(getRawName(), codec, RedisCommands.ZINTERCARD_INT, args.toArray()); + } + @Override public int union(String... names) { return get(unionAsync(names)); diff --git a/redisson/src/main/java/org/redisson/api/RScoredSortedSet.java b/redisson/src/main/java/org/redisson/api/RScoredSortedSet.java index 3e160a110..ae1ec1d0f 100644 --- a/redisson/src/main/java/org/redisson/api/RScoredSortedSet.java +++ b/redisson/src/main/java/org/redisson/api/RScoredSortedSet.java @@ -930,6 +930,27 @@ public interface RScoredSortedSet extends RScoredSortedSetAsync, Iterable< */ Collection readIntersection(Map nameWithWeight); + /** + * Counts elements of set as a result of sets intersection with current set. + *

+ * Requires Redis 7.0.0 and higher. + * + * @param names - name of sets + * @return amount of elements + */ + Integer countIntersection(String... names); + + /** + * Counts elements of set as a result of sets intersection with current set. + *

+ * Requires Redis 7.0.0 and higher. + * + * @param names - name of sets + * @param limit - sets intersection limit + * @return amount of elements + */ + Integer countIntersection(int limit, String... names); + /** * Intersect provided ScoredSortedSets mapped to weight multiplier * with current ScoredSortedSet using defined aggregation method diff --git a/redisson/src/main/java/org/redisson/api/RScoredSortedSetAsync.java b/redisson/src/main/java/org/redisson/api/RScoredSortedSetAsync.java index 2d2216d76..700e832f3 100644 --- a/redisson/src/main/java/org/redisson/api/RScoredSortedSetAsync.java +++ b/redisson/src/main/java/org/redisson/api/RScoredSortedSetAsync.java @@ -808,6 +808,27 @@ public interface RScoredSortedSetAsync extends RExpirableAsync, RSortableAsyn */ RFuture> readIntersectionAsync(Aggregate aggregate, Map nameWithWeight); + /** + * Counts elements of set as a result of sets intersection with current set. + *

+ * Requires Redis 7.0.0 and higher. + * + * @param names - name of sets + * @return amount of elements + */ + RFuture countIntersectionAsync(String... names); + + /** + * Counts elements of set as a result of sets intersection with current set. + *

+ * Requires Redis 7.0.0 and higher. + * + * @param names - name of sets + * @param limit - sets intersection limit + * @return amount of elements + */ + RFuture countIntersectionAsync(int limit, String... names); + /** * Union provided ScoredSortedSets * and store result to current ScoredSortedSet diff --git a/redisson/src/main/java/org/redisson/api/RScoredSortedSetReactive.java b/redisson/src/main/java/org/redisson/api/RScoredSortedSetReactive.java index 2cffde387..204011549 100644 --- a/redisson/src/main/java/org/redisson/api/RScoredSortedSetReactive.java +++ b/redisson/src/main/java/org/redisson/api/RScoredSortedSetReactive.java @@ -833,6 +833,27 @@ public interface RScoredSortedSetReactive extends RExpirableReactive, RSortab */ Mono> readIntersection(Aggregate aggregate, Map nameWithWeight); + /** + * Counts elements of set as a result of sets intersection with current set. + *

+ * Requires Redis 7.0.0 and higher. + * + * @param names - name of sets + * @return amount of elements + */ + Mono countIntersection(String... names); + + /** + * Counts elements of set as a result of sets intersection with current set. + *

+ * Requires Redis 7.0.0 and higher. + * + * @param names - name of sets + * @param limit - sets intersection limit + * @return amount of elements + */ + Mono countIntersection(int limit, String... names); + /** * Union provided ScoredSortedSets * and store result to current ScoredSortedSet diff --git a/redisson/src/main/java/org/redisson/api/RScoredSortedSetRx.java b/redisson/src/main/java/org/redisson/api/RScoredSortedSetRx.java index 3073f3b9f..db9c40533 100644 --- a/redisson/src/main/java/org/redisson/api/RScoredSortedSetRx.java +++ b/redisson/src/main/java/org/redisson/api/RScoredSortedSetRx.java @@ -835,6 +835,27 @@ public interface RScoredSortedSetRx extends RExpirableRx, RSortableRx> */ Single> readIntersection(Aggregate aggregate, Map nameWithWeight); + /** + * Counts elements of set as a result of sets intersection with current set. + *

+ * Requires Redis 7.0.0 and higher. + * + * @param names - name of sets + * @return amount of elements + */ + Single countIntersection(String... names); + + /** + * Counts elements of set as a result of sets intersection with current set. + *

+ * Requires Redis 7.0.0 and higher. + * + * @param names - name of sets + * @param limit - sets intersection limit + * @return amount of elements + */ + Single countIntersection(int limit, String... names); + /** * Union provided ScoredSortedSets * and store result to current ScoredSortedSet diff --git a/redisson/src/main/java/org/redisson/client/protocol/RedisCommands.java b/redisson/src/main/java/org/redisson/client/protocol/RedisCommands.java index b6eadc193..a7f931d59 100644 --- a/redisson/src/main/java/org/redisson/client/protocol/RedisCommands.java +++ b/redisson/src/main/java/org/redisson/client/protocol/RedisCommands.java @@ -84,6 +84,7 @@ public interface RedisCommands { RedisStrictCommand> ZDIFF = new RedisStrictCommand<>("ZDIFF", new ObjectListReplayDecoder<>()); RedisCommand> ZUNION = new RedisCommand<>("ZUNION", new ObjectListReplayDecoder<>()); RedisCommand> ZINTER = new RedisCommand<>("ZINTER", new ObjectListReplayDecoder<>()); + RedisStrictCommand ZINTERCARD_INT = new RedisStrictCommand<>("ZINTERCARD", new IntegerReplayConvertor()); RedisStrictCommand ZDIFFSTORE_INT = new RedisStrictCommand("ZDIFFSTORE", new IntegerReplayConvertor()); RedisStrictCommand ZUNIONSTORE_INT = new RedisStrictCommand("ZUNIONSTORE", new IntegerReplayConvertor()); RedisStrictCommand ZINTERSTORE_INT = new RedisStrictCommand("ZINTERSTORE", new IntegerReplayConvertor());