Framework: Can't flush tags on Redis cluster cache in Laravel 5.1.30 and later

Created on 1 Feb 2017  路  34Comments  路  Source: laravel/framework

  • 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).

1) Set Redis in cluster mode by putting 'cluster' => true in your Redis config in config/database.php. For example:

'redis' => [
    'cluster' => true,
    'default' => [
        'host' => '127.0.0.1',
        'port' => 6379,
        'database' => 0
    ]
]

2) 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 );

3) 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.'

bug help wanted

Most helpful comment

Any updates on this issue?
if not, then I'm ready to work on it.

All 34 comments

Update: the issue was introduced with the 5.1.30 release of laravel/framework.

You are seeing a Predis exception. I'm not sure there is much we can do about it? Perhaps asks on their repository?

Same thing with 'cluster' => false in 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.

This issue should be tagged for any version of Laravel because of wrong definition of tags into Illuminate\Cache\RedisTaggedCache.

Refer to this https://github.com/laravel/framework/pull/17792#issuecomment-277977633 for more informations, and this about what could be changed: https://github.com/laravel/framework/pull/17792/files.

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.

Is this moving forward?

Still no fix or workaround for this bug?

So it seems like this bug is the same as the one I posted (#22788). Does anybody could take a look? @taylorotwell @themsaid

I'd suggest to submit a PR for v5.6.

Will do that once I have some time. I'm not really familiar with the code base.

Had the issue too. Have the same app on a redis 3.2.8 don't reproduce the error.

Any update on this?

Getting similar error wthile trying to flush a tag. Also using Redis Clusters.

@mattmant I wonder how this still isn't merged :(
Is there any alternative right now to be able to do Cache::tags('something')->flush() with Redis Cluster enabled?

I'm on 5.6 btw and have the same issue.

I wonder how this still isn't merged :(

This is not a pull request. There's nothing to merge?

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.

We're open to pull requests to fix this.

That's what I meant, there was one a year ago for 5.1 https://github.com/laravel/framework/pull/17792/files

;)

Taylor mentioned on that pull request, that something similar may be considered for master. Maybe someone just needs to PR it?

Yeah, just send a PR to v5.7.

I haven't found a solution but maybe a way around it for some cases. In my case I was tagging single posts with this tag: Cache::tags(["post_$postId"])and I had a problem when I was trying to clear the cache for a user鈥檚 posts like so

foreach($user->posts() as $post) {
Cache::tags(["post_$post->id"])->flush();
}

Somehow the bug didn't occurred all the time. Within some methods the foreach worked properly. Only in one method it failed.

I found a solution by adding this tag "post_user_$post->user->id"
So now I have two tags:

Cache::tags(["post_user_$post->user->id", "post_excerpt_$postId"])

and I can clear the cache for those posts with:
Cache::tags(["post_user_$user->id"])->flush();

Any update on this? Running into the same issue.

Can anyone confirm this is occuring on Laravel 5.7 (or 5.5)? Would be good to know if any of the recent updates fixed this?

same error :-(

Same problem, anyone any idea?? @taylorotwell

So, how to use tags with this bug? any way around it?

So, how to use tags with this bug? any way around it?

use phpredis instead of predis if you want to go around it

Any updates on this issue?
if not, then I'm ready to work on it.

This is still an issue with Memcached..

@Jafo232 we're welcoming prs to help solve this.

It's still an issue because nobody has fixed it. Simple as that. 馃槃 Anyone can fix it by making a PR to the framework.

I have confirmed this is working on a Redis cluster I provisioned on ScaleGrid.io and using the phpredis PHP extension (default Redis driver for Laravel now). If it is not working on Predis I'm not sure what to do about that. Predis is no longer maintained as a library.

I have the issue with memcached too.

edit : so I switched to redis (using php-redis) and it works fine... Maybe memcached should not be authorized to use tags, as it is the case for file or database.

I have confirmed this is working on a Redis cluster I provisioned on ScaleGrid.io and using the phpredis PHP extension (default Redis driver for Laravel now). If it is not working on Predis I'm not sure what to do about that. Predis is no longer maintained as a library.

@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:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

klimentLambevski picture klimentLambevski  路  3Comments

progmars picture progmars  路  3Comments

SachinAgarwal1337 picture SachinAgarwal1337  路  3Comments

JamborJan picture JamborJan  路  3Comments