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



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

def initialize
  @redis_conn = Redis.new(url: Anycable.config.redis_url)
end

Instance Attribute Details

#redis_connObject (readonly)

Returns the value of attribute redis_conn.



7
8
9
# File 'lib/anycable/pubsub.rb', line 7

def redis_conn
  @redis_conn
end

Instance Method Details

#broadcast(channel, payload) ⇒ Object



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

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