浏览代码

Rename to getConnectionByCommand($command).

Daniele Alessandri 9 年之前
父节点
当前提交
9d8adee1b1

+ 3 - 0
CHANGELOG.md

@@ -48,6 +48,9 @@ v2.0.0 (201x-xx-xx)
   namespaces for cluster backends (`Predis\Connection\Cluster`) and replication
   backends (`Predis\Connection\Replication`).
 
+- The method `Predis\Connection\AggregateConnectionInterface::getConnection()`
+  has been renamed to `getConnectionByCommand()`.
+
 - The methods `switchToMaster()` and `switchToSlave()` have been promoted to be
   part of `Predis\Connection\Replication\ReplicationInterface` while the method
   `switchTo($connection)` has been removed from it.

+ 1 - 1
src/Connection/AggregateConnectionInterface.php

@@ -44,7 +44,7 @@ interface AggregateConnectionInterface extends ConnectionInterface
      *
      * @return NodeConnectionInterface
      */
-    public function getConnection(CommandInterface $command);
+    public function getConnectionByCommand(CommandInterface $command);
 
     /**
      * Returns a connection instance from the aggregate connection by its alias.

+ 4 - 4
src/Connection/Cluster/PredisCluster.php

@@ -126,7 +126,7 @@ class PredisCluster implements ClusterInterface, \IteratorAggregate, \Countable
     /**
      * {@inheritdoc}
      */
-    public function getConnection(CommandInterface $command)
+    public function getConnectionByCommand(CommandInterface $command)
     {
         $slot = $this->strategy->getSlot($command);
 
@@ -196,7 +196,7 @@ class PredisCluster implements ClusterInterface, \IteratorAggregate, \Countable
      */
     public function writeRequest(CommandInterface $command)
     {
-        $this->getConnection($command)->writeRequest($command);
+        $this->getConnectionByCommand($command)->writeRequest($command);
     }
 
     /**
@@ -204,7 +204,7 @@ class PredisCluster implements ClusterInterface, \IteratorAggregate, \Countable
      */
     public function readResponse(CommandInterface $command)
     {
-        return $this->getConnection($command)->readResponse($command);
+        return $this->getConnectionByCommand($command)->readResponse($command);
     }
 
     /**
@@ -212,6 +212,6 @@ class PredisCluster implements ClusterInterface, \IteratorAggregate, \Countable
      */
     public function executeCommand(CommandInterface $command)
     {
-        return $this->getConnection($command)->executeCommand($command);
+        return $this->getConnectionByCommand($command)->executeCommand($command);
     }
 }

+ 2 - 2
src/Connection/Cluster/RedisCluster.php

@@ -372,7 +372,7 @@ class RedisCluster implements ClusterInterface, \IteratorAggregate, \Countable
     /**
      * {@inheritdoc}
      */
