Explorar o código

Reduce method calls by one when creating a new connection in Predis\Client.

Daniele Alessandri %!s(int64=14) %!d(string=hai) anos
pai
achega
6e6a28a9f0
Modificáronse 1 ficheiros con 11 adicións e 15 borrados
  1. 11 15
      lib/Predis/Client.php

+ 11 - 15
lib/Predis/Client.php

@@ -65,24 +65,20 @@ class Client {
         return $this->createConnection($parameters);
     }
 
-    private function createConnection($parameters) {
+    protected function createConnection($parameters) {
         $connection = $this->_connectionFactory->create($parameters);
-        $this->pushInitCommands($connection);
-        return $connection;
-    }
-
-    private function pushInitCommands(IConnectionSingle $connection) {
-        $params = $connection->getParameters();
-        if (isset($params->password)) {
-            $connection->pushInitCommand($this->createCommand(
-                'auth', array($params->password)
-            ));
+        $parameters = $connection->getParameters();
+        if (isset($parameters->password)) {
+            $connection->pushInitCommand(
+                $this->createCommand('auth', array($parameters->password))
+            );
         }
-        if (isset($params->database)) {
-            $connection->pushInitCommand($this->createCommand(
-                'select', array($params->database)
-            ));
+        if (isset($parameters->database)) {
+            $connection->pushInitCommand(
+                $this->createCommand('select', array($parameters->database))
+            );
         }
+        return $connection;
     }
 
     public function getProfile() {