fix: redis resource reads _APP_CONNECTIONS_CACHE with _APP_REDIS_* fallback

The dedicated \Redis DI resource (used by timelimit and the new Lock
class) was reading _APP_REDIS_HOST/PORT/PASS exclusively. Cloud
deployments configure cache via _APP_CONNECTIONS_CACHE URI form
(e.g. cache=redis://dragonfly:6379) and don't pass the legacy
_APP_REDIS_* vars to the appwrite container locally, so timelimit and
Lock both fail to connect outside production where Helm separately
injects the legacy vars.

Now prefers _APP_CONNECTIONS_CACHE when set (matching the cache pool
backend), falls back to _APP_REDIS_* for CE-style configs. No new env
vars introduced; both timelimit and Lock work in CE, cloud-local, and
cloud-production without compose changes.
This commit is contained in:
Prem Palanisamy committed 2026-04-29 10:16:17 +01:00
1 parent 18a67e00d3
commit b2b9ac5b4d
1 file changed
+17 -4
+17 -4
View File
@@ -193,12 +193,25 @@ $container->set('cache', function (Group $pools, Telemetry $telemetry) {
}, ['pools', 'telemetry']);
$container->set('redis', function () {
$host = System::getEnv('_APP_REDIS_HOST', 'localhost');
$port = System::getEnv('_APP_REDIS_PORT', 6379);
$pass = System::getEnv('_APP_REDIS_PASS', '');
// Prefer _APP_CONNECTIONS_CACHE (URI form, used by cloud and the pool layer)
// so that direct \Redis consumers (timelimit, Lock) match the same backend
// as the cache pool. Fall back to _APP_REDIS_* for CE-style configs.
$cacheDsn = System::getEnv('_APP_CONNECTIONS_CACHE', '');
if ($cacheDsn !== '') {
$first = explode(';', $cacheDsn)[0];
$uri = explode('=', $first, 2)[1] ?? $first;
$dsn = new DSN($uri);
$host = $dsn->getHost();
$port = (int) ($dsn->getPort() ?: 6379);
$pass = $dsn->getPassword() ?? '';
} else {
$host = System::getEnv('_APP_REDIS_HOST', 'localhost');
$port = (int) System::getEnv('_APP_REDIS_PORT', 6379);
$pass = System::getEnv('_APP_REDIS_PASS', '');
}
$redis = new \Redis();
@$redis->pconnect($host, (int) $port);
@$redis->pconnect($host, $port);
if ($pass) {
$redis->auth($pass);
}