const subs = {};
- redisSubscribeClient.on('pmessage', (_, channel, message) => {
+ redisSubscribeClient.on('message', (channel, message) => {
const callbacks = subs[channel];
log.silly(`New message on channel ${channel}`);
callbacks.forEach(callback => callback(message));
});
- redisSubscribeClient.psubscribe(`${redisPrefix}timeline:*`);
-
const subscriptionHeartbeat = (channel) => {
const interval = 6*60;
const tellSubscribed = () => {
const subscribe = (channel, callback) => {
log.silly(`Adding listener for ${channel}`);
subs[channel] = subs[channel] || [];
+ if (subs[channel].length === 0) {
+ log.verbose(`Subscribe ${channel}`);
+ redisSubscribeClient.subscribe(channel);
+ }
subs[channel].push(callback);
};
const unsubscribe = (channel, callback) => {
log.silly(`Removing listener for ${channel}`);
subs[channel] = subs[channel].filter(item => item !== callback);
+ if (subs[channel].length === 0) {
+ log.verbose(`Unsubscribe ${channel}`);
+ redisSubscribeClient.unsubscribe(channel);
+ }
};
const allowCrossDomain = (req, res, next) => {