w3resource

Redis KEY

KEY pattern

Redis KEYS command is used to return all keys matching a pattern.

Supported glob-style patterns:

  • h?llo matches hello, hallo and hxllo
  • h*llo matches hllo and heeeello
  • h[ae]llo matches hello and hallo, but not hillo
  • h[^e]llo matches hallo, hbllo, ... but not hello
  • h[a-b]llo matches hallo and hbllo

Use \ to escape special characters if you want to match them verbatim.

Syntax:

KEYS PATTERN

Available since

1.0.0.

Return Value

Array Reply : List of keys matching pattern (Array).

Return Value Type

Array

Example: Redis KEYS

First, create a key in redis and set some value in it.

127.0.0.1:6379> MSET key 1 key1 2 key2 3 key3 4
OK
127.0.0.1:6379> KEYS *e*
 1) "key"
 2) "user-p"
 3) "keys"
 4) "user"
 5) "languages"
 6) "user-y"
 7) "numbers"
 8) "user-v"
 9) "user-x"
10) "hash key"
11) "key3"
12) "key1"
13) "key2"
127.0.0.1:6379> KEYS s??
(empty list or set)
127.0.0.1:6379> KEYS *
 1) "key"
 2) "user-p"
 3) "langhash"
 4) "keys"
 5) "user"
 6) "xhash"
 7) "languages"
 8) "user-y"
 9) "lang"
10) "numbers"
11) "user-v"
12) "user-x"
13) "hash key"
14) "myhash"
15) "key3"
16) "key1"
17) "key2"

Previous: EXPIREAT
Next: MOVE



Follow us on Facebook and Twitter for latest update.