Created
September 29, 2011 06:07
-
-
Save weixiyen/1250090 to your computer and use it in GitHub Desktop.
Push server with Redis Subscriber
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
require.paths.unshift(process.cwd() + '/lib') | |
require.paths.unshift(process.cwd() + '/contrib') | |
redis = require 'redis' | |
settings = require('settings').stream | |
# DEFAULT SETTINGS | |
# ------------------------------------------------- | |
settings.port = process.argv[2] if process.argv[2]? | |
io = require('socket.io').listen Number(settings.port) | |
subscriber = redis.createClient() | |
subscriber.subscribe 'stream' | |
io.sockets.on 'connection', (client) -> | |
subscriber.on 'message', ( channel, raw_data ) -> | |
msg = JSON.parse raw_data | |
client.emit msg.channel, msg.data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment