Reputation: 3460
I have a Redis cluster running inside Kubernetes. A Redis cluster can only have 1 master and N slaves. Is it possible to have multiple Redis connections inside Laravel for reading and writing? so I can write to the master and read from a slave. It's possible for 'normal' databases:
'mysql' => [
'read' => [
'host' => ['192.168.1.1'],
],
'write' => [
'host' => ['196.168.1.2'],
],
'....' => .....
]
Is there anyway to achieve this for Redis?
Thankyou,
Upvotes: 10
Views: 3541
Reputation: 5599
You can change which connection is used with the connection
method which will return a Redis instance, e.g:
$redis = Redis::connection('read');
$redis->get('example');
You would configure the different connections in the same way you would for MySQL.
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
'read' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6380),
'database' => 0,
],
],
Upvotes: 6