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:
self,
ChannelPrefix ,
Base
|
|
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 differentRedis
library than the redis gem.
Class Method Summary
Instance Attribute Summary
Instance Method Summary
- #broadcast(channel, payload)
- #redis_connection_for_subscriptions
- #shutdown
- #subscribe(channel, callback, success_callback = nil)
- #unsubscribe(channel, callback)
- #config_options private
- #listener private
- #redis_connection private
- #redis_connection_for_broadcasts private
ChannelPrefix
- Included
#broadcast, #subscribe, #unsubscribe, | |
#channel_with_prefix | Returns the channel name, including channel_prefix specified in cable.yml. |
Base
- Inherited
Constructor Details
.new ⇒ Redis
# 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
.
# 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 ||= @server.config.cable.deep_symbolize_keys.merge(id: identifier) end
#listener (private)
[ GitHub ]#redis_connection (private)
[ GitHub ]# File 'actioncable/lib/action_cable/subscription_adapter/redis.rb', line 59
def redis_connection self.class.redis_connector.call( ) 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