ServerClient.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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\Command;
  11. /**
  12. * @link http://redis.io/commands/client
  13. * @author Daniele Alessandri <suppakilla@gmail.com>
  14. */
  15. class ServerClient extends AbstractCommand
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function getId()
  21. {
  22. return 'CLIENT';
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function parseResponse($data)
  28. {
  29. $args = array_change_key_case($this->getArguments(), CASE_UPPER);
  30. switch (strtoupper($args[0])) {
  31. case 'LIST':
  32. return $this->parseClientList($data);
  33. case 'KILL':
  34. case 'GETNAME':
  35. case 'SETNAME':
  36. default:
  37. return $data;
  38. }
  39. }
  40. /**
  41. * Parses the reply buffer and returns the list of clients returned by
  42. * the CLIENT LIST command.
  43. *
  44. * @param string $data Reply buffer
  45. * @return array
  46. */
  47. protected function parseClientList($data)
  48. {
  49. $clients = array();
  50. foreach (explode("\n", $data, -1) as $clientData) {
  51. $client = array();
  52. foreach (explode(' ', $clientData) as $kv) {
  53. @list($k, $v) = explode('=', $kv);
  54. $client[$k] = $v;
  55. }
  56. $clients[] = $client;
  57. }
  58. return $clients;
  59. }
  60. }