mirror of
https://github.com/benbusby/farside.git
synced 2025-03-15 11:46:32 -04:00

Can just use a wildcard in the initial keys query, rather than grabbing all keys and filtering by service prefix.
37 lines
762 B
Elixir
37 lines
762 B
Elixir
defmodule Farside do
|
|
@service_prefix Application.fetch_env!(:farside, :service_prefix)
|
|
|
|
def get_services_map do
|
|
{:ok, service_list} = Redix.command(:redix, ["KEYS", "#{@service_prefix}*"])
|
|
|
|
# Match service name to list of available instances
|
|
Enum.reduce(service_list, %{}, fn service, acc ->
|
|
{:ok, instance_list} =
|
|
Redix.command(
|
|
:redix,
|
|
["LRANGE", service, "0", "-1"]
|
|
)
|
|
|
|
Map.put(
|
|
acc,
|
|
String.replace_prefix(
|
|
service,
|
|
@service_prefix,
|
|
""
|
|
),
|
|
instance_list
|
|
)
|
|
end)
|
|
end
|
|
|
|
def get_last_updated do
|
|
{:ok, last_updated} =
|
|
Redix.command(
|
|
:redix,
|
|
["GET", "last_updated"]
|
|
)
|
|
|
|
last_updated
|
|
end
|
|
end
|