From 62b19dc70226e2174c6b4a865076862225ffe3f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Fri, 21 Jan 2022 08:59:48 -0800 Subject: [PATCH 1/6] move cluster flush logic to related connection --- .../Redis/Connections/PhpRedisClusterConnection.php | 12 +++++++++++- .../Redis/Connections/PhpRedisConnection.php | 9 +-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php b/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php index e246fe6a1d12..4cc62ed1b639 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php @@ -4,5 +4,15 @@ class PhpRedisClusterConnection extends PhpRedisConnection { - // + /** + * Flush the selected Redis database. + * + * @return void + */ + public function flushdb() + { + foreach ($this->client->_masters() as $master) { + $this->client->flushdb($master); + } + } } diff --git a/src/Illuminate/Redis/Connections/PhpRedisConnection.php b/src/Illuminate/Redis/Connections/PhpRedisConnection.php index ca9bd54457cc..34a1dcb76fa4 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisConnection.php @@ -7,7 +7,6 @@ use Illuminate\Support\Arr; use Illuminate\Support\Str; use Redis; -use RedisCluster; use RedisException; /** @@ -499,13 +498,7 @@ public function createSubscription($channels, Closure $callback, $method = 'subs */ public function flushdb() { - if (! $this->client instanceof RedisCluster) { - return $this->command('flushdb'); - } - - foreach ($this->client->_masters() as $master) { - $this->client->flushDb($master); - } + return $this->command('flushdb'); } /** From 652d1781dc86dd637b3410a225639c60fb3b9ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Fri, 21 Jan 2022 09:26:44 -0800 Subject: [PATCH 2/6] support Predis syntax in PhpRedis connection translate Predis syntax to PhpRedis' `true` parameter --- src/Illuminate/Redis/Connections/PhpRedisConnection.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Redis/Connections/PhpRedisConnection.php b/src/Illuminate/Redis/Connections/PhpRedisConnection.php index 34a1dcb76fa4..8303ae0ccc67 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisConnection.php @@ -494,10 +494,15 @@ public function createSubscription($channels, Closure $callback, $method = 'subs /** * Flush the selected Redis database. * + * @param string $modifier * @return void */ - public function flushdb() + public function flushdb($modifier = null) { + if (strtoupper($modifier) === 'ASYNC') { + return $this->command('flushdb', [true]); + } + return $this->command('flushdb'); } From ddd16f68746cf869f5980f1fdc3c84ae29754a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Fri, 21 Jan 2022 09:43:24 -0800 Subject: [PATCH 3/6] fix types --- .../Redis/Connections/PhpRedisClusterConnection.php | 2 +- src/Illuminate/Redis/Connections/PhpRedisConnection.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php b/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php index 4cc62ed1b639..94bbd44c9950 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php @@ -7,7 +7,7 @@ class PhpRedisClusterConnection extends PhpRedisConnection /** * Flush the selected Redis database. * - * @return void + * @return mixed */ public function flushdb() { diff --git a/src/Illuminate/Redis/Connections/PhpRedisConnection.php b/src/Illuminate/Redis/Connections/PhpRedisConnection.php index 8303ae0ccc67..6d884ad5088b 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisConnection.php @@ -494,8 +494,8 @@ public function createSubscription($channels, Closure $callback, $method = 'subs /** * Flush the selected Redis database. * - * @param string $modifier - * @return void + * @param string|null $modifier + * @return mixed */ public function flushdb($modifier = null) { From 54e73135e44866c3c00c52df7fa1ff2f5cd18742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Fri, 21 Jan 2022 09:43:43 -0800 Subject: [PATCH 4/6] support async cluster flushing --- .../Redis/Connections/PhpRedisClusterConnection.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php b/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php index 94bbd44c9950..52885458e66e 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php @@ -7,12 +7,17 @@ class PhpRedisClusterConnection extends PhpRedisConnection /** * Flush the selected Redis database. * + * @param string|null $modifier * @return mixed */ - public function flushdb() + public function flushdb($modifier = null) { + $async = strtoupper($modifier) === 'ASYNC'; + foreach ($this->client->_masters() as $master) { - $this->client->flushdb($master); + $async + ? $this->command('rawCommand', [$master, 'flushdb', 'async']) + : $this->command('flushdb', [$master]); } } } From 1df0fe7523e51fb901d647dc8c2c1a715706b59e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Fri, 21 Jan 2022 10:10:50 -0800 Subject: [PATCH 5/6] avoid null errors --- .../Redis/Connections/PhpRedisClusterConnection.php | 8 ++++---- src/Illuminate/Redis/Connections/PhpRedisConnection.php | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php b/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php index 52885458e66e..5c2669716dca 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php @@ -5,14 +5,14 @@ class PhpRedisClusterConnection extends PhpRedisConnection { /** - * Flush the selected Redis database. + * Flush the selected Redis database on all master nodes. * - * @param string|null $modifier * @return mixed */ - public function flushdb($modifier = null) + public function flushdb() { - $async = strtoupper($modifier) === 'ASYNC'; + $arguments = func_get_args(); + $async = strtoupper((string) $arguments[0] ?? null) === 'ASYNC'; foreach ($this->client->_masters() as $master) { $async diff --git a/src/Illuminate/Redis/Connections/PhpRedisConnection.php b/src/Illuminate/Redis/Connections/PhpRedisConnection.php index 6d884ad5088b..acf586bf6bdc 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisConnection.php @@ -494,12 +494,13 @@ public function createSubscription($channels, Closure $callback, $method = 'subs /** * Flush the selected Redis database. * - * @param string|null $modifier * @return mixed */ - public function flushdb($modifier = null) + public function flushdb() { - if (strtoupper($modifier) === 'ASYNC') { + $arguments = func_get_args(); + + if (strtoupper((string) $arguments[0] ?? null) === 'ASYNC') { return $this->command('flushdb', [true]); } From 44b93c28a998201c5768cae66eabac0cf43eb446 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 22 Jan 2022 12:13:29 -0600 Subject: [PATCH 6/6] Update PhpRedisClusterConnection.php --- src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php b/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php index 5c2669716dca..7a9d2d0abc62 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php @@ -12,6 +12,7 @@ class PhpRedisClusterConnection extends PhpRedisConnection public function flushdb() { $arguments = func_get_args(); + $async = strtoupper((string) $arguments[0] ?? null) === 'ASYNC'; foreach ($this->client->_masters() as $master) {