1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-29 17:41:15 +03:00

Use Context.Deadline to set net.Conn deadline

This commit is contained in:
Vladimir Mihailenco
2019-06-08 15:02:51 +03:00
parent 4fe609d47c
commit 5460bc10f2
5 changed files with 57 additions and 46 deletions

View File

@ -1,6 +1,7 @@
package redis
import (
"context"
"errors"
"fmt"
"strings"
@ -83,8 +84,8 @@ func (c *PubSub) _conn(newChannels []string) (*pool.Conn, error) {
return cn, nil
}
func (c *PubSub) writeCmd(cn *pool.Conn, cmd Cmder) error {
return cn.WithWriter(c.opt.WriteTimeout, func(wr *proto.Writer) error {
func (c *PubSub) writeCmd(ctx context.Context, cn *pool.Conn, cmd Cmder) error {
return cn.WithWriter(ctx, c.opt.WriteTimeout, func(wr *proto.Writer) error {
return writeCmd(wr, cmd)
})
}
@ -128,7 +129,7 @@ func (c *PubSub) _subscribe(
args = append(args, channel)
}
cmd := NewSliceCmd(args...)
return c.writeCmd(cn, cmd)
return c.writeCmd(context.TODO(), cn, cmd)
}
func (c *PubSub) releaseConn(cn *pool.Conn, err error, allowTimeout bool) {
@ -258,7 +259,7 @@ func (c *PubSub) Ping(payload ...string) error {
return err
}
err = c.writeCmd(cn, cmd)
err = c.writeCmd(context.TODO(), cn, cmd)
c.releaseConn(cn, err, false)
return err
}
@ -350,7 +351,7 @@ func (c *PubSub) ReceiveTimeout(timeout time.Duration) (interface{}, error) {
return nil, err
}
err = cn.WithReader(timeout, func(rd *proto.Reader) error {
err = cn.WithReader(context.TODO(), timeout, func(rd *proto.Reader) error {
return c.cmd.readReply(rd)
})