Преглед изворни кода

Pipelines can now be initialized and used even without an anonymous function block. This is also needed to get pipelining support backported to PHP 5.2.

Daniele Alessandri пре 15 година
родитељ
комит
0adcd39486
1 измењених фајлова са 6 додато и 4 уклоњено
  1. 6 4
      lib/Predis.php

+ 6 - 4
lib/Predis.php

@@ -93,9 +93,9 @@ class Client {
         return $this->_connection->rawCommand($rawCommandData, $closesConnection);
         return $this->_connection->rawCommand($rawCommandData, $closesConnection);
     }
     }
 
 
-    public function pipeline(\Closure $pipelineBlock) {
+    public function pipeline(\Closure $pipelineBlock = null) {
         $pipeline = new CommandPipeline($this);
         $pipeline = new CommandPipeline($this);
-        return $pipeline->execute($pipelineBlock);
+        return $pipelineBlock !== null ? $pipeline->execute($pipelineBlock) : $pipeline;
     }
     }
 
 
     public function registerCommands(Array $commands) {
     public function registerCommands(Array $commands) {
@@ -511,12 +511,14 @@ class CommandPipeline {
         $this->_running = $bool;
         $this->_running = $bool;
     }
     }
 
 
-    public function execute(\Closure $block) {
+    public function execute(\Closure $block = null) {
         $this->setRunning(true);
         $this->setRunning(true);
         $pipelineBlockException = null;
         $pipelineBlockException = null;
 
 
         try {
         try {
-            $block($this);
+            if ($block !== null) {
+                $block($this);
+            }
             $this->flushPipeline();
             $this->flushPipeline();
         }
         }
         catch (\Exception $exception) {
         catch (\Exception $exception) {