@@ -72,12 +72,16 @@ type Options struct {
72
72
// Default is 5 seconds.
73
73
DialTimeout time.Duration
74
74
// Timeout for socket reads. If reached, commands will fail
75
- // with a timeout instead of blocking. Use value -1 for no timeout and 0 for default.
76
- // Default is 3 seconds.
75
+ // with a timeout instead of blocking. Supported values:
76
+ // - `0` - default timeout (3 seconds).
77
+ // - `-1` - no timeout (block indefinitely).
78
+ // - `-2` - disables SetReadDeadline calls completely.
77
79
ReadTimeout time.Duration
78
80
// Timeout for socket writes. If reached, commands will fail
79
- // with a timeout instead of blocking.
80
- // Default is ReadTimeout.
81
+ // with a timeout instead of blocking. Supported values:
82
+ // - `0` - default timeout (3 seconds).
83
+ // - `-1` - no timeout (block indefinitely).
84
+ // - `-2` - disables SetWriteDeadline calls completely.
81
85
WriteTimeout time.Duration
82
86
83
87
// Type of connection pool.
@@ -144,19 +148,27 @@ func (opt *Options) init() {
144
148
opt .PoolSize = 10 * runtime .GOMAXPROCS (0 )
145
149
}
146
150
switch opt .ReadTimeout {
151
+ case - 2 :
152
+ opt .ReadTimeout = - 1
147
153
case - 1 :
148
154
opt .ReadTimeout = 0
149
155
case 0 :
150
156
opt .ReadTimeout = 3 * time .Second
151
157
}
152
158
switch opt .WriteTimeout {
159
+ case - 2 :
160
+ opt .WriteTimeout = - 1
153
161
case - 1 :
154
162
opt .WriteTimeout = 0
155
163
case 0 :
156
164
opt .WriteTimeout = opt .ReadTimeout
157
165
}
158
166
if opt .PoolTimeout == 0 {
159
- opt .PoolTimeout = opt .ReadTimeout + time .Second
167
+ if opt .ReadTimeout > 0 {
168
+ opt .PoolTimeout = opt .ReadTimeout + time .Second
169
+ } else {
170
+ opt .PoolTimeout = 30 * time .Second
171
+ }
160
172
}
161
173
if opt .ConnMaxIdleTime == 0 {
162
174
opt .ConnMaxIdleTime = 30 * time .Minute
0 commit comments