@@ -47,7 +47,7 @@ func shouldRetry(err error, retryTimeout bool) bool {
4747 if strings .HasPrefix (s , "LOADING " ) {
4848 return true
4949 }
50- if strings . HasPrefix ( s , "READONLY " ) {
50+ if IsReadOnlyError ( err ) {
5151 return true
5252 }
5353 if strings .HasPrefix (s , "CLUSTERDOWN " ) {
@@ -75,7 +75,7 @@ func isBadConn(err error, allowTimeout bool, addr string) bool {
7575
7676 if isRedisError (err ) {
7777 switch {
78- case isReadOnlyError (err ):
78+ case IsReadOnlyError (err ):
7979 // Close connections in read only state in case domain addr is used
8080 // and domain resolves to a different Redis Server. See #790.
8181 return true
@@ -125,8 +125,15 @@ func isLoadingError(err error) bool {
125125 return strings .HasPrefix (err .Error (), "LOADING " )
126126}
127127
128- func isReadOnlyError (err error ) bool {
129- return strings .HasPrefix (err .Error (), "READONLY " )
128+ func IsReadOnlyError (err error ) bool {
129+ redisError := err .Error ()
130+ if strings .HasPrefix (redisError , "READONLY " ) {
131+ return true
132+ }
133+
134+ // For a Lua script that includes write commands, the read-only error string
135+ // contains "-READONLY" rather than beginning with "READONLY "
136+ return strings .Contains (redisError , "-READONLY" )
130137}
131138
132139func isMovedSameConnAddr (err error , addr string ) bool {
0 commit comments