Skip to content

Commit

Permalink
Merge pull request redis#978 from go-redis/fix/lua-readonly-error
Browse files Browse the repository at this point in the history
Retry master node on readonly errors. Fixes redis#977
  • Loading branch information
vmihailenco authored Feb 27, 2019
2 parents bd54208 + ac9e1ab commit d22fde8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ func (c *ClusterClient) Watch(fn func(*Tx) error, keys ...string) error {
continue
}

if err == pool.ErrClosed {
if err == pool.ErrClosed || internal.IsReadOnlyError(err) {
node, err = c.slotMasterNode(slot)
if err != nil {
return err
Expand Down Expand Up @@ -960,7 +960,7 @@ func (c *ClusterClient) defaultProcess(cmd Cmder) error {
continue
}

if err == pool.ErrClosed {
if err == pool.ErrClosed || internal.IsReadOnlyError(err) {
node = nil
continue
}
Expand Down
7 changes: 6 additions & 1 deletion internal/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func IsBadConn(err error, allowTimeout bool) bool {
return false
}
if IsRedisError(err) {
return strings.HasPrefix(err.Error(), "READONLY ")
// #790
return IsReadOnlyError(err)
}
if allowTimeout {
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
Expand Down Expand Up @@ -82,3 +83,7 @@ func IsMovedError(err error) (moved bool, ask bool, addr string) {
func IsLoadingError(err error) bool {
return strings.HasPrefix(err.Error(), "LOADING ")
}

func IsReadOnlyError(err error) bool {
return strings.HasPrefix(err.Error(), "READONLY ")
}

0 comments on commit d22fde8

Please sign in to comment.