possible fix for pubsub

v1.18.x
Barış Soner Uşaklı 7 years ago
parent 33a8cb947e
commit 8a6345ded7

@ -122,7 +122,6 @@ mongoModule.init = function (callback) {
require('./mongo/sets')(db, mongoModule);
require('./mongo/sorted')(db, mongoModule);
require('./mongo/list')(db, mongoModule);
require('./mongo/pubsub')(db, mongoModule);
callback();
});
};

@ -1,5 +1,7 @@
'use strict';
var pubsub = require('../../pubsub');
module.exports = function (db, module) {
var helpers = module.helpers.mongo;
@ -16,6 +18,25 @@ module.exports = function (db, module) {
cache.hits = 0;
module.objectCache = cache;
pubsub.on('mongo:hash:cache:del', function (key) {
cache.del(key);
});
pubsub.on('mongo:hash:cache:reset', function () {
cache.reset();
});
module.delObjectCache = function (key) {
pubsub.publish('mongo:hash:cache:del', key);
cache.del(key);
};
module.resetObjectCache = function () {
pubsub.publish('mongo:hash:cache:reset');
cache.reset();
};
module.setObject = function (key, data, callback) {
callback = callback || helpers.noop;
if (!key || !data) {

@ -1,34 +1,8 @@
'use strict';
var nconf = require('nconf');
var mubsub = require('mubsub');
module.exports = function (db, mongoModule) {
var pubsub;
var db = require('../mongo');
var client = mubsub(db.client);
if (!nconf.get('redis')) {
var mubsub = require('mubsub');
var client = mubsub(db);
pubsub = client.channel('pubsub');
mongoModule.pubsub = pubsub;
} else {
pubsub = require('../../pubsub');
}
pubsub.on('mongo:hash:cache:del', function (key) {
mongoModule.objectCache.del(key);
});
pubsub.on('mongo:hash:cache:reset', function () {
mongoModule.objectCache.reset();
});
mongoModule.delObjectCache = function (key) {
pubsub.publish('mongo:hash:cache:del', key);
mongoModule.objectCache.del(key);
};
mongoModule.resetObjectCache = function () {
pubsub.publish('mongo:hash:cache:reset');
mongoModule.objectCache.reset();
};
};
module.exports = client.channel('pubsub');

@ -50,7 +50,6 @@ redisModule.init = function (callback) {
require('./redis/sets')(redisClient, redisModule);
require('./redis/sorted')(redisClient, redisModule);
require('./redis/list')(redisClient, redisModule);
require('./redis/pubsub')(redisClient, redisModule);
callback();
});

@ -7,10 +7,10 @@ var EventEmitter = require('events').EventEmitter;
var channelName;
var PubSub = function (redisModule) {
var PubSub = function (db) {
var self = this;
var subClient = redisModule.connect();
this.pubClient = redisModule.connect();
var subClient = db.connect();
this.pubClient = db.connect();
channelName = 'db:' + nconf.get('redis:database') + 'pubsub_channel';
subClient.subscribe(channelName);
@ -35,6 +35,7 @@ PubSub.prototype.publish = function (event, data) {
this.pubClient.publish(channelName, JSON.stringify({ event: event, data: data }));
};
module.exports = function (redisClient, redisModule) {
redisModule.pubsub = new PubSub(redisModule);
module.exports = function () {
var db = require('../redis');
return new PubSub(db);
};

@ -32,9 +32,9 @@ function get() {
pubsub = new EventEmitter();
pubsub.publish = pubsub.emit.bind(pubsub);
} else if (nconf.get('redis')) {
pubsub = require('./database/redis').pubsub;
} else {
pubsub = require('./database').pubsub;
pubsub = require('./database/redis/pubsub');
} else if (nconf.get('mongo')) {
pubsub = require('./database/mongo/pubsub');
}
if (!pubsub) {

Loading…
Cancel
Save