Created
November 15, 2010 02:30
-
-
Save dongyuwei/676345 to your computer and use it in GitHub Desktop.
redis pub sub test
This file contains 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 "rubygems" | |
require "redis" | |
puts <<-EOS | |
To play with this example use redis-cli from another terminal, like this: | |
$ redis-cli publish test msg | |
EOS | |
redis = Redis.connect | |
trap(:INT) { puts; exit } | |
redis.subscribe(:test) do |on| | |
on.message do |channel, message| | |
puts "##{channel}: #{message}" | |
#必须建立一个新连接,否则必报错。 | |
#lib/redis/connection.rb:86:in `format_error_reply': - | |
#ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / QUIT allowed in this context (RuntimeError) | |
redis2 = Redis.connect | |
puts redis2.get 'dyw' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment