Skip to content

Commit 62041c5

Browse files
author
Ruben Bridgewater
committed
Test for statements instead of matching them if test is enough
precompile regex
1 parent 19db6d1 commit 62041c5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ RedisClient.prototype.on_error = function (msg) {
199199
this.connection_gone("error");
200200
};
201201

202+
var noPasswordIsSet = /no password is set/;
203+
var loading = /LOADING/;
204+
202205
RedisClient.prototype.do_auth = function () {
203206
var self = this;
204207

@@ -207,14 +210,14 @@ RedisClient.prototype.do_auth = function () {
207210
self.send_anyway = true;
208211
self.send_command("auth", [this.auth_pass], function (err, res) {
209212
if (err) {
210-
if (err.toString().match("LOADING")) {
213+
if (loading.test(err.message)) {
211214
// if redis is still loading the db, it will not authenticate and everything else will fail
212215
console.log("Redis still loading, trying to authenticate later");
213216
setTimeout(function () {
214217
self.do_auth();
215218
}, 2000); // TODO - magic number alert
216219
return;
217-
} else if (err.toString().match("no password is set")) {
220+
} else if (noPasswordIsSet.test(err.message)) {
218221
console.log("Warning: Redis server does not require a password, but a password was supplied.");
219222
err = null;
220223
res = "OK";

0 commit comments

Comments
 (0)