mirror of https://github.com/go-redis/redis.git
Set cmd timeout when Block >= 0
This commit is contained in:
parent
f7094544a5
commit
40dbb03d62
13
commands.go
13
commands.go
|
@ -8,13 +8,6 @@ import (
|
||||||
"github.com/go-redis/redis/internal"
|
"github.com/go-redis/redis/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func readTimeout(timeout time.Duration) time.Duration {
|
|
||||||
if timeout == 0 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return timeout + 10*time.Second
|
|
||||||
}
|
|
||||||
|
|
||||||
func usePrecise(dur time.Duration) bool {
|
func usePrecise(dur time.Duration) bool {
|
||||||
return dur < time.Second || dur%time.Second != 0
|
return dur < time.Second || dur%time.Second != 0
|
||||||
}
|
}
|
||||||
|
@ -1397,6 +1390,9 @@ func (c *cmdable) XRead(a *XReadArgs) *XStreamSliceCmd {
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := NewXStreamSliceCmd(args...)
|
cmd := NewXStreamSliceCmd(args...)
|
||||||
|
if a.Block >= 0 {
|
||||||
|
cmd.setReadTimeout(a.Block)
|
||||||
|
}
|
||||||
c.process(cmd)
|
c.process(cmd)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -1455,6 +1451,9 @@ func (c *cmdable) XReadGroup(a *XReadGroupArgs) *XStreamSliceCmd {
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := NewXStreamSliceCmd(args...)
|
cmd := NewXStreamSliceCmd(args...)
|
||||||
|
if a.Block >= 0 {
|
||||||
|
cmd.setReadTimeout(a.Block)
|
||||||
|
}
|
||||||
c.process(cmd)
|
c.process(cmd)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
6
redis.go
6
redis.go
|
@ -188,7 +188,11 @@ func (c *baseClient) retryBackoff(attempt int) time.Duration {
|
||||||
|
|
||||||
func (c *baseClient) cmdTimeout(cmd Cmder) time.Duration {
|
func (c *baseClient) cmdTimeout(cmd Cmder) time.Duration {
|
||||||
if timeout := cmd.readTimeout(); timeout != nil {
|
if timeout := cmd.readTimeout(); timeout != nil {
|
||||||
return readTimeout(*timeout)
|
t := *timeout
|
||||||
|
if t == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return t + 10*time.Second
|
||||||
}
|
}
|
||||||
return c.opt.ReadTimeout
|
return c.opt.ReadTimeout
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue