From 56803fcfea15088f9aad0530f593e35602757426 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 2 Jul 2026 03:38:29 +1200 Subject: [PATCH] refactor(cache): drop the redundant second clearLastError in leaseEvalSha MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getLastError()/clearLastError() are client-side accessors (~16ns, no round trip), so cost was never the issue — but the clear before throwing NoScript was dead: the EVAL fallback never reads getLastError() and the next leaseEvalSha clears again. Keep only the leading clear, which is what makes the getLastError() check reflect this call rather than a prior command. Addresses review. Co-Authored-By: Claude Opus 4.8 --- src/Cache/Adapter/Redis.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cache/Adapter/Redis.php b/src/Cache/Adapter/Redis.php index e457d55790..e67c544dcf 100644 --- a/src/Cache/Adapter/Redis.php +++ b/src/Cache/Adapter/Redis.php @@ -195,6 +195,8 @@ class Redis extends Leasable implements Adapter, Retryable protected function leaseEvalSha(string $sha, string $key, array $args): mixed { return $this->execute(function () use ($sha, $key, $args) { + // Client-side reset (no round trip) so the getLastError() check below + // reflects only this evalSha, not an error left by a prior command. $this->redis->clearLastError(); try { @@ -213,8 +215,6 @@ class Redis extends Leasable implements Adapter, Retryable // inspect; NOSCRIPT means leaseRun() should resend the body. $error = (string) $this->redis->getLastError(); if ($result === false && NoScript::matches($error)) { - $this->redis->clearLastError(); - throw NoScript::from($error); }