monospice / laravel-redis-sentinel-drivers

Redis Sentinel integration for Laravel and Lumen.
MIT License
101 stars 48 forks source link

[Question] How to set prefix with your package ?? #31

Closed a-h-abid closed 3 years ago

a-h-abid commented 4 years ago

Hi, I'm trying to set prefix for my redis sentinel with your package. When I used single redis master, it uses the prefix from configuration file. But for sentinel, it is not working. Can you please help?

Using Lumen v6.3.5

My configuration:

'redis' => [
    'driver' => env('REDIS_DRIVER', 'redis-sentinel'),

    'client' => 'predis',

    'cluster' => env('REDIS_CLUSTER', false),

    'default' => [
        'host' => env('REDIS_HOST'),
        'password' => env('REDIS_PASSWORD', null),
        'port' => env('REDIS_PORT', 6379),
        'database' => env('REDIS_DB', 0),
        'read_write_timeout' => 60,
        'prefix' => env('REDIS_PREFIX', ''),
    ],
],
cyrossignol commented 4 years ago

Hi @a-h-abid,

The configuration that you show above does not apply to Sentinel connections. This package uses a separate configuration block so that developers can configure Redis and Sentinel connections separately if needed.

We can set a prefix in the options for a Sentinel connection like we can for standard Redis connections:

'redis-sentinel' => [
    'default' => [
        ...
        'options' => [
            ...
            'prefix' => env('REDIS_PREFIX', 'example:'), 
        ],
    ],
],

If you're using the environment-based configuration for Lumen, you'll need to create a configuration file (either database.php or redis-sentinel.php) for the above because this package doesn't consume the REDIS_PREFIX environment variable automatically yet.

a-h-abid commented 3 years ago

Thanks for the help. Mangaed to get it to work.