Class: AnyCable::BroadcastAdapters::Redis

Inherits:
Base
  • Object
show all
Defined in:
lib/anycable/broadcast_adapters/redis.rb

Overview

Redis adapter for broadcasting.

Example:

AnyCable.broadcast_adapter = :redis

It uses Redis configuration from global AnyCable config by default.

You can override these params:

AnyCable.broadcast_adapter = :redis, { url: "redis://my_redis", channel: "_any_cable_" }

Direct Known Subclasses

Redisx

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#batching, #batching?, #broadcast, #broadcast_command, #finish_batching, #start_batching

Constructor Details

#initialize(channel: AnyCable.config.redis_channel, **options) ⇒ Redis

Returns a new instance of Redis.



28
29
30
31
32
33
34
35
36
# File 'lib/anycable/broadcast_adapters/redis.rb', line 28

def initialize(
  channel: AnyCable.config.redis_channel,
  **options
)
  options = AnyCable.config.to_redis_params.merge(options)
  options[:driver] ||= :ruby
  @redis_conn = ::Redis.new(**options)
  @channel = channel
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



26
27
28
# File 'lib/anycable/broadcast_adapters/redis.rb', line 26

def channel
  @channel
end

#redis_connObject (readonly)

Returns the value of attribute redis_conn.



26
27
28
# File 'lib/anycable/broadcast_adapters/redis.rb', line 26

def redis_conn
  @redis_conn
end

Instance Method Details

#announce!Object



42
43
44
# File 'lib/anycable/broadcast_adapters/redis.rb', line 42

def announce!
  logger.info "Broadcasting Redis channel: #{channel}"
end

#raw_broadcast(payload) ⇒ Object



38
39
40
# File 'lib/anycable/broadcast_adapters/redis.rb', line 38

def raw_broadcast(payload)
  redis_conn.publish(channel, payload)
end