Sha256: 269ece05fe7d71f165a4754093cea2eb77a6f51e5042e691aa334247122396e3

Contents?: true

Size: 676 Bytes

Versions: 9

Compression:

Stored size: 676 Bytes

Contents

require 'rubygems'
require 'redis'

puts "To play with this example use redis-cli from another terminal, like this:"
puts "  ./redis-cli publish one hello"
puts "Finally force the example to exit sending the 'exit' message with"
puts "  ./redis-cli publish two exit"
puts ""

@redis = Redis.new(:timeout => 0)

@redis.subscribe('one','two') do |on|
  on.subscribe {|klass, num_subs| puts "Subscribed to #{klass} (#{num_subs} subscriptions)" }
  on.message do |klass, msg| 
    puts "#{klass} received: #{msg}"
    if msg == 'exit'
      @redis.unsubscribe
    end
  end
  on.unsubscribe {|klass, num_subs| puts "Unsubscribed to #{klass} (#{num_subs} subscriptions)" }
end




Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
lunar-0.4.1 vendor/redis/examples/pubsub.rb
lunar-0.4.0 vendor/redis/examples/pubsub.rb
lunar-0.3.0 vendor/redis/examples/pubsub.rb
lunar-0.2.3 vendor/redis/examples/pubsub.rb
lunar-0.2.2 vendor/redis/examples/pubsub.rb
lunar-0.2.1 vendor/redis/examples/pubsub.rb
lunar-0.2.0 vendor/redis/examples/pubsub.rb
lunar-0.1.1 vendor/redis/examples/pubsub.rb
lunar-0.1.0 vendor/redis/examples/pubsub.rb