-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathoption.go
78 lines (67 loc) · 1.5 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
76
77
78
package eredis
import (
"github.com/go-redis/redis/v8"
)
// WithStub set mode to "stub"
func WithStub() Option {
return func(c *Container) {
c.config.Mode = StubMode
}
}
// WithStub set mode to "cluster"
func WithCluster() Option {
return func(c *Container) {
c.config.Mode = ClusterMode
}
}
// WithStub set mode to "sentinel"
func WithSentinel() Option {
return func(c *Container) {
c.config.Mode = SentinelMode
}
}
// withInterceptor 注入拦截器
func withInterceptor(interceptors ...redis.Hook) Option {
return func(c *Container) {
if c.config.interceptors == nil {
c.config.interceptors = make([]redis.Hook, 0, len(interceptors))
}
c.config.interceptors = append(c.config.interceptors, interceptors...)
}
}
// WithPassword set password
func WithPassword(password string) Option {
return func(c *Container) {
c.config.Password = password
}
}
// WithAddr set address
func WithAddr(addr string) Option {
return func(c *Container) {
c.config.Addr = addr
}
}
// WithAddrs set addresses
func WithAddrs(addrs []string) Option {
return func(c *Container) {
c.config.Addrs = addrs
}
}
// WithMasterName set masterName for sentinel mode
func WithMasterName(masterName string) Option {
return func(c *Container) {
c.config.MasterName = masterName
}
}
// WithPoolSize set pool size
func WithPoolSize(poolSize int) Option {
return func(c *Container) {
c.config.PoolSize = poolSize
}
}
// WithDB set db number
func WithDB(db int) Option {
return func(c *Container) {
c.config.DB = db
}
}