Sfoglia il codice sorgente

New command: CLIENT (Redis v2.4-dev).

Daniele Alessandri 14 anni fa
parent
commit
dd3faa3d53
3 ha cambiato i file con 40 aggiunte e 1 eliminazioni
  1. 2 1
      TODO
  2. 37 0
      lib/Predis/Commands/Client.php
  3. 1 0
      lib/Predis/Profiles/ServerVersionNext.php

+ 2 - 1
TODO

@@ -15,4 +15,5 @@
   as it does not cover all of its features.
 
 * Missing tests for commands:
-    PUBLISH, SUBSCRIBE, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, DEBUG, OBJECT
+    PUBLISH, SUBSCRIBE, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, DEBUG, OBJECT,
+    CLIENT

+ 37 - 0
lib/Predis/Commands/Client.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace Predis\Commands;
+
+class Client extends Command {
+    public function getId() {
+        return 'CLIENT';
+    }
+
+    protected function canBeHashed() {
+        return false;
+    }
+
+    public function parseResponse($data) {
+        $args = array_change_key_case($this->getArguments(), CASE_UPPER);
+        switch (strtoupper($args[0])) {
+            case 'LIST':
+                return $this->parseClientList($data);
+            case 'KILL':
+            default:
+                return $data;
+        }
+    }
+
+    protected function parseClientList($data) {
+        $clients = array();
+        foreach (explode("\n", $data, -1) as $clientData) {
+            $client = array();
+            foreach (explode(' ', $clientData) as $kv) {
+                @list($k, $v) = explode('=', $kv);
+                $client[$k] = $v;
+            }
+            $clients[] = $client;
+        }
+        return $clients;
+    }
+}

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

@@ -19,6 +19,7 @@ class ServerVersionNext extends ServerVersion22 {
 
             /* remote server control commands */
             'info'                  => '\Predis\Commands\InfoV24x',
+            'client'                => '\Predis\Commands\Client',
         ));
     }
 }