Class: ActionCable::SubscriptionAdapter::EventedRedis

Inherits:
Base
  • Object
show all
Includes:
ChannelPrefix
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.



26
27
28
29
30
31
32
33
34
35
# File 'lib/action_cable/subscription_adapter/evented_redis.rb', line 26

def initialize(*)
  ActiveSupport::Deprecation.warn(<<-MSG.squish)
    The "evented_redis" subscription adapter is deprecated and
    will be removed in Rails 5.2. Please use the "redis" adapter
    instead.
  MSG

  super
  @redis_connection_for_broadcasts = @redis_connection_for_subscriptions = nil
end

Instance Method Details

#broadcast(channel, payload) ⇒ Object



37
38
39
# File 'lib/action_cable/subscription_adapter/evented_redis.rb', line 37

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

#shutdownObject



51
52
53
54
# File 'lib/action_cable/subscription_adapter/evented_redis.rb', line 51

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

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



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

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



47
48
49
# File 'lib/action_cable/subscription_adapter/evented_redis.rb', line 47

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