mirror of
https://github.com/predis/predis.git
synced 2026-08-25 07:29:40 +00:00
Apply common parameters to connections created on the fly in cluster.
These parameters are applied only to connections being created on the fly when not part of the current pool. This condition usually happens upon -MOVE or -ASK responses returned by Redis to redirect client to different nodes.
This commit is contained in:
@@ -47,6 +47,7 @@ use Predis\Response;
|
||||
class RedisCluster implements ClusterConnectionInterface, IteratorAggregate, Countable
|
||||
{
|
||||
private $askClusterNodes = false;
|
||||
private $defaultParameters = array();
|
||||
private $pool = array();
|
||||
private $slots = array();
|
||||
private $slotsMap;
|
||||
@@ -298,11 +299,12 @@ class RedisCluster implements ClusterConnectionInterface, IteratorAggregate, Cou
|
||||
|
||||
if (!$connection = $this->getConnectionById($connectionID)) {
|
||||
$host = explode(':', $connectionID, 2);
|
||||
$connection = $this->connections->create(array(
|
||||
$parameters = array_merge($this->defaultParameters, array(
|
||||
'host' => $host[0],
|
||||
'port' => $host[1],
|
||||
));
|
||||
|
||||
$connection = $this->connections->create($parameters);
|
||||
$this->pool[$connectionID] = $connection;
|
||||
}
|
||||
|
||||
@@ -381,11 +383,12 @@ class RedisCluster implements ClusterConnectionInterface, IteratorAggregate, Cou
|
||||
|
||||
if (!$connection) {
|
||||
$host = explode(':', $host, 2);
|
||||
|
||||
$connection = $this->connections->create(array(
|
||||
$parameters = array_merge($this->defaultParameters, array(
|
||||
'host' => $host[0],
|
||||
'port' => $host[1],
|
||||
));
|
||||
|
||||
$connection = $this->connections->create($parameters);
|
||||
}
|
||||
|
||||
switch ($request) {
|
||||
@@ -484,4 +487,22 @@ class RedisCluster implements ClusterConnectionInterface, IteratorAggregate, Cou
|
||||
{
|
||||
$this->askClusterNodes = (bool) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a default array of connection parameters to be applied when creating
|
||||
* new connection instances on the fly when they are not part of the initial
|
||||
* pool supplied upon cluster initialization.
|
||||
*
|
||||
* These parameters are not applied to connections added to the pool using
|
||||
* the add() method.
|
||||
*
|
||||
* @param array $parameters Array of connection parameters.
|
||||
*/
|
||||
public function setDefaultParameters(array $parameters)
|
||||
{
|
||||
$this->defaultParameters = array_merge(
|
||||
$this->defaultParameters,
|
||||
$parameters ?: array()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user