Predis\Connection\Aggregate\PredisCluster::add PHP Method

add() public method

public add ( Predis\Connection\NodeConnectionInterface $connection )
$connection Predis\Connection\NodeConnectionInterface
    public function add(NodeConnectionInterface $connection)
    {
        $parameters = $connection->getParameters();
        if (isset($parameters->alias)) {
            $this->pool[$parameters->alias] = $connection;
        } else {
            $this->pool[] = $connection;
        }
        $weight = isset($parameters->weight) ? $parameters->weight : null;
        $this->distributor->add($connection, $weight);
    }

Usage Example

コード例 #1
0
 /**
  * @group disconnected
  */
 public function testCanBeSerialized()
 {
     $connection1 = $this->getMockConnection('tcp://host1?alias=first');
     $connection2 = $this->getMockConnection('tcp://host2?alias=second');
     $cluster = new PredisCluster();
     $cluster->add($connection1);
     $cluster->add($connection2);
     // We use the following line to initialize the underlying hashring.
     $cluster->getConnectionByKey('foo');
     $unserialized = unserialize(serialize($cluster));
     $this->assertEquals($cluster, $unserialized);
 }