Browse Source

Implement a new command class for INFO to parse the new reply format for this command in Redis > 2.2.

Daniele Alessandri 14 years ago
parent
commit
6c9b246b2b
2 changed files with 42 additions and 0 deletions
  1. 36 0
      lib/Predis/Commands/InfoV24x.php
  2. 6 0
      lib/Predis/Profiles/ServerVersionNext.php

+ 36 - 0
lib/Predis/Commands/InfoV24x.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace Predis\Commands;
+
+class InfoV24x extends Command {
+    public function canBeHashed()  { return false; }
+    public function getId() { return 'INFO'; }
+    public function parseResponse($data) {
+        $info      = array();
+        $current   = null;
+        $infoLines = explode("\r\n", $data, -1);
+        foreach ($infoLines as $row) {
+            if ($row === '') {
+                continue;
+            }
+            if (preg_match('/^# (\w+)$/', $row, $matches)) {
+                $info[$matches[1]] = array();
+                $current = &$info[$matches[1]];
+                continue;
+            }
+            list($k, $v) = explode(':', $row);
+            if (!preg_match('/^db\d+$/', $k)) {
+                $current[$k] = $v;
+            }
+            else {
+                $db = array();
+                foreach (explode(',', $v) as $dbvar) {
+                    list($dbvk, $dbvv) = explode('=', $dbvar);
+                    $db[trim($dbvk)] = $dbvv;
+                }
+                $current[$k] = $db;
+            }
+        }
+        return $info;
+    }
+}

+ 6 - 0
lib/Predis/Profiles/ServerVersionNext.php

@@ -4,4 +4,10 @@ namespace Predis\Profiles;
 
 class ServerVersionNext extends ServerVersion22 {
     public function getVersion() { return 'DEV'; }
+    public function getSupportedCommands() {
+        return array_merge(parent::getSupportedCommands(), array(
+            /* remote server control commands */
+            'info'                  => '\Predis\Commands\InfoV24x',
+        ));
+    }
 }