Redis - Keys Random key Command


Advertisements

Redis RANDOMKEY command is used to get a random key from Redis database.

Return Value

String, a random key or nil, if the database is empty.

Syntax

Following is the basic syntax of Redis RANDOMKEY command.

redis 127.0.0.1:6379> RANDOMKEY 

Example

First, create some keys in Redis and set some values in it.

redis 127.0.0.1:6379> SET tutorial1 redis 
OK 
redis 127.0.0.1:6379> SET tutorial2 mysql 
OK 
redis 127.0.0.1:6379> SET tutorial3 mongodb 
OK

Now, get a random key from Redis.

redis 127.0.0.1:6379> RANDOMKEY 
1) tutorial3 
redis_keys.htm
Advertisements