SocketCluster / socketcluster

Highly scalable realtime pub/sub and RPC framework
https://socketcluster.io
MIT License
6.15k stars 314 forks source link

Global Redis Subscriber #463

Open ansubur opened 5 years ago

ansubur commented 5 years ago

I use node_redis to subscribe to a channel which then publishes to all the subscribed clients

The below code is inside worker.js & SC runs 4 worker process. var RedSubclient = redis.createClient(6379, '127.0.0.1'); RedSubclient.psubscribe(subChannelName); RedSubclient.on("pmessage", function(pattern, channel, message){ scServer.exchange.publish(channel, message); });

The issue is that, this code receives & publishes each message 4 times. Looks like the Redisclient should be used globally, but I don't have clear idea how to do it. Can anyone share a snippet?

ansubur commented 5 years ago

anybody to help?

JoshuaVSherman commented 5 years ago

socketCluster already does this for you, so you don't need node_redis

ansubur commented 5 years ago

I'm not aware of it, can you point me how it is done?