diff --git a/src/main/java/com/lambdaworks/redis/AbstractRedisAsyncCommands.java b/src/main/java/com/lambdaworks/redis/AbstractRedisAsyncCommands.java index 8a5401ee3e..117ae02ade 100644 --- a/src/main/java/com/lambdaworks/redis/AbstractRedisAsyncCommands.java +++ b/src/main/java/com/lambdaworks/redis/AbstractRedisAsyncCommands.java @@ -982,7 +982,7 @@ public RedisFuture srandmember(K key) { } @Override - public RedisFuture> srandmember(K key, long count) { + public RedisFuture> srandmember(K key, long count) { return dispatch(commandBuilder.srandmember(key, count)); } diff --git a/src/main/java/com/lambdaworks/redis/RedisCommandBuilder.java b/src/main/java/com/lambdaworks/redis/RedisCommandBuilder.java index 88b54dd0a9..03a1c63ff9 100644 --- a/src/main/java/com/lambdaworks/redis/RedisCommandBuilder.java +++ b/src/main/java/com/lambdaworks/redis/RedisCommandBuilder.java @@ -1262,11 +1262,11 @@ public Command srandmember(K key) { return createCommand(SRANDMEMBER, new ValueOutput(codec), key); } - public Command> srandmember(K key, long count) { + public Command> srandmember(K key, long count) { notNullKey(key); CommandArgs args = new CommandArgs(codec).addKey(key).add(count); - return createCommand(SRANDMEMBER, new ValueSetOutput(codec), args); + return createCommand(SRANDMEMBER, new ValueListOutput(codec), args); } public Command srandmember(ValueStreamingChannel channel, K key, long count) { diff --git a/src/main/java/com/lambdaworks/redis/RedisSetsAsyncConnection.java b/src/main/java/com/lambdaworks/redis/RedisSetsAsyncConnection.java index 97ab3a61f6..1a5c4aa759 100644 --- a/src/main/java/com/lambdaworks/redis/RedisSetsAsyncConnection.java +++ b/src/main/java/com/lambdaworks/redis/RedisSetsAsyncConnection.java @@ -1,5 +1,6 @@ package com.lambdaworks.redis; +import java.util.List; import java.util.Set; import com.lambdaworks.redis.api.async.RedisSetAsyncCommands; @@ -165,7 +166,7 @@ public interface RedisSetsAsyncConnection { * @return RedisFuture<Set<V>> bulk-string-reply without the additional {@code count} argument the command * returns a Bulk Reply with the randomly selected element, or {@literal null} when {@code key} does not exist. */ - RedisFuture> srandmember(K key, long count); + RedisFuture> srandmember(K key, long count); /** * Get one or multiple random members from a set. diff --git a/src/main/java/com/lambdaworks/redis/RedisSetsConnection.java b/src/main/java/com/lambdaworks/redis/RedisSetsConnection.java index 568624ace9..9104cb8d02 100644 --- a/src/main/java/com/lambdaworks/redis/RedisSetsConnection.java +++ b/src/main/java/com/lambdaworks/redis/RedisSetsConnection.java @@ -1,5 +1,6 @@ package com.lambdaworks.redis; +import java.util.List; import java.util.Set; import com.lambdaworks.redis.api.sync.RedisSetCommands; @@ -165,7 +166,7 @@ public interface RedisSetsConnection { * @return Set<V> bulk-string-reply without the additional {@code count} argument the command returns a Bulk Reply * with the randomly selected element, or {@literal null} when {@code key} does not exist. */ - Set srandmember(K key, long count); + List srandmember(K key, long count); /** * Get one or multiple random members from a set. diff --git a/src/main/java/com/lambdaworks/redis/api/async/RedisSetAsyncCommands.java b/src/main/java/com/lambdaworks/redis/api/async/RedisSetAsyncCommands.java index bafb25ce5d..5f3125ad92 100644 --- a/src/main/java/com/lambdaworks/redis/api/async/RedisSetAsyncCommands.java +++ b/src/main/java/com/lambdaworks/redis/api/async/RedisSetAsyncCommands.java @@ -1,5 +1,6 @@ package com.lambdaworks.redis.api.async; +import java.util.List; import java.util.Set; import com.lambdaworks.redis.ScanArgs; import com.lambdaworks.redis.ScanCursor; @@ -167,7 +168,7 @@ public interface RedisSetAsyncCommands { * @return Set<V> bulk-string-reply without the additional {@code count} argument the command returns a Bulk Reply * with the randomly selected element, or {@literal null} when {@code key} does not exist. */ - RedisFuture> srandmember(K key, long count); + RedisFuture> srandmember(K key, long count); /** * Get one or multiple random members from a set. diff --git a/src/main/java/com/lambdaworks/redis/api/sync/RedisSetCommands.java b/src/main/java/com/lambdaworks/redis/api/sync/RedisSetCommands.java index 9003114aaa..6a67e804e2 100644 --- a/src/main/java/com/lambdaworks/redis/api/sync/RedisSetCommands.java +++ b/src/main/java/com/lambdaworks/redis/api/sync/RedisSetCommands.java @@ -1,5 +1,6 @@ package com.lambdaworks.redis.api.sync; +import java.util.List; import java.util.Set; import com.lambdaworks.redis.ScanArgs; import com.lambdaworks.redis.ScanCursor; @@ -166,7 +167,7 @@ public interface RedisSetCommands { * @return Set<V> bulk-string-reply without the additional {@code count} argument the command returns a Bulk Reply * with the randomly selected element, or {@literal null} when {@code key} does not exist. */ - Set srandmember(K key, long count); + List srandmember(K key, long count); /** * Get one or multiple random members from a set. diff --git a/src/main/java/com/lambdaworks/redis/cluster/api/async/NodeSelectionSetAsyncCommands.java b/src/main/java/com/lambdaworks/redis/cluster/api/async/NodeSelectionSetAsyncCommands.java index af64e2e9b4..6e9d1c6337 100644 --- a/src/main/java/com/lambdaworks/redis/cluster/api/async/NodeSelectionSetAsyncCommands.java +++ b/src/main/java/com/lambdaworks/redis/cluster/api/async/NodeSelectionSetAsyncCommands.java @@ -1,5 +1,6 @@ package com.lambdaworks.redis.cluster.api.async; +import java.util.List; import java.util.Set; import com.lambdaworks.redis.ScanArgs; import com.lambdaworks.redis.ScanCursor; @@ -167,7 +168,7 @@ public interface NodeSelectionSetAsyncCommands { * @return Set<V> bulk-string-reply without the additional {@code count} argument the command returns a Bulk Reply * with the randomly selected element, or {@literal null} when {@code key} does not exist. */ - AsyncExecutions> srandmember(K key, long count); + AsyncExecutions> srandmember(K key, long count); /** * Get one or multiple random members from a set. diff --git a/src/main/java/com/lambdaworks/redis/cluster/api/sync/NodeSelectionSetCommands.java b/src/main/java/com/lambdaworks/redis/cluster/api/sync/NodeSelectionSetCommands.java index e783e0d322..ff8ade03ca 100644 --- a/src/main/java/com/lambdaworks/redis/cluster/api/sync/NodeSelectionSetCommands.java +++ b/src/main/java/com/lambdaworks/redis/cluster/api/sync/NodeSelectionSetCommands.java @@ -1,5 +1,6 @@ package com.lambdaworks.redis.cluster.api.sync; +import java.util.List; import java.util.Set; import com.lambdaworks.redis.ScanArgs; import com.lambdaworks.redis.ScanCursor; @@ -166,7 +167,7 @@ public interface NodeSelectionSetCommands { * @return Set<V> bulk-string-reply without the additional {@code count} argument the command returns a Bulk Reply * with the randomly selected element, or {@literal null} when {@code key} does not exist. */ - Executions> srandmember(K key, long count); + Executions> srandmember(K key, long count); /** * Get one or multiple random members from a set. diff --git a/src/main/templates/com/lambdaworks/redis/api/RedisSetCommands.java b/src/main/templates/com/lambdaworks/redis/api/RedisSetCommands.java index 0f796a874e..56efcb1a10 100644 --- a/src/main/templates/com/lambdaworks/redis/api/RedisSetCommands.java +++ b/src/main/templates/com/lambdaworks/redis/api/RedisSetCommands.java @@ -166,7 +166,7 @@ public interface RedisSetCommands { * @return Set<V> bulk-string-reply without the additional {@code count} argument the command returns a Bulk Reply * with the randomly selected element, or {@literal null} when {@code key} does not exist. */ - Set srandmember(K key, long count); + List srandmember(K key, long count); /** * Get one or multiple random members from a set. diff --git a/src/test/java/com/lambdaworks/redis/commands/SetCommandTest.java b/src/test/java/com/lambdaworks/redis/commands/SetCommandTest.java index 9b649dddbb..f390738fe7 100644 --- a/src/test/java/com/lambdaworks/redis/commands/SetCommandTest.java +++ b/src/test/java/com/lambdaworks/redis/commands/SetCommandTest.java @@ -5,6 +5,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -133,9 +134,11 @@ public void srandmember() throws Exception { redis.sadd(key, "a", "b", "c", "d"); assertThat(set("a", "b", "c", "d").contains(redis.srandmember(key))).isTrue(); assertThat(redis.smembers(key)).isEqualTo(set("a", "b", "c", "d")); - Set rand = redis.srandmember(key, 3); + List rand = redis.srandmember(key, 3); assertThat(rand).hasSize(3); assertThat(set("a", "b", "c", "d").containsAll(rand)).isTrue(); + List randWithDuplicates = redis.srandmember(key, -10); + assertThat(randWithDuplicates).hasSize(10); } @Test