refactor(cache): drop the redundant second clearLastError in leaseEvalSha

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 <noreply@anthropic.com>
This commit is contained in:
Jake BarnbyandClaude Opus 4.8 committed 2026-07-02 03:38:29 +12:00
1 parent a494130eea
commit 56803fcfea
1 file changed
+2 -2
+2 -2
View File
@@ -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);
}