RedisProfilerStorage wrong db-number/index-number selected
This commit is contained in:
parent
52bd4ffa56
commit
c82c754b8e
@ -193,12 +193,13 @@ class RedisProfilerStorage implements ProfilerStorageInterface
|
|||||||
protected function getRedis()
|
protected function getRedis()
|
||||||
{
|
{
|
||||||
if (null === $this->redis) {
|
if (null === $this->redis) {
|
||||||
if (!preg_match('#^redis://(?(?=\[.*\])\[(.*)\]|(.*)):(.*)$#', $this->dsn, $matches)) {
|
if (!preg_match('#^redis://(?(?=\[.*\])\[(.*)\]|(.*)):(\d+)(/(\d+))?$#', $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));
|
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[/db-number]".', $this->dsn));
|
||||||
}
|
}
|
||||||
|
|
||||||
$host = $matches[1] ?: $matches[2];
|
$host = $matches[1] ?: $matches[2];
|
||||||
$port = $matches[3];
|
$port = $matches[3];
|
||||||
|
$dbnum = !empty($matches[5]) ? intval($matches[5]) : -1;
|
||||||
|
|
||||||
if (!extension_loaded('redis')) {
|
if (!extension_loaded('redis')) {
|
||||||
throw new \RuntimeException('RedisProfilerStorage requires that the redis extension is loaded.');
|
throw new \RuntimeException('RedisProfilerStorage requires that the redis extension is loaded.');
|
||||||
@ -206,6 +207,11 @@ class RedisProfilerStorage implements ProfilerStorageInterface
|
|||||||
|
|
||||||
$redis = new Redis;
|
$redis = new Redis;
|
||||||
$redis->connect($host, $port);
|
$redis->connect($host, $port);
|
||||||
|
|
||||||
|
// if a valid dbnumber is given select the redis index
|
||||||
|
if (-1 < $dbnum) {
|
||||||
|
$redis->select($dbnum);
|
||||||
|
}
|
||||||
|
|
||||||
$redis->setOption(self::REDIS_OPT_PREFIX, self::TOKEN_PREFIX);
|
$redis->setOption(self::REDIS_OPT_PREFIX, self::TOKEN_PREFIX);
|
||||||
|
|
||||||
|
@ -238,4 +238,17 @@ class RedisMock
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function select($dbnum)
|
||||||
|
{
|
||||||
|
if (!$this->connected) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 > $dbnum) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user