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.
This commit is contained in:
Daniele Alessandri
2013-11-16 21:54:17 +01:00
parent 8068c87e47
commit 3d499e82a3
3 changed files with 19 additions and 4 deletions
+7 -1
View File
@@ -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.
+9 -1
View File
@@ -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);
+3 -2
View File
@@ -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)));
}
/**