cooperaj / laravel-redis-sentinel
提供与Redis Sentinel一起工作的laravel队列驱动。
v1.0
2017-06-08 15:03 UTC
Requires
- php: >5.5.0
- illuminate/contracts: ^5.3.0
- illuminate/queue: ^5.3.0
- illuminate/redis: ^5.3.0
- illuminate/support: ^5.3.0
- predis/predis: ~1.0
Requires (Dev)
- phpunit/phpunit: ^4.0
This package is auto-updated.
Last update: 2024-09-20 22:58:35 UTC
README
此提供Laravel的Sentinel感知驱动。具有Sentinel的Redis集群支持高可用性主/从架构,当节点停止工作时提供自动故障转移。
代码简单,仅允许您通过更改Laravel对您如何使用Redis的某些假设来正确配置Sentinel。
兼容性
安装
将服务提供者添加到您的config/app.php
,您还应该注释掉(或删除)默认的illuminate
Redis驱动程序
'providers' => [
// Illuminate\Redis\RedisServiceProvider::class,
...
RedisSentinel\Laravel\RedisSentinelServiceProvider::class,
]
将Redis数据库指向一组Redis Sentinel。将config/database.php
中的redis
部分更改为以下内容
'redis' => [
'cluster' => false,
'default' => [
[
'host' => env('REDIS_SENTINEL_1'),
'port' => 26379
],
[
'host' => env('REDIS_SENTINEL_2'),
'port' => 26379
],
[
'host' => env('REDIS_SENTINEL_3'),
'port' => 26379
],
'options' => [
'replication' => 'sentinel',
'service' => 'mymaster',
'parameters' => [
'database' => 0,
'password' => env('REDIS_PASSWORD', null)
]
]
],
// optional configuration for a separate Redis 'database' for just a cache
'cache' => [
[
'host' => env('REDIS_SENTINEL_1'),
'port' => 26379
],
[
'host' => env('REDIS_SENTINEL_2'),
'port' => 26379
],
[
'host' => env('REDIS_SENTINEL_3'),
'port' => 26379
],
'options' => [
'replication' => 'sentinel',
'service' => 'mymaster',
'parameters' => [
'database' => 1, // note the differing 'database' number
'password' => env('REDIS_PASSWORD', null)
]
]
],
'options' => [
]
],
可选地,您可以添加一个配置选项,使Predis调查给定的Sentinel以获取Sentinel的完整列表。如果这样做,则只需在配置中提供单个Sentinel。Predis将确保Sentinel列表在后续查询中保持最新。
'default' => [
[
'host' => env('REDIS_SENTINEL'),
'port' => 26379
],
'options' => [
'replication' => 'sentinel',
'service' => 'mymaster',
'update_sentinels' => true,
'parameters' => [
'database' => 0,
'password' => env('REDIS_PASSWORD', null)
]
]
],
队列
将连接添加到您的config/queue.php
文件
'connections' => [
...
'sentinel' => [
'driver' => 'sentinel-redis',
'connection' => 'default', // or any other named 'database' you define in database.php
'queue' => 'default',
'retry_after' => 90,
],
],
配置您的env文件以使用新驱动程序
QUEUE_DRIVER=sentinel
缓存
Laravel将非常乐意使用Redis作为缓存位置。他们没有告诉您的是,清除缓存会执行简单的FLUSHDB
命令。如果您在Redis中也使用队列,则不想使用此命令。"哦不,我的所有队列作业都消失了"。
要修复此设置,请像上面示例config/database.php
片段中所示设置缓存数据库配置,确保您使用不同的数据库编号,并将config/cache.php
中的Redis部分更改为以下内容
'redis' => [
'driver' => 'redis',
'connection' => 'cache', \\ make sure this matches the name you gave your 'database'
],