N
N
nepster-web2016-01-18 17:36:33
Redis
nepster-web, 2016-01-18 17:36:33

How to correctly send messages from redis to sockets?

I use node.js, socket.io and redis.
There is a php script that, depending on the event, throws a message into the Redis channel (pub/sub). Further, in turn, there is node.js, which is also subscribed to radish channels and works in parallel with sockets.
The task is such, for example, a post is created on the site, the message flies to the radish, node.js receives the message, and all sockets in a certain room need to send data to the client. Since the language is still asynchronous, a problem arose: How to do it right?
If you do something like this, the message flies all the socket, about as many times as there are total connected sockets.

io.on('connection', function (socket) {
...
    redisClient.on("message", function (channel, message) {
        message = JSON.parse(message);

        console.log('---- redis');
        console.log(message);

        io.to(room).emit('test', {
            channel: channel,
            message: message
        });
    });

How correctly to send one message (we receive through a radish, we bullet on sockets)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nepster-web, 2016-01-18
@nepster-web

stackoverflow.com/questions/13541176/duplicate-mes...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question