Created
February 19, 2012 20:27
-
-
Save jamesu/1865608 to your computer and use it in GitHub Desktop.
Redis Pubsub test
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
# 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