Simplify retrieval of service keys from redis

Can just use a wildcard in the initial keys query, rather than grabbing
all keys and filtering by service prefix.
This commit is contained in:
Ben Busby 2021-11-10 10:47:04 -07:00
parent 85123cb524
commit 2189c9ddca
No known key found for this signature in database
GPG key ID: 339B7B7EB5333D14

View file

@ -2,16 +2,7 @@ defmodule Farside do
@service_prefix Application.fetch_env!(:farside, :service_prefix)
def get_services_map do
{:ok, redis_keys} = Redix.command(:redix, ["KEYS", "*"])
# Extract only service related keys
service_list =
Enum.filter(
redis_keys,
fn key ->
String.starts_with?(key, @service_prefix)
end
)
{:ok, service_list} = Redix.command(:redix, ["KEYS", "#{@service_prefix}*"])
# Match service name to list of available instances
Enum.reduce(service_list, %{}, fn service, acc ->