瀏覽代碼

Use only one check for replies that should not be passed to a reply parser.

Daniele Alessandri 14 年之前
父節點
當前提交
118af2809c
共有 2 個文件被更改,包括 16 次插入4 次删除
  1. 14 4
      lib/Predis.php
  2. 2 0
      test/PredisClientFeatures.php

+ 14 - 4
lib/Predis.php

@@ -697,6 +697,7 @@ class ResponseReader {
 }
 
 class ResponseError {
+    public $skipParse = true;
     private $_message;
 
     public function __construct($message) {
@@ -722,11 +723,21 @@ class ResponseError {
 }
 
 class ResponseQueued {
-    public $queued = true;
+    public $skipParse = true;
 
     public function __toString() {
         return Protocol::QUEUED;
     }
+
+    public function __get($property) {
+        if ($property === 'queued') {
+            return true;
+        }
+    }
+
+    public function __isset($property) {
+        return $property === 'queued';
+    }
 }
 
 /* ------------------------------------------------------------------------- */
@@ -873,7 +884,7 @@ class MultiExecBlock {
         }
         $command  = $client->createCommand($method, $arguments);
         $response = $client->executeCommand($command);
-        if (!isset($response->queued)) {
+        if (!$response instanceof \Predis\ResponseQueued) {
             $this->malformedServerResponse(
                 'The server did not respond with a QUEUED status reply'
             );
@@ -1344,8 +1355,7 @@ class Connection implements IConnection {
 
     public function readResponse(Command $command) {
         $response = $this->_reader->read($this);
-        $skipparse = isset($response->queued) || isset($response->error);
-        return $skipparse ? $response : $command->parseResponse($response);
+        return isset($response->skipParse) ? $response : $command->parseResponse($response);
     }
 
     public function executeCommand(Command $command) {

+ 2 - 0
test/PredisClientFeatures.php

@@ -216,6 +216,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
 
     function testResponseQueued() {
         $response = new \Predis\ResponseQueued();
+        $this->assertTrue($response->skipParse);
         $this->assertTrue($response->queued);
         $this->assertEquals(\Predis\Protocol::QUEUED, (string)$response);
     }
@@ -227,6 +228,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
         $errorMessage = 'ERROR MESSAGE';
         $response = new \Predis\ResponseError($errorMessage);
 
+        $this->assertTrue($response->skipParse);
         $this->assertTrue($response->error);
         $this->assertEquals($errorMessage, $response->message);
         $this->assertEquals($errorMessage, (string)$response);