Skip to content

Commit

Permalink
seperate concerns
Browse files Browse the repository at this point in the history
  • Loading branch information
cokeeffekt committed Mar 22, 2020
1 parent 5834086 commit 38483d6
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions snub.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = function (config) {
debug: false,
monoWait: 50,
timeout: 5000,
stats: _ => {}
stats: _ => {},
}, config || {});
if (!config.auth)
delete config.auth;
Expand All @@ -16,18 +16,32 @@ module.exports = function (config) {
var snubSelf = this;
var prefix = config.prefix.replace(/:/igm, '') + ':';
const Redis = require('ioredis');

// redis connection for each concern
const redis = new Redis(config);
const pub = new Redis(config);
const sub = new Redis(config);
var eventsRegistered = [];

this.redis = pub;
this.redis = redis;

Object.defineProperty(this, 'status', {
get () {
return {
listeners: eventsRegistered.length,
redis: redis.status,
redisPub: pub.status,
redisSub: sub.status
};
}
});

function stat (obj) {
if (!obj.pattern.startsWith(prefix))
config.stats(obj);
};

redis.on('pmessage', (pattern, channel, message) => {
sub.on('pmessage', (pattern, channel, message) => {
pattern = pattern.replace(prefix, '');

var e = eventsRegistered
Expand Down

0 comments on commit 38483d6

Please sign in to comment.