Class: Anycable::PubSub
- Inherits:
-
Object
- Object
- Anycable::PubSub
- Defined in:
- lib/anycable/pubsub.rb
Overview
PubSub for broadcasting
Instance Attribute Summary collapse
-
#redis_conn ⇒ Object
readonly
Returns the value of attribute redis_conn.
Instance Method Summary collapse
- #broadcast(channel, payload) ⇒ Object
-
#initialize ⇒ PubSub
constructor
A new instance of PubSub.
Constructor Details
#initialize ⇒ PubSub
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_conn ⇒ Object (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 |