Skip to content

Commit d1c26e1

Browse files
committed
recognise read only error returned from Lua script
1 parent af4872c commit d1c26e1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

error.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func shouldRetry(err error, retryTimeout bool) bool {
5858
if strings.HasPrefix(s, "LOADING ") {
5959
return true
6060
}
61-
if strings.HasPrefix(s, "READONLY ") {
61+
if isReadOnlyError(err) {
6262
return true
6363
}
6464
if strings.HasPrefix(s, "CLUSTERDOWN ") {
@@ -137,7 +137,14 @@ func isLoadingError(err error) bool {
137137
}
138138

139139
func isReadOnlyError(err error) bool {
140-
return strings.HasPrefix(err.Error(), "READONLY ")
140+
redisError := err.Error()
141+
if strings.HasPrefix(redisError, "READONLY ") {
142+
return true
143+
}
144+
145+
// For a Lua script that includes a write command, the error string
146+
// contains "-READONLY" rather than beginning with "READONLY "
147+
return strings.Contains(redisError, "-READONLY")
141148
}
142149

143150
func isMovedSameConnAddr(err error, addr string) bool {

0 commit comments

Comments
 (0)