From 37b54d1fc760778690adfd9a35dcde6a141e2b75 Mon Sep 17 00:00:00 2001 From: xujb <38559608+xujb977644703@users.noreply.github.com> Date: Wed, 22 Jan 2025 23:28:14 +0800 Subject: [PATCH] A new User property has been added to the RedisConf object. (#4559) --- core/stores/redis/conf.go | 4 ++++ core/stores/redis/redis.go | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/core/stores/redis/conf.go b/core/stores/redis/conf.go index 5328757f..da205bc0 100644 --- a/core/stores/redis/conf.go +++ b/core/stores/redis/conf.go @@ -19,6 +19,7 @@ type ( RedisConf struct { Host string Type string `json:",default=node,options=node|cluster"` + User string `json:",optional"` Pass string `json:",optional"` Tls bool `json:",optional"` NonBlock bool `json:",default=true"` @@ -40,6 +41,9 @@ func (rc RedisConf) NewRedis() *Redis { if rc.Type == ClusterType { opts = append(opts, Cluster()) } + if len(rc.User) > 0 { + opts = append(opts, WithUser(rc.User)) + } if len(rc.Pass) > 0 { opts = append(opts, WithPass(rc.Pass)) } diff --git a/core/stores/redis/redis.go b/core/stores/redis/redis.go index e0c3e686..2d486227 100644 --- a/core/stores/redis/redis.go +++ b/core/stores/redis/redis.go @@ -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) {