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

Cleanup error handling code.

This commit is contained in:
Vladimir Mihailenco
2016-03-19 16:33:14 +02:00
parent d2ae7d8707
commit 30ce5ebd57
3 changed files with 20 additions and 18 deletions

View File

@ -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)
}