Class: ActionCable::SubscriptionAdapter::EventedRedis

Inherits:
Base
  • Object
show all
Defined in:
lib/action_cable/subscription_adapter/evented_redis.rb

Overview

:nodoc:

Constant Summary collapse

@@mutex =
Mutex.new

Instance Attribute Summary

Attributes inherited from Base

#logger, #server

Instance Method Summary collapse

Constructor Details

#initializeEventedRedis

Returns a new instance of EventedRedis.



24
25
26
27
# File 'lib/action_cable/subscription_adapter/evented_redis.rb', line 24

def initialize(*)
  super
  @redis_connection_for_broadcasts = @redis_connection_for_subscriptions = nil
end

Instance Method Details

#broadcast(channel, payload) ⇒ Object



29
30
31
# File 'lib/action_cable/subscription_adapter/evented_redis.rb', line 29

def broadcast(channel, payload)
  redis_connection_for_broadcasts.publish(channel, payload)
end

#shutdownObject



43
44
45
46
# File 'lib/action_cable/subscription_adapter/evented_redis.rb', line 43

def shutdown
  redis_connection_for_subscriptions.pubsub.close_connection
  @redis_connection_for_subscriptions = nil
end

#subscribe(channel, message_callback, success_callback = nil) ⇒ Object



33
34
35
36
37
# File 'lib/action_cable/subscription_adapter/evented_redis.rb', line 33

def subscribe(channel, message_callback, success_callback = nil)
  redis_connection_for_subscriptions.pubsub.subscribe(channel, &message_callback).tap do |result|
    result.callback { |reply| success_callback.call } if success_callback
  end
end

#unsubscribe(channel, message_callback) ⇒ Object



39
40
41
# File 'lib/action_cable/subscription_adapter/evented_redis.rb', line 39

def unsubscribe(channel, message_callback)
  redis_connection_for_subscriptions.pubsub.unsubscribe_proc(channel, message_callback)
end