mirror of
https://github.com/glowingblue/flarum-ext-redis-setup.git
synced 2026-03-22 06:57:45 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3284a36926 | ||
|
|
68af330669 | ||
|
|
09a30f786d | ||
|
|
68a5cafdfc | ||
|
|
ed83a0123d |
@@ -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
|
||||||
|
|||||||
@@ -14,8 +14,8 @@
|
|||||||
},
|
},
|
||||||
"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@beta"
|
"blomstra/flarum-redis": "^0.4.0"
|
||||||
},
|
},
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
@@ -40,4 +40,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
1144
js/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -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"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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_';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user