bokt / flarum-redis
0.4.2
2022-03-03 21:05 UTC
Requires
- flarum/core: ^1.0.0
- illuminate/redis: *
- predis/predis: *
This package is auto-updated.
Last update: 2022-03-03 21:26:52 UTC
README
此库允许使用Redis作为缓存、会话和队列。您只能通过使用本地扩展器(您的Flarum安装根目录中的extend.php
)来启用这些服务。请参阅下面的“设置”部分。
这是一个针对网站管理员的先进工具!
安装
使用Composer手动安装
composer require blomstra/flarum-redis:*
设置
在您的extend.php
return [ new Blomstra\Redis\Extend\Redis([ 'host' => '127.0.0.1', 'password' => null, 'port' => 6379, 'database' => 1 ]) ];
这使会话、缓存和队列在Redis上运行。
请参阅下面的“为每个服务使用不同的数据库”以分离缓存和会话、队列的数据库,因为如果它们使用相同的数据库,缓存清除操作将清除会话和队列作业。
高级配置
- 禁用特定服务
return [ (new Blomstra\Redis\Extend\Redis([ 'host' => '127.0.0.1', 'password' => null, 'port' => 6379, 'database' => 1, ]))->disable(['cache', 'queue']) ];
- 为每个服务使用不同的数据库
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) ];
- 完全分离配置数组
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, ], ], ])) ];
- 使用集群
return [ (new Blomstra\Redis\Extend\Redis([ 'host' => '127.0.0.1', 'password' => null, 'port' => 6379, 'database' => 1, 'options' => [ 'replication' => 'sentinel', 'service' => 'mymaster:26379', ] ])) ->useDatabaseWith('cache', 1) ->useDatabaseWith('queue', 2) ->useDatabaseWith('session', 3) ];
队列
确保启动您的队列工作进程,有关详细信息,请参阅Laravel文档。要测试工作进程是否可以启动,请使用php flarum queue:work
。
队列选项
队列允许添加几个选项,例如retry_after、block_for和after_commit。您可以通过在配置中添加一个queue
数组来设置这些选项。
return [ (new Blomstra\Redis\Extend\Redis([ 'host' => '127.0.0.1', 'password' => null, 'port' => 6379, 'database' => 1, 'queue' => [ 'retry_after' => 120, // seconds 'block_for' => 5, // seconds 'after_commit' => true ] ])) ->useDatabaseWith('cache', 1) ->useDatabaseWith('queue', 2) ->useDatabaseWith('session', 3) ];
您可以在Laravel文档中了解这些选项的含义。
更新
composer update blomstra/flarum-redis
常见问题解答
为什么存储/缓存中仍有文件? 一些代码仍然依赖于物理文件的存在。这包括格式化缓存和视图缓存。
链接
- Blomstra提供Flarum托管服务。
- https://blomstra.net
- https://blomstra.community/t/ext-cache-assets