Skip to content
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 @@ -85,7 +85,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, "MASTERDOWN ") {
Expand Down Expand Up @@ -169,7 +169,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
Loading