ソースを参照

Switch to the master server right before the execution of a pipeline.

This is actually a temporary solution since we should be using a dedicated
pipeline executor to handle the master/slave replication connection.

Ideally we should stick with a slave if no write operations are present in
the buffer, but forcing a switch to the master connection is the easiest
solution for now and users can still create a new client instance from one
of the slaves when they are sure that their pipelines contain read-only
operations.
Daniele Alessandri 13 年 前
コミット
63cb150fc2
1 ファイル変更8 行追加0 行削除
  1. 8 0
      lib/Predis/Pipeline/PipelineContext.php

+ 8 - 0
lib/Predis/Pipeline/PipelineContext.php

@@ -15,6 +15,7 @@ use Predis\Client;
 use Predis\Helpers;
 use Predis\ClientException;
 use Predis\Commands\ICommand;
+use Predis\Network\IConnectionReplication;
 
 /**
  * Abstraction of a pipeline context where write and read operations
@@ -120,6 +121,13 @@ class PipelineContext
         if (count($this->pipeline) > 0) {
             if ($send) {
                 $connection = $this->client->getConnection();
+
+                // TODO: it would be better to use a dedicated pipeline executor
+                //       for classes implementing master/slave replication.
+                if ($connection instanceof IConnectionReplication) {
+                    $connection->switchTo('master');
+                }
+
                 $replies = $this->executor->execute($connection, $this->pipeline);
                 $this->replies = array_merge($this->replies, $replies);
             }