Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

RANDOMKEY

Last updated
RANDOMKEY
Group
Keys
Complexity
O(1)
Arity
1 (exactly, counting the command name)
Flags
read-only
HotKV Cloud
All plans
On-Premise
no license needed

RANDOMKEY returns the name of a key picked at random from the selected database. Use it for sampling or spot checks; it is not meant for iterating over the keyspace (use SCAN for that).

Case RESP2 RESP3
The database has keys Bulk string: a key name Bulk string
The database is empty Nil bulk string Null
127.0.0.1:6379> MSET a 1 b 2 c 3
OK
127.0.0.1:6379> RANDOMKEY
"b"

Same as Redis 7 and Valkey 8.

SCAN, KEYS