Redis – Keys Command

  • Post author:
  • Post category:Redis
  • Post comments:0 Comments

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

Now, search Redis with keys starting from the keyword tutorial.

redis 127.0.0.1:6379> KEYS Adglob* 
1) "Adglob3" 
2) "Adglob1" 
3) "Adglob2" 

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

redis 127.0.0.1:6379> KEYS * 
1) "Adglob3" 
2) "Adglob1" 
3) "Adglob2" 

Leave a Reply