thbourlove 11 vuotta sitten
vanhempi
commit
e1d700dd0c
2 muutettua tiedostoa jossa 25 lisäystä ja 25 poistoa
  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 AbstractCommand
         $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 single row of the reply buffer and returns the key-value pair.
+     *
+     * @param string $row Single row of the reply buffer.
+     * @return array
+     */
+    public 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 [$k, $v];
+    }
+
     /**
      * Parses the reply buffer and extracts the statistics of each logical DB.
      *

+ 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;