@@ -133,16 +133,7 @@ func (opt *Options) init() {
133
133
opt .DialTimeout = 5 * time .Second
134
134
}
135
135
if opt .Dialer == nil {
136
- opt .Dialer = func (ctx context.Context , network , addr string ) (net.Conn , error ) {
137
- netDialer := & net.Dialer {
138
- Timeout : opt .DialTimeout ,
139
- KeepAlive : 5 * time .Minute ,
140
- }
141
- if opt .TLSConfig == nil {
142
- return netDialer .DialContext (ctx , network , addr )
143
- }
144
- return tls .DialWithDialer (netDialer , network , addr , opt .TLSConfig )
145
- }
136
+ opt .Dialer = DefaultDialer (opt )
146
137
}
147
138
if opt .PoolSize == 0 {
148
139
opt .PoolSize = 10 * runtime .GOMAXPROCS (0 )
@@ -198,6 +189,21 @@ func (opt *Options) clone() *Options {
198
189
return & clone
199
190
}
200
191
192
+ // DefaultDialer returns a function that will be used as the default dialer
193
+ // when none is specified in Options.Dialer.
194
+ func DefaultDialer (opt * Options ) func (context.Context , string , string ) (net.Conn , error ) {
195
+ return func (ctx context.Context , network , addr string ) (net.Conn , error ) {
196
+ netDialer := & net.Dialer {
197
+ Timeout : opt .DialTimeout ,
198
+ KeepAlive : 5 * time .Minute ,
199
+ }
200
+ if opt .TLSConfig == nil {
201
+ return netDialer .DialContext (ctx , network , addr )
202
+ }
203
+ return tls .DialWithDialer (netDialer , network , addr , opt .TLSConfig )
204
+ }
205
+ }
206
+
201
207
// ParseURL parses an URL into Options that can be used to connect to Redis.
202
208
// Scheme is required.
203
209
// There are two connection types: by tcp socket and by unix socket.
0 commit comments