ServerClient.php 1.7 KB

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