fix: disable fof/redis settings cache to avoid circular boot dependency (#7)
Some checks failed
GB Redis Setup PHP / run (push) Has been cancelled
GB Redis Setup JS / run (push) Has been cancelled

fof/redis >=1.1 introduces a `settings` service that replaces
SettingsRepositoryInterface with a Redis-backed caching layer.
Enabling it here creates a circular dependency: this extension reads
settings to decide which Redis services to enable, but with the
settings cache active those reads require Redis to already be wired.

Always disable the `settings` service when delegating to fof/redis.
Also fixes a cast-precedence bug in the database env var helpers
where `(int) getenv(...) ? getenv(...) : N` applied the cast to the
ternary condition rather than the result, causing REDIS_DATABASE_*=0
to return the default instead of 0.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
IanM
2026-03-03 17:29:17 +00:00
committed by GitHub
parent 4f261dbee4
commit 77ad7422e7
3 changed files with 23 additions and 9 deletions

View File

@@ -31,7 +31,7 @@ class EnableRedis implements ExtenderInterface
/** @var Redis $redis */
$redis = (new Redis($config))
->disable($this->getDisabledServices());
->disable(['settings', ...$this->getDisabledServices()]);
$redis->extend($container, $extension);
}
@@ -88,36 +88,42 @@ class EnableRedis implements ExtenderInterface
public static function getHost(): string
{
return getenv('REDIS_HOST') ? getenv('REDIS_HOST') : '127.0.0.1';
return getenv('REDIS_HOST') ?: '127.0.0.1';
}
public static function getPassword(): ?string
{
return getenv('REDIS_PASSWORD') ? getenv('REDIS_PASSWORD') : null;
return getenv('REDIS_PASSWORD') ?: null;
}
public static function getPort(): string
{
return getenv('REDIS_PORT') ? getenv('REDIS_PORT') : '6379';
return getenv('REDIS_PORT') ?: '6379';
}
public static function getCacheDatabase(): int
{
return (int) getenv('REDIS_DATABASE_CACHE') ? getenv('REDIS_DATABASE_CACHE') : 1;
$val = getenv('REDIS_DATABASE_CACHE');
return $val !== false ? (int) $val : 1;
}
public static function getQueueDatabase(): int
{
return (int) getenv('REDIS_DATABASE_QUEUE') ? getenv('REDIS_DATABASE_QUEUE') : 2;
$val = getenv('REDIS_DATABASE_QUEUE');
return $val !== false ? (int) $val : 2;
}
public static function getSessionDatabase(): int
{
return (int) getenv('REDIS_DATABASE_SESSION') ? getenv('REDIS_DATABASE_SESSION') : 3;
$val = getenv('REDIS_DATABASE_SESSION');
return $val !== false ? (int) $val : 3;
}
public static function getPrefix(): string
{
return getenv('REDIS_PREFIX') ? getenv('REDIS_PREFIX') : 'flarum_';
return getenv('REDIS_PREFIX') ?: 'flarum_';
}
}