[PROFILER][REDIS] Support database, auth on redis connection
This commit is contained in:
parent
7ab8e48373
commit
d027f45833
@ -17,6 +17,7 @@ use Redis;
|
||||
* RedisProfilerStorage stores profiling information in Redis.
|
||||
*
|
||||
* @author Andrej Hudec <pulzarraider@gmail.com>
|
||||
* @author Stephane PY <py.stephane1@gmail.com>
|
||||
*/
|
||||
class RedisProfilerStorage implements ProfilerStorageInterface
|
||||
{
|
||||
@ -213,19 +214,26 @@ class RedisProfilerStorage implements ProfilerStorageInterface
|
||||
protected function getRedis()
|
||||
{
|
||||
if (null === $this->redis) {
|
||||
if (!preg_match('#^redis://(?(?=\[.*\])\[(.*)\]|(.*)):(.*)$#', $this->dsn, $matches)) {
|
||||
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Redis with an invalid dsn "%s". The expected format is "redis://[host]:port".', $this->dsn));
|
||||
}
|
||||
$data = parse_url($this->dsn);
|
||||
|
||||
$host = $matches[1] ?: $matches[2];
|
||||
$port = $matches[3];
|
||||
if (false === $data || !isset($data['scheme']) || $data['scheme'] !== 'redis' || !isset($data['host']) || !isset($data['port'])) {
|
||||
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Redis with an invalid dsn "%s". The minimal expected format is "redis://[host]:port".', $this->dsn));
|
||||
}
|
||||
|
||||
if (!extension_loaded('redis')) {
|
||||
throw new \RuntimeException('RedisProfilerStorage requires that the redis extension is loaded.');
|
||||
}
|
||||
|
||||
$redis = new Redis;
|
||||
$redis->connect($host, $port);
|
||||
$redis->connect($data['host'], $data['port']);
|
||||
|
||||
if (isset($data['path'])) {
|
||||
$redis->select(substr($data['path'], 1));
|
||||
}
|
||||
|
||||
if (isset($data['pass'])) {
|
||||
$redis->auth($data['pass']);
|
||||
}
|
||||
|
||||
$redis->setOption(self::REDIS_OPT_PREFIX, self::TOKEN_PREFIX);
|
||||
|
||||
|
Reference in New Issue
Block a user