SRANDMEMBER

Since 1.1.0Sets

Syntax

SRANDMEMBER key [count]
  • Flags: readonly
  • ACL categories: @read, @set, @slow
  • Arity: -2

Returns members of the 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.
  • With a negative count: exactly -count members, which may repeat.

Examples

> SADD r 1 2 3
(integer) 3
> SRANDMEMBER r 2
1) "2"
2) "1"
> SRANDMEMBER r -5
1) "3"
2) "3"
3) "3"
4) "2"
5) "3"