From c27fae800e99de5e04eda7960f22455588244a3c Mon Sep 17 00:00:00 2001 From: Rafael Dohms Date: Sun, 14 Oct 2018 20:29:39 +0200 Subject: [PATCH] Support database selection In order to allow the use of different databases in Redis, the connection now supports switching to a new database. One important factor to understand here is that if you are using `pconnect` and you do a `select` operation, you may be changing the same connection the rest of your code is using. --- src/Prometheus/Storage/Redis.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Prometheus/Storage/Redis.php b/src/Prometheus/Storage/Redis.php index f38391b..091577c 100644 --- a/src/Prometheus/Storage/Redis.php +++ b/src/Prometheus/Storage/Redis.php @@ -97,7 +97,12 @@ private function openConnection() if ($this->options['password']) { $this->redis->auth($this->options['password']); } + if (isset($this->options['database'])) { + $this->redis->select($this->options['database']); + } + $this->redis->setOption(\Redis::OPT_READ_TIMEOUT, $this->options['read_timeout']); + } catch (\RedisException $e) { throw new StorageException("Can't connect to Redis server", 0, $e); }