Skip to content

Commit cd23f4b

Browse files
committed
Add intersectSize methods for SINTERCARD operation in RedisSet
Signed-off-by: Kiminni <imk0980@gmail.com>
1 parent bebdda7 commit cd23f4b

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/main/java/org/springframework/data/redis/support/collections/DefaultRedisSet.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* @author Costin Leau
3434
* @author Christoph Strobl
3535
* @author Mark Paluch
36+
* @author Mingi Lee
3637
*/
3738
public class DefaultRedisSet<E> extends AbstractRedisCollection<E> implements RedisSet<E> {
3839

@@ -117,6 +118,16 @@ public RedisSet<E> intersectAndStore(Collection<? extends RedisSet<?>> sets, Str
117118
return new DefaultRedisSet<>(boundSetOps.getOperations().boundSetOps(destKey));
118119
}
119120

121+
@Override
122+
public Long intersectSize(RedisSet<?> set) {
123+
return boundSetOps.intersectSize(set.getKey());
124+
}
125+
126+
@Override
127+
public Long intersectSize(Collection<? extends RedisSet<?>> sets) {
128+
return boundSetOps.intersectSize(CollectionUtils.extractKeys(sets));
129+
}
130+
120131
@Override
121132
public Set<E> union(RedisSet<?> set) {
122133
return boundSetOps.union(set.getKey());

src/main/java/org/springframework/data/redis/support/collections/RedisSet.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* @author Costin Leau
2929
* @author Christoph Strobl
3030
* @author Mark Paluch
31+
* @author Mingi Lee
3132
*/
3233
public interface RedisSet<E> extends RedisCollection<E>, Set<E> {
3334

@@ -122,6 +123,28 @@ static <E> RedisSet<E> create(String key, RedisOperations<String, E> operations)
122123
*/
123124
RedisSet<E> intersectAndStore(Collection<? extends RedisSet<?>> sets, String destKey);
124125

126+
/**
127+
* Returns the cardinality of the set which would result from the intersection of this set and another
128+
* {@link RedisSet}.
129+
*
130+
* @param set must not be {@literal null}.
131+
* @return the cardinality of the intersection.
132+
* @see <a href="https://redis.io/commands/sintercard">Redis Documentation: SINTERCARD</a>
133+
* @since 4.0
134+
*/
135+
Long intersectSize(RedisSet<?> set);
136+
137+
/**
138+
* Returns the cardinality of the set which would result from the intersection of this set and other
139+
* {@link RedisSet}s.
140+
*
141+
* @param sets must not be {@literal null}.
142+
* @return the cardinality of the intersection.
143+
* @see <a href="https://redis.io/commands/sintercard">Redis Documentation: SINTERCARD</a>
144+
* @since 4.0
145+
*/
146+
Long intersectSize(Collection<? extends RedisSet<?>> sets);
147+
125148
/**
126149
* Get random element from the set.
127150
*

0 commit comments

Comments
 (0)