Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Redis Sentinel option config #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/phoenix_pubsub_redis/redis.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ defmodule Phoenix.PubSub.Redis do
compression_level = Keyword.get(opts, :compression_level, 0)

opts = handle_url_opts(opts)
opts = Keyword.merge(@defaults, opts)
opts = merged_opts(opts)
redis_opts = Keyword.take(opts, @redis_opts)

node_name = opts[:node_name] || node()
Expand All @@ -92,7 +92,7 @@ defmodule Phoenix.PubSub.Redis do

Supervisor.init(children, strategy: :rest_for_one)
end

defp handle_url_opts(opts) do
if opts[:url] do
merge_url_opts(opts)
Expand All @@ -116,6 +116,14 @@ defmodule Phoenix.PubSub.Redis do
|> Keyword.merge(host: info.host, port: info.port || @defaults[:port])
end

defp merged_opts(opts) do
case Keyword.take(opts, [:sentinel]) do
[] -> Keyword.merge(@defaults, opts)
# Redix doesn't support host and port for Redis Sentinel
[_head | _tail] -> opts
end
end

defp validate_node_name!(node_name) do
if node_name in [nil, :nonode@nohost] do
raise ArgumentError, ":node_name is a required option for unnamed nodes"
Expand Down