mirror of
https://github.com/wassname/talk.git
synced 2026-06-28 23:58:38 +08:00
25 lines
554 B
JavaScript
25 lines
554 B
JavaScript
const {RedisPubSub} = require('graphql-redis-subscriptions');
|
|
const {connectionOptions, attachMonitors} = require('./redis');
|
|
|
|
/**
|
|
* getClient returns the pubsub singleton for this instance.
|
|
*/
|
|
let pubsub = null;
|
|
const getClient = () => {
|
|
if (pubsub !== null) {
|
|
return pubsub;
|
|
}
|
|
|
|
pubsub = new RedisPubSub({connection: connectionOptions});
|
|
|
|
// Attach the node monitors to the subscriber + publishers.
|
|
attachMonitors(pubsub.redisPublisher);
|
|
attachMonitors(pubsub.redisSubscriber);
|
|
|
|
return pubsub;
|
|
};
|
|
|
|
module.exports = {
|
|
getClient,
|
|
};
|