phoenixframework / phoenix_pubsub_redis

The Redis PubSub adapter for the Phoenix framework
175 stars 66 forks source link

Recommended configuration for development #54

Open liamwhite opened 3 years ago

liamwhite commented 3 years ago

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?

yoelfme commented 3 years ago

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
liamwhite commented 3 years ago

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?

yoelfme commented 3 years ago

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