Skip to content
This repository was archived by the owner on Oct 22, 2019. It is now read-only.

Commit 746e5b9

Browse files
authored
Merge pull request #53 from oraoto/redis-auth
Add Redis auth support
2 parents 0bef12d + ab6b1a9 commit 746e5b9

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Change the Redis options (the example shows the defaults):
6666
[
6767
'host' => '127.0.0.1',
6868
'port' => 6379,
69+
'password' => null,
6970
'timeout' => 0.1, // in seconds
7071
'read_timeout' => 10, // in seconds
7172
'persistent_connections' => false

src/Prometheus/Storage/Redis.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public function __construct(array $options = array())
3838
if (!isset(self::$defaultOptions['persistent_connections'])) {
3939
self::$defaultOptions['persistent_connections'] = false;
4040
}
41+
if (!isset(self::$defaultOptions['password'])) {
42+
self::$defaultOptions['password'] = null;
43+
}
4144

4245
$this->options = array_merge(self::$defaultOptions, $options);
4346
$this->redis = new \Redis();
@@ -91,6 +94,9 @@ private function openConnection()
9194
} else {
9295
@$this->redis->connect($this->options['host'], $this->options['port'], $this->options['timeout']);
9396
}
97+
if ($this->options['password']) {
98+
$this->redis->auth($this->options['password']);
99+
}
94100
$this->redis->setOption(\Redis::OPT_READ_TIMEOUT, $this->options['read_timeout']);
95101
} catch (\RedisException $e) {
96102
throw new StorageException("Can't connect to Redis server", 0, $e);

0 commit comments

Comments
 (0)