Skip to content

Commit c1f7755

Browse files
author
Ruben Bridgewater
committed
Keep monitoring mode if once activated and use internal function for select and monitor while connecting
1 parent b3e89fe commit c1f7755

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

index.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var net = require('net');
44
var tls = require('tls');
55
var util = require('util');
66
var utils = require('./lib/utils');
7+
var Command = require('./lib/command');
78
var Queue = require('double-ended-queue');
89
var errorClasses = require('./lib/customErrors');
910
var EventEmitter = require('events');
@@ -154,7 +155,6 @@ function RedisClient (options, stream) {
154155
this.times_connected = 0;
155156
this.buffers = options.return_buffers || options.detect_buffers;
156157
this.options = options;
157-
this.old_state = {};
158158
this.reply = 'ON'; // Returning replies is the default
159159
// Init parser
160160
this.reply_parser = create_parser(this);
@@ -445,10 +445,10 @@ RedisClient.prototype.on_ready = function () {
445445

446446
// Restore modal commands from previous connection. The order of the commands is important
447447
if (this.selected_db !== undefined) {
448-
this.select(this.selected_db);
448+
this.internal_send_command(new Command('select', [this.selected_db]));
449449
}
450-
if (this.old_state.monitoring) { // Monitor has to be fired before pub sub commands
451-
this.monitor();
450+
if (this.monitoring) { // Monitor has to be fired before pub sub commands
451+
this.internal_send_command(new Command('monitor', []));
452452
}
453453
var callback_count = Object.keys(this.subscription_set).length;
454454
if (!this.options.disable_resubscribing && callback_count) {
@@ -571,12 +571,6 @@ RedisClient.prototype.connection_gone = function (why, error) {
571571
this.cork = noop;
572572
this.uncork = noop;
573573
this.pipeline = false;
574-
575-
var state = {
576-
monitoring: this.monitoring
577-
};
578-
this.old_state = state;
579-
this.monitoring = false;
580574
this.pub_sub_mode = 0;
581575

582576
// since we are collapsing end and close, users don't expect to be called twice
@@ -874,16 +868,16 @@ RedisClient.prototype.internal_send_command = function (command_obj) {
874868
var big_data = false;
875869
var args_copy = new Array(len);
876870

877-
if (process.domain && command_obj.callback) {
878-
command_obj.callback = process.domain.bind(command_obj.callback);
879-
}
880-
881871
if (this.ready === false || this.stream.writable === false) {
882872
// Handle offline commands right away
883873
handle_offline_command(this, command_obj);
884874
return false; // Indicate buffering
885875
}
886876

877+
if (process.domain && command_obj.callback) {
878+
command_obj.callback = process.domain.bind(command_obj.callback);
879+
}
880+
887881
for (i = 0; i < len; i += 1) {
888882
if (typeof args[i] === 'string') {
889883
// 30000 seemed to be a good value to switch to buffers after testing and checking the pros and cons

0 commit comments

Comments
 (0)