Larave 连接 Redis 集群的配置及使用
配置文件:
config/database.php
配置项如下:
'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',
],
'clusters' => [
'cluster1' => [
[
'host' => '172.17.0.1',
'password' => null,
'port' => 6379,
'database' => 0,
],
],
'cluster2' => [
[
'host' => '192.168.31.244',
'password' => null,
'port' => 6379,
'database' => 0,
],
],
],
],
使用 Redis:
$redis = Redis::connection('cluster1');
$redis->set('username','wdh');
echo $redis->get('username');
相关参考:
1. laravel框架5.5 连接redis和redis集群:https : // www . cn blogs . com /liaokaichang/p/8874808.html
2. Laravel redis集群:https : // www . cnblogs . com /yinguohai/p/11329273.html