Created
May 22, 2012 19:30
-
-
Save ciberch/2771117 to your computer and use it in GitHub Desktop.
Publishing and Activity to Redis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var redis = require("redis"); | |
| var publisher = redis.createClient(options.redis.port, options.redis.host); | |
| if(options.redis.pass) { | |
| publisher.auth(options.redis.pass); | |
| } | |
| function publish(streamName, activity) { | |
| activity.save(function(err) { | |
| if (!_.isArray(activity.streams)) { | |
| activity.streams = [] | |
| } | |
| if (!_.include(activity.streams, streamName)) { | |
| activity.streams.push(streamName); | |
| } | |
| if (!err && streamName && publisher) { | |
| // Send to Redis PubSub | |
| publisher.publish(streamName, JSON.stringify(activity)); | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment