added setExpectedException and check empty($search)

This commit is contained in:
Vyacheslav Agafonov
2011-11-30 13:29:48 +04:00
parent be83874392
commit 69169590da
4 changed files with 36 additions and 19 deletions

View File

@ -25,6 +25,12 @@ class RedisDebug
{
$command = $this->r_implode(', ', $arguments);
$profiler = Profiler::getInstance()->profilerCommand('Redis->' . $name, $command);
$search = array_search($name, get_class_methods($this->redis));
if (empty($search)) {
throw new GeneralException('undefined method:'.$name);
}
$data = call_user_func_array(array($this->redis, $name), $arguments);
$profiler->end();
return $data;

View File

@ -31,11 +31,15 @@ class RedisManager
{
if (!isset(self::$connections[$name])) {
if (!$config) {
$config = Config::get('Redis')->$name;
if (gettype(Config::get('Redis')) != 'object') {
throw new GeneralException('config non-object');
}
$config = Config::get('Redis')->$name;
}
if (!is_array($config)) {
throw new Exception('Connection parameters must be an array');
throw new GeneralException('Connection parameters must be an array');
}
$host = isset($config['host']) ? $config['host'] : 'localhost';
@ -50,11 +54,11 @@ class RedisManager
$connection = new RedisDebug($connection);
}
if (!$connection->connect($host, $port)) {
throw new Exception('Failed to connect to Redis server at ' . $host . ':' . $port);
throw new GeneralException('Failed to connect to Redis server at ' . $host . ':' . $port);
}
if ($database) {
if (!$connection->select($database)) {
throw new Exception('Failed to select Redis database with index ' . $database);
throw new GeneralException('Failed to select Redis database with index ' . $database);
}
}
self::$connections[$name] = $connection;