mirror of
https://github.com/benbusby/farside.git
synced 2025-04-20 10:58:42 +00:00
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:
parent
85123cb524
commit
2189c9ddca
1 changed files with 1 additions and 10 deletions
|
@ -2,16 +2,7 @@ defmodule Farside do
|
||||||
@service_prefix Application.fetch_env!(:farside, :service_prefix)
|
@service_prefix Application.fetch_env!(:farside, :service_prefix)
|
||||||
|
|
||||||
def get_services_map do
|
def get_services_map do
|
||||||
{:ok, redis_keys} = Redix.command(:redix, ["KEYS", "*"])
|
{:ok, service_list} = Redix.command(:redix, ["KEYS", "#{@service_prefix}*"])
|
||||||
|
|
||||||
# Extract only service related keys
|
|
||||||
service_list =
|
|
||||||
Enum.filter(
|
|
||||||
redis_keys,
|
|
||||||
fn key ->
|
|
||||||
String.starts_with?(key, @service_prefix)
|
|
||||||
end
|
|
||||||
)
|
|
||||||
|
|
||||||
# Match service name to list of available instances
|
# Match service name to list of available instances
|
||||||
Enum.reduce(service_list, %{}, fn service, acc ->
|
Enum.reduce(service_list, %{}, fn service, acc ->
|
||||||
|
|
Loading…
Add table
Reference in a new issue