1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Merge pull request #101 from danmaz74/master

Fix bug with authentication and LOADING error response.
This commit is contained in:
Matt Ranney
2011-06-30 11:19:20 -07:00

View File

@@ -158,13 +158,25 @@ RedisClient.prototype.on_connect = function () {
this.stream.setTimeout(0);
if (this.auth_pass) {
var self = this;
// if redis is still loading the db, it will not authenticate and everything else will fail
function cmd_do_auth() {
if (exports.debug_mode) {
console.log("Sending auth to " + this.host + ":" + this.port + " fd " + this.stream.fd);
console.log("Sending auth to " + self.host + ":" + self.port + " fd " + self.stream.fd);
}
self.send_anyway = true;
self.send_command("auth", this.auth_pass, function (err, res) {
self.send_command("auth", self.auth_pass, function (err, res) {
if (err) {
return self.emit("error", "Auth error: " + err);
if (err.toString().match("LOADING")) {
// still loading, try to authenticate later
console.log("Redis still loading, trying to authenticate later");
setTimeout(cmd_do_auth,2000);
return;
}
else return self.emit("error", "Auth error: " + err);
}
if (res.toString() !== "OK") {
return self.emit("error", "Auth failed: " + res.toString());
@@ -176,10 +188,24 @@ RedisClient.prototype.on_connect = function () {
self.auth_callback(err, res);
self.auth_callback = null;
}
// now we are really connected
self.emit("connect");
if (self.options.no_ready_check) {
self.ready = true;
self.send_offline_queue();
} else {
self.ready_check();
}
});
self.send_anyway = false;
}
cmd_do_auth();
} else {
this.emit("connect");
if (this.options.no_ready_check) {
@@ -188,6 +214,8 @@ RedisClient.prototype.on_connect = function () {
} else {
this.ready_check();
}
}
};
RedisClient.prototype.ready_check = function () {