Skip to content
Permalink
Browse files

support flush db on clusters

  • Loading branch information...
taylorotwell committed May 14, 2019
1 parent f7caed6 commit f4e8d5c1f1b72e24baac33c336233cca24230783
@@ -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.
*
@@ -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.
You can’t perform that action at this time.