Skip to content

Commit

Permalink
support flush db on clusters
Browse files Browse the repository at this point in the history
taylorotwell committed May 14, 2019
1 parent f7caed6 commit f4e8d5c
Showing 2 changed files with 35 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Illuminate/Redis/Connections/PhpRedisConnection.php
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@

use Redis;
use Closure;
use RedisCluster;
use Illuminate\Contracts\Redis\Connection as ConnectionContract;

/**
@@ -388,6 +389,22 @@ public function createSubscription($channels, Closure $callback, $method = 'subs
//
}

/**
* Flush the selected Redis database.
*
* @return void
*/
public function flushdb()
{
if (! $this->client instanceof RedisCluster) {
return $this->command('flushdb');
}

foreach ($this->client->_masters() as [$host, $port]) {
tap(new Redis)->connect($host, $port)->flushDb();
}
}

/**
* Execute a raw command.
*
18 changes: 18 additions & 0 deletions src/Illuminate/Redis/Connections/PredisConnection.php
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@
namespace Illuminate\Redis\Connections;

use Closure;
use Predis\Command\ServerFlushDatabase;
use Predis\Connection\Aggregate\PredisCluster;
use Illuminate\Contracts\Redis\Connection as ConnectionContract;

/**
@@ -43,4 +45,20 @@ public function createSubscription($channels, Closure $callback, $method = 'subs

unset($loop);
}

/**
* Flush the selected Redis database.
*
* @return void
*/
public function flushdb()
{
if (! $this->client->getConnection() instanceof PredisCluster) {
return $this->command('flushdb');
}

foreach ($this->getConnection() as $node) {
$node->executeCommand(new ServerFlushDatabase);
}
}
}

0 comments on commit f4e8d5c

Please sign in to comment.