-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
109 lines (92 loc) · 2.77 KB
/
options.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package redis
import (
"crypto/tls"
"time"
"github.com/redis/go-redis/v9"
)
// Option is a function type that can be used to configure the `Redis`.
type Option func(*redis.Options)
// ApplyOptions applies the given options to the given backend.
func ApplyOptions(opt *redis.Options, options ...Option) {
for _, option := range options {
option(opt)
}
}
// WithAddr sets the `Addr` field of the `redis.Options` struct.
func WithAddr(addr string) Option {
return func(opt *redis.Options) {
opt.Addr = addr
}
}
// WithUsername sets the `Username` field of the `redis.Options` struct.
func WithUsername(username string) Option {
return func(opt *redis.Options) {
opt.Username = username
}
}
// WithPassword sets the `Password` field of the `redis.Options` struct.
func WithPassword(password string) Option {
return func(opt *redis.Options) {
opt.Password = password
}
}
// WithDB sets the `DB` field of the `redis.Options` struct.
func WithDB(db int) Option {
return func(opt *redis.Options) {
opt.DB = db
}
}
// WithMaxRetries sets the `MaxRetries` field of the `redis.Options` struct.
func WithMaxRetries(maxRetries int) Option {
return func(opt *redis.Options) {
opt.MaxRetries = maxRetries
}
}
// WithDialTimeout sets the `DialTimeout` field of the `redis.Options` struct.
func WithDialTimeout(dialTimeout time.Duration) Option {
return func(opt *redis.Options) {
opt.DialTimeout = dialTimeout
}
}
// WithReadTimeout sets the `ReadTimeout` field of the `redis.Options` struct.
func WithReadTimeout(readTimeout time.Duration) Option {
return func(opt *redis.Options) {
opt.ReadTimeout = readTimeout
}
}
// WithWriteTimeout sets the `WriteTimeout` field of the `redis.Options` struct.
func WithWriteTimeout(writeTimeout time.Duration) Option {
return func(opt *redis.Options) {
opt.WriteTimeout = writeTimeout
}
}
// WithPoolFIFO sets the `PoolFIFO` field of the `redis.Options` struct.
func WithPoolFIFO(poolFIFO bool) Option {
return func(opt *redis.Options) {
opt.PoolFIFO = poolFIFO
}
}
// WithPoolSize sets the `PoolSize` field of the `redis.Options` struct.
func WithPoolSize(poolSize int) Option {
return func(opt *redis.Options) {
opt.PoolSize = poolSize
}
}
// WithPoolTimeout sets the `PoolTimeout` field of the `redis.Options` struct.
func WithPoolTimeout(poolTimeout time.Duration) Option {
return func(opt *redis.Options) {
opt.PoolTimeout = poolTimeout
}
}
// WithTLSConfig sets the `TLSConfig` field of the `redis.Options` struct.
func WithTLSConfig(tlsConfig *tls.Config) Option {
return func(opt *redis.Options) {
opt.TLSConfig = tlsConfig
}
}
// WithMinIdleConns sets the `MinIdleConns` field of the `redis.Options` struct.
func WithMinIdleConns(minIdleConns int) Option {
return func(opt *redis.Options) {
opt.MinIdleConns = minIdleConns
}
}