Skip to content

Commit

Permalink
Allow 'rediss' scheme to define whether SSL is enabled
Browse files Browse the repository at this point in the history
If the URL uses the 'rediss' scheme, SSL should be enabled. This follows the
behaviour of Redix standalone and embedded in other libraries.
  • Loading branch information
tomtaylor committed Jul 14, 2021
1 parent 91df117 commit f98b5f6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Option | Description
`:host` | The redis-server host IP | `"127.0.0.1"` |
`:port` | The redis-server port | `6379` |
`:password` | The redis-server password | `""` |
`:ssl` | The redis-server SSL flag | `false` |
`:compression_level` | Compression level applied to serialized terms (`0` - none, `9` - highest) | `0` |
`:socket_opts` | The redis-server network layer options | `[]` |

Expand Down
5 changes: 4 additions & 1 deletion lib/phoenix_pubsub_redis/redis.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule Phoenix.PubSub.Redis do
* `:host` - The redis-server host IP, defaults `"127.0.0.1"`
* `:port` - The redis-server port, defaults `6379`
* `:password` - The redis-server password, defaults `""`
* `:ssl` - The redis-server ssl option, defaults `false`
* `:ssl` - The redis-server ssl option, defaults `false`, unless the URL scheme is `rediss`
* `:redis_pool_size` - The size of the redis connection pool. Defaults `5`
* `:compression_level` - Compression level applied to serialized terms - from `0` (no compression), to `9` (highest). Defaults `0`
* `:socket_opts` - List of options that are passed to the network layer when connecting to the Redis server. Default `[]`
Expand Down Expand Up @@ -111,9 +111,12 @@ defmodule Phoenix.PubSub.Redis do
[username, password] -> [username: username, password: password]
end

ssl = info.scheme == "rediss"

opts
|> Keyword.merge(user_opts)
|> Keyword.merge(host: info.host, port: info.port || @defaults[:port])
|> Keyword.put(:ssl, ssl)
end

defp validate_node_name!(node_name) do
Expand Down

0 comments on commit f98b5f6

Please sign in to comment.