Skip to content

Commit

Permalink
docs(README): adjust README reconnectOnError code sample (#1089)
Browse files Browse the repository at this point in the history
The existing README code sample checks for an error message that begins
with the string READONLY however if the error is produced from a lua
script the condition would not match it. A lua script READONLY error
looks like this:

ERR Error running script (call to
f_45e87c07f6aff394093b73766a458691d0460655): @user_script:1:
@user_script: 1: -READONLY You can't write against a read only replica.

This changes the sample to instead check for READONLY as a substring
  • Loading branch information
alavers authored Apr 4, 2020
1 parent f275bc2 commit e22cae6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,8 @@ Besides auto-reconnect when the connection is closed, ioredis supports reconnect
var redis = new Redis({
reconnectOnError: function (err) {
var targetError = "READONLY";
if (err.message.slice(0, targetError.length) === targetError) {
// Only reconnect when the error starts with "READONLY"
if (err.message.includes(targetError)) {
// Only reconnect when the error contains "READONLY"
return true; // or `return 1;`
}
},
Expand Down

2 comments on commit e22cae6

@tuananh
Copy link
Contributor

@tuananh tuananh commented on e22cae6 Apr 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tuananh
Copy link
Contributor

@tuananh tuananh commented on e22cae6 Apr 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my bad. Didn't see the PR

Please sign in to comment.