diff --git a/lib/Predis/Command/ServerInfo.php b/lib/Predis/Command/ServerInfo.php index 899b16b1..e01c8b5b 100644 --- a/lib/Predis/Command/ServerInfo.php +++ b/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. * diff --git a/lib/Predis/Command/ServerInfoV26x.php b/lib/Predis/Command/ServerInfoV26x.php index 457fe30f..22165db2 100644 --- a/lib/Predis/Command/ServerInfoV26x.php +++ b/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;