From 580999b9c794aa9eae58bde3057eb6db00f28466 Mon Sep 17 00:00:00 2001 From: J0WI Date: Thu, 1 Oct 2026 23:52:49 +0200 Subject: [PATCH] Refactor Redis connection for TLS and unix sockets (#2557) Signed-off-by: J0WI --- .config/redis.config.php | 8 +++++--- README.md | 5 +++-- docker-entrypoint.sh | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.config/redis.config.php b/.config/redis.config.php index 2069812f..415339d3 100644 --- a/.config/redis.config.php +++ b/.config/redis.config.php @@ -4,14 +4,16 @@ if (getenv('REDIS_HOST')) { 'memcache.distributed' => '\OC\Memcache\Redis', 'memcache.locking' => '\OC\Memcache\Redis', 'redis' => array( - 'host' => getenv('REDIS_HOST'), + 'host' => (getenv('REDIS_HOST')[0] === '/' ? 'unix' : (getenv('REDIS_PROTOCOL') ?: 'tcp')) . "://" . getenv('REDIS_HOST'), 'password' => getenv('REDIS_HOST_PASSWORD_FILE') ? trim(file_get_contents(getenv('REDIS_HOST_PASSWORD_FILE'))) : (string) getenv('REDIS_HOST_PASSWORD'), ), ); - if (getenv('REDIS_HOST_PORT') !== false) { + if (getenv('REDIS_HOST')[0] === '/') { + $CONFIG['redis']['port'] = 0; + } elseif (getenv('REDIS_HOST_PORT') !== false) { $CONFIG['redis']['port'] = (int) getenv('REDIS_HOST_PORT'); - } elseif (getenv('REDIS_HOST')[0] != '/') { + } else { $CONFIG['redis']['port'] = 6379; } diff --git a/README.md b/README.md index f3fedb5d..47cfd625 100644 --- a/README.md +++ b/README.md @@ -285,10 +285,11 @@ You might want to make sure the htaccess is up to date after each container upda To use Redis for memory caching as well as PHP session storage, specify the following values and also add a [Redis](https://hub.docker.com/_/redis/) container to your stack. See the [examples](https://github.com/nextcloud/docker/tree/master/.examples) for further instructions. -- `REDIS_HOST` (not set by default) Name of Redis container +- `REDIS_HOST` (not set by default) Name of Redis container. - `REDIS_HOST_PORT` (default: `6379`) Optional port for Redis, only use for external Redis servers that run on non-standard ports. - `REDIS_HOST_USER` (not set by default) Optional username for Redis, only use for external Redis servers that require a user. -- `REDIS_HOST_PASSWORD` (not set by default) Redis password +- `REDIS_HOST_PASSWORD` (not set by default) Redis password. +- `REDIS_PROTOCOL` (default: `tcp`) Set to `tls` to use TLS when connecting to Redis server. Check the [Nextcloud documentation](https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/caching_configuration.html) for more information. diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index d8d21c1f..ccbd4654 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -107,7 +107,7 @@ configure_redis_session() { redis_save_path="unix://${REDIS_HOST}" ;; *) - redis_save_path="tcp://${REDIS_HOST}:${REDIS_HOST_PORT:=6379}" + redis_save_path="${REDIS_PROTOCOL:=tcp}://${REDIS_HOST}:${REDIS_HOST_PORT:=6379}" ;; esac