Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.client = options.client || redis.createClient(options);
// Redis doesn't allow the same connection to both listen to channels and do
// operations. Make an extra redis connection for subscribing with the same
// options if not provided
this.observer = options.observer || redis.createClient(this.client.options);
var pubsub = this;
this.observer.on('message', function(channel, message) {
var data = JSON.parse(message);
pubsub._emit(channel, data);
});
}
module.exports = RedisPubSub;
RedisPubSub.prototype = Object.create(PubSub.prototype);
RedisPubSub.prototype.close = function(callback) {
if (!callback) {
callback = function(err) {
if (err) throw err;
};
}
var pubsub = this;
PubSub.prototype.close.call(this, function(err) {
if (err) return callback(err);
pubsub.client.quit(function(err) {
if (err) return callback(err);
pubsub.observer.quit(callback);
});
});
};
RedisPubSub.prototype.close = function(callback) {
if (!callback) {
callback = function(err) {
if (err) throw err;
};
}
var pubsub = this;
PubSub.prototype.close.call(this, function(err) {
if (err) return callback(err);
pubsub.client.quit(function(err) {
if (err) return callback(err);
pubsub.observer.quit(callback);
});
});
};