|
@@ -13,6 +13,7 @@ namespace Predis\Pipeline;
|
|
|
|
|
|
use Predis\ServerException;
|
|
|
use Predis\Connection\ConnectionInterface;
|
|
|
+use Predis\Connection\ReplicationConnectionInterface;
|
|
|
|
|
|
/**
|
|
|
* Implements the standard pipeline executor strategy used
|
|
@@ -23,6 +24,20 @@ use Predis\Connection\ConnectionInterface;
|
|
|
*/
|
|
|
class StandardExecutor implements PipelineExecutorInterface
|
|
|
{
|
|
|
+ /**
|
|
|
+ * Allows the pipeline executor to perform operations on the
|
|
|
+ * connection before starting to execute the commands stored
|
|
|
+ * in the pipeline.
|
|
|
+ *
|
|
|
+ * @param ConnectionInterface Connection instance.
|
|
|
+ */
|
|
|
+ protected function checkConnection(ConnectionInterface $connection)
|
|
|
+ {
|
|
|
+ if ($connection instanceof ReplicationConnectionInterface) {
|
|
|
+ $connection->switchTo('master');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* {@inheritdoc}
|
|
|
*/
|
|
@@ -31,6 +46,8 @@ class StandardExecutor implements PipelineExecutorInterface
|
|
|
$sizeofPipe = count($commands);
|
|
|
$values = array();
|
|
|
|
|
|
+ $this->checkConnection($connection);
|
|
|
+
|
|
|
foreach ($commands as $command) {
|
|
|
$connection->writeCommand($command);
|
|
|
}
|