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

authentication retry while server is loading db (danmaz74) [GH-101]

This commit is contained in:
Matt Ranney
2011-06-30 14:29:15 -06:00
parent f9e17556d2
commit fa272cf763

View File

@@ -144,25 +144,9 @@ function RedisClient(stream, options) {
util.inherits(RedisClient, events.EventEmitter);
exports.RedisClient = RedisClient;
RedisClient.prototype.on_connect = function () {
if (exports.debug_mode) {
console.log("Stream connected " + this.host + ":" + this.port + " fd " + this.stream.fd);
}
RedisClient.prototype.do_auth = function () {
var self = this;
this.connected = true;
this.ready = false;
this.attempts = 0;
this.connections += 1;
this.command_queue = new Queue();
this.emitted_end = false;
this.retry_timer = null;
this.current_retry_delay = this.retry_time;
this.stream.setNoDelay();
this.stream.setTimeout(0);
// 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 " + self.host + ":" + self.port + " fd " + self.stream.fd);
}
@@ -170,8 +154,11 @@ RedisClient.prototype.on_connect = function () {
self.send_command("auth", [this.auth_pass], function (err, res) {
if (err) {
if (err.toString().match("LOADING")) {
// 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(cmd_do_auth, 2000); // TODO - magic number alert
setTimeout(function () {
self.do_auth();
}, 2000); // TODO - magic number alert
return;
} else {
return self.emit("error", "Auth error: " + err);
@@ -198,10 +185,27 @@ RedisClient.prototype.on_connect = function () {
}
});
self.send_anyway = false;
};
RedisClient.prototype.on_connect = function () {
if (exports.debug_mode) {
console.log("Stream connected " + this.host + ":" + this.port + " fd " + this.stream.fd);
}
var self = this;
this.connected = true;
this.ready = false;
this.attempts = 0;
this.connections += 1;
this.command_queue = new Queue();
this.emitted_end = false;
this.retry_timer = null;
this.current_retry_delay = this.retry_time;
this.stream.setNoDelay();
this.stream.setTimeout(0);
if (this.auth_pass) {
cmd_do_auth();
this.do_auth();
} else {
this.emit("connect");