Skip to content

Commit d22fde8

Browse files
authored
Merge pull request redis#978 from go-redis/fix/lua-readonly-error
Retry master node on readonly errors. Fixes redis#977
2 parents bd54208 + ac9e1ab commit d22fde8

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

cluster.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ func (c *ClusterClient) Watch(fn func(*Tx) error, keys ...string) error {
862862
continue
863863
}
864864

865-
if err == pool.ErrClosed {
865+
if err == pool.ErrClosed || internal.IsReadOnlyError(err) {
866866
node, err = c.slotMasterNode(slot)
867867
if err != nil {
868868
return err
@@ -960,7 +960,7 @@ func (c *ClusterClient) defaultProcess(cmd Cmder) error {
960960
continue
961961
}
962962

963-
if err == pool.ErrClosed {
963+
if err == pool.ErrClosed || internal.IsReadOnlyError(err) {
964964
node = nil
965965
continue
966966
}

internal/error.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ func IsBadConn(err error, allowTimeout bool) bool {
4747
return false
4848
}
4949
if IsRedisError(err) {
50-
return strings.HasPrefix(err.Error(), "READONLY ")
50+
// #790
51+
return IsReadOnlyError(err)
5152
}
5253
if allowTimeout {
5354
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
@@ -82,3 +83,7 @@ func IsMovedError(err error) (moved bool, ask bool, addr string) {
8283
func IsLoadingError(err error) bool {
8384
return strings.HasPrefix(err.Error(), "LOADING ")
8485
}
86+
87+
func IsReadOnlyError(err error) bool {
88+
return strings.HasPrefix(err.Error(), "READONLY ")
89+
}

0 commit comments

Comments
 (0)