You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Merge branch 'select_db_exception' of https://github.com/roamm/node_redis into roamm-select_db_exception
This commit is contained in:
9
index.js
9
index.js
@@ -285,7 +285,12 @@ RedisClient.prototype.on_ready = function () {
|
|||||||
|
|
||||||
// magically restore any modal commands from a previous connection
|
// magically restore any modal commands from a previous connection
|
||||||
if (this.selected_db !== null) {
|
if (this.selected_db !== null) {
|
||||||
|
// this trick works if and only if the following send_command
|
||||||
|
// never goes into the offline queue
|
||||||
|
var pub_sub_mode = this.pub_sub_mode;
|
||||||
|
this.pub_sub_mode = false;
|
||||||
this.send_command('select', [this.selected_db]);
|
this.send_command('select', [this.selected_db]);
|
||||||
|
this.pub_sub_mode = pub_sub_mode;
|
||||||
}
|
}
|
||||||
if (this.pub_sub_mode === true) {
|
if (this.pub_sub_mode === true) {
|
||||||
// only emit "ready" when all subscriptions were made again
|
// only emit "ready" when all subscriptions were made again
|
||||||
@@ -494,8 +499,8 @@ RedisClient.prototype.return_error = function (err) {
|
|||||||
var command_obj = this.command_queue.shift(), queue_len = this.command_queue.getLength();
|
var command_obj = this.command_queue.shift(), queue_len = this.command_queue.getLength();
|
||||||
|
|
||||||
if (this.pub_sub_mode === false && queue_len === 0) {
|
if (this.pub_sub_mode === false && queue_len === 0) {
|
||||||
this.emit("idle");
|
|
||||||
this.command_queue = new Queue();
|
this.command_queue = new Queue();
|
||||||
|
this.emit("idle");
|
||||||
}
|
}
|
||||||
if (this.should_buffer && queue_len <= this.command_queue_low_water) {
|
if (this.should_buffer && queue_len <= this.command_queue_low_water) {
|
||||||
this.emit("drain");
|
this.emit("drain");
|
||||||
@@ -585,8 +590,8 @@ RedisClient.prototype.return_reply = function (reply) {
|
|||||||
queue_len = this.command_queue.getLength();
|
queue_len = this.command_queue.getLength();
|
||||||
|
|
||||||
if (this.pub_sub_mode === false && queue_len === 0) {
|
if (this.pub_sub_mode === false && queue_len === 0) {
|
||||||
this.emit("idle");
|
|
||||||
this.command_queue = new Queue(); // explicitly reclaim storage from old Queue
|
this.command_queue = new Queue(); // explicitly reclaim storage from old Queue
|
||||||
|
this.emit("idle");
|
||||||
}
|
}
|
||||||
if (this.should_buffer && queue_len <= this.command_queue_low_water) {
|
if (this.should_buffer && queue_len <= this.command_queue_low_water) {
|
||||||
this.emit("drain");
|
this.emit("drain");
|
||||||
|
21
test.js
21
test.js
@@ -724,6 +724,27 @@ tests.reconnect = function () {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
tests.reconnect_select_db_after_pubsub = function() {
|
||||||
|
var name = "reconnect_select_db_after_pubsub";
|
||||||
|
|
||||||
|
client.select(test_db_num);
|
||||||
|
client.set(name, "one");
|
||||||
|
client.subscribe('ChannelV', function (err, res) {
|
||||||
|
client.stream.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on("reconnecting", function on_recon(params) {
|
||||||
|
client.on("ready", function on_connect() {
|
||||||
|
client.unsubscribe('ChannelV', function (err, res) {
|
||||||
|
client.get(name, require_string("one", name));
|
||||||
|
client.removeListener("connect", on_connect);
|
||||||
|
client.removeListener("reconnecting", on_recon);
|
||||||
|
next(name);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
tests.idle = function () {
|
tests.idle = function () {
|
||||||
var name = "idle";
|
var name = "idle";
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user