VRANDMEMBER

Since 1.1.0Vector sets

Syntax

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

Returns elements of the vector set at key, picked at random. Use it to sample a set, for example to take a few stored vectors as test queries for VSIM.

  • Without count: one element, as a string.
  • With a positive count: up to count different elements; all of them, in random order, if the set has fewer.
  • With a negative count: exactly -count elements, which may repeat.
  • 0: an empty array.

A count that is not an integer is ERR COUNT value is not an integer, and more arguments are refused, as in Redis, since 1.2.1.

Reply

  • An element, or nil without count when the key does not exist.
  • An array of elements with count; (empty array) when the key does not exist.
  • WRONGTYPE if the key holds another type.

Examples

> VRANDMEMBER points
"a"
> VRANDMEMBER points 2
1) "b"
2) "c"
> VRANDMEMBER points 10
1) "c"
2) "b"
3) "a"
> VRANDMEMBER points -5
1) "c"
2) "c"
3) "a"
4) "a"
5) "c"
> VRANDMEMBER missing
(nil)