Skip to content

Commit e66fb52

Browse files
Fix flushDb (cache:clear) for redis clusters (#36281)
When running `php artisan cache:clear` with a redis cluster, the flushDb() function is currently unable to run on each master if you are using a password or TLS scheme - #35180 For redis clusters an empty `$config` array is passed through to the constructor of `vendor\laravel\framework\src\Illuminate\Redis\Connections\PhpRedisConnection.php` causing authentication to fail. However, even if you update `vendor\laravel\framework\src\Illuminate\Redis\Connectors\PhpRedisConnector.php` to pass through the cluster password it still fails because `$redis = tap(new Redis)->connect($host, $port);` does not connect to each master node using the correct TLS scheme or any steam context such as `local_cert`, `local_pk`, `cafile` or `verify_peer_name`. This pull request fixes the issue by using `Directed node commands` as described here - https://github.com/phpredis/phpredis/blob/develop/cluster.markdown#directed-node-commands It uses the already authenticated `RedisCluster` connection with correct scheme and context to direct the `flushdb` command to each master node to succesfully clear the cache.
1 parent 4aefa54 commit e66fb52

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/Illuminate/Redis/Connections/PhpRedisConnection.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -501,14 +501,8 @@ public function flushdb()
501501
return $this->command('flushdb');
502502
}
503503

504-
foreach ($this->client->_masters() as [$host, $port]) {
505-
$redis = tap(new Redis)->connect($host, $port);
506-
507-
if (isset($this->config['password']) && ! empty($this->config['password'])) {
508-
$redis->auth($this->config['password']);
509-
}
510-
511-
$redis->flushDb();
504+
foreach ($this->client->_masters() as $master) {
505+
$this->client->flushDb($master);
512506
}
513507
}
514508

0 commit comments

Comments
 (0)