Use KEYS to list every key in the database whose name matches a glob-style pattern.
The pattern supports * for any sequence of characters, ? for a single character, [...] for character classes, and \ to escape a literal, so user:*:session matches all session keys of all users and * matches everything.
The command walks the entire keyspace and returns all matches in one reply, which on a database of any real size means a long block and a very large response. Treat it as a debugging and maintenance tool: on hot paths use SCAN, which accepts the same MATCH patterns but walks the keyspace in small batches, or keep an index of your keys in a set instead.
Syntax#
Arguments#
| Argument | Required | Repeatable | Description |
|---|---|---|---|
<pattern> | Yes | No | Glob-style pattern to match keys against. |
Important points#
- This command can expose administrative information or make a broad destructive change. Restrict it to trusted code paths.
- This operation can inspect a large part of the database. Prefer cursor-based scans where possible and avoid unbounded use on hot paths.
Response#
The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.
| Protocol | Reply |
|---|---|
| RESP2 | Array of bulk-string keys |
| RESP3 | Array of bulk-string keys |
Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.
Examples#
TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.