You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Add QUIT command for orderly shutdown.
This commit is contained in:
17
index.js
17
index.js
@@ -305,6 +305,7 @@ function RedisClient(stream) {
|
|||||||
this.retry_delay = 250;
|
this.retry_delay = 250;
|
||||||
this.retry_backoff = 1.7;
|
this.retry_backoff = 1.7;
|
||||||
this.subscriptions = false;
|
this.subscriptions = false;
|
||||||
|
this.closing = false;
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
@@ -349,6 +350,9 @@ function RedisClient(stream) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.stream.on("error", function (msg) {
|
this.stream.on("error", function (msg) {
|
||||||
|
if (this.closing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (exports.debug_mode) {
|
if (exports.debug_mode) {
|
||||||
console.warn("Connecting to redis server: " + msg);
|
console.warn("Connecting to redis server: " + msg);
|
||||||
}
|
}
|
||||||
@@ -377,6 +381,7 @@ sys.inherits(RedisClient, events.EventEmitter);
|
|||||||
RedisClient.prototype.connection_gone = function () {
|
RedisClient.prototype.connection_gone = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
// If a retry is already in progress, just let that happen
|
||||||
if (self.retry_timer) {
|
if (self.retry_timer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -391,6 +396,13 @@ RedisClient.prototype.connection_gone = function () {
|
|||||||
args[2]("Server connection closed");
|
args[2]("Server connection closed");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If this is a requested shutdown, then don't retry
|
||||||
|
if (self.closing) {
|
||||||
|
self.retry_timer = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (exports.debug_mode) {
|
if (exports.debug_mode) {
|
||||||
console.log("Retry conneciton in " + self.retry_delay + " ms");
|
console.log("Retry conneciton in " + self.retry_delay + " ms");
|
||||||
}
|
}
|
||||||
@@ -526,6 +538,9 @@ RedisClient.prototype.send_command = function () {
|
|||||||
if (this.subscriptions === true) {
|
if (this.subscriptions === true) {
|
||||||
throw new Error("Connection in pub/sub mode, only pub/sub commands may be used");
|
throw new Error("Connection in pub/sub mode, only pub/sub commands may be used");
|
||||||
}
|
}
|
||||||
|
if (command === "QUIT") {
|
||||||
|
this.closing = true;
|
||||||
|
}
|
||||||
this.command_queue.push(command_obj);
|
this.command_queue.push(command_obj);
|
||||||
}
|
}
|
||||||
this.commands_sent += 1;
|
this.commands_sent += 1;
|
||||||
@@ -592,6 +607,8 @@ RedisClient.prototype.end = function () {
|
|||||||
|
|
||||||
// http://code.google.com/p/redis/wiki/CommandReference
|
// http://code.google.com/p/redis/wiki/CommandReference
|
||||||
exports.commands = [
|
exports.commands = [
|
||||||
|
// Connection handling
|
||||||
|
"QUIT", "AUTH",
|
||||||
// Commands operating on all value types
|
// Commands operating on all value types
|
||||||
"EXISTS", "DEL", "TYPE", "KEYS", "RANDOMKEY", "RENAME", "RENAMENX", "DBSIZE", "EXPIRE", "TTL", "SELECT",
|
"EXISTS", "DEL", "TYPE", "KEYS", "RANDOMKEY", "RENAME", "RENAMENX", "DBSIZE", "EXPIRE", "TTL", "SELECT",
|
||||||
"MOVE", "FLUSHDB", "FLUSHALL",
|
"MOVE", "FLUSHDB", "FLUSHALL",
|
||||||
|
4
test.js
4
test.js
@@ -369,8 +369,8 @@ function run_next_test() {
|
|||||||
tests[test_name]();
|
tests[test_name]();
|
||||||
} else {
|
} else {
|
||||||
console.log('\n completed \x1b[32m%d\x1b[0m tests in \x1b[33m%d\x1b[0m ms\n', test_count, new Date - all_start);
|
console.log('\n completed \x1b[32m%d\x1b[0m tests in \x1b[33m%d\x1b[0m ms\n', test_count, new Date - all_start);
|
||||||
client.end();
|
client.quit();
|
||||||
client2.end();
|
client2.quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
test_start_stop.js
Normal file
5
test_start_stop.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
var redis = require("redis"),
|
||||||
|
client = redis.createClient();
|
||||||
|
|
||||||
|
redis.debug_mode = true;
|
||||||
|
client.quit();
|
Reference in New Issue
Block a user