ServerSlowlog.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. use Predis\Iterators\MultiBulkResponse;
  12. /**
  13. * @link http://redis.io/commands/slowlog
  14. * @author Daniele Alessandri <suppakilla@gmail.com>
  15. */
  16. class ServerSlowlog extends Command
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function getId()
  22. {
  23. return 'SLOWLOG';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. protected function onPrefixKeys(Array $arguments, $prefix)
  29. {
  30. /* NOOP */
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. protected function canBeHashed()
  36. {
  37. return false;
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function parseResponse($data)
  43. {
  44. if (($iterable = $data instanceof \Iterator) || is_array($data)) {
  45. // NOTE: we consume iterable multibulk replies inplace since it is not
  46. // possible to do anything fancy on sub-elements.
  47. $log = array();
  48. foreach ($data as $index => $entry) {
  49. if ($iterable) {
  50. $entry = iterator_to_array($entry);
  51. }
  52. $log[$index] = array(
  53. 'id' => $entry[0],
  54. 'timestamp' => $entry[1],
  55. 'duration' => $entry[2],
  56. 'command' => $iterable ? iterator_to_array($entry[3]) : $entry[3],
  57. );
  58. }
  59. if ($iterable === true) {
  60. unset($data);
  61. }
  62. return $log;
  63. }
  64. return $data;
  65. }
  66. }