mirror of
https://github.com/redis/go-redis.git
synced 2025-12-18 23:34:11 +03:00
fix(retry): Add retry mechanism for NOREPLICAS error (#3647)
This commit is contained in:
14
error.go
14
error.go
@@ -124,6 +124,9 @@ func shouldRetry(err error, retryTimeout bool) bool {
|
||||
if proto.IsTryAgainError(err) {
|
||||
return true
|
||||
}
|
||||
if proto.IsNoReplicasError(err) {
|
||||
return true
|
||||
}
|
||||
|
||||
// Fallback to string checking for backward compatibility with plain errors
|
||||
s := err.Error()
|
||||
@@ -145,6 +148,9 @@ func shouldRetry(err error, retryTimeout bool) bool {
|
||||
if strings.HasPrefix(s, "MASTERDOWN ") {
|
||||
return true
|
||||
}
|
||||
if strings.HasPrefix(s, "NOREPLICAS ") {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@@ -342,6 +348,14 @@ func IsOOMError(err error) bool {
|
||||
return proto.IsOOMError(err)
|
||||
}
|
||||
|
||||
// IsNoReplicasError checks if an error is a Redis NOREPLICAS error, even if wrapped.
|
||||
// NOREPLICAS errors occur when not enough replicas acknowledge a write operation.
|
||||
// This typically happens with WAIT/WAITAOF commands or CLUSTER SETSLOT with synchronous
|
||||
// replication when the required number of replicas cannot confirm the write within the timeout.
|
||||
func IsNoReplicasError(err error) bool {
|
||||
return proto.IsNoReplicasError(err)
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
type timeoutError interface {
|
||||
|
||||
Reference in New Issue
Block a user