Skip to content

Commit e6aa382

Browse files
author
Ruben Bridgewater
committed
Small speedup: do not call data.toString() on debug messages
1 parent 8fa5b93 commit e6aa382

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

index.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ try {
3131
parsers.push(require("./lib/parser/hiredis"));
3232
} catch (err) {
3333
/* istanbul ignore next: won't be reached with tests */
34-
debug("hiredis parser not installed.");
34+
debug("Hiredis parser not installed.");
3535
}
3636

3737
parsers.push(require("./lib/parser/javascript"));
@@ -133,7 +133,7 @@ RedisClient.prototype.initialize_retry_vars = function () {
133133

134134
RedisClient.prototype.unref = function () {
135135
if (this.connected) {
136-
debug("unref'ing the socket connection");
136+
debug("Unref'ing the socket connection");
137137
this.stream.unref();
138138
} else {
139139
debug("Not connected yet, will unref later");
@@ -340,7 +340,7 @@ RedisClient.prototype.on_ready = function () {
340340
};
341341
Object.keys(this.subscription_set).forEach(function (key) {
342342
var parts = key.split(" ");
343-
debug("sending pub/sub on_ready " + parts[0] + ", " + parts[1]);
343+
debug("Sending pub/sub on_ready " + parts[0] + ", " + parts[1]);
344344
callback_count++;
345345
self.send_command(parts[0] + "scribe", [parts[1]], callback);
346346
});
@@ -399,7 +399,7 @@ RedisClient.prototype.on_info_cmd = function (err, res) {
399399
RedisClient.prototype.ready_check = function () {
400400
var self = this;
401401

402-
debug("checking server ready state...");
402+
debug("Checking server ready state...");
403403

404404
this.send_anyway = true; // secret flag to send_command to send something even if not "ready"
405405
this.info(function (err, res) {
@@ -460,7 +460,7 @@ RedisClient.prototype.connection_gone = function (why) {
460460
// If this is a requested shutdown, then don't retry
461461
if (this.closing) {
462462
this.retry_timer = null;
463-
debug("connection ended from quit command, not retrying.");
463+
debug("Connection ended from quit command, not retrying.");
464464
return;
465465
}
466466

@@ -477,7 +477,7 @@ RedisClient.prototype.connection_gone = function (why) {
477477
this.retry_timer = null;
478478
// TODO - some people need a "Redis is Broken mode" for future commands that errors immediately, and others
479479
// want the program to exit. Right now, we just log, which doesn't really help in either case.
480-
debug("node_redis: Couldn't get Redis connection after " + this.max_attempts + " attempts.");
480+
debug("Couldn't get Redis connection after " + this.max_attempts + " attempts.");
481481
return;
482482
}
483483

@@ -494,7 +494,7 @@ RedisClient.prototype.connection_gone = function (why) {
494494
if (self.connect_timeout && self.retry_totaltime >= self.connect_timeout) {
495495
self.retry_timer = null;
496496
// TODO - engage Redis is Broken mode for future commands, or whatever
497-
debug("node_redis: Couldn't get Redis connection after " + self.retry_totaltime + "ms.");
497+
debug("Couldn't get Redis connection after " + self.retry_totaltime + "ms.");
498498
return;
499499
}
500500

@@ -505,7 +505,8 @@ RedisClient.prototype.connection_gone = function (why) {
505505
};
506506

507507
RedisClient.prototype.on_data = function (data) {
508-
debug("net read " + this.address + " id " + this.connection_id + ": " + data.toString());
508+
// The data.toString() has a significant impact on big chunks and therefor this should only be used if necessary
509+
// debug("Net read " + this.address + " id " + this.connection_id + ": " + data.toString());
509510

510511
try {
511512
this.reply_parser.execute(data);
@@ -608,7 +609,7 @@ RedisClient.prototype.return_reply = function (reply) {
608609
}
609610

610611
if (this.pub_sub_mode && (type === 'message' || type === 'pmessage')) {
611-
debug("received pubsub message");
612+
debug("Received pubsub message");
612613
}
613614
else {
614615
command_obj = this.command_queue.shift();
@@ -640,7 +641,7 @@ RedisClient.prototype.return_reply = function (reply) {
640641

641642
try_callback(command_obj.callback, reply);
642643
} else {
643-
debug("no callback for reply: " + (reply && reply.toString && reply.toString()));
644+
debug("No callback for reply");
644645
}
645646
} else if (this.pub_sub_mode || (command_obj && command_obj.sub_command)) {
646647
if (Array.isArray(reply)) {
@@ -754,12 +755,11 @@ RedisClient.prototype.send_command = function (command, args, callback) {
754755

755756
command_obj = new Command(command, args, false, buffer_args, callback);
756757

757-
if ((!this.ready && !this.send_anyway) || !stream.writable) {
758-
if (!stream.writable) {
759-
debug("send command: stream is not writeable.");
760-
}
761-
758+
if (!this.ready && !this.send_anyway || !stream.writable) {
762759
if (this.enable_offline_queue) {
760+
if (!stream.writable) {
761+
debug("send command: stream is not writeable.");
762+
}
763763
debug("Queueing " + command + " for next server connection.");
764764
this.offline_queue.push(command_obj);
765765
this.should_buffer = true;
@@ -794,18 +794,18 @@ RedisClient.prototype.send_command = function (command, args, callback) {
794794

795795
command_str = "*" + elem_count + "\r\n$" + command.length + "\r\n" + command + "\r\n";
796796

797-
if (! buffer_args) { // Build up a string and send entire command in one write
797+
if (!buffer_args) { // Build up a string and send entire command in one write
798798
for (i = 0, il = args.length, arg; i < il; i += 1) {
799799
arg = args[i];
800800
if (typeof arg !== "string") {
801801
arg = String(arg);
802802
}
803803
command_str += "$" + Buffer.byteLength(arg) + "\r\n" + arg + "\r\n";
804804
}
805-
debug("send " + this.address + " id " + this.connection_id + ": " + command_str);
805+
debug("Send " + this.address + " id " + this.connection_id + ": " + command_str);
806806
buffered_writes += !stream.write(command_str);
807807
} else {
808-
debug("send command (" + command_str + ") has Buffer arguments");
808+
debug("Send command (" + command_str + ") has Buffer arguments");
809809
buffered_writes += !stream.write(command_str);
810810

811811
for (i = 0, il = args.length, arg; i < il; i += 1) {

0 commit comments

Comments
 (0)