Skip to content

Instantly share code, notes, and snippets.

@emschwar
Last active February 29, 2016 23:55
Show Gist options
  • Save emschwar/fe630a4bc6d641fb3447 to your computer and use it in GitHub Desktop.
Save emschwar/fe630a4bc6d641fb3447 to your computer and use it in GitHub Desktop.
Hello Controller with redis
defmodule HelloPhoenix.HelloController do
use HelloPhoenix.Web, :controller
def index(conn, _params) do
render conn, "index.html"
end
def show(conn, %{"messenger" => messenger} = params) do
HelloPhoenix.Endpoint.subscribe(self(), "potato")
receive do
%Phoenix.Socket.Broadcast{event: "response", payload: %{message: message}, topic: "potato"} ->
IO.puts "here's a message"
IO.inspect message
render conn, "show.html", messenger: messenger, message: message
after
120000 -> send_resp(conn, :no_content, "")
end
end
def create(conn, %{"message" => message} = params) do
HelloPhoenix.Endpoint.broadcast("potato", "response", %{message: message})
send_resp(conn, :no_content, "")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment