diff --git a/cluster.go b/cluster.go index 5ac079c7..a31559bf 100644 --- a/cluster.go +++ b/cluster.go @@ -195,12 +195,12 @@ func (c *ClusterClient) process(cmd Cmder) { // If there is no (real) error, we are done! err := cmd.Err() - if err == nil || err == Nil || err == TxFailedErr { + if err == nil { return } // On network errors try random node. - if isNetworkError(err) { + if shouldRetry(err) { client, err = c.randomClient() if err != nil { return diff --git a/error.go b/error.go index 3f2a560c..f0b27a84 100644 --- a/error.go +++ b/error.go @@ -25,6 +25,11 @@ func (err redisError) Error() string { return err.s } +func isInternalError(err error) bool { + _, ok := err.(redisError) + return ok +} + func isNetworkError(err error) bool { if err == io.EOF { return true @@ -37,7 +42,7 @@ func isBadConn(err error, allowTimeout bool) bool { if err == nil { return false } - if _, ok := err.(redisError); ok { + if isInternalError(err) { return false } if allowTimeout { @@ -53,27 +58,24 @@ func isMovedError(err error) (moved bool, ask bool, addr string) { return } - parts := strings.SplitN(err.Error(), " ", 3) - if len(parts) != 3 { + s := err.Error() + if strings.HasPrefix(s, "MOVED ") { + moved = true + } else if strings.HasPrefix(s, "ASK ") { + ask = true + } else { return } - switch parts[0] { - case "MOVED": - moved = true - addr = parts[2] - case "ASK": - ask = true - addr = parts[2] + ind := strings.LastIndexByte(s, ' ') + if ind == -1 { + return false, false, "" } - + addr = s[ind+1:] return } // shouldRetry reports whether failed command should be retried. func shouldRetry(err error) bool { - if err == nil { - return false - } return isNetworkError(err) } diff --git a/redis.go b/redis.go index aaa0dac8..27b7b614 100644 --- a/redis.go +++ b/redis.go @@ -104,7 +104,7 @@ func (c *baseClient) process(cmd Cmder) { if err := writeCmd(cn, cmd); err != nil { c.putConn(cn, err, false) cmd.setErr(err) - if shouldRetry(err) { + if err != nil && shouldRetry(err) { continue } return @@ -112,7 +112,7 @@ func (c *baseClient) process(cmd Cmder) { err = cmd.readReply(cn) c.putConn(cn, err, readTimeout != nil) - if shouldRetry(err) { + if err != nil && shouldRetry(err) { continue }