Thursday 20 December 2018

How to send data from a redis subscriber to an express route

I have a redis pubsub client where publisher is in one file and subscriber is in another file working perfectlyI have 2 controllers a home controller that handles '/' route and a data controller that handles '/data' routeInside my redis subscriber I want to update the state of a variable that I continuously get from publisherHow do I send this state to both controllers when they do a request​I was doingapp.get('/', (req, res) => {c = redis.createClient()c.on("message", (channel, message) => {// Send data here})})This does not look like a good idea, it is creating a new CLIENT for every request to the '/' endpointI want to be able to do// home controller fileapp.get('/', (req, res) => {res.json(state)})// data controller fileapp.get('/data', (req, res) => {res.json(state)})​How to implement this state

Submitted December 20, 2018 at 01:37PM by mypirateapp

No comments:

Post a Comment