Эх сурвалжийг харах

Give up on some core reusing practices in favor of execution speed and memory usage.

Daniele Alessandri 14 жил өмнө
parent
commit
665e428366

+ 14 - 7
lib/Predis/Network/StreamConnection.php

@@ -12,7 +12,7 @@ use Predis\Protocols\TextCommandSerializer;
 use Predis\Iterators\MultiBulkResponseSimple;
 
 class StreamConnection extends ConnectionBase {
-    private $_commandSerializer, $_mbiterable, $_throwErrors;
+    private $_mbiterable, $_throwErrors;
 
     public function __destruct() {
         if (!$this->_params->connection_persistent) {
@@ -20,11 +20,6 @@ class StreamConnection extends ConnectionBase {
         }
     }
 
-    protected function initializeProtocol(ConnectionParameters $parameters) {
-        $this->_commandSerializer = new TextCommandSerializer();
-        parent::initializeProtocol($parameters);
-    }
-
     protected function createResource() {
         $parameters = $this->_params;
         $initializer = array($this, "{$parameters->scheme}StreamInitializer");
@@ -180,7 +175,19 @@ class StreamConnection extends ConnectionBase {
     }
 
     public function writeCommand(ICommand $command) {
-        $this->write($this->_commandSerializer->serialize($command));
+        $commandId = $command->getId();
+        $arguments = $command->getArguments();
+
+        $cmdlen = strlen($commandId);
+        $reqlen = count($arguments) + 1;
+
+        $buffer = "*{$reqlen}\r\n\${$cmdlen}\r\n{$commandId}\r\n";
+        for ($i = 0; $i < $reqlen - 1; $i++) {
+            $argument = $arguments[$i];
+            $arglen  = strlen($argument);
+            $buffer .= "\${$arglen}\r\n{$argument}\r\n";
+        }
+        $this->write($buffer);
     }
 
     public function readResponse(ICommand $command) {