Skip to content
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

Add support for ZMSCORE、SMISMEMBER command #1456

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Add support for SMISMEMBER command
dengliming committed Oct 11, 2020
commit 01b9193d8a2f994bf60afe5a4bf31d70cc1c1921
6 changes: 6 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@
* @author Will Glozer
* @author Mark Paluch
* @author Tugdual Grall
* @author dengliming
*/
@SuppressWarnings("unchecked")
public abstract class AbstractRedisAsyncCommands<K, V> implements RedisHashAsyncCommands<K, V>, RedisKeyAsyncCommands<K, V>,
@@ -1485,6 +1486,11 @@ public RedisFuture<StreamScanCursor> sscan(ValueStreamingChannel<V> channel, K k
return dispatch(commandBuilder.sscanStreaming(channel, key, scanCursor));
}

@Override
public RedisFuture<List<Boolean>> smismember(K key, V... members) {
return dispatch(commandBuilder.smismember(key, members));
}

@Override
public RedisFuture<Long> strlen(K key) {
return dispatch(commandBuilder.strlen(key));
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@
* @author Mark Paluch
* @author Nikolai Perevozchikov
* @author Tugdual Grall
* @author dengliming
* @since 4.0
*/
public abstract class AbstractRedisReactiveCommands<K, V> implements RedisHashReactiveCommands<K, V>,
@@ -1557,6 +1558,11 @@ public Mono<StreamScanCursor> sscan(ValueStreamingChannel<V> channel, K key, Sca
return createMono(() -> commandBuilder.sscanStreaming(channel, key, scanCursor));
}

@Override
public Flux<Boolean> smismember(K key, V... members) {
return createDissolvingFlux(() -> commandBuilder.smismember(key, members));
}

@Override
public Mono<Long> strlen(K key) {
return createMono(() -> commandBuilder.strlen(key));
8 changes: 8 additions & 0 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
@@ -2060,6 +2060,14 @@ Command<K, V, StreamScanCursor> sscanStreaming(ValueStreamingChannel<V> channel,
return createCommand(SSCAN, output, args);
}

Command<K, V, List<Boolean>> smismember(K key, V... members) {
notNullKey(key);
LettuceAssert.notNull(members, "Members " + MUST_NOT_BE_NULL);
LettuceAssert.notEmpty(members, "Members " + MUST_NOT_BE_EMPTY);

return createCommand(SMISMEMBER, new BooleanListOutput<>(codec), key, members);
}

Command<K, V, Long> strlen(K key) {
notNullKey(key);

Original file line number Diff line number Diff line change
@@ -303,4 +303,13 @@ public interface RedisSetAsyncCommands<K, V> {
*/
RedisFuture<StreamScanCursor> sscan(ValueStreamingChannel<V> channel, K key, ScanCursor scanCursor);

/**
* Returns whether each member is a member of the set stored at key.
*
* @param key the key.
* @param members the member type: value.
* @return List&lt;Boolean&gt; array-reply list representing the membership of the given elements, in the same order as they are requested.
*/
RedisFuture<List<Boolean>> smismember(K key, V... members);

}
Original file line number Diff line number Diff line change
@@ -330,4 +330,14 @@ public interface RedisSetReactiveCommands<K, V> {
*/
@Deprecated
Mono<StreamScanCursor> sscan(ValueStreamingChannel<V> channel, K key, ScanCursor scanCursor);

/**
* Returns whether each member is a member of the set stored at key.
*
* @param key the key.
* @param members the member type: value.
* @return List&lt;Boolean&gt; array-reply list representing the membership of the given elements, in the same order as they are requested.
*/
Flux<Boolean> smismember(K key, V... members);

}
9 changes: 9 additions & 0 deletions src/main/java/io/lettuce/core/api/sync/RedisSetCommands.java
Original file line number Diff line number Diff line change
@@ -306,4 +306,13 @@ public interface RedisSetCommands<K, V> {
*/
StreamScanCursor sscan(ValueStreamingChannel<V> channel, K key, ScanCursor scanCursor);

/**
* Returns whether each member is a member of the set stored at key.
*
* @param key the key.
* @param members the member type: value.
* @return List&lt;Boolean&gt; array-reply list representing the membership of the given elements, in the same order as they are requested.
*/
List<Boolean> smismember(K key, V... members);

}
Original file line number Diff line number Diff line change
@@ -306,4 +306,12 @@ public interface NodeSelectionSetAsyncCommands<K, V> {
*/
AsyncExecutions<StreamScanCursor> sscan(ValueStreamingChannel<V> channel, K key, ScanCursor scanCursor);

/**
* Returns whether each member is a member of the set stored at key.
*
* @param key the key.
* @param members the member type: value.
* @return List&lt;Boolean&gt; array-reply list representing the membership of the given elements, in the same order as they are requested.
*/
AsyncExecutions<List<Boolean>> smismember(K key, V... members);
}
Original file line number Diff line number Diff line change
@@ -306,4 +306,13 @@ public interface NodeSelectionSetCommands<K, V> {
*/
Executions<StreamScanCursor> sscan(ValueStreamingChannel<V> channel, K key, ScanCursor scanCursor);

/**
* Returns whether each member is a member of the set stored at key.
*
* @param key the key.
* @param members the member type: value.
* @return List&lt;Boolean&gt; array-reply list representing the membership of the given elements, in the same order as they are requested.
*/
Executions<List<Boolean>> smismember(K key, V... members);

}
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/protocol/CommandType.java
Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@ public enum CommandType implements ProtocolKeyword {

// Sets

SADD, SCARD, SDIFF, SDIFFSTORE, SINTER, SINTERSTORE, SISMEMBER, SMEMBERS, SMOVE, SPOP, SRANDMEMBER, SREM, SUNION, SUNIONSTORE, SSCAN,
SADD, SCARD, SDIFF, SDIFFSTORE, SINTER, SINTERSTORE, SISMEMBER, SMEMBERS, SMOVE, SPOP, SRANDMEMBER, SREM, SUNION, SUNIONSTORE, SSCAN, SMISMEMBER,

// Sorted Set

Original file line number Diff line number Diff line change
@@ -218,5 +218,14 @@ interface RedisSetCoroutinesCommands<K : Any, V : Any> {
*/
suspend fun sscan(key: K, scanCursor: ScanCursor): ValueScanCursor<V>?

/**
* Returns whether each member is a member of the set stored at key.
*
* @param key the key.
* @param members the member type: value.
* @return List<Boolean> array-reply list representing the membership of the given elements, in the same order as they are requested.
*/
fun smismember(key: K, vararg members: V): Flow<Boolean>

}

Original file line number Diff line number Diff line change
@@ -80,5 +80,7 @@ internal class RedisSetCoroutinesCommandsImpl<K : Any, V : Any>(private val ops:

override suspend fun sscan(key: K, scanCursor: ScanCursor): ValueScanCursor<V>? = ops.sscan(key, scanCursor).awaitFirstOrNull()

override fun smismember(key: K, vararg members: V): Flow<Boolean> = ops.smismember(key, *members).asFlow()

}

8 changes: 8 additions & 0 deletions src/main/templates/io/lettuce/core/api/RedisSetCommands.java
Original file line number Diff line number Diff line change
@@ -304,4 +304,12 @@ public interface RedisSetCommands<K, V> {
*/
StreamScanCursor sscan(ValueStreamingChannel<V> channel, K key, ScanCursor scanCursor);

/**
* Returns whether each member is a member of the set stored at key.
*
* @param key the key.
* @param members the member type: value.
* @return List&lt;Boolean&gt; array-reply list representing the membership of the given elements, in the same order as they are requested.
*/
List<Boolean> smismember(K key, V... members);
}
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@
class KotlinCompilationUnitFactory {

private static final Set<String> SKIP_IMPORTS = LettuceSets.unmodifiableSet("java.util.List", "java.util.Set", "java.util.Map");
private static final Set<String> FLOW_METHODS = LettuceSets.unmodifiableSet("keys", "geohash", "georadius", "georadiusbymember", "hgetall", "hmget", "hkeys", "hvals", "sort", "zpopmin", "zpopmax", "zrange", "zrangebylex", "zrangebyscore", "zrangeWithScores", "zrangebyscoreWithScores", "zrevrange", "zrevrangeWithScores", "zrevrangebylex", "zrevrangebyscore", "zrevrangebyscore", "zrevrangebyscoreWithScores", "mget", "sdiff", "sinter", "smembers", "srandmember", "sunion", "xclaim", "xpending", "xrange", "xread", "xreadgroup", "xrevrange");
private static final Set<String> FLOW_METHODS = LettuceSets.unmodifiableSet("keys", "geohash", "georadius", "georadiusbymember", "hgetall", "hmget", "hkeys", "hvals", "sort", "zpopmin", "zpopmax", "zrange", "zrangebylex", "zrangebyscore", "zrangeWithScores", "zrangebyscoreWithScores", "zrevrange", "zrevrangeWithScores", "zrevrangebylex", "zrevrangebyscore", "zrevrangebyscore", "zrevrangebyscoreWithScores", "mget", "sdiff", "sinter", "smembers", "srandmember", "sunion", "xclaim", "xpending", "xrange", "xread", "xreadgroup", "xrevrange", "smismember");
private static final Set<String> NON_SUSPENDABLE_METHODS = LettuceSets.unmodifiableSet("isOpen", "flushCommands", "setAutoFlushCommands");

private static final Set<String> NON_NULLABLE_RESULT_METHODS = LettuceSets.unmodifiableSet("discard", "multi", "exec",
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@
/**
* @author Will Glozer
* @author Mark Paluch
* @author dengliming
*/
@ExtendWith(LettuceExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@@ -370,6 +371,14 @@ void scanMatch() {
assertThat(cursor.getValues()).hasSize(11);
}

@Test
void smismember() {
assertThat(redis.smismember(key, "a")).isEqualTo(list(false));
redis.sadd(key, "a");
assertThat(redis.smismember(key, "a")).isEqualTo(list(true));
assertThat(redis.smismember(key, "b", "a")).isEqualTo(list(false, true));
}

void setup100KeyValues(Set<String> expect) {
for (int i = 0; i < 100; i++) {
redis.sadd(key, value + i);