mirror of
https://github.com/predis/predis.git
synced 2026-08-19 19:31:46 +00:00
Added possibility to use custom connection cluster classes in Predis\Client constructor.
Added three methods (used by \Predis\Client) to IConnectionSingle interface.
This commit is contained in:
@@ -93,6 +93,9 @@ class Client {
|
||||
}
|
||||
$this->setConnection($cluster);
|
||||
}
|
||||
else if ($parameters instanceof IConnectionCluster) {
|
||||
$this->setConnection($parameters);
|
||||
}
|
||||
else {
|
||||
$this->setConnection($this->createConnection($parameters));
|
||||
}
|
||||
@@ -1206,6 +1209,9 @@ interface IConnectionSingle extends IConnection {
|
||||
public function writeBytes($buffer);
|
||||
public function readBytes($length);
|
||||
public function readLine();
|
||||
public function getParameters();
|
||||
public function pushInitCommand(ICommand $command);
|
||||
public function __toString();
|
||||
}
|
||||
|
||||
interface IConnectionCluster extends IConnection {
|
||||
|
||||
@@ -408,18 +408,33 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
|
||||
$params3 = new \Predis\ConnectionParameters($params1);
|
||||
$params4 = new \Predis\TcpConnection($params3);
|
||||
|
||||
$client = new \Predis\Client(array($params1, $params2, $params3, $params4));
|
||||
foreach ($client->getConnection() as $connection) {
|
||||
$parameters = $connection->getParameters();
|
||||
$this->assertEquals($params1['host'], $parameters->host);
|
||||
$this->assertEquals($params1['port'], $parameters->port);
|
||||
$this->assertEquals($params1['connection_timeout'], $parameters->connection_timeout);
|
||||
$this->assertEquals($params1['read_write_timeout'], $parameters->read_write_timeout);
|
||||
$this->assertNull($parameters->password);
|
||||
$connectionCluster1 = array($params1, $params2, $params3, $params4);
|
||||
$connectionCluster2 = array($params4);
|
||||
$connectionCluster3 = new \Predis\ConnectionCluster();
|
||||
$connectionCluster3->add($params4);
|
||||
|
||||
foreach (array($connectionCluster1, $connectionCluster2, $connectionCluster3) as $connectionCluster) {
|
||||
$client = new \Predis\Client($connectionCluster);
|
||||
|
||||
foreach ($client->getConnection() as $connection) {
|
||||
$parameters = $connection->getParameters();
|
||||
$this->assertEquals($params1['host'], $parameters->host);
|
||||
$this->assertEquals($params1['port'], $parameters->port);
|
||||
$this->assertEquals($params1['connection_timeout'], $parameters->connection_timeout);
|
||||
$this->assertEquals($params1['read_write_timeout'], $parameters->read_write_timeout);
|
||||
$this->assertNull($parameters->password);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (array($connectionCluster2, $connectionCluster3) as $connectionCluster) {
|
||||
$client = new \Predis\Client($connectionCluster);
|
||||
|
||||
foreach ($client->getConnection() as $connection) {
|
||||
$this->assertSame($params4, $connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Client + CommandPipeline */
|
||||
|
||||
function testCommandPipeline_Simple() {
|
||||
|
||||
Reference in New Issue
Block a user