Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can use different redis connection in laravel

Tags:

redis

laravel

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.

like image 526
Vikash Avatar asked Dec 13 '22 21:12

Vikash


1 Answers

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
      ] 
]);
like image 76
online Thomas Avatar answered Dec 31 '22 05:12

online Thomas