如何在Laravel中使用不同的Redis连接 [英] How can use different redis connection in laravel
问题描述
我正在创建一个laravel软件包,在这个页面中,我需要在redis中保存一些数据,但是我希望该软件包使用不同的redis连接,以便他们可以在软件包的config文件中设置redis详细信息凭据,并将使用此程序包的此连接.我想给包用户自由使用不同的Redis连接.
I am creating a laravel package, in this pacakge i need to save some data in redis, but i want this package to use different redis connection, so that if they can setup the redis details credential in package's config file and will use this connection for this package. I want to give freedom to use different redis connection to the package user.
如果您有任何想法,我该如何实现.任何帮助将不胜感激.
If you have any idea how can i achieve this. Any help would be appreciated.
推荐答案
文档中有一个部分称为
使用多个Redis连接
Using Multiple Redis Connections
更改您的连接呼叫
$redis = Redis::connection('my-connection');
您可以在运行时使用配置帮助器在配置中添加和删除连接.
You can add and remove connections from config during runtime with the config helper.
config(['database.redis.new-connection' => [
'host' => '127.0.0.1',
'password' => 'secret',
'port' => '6379',
'database' => 0
]
]);
这篇关于如何在Laravel中使用不同的Redis连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!