From 6b5f3713553f7b7a4e15c3fb7bf156c642a8156a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Sun, 23 Jan 2022 14:52:53 -0800 Subject: [PATCH] Avoid `undefined array key 0` error --- .../Connections/PhpRedisClusterConnection.php | 2 +- .../Redis/Connections/PhpRedisConnection.php | 2 +- tests/Redis/RedisConnectionTest.php | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php b/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php index 7a9d2d0abc62..bf4816a4306e 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php @@ -13,7 +13,7 @@ public function flushdb() { $arguments = func_get_args(); - $async = strtoupper((string) $arguments[0] ?? null) === 'ASYNC'; + $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 acf586bf6bdc..4e68547de3d0 100644 --- a/src/Illuminate/Redis/Connections/PhpRedisConnection.php +++ b/src/Illuminate/Redis/Connections/PhpRedisConnection.php @@ -500,7 +500,7 @@ public function flushdb() { $arguments = func_get_args(); - if (strtoupper((string) $arguments[0] ?? null) === 'ASYNC') { + if (strtoupper((string) ($arguments[0] ?? null)) === 'ASYNC') { return $this->command('flushdb', [true]); } diff --git a/tests/Redis/RedisConnectionTest.php b/tests/Redis/RedisConnectionTest.php index ea0667d8efe0..a89ebd2d4fc4 100644 --- a/tests/Redis/RedisConnectionTest.php +++ b/tests/Redis/RedisConnectionTest.php @@ -467,6 +467,28 @@ public function testItGetsMultipleKeys() } } + public function testItFlushes() + { + foreach ($this->connections() as $redis) { + $redis->set('name', 'Till'); + $this->assertSame(1, $redis->exists('name')); + + $redis->flushdb(); + $this->assertSame(0, $redis->exists('name')); + } + } + + public function testItFlushesAsynchronous() + { + foreach ($this->connections() as $redis) { + $redis->set('name', 'Till'); + $this->assertSame(1, $redis->exists('name')); + + $redis->flushdb('ASYNC'); + $this->assertSame(0, $redis->exists('name')); + } + } + public function testItRunsEval() { foreach ($this->connections() as $redis) {