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

Set read/write timeouts more consistently.

This commit is contained in:
Vladimir Mihailenco
2016-12-03 17:30:13 +02:00
parent e7f23a300b
commit b4efc45f1c
18 changed files with 343 additions and 198 deletions

12
tx.go
View File

@ -45,11 +45,11 @@ func (c *Client) Watch(fn func(*Tx) error, keys ...string) error {
return err
}
}
retErr := fn(tx)
if err := tx.close(); err != nil && retErr == nil {
retErr = err
firstErr := fn(tx)
if err := tx.close(); err != nil && firstErr == nil {
firstErr = err
}
return retErr
return firstErr
}
// close closes the transaction, releasing any open resources.
@ -133,12 +133,16 @@ func (c *Tx) exec(cmds []Cmder) error {
}
func (c *Tx) execCmds(cn *pool.Conn, cmds []Cmder) error {
cn.SetWriteTimeout(c.opt.WriteTimeout)
err := writeCmd(cn, cmds...)
if err != nil {
setCmdsErr(cmds[1:len(cmds)-1], err)
return err
}
// Set read timeout for all commands.
cn.SetReadTimeout(c.opt.ReadTimeout)
// Omit last command (EXEC).
cmdsLen := len(cmds) - 1