Parse allocation_stats if present in the INFO reply.

This commit is contained in:
Daniele Alessandri
2011-03-06 12:04:31 +01:00
parent 3f8b639e2b
commit 3186da49b4
2 changed files with 22 additions and 1 deletions
+17
View File
@@ -11,6 +11,10 @@ class Info extends Command {
foreach ($infoLines as $row) {
list($k, $v) = explode(':', $row);
if (!preg_match('/^db\d+$/', $k)) {
if ($k === 'allocation_stats') {
$info[$k] = $this->parseAllocationStats($v);
continue;
}
$info[$k] = $v;
}
else {
@@ -24,4 +28,17 @@ class Info extends Command {
}
return $info;
}
protected function parseAllocationStats($str) {
$stats = array();
foreach (explode(',', $str) as $kv) {
list($size, $objects, $extra) = explode('=', $kv);
// hack to prevent incorrect values when parsing the >=256 key
if (isset($extra)) {
$size = ">=$objects";
$objects = $extra;
}
$stats[$size] = $objects;
}
return $stats;
}
}
+5 -1
View File
@@ -2,7 +2,7 @@
namespace Predis\Commands;
class InfoV24x extends Command {
class InfoV24x extends Info {
public function canBeHashed() { return false; }
public function getId() { return 'INFO'; }
public function parseResponse($data) {
@@ -20,6 +20,10 @@ class InfoV24x extends Command {
}
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 {