ServerClient.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /*
  3. * This file is part of the Predis package.
  4. *
  5. * (c) Daniele Alessandri <suppakilla@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Predis\Commands;
  11. class ServerClient extends Command
  12. {
  13. public function getId()
  14. {
  15. return 'CLIENT';
  16. }
  17. protected function onPrefixKeys(Array $arguments, $prefix)
  18. {
  19. /* NOOP */
  20. }
  21. protected function canBeHashed()
  22. {
  23. return false;
  24. }
  25. public function parseResponse($data)
  26. {
  27. $args = array_change_key_case($this->getArguments(), CASE_UPPER);
  28. switch (strtoupper($args[0])) {
  29. case 'LIST':
  30. return $this->parseClientList($data);
  31. case 'KILL':
  32. default:
  33. return $data;
  34. }
  35. }
  36. protected function parseClientList($data)
  37. {
  38. $clients = array();
  39. foreach (explode("\n", $data, -1) as $clientData) {
  40. $client = array();
  41. foreach (explode(' ', $clientData) as $kv) {
  42. @list($k, $v) = explode('=', $kv);
  43. $client[$k] = $v;
  44. }
  45. $clients[] = $client;
  46. }
  47. return $clients;
  48. }
  49. }