You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.0 KiB

  1. <?php
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage Redis
  7. * @since 2011-07-29
  8. */
  9. class RedisDebug
  10. {
  11. private $redis;
  12. public function __construct($redis)
  13. {
  14. if (!is_a($redis, 'Redis')) {
  15. throw new GeneralException();
  16. }
  17. $this->redis = $redis;
  18. }
  19. public function __call($name, $arguments)
  20. {
  21. $command = $this->r_implode(', ', $arguments);
  22. $profiler = Profiler::getInstance()->profilerCommand('Redis->' . $name, $command);
  23. $data = call_user_func_array(array($this->redis, $name), $arguments);
  24. $profiler->end();
  25. return $data;
  26. }
  27. protected function r_implode($glue, $pieces)
  28. {
  29. $retVal = array();
  30. foreach ($pieces as $r_pieces) {
  31. if (is_array($r_pieces)) {
  32. $retVal[] = '(' . $this->r_implode($glue, $r_pieces) . ')';
  33. } else {
  34. $retVal[] = $r_pieces;
  35. }
  36. }
  37. return implode($glue, $retVal);
  38. }
  39. }