PubSubPubsub.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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/pubsub
  13. * @author Daniele Alessandri <suppakilla@gmail.com>
  14. */
  15. class PubSubPubsub extends Command
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function getId()
  21. {
  22. return 'PUBSUB';
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function parseResponse($data)
  28. {
  29. switch (strtolower($this->getArgument(0))) {
  30. case 'numsub':
  31. return self::processNumsub($data);
  32. default:
  33. return $data;
  34. }
  35. }
  36. /**
  37. * Returns the processed response to PUBSUB NUMSUB.
  38. *
  39. * @param array $channels List of channels
  40. * @return array
  41. */
  42. protected static function processNumsub(array $channels)
  43. {
  44. $processed = array();
  45. $count = count($channels);
  46. for ($i = 0; $i < $count; $i++) {
  47. $processed[$channels[$i]] = $channels[++$i];
  48. }
  49. return $processed;
  50. }
  51. }