Vikash
Vikash

Reputation: 3551

How can use different redis connection in 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.

Upvotes: 5

Views: 10817

Answers (1)

online Thomas
online Thomas

Reputation: 9381

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
      ] 
]);

Upvotes: 13

Related Questions