Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How can I trigger events to fire on connected clients using node.js, sockets.io and redis?

Tags: nodejs redis code

How can I trigger events to fire on connected clients using node.js, sockets.io and redis?

Problem

Ok, so I previously asked a question asking about my options, I have looked into sockets.io and Redis, and really like what I see.

Anyway, I would like to have multiple clients connected to a node.js server. Then when my redis db has a change, for example some boolean from 0 to 1, I want all node.js connections to send this update to all clients.

I am not looking for some Code to loop and check for this change, I am wondering how I can fire an event to specific clients when a change is made in a redis db. Any psuedo code to help me get my mind around this, would be awesome. I would also really appreciate any node.js code that shows how to hook an event to changes in a redis instance.

Cheers, Josh

Problem courtesy of: Josh Mc

Solution

I can't write any node.js code for you, but sounds like what you want is exactly what Redis's pub/sub functionality is for:

http://redis.io/topics/pubsub

Each node.js client would subscribe to a channel, where they will block/wait for messages to arrive. No looping/polling required.

Solution courtesy of: Carl Zulauf

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

How can I trigger events to fire on connected clients using node.js, sockets.io and redis?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×