Skip to content

Commit b4ddb71

Browse files
committed
support db select option
(pull request Jimdo#96 from original repo)
1 parent 01c8937 commit b4ddb71

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/Prometheus/Storage/Redis.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public function __construct(array $options = array())
4141
if (!isset(self::$defaultOptions['password'])) {
4242
self::$defaultOptions['password'] = null;
4343
}
44+
if (!isset(self::$defaultOptions['db'])) {
45+
self::$defaultOptions['db'] = false;
46+
}
4447

4548
$this->options = array_merge(self::$defaultOptions, $options);
4649
$this->redis = new \Redis();
@@ -97,6 +100,9 @@ private function openConnection()
97100
if ($this->options['password']) {
98101
$this->redis->auth($this->options['password']);
99102
}
103+
if($this->options['db']){
104+
$this->redis->select($this->options['db']);
105+
}
100106
$this->redis->setOption(\Redis::OPT_READ_TIMEOUT, $this->options['read_timeout']);
101107
} catch (\RedisException $e) {
102108
throw new StorageException("Can't connect to Redis server", 0, $e);

0 commit comments

Comments
 (0)