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

Make sure all individual handled command work in multi context the same

Fix quit possibly resulting in reconnections
This commit is contained in:
Ruben Bridgewater
2016-04-14 01:14:41 +02:00
parent 0424cb0bf3
commit 3038c9043d
7 changed files with 334 additions and 99 deletions

View File

@@ -735,12 +735,35 @@ function return_pub_sub (self, reply) {
}
RedisClient.prototype.return_reply = function (reply) {
if (this.pub_sub_mode === 1 && reply instanceof Array && reply.length !== 0 && reply[0]) {
// If in monitor mode, all normal commands are still working and we only want to emit the streamlined commands
// As this is not the average use case and monitor is expensive anyway, let's change the code here, to improve
// the average performance of all other commands in case of no monitor mode
if (this.monitoring) {
var replyStr;
if (this.buffers && Buffer.isBuffer(reply)) {
replyStr = reply.toString();
} else {
replyStr = reply;
}
// While reconnecting the redis server does not recognize the client as in monitor mode anymore
// Therefore the monitor command has to finish before it catches further commands
if (typeof replyStr === 'string' && utils.monitor_regex.test(replyStr)) {
var timestamp = replyStr.slice(0, replyStr.indexOf(' '));
var args = replyStr.slice(replyStr.indexOf('"') + 1, -1).split('" "').map(function (elem) {
return elem.replace(/\\"/g, '"');
});
this.emit('monitor', timestamp, args, replyStr);
return;
}
}
if (this.pub_sub_mode === 0) {
normal_reply(this, reply);
} else if (this.pub_sub_mode !== 1) {
this.pub_sub_mode--;
normal_reply(this, reply);
} else if (reply instanceof Array && reply.length > 2 && reply[0]) {
return_pub_sub(this, reply);
} else {
if (this.pub_sub_mode !== 0 && this.pub_sub_mode !== 1) {
this.pub_sub_mode--;
}
normal_reply(this, reply);
}
};