class Phoenix::Pubsub::Redis

Public Class Methods

new(redis_url: 'redis://localhost:6379', phoenix_class: 'Chat.PubSub') click to toggle source
# File lib/phoenix/pubsub.rb, line 43
def initialize(redis_url: 'redis://localhost:6379', phoenix_class: 'Chat.PubSub')
  @phoenix_class_name = phoenix_class
  @redis = ::Redis.new(url: redis_url)
end

Public Instance Methods

publish(topic, event, payload) click to toggle source
# File lib/phoenix/pubsub.rb, line 48
def publish topic, event, payload
  @redis.publish("phx:Elixir.#{@phoenix_class_name}", serialize_message(topic, event, payload))
end

Private Instance Methods

serialize_message(topic, event, payload) click to toggle source
# File lib/phoenix/pubsub.rb, line 54
def serialize_message topic, event, payload
  vsn = 1
  node_ref = ''
  fastlane = :nil
  pool_size = 1
  from_pid = :none
  msg = {
    :__struct__ => :"Elixir.Phoenix.Socket.Broadcast",
    :event => event,
    :payload => payload,
    :topic => topic
  }

  term = Erlang::Tuple[vsn, node_ref, fastlane, pool_size, from_pid, topic, msg]
  Erlang.term_to_binary term
end