Concept Flow - KEYS pattern matching (avoid in production)
Start
Input pattern
Scan all keys in Redis
Match keys against pattern
Return matched keys
End
The KEYS command scans all keys in Redis and returns those matching the given pattern.
KEYS user:*
# Returns all keys starting with 'user:'| Step | Action | Current Key | Pattern | Match Result | Output Keys |
|---|---|---|---|---|---|
| 1 | Start scanning keys | user:* | [] | ||
| 2 | Check key | user:1 | user:* | Match | ["user:1"] |
| 3 | Check key | user:2 | user:* | Match | ["user:1", "user:2"] |
| 4 | Check key | session:1 | user:* | No Match | ["user:1", "user:2"] |
| 5 | Check key | user:profile | user:* | Match | ["user:1", "user:2", "user:profile"] |
| 6 | Check key | config | user:* | No Match | ["user:1", "user:2", "user:profile"] |
| 7 | Finish scanning | user:* | ["user:1", "user:2", "user:profile"] |
| Variable | Start | After 1 | After 2 | After 3 | After 4 | After 5 | Final |
|---|---|---|---|---|---|---|---|
| Output Keys | [] | ["user:1"] | ["user:1", "user:2"] | ["user:1", "user:2"] | ["user:1", "user:2", "user:profile"] | ["user:1", "user:2", "user:profile"] | ["user:1", "user:2", "user:profile"] |
KEYS pattern matching in Redis: - Syntax: KEYS <pattern> - Scans all keys to find matches - Patterns use * as wildcard - Not recommended in production due to blocking and performance - Use SCAN for safer iteration