Address failure when only running selected redis services

This commit is contained in:
Ian Morland
2021-07-01 21:23:57 +01:00
parent ed83a0123d
commit 68a5cafdfc
5 changed files with 594 additions and 581 deletions

View File

@@ -14,7 +14,7 @@
},
"homepage": "https://glowingblue.com",
"require": {
"flarum/core": "^1.0.0",
"flarum/core": "^1.0.4",
"blomstra/flarum-redis": "^0.4.0"
},
"authors": [

View File

@@ -21,8 +21,8 @@ return [
new Extend\Locales(__DIR__.'/resources/locale'),
new EnableRedis(),
(new Extend\ServiceProvider())
->register(QueueProvider::class),
new EnableRedis()
];

1144
js/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"flarum-webpack-config": "^0.1.0-beta.10",
"flarum-webpack-config": "^1.0.0",
"webpack": "^4.26.0",
"webpack-cli": "^3.0.7"
},

View File

@@ -18,10 +18,15 @@ class EnableRedis implements ExtenderInterface
public function extend(Container $container, Extension $extension = null)
{
$config = $this->buildConfig();
$disabled = $this->getDisabledServices();
if (Arr::hasAny($config, [self::CACHE_KEY, self::QUEUE_KEY, self::SESSION_KEY])) {
(new Redis($config))->disable($this->getDisabledServices())->extend($container, $extension);
$redis = (new Redis($config));
foreach ($disabled as $service) {
$redis->disable($service);
}
$redis->extend($container, $extension);
}
private function getDisabledServices(): array
@@ -42,7 +47,7 @@ class EnableRedis implements ExtenderInterface
if (!(bool) $settings->get('glowingblue-redis.redisSessions', false)) {
$disabled[] = 'session';
}
return $disabled;
}
@@ -59,6 +64,7 @@ class EnableRedis implements ExtenderInterface
'password' => $this->getPassword(),
'port' => $this->getPort(),
'database' => $this->getCacheDatabase(),
'prefix' => $this->getPrefix(),
];
$queue = [
@@ -66,6 +72,7 @@ class EnableRedis implements ExtenderInterface
'password' => $this->getPassword(),
'port' => $this->getPort(),
'database' => $this->getQueueDatabase(),
'prefix' => $this->getPrefix(),
];
$session = [
@@ -73,6 +80,7 @@ class EnableRedis implements ExtenderInterface
'password' => $this->getPassword(),
'port' => $this->getPort(),
'database' => $this->getSessionDatabase(),
'prefix' => $this->getPrefix(),
];
$config = Arr::add($config, self::CACHE_KEY, $cache);
@@ -82,9 +90,9 @@ class EnableRedis implements ExtenderInterface
return $config;
}
private function getHost(): ?string
private function getHost(): string
{
return getenv('REDIS_HOST') ? getenv('REDIS_HOST') : null;
return getenv('REDIS_HOST') ? getenv('REDIS_HOST') : '127.0.0.1';
}
private function getPassword(): ?string
@@ -111,4 +119,9 @@ class EnableRedis implements ExtenderInterface
{
return (int) getenv('REDIS_DATABASE_SESSION') ? getenv('REDIS_DATABASE_SESSION') : 3;
}
private function getPrefix(): string
{
return getenv('REDIS_PREFIX') ? getenv('REDIS_PREFIX') : 'flarum_';
}
}