ZRANDMEMBER key [count [WITHSCORES]]
@read,
@sortedset,
@slow,
When called with just the key argument, return a random element from the sorted set value stored at key.
If the provided count argument is positive, return an array of distinct elements.
The array's length is either count or the sorted set's cardinality (ZCARD), whichever is lower.
If called with a negative count, the behavior changes and the command is allowed to return the same element multiple times.
In this case, the number of returned elements is the absolute value of the specified count.
The optional WITHSCORES modifier changes the reply so it includes the respective scores of the randomly selected elements from the sorted set.
When the count argument is a positive value this command behaves as follows:
count is bigger than the cardinality of the sorted set, the command will only return the whole sorted set without additional elements.When the count is a negative value, the behavior changes as follows:
count elements, or an empty array if the sorted set is empty (non-existing key), are always returned.| Redis Enterprise |
Redis Cloud |
Notes |
|---|---|---|
| ✅ Standard ✅ Active-Active |
✅ Standard ✅ Active-Active |