-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[8.x] Fix possible out of memory error when deleting values by reference key from cache in Redis driver #39939
[8.x] Fix possible out of memory error when deleting values by reference key from cache in Redis driver #39939
Conversation
…nce key from cache in Redis driver
fa0e50b
to
fa883b1
Compare
I'm having a similar issue with the I read that it is possible to delete all keys within a set using the
Would it not be a better idea to let the |
@dkuzmenchuk any thoughts on @gdebrauwer's comment? |
Marking this as draft for now pending feedback on comments above. Please mark as ready for review again when you're ready for me to look at it. |
Hi there, There is a method which used to delete cached values
If I understood @gdebrauwer comment correct, he suggests to simply remove Please let me know if you have any comments. |
I think we can do the following: protected function deleteValues($referenceKey)
{
$this->store->connection()->del($referenceKey);
} If I understand it correctly, Apparently you can also do this in one command, by providing the set name to the |
Method As you can see values referenced by |
Of course, sorry, I was completely wrong 🤦♂️ Thanks for the explanation 🙂 |
Thanks for contributing to Laravel! ❤️ |
…nce key from cache in Redis driver (laravel#39939) * [8.x] Fix possible out of memory error when deleting values by reference key from cache in Redis driver * formatting Co-authored-by: Denis Kuzmenchuk <denis@alphaflightguru.com> Co-authored-by: Taylor Otwell <taylor@laravel.com>
@dkuzmenchuk - What mock tool are you using for testing Redis? The m6web/redis-mock does not implement sscan. |
@robertmarney As I see, Laravel does not use any Redis-specific mock tool for testing Redis. If you check a test case, you'll see that redis connection is just a mock on stdClass.
I used the same way to write test for my feature. |
I think we should add test to cover this case #40149 after fixing |
Hi there,
This PR solves possible out of memory issue when deleting values by reference key from cache in Redis driver.
Example:
$values = array_unique($this->store->connection()->smembers($referenceKey));
Issue:
If there are too many values referenced by key, we get out of memory error. In this case deleting values using chunks does not make sense because memory overflows earlier.
Solution:
I suggest to use
sscan
to retrieve values from Redis by chunks using cursor. Then remove all unique values in chunk and get new chunk. Repeat before all values have been processed.