Created
September 14, 2011 15:05
Revisions
-
mloughran revised this gist
Sep 14, 2011 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -19,6 +19,14 @@ # Passing such an object is useful if you want to unsubscribe redis.pubsub.unsubscribe_proc('foo', callback) # Or if you want to call a method on a certain object on message class Thing def receive_message(message) puts "Foo received #{message}" end end redis.pubsub.subscribe('foo', Thing.new.method(:receive_message)) # You can also unsubscribe completely from a channel # redis.pubsub.unsubscribe('foo') } -
Martyn Loughran created this gist
Sep 14, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ require 'em-hiredis' EM.run { require 'em-hiredis' redis = EM::Hiredis.connect # If you pass a block to subscribe it will be called whenever a message # is received on this channel redis.pubsub.subscribe('foo') { |msg| p [:received_foo, msg] } # You can also pass any other object which responds to call if you wish callback = Proc.new { |msg| p [:received, msg] } redis.pubsub.subscribe('foo', callback) # Passing such an object is useful if you want to unsubscribe redis.pubsub.unsubscribe_proc('foo', callback) # You can also unsubscribe completely from a channel # redis.pubsub.unsubscribe('foo') }