ZRANDMEMBER

Since 1.1.0Sorted sets

Syntax

ZRANDMEMBER key [count [WITHSCORES]]
  • Flags: readonly
  • ACL categories: @read, @slow, @sortedset
  • Arity: -2

Returns members of the sorted set at key, picked at random, without removing them.

Reply

  • Without count: a member, or nil if the key does not exist.
  • With a positive count: up to count different members; a negative count returns exactly -count, which may repeat. WITHSCORES gives each score.

Examples

> ZADD rr 1 a 2 b 3 c
(integer) 3
> ZRANDMEMBER rr 2 WITHSCORES
1) "b"
2) "2"
3) "a"
4) "1"