Redis sessions, cache & queues
This library allows using Redis as cache, session and for the queue. You can only enable these services by using a local extender (the extend.php
in the root of your Flarum installation). See the "Set up" section below.
This is an advanced utility for webmasters! It is not an extension and won't be visible in the admin area. Configuration can be done using a local extender or the glowingblue redis setup extension.
Installation
Install manually with composer:
composer require blomstra/flarum-redis:*
Set up
In your extend.php
:
return [
new Blomstra\Redis\Extend\Redis([
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
'database' => 1,
])
];
This enables sessions, cache and queue to run on redis.
See "Use different database for each service" below to split up the database for cache vs sessions, queue, because a cache clear action will clear sessions and queue jobs as well if they share the same database.
Advanced configuration
- Disable specific services:
return [
(new Blomstra\Redis\Extend\Redis([
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
'database' => 1,
]))->disable(['cache', 'queue'])
];
- Use different database for each service:
return [
(new Blomstra\Redis\Extend\Redis([
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
'database' => 1,
]))
->useDatabaseWith('cache', 1)
->useDatabaseWith('queue', 2)
->useDatabaseWith('session', 3)
];
- Completely separate the config array:
return [
(new Blomstra\Redis\Extend\Redis([
'connections' => [
'cache' => [
'host' => 'cache.int.yoursite.com',
'password' => 'foo-bar',
'port' => 6379,
'database' => 1,
],
'queue' => [
'host' => 'queue.int.yoursite.com',
'password' => 'foo-bar',
'port' => 6379,
'database' => 1,
],
'session' => [
'host' => 'session.int.yoursite.com',
'password' => 'foo-bar',
'port' => 6379,
'database' => 1,
],
],
]))
];
Queue
Make sure to start your queue workers, see the laravel documentation for specifics.
To test the worker can start use php flarum queue:work
.
Updating
composer update blomstra/flarum-redis
Make sure to restart your queue workers every time you upgrade flarum, add or remove extensions. So whenever you ran composer commands you have to restart the queue.
FAQ
How do I configure a redis socket?
Use the following configuration:
[
'scheme' => 'unix',
'path' => '<path to>redis.sock',
'port' => 0,
'database' => 1
]
Links