Redis – Keys Random key Command

  • Post author:
  • Post category:Redis
  • Post comments:1 Comment

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 Adglob1 redis 
OK 
redis 127.0.0.1:6379> SET Adglob2 mysql 
OK 
redis 127.0.0.1:6379> SET Adglob3 mongodb 
OK

Now, get a random key from Redis.

redis 127.0.0.1:6379> RANDOMKEY 
1) Adglob3 

This Post Has One Comment

Leave a Reply