|
|
@ -9,6 +9,7 @@ import (
|
|
|
|
red "github.com/go-redis/redis"
|
|
|
|
red "github.com/go-redis/redis"
|
|
|
|
"github.com/tal-tech/go-zero/core/breaker"
|
|
|
|
"github.com/tal-tech/go-zero/core/breaker"
|
|
|
|
"github.com/tal-tech/go-zero/core/mapping"
|
|
|
|
"github.com/tal-tech/go-zero/core/mapping"
|
|
|
|
|
|
|
|
"github.com/tal-tech/go-zero/core/syncx"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
const (
|
|
|
@ -24,8 +25,11 @@ const (
|
|
|
|
defaultSlowThreshold = time.Millisecond * 100
|
|
|
|
defaultSlowThreshold = time.Millisecond * 100
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
// ErrNilNode is an error that indicates a nil redis node.
|
|
|
|
// ErrNilNode is an error that indicates a nil redis node.
|
|
|
|
var ErrNilNode = errors.New("nil redis node")
|
|
|
|
ErrNilNode = errors.New("nil redis node")
|
|
|
|
|
|
|
|
slowThreshold = syncx.ForAtomicDuration(defaultSlowThreshold)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type (
|
|
|
|
type (
|
|
|
|
// Option defines the method to customize a Redis.
|
|
|
|
// Option defines the method to customize a Redis.
|
|
|
@ -44,7 +48,6 @@ type (
|
|
|
|
Pass string
|
|
|
|
Pass string
|
|
|
|
tls bool
|
|
|
|
tls bool
|
|
|
|
brk breaker.Breaker
|
|
|
|
brk breaker.Breaker
|
|
|
|
slowThreshold time.Duration
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// RedisNode interface represents a redis node.
|
|
|
|
// RedisNode interface represents a redis node.
|
|
|
@ -81,7 +84,6 @@ func New(addr string, opts ...Option) *Redis {
|
|
|
|
Addr: addr,
|
|
|
|
Addr: addr,
|
|
|
|
Type: NodeType,
|
|
|
|
Type: NodeType,
|
|
|
|
brk: breaker.NewBreaker(),
|
|
|
|
brk: breaker.NewBreaker(),
|
|
|
|
slowThreshold: defaultSlowThreshold,
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for _, opt := range opts {
|
|
|
|
for _, opt := range opts {
|
|
|
@ -1759,6 +1761,11 @@ func Cluster() Option {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SetSlowThreshold sets the slow threshold.
|
|
|
|
|
|
|
|
func SetSlowThreshold(threshold time.Duration) {
|
|
|
|
|
|
|
|
slowThreshold.Set(threshold)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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) {
|
|
|
@ -1766,13 +1773,6 @@ func WithPass(pass string) Option {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// WithSlowThreshold sets the slow threshold.
|
|
|
|
|
|
|
|
func WithSlowThreshold(threshold time.Duration) Option {
|
|
|
|
|
|
|
|
return func(r *Redis) {
|
|
|
|
|
|
|
|
r.slowThreshold = threshold
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// WithTLS customizes the given Redis with TLS enabled.
|
|
|
|
// WithTLS customizes the given Redis with TLS enabled.
|
|
|
|
func WithTLS() Option {
|
|
|
|
func WithTLS() Option {
|
|
|
|
return func(r *Redis) {
|
|
|
|
return func(r *Redis) {
|
|
|
|