mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-08 05:30:40 +01:00
fix pubsub channels for multi dbs
This commit is contained in:
@@ -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;
|
||||
module.exports = pubsub;
|
||||
|
||||
Reference in New Issue
Block a user