1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

Cancel sleep when context is cancelled

This commit is contained in:
Vladimir Mihailenco
2019-07-30 12:13:00 +03:00
parent 6d8db67ef5
commit c837612911
6 changed files with 58 additions and 16 deletions

View File

@ -244,7 +244,9 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
func (c *baseClient) process(ctx context.Context, cmd Cmder) error {
for attempt := 0; attempt <= c.opt.MaxRetries; attempt++ {
if attempt > 0 {
time.Sleep(c.retryBackoff(attempt))
if err := internal.Sleep(ctx, c.retryBackoff(attempt)); err != nil {
return err
}
}
cn, err := c.getConn(ctx)
@ -331,7 +333,9 @@ func (c *baseClient) generalProcessPipeline(
) error {
for attempt := 0; attempt <= c.opt.MaxRetries; attempt++ {
if attempt > 0 {
time.Sleep(c.retryBackoff(attempt))
if err := internal.Sleep(ctx, c.retryBackoff(attempt)); err != nil {
return err
}
}
cn, err := c.getConn(ctx)