ServerClient.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. default:
  35. return $data;
  36. }
  37. }
  38. /**
  39. * Parses the reply buffer and returns the list of clients returned by
  40. * the CLIENT LIST command.
  41. *
  42. * @param string $data Reply buffer
  43. * @return array
  44. */
  45. protected function parseClientList($data)
  46. {
  47. $clients = array();
  48. foreach (explode("\n", $data, -1) as $clientData) {
  49. $client = array();
  50. foreach (explode(' ', $clientData) as $kv) {
  51. @list($k, $v) = explode('=', $kv);
  52. $client[$k] = $v;
  53. }
  54. $clients[] = $client;
  55. }
  56. return $clients;
  57. }
  58. }