ServerSlowlog.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 canBeHashed()
  29. {
  30. return false;
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function parseResponse($data)
  36. {
  37. if (($iterable = $data instanceof \Iterator) || is_array($data)) {
  38. // NOTE: we consume iterable multibulk replies inplace since it is not
  39. // possible to do anything fancy on sub-elements.
  40. $log = array();
  41. foreach ($data as $index => $entry) {
  42. if ($iterable) {
  43. $entry = iterator_to_array($entry);
  44. }
  45. $log[$index] = array(
  46. 'id' => $entry[0],
  47. 'timestamp' => $entry[1],
  48. 'duration' => $entry[2],
  49. 'command' => $iterable ? iterator_to_array($entry[3]) : $entry[3],
  50. );
  51. }
  52. if ($iterable === true) {
  53. unset($data);
  54. }
  55. return $log;
  56. }
  57. return $data;
  58. }
  59. }