-
Notifications
You must be signed in to change notification settings - Fork 3
/
option.go
54 lines (45 loc) · 972 Bytes
/
option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package goredis
import "time"
// Option set the redis options.
type Option func(*options)
type options struct {
enableTrace bool
dialTimeout time.Duration
readTimeout time.Duration
writeTimeout time.Duration
}
func (o *options) apply(opts ...Option) {
for _, opt := range opts {
opt(o)
}
}
// 默认设置
func defaultOptions() *options {
return &options{
enableTrace: false, // 是否开启链路跟踪,默认关闭
}
}
// WithEnableTrace use trace
func WithEnableTrace() Option {
return func(o *options) {
o.enableTrace = true
}
}
// WithDialTimeout set dail timeout
func WithDialTimeout(t time.Duration) Option {
return func(o *options) {
o.dialTimeout = t
}
}
// WithReadTimeout set read timeout
func WithReadTimeout(t time.Duration) Option {
return func(o *options) {
o.readTimeout = t
}
}
// WithWriteTimeout set write timeout
func WithWriteTimeout(t time.Duration) Option {
return func(o *options) {
o.writeTimeout = t
}
}