mirror of
https://github.com/predis/predis.git
synced 2026-09-03 22:36:44 +00:00
Use custom ID when adding connection with no alias.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user