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

Retry multiple commands more conservatively.

This commit is contained in:
Vladimir Mihailenco
2016-10-13 13:56:24 +03:00
parent 21cae7f9ab
commit 8558a92fa4
4 changed files with 53 additions and 43 deletions

View File

@ -197,28 +197,31 @@ func (c *Client) Pipelined(fn func(*Pipeline) error) ([]Cmder, error) {
}
func (c *Client) pipelineExec(cmds []Cmder) error {
var retErr error
failedCmds := cmds
var firstErr error
for i := 0; i <= c.opt.MaxRetries; i++ {
if i > 0 {
resetCmds(cmds)
}
cn, _, err := c.conn()
if err != nil {
setCmdsErr(failedCmds, err)
setCmdsErr(cmds, err)
return err
}
if i > 0 {
resetCmds(failedCmds)
}
failedCmds, err = execCmds(cn, failedCmds)
retry, err := execCmds(cn, cmds)
c.putConn(cn, err, false)
if err != nil && retErr == nil {
retErr = err
if err == nil {
return nil
}
if len(failedCmds) == 0 {
if firstErr == nil {
firstErr = err
}
if !retry {
break
}
}
return retErr
return firstErr
}
func (c *Client) pubSub() *PubSub {