Skip to content

Instantly share code, notes, and snippets.

@jamesu
Created February 19, 2012 20:27
Show Gist options
  • Save jamesu/1865608 to your computer and use it in GitHub Desktop.
Save jamesu/1865608 to your computer and use it in GitHub Desktop.
Redis Pubsub test
# Simple redis client to test pubsub
# All clients will send the current time to 'chan'
# and print out any messages they receive.
require 'rubygems'
require 'em-hiredis'
EventMachine.run do
# Make $rl to listen
$rl = EM::Hiredis.connect
$rl.on(:message) do |channel, msg|
puts "MESSAGE: #{channel} :: #{msg}"
end
$rl.subscribe 'chan'
# Make $r to send messages
$r = EM::Hiredis.connect
EventMachine::PeriodicTimer.new(1) do
# Dispatch message every second
puts "TIMER -> dispatch"
$r.publish 'chan', Time.now.utc.to_i.to_s
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment