Commit 4990778
fix(redis): use KEYS command instead of SCAN for pattern matching
Problem:
Laravel's PhpRedisConnection has inconsistent behavior between KEYS and SCAN:
- KEYS command: Automatically adds Laravel's Redis prefix to patterns
- SCAN command: Does NOT add prefix, requires full pattern
This caused scanKeys() to return 0 results even when keys existed:
- Pattern sent: laravel_database_queue_metrics:jobs:*
- SCAN looked for: laravel_database_queue_metrics:jobs:* (no auto-prefix)
- KEYS would look for: laravel_database_queue_metrics:jobs:* (auto-prefixed)
Solution:
- Changed scanKeys() to use KEYS command instead of SCAN
- KEYS automatically handles prefix, making behavior consistent
- Simplified MetricsQueryService to use manager->key() pattern
Note: KEYS is fine for our use case because:
1. We use specific patterns (jobs:*:*:*), not wildcard scans
2. Number of job types is limited (not millions of keys)
3. It's called infrequently (overview endpoint)
For production systems with millions of keys, SCAN would be
preferred, but that would require handling phpredis prefix manually.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 422005d commit 4990778
File tree
2 files changed
+10
-17
lines changed- src
- Services
- Storage
2 files changed
+10
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
104 | 103 | | |
105 | 104 | | |
106 | 105 | | |
107 | | - | |
108 | | - | |
| 106 | + | |
| 107 | + | |
109 | 108 | | |
110 | 109 | | |
111 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
154 | 148 | | |
155 | 149 | | |
156 | 150 | | |
| |||
0 commit comments