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

removeById() public method

Removes a connection instance using its alias or index.
public removeById ( string $connectionID ) : boolean
$connectionID string Alias or index of a connection.
return boolean Returns true if the connection was in the pool.
    public function removeById($connectionID)
    {
        if ($connection = $this->getConnectionById($connectionID)) {
            return $this->remove($connection);
        }
        return false;
    }

Usage Example

 /**
  * @group disconnected
  */
 public function testRemovingConnectionsFromClusterByAlias()
 {
     $connection1 = $this->getMockConnection();
     $connection2 = $this->getMockConnection('tcp://host1:7001?alias=node2');
     $connection3 = $this->getMockConnection('tcp://host1:7002?alias=node3');
     $cluster = new PredisCluster();
     $cluster->add($connection1);
     $cluster->add($connection2);
     $cluster->add($connection3);
     $this->assertTrue($cluster->removeById(0));
     $this->assertTrue($cluster->removeById('node2'));
     $this->assertFalse($cluster->removeById('node4'));
     $this->assertSame(1, count($cluster));
 }