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

Blocking Pub/Sub (Is this gem dead?) #22

@eppdot

Description

@eppdot

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions