Sha256: 9c809f4cf5d88bbd7cf340a37f913c83e25bd221a289778eabb91448e071c0cd

Contents?: true

Size: 697 Bytes

Versions: 56

Compression:

Stored size: 697 Bytes

Contents

require "redis"

puts <<-EOS
To play with this example use redis-cli from another terminal, like this:

  $ redis-cli publish one hello

Finally force the example to exit sending the 'exit' message with:

  $ redis-cli publish two exit

EOS

redis = Redis.connect

trap(:INT) { puts; exit }

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

Version data entries

56 entries across 56 versions & 8 rubygems

Version Path
abaci-0.3.0 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.7.5 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.7.4 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.7.3 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.7.2 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.7.1 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.7.0 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.6.9 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.6.8 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.6.7 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.6.6 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.6.5 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.6.4 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.6.3 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.6.2 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.6.1 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.6.0 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.5.17 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.5.16 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb
classiccms-0.5.15 vendor/bundle/gems/redis-2.2.2/examples/pubsub.rb