Browse Source

Improved the internals of MultiExecBlock::execute (slight reduction in memory usage; check for out-of-sync conditions between the client and the server)

Daniele Alessandri 15 years ago
parent
commit
46dd3d6f19
1 changed files with 12 additions and 2 deletions
  1. 12 2
      lib/Predis.php

+ 12 - 2
lib/Predis.php

@@ -495,9 +495,19 @@ class MultiExecBlock {
             if ($block !== null) {
                 $block($this);
             }
+
             $execReply = $this->_redisClient->exec();
-            for ($i = 0; $i < count($execReply); $i++) {
-                $returnValues[] = $this->_commands[$i]->parseResponse($execReply[$i]);
+            $commands  = &$this->_commands;
+            $sizeofReplies = count($execReply);
+
+            if ($sizeofReplies !== count($commands)) {
+                // TODO: think of a better exception message
+                throw new ClientException("Out-of-sync");
+            }
+
+            for ($i = 0; $i < $sizeofReplies; $i++) {
+                $returnValues[] = $commands[$i]->parseResponse($execReply[$i]);
+                unset($commands[$i]);
             }
         }
         catch (\Exception $exception) {