From 15d6b5e1c7203441fecda3f71a5be50d149f8b7e Mon Sep 17 00:00:00 2001 From: PatNowak Date: Mon, 13 Jan 2025 09:29:13 +0100 Subject: [PATCH] [Lock] Make sure RedisStore will also support Valkey --- src/Symfony/Component/Lock/Store/RedisStore.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Lock/Store/RedisStore.php b/src/Symfony/Component/Lock/Store/RedisStore.php index 503d3067bf560..23f62898f8d8f 100644 --- a/src/Symfony/Component/Lock/Store/RedisStore.php +++ b/src/Symfony/Component/Lock/Store/RedisStore.php @@ -29,7 +29,7 @@ class RedisStore implements SharedLockStoreInterface { use ExpiringStoreTrait; - private const NO_SCRIPT_ERROR_MESSAGE = 'NOSCRIPT No matching script. Please use EVAL.'; + private const NO_SCRIPT_ERROR_MESSAGE_PREFIX = 'NOSCRIPT No matching script.'; private bool $supportTime; @@ -234,7 +234,7 @@ private function evaluate(string $script, string $resource, array $args): mixed $this->redis->clearLastError(); $result = $this->redis->evalSha($scriptSha, array_merge([$resource], $args), 1); - if (self::NO_SCRIPT_ERROR_MESSAGE === $err = $this->redis->getLastError()) { + if (null !== ($err = $this->redis->getLastError()) && str_starts_with($err, self::NO_SCRIPT_ERROR_MESSAGE_PREFIX)) { $this->redis->clearLastError(); if ($this->redis instanceof \RedisCluster) { @@ -263,7 +263,7 @@ private function evaluate(string $script, string $resource, array $args): mixed $client = $this->redis->_instance($this->redis->_target($resource)); $client->clearLastError(); $result = $client->evalSha($scriptSha, array_merge([$resource], $args), 1); - if (self::NO_SCRIPT_ERROR_MESSAGE === $err = $client->getLastError()) { + if (null !== ($err = $this->redis->getLastError()) && str_starts_with($err, self::NO_SCRIPT_ERROR_MESSAGE_PREFIX)) { $client->clearLastError(); $client->script('LOAD', $script); @@ -285,7 +285,7 @@ private function evaluate(string $script, string $resource, array $args): mixed \assert($this->redis instanceof \Predis\ClientInterface); $result = $this->redis->evalSha($scriptSha, 1, $resource, ...$args); - if ($result instanceof Error && self::NO_SCRIPT_ERROR_MESSAGE === $result->getMessage()) { + if ($result instanceof Error && str_starts_with($result->getMessage(), self::NO_SCRIPT_ERROR_MESSAGE_PREFIX)) { $result = $this->redis->script('LOAD', $script); if ($result instanceof Error) { throw new LockStorageException($result->getMessage());