mirror of
https://github.com/predis/predis.git
synced 2026-09-11 10:57:00 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user