RedisCacheDriver.php: use CacheDriverTrait

This commit is contained in:
Zankaria 2025-05-29 23:54:53 +02:00
parent 84a22a788e
commit b9a29927f3

View file

@ -5,18 +5,17 @@ defined('TINYBOARD') or exit;
class RedisCacheDriver implements CacheDriver { class RedisCacheDriver implements CacheDriver {
use CacheDriverTrait;
private string $prefix; private string $prefix;
private \Redis $inner; private \Redis $inner;
public function __construct(string $prefix, string $host, ?int $port, ?string $password, int $database) { public function __construct(string $prefix, string $host, ?int $port, ?string $password, int $database) {
$this->inner = new \Redis(); $this->inner = new \Redis();
if (str_starts_with($host, 'unix:') || str_starts_with($host, ':')) { $maybe_unix = self::asUnixSocketPath($host);
$ret = \explode(':', $host);
if (count($ret) < 2) { if ($maybe_unix !== null) {
throw new \RuntimeException("Invalid unix socket path $host"); $this->inner->connect($maybe_unix);
}
// Unix socket.
$this->inner->connect($ret[1]);
} elseif ($port === null) { } elseif ($port === null) {
$this->inner->connect($host); $this->inner->connect($host);
} else { } else {