merged branch stephpy/redis_profiler (PR #6680)
This PR was merged into the master branch.
Commits
-------
d027f45
[PROFILER][REDIS] Support database, auth on redis connection
Discussion
----------
[PROFILER][REDIS] Support database, auth on redis connection
Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Allow database and password on dsn:
```yml
framework:
profiler:
dsn: redis://127.0.0.1:6379
dsn: redis://127.0.0.1:6379/3
dsn: redis://user:password@127.0.0.1:6379/3
```
Since redis uses only password for authentification, user will not be used ...
---------------------------------------------------------------------------
by shouze at 2013-01-10T16:58:02Z
👍 db selection is a must have
This commit is contained in:
commit
9f25451134
@ -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