Skip to content

Commit

Permalink
auth with each master on flushdb
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell authored and driesvints committed Apr 24, 2020
1 parent 82f8ddb commit d0afa58
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/Illuminate/Redis/Connections/PhpRedisConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,25 @@ class PhpRedisConnection extends Connection implements ConnectionContract
*/
protected $connector;

/**
* The connection configuration array.
*
* @var array
*/
protected $config;

/**
* Create a new PhpRedis connection.
*
* @param \Redis $client
* @param callable|null $connector
* @param array $config
* @return void
*/
public function __construct($client, callable $connector = null)
public function __construct($client, callable $connector = null, array $config = [])
{
$this->client = $client;
$this->config = $config;
$this->connector = $connector;
}

Expand Down Expand Up @@ -476,7 +485,13 @@ public function flushdb()
}

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

if (isset($this->config['password']) && ! empty($this->config['password'])) {
$redis->auth($this->config['password']);
}

$redis->flushDb();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Redis/Connectors/PhpRedisConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function connect(array $config, array $options)
));
};

return new PhpRedisConnection($connector(), $connector);
return new PhpRedisConnection($connector(), $connector, $config);
}

/**
Expand Down

0 comments on commit d0afa58

Please sign in to comment.