Skip to content

Add support for SMISMEMBER #2105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.6.0-SNAPSHOT</version>
<version>2.6.0-2037-SNAPSHOT</version>

<name>Spring Data Redis</name>

Expand Down
2 changes: 1 addition & 1 deletion src/main/asciidoc/new-features.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This section briefly covers items that are new and noteworthy in the latest rele
== New in Spring Data Redis 2.6

* Support for `SubscriptionListener` when using `MessageListener` for subscription confirmation callbacks. `ReactiveRedisMessageListenerContainer` and `ReactiveRedisOperations` provide `receiveLater(…)` and `listenToLater(…)` methods to await until Redis acknowledges the subscription.
* Support Redis 6.2 commands (`LPOP`/`RPOP` with `count`, `COPY`, `GETEX`, `GETDEL`, `ZPOPMIN`, `BZPOPMIN`, `ZPOPMAX`, `BZPOPMAX`, `ZMSCORE`, `ZDIFF`, `ZDIFFSTORE`, `ZINTER`, `ZUNION`).
* Support Redis 6.2 commands (`LPOP`/`RPOP` with `count`, `COPY`, `GETEX`, `GETDEL`, `SMISMEMBER`, `ZPOPMIN`, `BZPOPMIN`, `ZPOPMAX`, `BZPOPMAX`, `ZMSCORE`, `ZDIFF`, `ZDIFFSTORE`, `ZINTER`, `ZUNION`).

