From 7682b56d78998f750fe00aa656dc7870d741e673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 14 Apr 2015 11:03:03 -0400 Subject: [PATCH] fix pubsub channels for multi dbs --- src/pubsub.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/pubsub.js b/src/pubsub.js index 42c0f54cfb..dd3c251ce0 100644 --- a/src/pubsub.js +++ b/src/pubsub.js @@ -6,17 +6,20 @@ var nconf = require('nconf'), winston = require('winston'), EventEmitter = require('events').EventEmitter; +var channelName; + var PubSub = function() { var self = this; if (nconf.get('redis')) { var redis = require('./database/redis'); 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); } @@ -42,4 +45,4 @@ PubSub.prototype.publish = function(event, data) { var pubsub = new PubSub(); -module.exports = pubsub; \ No newline at end of file +module.exports = pubsub;