forked from clone/flarum-ext-redis-setup
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3284a36926 | ||
|
|
68af330669 | ||
|
|
09a30f786d | ||
|
|
68a5cafdfc | ||
|
|
ed83a0123d | ||
|
|
98fee09892 |
@@ -10,15 +10,16 @@ Makes it easy to enable/disable Redis features:
|
||||
- Queue
|
||||
- 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
|
||||
REDIS_HOST=null # Required
|
||||
REDIS_HOST='127.0.0.1 # 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_QUEUE=2 # Optional, else uses default
|
||||
REDIS_DATABASE_SESSION=3 # Optional, else uses default
|
||||
REDIS_PREFIX='flarum_' # Optional, else uses default
|
||||
```
|
||||
|
||||
## 📥 Installation
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
},
|
||||
"homepage": "https://glowingblue.com",
|
||||
"require": {
|
||||
"flarum/core": "^1.0.0",
|
||||
"blomstra/flarum-redis": "^0.4"
|
||||
"flarum/core": "^1.0.4",
|
||||
"blomstra/flarum-redis": "^0.4.0"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
@@ -40,4 +40,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace GlowingBlue\RedisSetup;
|
||||
|
||||
use Flarum\Extend;
|
||||
use GlowingBlue\RedisSetup\Extend\EnableRedis;
|
||||
use GlowingBlue\RedisSetup\Extend as GBExtend;
|
||||
use GlowingBlue\RedisSetup\Provider\QueueProvider;
|
||||
|
||||
return [
|
||||
@@ -21,8 +21,8 @@ return [
|
||||
|
||||
new Extend\Locales(__DIR__.'/resources/locale'),
|
||||
|
||||
new GBExtend\EnableRedis(),
|
||||
|
||||
(new Extend\ServiceProvider())
|
||||
->register(QueueProvider::class),
|
||||
|
||||
new EnableRedis()
|
||||
];
|
||||
|
||||
1144
js/package-lock.json
generated
1144
js/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -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"
|
||||
},
|
||||
|
||||
@@ -18,10 +18,10 @@ class EnableRedis implements ExtenderInterface
|
||||
public function extend(Container $container, Extension $extension = null)
|
||||
{
|
||||
$config = $this->buildConfig();
|
||||
|
||||
if (Arr::hasAny($config, [self::CACHE_KEY, self::QUEUE_KEY, self::SESSION_KEY])) {
|
||||
(new Redis($config))->disable($this->getDisabledServices())->extend($container, $extension);
|
||||
}
|
||||
|
||||
(new Redis($config))
|
||||
->disable($this->getDisabledServices())
|
||||
->extend($container, $extension);
|
||||
}
|
||||
|
||||
private function getDisabledServices(): array
|
||||
@@ -42,23 +42,18 @@ class EnableRedis implements ExtenderInterface
|
||||
if (!(bool) $settings->get('glowingblue-redis.redisSessions', false)) {
|
||||
$disabled[] = 'session';
|
||||
}
|
||||
|
||||
|
||||
return $disabled;
|
||||
}
|
||||
|
||||
private function buildConfig(): array
|
||||
private function buildConfig($config = []): array
|
||||
{
|
||||
if ($this->getHost() === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$config = [];
|
||||
|
||||
$cache = [
|
||||
'host' => $this->getHost(),
|
||||
'password' => $this->getPassword(),
|
||||
'port' => $this->getPort(),
|
||||
'database' => $this->getCacheDatabase(),
|
||||
'prefix' => $this->getPrefix(),
|
||||
];
|
||||
|
||||
$queue = [
|
||||
@@ -66,6 +61,7 @@ class EnableRedis implements ExtenderInterface
|
||||
'password' => $this->getPassword(),
|
||||
'port' => $this->getPort(),
|
||||
'database' => $this->getQueueDatabase(),
|
||||
'prefix' => $this->getPrefix(),
|
||||
];
|
||||
|
||||
$session = [
|
||||
@@ -73,6 +69,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 +79,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 +108,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_';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user