Keys Randomkey
# Redis RANDOMKEY Command
[!(#) Redis Keys](#)
The Redis RANDOMKEY command returns a random key from the current database.
### Syntax
The basic syntax of the Redis RANDOMKEY command is as follows:
redis 127.0.0.1:6379> RANDOMKEY
### Available Since
>= 1.0.0
### Return Value
When the database is not empty, a key is returned. When the database is empty, nil is returned (on Windows systems, null is returned).
### Example
# Database is not empty
redis> MSET fruit "apple" drink "beer" food "cookies" # Set multiple keys
OK
redis> RANDOMKEY
"fruit"
redis> RANDOMKEY
"food"
redis> KEYS * # View all keys in the database, proving RANDOMKEY does not delete keys
1) "food"
2) "drink"
3) "fruit"
# Database is empty
redis> FLUSHDB # Delete all keys in the current database
OK
redis> RANDOMKEY
(nil)
[!(#) Redis Keys](#)
YouTip