Skip to content

Commit 0c89741

Browse files
committed
Start redis if REDIS_URL is defined
1 parent 45d66ca commit 0c89741

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

config/runtime.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ if config_env() == :prod do
7070
end
7171

7272
config :components_guide, :upstash,
73-
redis_url: System.fetch_env!("UPSTASH_REDIS_URL"),
73+
redis_url: System.get_env("REDIS_URL", ""),
7474
redis_rest_url: System.fetch_env!("UPSTASH_REDIS_REST_URL"),
7575
redis_rest_token: System.fetch_env!("UPSTASH_REDIS_REST_TOKEN")

lib/components_guide/application.ex

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ defmodule ComponentsGuide.Application do
99
def start(_type, _args) do
1010
upstash_config = Application.fetch_env!(:components_guide, :upstash)
1111
redis_url_string = Access.fetch!(upstash_config, :redis_url)
12-
redis_uri = URI.new!(redis_url_string)
13-
IO.inspect(redis_uri)
1412

1513
children = [
1614
# Start the Telemetry supervisor
@@ -32,11 +30,20 @@ defmodule ComponentsGuide.Application do
3230
id: :research_spec_cache,
3331
start: {Cachex, :start_link, [:research_spec_cache, []]}
3432
},
33+
case redis_url_string do
34+
"" ->
35+
nil
36+
37+
redis_url_string ->
38+
{Redix, {redis_url_string, [name: :upstash_redix]}}
39+
end,
40+
nil
3541
# {Redix, {Access.fetch!(upstash_config, :redis_url), [name: :upstash_redix]}}
36-
# {Redix, {redis_url_string, [name: :upstash_redix]}}
3742
# ComponentsGuide.Worker
3843
]
3944

45+
children = children |> Enum.reject(&is_nil/1)
46+
4047
# See https://hexdocs.pm/elixir/Supervisor.html
4148
# for other strategies and supported options
4249
opts = [strategy: :one_for_one, name: ComponentsGuide.Supervisor]

0 commit comments

Comments
 (0)