Skip to content

Commit b4e88c9

Browse files
fix(redis): strip Laravel prefix from keys before getHash()
Problem: Laravel's Redis commands have inconsistent prefix behavior: - keys() returns: "laravel_database_queue_metrics:jobs:..." (WITH prefix) - hgetall() expects: "queue_metrics:jobs:..." (WITHOUT prefix, adds it automatically) When we passed keys() results directly to getHash(), Laravel added prefix twice, looking for non-existent keys. Solution: Strip Laravel's Redis prefix from keys returned by keys() before passing them to getHash(). This ensures getHash() can add the prefix correctly. Result: Overview endpoint now correctly aggregates job counts: - total_jobs_processed: 160 (was 0) - total_jobs_failed: 40 (was 0) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4990778 commit b4e88c9

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Services/MetricsQueryService.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,18 @@ public function getOverview(): array
106106
// Get all job metrics keys
107107
$keys = $driver->scanKeys($pattern);
108108

109+
// Laravel's Redis prefix for stripping
110+
$laravelPrefix = config('database.redis.options.prefix', '');
111+
109112
// Sum metrics from all keys
110-
foreach ($keys as $key) {
111-
// getHash also needs the full key with prefix
112-
$data = $driver->getHash($key);
113+
foreach ($keys as $fullKey) {
114+
// keys() returns keys WITH Laravel prefix already applied
115+
// But getHash() will ADD prefix again, so we need to strip it first
116+
$relativeKey = $laravelPrefix !== ''
117+
? str_replace($laravelPrefix, '', $fullKey)
118+
: $fullKey;
119+
120+
$data = $driver->getHash($relativeKey);
113121
if (is_array($data)) {
114122
$totalProcessed += (int) ($data['total_processed'] ?? 0);
115123
$totalFailed += (int) ($data['total_failed'] ?? 0);

0 commit comments

Comments
 (0)