Skip to content

Commit 1dd6f9d

Browse files
committed
[12.x] flushAll for Redis cluster connections
1 parent 3957f1f commit 1dd6f9d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,24 @@ public function flushdb()
6363
}
6464
}
6565

66+
/**
67+
* Flush the selected Redis database on all master nodes.
68+
*
69+
* @return void
70+
*/
71+
public function flushAll()
72+
{
73+
$arguments = func_get_args();
74+
75+
$async = strtoupper((string) ($arguments[0] ?? null)) === 'ASYNC';
76+
77+
foreach ($this->client->_masters() as $master) {
78+
$async
79+
? $this->command('rawCommand', [$master, 'flushall', 'async'])
80+
: $this->command('flushall', [$master]);
81+
}
82+
}
83+
6684
/**
6785
* Return default node to use for cluster.
6886
*

src/Illuminate/Redis/Connections/PredisClusterConnection.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Redis\Connections;
44

5+
use Predis\Command\Redis\FLUSHALL;
56
use Predis\Command\Redis\FLUSHDB;
67
use Predis\Command\ServerFlushDatabase;
78

@@ -22,4 +23,16 @@ public function flushdb()
2223
$node->executeCommand(tap(new $command)->setArguments(func_get_args()));
2324
}
2425
}
26+
27+
/**
28+
* Flush the selected Redis database on all master nodes.
29+
*
30+
* @return void
31+
*/
32+
public function flushAll()
33+
{
34+
foreach ($this->client as $node) {
35+
$node->executeCommand(tap(new FLUSHALL())->setArguments(func_get_args()));
36+
}
37+
}
2538
}

0 commit comments

Comments
 (0)