A new User property has been added to the RedisConf object. (#4559)

This commit is contained in:
xujb
2025-01-22 23:28:14 +08:00
committed by GitHub
parent 00e0db5def
commit 37b54d1fc7
2 changed files with 15 additions and 0 deletions

View File

@@ -55,6 +55,7 @@ type (
Redis struct {
Addr string
Type string
User string
Pass string
tls bool
brk breaker.Breaker
@@ -126,6 +127,9 @@ func NewRedis(conf RedisConf, opts ...Option) (*Redis, error) {
if conf.Type == ClusterType {
opts = append([]Option{Cluster()}, opts...)
}
if len(conf.User) > 0 {
opts = append([]Option{WithUser(conf.User)}, opts...)
}
if len(conf.Pass) > 0 {
opts = append([]Option{WithPass(conf.Pass)}, opts...)
}
@@ -2405,6 +2409,13 @@ func SetSlowThreshold(threshold time.Duration) {
slowThreshold.Set(threshold)
}
// WithPass customizes the given Redis with given password.
func WithUser(user string) Option {
return func(r *Redis) {
r.User = user
}
}
// WithPass customizes the given Redis with given password.
func WithPass(pass string) Option {
return func(r *Redis) {