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

Retry timeout and retryable error

This commit is contained in:
Vladimir Mihailenco
2020-07-24 14:57:12 +03:00
parent 16e62e05a1
commit 21a1f58caf
5 changed files with 23 additions and 12 deletions

View File

@ -24,15 +24,16 @@ type Error interface {
var _ Error = proto.RedisError("")
func isRetryableError(err error, retryTimeout bool) bool {
func shouldRetry(err error, retryTimeout bool) bool {
switch err {
case io.EOF, io.ErrUnexpectedEOF:
return true
case nil, context.Canceled, context.DeadlineExceeded:
return false
case io.EOF:
return true
}
if netErr, ok := err.(net.Error); ok {
if netErr.Timeout() {
if v, ok := err.(timeoutError); ok {
if v.Timeout() {
return retryTimeout
}
return true
@ -51,6 +52,7 @@ func isRetryableError(err error, retryTimeout bool) bool {
if strings.HasPrefix(s, "CLUSTERDOWN ") {
return true
}
return false
}
@ -63,16 +65,19 @@ func isBadConn(err error, allowTimeout bool) bool {
if err == nil {
return false
}
if isRedisError(err) {
// Close connections in read only state in case domain addr is used
// and domain resolves to a different Redis Server. See #790.
return isReadOnlyError(err)
}
if allowTimeout {
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
return false
return !netErr.Temporary()
}
}
return true
}
@ -106,3 +111,9 @@ func isLoadingError(err error) bool {
func isReadOnlyError(err error) bool {
return strings.HasPrefix(err.Error(), "READONLY ")
}
//------------------------------------------------------------------------------
type timeoutError interface {
Timeout() bool
}