123456789_123456789_123456789_123456789_123456789_

Class: ActionCable::SubscriptionAdapter::Redis

Do not use. This class is for internal use only.
Relationships & Source Files
Namespace Children
Classes:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Base
Instance Chain:
Inherits: ActionCable::SubscriptionAdapter::Base
Defined in: actioncable/lib/action_cable/subscription_adapter/redis.rb

Class Attribute Summary

  • .redis_connector (also: #redis_connector) rw

    Overwrite this factory method for Redis connections if you want to use a different Redis library than the redis gem.

Class Method Summary

Base - Inherited

Instance Attribute Summary

Instance Method Summary

Constructor Details

.newRedis

[ GitHub ]

  
# File 'actioncable/lib/action_cable/subscription_adapter/redis.rb', line 22

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

Class Attribute Details

.redis_connector (rw) Also known as: #redis_connector

Overwrite this factory method for Redis connections if you want to use a different Redis library than the redis gem. This is needed, for example, when using Makara proxies for distributed Redis.

[ GitHub ]

  
# File 'actioncable/lib/action_cable/subscription_adapter/redis.rb', line 18

cattr_accessor :redis_connector, default: ->(config) do
  ::Redis.new(config.except(:adapter, :channel_prefix))
end

Instance Attribute Details

#redis_connector (rw)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/subscription_adapter/redis.rb', line 18

cattr_accessor :redis_connector, default: ->(config) do
  ::Redis.new(config.except(:adapter, :channel_prefix))
end

Instance Method Details

#broadcast(channel, payload)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/subscription_adapter/redis.rb', line 28

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

#config_options (private)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/subscription_adapter/redis.rb', line 63

def config_options
  @config_options ||= @server.config.cable.deep_symbolize_keys.merge(id: identifier)
end

#listener (private)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/subscription_adapter/redis.rb', line 49

def listener
  @listener || @server.mutex.synchronize { @listener ||= Listener.new(self, config_options, @server.event_loop) }
end

#redis_connection (private)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/subscription_adapter/redis.rb', line 59

def redis_connection
  self.class.redis_connector.call(config_options)
end

#redis_connection_for_broadcasts (private)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/subscription_adapter/redis.rb', line 53

def redis_connection_for_broadcasts
  @redis_connection_for_broadcasts || @server.mutex.synchronize do
    @redis_connection_for_broadcasts ||= redis_connection
  end
end

#redis_connection_for_subscriptions

[ GitHub ]

  
# File 'actioncable/lib/action_cable/subscription_adapter/redis.rb', line 44

def redis_connection_for_subscriptions
  redis_connection
end

#shutdown

[ GitHub ]

  
# File 'actioncable/lib/action_cable/subscription_adapter/redis.rb', line 40

def shutdown
  @listener.shutdown if @listener
end

#subscribe(channel, callback, success_callback = nil)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/subscription_adapter/redis.rb', line 32

def subscribe(channel, callback, success_callback = nil)
  listener.add_subscriber(channel, callback, success_callback)
end

#unsubscribe(channel, callback)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/subscription_adapter/redis.rb', line 36

def unsubscribe(channel, callback)
  listener.remove_subscriber(channel, callback)
end