Thanks to visit codestin.com
Credit goes to github.com

Skip to content

RedisTrait is incompatible with PhpRedis 6.0 when using RedisSentinel and a DSN #51678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Qonstrukt opened this issue Sep 18, 2023 · 10 comments
Closed

Comments

@Qonstrukt
Copy link
Contributor

Qonstrukt commented Sep 18, 2023

Symfony version(s) affected

6.3.x

Description

Version 6.0 of PhpRedis (ext-redis) got released a little over a week ago, and unfortunately the API of RedisSentinel changed such that it's no longer compatible with the way it's being constructed from Symfony\Component\Cache\Traits\RedisTrait when using a DSN.
This will throw errors like:

{
 "class": "ArgumentCountError",
 "message": "RedisSentinel::__construct() expects at most 1 argument, 6 given",
 "code": 0,
 "file": "/var/www/html/vendor/symfony/cache/Traits/RedisTrait.php:228",
 "trace": [
  "/var/www/html/vendor/symfony/cache/Traits/RedisTrait.php:228",
  "/var/www/html/vendor/symfony/cache/Traits/Redis6Proxy.php:656",
  "/var/www/html/vendor/symfony/cache/Traits/RedisTrait.php:400",
  "/var/www/html/vendor/symfony/cache/Traits/AbstractAdapterTrait.php:195",
  "/var/www/html/vendor/symfony/cache-contracts/CacheTrait.php:44",
  "/var/www/html/vendor/symfony/cache/Traits/ContractsTrait.php:85",
  "/var/www/html/vendor/symfony/cache-contracts/CacheTrait.php:30",
  "/var/www/html/src/Momo/Application/Health/Controller/HealthController.php:28",
  "/var/www/html/vendor/symfony/http-kernel/HttpKernel.php:182",
  "/var/www/html/vendor/symfony/http-kernel/HttpKernel.php:76",
  "/var/www/html/vendor/symfony/http-kernel/Kernel.php:197",
  "/var/www/html/vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:35",
  "/var/www/html/vendor/autoload_runtime.php:29",
  "/var/www/html/public/index.php:5"
 ]
}

The constructor of RedisSentinel is now synchronised with the one used in the Redis class:
phpredis/phpredis@ebb2386e

Perhaps there are more compatibility issues, but we haven't run into them with just a single Redis Node, without sentinel on our dev environment.

How to reproduce

Using a DSN like this causes problems:

parameters:
    redis_service: 'my-redis-service'
    redis_domain:  '%redis_service%-headless.redis.svc.cluster.local'
    redis_port:    26379
    redis_db:      0
    redis_dsn: >-
        redis:?
        host[%redis_service%-node-0.%redis_domain%:%redis_port%]&
        host[%redis_service%-node-1.%redis_domain%:%redis_port%]&
        host[%redis_service%-node-2.%redis_domain%:%redis_port%]&
        redis_sentinel=mymaster&
        dbindex=%redis_db%

framework:
    cache:
        default_redis_provider: '%redis_dsn%'

Possible Solution

Support the new single parameter constructor for at least RedisSentinel, which is now synchronised with the Redis class implementation.

Additional Context

No response

@Qonstrukt Qonstrukt added the Bug label Sep 18, 2023
@xabbuh xabbuh added the Cache label Sep 18, 2023
@derrabus
Copy link
Member

Thank you for your report. Would you be able to work on a fix for the 5.4 branch?

@Qonstrukt
Copy link
Contributor Author

Qonstrukt commented Sep 18, 2023

No problem. I'll see if I can make some time later today.
Are there any best practices that I can follow to detect which constructor should be used? (Or where I can best search for them.) Not sure if Reflection is permitted? Or would a try/catch suffice?

@derrabus
Copy link
Member

Reflection is fine, I think. I'd prefer to detect the correct way of calling the constructor before we actually call it.

@stof
Copy link
Member

stof commented Sep 18, 2023

or using phpversion('redis') to get the version of the extension.

@Qonstrukt
Copy link
Contributor Author

I've create a PR on the 5.4 branch, but there are some changes in the 6.x tree that might make it harder to directly merge it over.

nicolas-grekas added a commit that referenced this issue Sep 19, 2023
….0 (Qonstrukt)

This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[Cache] Fix support for Redis Sentinel using php-redis 6.0.0

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #51678
| License       | MIT

Added support for [php-redis 6.0.0](https://github.com/phpredis/phpredis/blob/develop/CHANGELOG.md#600---2023-09-09-github-pecl) to `Symfony/Component/Cache/Traits/RedisTrait`.

Made changes to how `RedisSentinel` is constructed, which now uses [the same constructor](phpredis/phpredis@ebb2386e) as the main `Redis` class. Didn't find any other changes that might be relevant yet, but it's why I mention Redis Sentinel explicitly.

Commits
-------

9423c71 [Cache] Fix support for Redis Sentinel using php-redis 6.0.0
@igoooor
Copy link

igoooor commented Sep 21, 2023

Any plan for this to come into the 6.3 branch?

@stof
Copy link
Member

stof commented Sep 21, 2023

@igoooor yes. Maintained branches are merged together (generally once a week) to propagate bug fixes to newer branches.

@igoooor
Copy link

igoooor commented Oct 4, 2023

I think the same issue exists for \Symfony\Component\Messenger\Bridge\Redis\Transport\Connection no?

@pimjansen
Copy link

How come that the package has not a fixed dependency on the libs here? Since an upgrade to 7.x could break it again?

@dkarlovi
Copy link
Contributor

dkarlovi commented Nov 7, 2023

@igoooor it does, I'm just looking into why the sentinel mode cannot connect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants