From 1bdba8d7f5ac75ab75ac58f69a1a603f200109d5 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sun, 24 Nov 2024 18:51:17 +0100 Subject: [PATCH] RedisCacheDriver.php: better support unix sockets --- inc/Data/Driver/RedisCacheDriver.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/inc/Data/Driver/RedisCacheDriver.php b/inc/Data/Driver/RedisCacheDriver.php index d1b36d57..a2354482 100644 --- a/inc/Data/Driver/RedisCacheDriver.php +++ b/inc/Data/Driver/RedisCacheDriver.php @@ -8,9 +8,21 @@ class RedisCacheDriver implements CacheDriver { private string $prefix; private \Redis $inner; - public function __construct(string $prefix, string $host, int $port, ?string $password, string $database) { + public function __construct(string $prefix, string $host, ?int $port, ?string $password, string $database) { $this->inner = new \Redis(); - $this->inner->connect($host, $port); + if (str_starts_with($host, 'unix:') || str_starts_with($host, ':')) { + $ret = \explode(':', $host); + if (count($ret) < 2) { + throw new \RuntimeException("Invalid unix socket path $host"); + } + // Unix socket. + $this->inner->connect($ret[1]); + } elseif ($port === null) { + $this->inner->connect($host); + } else { + // IP + port. + $this->inner->connect($host, $port); + } if ($password) { $this->inner->auth($password); }