فهرست منبع

Switch to the new lightweight response reader.

Daniele Alessandri 14 سال پیش
والد
کامیت
434b9dd0f7
3فایلهای تغییر یافته به همراه16 افزوده شده و 27 حذف شده
  1. 5 3
      CHANGELOG
  2. 5 5
      lib/Predis.php
  3. 6 19
      test/ClientFeaturesTest.php

+ 5 - 3
CHANGELOG

@@ -7,9 +7,11 @@ v0.6.6 (2011-xx-xx)
   * Some performance improvements for multibulk replies (parsing them is about 
     16% faster than the previous version).
 
-  * Added a new and optional protocol reader, more lightweight and faster than 
-    the default handlers-based one. Users can also specify a custom protocol 
-    reader using the new 'reader' client option.
+  * Predis now uses by default a new protocol reader, more lightweight and 
+    faster than the default handler-based one. Users can revert to the old 
+    protocol reader with the 'reader' client option set to 'composable'.
+    This client option can also accept custom reader classes implementing the 
+    new Predis\IResponseReader interface.
 
   * Added support for connecting to Redis using UNIX domain sockets (ISSUE #25).
 

+ 5 - 5
lib/Predis.php

@@ -356,8 +356,8 @@ class ClientOptionsReader implements IClientOptionsHandler {
             return $value;
         }
         if (is_string($value)) {
-            if ($value === 'fast') {
-                return new \Predis\FastResponseReader();
+            if ($value === 'composable') {
+                return new \Predis\ResponseReader();
             }
             $valueReflection = new \ReflectionClass($value);
             if ($valueReflection->isSubclassOf('\Predis\IResponseReader')) {
@@ -368,7 +368,7 @@ class ClientOptionsReader implements IClientOptionsHandler {
     }
 
     public function getDefault() {
-        return new \Predis\ResponseReader();
+        return new \Predis\FastResponseReader();
     }
 }
 
@@ -721,7 +721,7 @@ class FastResponseReader implements IResponseReader {
                     return null;
                 }
                 if ($this->_iterableMultibulk) {
-                    return new MultiBulkResponseSimple($connection, $count);
+                    return new \Predis\Shared\MultiBulkResponseIterator($connection, $count);
                 }
                 $multibulk = array();
                 for ($i = 0; $i < $count; $i++) {
@@ -1421,7 +1421,7 @@ class Connection implements IConnection {
         $this->_initializer = array($this, "{$parameters->scheme}StreamInitializer");
         $this->_params   = $parameters;
         $this->_initCmds = array();
-        $this->_reader   = $reader ?: new ResponseReader();
+        $this->_reader   = $reader ?: new FastResponseReader();
     }
 
     public function __destruct() {

+ 6 - 19
test/ClientFeaturesTest.php

@@ -336,18 +336,11 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
 
     function testResponseReader_OptionIterableMultiBulkReplies() {
         $connection = new \Predis\Connection(RC::getConnectionParameters());
-        $responseReader = $connection->getResponseReader();
 
-        $responseReader->setHandler(
-            \Predis\Protocol::PREFIX_MULTI_BULK, 
-            new \Predis\ResponseMultiBulkHandler()
-        );
+        $connection->getResponseReader()->setOption('iterable_multibulk', false);
         $this->assertInternalType('array', $connection->rawCommand("KEYS *\r\n"));
 
-        $responseReader->setHandler(
-            \Predis\Protocol::PREFIX_MULTI_BULK, 
-            new \Predis\ResponseMultiBulkStreamHandler()
-        );
+        $connection->getResponseReader()->setOption('iterable_multibulk', true);
         $this->assertInstanceOf('\Iterator', $connection->rawCommand("KEYS *\r\n"));
     }
 
@@ -357,18 +350,12 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
         $connection->rawCommand("*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n");
         $rawCmdUnexpected = "*3\r\n$5\r\nLPUSH\r\n$3\r\nkey\r\n$5\r\nvalue\r\n";
 
-        $responseReader->setHandler(
-            \Predis\Protocol::PREFIX_ERROR,  
-            new \Predis\ResponseErrorSilentHandler()
-        );
+        $responseReader->setOption('throw_on_error', false);
         $errorReply = $connection->rawCommand($rawCmdUnexpected);
         $this->assertInstanceOf('\Predis\ResponseError', $errorReply);
         $this->assertEquals(RC::EXCEPTION_WRONG_TYPE, $errorReply->message);
 
-        $responseReader->setHandler(
-            \Predis\Protocol::PREFIX_ERROR, 
-            new \Predis\ResponseErrorHandler()
-        );
+        $responseReader->setOption('throw_on_error', true);
         RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function() 
             use ($connection, $rawCmdUnexpected) {
 
@@ -448,7 +435,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
     function testCommandPipeline_ServerExceptionInCallableBlock() {
         $client = RC::getConnection();
         $client->flushdb();
-        $client->getResponseReader()->setHandler('-', new \Predis\ResponseErrorSilentHandler());
+        $client->getResponseReader()->setOption('throw_on_error', false);
 
         $replies = $client->pipeline(function($pipe) {
             $pipe->set('foo', 'bar');
@@ -570,7 +557,7 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
     function testMultiExecBlock_ServerExceptionInCallableBlock() {
         $client = RC::getConnection();
         $client->flushdb();
-        $client->getResponseReader()->setHandler('-', new \Predis\ResponseErrorSilentHandler());
+        $client->getResponseReader()->setOption('throw_on_error', false);
 
         $replies = $client->multiExec(function($multi) {
             $multi->set('foo', 'bar');