RANDOMKEY
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).
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| The database has keys | Bulk string: a key name | Bulk string |
| The database is empty | Nil bulk string | Null |
Examples
Section titled “Examples”127.0.0.1:6379> MSET a 1 b 2 c 3OK127.0.0.1:6379> RANDOMKEY"b"Compatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.