Use custom ID when adding connection with no alias.

This commit is contained in:
Daniele Alessandri
2016-05-16 17:28:13 +02:00
parent a933a13087
commit 89a1e236ce
2 changed files with 17 additions and 1 deletions
@@ -71,7 +71,7 @@ class MasterSlaveReplication implements ReplicationInterface
if ($alias === 'master') {
$this->master = $connection;
} else {
$this->slaves[$alias ?: count($this->slaves)] = $connection;
$this->slaves[$alias ?: "slave-$connection"] = $connection;
}
$this->reset();
@@ -63,6 +63,22 @@ class MasterSlaveReplicationTest extends PredisTestCase
$this->assertSame(array(), $replication->getSlaves());
}
/**
* @group disconnected
*/
public function testAddingConnectionsToReplicationWithoutAliasesResultsInCustomId()
{
$slave1 = $this->getMockConnection('tcp://host1');
$slave2 = $this->getMockConnection('tcp://host2:6380');
$replication = new MasterSlaveReplication();
$replication->add($slave1);
$replication->add($slave2);
$this->assertSame($slave1, $replication->getConnectionById('slave-host1:6379'));
$this->assertSame($slave2, $replication->getConnectionById('slave-host2:6380'));
}
/**
* @group disconnected
* @expectedException \Predis\ClientException