Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ public RedisFuture<V> srandmember(K key) {
}

@Override
public RedisFuture<Set<V>> srandmember(K key, long count) {
public RedisFuture<List<V>> srandmember(K key, long count) {
return dispatch(commandBuilder.srandmember(key, count));
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/lambdaworks/redis/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1262,11 +1262,11 @@ public Command<K, V, V> srandmember(K key) {
return createCommand(SRANDMEMBER, new ValueOutput<K, V>(codec), key);
}

public Command<K, V, Set<V>> srandmember(K key, long count) {
public Command<K, V, List<V>> srandmember(K key, long count) {
notNullKey(key);

CommandArgs<K, V> args = new CommandArgs<K, V>(codec).addKey(key).add(count);
return createCommand(SRANDMEMBER, new ValueSetOutput<K, V>(codec), args);
return createCommand(SRANDMEMBER, new ValueListOutput<K, V>(codec), args);
}

public Command<K, V, Long> srandmember(ValueStreamingChannel<V> channel, K key, long count) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lambdaworks.redis;

import java.util.List;
import java.util.Set;

import com.lambdaworks.redis.api.async.RedisSetAsyncCommands;
Expand Down Expand Up @@ -165,7 +166,7 @@ public interface RedisSetsAsyncConnection<K, V> {
* @return RedisFuture&lt;Set&lt;V&gt;&gt; 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<Set<V>> srandmember(K key, long count);
RedisFuture<List<V>> srandmember(K key, long count);

/**
* Get one or multiple random members from a set.
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/lambdaworks/redis/RedisSetsConnection.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lambdaworks.redis;

import java.util.List;
import java.util.Set;

import com.lambdaworks.redis.api.sync.RedisSetCommands;
Expand Down Expand Up @@ -165,7 +166,7 @@ public interface RedisSetsConnection<K, V> {
* @return Set&lt;V&gt; 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<V> srandmember(K key, long count);
List<V> srandmember(K key, long count);

/**
* Get one or multiple random members from a set.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -167,7 +168,7 @@ public interface RedisSetAsyncCommands<K, V> {
* @return Set&lt;V&gt; 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<Set<V>> srandmember(K key, long count);
RedisFuture<List<V>> srandmember(K key, long count);

/**
* Get one or multiple random members from a set.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -166,7 +167,7 @@ public interface RedisSetCommands<K, V> {
* @return Set&lt;V&gt; 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<V> srandmember(K key, long count);
List<V> srandmember(K key, long count);

/**
* Get one or multiple random members from a set.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -167,7 +168,7 @@ public interface NodeSelectionSetAsyncCommands<K, V> {
* @return Set&lt;V&gt; 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<Set<V>> srandmember(K key, long count);
AsyncExecutions<List<V>> srandmember(K key, long count);

/**
* Get one or multiple random members from a set.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -166,7 +167,7 @@ public interface NodeSelectionSetCommands<K, V> {
* @return Set&lt;V&gt; 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<Set<V>> srandmember(K key, long count);
Executions<List<V>> srandmember(K key, long count);

/**
* Get one or multiple random members from a set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public interface RedisSetCommands<K, V> {
* @return Set&lt;V&gt; 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<V> srandmember(K key, long count);
List<V> srandmember(K key, long count);

/**
* Get one or multiple random members from a set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String> rand = redis.srandmember(key, 3);
List<String> rand = redis.srandmember(key, 3);
assertThat(rand).hasSize(3);
assertThat(set("a", "b", "c", "d").containsAll(rand)).isTrue();
List<String> randWithDuplicates = redis.srandmember(key, -10);
assertThat(randWithDuplicates).hasSize(10);
}

@Test
Expand Down