Debug key naming
Inspecting a development database
Redis · Command
Returns every key name matching a glob-style pattern. Because it can block the Redis server while producing the complete result, reserve it for debugging and exceptional administrative tasks.
KEYS scans the database for every key name matching a glob-style pattern and returns the matches as an array. Pattern characters can select exact names, prefixes, suffixes, or single-character variations, but the command runs synchronously and can block the server while collecting results.
KEYS pattern| Name | Type | Description |
|---|---|---|
pattern | string | A glob-style pattern used to match key names. |
An array reply containing all key names that match the pattern.
redis-cli SET user:1 Alice
redis-cli SET user:2 Bob
redis-cli KEYS 'user:*'Creates two sample keys, then lists keys whose names begin with user:.
Inspecting a development database
Renaming or restructuring a keyspace during maintenance
Checking whether keys with a naming prefix exist
KEYS takes one glob-style pattern and returns every key name matching it. For example, KEYS user:* matches keys whose names begin with user:.
Follow-up: Why can KEYS harm latency? It blocks the Redis server while all matching keys are returned, so large databases can experience substantial pauses.
The pattern is the required argument and uses glob-style matching. A literal pattern matches one name, while wildcard patterns can match groups of names.
Follow-up: What should replace KEYS for incremental traversal? SCAN is the documented alternative when iterating through a keyspace subset because it avoids requesting the entire result at once.
KEYS is intended for debugging and special operations, such as changing keyspace layout. It should not be used in regular application code because it can block the server.
Follow-up: How should a production application find a subset of keys? Prefer SCAN or an appropriate set-based design instead of scanning the full keyspace with KEYS.
SCANSETDELMGET