Skip to content

recognise read only error returned from Lua script #2770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ") {
Expand Down Expand Up @@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be more strict here? I assume one can easily use a command with working on a "something-readonly" key and trigger an error that will return true for containing "-readonly"

}

func isMovedSameConnAddr(err error, addr string) bool {
Expand Down