Pārlūkot izejas kodu

Address #133 by reusing our own methods.

The main reason behind that code duplication was performance related
as we tried to reduce method calls when possible, even at the cost of
falling into the realm of early optimizations. Apparently we just lose
~400 req/sec on a 21000 req/sec basis ("SET foo bar") using PHP 5.5.3
(packaged by Ubuntu 13.10) on an Intel Q6600, so we will most likely
stick with this change for the sake of best practices.

Backported from v0.9-dev.
Daniele Alessandri 11 gadi atpakaļ
vecāks
revīzija
4e664c6c90
2 mainītis faili ar 11 papildinājumiem un 18 dzēšanām
  1. 10 17
      lib/Predis/Client.php
  2. 1 1
      tests/Predis/ClientTest.php

+ 10 - 17
lib/Predis/Client.php

@@ -215,34 +215,27 @@ class Client implements ClientInterface
     }
 
     /**
-     * Dynamically invokes a Redis command with the specified arguments.
+     * Creates a Redis command with the specified arguments and sends a request
+     * to the server.
      *
-     * @param string $method The name of a Redis command.
-     * @param array $arguments The arguments for the command.
+     * @param string $commandID Command ID.
+     * @param array $arguments Arguments for the command.
      * @return mixed
      */
-    public function __call($method, $arguments)
+    public function __call($commandID, $arguments)
     {
-        $command = $this->profile->createCommand($method, $arguments);
-        $response = $this->connection->executeCommand($command);
-
-        if ($response instanceof ResponseObjectInterface) {
-            if ($response instanceof ResponseErrorInterface) {
-                $response = $this->onResponseError($command, $response);
-            }
+        $command = $this->createCommand($commandID, $arguments);
+        $response = $this->executeCommand($command);
 
-            return $response;
-        }
-
-        return $command->parseResponse($response);
+        return $response;
     }
 
     /**
      * {@inheritdoc}
      */
-    public function createCommand($method, $arguments = array())
+    public function createCommand($commandID, $arguments = array())
     {
-        return $this->profile->createCommand($method, $arguments);
+        return $this->profile->createCommand($commandID, $arguments);
     }
 
     /**

+ 1 - 1
tests/Predis/ClientTest.php

@@ -404,7 +404,7 @@ class ClientTest extends StandardTestCase
                 ->will($this->returnValue($ping));
 
         $options = array('profile' => $profile);
-        $client = $this->getMock('Predis\Client', array('createCommand'), array($connection, $options));
+        $client = $this->getMock('Predis\Client', null, array($connection, $options));
 
         $this->assertTrue($client->ping());
     }