framework: Can't flush tags on Redis cluster cache in Laravel 5.1.30 and later
- Laravel Version: 5.1.45
- PHP Version: 5.5.9
- Redis Version: 3.2.6
Description:
I updated Laravel from version 5.1.20 to version 5.1.45. I’m using cache Redis with tags to store some informations. The application is running on 3 web-servers and Redis is in cluster mode.
After the update I can’t flush tags saved in Redis because I get the following error:
NotSupportedException in RedisCluster.php line 380:
Cannot use 'DEL' with redis-cluster.
The important thing is that before updating Laravel the application was stable and was working well.
I saw that there was many important changes into Illuminate\Cache\RedisTaggedCache
with the introduction of $this->deleteStandardKeys();
into the flush()
method.
Steps To Reproduce:
You can test the behavior in your local machine with a single Redis node (the same happens if you have a real Redis cluster also).
- Set Redis in cluster mode by putting
'cluster' => true
in your Redis config inconfig/database.php
. For example:
'redis' => [
'cluster' => true,
'default' => [
'host' => '127.0.0.1',
'port' => 6379,
'database' => 0
]
]
- Store at least two keys for the same tag:
Cache::store( "redis" )->tags( "tag" )->put( "key1", "test", 100 );
Cache::store( "redis" )->tags( "tag" )->put( "key2", "test", 100 );
- Now try to flush the tag:
Cache::store( "redis" )->tags( "tag" )->flush();
You will get the following red message:
Predis\NotSupportedException with message 'Cannot use 'DEL' with redis-cluster.'
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 7
- Comments: 34 (8 by maintainers)
Any updates on this issue? if not, then I’m ready to work on it.
Same problem, anyone any idea?? @taylorotwell
That’s what I meant, there was one a year ago for 5.1 https://github.com/laravel/framework/pull/17792/files
😉
use phpredis instead of predis if you want to go around it
Okay sorry for not using 100% accurate verbiage @GrahamCampbell , but in the end this still doesn’t work in 5.6 and cannot flush tagged cache with redis cluster.
It’s still an issue because nobody has fixed it. Simple as that. 😄 Anyone can fix it by making a PR to the framework.
So, how to use tags with this bug? any way around it?
@taylorotwell As I have suggested three years ago, I’m still using the following solution, without any side effects on performance/data: https://github.com/laravel/framework/pull/17792/files
It is not a BC as you said here https://github.com/laravel/framework/pull/17792#issuecomment-278015728. It is a simply way to tell to predis how to manage associative keys. Redis keys and the way they are defined/stored will not be changed.
For more information:
This is still an issue with Memcached…
We’re open to pull requests to fix this.
Your updated #17792 PR that uses hash tags looks good to me. If it doesn’t get merged into 5.1, I’d at least submit it for 5.4.
@taylorotwell yes, it is a Predis exception and it would be a good idea to ask in their repository, after have reproduced the behaviour directly on it.
But, updating Laravel from 5.1.20 to 5.1.45 didn’t affect Predis package version: it still remains v1.1.1. It seems that after changes on
Illuminate\Cache\RedisTaggedCache
it doesn’t properly support redis cluster… because my application was stable and was working well before these changes.