Преглед изворни кода

Change methods of replication connection interface.

Promoted the "switchToMaster()" and "switchToSlave()" methods to be
part of the replication connection interface and demoted the method
"switchTo($connection)".
Daniele Alessandri пре 8 година
родитељ
комит
7c4c4ae58a

+ 4 - 0
CHANGELOG.md

@@ -41,6 +41,10 @@ v2.0.0 (201x-xx-xx)
   namespaces for cluster backends (`Predis\Connection\Cluster`) and replication
   backends (`Predis\Connection\Replication`).
 
+- 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.
+
 
 v1.1.0 (2016-06-02)
 ================================================================================

+ 6 - 3
src/Connection/Replication/MasterSlaveReplication.php

@@ -181,7 +181,10 @@ class MasterSlaveReplication implements ReplicationInterface
     }
 
     /**
-     * {@inheritdoc}
+     * Switches the connection in use by the backend to the specified instance
+     * or alias of a connection.
+     *
+     * @param NodeConnectionInterface|string $connection Instance or alias of a connection.
      */
     public function switchTo($connection)
     {
@@ -201,7 +204,7 @@ class MasterSlaveReplication implements ReplicationInterface
     }
 
     /**
-     * Switches to the master server.
+     * {@inheritdoc}
      */
     public function switchToMaster()
     {
@@ -209,7 +212,7 @@ class MasterSlaveReplication implements ReplicationInterface
     }
 
     /**
-     * Switches to a random slave server.
+     * {@inheritdoc}
      */
     public function switchToSlave()
     {

+ 10 - 8
src/Connection/Replication/ReplicationInterface.php

@@ -22,29 +22,31 @@ use Predis\Connection\NodeConnectionInterface;
 interface ReplicationInterface extends AggregateConnectionInterface
 {
     /**
-     * Switches the internal connection instance in use.
-     *
-     * @param string $connection Alias of a connection
+     * Switches the internal connection in use to the master server.
+     */
+    public function switchToMaster();
+
+    /**
+     * Switches the internal connection in use to a random slave server.
      */
-    public function switchTo($connection);
+    public function switchToSlave();
 
     /**
-     * Returns the connection instance currently in use by the aggregate
-     * connection.
+     * Returns the connection in use by the replication backend.
      *
      * @return NodeConnectionInterface
      */
     public function getCurrent();
 
     /**
-     * Returns the connection instance for the master Redis node.
+     * Returns the connection to the master server.
      *
      * @return NodeConnectionInterface
      */
     public function getMaster();
 
     /**
-     * Returns a list of connection instances to slave nodes.
+     * Returns a list of connections to slave servers.
      *
      * @return NodeConnectionInterface
      */

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

@@ -587,7 +587,7 @@ class SentinelReplication implements ReplicationInterface
     }
 
     /**
-     * Switches to the master server.
+     * {@inheritdoc}
      */
     public function switchToMaster()
     {
@@ -595,7 +595,7 @@ class SentinelReplication implements ReplicationInterface
     }
 
     /**
-     * Switches to a random slave server.
+     * {@inheritdoc}
      */
     public function switchToSlave()
     {

+ 1 - 1
src/Pipeline/Pipeline.php

@@ -112,7 +112,7 @@ class Pipeline implements ClientContextInterface
         $connection = $this->getClient()->getConnection();
 
         if ($connection instanceof ReplicationInterface) {
-            $connection->switchTo('master');
+            $connection->switchToMaster();
         }
 
         return $connection;

+ 1 - 2
tests/Predis/Pipeline/FireAndForgetTest.php

@@ -44,8 +44,7 @@ class FireAndForgetTest extends PredisTestCase
     {
         $connection = $this->getMock('Predis\Connection\Replication\ReplicationInterface');
         $connection->expects($this->once())
-                   ->method('switchTo')
-                   ->with('master');
+                   ->method('switchToMaster');
         $connection->expects($this->exactly(3))
                    ->method('writeRequest');
         $connection->expects($this->never())

+ 1 - 2
tests/Predis/Pipeline/PipelineTest.php

@@ -242,8 +242,7 @@ class PipelineTest extends PredisTestCase
 
         $connection = $this->getMock('Predis\Connection\Replication\ReplicationInterface');
         $connection->expects($this->once())
-                   ->method('switchTo')
-                   ->with('master');
+                   ->method('switchToMaster');
         $connection->expects($this->exactly(3))
                    ->method('writeRequest');
         $connection->expects($this->exactly(3))