feat: slow threshold customizable in redis (#1185)

* feat: slow threshold customizable in redis

* chore: improve config robustness
This commit is contained in:
Kevin Wan
2021-10-31 22:14:20 +08:00
committed by GitHub
parent b4d1c6da2c
commit 429f85a9de
8 changed files with 83 additions and 33 deletions

View File

@@ -1,6 +1,11 @@
package redis
import "errors"
import (
"errors"
"time"
"github.com/tal-tech/go-zero/core/conf"
)
var (
// ErrEmptyHost is an error that indicates no redis host is set.
@@ -14,10 +19,11 @@ var (
type (
// A RedisConf is a redis config.
RedisConf struct {
Host string
Type string `json:",default=node,options=node|cluster"`
Pass string `json:",optional"`
Tls bool `json:",default=false,options=true|false"`
Host string
Type string `json:",default=node,options=node|cluster"`
Pass string `json:",optional"`
Tls bool `json:",default=false,options=true|false"`
SlowThreshold time.Duration `json:",default=100ms"`
}
// A RedisKeyConf is a redis config with key.
@@ -36,6 +42,9 @@ func (rc RedisConf) NewRedis() *Redis {
if len(rc.Pass) > 0 {
opts = append(opts, WithPass(rc.Pass))
}
if rc.SlowThreshold > 0 {
opts = append(opts, WithSlowThreshold(conf.CheckedDuration(rc.SlowThreshold)))
}
if rc.Tls {
opts = append(opts, WithTLS())
}