@@ -72,12 +72,16 @@ type Options struct {
7272 // Default is 5 seconds.
7373 DialTimeout time.Duration
7474 // 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.
7779 ReadTimeout time.Duration
7880 // 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.
8185 WriteTimeout time.Duration
8286
8387 // Type of connection pool.
@@ -144,19 +148,27 @@ func (opt *Options) init() {
144148 opt .PoolSize = 10 * runtime .GOMAXPROCS (0 )
145149 }
146150 switch opt .ReadTimeout {
151+ case - 2 :
152+ opt .ReadTimeout = - 1
147153 case - 1 :
148154 opt .ReadTimeout = 0
149155 case 0 :
150156 opt .ReadTimeout = 3 * time .Second
151157 }
152158 switch opt .WriteTimeout {
159+ case - 2 :
160+ opt .WriteTimeout = - 1
153161 case - 1 :
154162 opt .WriteTimeout = 0
155163 case 0 :
156164 opt .WriteTimeout = opt .ReadTimeout
157165 }
158166 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+ }
160172 }
161173 if opt .ConnMaxIdleTime == 0 {
162174 opt .ConnMaxIdleTime = 30 * time .Minute
0 commit comments