Sfoglia il codice sorgente

Port #156 to the current master branch.

This fix the parsing of responses to INFO when the node is configured
to work with redis-sentinel.
Daniele Alessandri 11 anni fa
parent
commit
a51ff2d6e5
2 ha cambiato i file con 25 aggiunte e 25 eliminazioni
  1. 23 13
      lib/Predis/Command/ServerInfo.php
  2. 2 12
      lib/Predis/Command/ServerInfoV26x.php

+ 23 - 13
lib/Predis/Command/ServerInfo.php

@@ -34,27 +34,37 @@ class ServerInfo extends Command
         $infoLines = preg_split('/\r?\n/', $data);
 
         foreach ($infoLines as $row) {
-            @list($k, $v) = explode(':', $row);
-
-            if ($row === '' || !isset($v)) {
+            if (strpos($row, ':') === false) {
                 continue;
             }
 
-            if (!preg_match('/^db\d+$/', $k)) {
-                if ($k === 'allocation_stats') {
-                    $info[$k] = $this->parseAllocationStats($v);
-                    continue;
-                }
-
-                $info[$k] = $v;
-            } else {
-                $info[$k] = $this->parseDatabaseStats($v);
-            }
+            list($k, $v) = $this->parseRow($row);
+            $info[$k] = $v;
         }
 
         return $info;
     }
 
+    /**
+     * Parses a single row of the response and returns the key-value pair.
+     *
+     * @param string $row Single row of the response.
+     * @return array
+     */
+    protected function parseRow($row)
+    {
+        list($k, $v) = explode(':', $row, 2);
+
+        if (!preg_match('/^db\d+$/', $k)) {
+            if ($k === 'allocation_stats') {
+                $v = $this->parseAllocationStats($v);
+            }
+        } else {
+            $v = $this->parseDatabaseStats($v);
+        }
+        return array($k, $v);
+    }
+
     /**
      * Extracts the statistics of each logical DB from the string buffer.
      *

+ 2 - 12
lib/Predis/Command/ServerInfoV26x.php

@@ -41,18 +41,8 @@ class ServerInfoV26x extends ServerInfo
                 continue;
             }
 
-            list($k, $v) = explode(':', $row);
-
-            if (!preg_match('/^db\d+$/', $k)) {
-                if ($k === 'allocation_stats') {
-                    $current[$k] = $this->parseAllocationStats($v);
-                    continue;
-                }
-
-                $current[$k] = $v;
-            } else {
-                $current[$k] = $this->parseDatabaseStats($v);
-            }
+            list($k, $v) = $this->parseRow($row);
+            $current[$k] = $v;
         }
 
         return $info;