Class: AnyCable::BroadcastAdapters::Redisx

Inherits:
Redis
  • Object
show all
Defined in:
lib/anycable/broadcast_adapters/redisx.rb

Overview

Next-gen Redis adapter for broadcasting over Redis streams.

Unlike Redis adapter, RedisX adapter delivers each broadcast message only to a single WS server, which is responsible for re-broadcasting it within the cluster. It’s required for the Broker (hot streams cache) support.

Example:

AnyCable.broadcast_adapter = :redisx

It uses Redis configuration from global AnyCable config by default. NOTE: The ‘redis_channel` config param is used as a stream name.

You can override these params:

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

Instance Attribute Summary

Attributes inherited from Redis

#channel, #redis_conn

Instance Method Summary collapse

Methods inherited from Redis

#initialize

Methods inherited from Base

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

Constructor Details

This class inherits a constructor from AnyCable::BroadcastAdapters::Redis

Instance Method Details

#announce!Object



29
30
31
# File 'lib/anycable/broadcast_adapters/redisx.rb', line 29

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

#raw_broadcast(payload) ⇒ Object



25
26
27
# File 'lib/anycable/broadcast_adapters/redisx.rb', line 25

def raw_broadcast(payload)
  redis_conn.xadd(channel, {payload: payload})
end