From 6bb2ae0df4bb60ba6b1817e545db54d074d6c646 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 13 Jul 2026 12:27:29 -0400 Subject: [PATCH 1/2] fix(memcache): only fall back to EVAL on Redis NOSCRIPT errors Signed-off-by: Josh --- lib/private/Memcache/Redis.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/private/Memcache/Redis.php b/lib/private/Memcache/Redis.php index edf9a80aad497..d3691c0f2dd06 100644 --- a/lib/private/Memcache/Redis.php +++ b/lib/private/Memcache/Redis.php @@ -39,6 +39,8 @@ class Redis extends Cache implements IMemcacheTTL { private const MAX_TTL = 30 * 24 * 60 * 60; // 1 month + private const NO_SCRIPT_ERROR_MESSAGE_PREFIX = 'NOSCRIPT'; + private \Redis|\RedisCluster|null $cache = null; public function __construct($prefix = '', string $logFile = '') { @@ -218,12 +220,25 @@ protected function evalLua(string $scriptName, array $keys, array $args) { $args = array_merge($keys, $args); $script = self::LUA_SCRIPTS[$scriptName]; - $result = $this->getCache()->evalSha($script[1], $args, count($keys)); - if ($result === false) { - $result = $this->getCache()->eval($script[0], $args, count($keys)); + $cache = $this->getCache(); + $cache->clearLastError(); + + $result = $cache->evalSha($script[1], $args, count($keys)); + if ($result !== false) { + return $result; + } + + $error = $cache->getLastError(); + if ($error !== null && str_starts_with($error, self::NO_SCRIPT_ERROR_MESSAGE_PREFIX)) { + $cache->clearLastError(); + return $cache->eval($script[0], $args, count($keys)); + } + + if ($error !== null) { + throw new \RuntimeException('Redis EVALSHA failed: ' . $error); } - return $result; + return false; } protected static function encodeValue(mixed $value): string { From 02f0ab1f41526a9978d746c3c38eded6f9ba58db Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 13 Jul 2026 13:52:57 -0400 Subject: [PATCH 2/2] chore(memcache): handle wrong type error in evalLua Signed-off-by: Josh --- lib/private/Memcache/Redis.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/private/Memcache/Redis.php b/lib/private/Memcache/Redis.php index d3691c0f2dd06..2602f0070490d 100644 --- a/lib/private/Memcache/Redis.php +++ b/lib/private/Memcache/Redis.php @@ -234,6 +234,10 @@ protected function evalLua(string $scriptName, array $keys, array $args) { return $cache->eval($script[0], $args, count($keys)); } + if ($error !== null && str_starts_with($error, 'WRONGTYPE')) { + return false; + } + if ($error !== null) { throw new \RuntimeException('Redis EVALSHA failed: ' . $error); }