Retry master node on readonly errors. Fixes #977

This commit is contained in:
Vladimir Mihailenco 2019-02-27 12:53:44 +02:00
parent bd542089bb
commit ac9e1abf54
2 changed files with 8 additions and 3 deletions

View File

@ -862,7 +862,7 @@ func (c *ClusterClient) Watch(fn func(*Tx) error, keys ...string) error {
continue continue
} }
if err == pool.ErrClosed { if err == pool.ErrClosed || internal.IsReadOnlyError(err) {
node, err = c.slotMasterNode(slot) node, err = c.slotMasterNode(slot)
if err != nil { if err != nil {
return err return err
@ -960,7 +960,7 @@ func (c *ClusterClient) defaultProcess(cmd Cmder) error {
continue continue
} }
if err == pool.ErrClosed { if err == pool.ErrClosed || internal.IsReadOnlyError(err) {
node = nil node = nil
continue continue
} }

View File

@ -47,7 +47,8 @@ func IsBadConn(err error, allowTimeout bool) bool {
return false return false
} }
if IsRedisError(err) { if IsRedisError(err) {
return strings.HasPrefix(err.Error(), "READONLY ") // #790
return IsReadOnlyError(err)
} }
if allowTimeout { if allowTimeout {
if netErr, ok := err.(net.Error); ok && netErr.Timeout() { if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
@ -82,3 +83,7 @@ func IsMovedError(err error) (moved bool, ask bool, addr string) {
func IsLoadingError(err error) bool { func IsLoadingError(err error) bool {
return strings.HasPrefix(err.Error(), "LOADING ") return strings.HasPrefix(err.Error(), "LOADING ")
} }
func IsReadOnlyError(err error) bool {
return strings.HasPrefix(err.Error(), "READONLY ")
}