From abe6bbb198ba83a306c45c9872c8f386dc323e91 Mon Sep 17 00:00:00 2001 From: Ragaga Date: Mon, 2 Dec 2024 16:27:42 +0400 Subject: [PATCH] Redis ACL AUTH two argument supporting. (#167) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Redis ACL AUTH two argument supporting. Signed-off-by: Gennadii Chernykh Signed-off-by: Gennadii Chernykh * Redis ACL AUTH two argument supporting. Signed-off-by: Gennadii Chernykh Signed-off-by: Gennadii Chernykh * Fix not using empty in Redis Adapter * Fix not using empty in RedisNg Adapter --------- Signed-off-by: Gennadii Chernykh Co-authored-by: Gennadii Chernykh Co-authored-by: Lukas Kämmerling --- src/Prometheus/Storage/Redis.php | 14 ++++++++++++-- src/Prometheus/Storage/RedisNg.php | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Prometheus/Storage/Redis.php b/src/Prometheus/Storage/Redis.php index 2763565c..0a4096eb 100644 --- a/src/Prometheus/Storage/Redis.php +++ b/src/Prometheus/Storage/Redis.php @@ -28,6 +28,7 @@ class Redis implements Adapter 'read_timeout' => '10', 'persistent_connections' => false, 'password' => null, + 'user' => null, ]; /** @@ -195,9 +196,18 @@ private function ensureOpenConnection(): void } $this->connectToServer(); + $authParams = []; - if ($this->options['password'] !== null) { - $this->redis->auth($this->options['password']); + if (isset($this->options['user'])) { + $authParams[] = $this->options['user']; + } + + if (isset($this->options['password'])) { + $authParams[] = $this->options['password']; + } + + if ($authParams !== []) { + $this->redis->auth($authParams); } if (isset($this->options['database'])) { diff --git a/src/Prometheus/Storage/RedisNg.php b/src/Prometheus/Storage/RedisNg.php index cb369ba7..865a07ed 100644 --- a/src/Prometheus/Storage/RedisNg.php +++ b/src/Prometheus/Storage/RedisNg.php @@ -28,6 +28,7 @@ class RedisNg implements Adapter 'read_timeout' => '10', 'persistent_connections' => false, 'password' => null, + 'user' => null, ]; /** @@ -195,9 +196,18 @@ private function ensureOpenConnection(): void } $this->connectToServer(); + $authParams = []; - if ($this->options['password'] !== null) { - $this->redis->auth($this->options['password']); + if (isset($this->options['user'])) { + $authParams[] = $this->options['user']; + } + + if (isset($this->options['password'])) { + $authParams[] = $this->options['password']; + } + + if ($authParams !== []) { + $this->redis->auth($authParams); } if (isset($this->options['database'])) {