Redis - Keys Command


Advertisements

Redis KEYS command is used to search keys with a matching pattern.

Return Value

List of keys with a matching pattern (Array).

Syntax

Following is the basic syntax of Redis KEYS command.

redis 127.0.0.1:6379> KEYS PATTERN

Example

First, create a key in Redis and set some value 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, search Redis with keys starting from the keyword tutorial.

redis 127.0.0.1:6379> KEYS tutorial* 
1) "tutorial3" 
2) "tutorial1" 
3) "tutorial2" 

To get a list of all the keys available in Redis, use only *

redis 127.0.0.1:6379> KEYS * 
1) "tutorial3" 
2) "tutorial1" 
3) "tutorial2" 
redis_keys.htm
Advertisements