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.

50 lines
1.3 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. * @version SVN: $Id$
  9. * @filesource $URL$
  10. */
  11. class RedisDebug
  12. {
  13. private $redis;
  14. public function __construct($redis)
  15. {
  16. if (!is_a($redis, 'Redis')) {
  17. throw new GeneralException();
  18. }
  19. $this->redis = $redis;
  20. }
  21. public function __call($name, $arguments)
  22. {
  23. $command = $this->r_implode(', ', $arguments);
  24. $profiler = Profiler::getInstance()->profilerCommand('Redis->' . $name, $command);
  25. $search = array_search($name, get_class_methods($this->redis));
  26. if (empty($search)) {
  27. throw new GeneralException('undefined method:'.$name);
  28. }
  29. $data = call_user_func_array(array($this->redis, $name), $arguments);
  30. $profiler->end();
  31. return $data;
  32. }
  33. protected function r_implode($glue, $pieces)
  34. {
  35. $retVal = array();
  36. foreach ($pieces as $r_pieces) {
  37. if (is_array($r_pieces)) {
  38. $retVal[] = '(' . $this->r_implode($glue, $r_pieces) . ')';
  39. } else {
  40. $retVal[] = $r_pieces;
  41. }
  42. }
  43. return implode($glue, $retVal);
  44. }
  45. }