[[new-in-2.5.0]]
== New in Spring Data Redis 2.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,15 @@ public Boolean sIsMember(byte[] key, byte[] value) {
return convertAndReturn(delegate.sIsMember(key, value), Converters.identityConverter());
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisSetCommands#sIsMember(byte[], byte[]...)
*/
@Override
public List<Boolean> sMIsMember(byte[] key, byte[]... values) {
return convertAndReturn(delegate.sMIsMember(key, values), Converters.identityConverter());
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisSetCommands#sMembers(byte[])
Expand Down Expand Up @@ -2766,6 +2775,15 @@ public Boolean sIsMember(String key, String value) {
return sIsMember(serialize(key), serialize(value));
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.StringRedisConnection#sMIsMember(java.lang.String, java.lang.String...)
*/
@Override
public List<Boolean> sMIsMember(String key, String... values) {
return sMIsMember(serialize(key), serializeMulti(values));
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.StringRedisConnection#sMembers(java.lang.String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,13 @@ default Boolean sIsMember(byte[] key, byte[] value) {
return setCommands().sIsMember(key, value);
}

/** @deprecated in favor of {@link RedisConnection#setCommands()}}. */
@Override
@Deprecated
default List<Boolean> sMIsMember(byte[] key, byte[]... value) {
return setCommands().sMIsMember(key, value);
}

/** @deprecated in favor of {@link RedisConnection#setCommands()}}. */
@Override
@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.springframework.data.redis.connection.ReactiveRedisConnection.CommandResponse;
import org.springframework.data.redis.connection.ReactiveRedisConnection.KeyCommand;
import org.springframework.data.redis.connection.ReactiveRedisConnection.KeyScanCommand;
import org.springframework.data.redis.connection.ReactiveRedisConnection.MultiValueResponse;
import org.springframework.data.redis.connection.ReactiveRedisConnection.NumericResponse;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.lang.Nullable;
Expand Down Expand Up @@ -546,14 +547,94 @@ default Mono<Boolean> sIsMember(ByteBuffer key, ByteBuffer value) {
}

/**
* Check if set at {@link SIsMemberCommand#getKey()} contains {@link SIsMemberCommand#getKey()}.
* Check if set at {@link SIsMemberCommand#getKey()} contains {@link SIsMemberCommand#getValue()}.
*
* @param commands must not be {@literal null}.
* @return
* @see <a href="https://redis.io/commands/sismember">Redis Documentation: SISMEMBER</a>
*/
Flux<BooleanResponse<SIsMemberCommand>> sIsMember(Publisher<SIsMemberCommand> commands);

/**
* {@code SMISMEMBER} command parameters.
*
* @author Mark Paluch
* @since 2.6
* @see <a href="https://redis.io/commands/smismember">Redis Documentation: SMISMEMBER</a>
*/
class SMIsMemberCommand extends KeyCommand {

private final List<ByteBuffer> values;

private SMIsMemberCommand(@Nullable ByteBuffer key, List<ByteBuffer> values) {

super(key);

this.values = values;
}

/**
* Creates a new {@link SMIsMemberCommand} given one or more {@literal values}.
*
* @param value must not be {@literal null}.
* @return a new {@link SMIsMemberCommand} for a {@literal value}.
*/
public static SMIsMemberCommand values(List<ByteBuffer> values) {

Assert.notNull(values, "Values must not be null!");
Assert.notEmpty(values, "Values must not be empty!");

return new SMIsMemberCommand(null, values);
}

/**
* Applies the {@literal set} key. Constructs a new command instance with all previously configured properties.
*
* @param set must not be {@literal null}.
* @return a new {@link SMIsMemberCommand} with {@literal set} applied.
*/
public SMIsMemberCommand of(ByteBuffer set) {

Assert.notNull(set, "Set key must not be null!");

return new SMIsMemberCommand(set, values);
}

/**
* @return
*/
public List<ByteBuffer> getValues() {
return values;
}
}

/**
* Check if set at {@code key} contains one or more {@code values}.
*
* @param key must not be {@literal null}.
* @param values must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 2.6
* @see <a href="https://redis.io/commands/smismember">Redis Documentation: SMISMEMBER</a>
*/
default Mono<List<Boolean>> sMIsMember(ByteBuffer key, List<ByteBuffer> values) {

Assert.notNull(key, "Key must not be null!");
Assert.notNull(values, "Value must not be null!");

return sMIsMember(Mono.just(SMIsMemberCommand.values(values).of(key))).next().map(MultiValueResponse::getOutput);
}

/**
* Check if set at {@link SMIsMemberCommand#getKey()} contains {@link SMIsMemberCommand#getValues()}.
*
* @param commands must not be {@literal null}.
* @return
* @since 2.6
* @see <a href="https://redis.io/commands/smismember">Redis Documentation: SMISMEMBER</a>
*/
Flux<MultiValueResponse<SMIsMemberCommand, Boolean>> sMIsMember(Publisher<SMIsMemberCommand> commands);

/**
* {@code SINTER} command parameters.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ public interface RedisSetCommands {
@Nullable
Boolean sIsMember(byte[] key, byte[] value);

/**
* Check if set at {@code key} contains one or more {@code values}.
*
* @param key must not be {@literal null}.
* @param values must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 2.6
* @see <a href="https://redis.io/commands/smismember">Redis Documentation: SMISMEMBER</a>
*/
@Nullable
List<Boolean> sMIsMember(byte[] key, byte[]... values);

/**
* Diff all sets for given {@code keys}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,19 @@ default Long lPos(String key, String element) {
*/
Boolean sIsMember(String key, String value);

/**
* Check if set at {@code key} contains one or more {@code values}.
*
* @param key must not be {@literal null}.
* @param values must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 2.6
* @see <a href="https://redis.io/commands/smismember">Redis Documentation: SMISMEMBER</a>
* @see RedisSetCommands#sMIsMember(byte[], byte[]...)
*/
@Nullable
List<Boolean> sMIsMember(String key, String... values);

/**
* Returns the members intersecting all given sets at {@code keys}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,24 @@ public Boolean sIsMember(byte[] key, byte[] value) {
}
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisSetCommands#sMIsMember(byte[], byte[]...)
*/
@Override
public List<Boolean> sMIsMember(byte[] key, byte[]... values) {

Assert.notNull(key, "Key must not be null!");
Assert.notNull(values, "Value must not be null!");
Assert.noNullElements(values, "Values must not contain null elements!");

try {
return connection.getCluster().smismember(key, values);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisSetCommands#sInter(byte[][])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ public Boolean sIsMember(byte[] key, byte[] value) {
return connection.invoke().just(BinaryJedis::sismember, MultiKeyPipelineBase::sismember, key, value);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisSetCommands#sMIsMember(byte[], byte[]...)
*/
@Override
public List<Boolean> sMIsMember(byte[] key, byte[]... values) {

Assert.notNull(key, "Key must not be null!");
Assert.notNull(values, "Values must not be null!");
Assert.noNullElements(values, "Values must not contain null elements!");

return connection.invoke().just(BinaryJedis::smismember, MultiKeyPipelineBase::smismember, key, values);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisSetCommands#sMembers(byte[])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import java.nio.ByteBuffer;

import org.reactivestreams.Publisher;

import org.springframework.data.redis.connection.ReactiveRedisConnection.BooleanResponse;
import org.springframework.data.redis.connection.ReactiveRedisConnection.ByteBufferResponse;
import org.springframework.data.redis.connection.ReactiveRedisConnection.CommandResponse;
import org.springframework.data.redis.connection.ReactiveRedisConnection.KeyCommand;
import org.springframework.data.redis.connection.ReactiveRedisConnection.KeyScanCommand;
import org.springframework.data.redis.connection.ReactiveRedisConnection.MultiValueResponse;
import org.springframework.data.redis.connection.ReactiveRedisConnection.NumericResponse;
import org.springframework.data.redis.connection.ReactiveSetCommands;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -163,6 +165,23 @@ public Flux<BooleanResponse<SIsMemberCommand>> sIsMember(Publisher<SIsMemberComm
}));
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.ReactiveSetCommands#sMIsMember(org.reactivestreams.Publisher)
*/
@Override
public Flux<MultiValueResponse<SMIsMemberCommand, Boolean>> sMIsMember(Publisher<SMIsMemberCommand> commands) {

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

Assert.notNull(command.getKey(), "Key must not be null!");
Assert.notNull(command.getValues(), "Values must not be null!");

return cmd.smismember(command.getKey(), command.getValues().toArray(new ByteBuffer[0])).collectList()
.map(value -> new MultiValueResponse<>(command, value));
}));
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.ReactiveSetCommands#sInter(org.reactivestreams.Publisher)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ public Boolean sIsMember(byte[] key, byte[] value) {
return connection.invoke().just(RedisSetAsyncCommands::sismember, key, value);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisSetCommands#sMIsMember(byte[], byte[]...)
*/
@Override
public List<Boolean> sMIsMember(byte[] key, byte[]... values) {

Assert.notNull(key, "Key must not be null!");
Assert.notNull(values, "Values must not be null!");
Assert.noNullElements(values, "Values must not contain null elements!");

return connection.invoke().just(RedisSetAsyncCommands::smismember, key, values);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisSetCommands#sMembers(byte[])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.lang.Nullable;
Expand Down Expand Up @@ -88,6 +89,18 @@ public interface BoundSetOperations<K, V> extends BoundKeyOperations<K> {
@Nullable
Boolean isMember(Object o);

/**
* Check if set at at the bound key contains one or more {@code values}.
*
* @param key must not be {@literal null}.
* @param objects
* @return {@literal null} when used in pipeline / transaction.
* @since 2.6
* @see <a href="https://redis.io/commands/smismember">Redis Documentation: SMISMEMBER</a>
*/
@Nullable
Map<Object, Boolean> isMember(Object... objects);

/**
* Returns the members intersecting all given sets at the bound key and {@code key}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.data.redis.connection.DataType;
Expand Down Expand Up @@ -143,6 +144,15 @@ public Boolean isMember(Object o) {
return ops.isMember(getKey(), o);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.BoundSetOperations#isMember(java.lang.Object...)
*/
@Override
public Map<Object, Boolean> isMember(Object... objects) {
return ops.isMember(getKey(), objects);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.BoundSetOperations#members()
Expand Down
Loading