You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Fix regression in reconnect logic.
Very much need automated tests for reconnection and queue logic.
This commit is contained in:
@@ -1,6 +1,12 @@
|
|||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
## v0.7.1 - November 15, 2011
|
||||||
|
|
||||||
|
Fix regression in reconnect logic.
|
||||||
|
|
||||||
|
Very much need automated tests for reconnection and queue logic.
|
||||||
|
|
||||||
## v0.7.0 - November 14, 2011
|
## v0.7.0 - November 14, 2011
|
||||||
|
|
||||||
Many contributed fixes. Thanks everybody.
|
Many contributed fixes. Thanks everybody.
|
||||||
|
26
index.js
26
index.js
@@ -33,7 +33,6 @@ function RedisClient(stream, options) {
|
|||||||
this.connected = false;
|
this.connected = false;
|
||||||
this.ready = false;
|
this.ready = false;
|
||||||
this.connections = 0;
|
this.connections = 0;
|
||||||
this.attempts = 1;
|
|
||||||
this.should_buffer = false;
|
this.should_buffer = false;
|
||||||
this.command_queue_high_water = this.options.command_queue_high_water || 1000;
|
this.command_queue_high_water = this.options.command_queue_high_water || 1000;
|
||||||
this.command_queue_low_water = this.options.command_queue_low_water || 0;
|
this.command_queue_low_water = this.options.command_queue_low_water || 0;
|
||||||
@@ -48,9 +47,7 @@ function RedisClient(stream, options) {
|
|||||||
if (options.connect_timeout && !isNaN(options.connect_timeout) && options.connect_timeout > 0) {
|
if (options.connect_timeout && !isNaN(options.connect_timeout) && options.connect_timeout > 0) {
|
||||||
this.connect_timeout = +options.connect_timeout;
|
this.connect_timeout = +options.connect_timeout;
|
||||||
}
|
}
|
||||||
this.retry_totaltime = 0;
|
this.initialize_retry_vars();
|
||||||
this.retry_delay = 250;
|
|
||||||
this.retry_backoff = 1.7;
|
|
||||||
this.subscriptions = false;
|
this.subscriptions = false;
|
||||||
this.monitoring = false;
|
this.monitoring = false;
|
||||||
this.closing = false;
|
this.closing = false;
|
||||||
@@ -91,6 +88,14 @@ function RedisClient(stream, options) {
|
|||||||
util.inherits(RedisClient, events.EventEmitter);
|
util.inherits(RedisClient, events.EventEmitter);
|
||||||
exports.RedisClient = RedisClient;
|
exports.RedisClient = RedisClient;
|
||||||
|
|
||||||
|
RedisClient.prototype.initialize_retry_vars = function () {
|
||||||
|
this.retry_timer = null;
|
||||||
|
this.retry_totaltime = 0;
|
||||||
|
this.retry_delay = 250;
|
||||||
|
this.retry_backoff = 1.7;
|
||||||
|
this.attempts = 1;
|
||||||
|
};
|
||||||
|
|
||||||
// flush offline_queue and command_queue, erroring any items with a callback first
|
// flush offline_queue and command_queue, erroring any items with a callback first
|
||||||
RedisClient.prototype.flush_and_error = function (message) {
|
RedisClient.prototype.flush_and_error = function (message) {
|
||||||
var command_obj;
|
var command_obj;
|
||||||
@@ -194,10 +199,7 @@ RedisClient.prototype.on_connect = function () {
|
|||||||
this.connections += 1;
|
this.connections += 1;
|
||||||
this.command_queue = new Queue();
|
this.command_queue = new Queue();
|
||||||
this.emitted_end = false;
|
this.emitted_end = false;
|
||||||
this.max_attempts = 0;
|
this.initialize_retry_vars();
|
||||||
this.retry_totaltime = 0;
|
|
||||||
this.retry_timer = null;
|
|
||||||
this.current_retry_delay = this.retry_delay;
|
|
||||||
this.stream.setNoDelay();
|
this.stream.setNoDelay();
|
||||||
this.stream.setTimeout(0);
|
this.stream.setTimeout(0);
|
||||||
|
|
||||||
@@ -373,7 +375,7 @@ RedisClient.prototype.connection_gone = function (why) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.current_retry_delay = this.current_retry_delay * this.retry_backoff;
|
this.retry_delay = Math.floor(this.retry_delay * this.retry_backoff);
|
||||||
|
|
||||||
if (exports.debug_mode) {
|
if (exports.debug_mode) {
|
||||||
console.log("Retry connection in " + this.current_retry_delay + " ms");
|
console.log("Retry connection in " + this.current_retry_delay + " ms");
|
||||||
@@ -387,8 +389,8 @@ RedisClient.prototype.connection_gone = function (why) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.attempts += 1;
|
this.attempts += 1;
|
||||||
self.emit("reconnecting", {
|
this.emit("reconnecting", {
|
||||||
delay: self.retry_delay,
|
delay: self.retry_delay,
|
||||||
attempt: self.attempts
|
attempt: self.attempts
|
||||||
});
|
});
|
||||||
@@ -408,7 +410,7 @@ RedisClient.prototype.connection_gone = function (why) {
|
|||||||
|
|
||||||
self.stream.connect(self.port, self.host);
|
self.stream.connect(self.port, self.host);
|
||||||
self.retry_timer = null;
|
self.retry_timer = null;
|
||||||
}, this.current_retry_delay);
|
}, this.retry_delay);
|
||||||
};
|
};
|
||||||
|
|
||||||
RedisClient.prototype.on_data = function (data) {
|
RedisClient.prototype.on_data = function (data) {
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
{ "name" : "redis",
|
{ "name" : "redis",
|
||||||
"version" : "0.7.0",
|
"version" : "0.7.1",
|
||||||
"description" : "Redis client library",
|
"description" : "Redis client library",
|
||||||
"author": "Matt Ranney <mjr@ranney.com>",
|
"author": "Matt Ranney <mjr@ranney.com>",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
var redis = require("../index").createClient(null, null, {
|
var redis = require("../index").createClient(null, null, {
|
||||||
max_attempts: 2
|
// max_attempts: 4
|
||||||
});
|
});
|
||||||
|
|
||||||
redis.on("error", function (err) {
|
redis.on("error", function (err) {
|
||||||
@@ -13,9 +13,6 @@ redis.on("ready", function () {
|
|||||||
redis.on("reconnecting", function (arg) {
|
redis.on("reconnecting", function (arg) {
|
||||||
console.log("Redis reconnecting: " + JSON.stringify(arg));
|
console.log("Redis reconnecting: " + JSON.stringify(arg));
|
||||||
});
|
});
|
||||||
redis.on("not_reconnecting", function (arg) {
|
|
||||||
console.log("Redis NOT reconnecting: " + arg);
|
|
||||||
});
|
|
||||||
redis.on("connect", function () {
|
redis.on("connect", function () {
|
||||||
console.log("Redis connected.");
|
console.log("Redis connected.");
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user