Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added command_logging option
  • Loading branch information
Carlos Rodriguez committed Jun 19, 2012
1 parent e6449a7 commit 297ddf9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -115,7 +115,6 @@ To see what's under the hood, try setting `redis.debug_mode = true`, and you can
see the failover process in detail:
```
[19:27:58](#1) info: set on 127.0.0.1:6380 (master default)
[19:27:58](#1) warning: MASTER is down! (127.0.0.1:6380)
[19:27:58](#1) info: reorientating (node down) in 2000ms
Redis connection gone from end event.
Expand All @@ -131,9 +130,11 @@ Redis connection gone from end event.
[19:28:00](#1) info: renegotating subSlave away from master
[19:28:00](#1) info: subSlave is now 127.0.0.1:6382
[19:28:00](#1) info: ready, using 127.0.0.1:6381 as master
[19:28:00](#1) info: set on 127.0.0.1:6381 (master default)
```
To get info on which commands are executed on which servers, try setting
`redis.command_logging = true`.
Running tests
=============
Expand Down
13 changes: 10 additions & 3 deletions index.js
Expand Up @@ -19,6 +19,7 @@ function createClient(nodes, options, etc) {
}
exports.createClient = createClient;
exports.debug_mode = false;
exports.command_logging = false;
exports.print = redis.print;

function RedisHAClient(nodeList, options) {
Expand Down Expand Up @@ -165,7 +166,9 @@ commands.forEach(function(k) {
}
}
}
self.log(k + ' on ' + this.subSlave);
if (exports.command_logging) {
self.log(k + ' on ' + this.subSlave);
}
return callCommand(this.subSlave.subClient, k, args);
case 'select':
// Need to execute on all nodes.
Expand Down Expand Up @@ -198,7 +201,9 @@ commands.forEach(function(k) {
var client, node;
if (this.options.auto_slaveok || this.slaveOk(k)) {
if (node = this.randomSlave()) {
self.log(k + ' on ' + node);
if (exports.command_logging) {
self.log(k + ' on ' + node);
}
client = node.client;
}
}
Expand All @@ -208,7 +213,9 @@ commands.forEach(function(k) {
function callCommand(client, command, args) {
self._slaveOk = false;
if (!client) {
self.log(command + ' on ' + self.master + ' (master default)');
if (exports.command_logging) {
self.log(command + ' on ' + self.master + ' (master default)');
}
client = self.master.client;
}
client[command].apply(client, args);
Expand Down
1 change: 1 addition & 0 deletions test/basic.js
Expand Up @@ -2,6 +2,7 @@ var redis = require('../')
, uuid = require('../lib/uuid')
;

redis.debug_mode = true;
var client = redis.createClient([6380, 6381, 6382]);

var cmd_per_sec = 0;
Expand Down
1 change: 1 addition & 0 deletions test/pubsub-oneclient.js
Expand Up @@ -2,6 +2,7 @@ var redis = require('../')
, uuid = require('../lib/uuid')
;

redis.debug_mode = true;
var nodes = [6380, 6381, 6382];
var client = redis.createClient(nodes);

Expand Down
1 change: 1 addition & 0 deletions test/pubsub.js
Expand Up @@ -2,6 +2,7 @@ var redis = require('../')
, uuid = require('../lib/uuid')
;

redis.debug_mode = true;
var nodes = [6380, 6381, 6382];
var client = redis.createClient(nodes);
var subClient = redis.createClient(nodes);
Expand Down

0 comments on commit 297ddf9

Please sign in to comment.