From 51e8973e7b09ebf10ae7bc7d578d9d8a21010a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E9=A1=BA=E9=92=B0?= Date: Tue, 5 Mar 2024 11:56:31 +0800 Subject: [PATCH] feat(redis/config): add sentinel auth config --- contrib/nosql/redis/redis.go | 36 +++++++++++++++++--------------- database/gredis/gredis_config.go | 2 ++ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/contrib/nosql/redis/redis.go b/contrib/nosql/redis/redis.go index 248624334d0..9df5e36e74a 100644 --- a/contrib/nosql/redis/redis.go +++ b/contrib/nosql/redis/redis.go @@ -44,23 +44,25 @@ func init() { func New(config *gredis.Config) *Redis { fillWithDefaultConfiguration(config) opts := &redis.UniversalOptions{ - Addrs: gstr.SplitAndTrim(config.Address, ","), - Username: config.User, - Password: config.Pass, - DB: config.Db, - MaxRetries: defaultMaxRetries, - PoolSize: config.MaxActive, - MinIdleConns: config.MinIdle, - MaxIdleConns: config.MaxIdle, - ConnMaxLifetime: config.MaxConnLifetime, - ConnMaxIdleTime: config.IdleTimeout, - PoolTimeout: config.WaitTimeout, - DialTimeout: config.DialTimeout, - ReadTimeout: config.ReadTimeout, - WriteTimeout: config.WriteTimeout, - MasterName: config.MasterName, - TLSConfig: config.TLSConfig, - Protocol: config.Protocol, + Addrs: gstr.SplitAndTrim(config.Address, ","), + Username: config.User, + Password: config.Pass, + SentinelUsername: config.SentinelUser, + SentinelPassword: config.SentinelPass, + DB: config.Db, + MaxRetries: defaultMaxRetries, + PoolSize: config.MaxActive, + MinIdleConns: config.MinIdle, + MaxIdleConns: config.MaxIdle, + ConnMaxLifetime: config.MaxConnLifetime, + ConnMaxIdleTime: config.IdleTimeout, + PoolTimeout: config.WaitTimeout, + DialTimeout: config.DialTimeout, + ReadTimeout: config.ReadTimeout, + WriteTimeout: config.WriteTimeout, + MasterName: config.MasterName, + TLSConfig: config.TLSConfig, + Protocol: config.Protocol, } var client redis.UniversalClient diff --git a/database/gredis/gredis_config.go b/database/gredis/gredis_config.go index caa6808bdd6..ca6d34e1840 100644 --- a/database/gredis/gredis_config.go +++ b/database/gredis/gredis_config.go @@ -25,6 +25,8 @@ type Config struct { Db int `json:"db"` // Redis db. User string `json:"user"` // Username for AUTH. Pass string `json:"pass"` // Password for AUTH. + SentinelUser string `json:"sentinel_user"` // Username for sentinel AUTH. + SentinelPass string `json:"sentinel_pass"` // Password for sentinel AUTH. MinIdle int `json:"minIdle"` // Minimum number of connections allowed to be idle (default is 0) MaxIdle int `json:"maxIdle"` // Maximum number of connections allowed to be idle (default is 10) MaxActive int `json:"maxActive"` // Maximum number of connections limit (default is 0 means no limit).