Class: Anycable::PubSub

Inherits:
Object
  • Object
show all
Defined in:
lib/anycable/pubsub.rb

Overview

PubSub for broadcasting

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePubSub

Returns a new instance of PubSub.



11
12
13
14
15
16
17
# File 'lib/anycable/pubsub.rb', line 11

def initialize
  redis_config = { url: Anycable.config.redis_url }
  unless Anycable.config.redis_sentinels.empty?
    redis_config[:sentinels] = Anycable.config.redis_sentinels
  end
  @redis_conn = Redis.new(redis_config)
end

Instance Attribute Details

#redis_connObject (readonly)

Returns the value of attribute redis_conn.



9
10
11
# File 'lib/anycable/pubsub.rb', line 9

def redis_conn
  @redis_conn
end

Instance Method Details

#broadcast(channel, payload) ⇒ Object



19
20
21
22
23
24
# File 'lib/anycable/pubsub.rb', line 19

def broadcast(channel, payload)
  redis_conn.publish(
    Anycable.config.redis_channel,
    { stream: channel, data: payload }.to_json
  )
end