Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
* @author Dennis Neufeld
* @author Shyngys Sapraliyev
* @author Jeonggyu Choi
* @author Mingi Lee
*/
@NullUnmarked
@SuppressWarnings({ "ConstantConditions", "deprecation" })
Expand Down Expand Up @@ -832,6 +833,11 @@ public Long sInterStore(byte[] destKey, byte[]... keys) {
return convertAndReturn(delegate.sInterStore(destKey, keys), Converters.identityConverter());
}

@Override
public Long sInterCard(byte[]... keys) {
return convertAndReturn(delegate.sInterCard(keys), Converters.identityConverter());
}

@Override
public Boolean sIsMember(byte[] key, byte[] value) {
return convertAndReturn(delegate.sIsMember(key, value), Converters.identityConverter());
Expand Down Expand Up @@ -1824,6 +1830,11 @@ public Long sInterStore(String destKey, String... keys) {
return sInterStore(serialize(destKey), serializeMulti(keys));
}

@Override
public Long sInterCard(String... keys) {
return sInterCard(serializeMulti(keys));
}

@Override
public Boolean sIsMember(String key, String value) {
return sIsMember(serialize(key), serialize(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
* @author Dennis Neufeld
* @author Shyngys Sapraliyev
* @author Tihomir Mateev
* @author Mingi Lee
* @since 2.0
*/
@Deprecated
Expand Down Expand Up @@ -890,6 +891,13 @@ default Long sInterStore(byte[] destKey, byte[]... keys) {
return setCommands().sInterStore(destKey, keys);
}

/** @deprecated in favor of {@link RedisConnection#setCommands()}}. */
@Override
@Deprecated
default Long sInterCard(byte[]... keys) {
return setCommands().sInterCard(keys);
}

/** @deprecated in favor of {@link RedisConnection#setCommands()}}. */
@Override
@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
*
* @author Christoph Strobl
* @author Mark Paluch
* @author Mingi Lee
* @since 2.0
*/
public interface ReactiveSetCommands {
Expand Down Expand Up @@ -775,6 +776,73 @@ default Mono<Long> sInterStore(ByteBuffer destinationKey, Collection<ByteBuffer>
*/
Flux<NumericResponse<SInterStoreCommand, Long>> sInterStore(Publisher<SInterStoreCommand> commands);

/**
* {@code SINTERCARD} command parameters.
*
* @author Mingi Lee
* @since 4.0
* @see <a href="https://redis.io/commands/sintercard">Redis Documentation: SINTERCARD</a>
*/
class SInterCardCommand implements Command {

private final List<ByteBuffer> keys;

private SInterCardCommand(List<ByteBuffer> keys) {
this.keys = keys;
}

/**
* Creates a new {@link SInterCardCommand} given a {@link Collection} of keys.
*
* @param keys must not be {@literal null}.
* @return a new {@link SInterCardCommand} for a {@link Collection} of keys.
*/
public static SInterCardCommand keys(Collection<ByteBuffer> keys) {

Assert.notNull(keys, "Keys must not be null");

return new SInterCardCommand(new ArrayList<>(keys));
}

@Override
public @Nullable ByteBuffer getKey() {
return null;
}

/**
* @return never {@literal null}.
*/
public List<ByteBuffer> getKeys() {
return keys;
}
}

/**
* Returns the cardinality of the set which would result from the intersection of all given sets at {@literal keys}.
*
* @param keys must not be {@literal null}.
* @return
* @see <a href="https://redis.io/commands/sintercard">Redis Documentation: SINTERCARD</a>
* @since 4.0
*/
default Mono<Long> sInterCard(Collection<ByteBuffer> keys) {

Assert.notNull(keys, "Keys must not be null");

return sInterCard(Mono.just(SInterCardCommand.keys(keys))).next().map(NumericResponse::getOutput);
}

/**
* Returns the cardinality of the set which would result from the intersection of all given sets at
* {@link SInterCardCommand#getKeys()}.
*
* @param commands must not be {@literal null}.
* @return
* @see <a href="https://redis.io/commands/sintercard">Redis Documentation: SINTERCARD</a>
* @since 4.0
*/
Flux<NumericResponse<SInterCardCommand, Long>> sInterCard(Publisher<SInterCardCommand> commands);

/**
* {@code SUNION} command parameters.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @author Costin Leau
* @author Christoph Strobl
* @author Mark Paluch
* @author Mingi Lee
* @see RedisCommands
*/
@NullUnmarked
Expand Down Expand Up @@ -153,6 +154,16 @@ public interface RedisSetCommands {
*/
Long sInterStore(byte @NonNull [] destKey, byte @NonNull [] @NonNull... keys);

/**
* Returns the cardinality of the set which would result from the intersection of all the given sets.
*
* @param keys must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="https://redis.io/commands/sintercard">Redis Documentation: SINTERCARD</a>
* @since 4.0
*/
Long sInterCard(byte @NonNull [] @NonNull... keys);

/**
* Union all sets at given {@code keys}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
* @author ihaohong
* @author Shyngys Sapraliyev
* @author Jeonggyu Choi
* @author Mingi Lee
* @see RedisCallback
* @see RedisSerializer
* @see StringRedisTemplate
Expand Down Expand Up @@ -1169,6 +1170,17 @@ String bLMove(@NonNull String sourceKey, @NonNull String destinationKey, @NonNul
*/
Long sInterStore(@NonNull String destKey, @NonNull String @NonNull... keys);

/**
* Returns the cardinality of the set which would result from the intersection of all the given sets.
*
* @param keys must not be {@literal null}.
* @return
* @see <a href="https://redis.io/commands/sintercard">Redis Documentation: SINTERCARD</a>
* @see RedisSetCommands#sInterCard(byte[]...)
* @since 4.0
*/
Long sInterCard(@NonNull String @NonNull... keys);

/**
* Union all sets at given {@code keys}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
/**
* @author Christoph Strobl
* @author Mark Paluch
* @author Mingi Lee
* @since 2.0
*/
class JedisClusterSetCommands implements RedisSetCommands {
Expand Down Expand Up @@ -230,6 +231,25 @@ public Long sInterStore(byte[] destKey, byte[]... keys) {
return sAdd(destKey, result.toArray(new byte[result.size()][]));
}

@Override
public Long sInterCard(byte[]... keys) {

Assert.notNull(keys, "Keys must not be null");
Assert.noNullElements(keys, "Keys must not contain null elements");

if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) {
try {
return connection.getCluster().sintercard(keys);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}

// For multi-slot clusters, calculate intersection cardinality by performing intersection
Set<byte[]> result = sInter(keys);
return (long) result.size();
}

@Override
public Set<byte[]> sUnion(byte[]... keys) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
/**
* @author Christoph Strobl
* @author Mark Paluch
* @author Mingi Lee
* @since 2.0
*/
@NullUnmarked
Expand Down Expand Up @@ -105,6 +106,15 @@ public Long sInterStore(byte @NonNull [] destKey, byte @NonNull [] @NonNull... k
return connection.invoke().just(Jedis::sinterstore, PipelineBinaryCommands::sinterstore, destKey, keys);
}

@Override
public Long sInterCard(byte @NonNull [] @NonNull... keys) {

Assert.notNull(keys, "Keys must not be null");
Assert.noNullElements(keys, "Keys must not contain null elements");

return connection.invoke().just(Jedis::sintercard, PipelineBinaryCommands::sintercard, keys);
}

@Override
public Boolean sIsMember(byte @NonNull [] key, byte @NonNull [] value) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
/**
* @author Christoph Strobl
* @author Mark Paluch
* @author Mingi Lee
* @since 2.0
*/
class LettuceClusterSetCommands extends LettuceSetCommands {
Expand Down Expand Up @@ -118,6 +119,21 @@ public Long sInterStore(byte[] destKey, byte[]... keys) {
return sAdd(destKey, result.toArray(new byte[result.size()][]));
}

@Override
public Long sInterCard(byte[]... keys) {

Assert.notNull(keys, "Keys must not be null");
Assert.noNullElements(keys, "Keys must not contain null elements");

if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) {
return super.sInterCard(keys);
}

// For multi-slot clusters, calculate intersection cardinality by performing intersection
Set<byte[]> result = sInter(keys);
return (long) result.size();
}

@Override
public Set<byte[]> sUnion(byte[]... keys) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
/**
* @author Christoph Strobl
* @author Mark Paluch
* @author Mingi Lee
* @since 2.0
*/
class LettuceReactiveSetCommands implements ReactiveSetCommands {
Expand Down Expand Up @@ -175,6 +176,18 @@ public Flux<NumericResponse<SInterStoreCommand, Long>> sInterStore(Publisher<SIn
}));
}

@Override
public Flux<NumericResponse<SInterCardCommand, Long>> sInterCard(Publisher<SInterCardCommand> commands) {

return connection.execute(cmd -> Flux.from(commands).concatMap(command -> {

Assert.notNull(command.getKeys(), "Keys must not be null");

return cmd.sintercard(command.getKeys().toArray(new ByteBuffer[0]))
.map(value -> new NumericResponse<>(command, value));
}));
}

@Override
public Flux<CommandResponse<SUnionCommand, Flux<ByteBuffer>>> sUnion(Publisher<SUnionCommand> commands) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
/**
* @author Christoph Strobl
* @author Mark Paluch
* @author Mingi Lee
* @since 2.0
*/
@NullUnmarked
Expand Down Expand Up @@ -106,6 +107,15 @@ public Long sInterStore(byte @NonNull [] destKey, byte @NonNull [] @NonNull... k
return connection.invoke().just(RedisSetAsyncCommands::sinterstore, destKey, keys);
}

@Override
public Long sInterCard(byte @NonNull [] @NonNull... keys) {

Assert.notNull(keys, "Keys must not be null");
Assert.noNullElements(keys, "Keys must not contain null elements");

return connection.invoke().just(RedisSetAsyncCommands::sintercard, keys);
}

@Override
public Boolean sIsMember(byte @NonNull [] key, byte @NonNull [] value) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*
* @author Costin Leau
* @author Mark Paluch
* @author Mingi Lee
*/
@NullUnmarked
public interface BoundSetOperations<K, V> extends BoundKeyOperations<K> {
Expand Down Expand Up @@ -131,6 +132,26 @@ public interface BoundSetOperations<K, V> extends BoundKeyOperations<K> {
*/
void intersectAndStore(@NonNull Collection<@NonNull K> keys, @NonNull K destKey);

/**
* Returns the cardinality of the set which would result from the intersection of the bound key and {@code key}.
*
* @param key must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="https://redis.io/commands/sintercard">Redis Documentation: SINTERCARD</a>
* @since 4.0
*/
Long intersectSize(@NonNull K key);

/**
* Returns the cardinality of the set which would result from the intersection of the bound key and {@code keys}.
*
* @param keys must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see <a href="https://redis.io/commands/sintercard">Redis Documentation: SINTERCARD</a>
* @since 4.0
*/
Long intersectSize(@NonNull Collection<@NonNull K> keys);

/**
* Union all sets at given {@code key} and {@code key}.
*
Expand Down
Loading