diff --git a/index.js b/index.js index b87850b9ea..50da18c91a 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ var net = require("net"), URL = require("url"), - util = require("./lib/util"), + util = require("util"), Queue = require("./lib/queue"), to_array = require("./lib/to_array"), events = require("events"), @@ -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"; @@ -302,11 +305,7 @@ RedisClient.prototype.init_parser = function () { // "reply error" is an error sent back by Redis this.reply_parser.on("reply error", function (reply) { - if (reply instanceof Error) { - self.return_error(reply); - } else { - self.return_error(new Error(reply)); - } + self.return_error(reply); }); this.reply_parser.on("reply", function (reply) { self.return_reply(reply); @@ -654,7 +653,9 @@ RedisClient.prototype.return_reply = function (reply) { } try_callback(command_obj.callback, reply); - } else debug("no callback for reply: " + (reply && reply.toString && reply.toString())); + } else { + debug("no callback for reply: " + (reply && reply.toString && reply.toString())); + } } else if (this.pub_sub_mode || (command_obj && command_obj.sub_command)) { if (Array.isArray(reply)) { type = reply[0].toString(); diff --git a/lib/parser/hiredis.js b/lib/parser/hiredis.js index f588bcc185..d1fd0b7a9a 100644 --- a/lib/parser/hiredis.js +++ b/lib/parser/hiredis.js @@ -1,7 +1,7 @@ 'use strict'; var events = require("events"), - util = require("../util"), + util = require("util"), hiredis = require("hiredis"); exports.name = "hiredis"; diff --git a/lib/parser/javascript.js b/lib/parser/javascript.js index 15f8390900..be5248d115 100644 --- a/lib/parser/javascript.js +++ b/lib/parser/javascript.js @@ -1,7 +1,7 @@ 'use strict'; var events = require("events"), - util = require("../util"); + util = require("util"); function Packet(type, size) { this.type = type; @@ -177,8 +177,7 @@ ReplyParser.prototype.execute = function (buffer) { if (ret === null) { break; } - - this.send_error(ret); + this.send_error(new Error(ret)); } else if (type === 58) { // : ret = this._parseResult(type); diff --git a/lib/util.js b/lib/util.js deleted file mode 100644 index 359cd7e948..0000000000 --- a/lib/util.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -// Support for very old versions of node where the module was called "sys". At some point, we should abandon this. - -var util; - -try { - util = require("util"); -} catch (err) { - util = require("sys"); -} - -module.exports = util;