From d027f458338a1b75cf75abce423127f46fdbddae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20PY?= Date: Thu, 10 Jan 2013 17:46:24 +0100 Subject: [PATCH] [PROFILER][REDIS] Support database, auth on redis connection --- .../Profiler/RedisProfilerStorage.php | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Profiler/RedisProfilerStorage.php b/src/Symfony/Component/HttpKernel/Profiler/RedisProfilerStorage.php index 5c143129c0..047b8ac62e 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/RedisProfilerStorage.php +++ b/src/Symfony/Component/HttpKernel/Profiler/RedisProfilerStorage.php @@ -17,6 +17,7 @@ use Redis; * RedisProfilerStorage stores profiling information in Redis. * * @author Andrej Hudec + * @author Stephane PY */ 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);