-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Cache::flush does not work with redis clusters #20406
Comments
@alibo, do you have any idea how to solve this? |
@Dadibom @themsaid PhpRedis, unlike Predis, needs a key to execute this command:
https://github.com/phpredis/phpredis/blob/develop/cluster.markdown#directed-node-commands public function testDBSize() {
for ($i = 0; $i < 10; $i++) {
$str_key = "key:$i";
$this->assertTrue($this->redis->flushdb($str_key));
$this->redis->set($str_key, "val:$i");
$this->assertEquals(1, $this->redis->dbsize($str_key));
}
} https://github.com/phpredis/phpredis/blob/master/tests/RedisClusterTest.php#L113 If you connect to one of master nodes and run In addition, if you use
As it doesn't remove the whole data stored in all master nodes and Predis doesn't support it, I think we can throw an exception for Also, another option is listing all master nodes and executing |
@alibo any idea how to list all the masters and run |
For $flushDbCommand = new \Predis\Command\ServerFlushDatabase();
foreach ($this->connection()->getConnection() as $node) {
$node->executeCommand($flushDbCommand);
} more info: predis/predis#354 For foreach ($this->connection()->_masters() as [$host, $port]) {
$redis = new Redis();
$redis->connect($host, $port);
$redis->flushDb();
} more info: https://github.com/phpredis/phpredis/blob/develop/cluster.markdown#directed-node-commands |
@themsaid: I still think that "flushdb" is quite dangerous to clear the cache. Especially since Redis cluster has only one database. If you also use Redis for queues or sessions than "cache:clear" will delete those. I'm not sure what the right solution is. A cache key prefix, cache tags, or something similar. |
that's the intended behaviour of flushdb, there is no difference in the risk between cluster and single node setups. |
Intended behaviour or not, it's bad UX and can lead to data loss. |
Listen mate my point is that you don't know what developers use their caches for. A lot of people use their cache servers as pure caches, in which case a full clear can be done without losing anything important (since it's just cache). And on top of that - this function is in the docs and work with single node redis instances, not having it work on clusters to protect the developers doesn't really make sense |
There's a cache prefix by default, right? How about scanning for all keys that start with the cache prefix and deleting those? |
Any news on that? Any workaround or advice? We use an automated script to deploy and clear the cache, but this issue complicates things quite a lot... Thanks |
This bug doesn't exist anymore. |
Which version has the fix? |
Scan Or Del is a command for a single redis node.If you do want to use it in the cluster, first get nodes list in the cluster, and run a scan or del for each node. Read this article for more info [https://qiita.com/mangano-ito/items/92e8a6b434c4b79b790c] For laravel, to get each connection or node you can use |
I am still having this issue with laravel 8.3 and predis. |
@bernardwiesner: Can you submit a PR to |
Description:
(1/1) ErrorException RedisCluster::flushdb() expects exactly 1 parameter, 0 given
Illuminate\Cache\RedisStore::flush does not accept any parameters and will not pass anything in the call to $this->connection()->flushdb
Steps To Reproduce:
Set cache driver to redis, set it to use a cluster, call \Cache::flush(0 /* or whatever, won't be passed anyway */);
The text was updated successfully, but these errors were encountered: