To configure a Redis Sentinel cluster in Laravel 10, you can use the predis/predis package. Here are the steps to follow:
- Install the predis/predis package using Composer:
composer require predis/predis
- In your Laravel configuration file (config/database.php), add the following Redis configuration:
'redis' => [
'client' => 'predis',
'sentinel' => [
'hosts' => [
[
'host' => 'sentinel1',
'port' => 26379,
],
[
'host' => 'sentinel2',
'port' => 26379,
],
[
'host' => 'sentinel3',
'port' => 26379,
],
],
'service' => 'mymaster',
'parameters' => [
'password' => 'yourpassword',
'database' => 0,
],
],
],
Replace sentinel1, sentinel2, and sentinel3 with the hostnames or IP addresses of your Redis Sentinel servers. Replace mymaster with the name of your Redis master server. Replace yourpassword with the password for your Redis server.
- In your Laravel configuration file (config/cache.php), add the following Redis cache configuration:
'redis' => [
'client' => 'predis',
'cluster' => true,
'default' => [
[
'host' => 'redis1',
'port' => 6379,
'password' => 'yourpassword',
'database' => 0,
],
[
'host' => 'redis2',
'port' => 6379,
'password' => 'yourpassword',
'database' => 0,
],
[
'host' => 'redis3',
'port' => 6379,
'password' => 'yourpassword',
'database' => 0,
],
],
],
Replace redis1, redis2, and redis3 with the hostnames or IP addresses of your Redis servers. Replace yourpassword with the password for your Redis server.
- In your Laravel configuration file (config/session.php), add the following Redis session configuration:
'driver' => 'redis',
'connection' => 'default',
'lifetime' => 120,
'path' => '/',
'domain' => null,
'secure' => false,
'http_only' => true,
- In your Laravel configuration file (config/queue.php), add the following Redis queue configuration:
'default' => 'redis',
'connections' => [
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'default',
'retry_after' => 90,
'block_for' => null,
],
],
- To flush the cache without flushing the session and queue jobs, you can use the following code:
Cache::flush();
Cache::store('redis')->flush();
This will flush the default cache and the Redis cache separately.
Note: Make sure to replace the Redis server details with your own.