Browse Source

Fix response parsing with scripted commands after -NOSCRIPT.

This commit fixes issue #94.
Daniele Alessandri 12 years ago
parent
commit
bfd96b15dc
3 changed files with 17 additions and 3 deletions
  1. 4 0
      CHANGELOG.md
  2. 7 1
      lib/Predis/Client.php
  3. 6 2
      tests/Predis/ClientTest.php

+ 4 - 0
CHANGELOG.md

@@ -4,6 +4,10 @@ v0.8.1 (201x-xx-xx)
   caused PHP errors when Redis did not return `+QUEUED` replies to commands
   when inside a MULTI / EXEC context.
 
+- __FIX__: the `parseResponse()` method implemented for a scripted command was
+  ignored when retrying to execute a Lua script by falling back to `EVAL` after
+  a `-NOSCRIPT` error (ISSUE #94).
+
 
 v0.8.0 (2012-10-23)
 ===============================================================================

+ 7 - 1
lib/Predis/Client.php

@@ -267,7 +267,13 @@ class Client implements ClientInterface
             $eval = $this->createCommand('eval');
             $eval->setRawArguments($command->getEvalArguments());
 
-            return $this->executeCommand($eval);
+            $response = $this->executeCommand($eval);
+
+            if (false === $response instanceof ResponseObjectInterface) {
+                $response = $command->parseResponse($response);
+            }
+
+            return $response;
         }
 
         if ($this->options->exceptions === true) {

+ 6 - 2
tests/Predis/ClientTest.php

@@ -656,10 +656,14 @@ class ClientTest extends StandardTestCase
      */
     public function testClientResendScriptedCommandUsingEvalOnNoScriptErrors()
     {
-        $command = $this->getMockForAbstractClass('Predis\Command\ScriptedCommand');
+        $command = $this->getMockForAbstractClass('Predis\Command\ScriptedCommand', array(), '', true, true, true, array('parseResponse'));
         $command->expects($this->once())
                 ->method('getScript')
                 ->will($this->returnValue('return redis.call(\'exists\', KEYS[1])'));
+        $command->expects($this->once())
+                ->method('parseResponse')
+                ->with('OK')
+                ->will($this->returnValue(true));
 
         $connection = $this->getMock('Predis\Connection\SingleConnectionInterface');
         $connection->expects($this->at(0))
@@ -669,7 +673,7 @@ class ClientTest extends StandardTestCase
         $connection->expects($this->at(1))
                    ->method('executeCommand')
                    ->with($this->isInstanceOf('Predis\Command\ServerEval'))
-                   ->will($this->returnValue(true));
+                   ->will($this->returnValue('OK'));
 
         $client = new Client($connection);