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.
There is a section in the documentation called
Using Multiple Redis Connections
To change your connection call
$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
]
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With