Skip to content

Commit d33cabd

Browse files
committed
Refactor Redis connection for TLS and unix sockets
Signed-off-by: J0WI <J0WI@users.noreply.github.com>
1 parent 5b2be27 commit d33cabd

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

.config/redis.config.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
'memcache.distributed' => '\OC\Memcache\Redis',
55
'memcache.locking' => '\OC\Memcache\Redis',
66
'redis' => array(
7-
'host' => getenv('REDIS_HOST'),
7+
'host' => (getenv('REDIS_HOST')[0] === '/' ? 'unix' : (getenv('REDIS_PROTOCOL') ?: 'tcp')) . "://" . getenv('REDIS_HOST'),
88
'password' => getenv('REDIS_HOST_PASSWORD_FILE') ? trim(file_get_contents(getenv('REDIS_HOST_PASSWORD_FILE'))) : (string) getenv('REDIS_HOST_PASSWORD'),
99
),
1010
);
1111

12-
if (getenv('REDIS_HOST_PORT') !== false) {
12+
if (getenv('REDIS_HOST')[0] === '/') {
13+
$CONFIG['redis']['port'] = 0;
14+
} elseif (getenv('REDIS_HOST_PORT') !== false) {
1315
$CONFIG['redis']['port'] = (int) getenv('REDIS_HOST_PORT');
14-
} elseif (getenv('REDIS_HOST')[0] != '/') {
16+
} else {
1517
$CONFIG['redis']['port'] = 6379;
1618
}
1719

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,11 @@ You might want to make sure the htaccess is up to date after each container upda
285285

286286
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.
287287

288-
- `REDIS_HOST` (not set by default) Name of Redis container
288+
- `REDIS_HOST` (not set by default) Name of Redis container.
289289
- `REDIS_HOST_PORT` (default: `6379`) Optional port for Redis, only use for external Redis servers that run on non-standard ports.
290290
- `REDIS_HOST_USER` (not set by default) Optional username for Redis, only use for external Redis servers that require a user.
291-
- `REDIS_HOST_PASSWORD` (not set by default) Redis password
291+
- `REDIS_HOST_PASSWORD` (not set by default) Redis password.
292+
- `REDIS_PROTOCOL` (default: `tcp`) Set to `tls` to use TLS when connecting to Redis server.
292293

293294
Check the [Nextcloud documentation](https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/caching_configuration.html) for more information.
294295

docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ configure_redis_session() {
108108
redis_save_path="unix://${REDIS_HOST}"
109109
;;
110110
*)
111-
redis_save_path="tcp://${REDIS_HOST}:${REDIS_HOST_PORT:=6379}"
111+
redis_save_path="${REDIS_PROTOCOL:=tcp}://${REDIS_HOST}:${REDIS_HOST_PORT:=6379}"
112112
;;
113113
esac
114114

0 commit comments

Comments
 (0)