lada-cache icon indicating copy to clipboard operation
lada-cache copied to clipboard

lada-cache:flush generates Redis-Cluster error - cannot use "KEYS"

Open madsem opened this issue 8 years ago • 12 comments

Laravel: v5.6.16

Trying to run lada-cache:flush before a new migration (and also trying to run the db:seed command) generates a redis error:

panel.vm $ php artisan lada-cache:flush

   Predis\NotSupportedException  : Cannot use 'KEYS' with redis-cluster.

This is my database.php config:

'redis' => [

        'client' => 'predis',

        'options' => [
            'cluster' => 'redis',
        ],

        'clusters' => [
            'default' => [
                'host' => env('REDIS_HOST', 'localhost'),
                'password' => env('REDIS_PASSWORD', null),
                'port' => env('REDIS_PORT', 6379),
                'database' => 0,
            ],
        ],

    ],

madsem avatar Apr 19 '18 13:04 madsem

Didn't test the flush command so far with a cluster, to be honest. Predis does currently not support several commands for cluster environments, will need to develop a workaround for this.

Are you actually using a cluster?

spiritix avatar Apr 19 '18 13:04 spiritix

yeah using a cluster in production on AWS Elasticache. A workaround is to change the config locally to default when running a migration, but that just introduces problems because I can't be sure if it will work the same way in production I guess.

madsem avatar Apr 19 '18 14:04 madsem

Well, what you always can do is flushing the entire Redis DB on production instead of just Lada Cache. That will certainly work if your application doesn't depend on any data in Redis being persistent.

spiritix avatar Apr 19 '18 14:04 spiritix

Ok true, or I switch to cluster mode disabled. Luckily I am flexible there. Laravel itself also has issues with Cache::tags() & cluster mode enabled.

madsem avatar Apr 19 '18 14:04 madsem

This is the fix suggested by someone in the Laravel repo for using flush with cache tags, it might also solve this issue here as I saw Lada cache also isn't using curly braces: https://github.com/laravel/framework/pull/17792/files

https://github.com/laravel/framework/pull/17792#issuecomment-277977633

madsem avatar Apr 21 '18 06:04 madsem

I am not sure if that's going to work, according to the author of Predis one would need to iterate over all connections: https://github.com/nrk/predis/issues/338#issuecomment-222321432

It appears a bit strange to me why this should be required since for all other commands iterating is not required, but ok, either this or your proposed solution should work for sure.

spiritix avatar Apr 23 '18 07:04 spiritix

Can't say anything about the connection looping, I tested the curly brace solution with Laravel 5.6 and there it seemed to fix the issue indeed, after implementation the errors about 'Cannot use 'DEL' with redis-cluster.' in combination with Cache::tags() were gone.

madsem avatar Apr 23 '18 07:04 madsem

@spiritix What's the state of this issue currently?

xwiz avatar May 27 '20 20:05 xwiz

@xwiz I currently only have capacity to fix major bugs in my open source projects. Contributions are very welcome.

spiritix avatar May 28 '20 15:05 spiritix

Thanks @spiritix

Looks like that will happens as I'm running into some issues. Good to know you're open to contributions.

xwiz avatar May 28 '20 15:05 xwiz

I think for contributors it would be great to have documented the current conditions that trigger the flush cache automatically. By default I assume that would be created, updated, and deleted but one needs to delve into the code to confirm.

xwiz avatar May 28 '20 15:05 xwiz

So the flush command is never triggered automatically. It's only for debug and maintenance purposes, that's why I am not scheduling this with high priority at the moment. The invalidation of the cached items is not related to flushing the cache, you may have a look at the Wiki to see how this works (https://github.com/spiritix/lada-cache/wiki).

spiritix avatar Jun 02 '20 09:06 spiritix