From dbba523031f134dbb86d477cb05da9acdb98e117 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 31 Aug 2025 19:38:23 -0600 Subject: [PATCH] Update StoryIndexService, improve redis compatability --- app/Services/StoryIndexService.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Services/StoryIndexService.php b/app/Services/StoryIndexService.php index a6cf26c42..097695e24 100644 --- a/app/Services/StoryIndexService.php +++ b/app/Services/StoryIndexService.php @@ -190,7 +190,11 @@ class StoryIndexService $pipe->hset($keyStory, 'view_count', (string) $viewCount); $pipe->expire($keyStory, (int) $ttl); - $pipe->zadd($keyAuth, [$sid => $score]); + if (config('database.redis.client') === 'predis') { + $pipe->zadd($keyAuth, [$sid => $score]); + } else { + $pipe->zadd($keyAuth, $score, $sid); + } $pipe->sadd('story:active_authors', $author); $pipe->expire($keyAuth, (int) ($ttl + 3600)); }); @@ -234,7 +238,11 @@ class StoryIndexService { $lockKey = $this->rebuildLockKey(); - if (! Redis::set($lockKey, '1', 'EX', self::REBUILD_LOCK_TTL, 'NX')) { + $lockAcquired = config('database.redis.client') === 'predis' + ? Redis::set($lockKey, '1', 'EX', self::REBUILD_LOCK_TTL, 'NX') + : Redis::set($lockKey, '1', ['ex' => self::REBUILD_LOCK_TTL, 'nx' => true]); + + if (! $lockAcquired) { return ['status' => 'already_rebuilding', 'message' => 'Index rebuild already in progress']; }