Skip to content

[Lock] "Cannot use 'SCRIPT' with redis-cluster" after updating to symfony/lock 7.2.* when using a redis cluster with RedisStore #59795

@acelaya

Description

@acelaya

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:

  1. docker compose up -d
  2. composer install
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy