v1.18.x
barisusakli 10 years ago
parent a055ff3547
commit 1cc80cbc84

@ -6,6 +6,8 @@ var nconf = require('nconf'),
winston = require('winston'),
EventEmitter = require('events').EventEmitter;
var channelName;
var PubSub = function() {
var self = this;
if (nconf.get('redis')) {
@ -13,10 +15,11 @@ var PubSub = function() {
var subClient = redis.connect();
this.pubClient = redis.connect();
subClient.subscribe('pubsub_channel');
channelName = 'db:' + nconf.get('redis:database') + 'pubsub_channel';
subClient.subscribe(channelName);
subClient.on('message', function(channel, message) {
if (channel !== 'pubsub_channel') {
if (channel !== channelName) {
return;
}
@ -34,7 +37,7 @@ util.inherits(PubSub, EventEmitter);
PubSub.prototype.publish = function(event, data) {
if (this.pubClient) {
this.pubClient.publish('pubsub_channel', JSON.stringify({event: event, data: data}));
this.pubClient.publish(channelName, JSON.stringify({event: event, data: data}));
} else {
this.emit(event, data);
}

Loading…
Cancel
Save