4 Commits
1.0.2 ... 1.0.3

Author SHA1 Message Date
Ian Morland
3284a36926 Cleanup 2021-07-05 14:12:08 +01:00
Ian Morland
68af330669 Add optional prefix 2021-07-01 21:28:35 +01:00
Ian Morland
09a30f786d Update usage 2021-07-01 21:26:55 +01:00
Ian Morland
68a5cafdfc Address failure when only running selected redis services 2021-07-01 21:23:57 +01:00
6 changed files with 597 additions and 594 deletions

View File

@@ -10,15 +10,16 @@ Makes it easy to enable/disable Redis features:
- Queue - Queue
- Sessions - Sessions
For this to work, environment variables have to be set on your host: If you are using a local redis setup, you will likely be able to simply use the defaults provided. Any of these can be overridden using environment variables as follows:
```ini ```ini
REDIS_HOST=null # Required REDIS_HOST='127.0.0.1 # Optional, else uses default
REDIS_PORT=6379 # Optional, else uses default REDIS_PORT=6379 # Optional, else uses default
REDIS_PASSWORD=null # Required, can be an empty string REDIS_PASSWORD=null # Optional, otherwise null
REDIS_DATABASE_CACHE=1 # Optional, else uses default REDIS_DATABASE_CACHE=1 # Optional, else uses default
REDIS_DATABASE_QUEUE=2 # Optional, else uses default REDIS_DATABASE_QUEUE=2 # Optional, else uses default
REDIS_DATABASE_SESSION=3 # Optional, else uses default REDIS_DATABASE_SESSION=3 # Optional, else uses default
REDIS_PREFIX='flarum_' # Optional, else uses default
``` ```
## 📥 Installation ## 📥 Installation

View File

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

View File

@@ -12,7 +12,7 @@
namespace GlowingBlue\RedisSetup; namespace GlowingBlue\RedisSetup;
use Flarum\Extend; use Flarum\Extend;
use GlowingBlue\RedisSetup\Extend\EnableRedis; use GlowingBlue\RedisSetup\Extend as GBExtend;
use GlowingBlue\RedisSetup\Provider\QueueProvider; use GlowingBlue\RedisSetup\Provider\QueueProvider;
return [ return [
@@ -21,8 +21,8 @@ return [
new Extend\Locales(__DIR__.'/resources/locale'), new Extend\Locales(__DIR__.'/resources/locale'),
new GBExtend\EnableRedis(),
(new Extend\ServiceProvider()) (new Extend\ServiceProvider())
->register(QueueProvider::class), ->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", "version": "0.0.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"flarum-webpack-config": "^0.1.0-beta.10", "flarum-webpack-config": "^1.0.0",
"webpack": "^4.26.0", "webpack": "^4.26.0",
"webpack-cli": "^3.0.7" "webpack-cli": "^3.0.7"
}, },

View File

@@ -18,10 +18,10 @@ class EnableRedis implements ExtenderInterface
public function extend(Container $container, Extension $extension = null) public function extend(Container $container, Extension $extension = null)
{ {
$config = $this->buildConfig(); $config = $this->buildConfig();
if (Arr::hasAny($config, [self::CACHE_KEY, self::QUEUE_KEY, self::SESSION_KEY])) { (new Redis($config))
(new Redis($config))->disable($this->getDisabledServices())->extend($container, $extension); ->disable($this->getDisabledServices())
} ->extend($container, $extension);
} }
private function getDisabledServices(): array private function getDisabledServices(): array
@@ -42,23 +42,18 @@ class EnableRedis implements ExtenderInterface
if (!(bool) $settings->get('glowingblue-redis.redisSessions', false)) { if (!(bool) $settings->get('glowingblue-redis.redisSessions', false)) {
$disabled[] = 'session'; $disabled[] = 'session';
} }
return $disabled; return $disabled;
} }
private function buildConfig(): array private function buildConfig($config = []): array
{ {
if ($this->getHost() === null) {
return [];
}
$config = [];
$cache = [ $cache = [
'host' => $this->getHost(), 'host' => $this->getHost(),
'password' => $this->getPassword(), 'password' => $this->getPassword(),
'port' => $this->getPort(), 'port' => $this->getPort(),
'database' => $this->getCacheDatabase(), 'database' => $this->getCacheDatabase(),
'prefix' => $this->getPrefix(),
]; ];
$queue = [ $queue = [
@@ -66,6 +61,7 @@ class EnableRedis implements ExtenderInterface
'password' => $this->getPassword(), 'password' => $this->getPassword(),
'port' => $this->getPort(), 'port' => $this->getPort(),
'database' => $this->getQueueDatabase(), 'database' => $this->getQueueDatabase(),
'prefix' => $this->getPrefix(),
]; ];
$session = [ $session = [
@@ -73,6 +69,7 @@ class EnableRedis implements ExtenderInterface
'password' => $this->getPassword(), 'password' => $this->getPassword(),
'port' => $this->getPort(), 'port' => $this->getPort(),
'database' => $this->getSessionDatabase(), 'database' => $this->getSessionDatabase(),
'prefix' => $this->getPrefix(),
]; ];
$config = Arr::add($config, self::CACHE_KEY, $cache); $config = Arr::add($config, self::CACHE_KEY, $cache);
@@ -82,9 +79,9 @@ class EnableRedis implements ExtenderInterface
return $config; 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 private function getPassword(): ?string
@@ -111,4 +108,9 @@ class EnableRedis implements ExtenderInterface
{ {
return (int) getenv('REDIS_DATABASE_SESSION') ? getenv('REDIS_DATABASE_SESSION') : 3; return (int) getenv('REDIS_DATABASE_SESSION') ? getenv('REDIS_DATABASE_SESSION') : 3;
} }
private function getPrefix(): string
{
return getenv('REDIS_PREFIX') ? getenv('REDIS_PREFIX') : 'flarum_';
}
} }