From e22cae6282e7f45410f9851745f3d53f412f36c9 Mon Sep 17 00:00:00 2001 From: Andrew Lavers Date: Sat, 4 Apr 2020 02:22:37 -0400 Subject: [PATCH] docs(README): adjust README reconnectOnError code sample (#1089) 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 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 271cd8b7..99879bf2 100644 --- a/README.md +++ b/README.md @@ -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;` } },