Skip to content

Instantly share code, notes, and snippets.

@weixiyen
Created September 29, 2011 06:07
Show Gist options
  • Save weixiyen/1250090 to your computer and use it in GitHub Desktop.
Save weixiyen/1250090 to your computer and use it in GitHub Desktop.
Push server with Redis Subscriber
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