ServerSlowlog.php 1.5 KB

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