Skip to content

Instantly share code, notes, and snippets.

@samflores
Created August 24, 2010 16:02
Show Gist options
  • Save samflores/547798 to your computer and use it in GitHub Desktop.
Save samflores/547798 to your computer and use it in GitHub Desktop.
require "redis"
@redis = Redis.new(:timeout => 0)
@redis.subscribe('a', 'b') do |on|
on.subscribe do |klass, num_subs|
puts "Subscribed to #{klass} (#{num_subs} subscriptions)"
end
on.message do |klass, msg|
puts "#{klass} received: #{msg}"
if msg == 'exit'
@redis.unsubscribe
end
end
on.unsubscribe do |klass, num_subs|
puts "Unsubscribed from #{klass} (#{num_subs} subscriptions)"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment