From 3d499e82a3fb46469db590ba7a226b010cca6779 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sat, 16 Nov 2013 21:54:17 +0100 Subject: [PATCH] Add some supported options to Predis\Client::pipeline(). Only two options available for now, used to specify which kind of pipeline object the client should use or return: - "atomic": returns a pipeline wrapped in a MULTI / EXEC transaction (class: Predis\Pipeline\Atomic). - "fire-and-forget": returns a pipeline that does not read back responses from the server (class: Predis\Pipeline\FireAndForget). We might add more options in the future. --- CHANGELOG.md | 8 +++++++- lib/Predis/Client.php | 10 +++++++++- tests/Predis/ClientTest.php | 5 +++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf3a9de7..3e0ea67d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,13 @@ v0.9.0 (201x-xx-xx) even for custom options defined by the user. - Removed pipeline executors, now command pipelines can be easily customized by - extending the standard `Predis\Pipeline\Pipeline` class. + extending the standard `Predis\Pipeline\Pipeline` class. Accepted options when + creating a pipeline using `Predis\Client::pipeline()` are: + + - `atomic`: returns a pipeline wrapped in a MULTI / EXEC transaction + (class: `Predis\Pipeline\Atomic`). + - `fire-and-forget`: returns a pipeline that does not read back responses + (class: `Predis\Pipeline\FireAndForget`). - Most classes and interfaces in the `Predis\Protocol` namespace have been moved or renamed while rationalizing the whole API of external protocol processors. diff --git a/lib/Predis/Client.php b/lib/Predis/Client.php index e2fe7119..7874e799 100644 --- a/lib/Predis/Client.php +++ b/lib/Predis/Client.php @@ -371,7 +371,15 @@ class Client implements ClientInterface */ protected function createPipeline(array $options = null, $callable = null) { - $pipeline = new Pipeline\Pipeline($this); + if (isset($options['atomic']) && $options['atomic']) { + $class = 'Predis\Pipeline\Atomic'; + } else if (isset($options['fire-and-forget']) && $options['fire-and-forget']) { + $class = 'Predis\Pipeline\FireAndForget'; + } else { + $class = 'Predis\Pipeline\Pipeline'; + } + + $pipeline = new $class($this); if (isset($callable)) { return $pipeline->execute($callable); diff --git a/tests/Predis/ClientTest.php b/tests/Predis/ClientTest.php index 918dddf5..c6d10473 100644 --- a/tests/Predis/ClientTest.php +++ b/tests/Predis/ClientTest.php @@ -581,9 +581,10 @@ class ClientTest extends StandardTestCase public function testPipelineWithArrayReturnsPipeline() { $client = new Client(); - $options = array(); - $this->assertInstanceOf('Predis\Pipeline\Pipeline', $client->pipeline($options)); + $this->assertInstanceOf('Predis\Pipeline\Pipeline', $client->pipeline(array())); + $this->assertInstanceOf('Predis\Pipeline\Atomic', $client->pipeline(array('atomic' => true))); + $this->assertInstanceOf('Predis\Pipeline\FireAndForget', $client->pipeline(array('fire-and-forget' => true))); } /**