Skip to content

Commit 8ef6057

Browse files
committed
Rearrange redis config
1 parent 7701e1b commit 8ef6057

File tree

3 files changed

+7
-17
lines changed

3 files changed

+7
-17
lines changed

config/runtime.exs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ if config_env() == :prod do
6969
# See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details.
7070
end
7171

72-
config :components_guide, :upstash,
73-
redis_url: System.get_env("REDIS_URL", "")
72+
config :components_guide, :redis,
73+
url: System.get_env("REDIS_URL", "")

lib/components_guide/application.ex

+3-13
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ defmodule ComponentsGuide.Application do
77

88
@impl true
99
def start(_type, _args) do
10-
upstash_config = Application.fetch_env!(:components_guide, :upstash)
11-
redis_url_string = Access.fetch!(upstash_config, :redis_url)
10+
redis_config = Application.fetch_env!(:components_guide, :redis)
11+
redis_url_string = Access.fetch!(redis_config, :url)
1212

1313
children = [
1414
# Start the Telemetry supervisor
@@ -30,20 +30,10 @@ defmodule ComponentsGuide.Application do
3030
id: :research_spec_cache,
3131
start: {Cachex, :start_link, [:research_spec_cache, []]}
3232
},
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
41-
# {Redix, {Access.fetch!(upstash_config, :redis_url), [name: :upstash_redix]}}
33+
{Redix, {redis_url_string, [name: :redix_cache]}}
4234
# ComponentsGuide.Worker
4335
]
4436

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

lib/components_guide/research/source.ex

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ defmodule ComponentsGuide.Research.Source do
2626
defp read_redis_cache(key) do
2727
{duration_microseconds, result} =
2828
:timer.tc(fn ->
29-
case Redix.command(:upstash_redix, ["GET", key]) do
29+
case Redix.command(:redix_cache, ["GET", key]) do
3030
{:ok, value} -> value
3131
_ -> nil
3232
end
@@ -38,7 +38,7 @@ defmodule ComponentsGuide.Research.Source do
3838
end
3939

4040
defp write_redis_cache(key, value) do
41-
result = Redix.command(:upstash_redix, ["SET", key, value])
41+
result = Redix.command(:redix_cache, ["SET", key, value])
4242
IO.inspect(result, label: "Redis write")
4343
end
4444

0 commit comments

Comments
 (0)