laravel框架5.5 连接redis和redis集群
'redis' => [ 'client' => 'predis', 'default' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => 0, ],
'options' => [
'cluster' => 'redis',
], 'mydefine' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => 4, ], 'clusters' => [ 'mycluster1' => [ [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => 1, ], [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => 2, ], [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => 3, ], ], ], ],
配置文件如上图所示
着重说一下redis集群的使用:
$redis = Redis::connection('mycluster1'); $redis->set('foo','bar'); echo $redis->get('foo');
其他的文档里面都有,或者可以参考这个博客总结的:https://www.2cto.com/database/201801/712685.html