Browse Source

Reduced memory consumption for pipelines

Daniele Alessandri 15 years ago
parent
commit
1d3e8cea59
1 changed files with 6 additions and 6 deletions
  1. 6 6
      lib/Predis.php

+ 6 - 6
lib/Predis.php

@@ -400,21 +400,21 @@ class CommandPipeline {
     }
     }
 
 
     public function flushPipeline() {
     public function flushPipeline() {
-        if (count($this->_pipelineBuffer) === 0) {
+        $sizeofPipe = count($this->_pipelineBuffer);
+        if ($sizeofPipe === 0) {
             return;
             return;
         }
         }
 
 
         $connection = $this->_redisClient->getConnection();
         $connection = $this->_redisClient->getConnection();
-        $commands   = $this->getRecordedCommands();
+        $commands   = &$this->_pipelineBuffer;
 
 
         foreach ($commands as $command) {
         foreach ($commands as $command) {
             $connection->writeCommand($command);
             $connection->writeCommand($command);
         }
         }
-        foreach ($commands as $command) {
-            $this->_returnValues[] = $connection->readResponse($command);
+        for ($i = 0; $i < $sizeofPipe; $i++) {
+            $this->_returnValues[] = $connection->readResponse($commands[$i]);
+            unset($commands[$i]);
         }
         }
-
-        $this->_pipelineBuffer = array();
     }
     }
 
 
     private function setRunning($bool) {
     private function setRunning($bool) {