1 Commits

Author SHA1 Message Date
Simon Hiller
078fd9a746 feat: implement settings config 2026-02-25 12:45:04 +01:00
3 changed files with 16 additions and 23 deletions

View File

@@ -38,14 +38,6 @@ composer update glowingblue/redis-setup
php flarum cache:clear php flarum cache:clear
``` ```
## Compatibility with `fof/redis`
This extension depends on [`fof/redis`](https://github.com/FriendsOfFlarum/redis) and deliberately disables the **`settings` service** that `fof/redis` ≥ 1.1 provides.
`fof/redis`'s settings service replaces Flarum's `SettingsRepositoryInterface` with a Redis-backed caching layer. However, this extension reads settings (e.g. which Redis services to enable) during its own boot sequence — *before* Redis is fully wired into the container. Enabling the Redis settings cache here would create a circular dependency: configuring Redis requires reading settings, but reading settings requires Redis.
The `settings` service from `fof/redis` is therefore always disabled in this extension's extender. If you want Redis-backed settings caching, configure `fof/redis` directly in your project's root `extend.php` instead of using this extension.
## 🔗 Links ## 🔗 Links
- [Flarum Discuss post](https://discuss.flarum.org/d/27455) - [Flarum Discuss post](https://discuss.flarum.org/d/27455)

View File

@@ -20,7 +20,7 @@
"require": { "require": {
"php": "^8.1", "php": "^8.1",
"flarum/core": "^1.8.5", "flarum/core": "^1.8.5",
"fof/redis": "^1.1.4" "fof/redis": "^1.0"
}, },
"authors": [ "authors": [
{ {

View File

@@ -24,6 +24,7 @@ class EnableRedis implements ExtenderInterface
const CACHE_KEY = 'connections.cache'; const CACHE_KEY = 'connections.cache';
const QUEUE_KEY = 'connections.queue'; const QUEUE_KEY = 'connections.queue';
const SESSION_KEY = 'connections.session'; const SESSION_KEY = 'connections.session';
const SETTINGS_KEY = 'connections.settings';
public function extend(Container $container, Extension $extension = null) public function extend(Container $container, Extension $extension = null)
{ {
@@ -31,7 +32,7 @@ class EnableRedis implements ExtenderInterface
/** @var Redis $redis */ /** @var Redis $redis */
$redis = (new Redis($config)) $redis = (new Redis($config))
->disable(['settings', ...$this->getDisabledServices()]); ->disable($this->getDisabledServices());
$redis->extend($container, $extension); $redis->extend($container, $extension);
} }
@@ -45,6 +46,7 @@ class EnableRedis implements ExtenderInterface
if (!(bool) $settings->get('glowingblue-redis.enableCache', false)) { if (!(bool) $settings->get('glowingblue-redis.enableCache', false)) {
$disabled[] = 'cache'; $disabled[] = 'cache';
$disabled[] = 'settings';
} }
if (!(bool) $settings->get('glowingblue-redis.enableQueue', false)) { if (!(bool) $settings->get('glowingblue-redis.enableQueue', false)) {
@@ -79,51 +81,50 @@ class EnableRedis implements ExtenderInterface
'database' => static::getSessionDatabase(), 'database' => static::getSessionDatabase(),
]; ];
$settings = $base + [
'database' => static::getSessionDatabase(),
];
$config = Arr::add($config, self::CACHE_KEY, $cache); $config = Arr::add($config, self::CACHE_KEY, $cache);
$config = Arr::add($config, self::QUEUE_KEY, $queue); $config = Arr::add($config, self::QUEUE_KEY, $queue);
$config = Arr::add($config, self::SESSION_KEY, $session); $config = Arr::add($config, self::SESSION_KEY, $session);
$config = Arr::add($config, self::SETTINGS_KEY, $settings);
return $config; return $config;
} }
public static function getHost(): string public static function getHost(): string
{ {
return getenv('REDIS_HOST') ?: '127.0.0.1'; return getenv('REDIS_HOST') ? getenv('REDIS_HOST') : '127.0.0.1';
} }
public static function getPassword(): ?string public static function getPassword(): ?string
{ {
return getenv('REDIS_PASSWORD') ?: null; return getenv('REDIS_PASSWORD') ? getenv('REDIS_PASSWORD') : null;
} }
public static function getPort(): string public static function getPort(): string
{ {
return getenv('REDIS_PORT') ?: '6379'; return getenv('REDIS_PORT') ? getenv('REDIS_PORT') : '6379';
} }
public static function getCacheDatabase(): int public static function getCacheDatabase(): int
{ {
$val = getenv('REDIS_DATABASE_CACHE'); return (int) getenv('REDIS_DATABASE_CACHE') ? getenv('REDIS_DATABASE_CACHE') : 1;
return $val !== false ? (int) $val : 1;
} }
public static function getQueueDatabase(): int public static function getQueueDatabase(): int
{ {
$val = getenv('REDIS_DATABASE_QUEUE'); return (int) getenv('REDIS_DATABASE_QUEUE') ? getenv('REDIS_DATABASE_QUEUE') : 2;
return $val !== false ? (int) $val : 2;
} }
public static function getSessionDatabase(): int public static function getSessionDatabase(): int
{ {
$val = getenv('REDIS_DATABASE_SESSION'); return (int) getenv('REDIS_DATABASE_SESSION') ? getenv('REDIS_DATABASE_SESSION') : 3;
return $val !== false ? (int) $val : 3;
} }
public static function getPrefix(): string public static function getPrefix(): string
{ {
return getenv('REDIS_PREFIX') ?: 'flarum_'; return getenv('REDIS_PREFIX') ? getenv('REDIS_PREFIX') : 'flarum_';
} }
} }