From d1c26e1fe6d3d6c1c8d5f1bbe7095e99a6ff719e Mon Sep 17 00:00:00 2001 From: jileizheng Date: Sun, 22 Oct 2023 22:42:05 +0800 Subject: [PATCH] recognise read only error returned from Lua script --- error.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/error.go b/error.go index d5ebad60..bf70de46 100644 --- a/error.go +++ b/error.go @@ -58,7 +58,7 @@ func shouldRetry(err error, retryTimeout bool) bool { if strings.HasPrefix(s, "LOADING ") { return true } - if strings.HasPrefix(s, "READONLY ") { + if isReadOnlyError(err) { return true } if strings.HasPrefix(s, "CLUSTERDOWN ") { @@ -137,7 +137,14 @@ func isLoadingError(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 {