ServerClient.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 onPrefixKeys(Array $arguments, $prefix)
  28. {
  29. /* NOOP */
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. protected function canBeHashed()
  35. {
  36. return false;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function parseResponse($data)
  42. {
  43. $args = array_change_key_case($this->getArguments(), CASE_UPPER);
  44. switch (strtoupper($args[0])) {
  45. case 'LIST':
  46. return $this->parseClientList($data);
  47. case 'KILL':
  48. default:
  49. return $data;
  50. }
  51. }
  52. /**
  53. * Parses the reply buffer and returns the list of clients returned by
  54. * the CLIENT LIST command.
  55. *
  56. * @param string $data Reply buffer
  57. * @return array
  58. */
  59. protected function parseClientList($data)
  60. {
  61. $clients = array();
  62. foreach (explode("\n", $data, -1) as $clientData) {
  63. $client = array();
  64. foreach (explode(' ', $clientData) as $kv) {
  65. @list($k, $v) = explode('=', $kv);
  66. $client[$k] = $v;
  67. }
  68. $clients[] = $client;
  69. }
  70. return $clients;
  71. }
  72. }