瀏覽代碼

Parse allocation_stats if present in the INFO reply.

Daniele Alessandri 14 年之前
父節點
當前提交
3186da49b4
共有 2 個文件被更改,包括 22 次插入1 次删除
  1. 17 0
      lib/Predis/Commands/Info.php
  2. 5 1
      lib/Predis/Commands/InfoV24x.php

+ 17 - 0
lib/Predis/Commands/Info.php

@@ -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
lib/Predis/Commands/InfoV24x.php

@@ -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 {