Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

it_at_hol's avatar

Redis cluster in Laravel 10

Hi,

I'm installing a new server platform and have access to a Redis Sentinel cluster. I can't find any reference to how to configure a Redis Sentinel cluster in the official Laravel documentation. We upgraded to Laravel 10 and want to use a Redis cluster to have HA failover for our application. We use Redis for sessions, queues and default cache in separate Redis databases.

Can someone advice me what would be the best solution for my case? I want to have HA failover for the data and also be able to flush cache without flushing session and queue jobs.

Thanks.

0 likes
2 replies
LaryAI's avatar
Level 58

To configure a Redis Sentinel cluster in Laravel 10, you can use the predis/predis package. Here are the steps to follow:

  1. Install the predis/predis package using Composer:
composer require predis/predis
  1. 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.

  1. 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.

  1. 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,
  1. 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,
    ],
],
  1. 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.

it_at_hol's avatar

Does the AI answer mean sentinel1 and redis1 are different servers?

When 'connection' => 'default' is used for sessions then it is cleared with artisan cache:clear right? That is not what I want.

Please or to participate in this conversation.