Added RedisDebug for profiling redis parts
This commit is contained in:
45
redis/RedisDebug.php
Normal file
45
redis/RedisDebug.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright NetMonsters <team@netmonsters.ru>
|
||||||
|
* @link http://netmonsters.ru
|
||||||
|
* @package Majestic
|
||||||
|
* @subpackage Redis
|
||||||
|
* @since 2011-07-29
|
||||||
|
* @version SVN: $Id$
|
||||||
|
* @filesource $URL$
|
||||||
|
*/
|
||||||
|
|
||||||
|
class RedisDebug
|
||||||
|
{
|
||||||
|
private $redis;
|
||||||
|
|
||||||
|
public function __construct($redis)
|
||||||
|
{
|
||||||
|
if (!is_a($redis, 'Redis')) {
|
||||||
|
throw new MJException();
|
||||||
|
}
|
||||||
|
$this->redis = $redis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __call($name, $arguments)
|
||||||
|
{
|
||||||
|
$command = $name . '(' . $this->r_implode(', ', $arguments) . ')';
|
||||||
|
$profiler = Profiler::getInstance()->profilerQuery($command);
|
||||||
|
$data = call_user_func_array(array($this->redis, $name), $arguments);
|
||||||
|
$profiler->end();
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function r_implode($glue, $pieces)
|
||||||
|
{
|
||||||
|
$retVal = array();
|
||||||
|
foreach ($pieces as $r_pieces) {
|
||||||
|
if (is_array($r_pieces)) {
|
||||||
|
$retVal[] = '(' . $this->r_implode($glue, $r_pieces) . ')';
|
||||||
|
} else {
|
||||||
|
$retVal[] = $r_pieces;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return implode($glue, $retVal);
|
||||||
|
}
|
||||||
|
}
|
@ -46,6 +46,9 @@ class RedisManager
|
|||||||
* @var Redis
|
* @var Redis
|
||||||
*/
|
*/
|
||||||
$connection = new Redis();
|
$connection = new Redis();
|
||||||
|
if (defined('DEBUG') && DEBUG == true) {
|
||||||
|
$connection = new RedisDebug($connection);
|
||||||
|
}
|
||||||
if (!$connection->connect($host, $port)) {
|
if (!$connection->connect($host, $port)) {
|
||||||
throw new Exception('Failed to connect to Redis server at ' . $host . ':' . $port);
|
throw new Exception('Failed to connect to Redis server at ' . $host . ':' . $port);
|
||||||
}
|
}
|
||||||
@ -59,3 +62,38 @@ class RedisManager
|
|||||||
return self::$connections[$name];
|
return self::$connections[$name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class RedisDebug
|
||||||
|
{
|
||||||
|
private $redis;
|
||||||
|
|
||||||
|
public function __construct($redis)
|
||||||
|
{
|
||||||
|
if (!is_a($redis, 'Redis')) {
|
||||||
|
throw new MJException();
|
||||||
|
}
|
||||||
|
$this->redis = $redis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __call($name, $arguments)
|
||||||
|
{
|
||||||
|
$command = $name . '(' . $this->r_implode(', ', $arguments) . ')';
|
||||||
|
$profiler = Profiler::getInstance()->profilerQuery($command);
|
||||||
|
$data = call_user_func_array(array($this->redis, $name), $arguments);
|
||||||
|
$profiler->end();
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function r_implode($glue, $pieces)
|
||||||
|
{
|
||||||
|
$retVal = array();
|
||||||
|
foreach ($pieces as $r_pieces) {
|
||||||
|
if (is_array($r_pieces)) {
|
||||||
|
$retVal[] = '(' . $this->r_implode($glue, $r_pieces) . ')';
|
||||||
|
} else {
|
||||||
|
$retVal[] = $r_pieces;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return implode($glue, $retVal);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user