From 62041c519f33b3d0edfa7655ddb9f3b6190a0f31 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 2 Sep 2015 00:44:17 +0200 Subject: [PATCH] Test for statements instead of matching them if test is enough precompile regex --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 11e6a77cb2..50da18c91a 100644 --- a/index.js +++ b/index.js @@ -199,6 +199,9 @@ RedisClient.prototype.on_error = function (msg) { this.connection_gone("error"); }; +var noPasswordIsSet = /no password is set/; +var loading = /LOADING/; + RedisClient.prototype.do_auth = function () { var self = this; @@ -207,14 +210,14 @@ RedisClient.prototype.do_auth = function () { self.send_anyway = true; self.send_command("auth", [this.auth_pass], function (err, res) { if (err) { - if (err.toString().match("LOADING")) { + if (loading.test(err.message)) { // if redis is still loading the db, it will not authenticate and everything else will fail console.log("Redis still loading, trying to authenticate later"); setTimeout(function () { self.do_auth(); }, 2000); // TODO - magic number alert return; - } else if (err.toString().match("no password is set")) { + } else if (noPasswordIsSet.test(err.message)) { console.log("Warning: Redis server does not require a password, but a password was supplied."); err = null; res = "OK";