phoenixframework/phoenix_pubsub_redis

Recommended configuration for development

liamwhite opened this issue · 3 comments

If you add

  {Phoenix.PubSub, adapter: Phoenix.PubSub.Redis}

to your list of child applications, and then try to start the application in development mode (for example with iex -S mix), you will get an error from this line:

    if node_name in [nil, :nonode@nohost] do
      raise ArgumentError, ":node_name is a required option for unnamed nodes"
    end

I hacked around this by doing the following:

  children = [
    {Phoenix.PubSub,
     [
       name: Philomena.PubSub,
       adapter: Phoenix.PubSub.Redis,
       node_name: valid_node_name(node())
     ]}
  ]

  # Redis adapter really really wants you to have a unique node name,
  # so just fake one if iex is being started
  defp valid_node_name(node) when node in [nil, :nonode@nohost],
    do: Base.encode16(:crypto.strong_rand_bytes(6))

  defp valid_node_name(node), do: node

Surely there must be a better way?

yep, I think that you can pass the --sname flag to the iex command and there set a name like:

iex --sname foo -S mix

and if you have zsh and you are using Mac you can get the current username name and pass that as a value to the flag:

iex --sname $(id -un) -S mix

I guess with this issue I am asking why it matters for this library. If the entire point is connecting to a named redis instance, why can't the node just be anonymous?

Oh got it, well maybe the authors can explained that better, I just showed u another "hack"