-
-
Save csquared/9010479 to your computer and use it in GitHub Desktop.
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 'redis' | |
$redis = Redis.new | |
def pub | |
puts 'pub' | |
$redis.publish('one', 'two') | |
$redis.publish(:one, 'two') | |
#$redis.publish(:one, 'exit') | |
end | |
def sub | |
$redis.subscribe(:one, :two) do |on| | |
on.subscribe do |channel, subscriptions| | |
puts "Subscribed to ##{channel} (#{subscriptions} subscriptions)" | |
end | |
on.message do |channel, message| | |
puts "##{channel}: #{message}" | |
$redis.unsubscribe if message == "exit" | |
end | |
on.unsubscribe do |channel, subscriptions| | |
puts "Unsubscribed from ##{channel} (#{subscriptions} subscriptions)" | |
end | |
end | |
end | |
t = Thread.new { sub } | |
Thread.new { pub } | |
t.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment