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/sets')(db, mongoModule);
require('./mongo/sorted')(db, mongoModule); require('./mongo/sorted')(db, mongoModule);
require('./mongo/list')(db, mongoModule); require('./mongo/list')(db, mongoModule);
require('./mongo/pubsub')(db, mongoModule);
callback(); callback();
}); });
}; };

@ -1,5 +1,7 @@
'use strict'; 'use strict';
var pubsub = require('../../pubsub');
module.exports = function (db, module) { module.exports = function (db, module) {
var helpers = module.helpers.mongo; var helpers = module.helpers.mongo;
@ -16,6 +18,25 @@ module.exports = function (db, module) {
cache.hits = 0; cache.hits = 0;
module.objectCache = cache; 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) { module.setObject = function (key, data, callback) {
callback = callback || helpers.noop; callback = callback || helpers.noop;
if (!key || !data) { if (!key || !data) {

@ -1,34 +1,8 @@
'use strict'; 'use strict';
var nconf = require('nconf'); var mubsub = require('mubsub');
module.exports = function (db, mongoModule) { var db = require('../mongo');
var pubsub; var client = mubsub(db.client);
if (!nconf.get('redis')) { module.exports = client.channel('pubsub');
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();
};
};

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

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

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

Loading…
Cancel
Save