RANDOMKEY
Since 1.1.0Keys
Syntax
RANDOMKEYReturns the name of a key of the current database, picked at random, or nil if the database has no keys. It is useful to sample a database: what kinds of keys it holds, or how their sizes or times to live look, without listing them all. To go through every key, use SCAN.
A key whose time to live has run out is not returned: it is deleted as it is found, and another key is picked. While writes are paused, by CLIENT PAUSE WRITE, such a key cannot be deleted, and if every pick finds one, it is returned, as in Redis.
Only the connection's current database is looked at; SELECT another to sample it.
Reply
- A key name.
nilif the database is empty.
Examples
> FLUSHDB
OK
> RANDOMKEY
(nil)
> SET k1 1
OK
> RANDOMKEY
"k1"
> RANDOMKEY extra
(error) ERR wrong number of arguments for 'randomkey' command