Skip to content

[Cache] Fixed incorrect usage of UNLINK with PHPRedis with Redis < 4.0 #39298

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

Merged
merged 1 commit into from
Dec 8, 2020

Conversation

colinpieper
Copy link

@colinpieper colinpieper commented Dec 3, 2020

Q A
Branch? 5.2
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #39280
License MIT

Currently, deleting cache keys is broken for users using PhpRedis with Redis-server < 4.0.0. The current implementation expects PhpRedis to throw an exception if the 'unlink'-function is used but unavailable, after which it's supposed to switch to using the 'del'-function. Using the 'unlink'-function on lower Redis-server versions seems to not throw an exception, but instead it appears to silently fail.

This pull request changes this behavior and checks the Redis-server version instead. If the version is 4.0 or higher, it uses the unlink function. If not, it uses the del-function.

Also see https://redis.io/commands/unlink > "Available since 4.0.0".

(Footnote: this is one of my first times contributing to an open-source project and my first time contributing to Symfony. I've tried following the guidelines, but please let me know if I missed anything. I'm unsure how I would go about unit testing this specific bugfix due to it being dependent on the Redis version, so I omitted it. Please let me know if a unit test is indeed required for this and if so, let me know if you have any suggestions on how to go about that.)

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 5.x branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@colinpieper colinpieper marked this pull request as draft December 3, 2020 10:28
@derrabus
Copy link
Member

derrabus commented Dec 3, 2020

Thank you very much for working on this issue. Because the 5.2 branch is affected by this bug, please base your PR on the 5.2 branch.

@derrabus derrabus added this to the 5.2 milestone Dec 3, 2020
@colinpieper colinpieper changed the base branch from 5.x to 5.2 December 3, 2020 13:37
Copy link
Member

@jderusse jderusse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the Redis documentation this is available since Redis 4.0 https://redis.io/commands/unlink

I believe the fix should also be applied to Predis. Right?

Looks like the Predis\Command\Redis\UNLINK does not exists. /cc @jonashrem

@colinpieper
Copy link
Author

colinpieper commented Dec 4, 2020

Here's the pull request that introduced these changes: #37993.

The UNLINK command is a pending pull request to Predis (see predis/predis#666) and not yet available, but might be in the future if/when it's approved. There's a check to see if that class exists or it will fall back to the DELETE-command, so there currently aren't any negative side effects in keeping it as far as I can see.

These changes will also need to be applied to the following two files:

  • src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php
  • src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php

I'll implement those corrections soon.

@nicolas-grekas
Copy link
Member

Which version of phpredis are you using?
On my machine, using v5.3.2, I do get an exception.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at @jderusse's comment at #39280 (comment), we should handle the case where the call returns false instead.

@nicolas-grekas
Copy link
Member

Thank you @Wickex.

@nicolas-grekas nicolas-grekas merged commit 5f08c61 into symfony:5.2 Dec 8, 2020
@fabpot fabpot mentioned this pull request Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RedisCache delete/clear not working anymore
6 participants