Skip to content

Commit 47704e7

Browse files
[8.x] Improve PhpRedis flushing (#40544)
* move cluster flush logic to related connection * support Predis syntax in PhpRedis connection translate Predis syntax to PhpRedis' `true` parameter * fix types * support async cluster flushing * avoid null errors * Update PhpRedisClusterConnection.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent da0df24 commit 47704e7

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,21 @@
44

55
class PhpRedisClusterConnection extends PhpRedisConnection
66
{
7-
//
7+
/**
8+
* Flush the selected Redis database on all master nodes.
9+
*
10+
* @return mixed
11+
*/
12+
public function flushdb()
13+
{
14+
$arguments = func_get_args();
15+
16+
$async = strtoupper((string) $arguments[0] ?? null) === 'ASYNC';
17+
18+
foreach ($this->client->_masters() as $master) {
19+
$async
20+
? $this->command('rawCommand', [$master, 'flushdb', 'async'])
21+
: $this->command('flushdb', [$master]);
22+
}
23+
}
824
}

src/Illuminate/Redis/Connections/PhpRedisConnection.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Illuminate\Support\Arr;
88
use Illuminate\Support\Str;
99
use Redis;
10-
use RedisCluster;
1110
use RedisException;
1211

1312
/**
@@ -495,17 +494,17 @@ public function createSubscription($channels, Closure $callback, $method = 'subs
495494
/**
496495
* Flush the selected Redis database.
497496
*
498-
* @return void
497+
* @return mixed
499498
*/
500499
public function flushdb()
501500
{
502-
if (! $this->client instanceof RedisCluster) {
503-
return $this->command('flushdb');
504-
}
501+
$arguments = func_get_args();
505502

506-
foreach ($this->client->_masters() as $master) {
507-
$this->client->flushDb($master);
503+
if (strtoupper((string) $arguments[0] ?? null) === 'ASYNC') {
504+
return $this->command('flushdb', [true]);
508505
}
506+
507+
return $this->command('flushdb');
509508
}
510509

511510
/**

0 commit comments

Comments
 (0)