怎么動態(tài)得使用redis數(shù)據(jù)庫呢?
項(xiàng)目有不同的id,想著一個id對應(yīng)一個redis庫怎么寫連接配置呢?
使用多個 Redis 連接
例如配置文件config/redis.php
return [
'default' => [
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
'database' => 0,
],
'cache' => [
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
'database' => 1,
],
]
默認(rèn)使用的是default下配置的連接,你可以用Redis::connection()方法選擇使用哪個redis連接。
$redis = Redis::connection('cache');
$redis->get('test_key');