Skip to content

Support predis 2.* on cache RedisAdapter #49238

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
acelaya opened this issue Feb 4, 2023 · 10 comments
Closed

Support predis 2.* on cache RedisAdapter #49238

acelaya opened this issue Feb 4, 2023 · 10 comments
Labels
Cache Feature Help wanted Issues and PRs which are looking for volunteers to complete them. Keep open

Comments

@acelaya
Copy link

acelaya commented Feb 4, 2023

Description

I was investigating an issue reported to a project where I use predis 2 together with symfony/cache. It was pretty hard to debug as it involved redis sentinels, which is complex to set-up.

After a lot of debugging I have found that the root cause was already reported and supposedly solved some years ago. However, it seemed to be back.

After checking the RedisTrait, I have realized the problem is that all the conditions implemented there are valid for predis 1, but some namespaces have changed in predis 2, which makes those conditions never properly trigger.

I think it shouldn't be super hard to support both versions. If there's a desire to support predis 2, I can try to give it a try and see how it goes.

Example

No response

@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@stloyd
Copy link
Contributor

stloyd commented Aug 5, 2023

Still would be useful, don't stale.

@carsonbot carsonbot removed the Stalled label Aug 5, 2023
@acelaya
Copy link
Author

acelaya commented Aug 5, 2023

Just to update on this. I started to implement something to support predis 1 and 2, but it became challenging to test.

The project depends on pedis 1, and apart from making it require 1 || 2, it would require some dancing on composer install to make it install the right version for every particular test.

After some time it was hard to find the motivation to continue, as I had a working workaround for my use case.

But yeah, ideally this should happen, because predis 1 is no longer maintained AFAIK.

Perhaps aiming to support only predis 2 once Symfony 7 releases would simplify things here.

pieterreynders added a commit to flexmail/predis that referenced this issue Nov 29, 2023
This is to solve an issue in the Symfony RedisAdapter.
See related issue: symfony/symfony#49238
pieterreynders added a commit to flexmail/predis that referenced this issue Nov 29, 2023
This is to solve an issue in the Symfony RedisAdapter.
See related issue: symfony/symfony#49238
@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@acelaya
Copy link
Author

acelaya commented Feb 8, 2024

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

I definitely would 😅

@carsonbot carsonbot removed the Stalled label Feb 8, 2024
@nicolas-grekas
Copy link
Member

PR welcome of course. It'd be great to figure out a way to make the adapter work with both versions of Predis.

@nicolas-grekas nicolas-grekas added Help wanted Issues and PRs which are looking for volunteers to complete them. Keep open labels Feb 8, 2024
@acelaya
Copy link
Author

acelaya commented Feb 8, 2024

PR welcome of course. It'd be great to figure out a way to make the adapter work with both versions of Predis.

Is there any other scenario where Symfony supports multiple major versions of the same dependency, that I could take a look at? As I mentioned a few months ago, the main challenge is to make sure tests are run with the appropriate predis version.

Also, it seems predis v3.0.0 is around the corner, just to make things more interesting 😅

predis 1 seems to still be the most installed version https://packagist.org/packages/predis/predis/stats#major/all, although v2 is slowly catching up.

@nicolas-grekas
Copy link
Member

We run tests with the lastet and with the lowest supported versions of deps automatically so there is nothing to do to have them installed. Then, test cases would need to be written in a way that can selectively run with v1 or v2 depending on what is installed. (let's see v3 as another future step)

@Justinas-Jurciukonis
Copy link

Justinas-Jurciukonis commented Jun 3, 2024

Hello @nicolas-grekas,

to support v1 and v2 following code adjustments can be made:

use Predis\Connection\Aggregate\ReplicationInterface as ReplicationInterfaceV1;
use Predis\Connection\Replication\ReplicationInterface as ReplicationInterfaceV2;

[...]

        if ($host instanceof \Predis\Client) {
            $connection = $host->getConnection();

            if ($connection instanceof ReplicationInterfaceV1) {
                $hosts = [$host->getClientFor('master')];
            } elseif ($connection instanceof ReplicationInterfaceV2) {
                $connection->switchToMaster();

                $hosts = [$host];
            }
        }

@DemigodCode
Copy link
Contributor

I've tried to fix this and write some tests.
Can someone look over the connection strings?

Thank you!

#59751

nicolas-grekas added a commit that referenced this issue Feb 11, 2025
This PR was submitted for the 7.2 branch but it was squashed and merged into the 6.4 branch instead.

Discussion
----------

[Cache] Tests for Redis Replication with cache

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #49238
| License       | MIT

Adding Replication of Redis to test config and fix bug

Commits
-------

159e6b9 [Cache] Tests for Redis Replication with cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cache Feature Help wanted Issues and PRs which are looking for volunteers to complete them. Keep open
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants