1
0
Fork 0

Add support for Unix domain sockets to Redis in setting defaults

- Add support for port = 0 in Redis driver
This commit is contained in:
Hypolite Petovan 2023-08-02 20:42:44 +02:00
commit 762bd7a847
2 changed files with 16 additions and 11 deletions

View file

@ -57,22 +57,27 @@ class RedisCache extends AbstractCache implements ICanCacheInMemory
$redis_host = $config->get('system', 'redis_host');
$redis_port = $config->get('system', 'redis_port');
$redis_pw = $config->get('system', 'redis_password');
$redis_db = $config->get('system', 'redis_db', 0);
$redis_db = (int)$config->get('system', 'redis_db', 0);
try {
if (!empty($redis_port) && !@$this->redis->connect($redis_host, $redis_port)) {
throw new CachePersistenceException('Expected Redis server at ' . $redis_host . ':' . $redis_port . ' isn\'t available');
} else if (!@$this->redis->connect($redis_host)) {
throw new CachePersistenceException('Expected Redis server at ' . $redis_host . ' isn\'t available');
if (is_numeric($redis_port) && $redis_port > -1) {
$connection_string = $redis_host . ':' . $redis_port;
if (!@$this->redis->connect($redis_host, $redis_port)) {
throw new CachePersistenceException('Expected Redis server at ' . $connection_string . " isn't available");
}
} else {
$connection_string = $redis_host;
if (!@$this->redis->connect($redis_host)) {
throw new CachePersistenceException('Expected Redis server at ' . $connection_string . ' isn\'t available');
}
}
if (!empty($redis_pw) && !$this->redis->auth($redis_pw)) {
throw new CachePersistenceException('Cannot authenticate redis server at ' . $redis_host . ':' . $redis_port);
throw new CachePersistenceException('Cannot authenticate redis server at ' . $connection_string);
}
if ($redis_db !== 0 && !$this->redis->select($redis_db)) {
throw new CachePersistenceException('Cannot switch to redis db ' . $redis_db . ' at ' . $redis_host . ':' . $redis_port);
throw new CachePersistenceException('Cannot switch to redis db ' . $redis_db . ' at ' . $connection_string);
}
} catch (\RedisException $exception) {
throw new CachePersistenceException('Redis connection fails unexpectedly', $exception);