This repository was archived by the owner on Dec 7, 2018. It is now read-only.

Description
I want to subscribe to redis, but it seems that the blocking redis subscribe blocks the whole actor. Thus, I tried celluloid-redis, but it seems I dont get it working. The following actor blocks inside subscribe and does not handle TerminationRequests within its Mailbox.
require 'celluloid/redis'
class RedisObserver
include Celluloid
finalizer :unsubscribe
def initialize
@redis = ::Redis.new(driver: :celluloid)
@redis.config(:set, "notify-keyspace-events", "EA")
after(1) { async.subscribe }
puts "initialized"
end
def subscribe
puts "starting"
@redis.psubscribe("__key*__:*") do |on|
on.psubscribe do |pattern, total|
puts "Subscribed to ##{pattern} (#{total} subscriptions)"
end
on.pmessage do |pattern, channel, message|
puts "#{pattern} ##{channel}: #{message}"
end
on.punsubscribe do |pattern, total|
puts "Unsubscribed from ##{pattern} (#{total} subscriptions)"
end
end
puts "started"
end
def unsubscribe
puts "unsubscribe"
begin
@redis.unsubscribe
rescue
puts $!
end
end
end