forked from GithubBackups/vichan
RedisCacheDriver.php: better support unix sockets
This commit is contained in:
parent
f2b536efe3
commit
1bdba8d7f5
@ -8,9 +8,21 @@ class RedisCacheDriver implements CacheDriver {
|
|||||||
private string $prefix;
|
private string $prefix;
|
||||||
private \Redis $inner;
|
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 = 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) {
|
if ($password) {
|
||||||
$this->inner->auth($password);
|
$this->inner->auth($password);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user