ServerClient.php 1.6 KB

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