|
@@ -21,8 +21,7 @@ const (
|
|
|
|
|
|
blockingQueryTimeout = 5 * time.Second
|
|
blockingQueryTimeout = 5 * time.Second
|
|
readWriteTimeout = 2 * time.Second
|
|
readWriteTimeout = 2 * time.Second
|
|
-
|
|
|
|
- slowThreshold = time.Millisecond * 100
|
|
|
|
|
|
+ defaultSlowThreshold = time.Millisecond * 100
|
|
)
|
|
)
|
|
|
|
|
|
// ErrNilNode is an error that indicates a nil redis node.
|
|
// ErrNilNode is an error that indicates a nil redis node.
|
|
@@ -40,11 +39,12 @@ type (
|
|
|
|
|
|
// Redis defines a redis node/cluster. It is thread-safe.
|
|
// Redis defines a redis node/cluster. It is thread-safe.
|
|
Redis struct {
|
|
Redis struct {
|
|
- Addr string
|
|
|
|
- Type string
|
|
|
|
- Pass string
|
|
|
|
- tls bool
|
|
|
|
- brk breaker.Breaker
|
|
|
|
|
|
+ Addr string
|
|
|
|
+ Type string
|
|
|
|
+ Pass string
|
|
|
|
+ tls bool
|
|
|
|
+ brk breaker.Breaker
|
|
|
|
+ slowThreshold time.Duration
|
|
}
|
|
}
|
|
|
|
|
|
// RedisNode interface represents a redis node.
|
|
// RedisNode interface represents a redis node.
|
|
@@ -78,9 +78,10 @@ type (
|
|
// New returns a Redis with given options.
|
|
// New returns a Redis with given options.
|
|
func New(addr string, opts ...Option) *Redis {
|
|
func New(addr string, opts ...Option) *Redis {
|
|
r := &Redis{
|
|
r := &Redis{
|
|
- Addr: addr,
|
|
|
|
- Type: NodeType,
|
|
|
|
- brk: breaker.NewBreaker(),
|
|
|
|
|
|
+ Addr: addr,
|
|
|
|
+ Type: NodeType,
|
|
|
|
+ brk: breaker.NewBreaker(),
|
|
|
|
+ slowThreshold: defaultSlowThreshold,
|
|
}
|
|
}
|
|
|
|
|
|
for _, opt := range opts {
|
|
for _, opt := range opts {
|
|
@@ -1765,6 +1766,13 @@ 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) {
|