recognise read only error returned from Lua script

This commit is contained in:
jileizheng 2023-10-22 22:42:05 +08:00
parent af4872cbd0
commit d1c26e1fe6
1 changed files with 9 additions and 2 deletions

View File

@ -58,7 +58,7 @@ func shouldRetry(err error, retryTimeout bool) bool {
if strings.HasPrefix(s, "LOADING ") { if strings.HasPrefix(s, "LOADING ") {
return true return true
} }
if strings.HasPrefix(s, "READONLY ") { if isReadOnlyError(err) {
return true return true
} }
if strings.HasPrefix(s, "CLUSTERDOWN ") { if strings.HasPrefix(s, "CLUSTERDOWN ") {
@ -137,7 +137,14 @@ func isLoadingError(err error) bool {
} }
func isReadOnlyError(err error) bool { func isReadOnlyError(err error) bool {
return strings.HasPrefix(err.Error(), "READONLY ") redisError := err.Error()
if strings.HasPrefix(redisError, "READONLY ") {
return true
}
// For a Lua script that includes a write command, the error string
// contains "-READONLY" rather than beginning with "READONLY "
return strings.Contains(redisError, "-READONLY")
} }
func isMovedSameConnAddr(err error, addr string) bool { func isMovedSameConnAddr(err error, addr string) bool {