Skip to content

Commit

Permalink
enhance: add sentinel auth config for redis (#3348)
Browse files Browse the repository at this point in the history
  • Loading branch information
laushunyu authored Mar 6, 2024
1 parent fbd266f commit 9b48da4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
36 changes: 19 additions & 17 deletions contrib/nosql/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions database/gredis/gredis_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down

0 comments on commit 9b48da4

Please sign in to comment.