HRANDFIELD

Since 1.1.0Hashes

Syntax

HRANDFIELD key [count [WITHVALUES]]
  • Flags: readonly
  • ACL categories: @hash, @read, @slow
  • Arity: -2

Returns fields of the hash at key, picked at random.

Options

OptionEffect
countReturn up to count different fields; a negative count returns exactly -count fields, which may repeat.
WITHVALUESReturn each field with its value.

Reply

  • Without count: a field name, or nil if the key does not exist.
  • With count: an array, empty if the key does not exist.

Examples

> HSET h a 1 b 2 c 3
(integer) 3
> HRANDFIELD h
"b"
> HRANDFIELD h -5
1) "b"
2) "b"
3) "a"
4) "c"
5) "a"
> HRANDFIELD h 2 WITHVALUES
1) "b"
2) "2"
3) "c"
4) "3"