/
option.go
75 lines (64 loc) · 1.49 KB
/
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package myredis
import (
"time"
)
// WithTimeout 设置过期时间
func WithTimeout(timeout time.Duration) Option {
return optionFunc(func(o *redisOptions) {
o.timeout = timeout
})
}
// WithGroupName 分组名
func WithGroupName(groupName string) Option {
return optionFunc(func(o *redisOptions) {
o.groupName = groupName
})
}
// WithPwd 密码
func WithPwd(pwd string) Option {
return optionFunc(func(o *redisOptions) {
o.pwd = pwd
})
}
// WithAddr 密码
func WithAddr(addr ...string) Option {
return optionFunc(func(o *redisOptions) {
o.addrs = append(o.addrs, addr...)
})
}
// WithDB 数据库地址(index)
func WithDB(db int) Option {
return optionFunc(func(o *redisOptions) {
o.db = db
})
}
// WithReadTimeout 设置读过期时间
func WithReadTimeout(timeout time.Duration) Option {
return optionFunc(func(o *redisOptions) {
o.readTimeout = timeout
})
}
// WithWriteTimeout 设置写过期时间
func WithWriteTimeout(timeout time.Duration) Option {
return optionFunc(func(o *redisOptions) {
o.writeTimeout = timeout
})
}
// WithPool 连接池配置
func WithPool(maxIdle, maxActive int) Option {
return optionFunc(func(o *redisOptions) {
o.maxIdle = maxIdle
o.maxActive = maxActive
})
}
// WithClientName 指定Redis服务器连接使用的客户端名称
func WithClientName(name string) Option {
return optionFunc(func(o *redisOptions) {
o.clientName = name
})
}
func WithLog(isLog bool) Option{
return optionFunc(func(o *redisOptions) {
o.isLog = isLog
})
}