Description
Symfony version(s) affected
7.2.*
Description
When trying to acquire a lock with symfony lock using a RedisStore
with predis
and a redis cluster, the error Cannot use 'SCRIPT' with redis-cluster
is thrown.
Everything works as expected on symfony/lock
7.1.6, so I guess the issue is somewhere here symfony/lock@v7.1.6...v7.2.0
On symfony/lock
7.2.3, a different error is thrown though, which was already reported in #59686, and solved via a PR.
I tested with the changes introduced in that PR, and the error goes back to what I'm reporting here.
How to reproduce
Create a folder with the following files:
docker-compose.yml
services:
redis:
image: redis:7.4-alpine
ports:
- "6381:6379"
composer.json
{
"name": "acelaya/symfony-lock-error-repro",
"type": "project",
"require": {
"symfony/lock": "7.2.0",
"predis/predis": "^2.3"
}
}
index.php
<?php
declare(strict_types=1);
use Predis\Client;
use Symfony\Component\Lock\LockFactory;
use Symfony\Component\Lock\Store\RedisStore;
require __DIR__ . '/vendor/autoload.php';
$predisClient = new Client(
['tcp://127.0.0.1:6381', 'tcp://127.0.0.1:6381'],
['cluster' => 'redis'],
);
$lockStore = new RedisStore($predisClient);
$lockFactory = new LockFactory($lockStore);
$lock = $lockFactory->createLock('test');
$lock->acquire();
$lock->release();
Then run the following commands:
docker compose up -d
composer install
php index.php
You will see the following error:
PHP Fatal error: Uncaught Predis\NotSupportedException: Cannot use 'SCRIPT' with redis-cluster. in /symfony-lock-bug/vendor/predis/predis/src/Connection/Cluster/RedisCluster.php:354
Stack trace:
#0 /symfony-lock-bug/vendor/predis/predis/src/Connection/Cluster/RedisCluster.php(531): Predis\Connection\Cluster\RedisCluster->getConnectionByCommand()
#1 /symfony-lock-bug/vendor/predis/predis/src/Connection/Cluster/RedisCluster.php(591): Predis\Connection\Cluster\RedisCluster->retryCommandOnFailure()
#2 /symfony-lock-bug/vendor/predis/predis/src/Client.php(381): Predis\Connection\Cluster\RedisCluster->executeCommand()
#3 /symfony-lock-bug/vendor/predis/predis/src/Client.php(335): Predis\Client->executeCommand()
#4 /symfony-lock-bug/vendor/symfony/lock/Store/RedisStore.php(297): Predis\Client->__call()
#5 /symfony-lock-bug/vendor/symfony/lock/Store/RedisStore.php(332): Symfony\Component\Lock\Store\RedisStore->evaluate()
#6 /symfony-lock-bug/vendor/symfony/lock/Store/RedisStore.php(60): Symfony\Component\Lock\Store\RedisStore->getNowCode()
#7 /symfony-lock-bug/vendor/symfony/lock/Lock.php(85): Symfony\Component\Lock\Store\RedisStore->save()
#8 /symfony-lock-bug/index.php(16): Symfony\Component\Lock\Lock->acquire()
#9 {main}
Next Symfony\Component\Lock\Exception\LockAcquiringException: Failed to acquire the "test" lock. in /symfony-lock-bug/vendor/symfony/lock/Lock.php:116
Stack trace:
#0 /symfony-lock-bug/index.php(16): Symfony\Component\Lock\Lock->acquire()
#1 {main}
thrown in /symfony-lock-bug/vendor/symfony/lock/Lock.php on line 116
If you update the composer.json
like this
{
"name": "acelaya/symfony-lock-error-repro",
"type": "project",
"require": {
- "symfony/lock": "7.2.0",
+ "symfony/lock": "7.1.6",
"predis/predis": "^2.3"
}
}
Then run composer update
and then php index.php
, you'll experience no such error.
Possible Solution
No response
Additional Context
Originally reported in shlinkio/shlink#2366