Skip to content

Commit

Permalink
Merge pull request #29 from sendle/master
Browse files Browse the repository at this point in the history
Allow configuration of redis using {:system, envvar}
  • Loading branch information
tompave committed Nov 7, 2018
2 parents 867a638 + b9c47c5 commit ce30d8a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -512,6 +512,9 @@ config :fun_with_flags, :redis,

# a URL string can be used instead
config :fun_with_flags, :redis, "redis://locahost:6379/0"

# a {:system, name} tuple can be used to read from the environment
config :fun_with_flags, :redis, {:system, "REDIS_URL"}
```

### Persistence Adapters
Expand Down
2 changes: 2 additions & 0 deletions lib/fun_with_flags/config.ex
Expand Up @@ -27,6 +27,8 @@ defmodule FunWithFlags.Config do
uri
opts when is_list(opts) ->
Keyword.merge(@default_redis_config, opts)
{:system, var} when is_binary(var) ->
System.get_env(var)
end
end

Expand Down
6 changes: 6 additions & 0 deletions test/fun_with_flags/config_test.exs
Expand Up @@ -28,6 +28,12 @@ defmodule FunWithFlags.ConfigTest do
assert 2000 == Config.redis_config[:port]
assert 42 == Config.redis_config[:database]

# Whe configured with a {:system, env} tuple it looks up the value in the env
System.put_env("123_TEST_REDIS_URL", url)
configure_redis_with({:system, "123_TEST_REDIS_URL"})
assert url == Config.redis_config
System.delete_env("123_TEST_REDIS_URL")

# cleanup
configure_redis_with(defaults)
end
Expand Down

0 comments on commit ce30d8a

Please sign in to comment.