From b2b9ac5b4d6046240eba55c153b4535db1cba7de Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Wed, 29 Apr 2026 10:16:17 +0100 Subject: [PATCH] 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. --- app/init/resources.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/init/resources.php b/app/init/resources.php index 29506bfc9c..aa82c19b75 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -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); }