From 024e01592b7513f525d9eb806ec41873a07af4e8 Mon Sep 17 00:00:00 2001 From: Vlad Vitan <23100181+vlasebian@users.noreply.github.com> Date: Tue, 18 Feb 2025 17:03:47 +0200 Subject: [PATCH] all: Add sentinel password to redis failover configuration --- pkg/redis/redis.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/pkg/redis/redis.go b/pkg/redis/redis.go index 7c66bb1d06..4dc62eadef 100644 --- a/pkg/redis/redis.go +++ b/pkg/redis/redis.go @@ -140,22 +140,23 @@ func (c Config) WithNamespace(namespace ...string) *Config { // IsZero returns whether the Redis configuration is empty. func (c Config) IsZero() bool { if c.Failover.Enable { - return c.Failover.MasterName == "" && len(c.Failover.Addresses) == 0 + return c.Failover.MasterName == "" && len(c.Failover.SentinelAddresses) == 0 } return c.Address == "" } // FailoverConfig represents Redis failover configuration. type FailoverConfig struct { - Enable bool `name:"enable" description:"Enable failover using Redis Sentinel"` - Addresses []string `name:"addresses" description:"Redis Sentinel server addresses"` - MasterName string `name:"master-name" description:"Redis Sentinel master name"` + Enable bool `name:"enable" description:"Enable failover using Redis Sentinel"` + SentinelAddresses []string `name:"addresses" description:"Redis Sentinel server addresses"` + SentinelPassword string `name:"password" description:"Redis Sentinel password"` + MasterName string `name:"master-name" description:"Redis Sentinel master name"` } // Equals checks if the other configuration is equivalent to this. func (c FailoverConfig) Equals(other FailoverConfig) bool { return c.Enable == other.Enable && - equalsStringSlice(c.Addresses, other.Addresses) && + equalsStringSlice(c.SentinelAddresses, other.SentinelAddresses) && c.MasterName == other.MasterName } @@ -200,14 +201,15 @@ func debugLogFunc(ctx context.Context, format string, v ...any) { func newRedisClient(conf *Config) *redis.Client { if conf.Failover.Enable { return redis.NewFailoverClient(&redis.FailoverOptions{ - Dialer: conf.makeDialer(), - MasterName: conf.Failover.MasterName, - SentinelAddrs: conf.Failover.Addresses, - Password: conf.Password, - DB: conf.Database, - PoolSize: conf.PoolSize, - ConnMaxIdleTime: conf.IdleTimeout, - ConnMaxLifetime: conf.ConnMaxLifetime, + Dialer: conf.makeDialer(), + MasterName: conf.Failover.MasterName, + SentinelAddrs: conf.Failover.SentinelAddresses, + SentinelPassword: conf.Failover.SentinelPassword, + Password: conf.Password, + DB: conf.Database, + PoolSize: conf.PoolSize, + ConnMaxIdleTime: conf.IdleTimeout, + ConnMaxLifetime: conf.ConnMaxLifetime, }) } return redis.NewClient(&redis.Options{