-    public function getConnection(CommandInterface $command)
+    public function getConnectionByCommand(CommandInterface $command)
     {
         $slot = $this->strategy->getSlot($command);
 
@@ -547,7 +547,7 @@ class RedisCluster implements ClusterInterface, \IteratorAggregate, \Countable
 
         RETRY_COMMAND: {
             try {
-                $response = $this->getConnection($command)->$method($command);
+                $response = $this->getConnectionByCommand($command)->$method($command);
             } catch (ConnectionException $exception) {
                 $connection = $exception->getConnection();
                 $connection->disconnect();

+ 2 - 2
src/Connection/Replication/MasterSlaveReplication.php

@@ -141,7 +141,7 @@ class MasterSlaveReplication implements ReplicationInterface
     /**
      * {@inheritdoc}
      */
-    public function getConnection(CommandInterface $command)
+    public function getConnectionByCommand(CommandInterface $command)
     {
         if (!$this->current) {
             if ($this->strategy->isReadOperation($command) && $slave = $this->pickSlave()) {
@@ -435,7 +435,7 @@ class MasterSlaveReplication implements ReplicationInterface
     {
         RETRY_COMMAND: {
             try {
-                $connection = $this->getConnection($command);
+                $connection = $this->getConnectionByCommand($command);
                 $response = $connection->$method($command);
 
                 if ($response instanceof ResponseErrorInterface && $response->getErrorType() === 'LOADING') {

+ 2 - 2
src/Connection/Replication/SentinelReplication.php

@@ -531,7 +531,7 @@ class SentinelReplication implements ReplicationInterface
     /**
      * {@inheritdoc}
      */
-    public function getConnection(CommandInterface $command)
+    public function getConnectionByCommand(CommandInterface $command)
     {
         $connection = $this->getConnectionInternal($command);
 
@@ -655,7 +655,7 @@ class SentinelReplication implements ReplicationInterface
 
         SENTINEL_RETRY: {
             try {
-                $response = $this->getConnection($command)->$method($command);
+                $response = $this->getConnectionByCommand($command)->$method($command);
             } catch (CommunicationException $exception) {
                 $this->wipeServerList();
                 $exception->getConnection()->disconnect();

+ 2 - 2
src/Pipeline/ConnectionErrorProof.php

@@ -93,7 +93,7 @@ class ConnectionErrorProof extends Pipeline
         $exceptions = array();
 
         foreach ($commands as $command) {
-            $cmdConnection = $connection->getConnection($command);
+            $cmdConnection = $connection->getConnectionByCommand($command);
 
             if (isset($exceptions[spl_object_hash($cmdConnection)])) {
                 continue;
@@ -109,7 +109,7 @@ class ConnectionErrorProof extends Pipeline
         for ($i = 0; $i < $sizeOfPipe; ++$i) {
             $command = $commands->dequeue();
 
-            $cmdConnection = $connection->getConnection($command);
+            $cmdConnection = $connection->getConnectionByCommand($command);
             $connectionHash = spl_object_hash($cmdConnection);
 
             if (isset($exceptions[$connectionHash])) {

+ 13 - 13
tests/Predis/Connection/Cluster/PredisClusterTest.php

@@ -255,23 +255,23 @@ class PredisClusterTest extends PredisTestCase
 
         $set = $commands->createCommand('set', array('node01:5431', 'foobar'));
         $get = $commands->createCommand('get', array('node01:5431'));
-        $this->assertSame($connection1, $cluster->getConnection($set));
-        $this->assertSame($connection1, $cluster->getConnection($get));
+        $this->assertSame($connection1, $cluster->getConnectionByCommand($set));
+        $this->assertSame($connection1, $cluster->getConnectionByCommand($get));
 
         $set = $commands->createCommand('set', array('prefix:{node01:5431}', 'foobar'));
         $get = $commands->createCommand('get', array('prefix:{node01:5431}'));
-        $this->assertSame($connection1, $cluster->getConnection($set));
-        $this->assertSame($connection1, $cluster->getConnection($get));
+        $this->assertSame($connection1, $cluster->getConnectionByCommand($set));
+        $this->assertSame($connection1, $cluster->getConnectionByCommand($get));
 
         $set = $commands->createCommand('set', array('node02:3212', 'foobar'));
         $get = $commands->createCommand('get', array('node02:3212'));
-        $this->assertSame($connection2, $cluster->getConnection($set));
-        $this->assertSame($connection2, $cluster->getConnection($get));
+        $this->assertSame($connection2, $cluster->getConnectionByCommand($set));
+        $this->assertSame($connection2, $cluster->getConnectionByCommand($get));
 
         $set = $commands->createCommand('set', array('prefix:{node02:3212}', 'foobar'));
         $get = $commands->createCommand('get', array('prefix:{node02:3212}'));
-        $this->assertSame($connection2, $cluster->getConnection($set));
-        $this->assertSame($connection2, $cluster->getConnection($get));
+        $this->assertSame($connection2, $cluster->getConnectionByCommand($set));
+        $this->assertSame($connection2, $cluster->getConnectionByCommand($get));
     }
 
     /**
@@ -287,7 +287,7 @@ class PredisClusterTest extends PredisTestCase
 
         $cluster->add($this->getMockConnection());
 
-        $cluster->getConnection($ping);
+        $cluster->getConnectionByCommand($ping);
     }
 
     /**
@@ -307,13 +307,13 @@ class PredisClusterTest extends PredisTestCase
 
         $set = $commands->createCommand('set', array('{node:1001}:foo', 'foobar'));
         $get = $commands->createCommand('get', array('{node:1001}:foo'));
-        $this->assertSame($connection1, $cluster->getConnection($set));
-        $this->assertSame($connection1, $cluster->getConnection($get));
+        $this->assertSame($connection1, $cluster->getConnectionByCommand($set));
+        $this->assertSame($connection1, $cluster->getConnectionByCommand($get));
 
         $set = $commands->createCommand('set', array('{node:1001}:bar', 'foobar'));
         $get = $commands->createCommand('get', array('{node:1001}:bar'));
-        $this->assertSame($connection1, $cluster->getConnection($set));
-        $this->assertSame($connection1, $cluster->getConnection($get));
+        $this->assertSame($connection1, $cluster->getConnectionByCommand($set));
+        $this->assertSame($connection1, $cluster->getConnectionByCommand($get));
     }
 
     /**

+ 11 - 11
tests/Predis/Connection/Cluster/RedisClusterTest.php

@@ -527,18 +527,18 @@ class RedisClusterTest extends PredisTestCase
 
         $set = $commands->createCommand('set', array('node:1001', 'foobar'));
         $get = $commands->createCommand('get', array('node:1001'));
-        $this->assertSame($connection1, $cluster->getConnection($set));
-        $this->assertSame($connection1, $cluster->getConnection($get));
+        $this->assertSame($connection1, $cluster->getConnectionByCommand($set));
+        $this->assertSame($connection1, $cluster->getConnectionByCommand($get));
 
         $set = $commands->createCommand('set', array('node:1048', 'foobar'));
         $get = $commands->createCommand('get', array('node:1048'));
-        $this->assertSame($connection2, $cluster->getConnection($set));
-        $this->assertSame($connection2, $cluster->getConnection($get));
+        $this->assertSame($connection2, $cluster->getConnectionByCommand($set));
+        $this->assertSame($connection2, $cluster->getConnectionByCommand($get));
 
         $set = $commands->createCommand('set', array('node:1082', 'foobar'));
         $get = $commands->createCommand('get', array('node:1082'));
-        $this->assertSame($connection3, $cluster->getConnection($set));
-        $this->assertSame($connection3, $cluster->getConnection($get));
+        $this->assertSame($connection3, $cluster->getConnectionByCommand($set));
+        $this->assertSame($connection3, $cluster->getConnectionByCommand($get));
     }
 
     /**
@@ -917,13 +917,13 @@ class RedisClusterTest extends PredisTestCase
 
         $set = $commands->createCommand('set', array('{node:1001}:foo', 'foobar'));
         $get = $commands->createCommand('get', array('{node:1001}:foo'));
-        $this->assertSame($connection1, $cluster->getConnection($set));
-        $this->assertSame($connection1, $cluster->getConnection($get));
+        $this->assertSame($connection1, $cluster->getConnectionByCommand($set));
+        $this->assertSame($connection1, $cluster->getConnectionByCommand($get));
 
         $set = $commands->createCommand('set', array('{node:1001}:bar', 'foobar'));
         $get = $commands->createCommand('get', array('{node:1001}:bar'));
-        $this->assertSame($connection1, $cluster->getConnection($set));
-        $this->assertSame($connection1, $cluster->getConnection($get));
+        $this->assertSame($connection1, $cluster->getConnectionByCommand($set));
+        $this->assertSame($connection1, $cluster->getConnectionByCommand($get));
     }
 
     /**
@@ -1259,7 +1259,7 @@ class RedisClusterTest extends PredisTestCase
 
         $cluster->add($this->getMockConnection('tcp://127.0.0.1:6379'));
 
-        $cluster->getConnection($ping);
+        $cluster->getConnectionByCommand($ping);
     }
 
     /**

+ 10 - 10
tests/Predis/Connection/Replication/MasterSlaveReplicationTest.php

@@ -367,10 +367,10 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $replication->add($slave1);
 
         $cmd = $commands->createCommand('exists', array('foo'));
-        $this->assertSame($slave1, $replication->getConnection($cmd));
+        $this->assertSame($slave1, $replication->getConnectionByCommand($cmd));
 
         $cmd = $commands->createCommand('get', array('foo'));
-        $this->assertSame($slave1, $replication->getConnection($cmd));
+        $this->assertSame($slave1, $replication->getConnectionByCommand($cmd));
     }
 
     /**
@@ -389,10 +389,10 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $replication->add($slave1);
 
         $cmd = $commands->createCommand('set', array('foo', 'bar'));
-        $this->assertSame($master, $replication->getConnection($cmd));
+        $this->assertSame($master, $replication->getConnectionByCommand($cmd));
 
         $cmd = $commands->createCommand('get', array('foo'));
-        $this->assertSame($master, $replication->getConnection($cmd));
+        $this->assertSame($master, $replication->getConnectionByCommand($cmd));
     }
 
     /**
@@ -409,10 +409,10 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $replication->add($master);
 
         $cmd = $commands->createCommand('exists', array('foo'));
-        $this->assertSame($master, $replication->getConnection($cmd));
+        $this->assertSame($master, $replication->getConnectionByCommand($cmd));
 
         $cmd = $commands->createCommand('set', array('foo', 'bar'));
-        $this->assertSame($master, $replication->getConnection($cmd));
+        $this->assertSame($master, $replication->getConnectionByCommand($cmd));
     }
 
     /**
@@ -431,13 +431,13 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $replication->add($slave1);
 
         $cmd = $commands->createCommand('exists', array('foo'));
-        $this->assertSame($slave1, $replication->getConnection($cmd));
+        $this->assertSame($slave1, $replication->getConnectionByCommand($cmd));
 
         $cmd = $commands->createCommand('set', array('foo', 'bar'));
-        $this->assertSame($master, $replication->getConnection($cmd));
+        $this->assertSame($master, $replication->getConnectionByCommand($cmd));
 
         $cmd = $commands->createCommand('exists', array('foo'));
-        $this->assertSame($master, $replication->getConnection($cmd));
+        $this->assertSame($master, $replication->getConnectionByCommand($cmd));
     }
 
     /**
@@ -867,7 +867,7 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $replication->add($this->getMockConnection('tcp://host1?alias=master'));
         $replication->add($this->getMockConnection('tcp://host2?alias=slave1'));
 
-        $replication->getConnection($cmd);
+        $replication->getConnectionByCommand($cmd);
     }
 
     /**

+ 9 - 9
tests/Predis/Connection/Replication/SentinelReplicationTest.php

@@ -828,11 +828,11 @@ class SentinelReplicationTest extends PredisTestCase
         $replication->add($master);
         $replication->add($slave1);
 
-        $this->assertSame($master, $replication->getConnection(
+        $this->assertSame($master, $replication->getConnectionByCommand(
             Command\RawCommand::create('set', 'key', 'value')
         ));
 
-        $this->assertSame($master, $replication->getConnection(
+        $this->assertSame($master, $replication->getConnectionByCommand(
             Command\RawCommand::create('del', 'key')
         ));
     }
@@ -864,11 +864,11 @@ class SentinelReplicationTest extends PredisTestCase
         $replication->add($master);
         $replication->add($slave1);
 
-        $this->assertSame($slave1, $replication->getConnection(
+        $this->assertSame($slave1, $replication->getConnectionByCommand(
             Command\RawCommand::create('get', 'key')
         ));
 
-        $this->assertSame($slave1, $replication->getConnection(
+        $this->assertSame($slave1, $replication->getConnectionByCommand(
             Command\RawCommand::create('exists', 'key')
         ));
     }
@@ -911,15 +911,15 @@ class SentinelReplicationTest extends PredisTestCase
         $replication->add($master);
         $replication->add($slave1);
 
-        $this->assertSame($slave1, $replication->getConnection(
+        $this->assertSame($slave1, $replication->getConnectionByCommand(
             Command\RawCommand::create('exists', 'key')
         ));
 
-        $this->assertSame($master, $replication->getConnection(
+        $this->assertSame($master, $replication->getConnectionByCommand(
             Command\RawCommand::create('set', 'key', 'value')
         ));
 
-        $this->assertSame($master, $replication->getConnection(
+        $this->assertSame($master, $replication->getConnectionByCommand(
             Command\RawCommand::create('get', 'key')
         ));
     }
@@ -950,7 +950,7 @@ class SentinelReplicationTest extends PredisTestCase
 
         $replication->add($master);
 
-        $replication->getConnection(Command\RawCommand::create('del', 'key'));
+        $replication->getConnectionByCommand(Command\RawCommand::create('del', 'key'));
     }
 
     /**
@@ -996,7 +996,7 @@ class SentinelReplicationTest extends PredisTestCase
 
         $replication->add($master);
 
-        $replication->getConnection(Command\RawCommand::create('get', 'key'));
+        $replication->getConnectionByCommand(Command\RawCommand::create('get', 'key'));
     }
 
     /**