diff --git a/commands.go b/commands.go index 9954cab1..e9a8992f 100644 --- a/commands.go +++ b/commands.go @@ -8,13 +8,6 @@ import ( "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 { return dur < time.Second || dur%time.Second != 0 } @@ -1397,6 +1390,9 @@ func (c *cmdable) XRead(a *XReadArgs) *XStreamSliceCmd { } cmd := NewXStreamSliceCmd(args...) + if a.Block >= 0 { + cmd.setReadTimeout(a.Block) + } c.process(cmd) return cmd } @@ -1455,6 +1451,9 @@ func (c *cmdable) XReadGroup(a *XReadGroupArgs) *XStreamSliceCmd { } cmd := NewXStreamSliceCmd(args...) + if a.Block >= 0 { + cmd.setReadTimeout(a.Block) + } c.process(cmd) return cmd } diff --git a/redis.go b/redis.go index 3e72bf06..8fa85ddf 100644 --- a/redis.go +++ b/redis.go @@ -188,7 +188,11 @@ func (c *baseClient) retryBackoff(attempt int) time.Duration { func (c *baseClient) cmdTimeout(cmd Cmder) time.Duration { 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 }