Skip to content

Commit 7fb5cef

Browse files
committed
Add intersectSize methods for SINTERCARD operation in SetOperations
1 parent 92feb11 commit 7fb5cef

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/main/java/org/springframework/data/redis/core/DefaultSetOperations.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,25 @@ public Long intersectAndStore(Collection<K> keys, K destKey) {
140140
return execute(connection -> connection.sInterStore(rawDestKey, rawKeys));
141141
}
142142

143+
@Override
144+
public Long intersectSize(K key, K otherKey) {
145+
return intersectSize(Arrays.asList(key, otherKey));
146+
}
147+
148+
@Override
149+
public Long intersectSize(K key, Collection<K> otherKeys) {
150+
151+
byte[][] rawKeys = rawKeys(key, otherKeys);
152+
return execute(connection -> connection.sInterCard(rawKeys));
153+
}
154+
155+
@Override
156+
public Long intersectSize(Collection<K> keys) {
157+
158+
byte[][] rawKeys = rawKeys(keys);
159+
return execute(connection -> connection.sInterCard(rawKeys));
160+
}
161+
143162
@Override
144163
public Boolean isMember(K key, Object o) {
145164

src/main/java/org/springframework/data/redis/core/SetOperations.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* @author Christoph Strobl
3131
* @author Mark Paluch
3232
* @author Roman Bezpalko
33+
* @author Mingi Lee
3334
*/
3435
@NullUnmarked
3536
public interface SetOperations<K, V> {
@@ -178,6 +179,38 @@ public interface SetOperations<K, V> {
178179
*/
179180
Long intersectAndStore(@NonNull Collection<@NonNull K> keys, @NonNull K destKey);
180181

182+
/**
183+
* Returns the cardinality of the set which would result from the intersection of {@code key} and {@code otherKey}.
184+
*
185+
* @param key must not be {@literal null}.
186+
* @param otherKey must not be {@literal null}.
187+
* @return {@literal null} when used in pipeline / transaction.
188+
* @see <a href="https://redis.io/commands/sintercard">Redis Documentation: SINTERCARD</a>
189+
* @since 3.4
190+
*/
191+
Long intersectSize(@NonNull K key, @NonNull K otherKey);
192+
193+
/**
194+
* Returns the cardinality of the set which would result from the intersection of {@code key} and {@code otherKeys}.
195+
*
196+
* @param key must not be {@literal null}.
197+
* @param otherKeys must not be {@literal null}.
198+
* @return {@literal null} when used in pipeline / transaction.
199+
* @see <a href="https://redis.io/commands/sintercard">Redis Documentation: SINTERCARD</a>
200+
* @since 3.4
201+
*/
202+
Long intersectSize(@NonNull K key, @NonNull Collection<@NonNull K> otherKeys);
203+
204+
/**
205+
* Returns the cardinality of the set which would result from the intersection of all given sets at {@code keys}.
206+
*
207+
* @param keys must not be {@literal null}.
208+
* @return {@literal null} when used in pipeline / transaction.
209+
* @see <a href="https://redis.io/commands/sintercard">Redis Documentation: SINTERCARD</a>
210+
* @since 3.4
211+
*/
212+
Long intersectSize(@NonNull Collection<@NonNull K> keys);
213+
181214
/**
182215
* Union all sets at given {@code keys} and {@code otherKey}.
183216
*

0 commit comments

Comments
 (0)