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.
This commit is contained in:
Daniele Alessandri
2011-12-21 21:08:14 +01:00
parent 466c666547
commit 63cb150fc2
+8
View File
@@ -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);
}