1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

Merge pull request #809 from fintura/stuff

Remove some old stuff that is not needed anymore and fix js parser sending non-Errors as errors.
This commit is contained in:
Ruben Bridgewater
2015-09-02 22:22:32 +02:00
4 changed files with 13 additions and 26 deletions

View File

@@ -4,7 +4,7 @@
var net = require("net"), var net = require("net"),
URL = require("url"), URL = require("url"),
util = require("./lib/util"), util = require("util"),
Queue = require("./lib/queue"), Queue = require("./lib/queue"),
to_array = require("./lib/to_array"), to_array = require("./lib/to_array"),
events = require("events"), events = require("events"),
@@ -199,6 +199,9 @@ RedisClient.prototype.on_error = function (msg) {
this.connection_gone("error"); this.connection_gone("error");
}; };
var noPasswordIsSet = /no password is set/;
var loading = /LOADING/;
RedisClient.prototype.do_auth = function () { RedisClient.prototype.do_auth = function () {
var self = this; var self = this;
@@ -207,14 +210,14 @@ RedisClient.prototype.do_auth = function () {
self.send_anyway = true; self.send_anyway = true;
self.send_command("auth", [this.auth_pass], function (err, res) { self.send_command("auth", [this.auth_pass], function (err, res) {
if (err) { 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 // 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"); console.log("Redis still loading, trying to authenticate later");
setTimeout(function () { setTimeout(function () {
self.do_auth(); self.do_auth();
}, 2000); // TODO - magic number alert }, 2000); // TODO - magic number alert
return; 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."); console.log("Warning: Redis server does not require a password, but a password was supplied.");
err = null; err = null;
res = "OK"; res = "OK";
@@ -302,11 +305,7 @@ RedisClient.prototype.init_parser = function () {
// "reply error" is an error sent back by Redis // "reply error" is an error sent back by Redis
this.reply_parser.on("reply error", function (reply) { this.reply_parser.on("reply error", function (reply) {
if (reply instanceof Error) { self.return_error(reply);
self.return_error(reply);
} else {
self.return_error(new Error(reply));
}
}); });
this.reply_parser.on("reply", function (reply) { this.reply_parser.on("reply", function (reply) {
self.return_reply(reply); self.return_reply(reply);
@@ -654,7 +653,9 @@ RedisClient.prototype.return_reply = function (reply) {
} }
try_callback(command_obj.callback, 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)) { } else if (this.pub_sub_mode || (command_obj && command_obj.sub_command)) {
if (Array.isArray(reply)) { if (Array.isArray(reply)) {
type = reply[0].toString(); type = reply[0].toString();

View File

@@ -1,7 +1,7 @@
'use strict'; 'use strict';
var events = require("events"), var events = require("events"),
util = require("../util"), util = require("util"),
hiredis = require("hiredis"); hiredis = require("hiredis");
exports.name = "hiredis"; exports.name = "hiredis";

View File

@@ -1,7 +1,7 @@
'use strict'; 'use strict';
var events = require("events"), var events = require("events"),
util = require("../util"); util = require("util");
function Packet(type, size) { function Packet(type, size) {
this.type = type; this.type = type;
@@ -177,8 +177,7 @@ ReplyParser.prototype.execute = function (buffer) {
if (ret === null) { if (ret === null) {
break; break;
} }
this.send_error(new Error(ret));
this.send_error(ret);
} else if (type === 58) { // : } else if (type === 58) { // :
ret = this._parseResult(type); ret = this._parseResult(type);

View File

@@ -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;