Question

Now i pushing data to channel redis everytime, when reload web page and this data is put to stack redis and is displayed here again and again:

$rediska->publish('real', 'PHP SENDING'); this is called every reload page

redisClient.on('pmessage', function(pattern, channel, message) {
    console.log("Sending from Redis: "+ channel); // here i get real, real, real, real

  });

how to control it? i must check if client side get message real, after dont send again this info, and delete data from redis if user click to button.

Était-ce utile?

La solution

I think your issue is located just outside the following code:

redisClient.on('pmessage', function(pattern, channel, message) {
 console.log("Sending from Redis: "+ channel); // here i get real, real, real, real
});

If you call this code each time a new user is connected (on the server-side) it will add another listener each time a user connects. So if you reload your page 3 times, your server-side handler will be binded 3 times to the pmessage event. That's why you get all those outputs.

To verify this, restart the node server, then load the page, you should see only one "Sending from Redis:", then reload the page again, you should be 2 new console output.

If that's the case just put your redisClient.on('pmessage'... code outside of the .on('connected', ... handler and it will do the trick.

PS: If this not solve your issue, you should send us more code (both on the server and the client side)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top