mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-02 16:28:39 +08:00
A new User property has been added to the RedisConf object. (#4559)
This commit is contained in:
parent
00e0db5def
commit
37b54d1fc7
@ -19,6 +19,7 @@ type (
|
|||||||
RedisConf struct {
|
RedisConf struct {
|
||||||
Host string
|
Host string
|
||||||
Type string `json:",default=node,options=node|cluster"`
|
Type string `json:",default=node,options=node|cluster"`
|
||||||
|
User string `json:",optional"`
|
||||||
Pass string `json:",optional"`
|
Pass string `json:",optional"`
|
||||||
Tls bool `json:",optional"`
|
Tls bool `json:",optional"`
|
||||||
NonBlock bool `json:",default=true"`
|
NonBlock bool `json:",default=true"`
|
||||||
@ -40,6 +41,9 @@ func (rc RedisConf) NewRedis() *Redis {
|
|||||||
if rc.Type == ClusterType {
|
if rc.Type == ClusterType {
|
||||||
opts = append(opts, Cluster())
|
opts = append(opts, Cluster())
|
||||||
}
|
}
|
||||||
|
if len(rc.User) > 0 {
|
||||||
|
opts = append(opts, WithUser(rc.User))
|
||||||
|
}
|
||||||
if len(rc.Pass) > 0 {
|
if len(rc.Pass) > 0 {
|
||||||
opts = append(opts, WithPass(rc.Pass))
|
opts = append(opts, WithPass(rc.Pass))
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,7 @@ type (
|
|||||||
Redis struct {
|
Redis struct {
|
||||||
Addr string
|
Addr string
|
||||||
Type string
|
Type string
|
||||||
|
User string
|
||||||
Pass string
|
Pass string
|
||||||
tls bool
|
tls bool
|
||||||
brk breaker.Breaker
|
brk breaker.Breaker
|
||||||
@ -126,6 +127,9 @@ func NewRedis(conf RedisConf, opts ...Option) (*Redis, error) {
|
|||||||
if conf.Type == ClusterType {
|
if conf.Type == ClusterType {
|
||||||
opts = append([]Option{Cluster()}, opts...)
|
opts = append([]Option{Cluster()}, opts...)
|
||||||
}
|
}
|
||||||
|
if len(conf.User) > 0 {
|
||||||
|
opts = append([]Option{WithUser(conf.User)}, opts...)
|
||||||
|
}
|
||||||
if len(conf.Pass) > 0 {
|
if len(conf.Pass) > 0 {
|
||||||
opts = append([]Option{WithPass(conf.Pass)}, opts...)
|
opts = append([]Option{WithPass(conf.Pass)}, opts...)
|
||||||
}
|
}
|
||||||
@ -2405,6 +2409,13 @@ func SetSlowThreshold(threshold time.Duration) {
|
|||||||
slowThreshold.Set(threshold)
|
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.
|
// WithPass customizes the given Redis with given password.
|
||||||
func WithPass(pass string) Option {
|
func WithPass(pass string) Option {
|
||||||
return func(r *Redis) {
|
return func(r *Redis) {
|
||||||
|
Loading…
Reference in New Issue
Block a user