Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

KEYS

Last updated
KEYS pattern
Group
Keys
Complexity
O(N) where N is the number of keys in the database
Arity
2 (exactly, counting the command name)
Flags
read-only, slow
HotKV Cloud
All plans
On-Premise
no license needed

KEYS returns all key names in the selected database that match pattern. It looks at every key in one call, so on a large database it can take a long time. Prefer SCAN in production code and keep KEYS for debugging and small datasets. In a cluster it returns the keys of the node you ask only.

Patterns use glob syntax:

Pattern Matches
* Any sequence of characters, including none
? Exactly one character
[abc] One of the listed characters
[^a] Any character except the listed ones
[a-z] One character in the range
\ Escapes the next character, for example \* for a literal *
Case RESP2 RESP3
Always Array of bulk strings (empty when nothing matches) Array

The order of the keys is not defined.

127.0.0.1:6379> MSET user:1 "ada" user:2 "grace" order:1 "book"
OK
127.0.0.1:6379> KEYS user:*
1) "user:2"
2) "user:1"
127.0.0.1:6379> KEYS nothing:*
(empty array)

Same as Redis 7 and Valkey 8.

SCAN, RANDOMKEY, EXISTS