CouncilEx.Registry.Backend behaviour (CouncilEx v0.1.0)

Copy Markdown View Source

Pluggable storage backend for CouncilEx.Registry runtime registrations.

Config entries (set via config :council_ex, :registry, ...) bypass the backend — they're read directly from app env on every lookup. The backend stores runtime-only registrations made via CouncilEx.Registry.register_*/2.

Built-in backends

  • CouncilEx.Registry.ETS — in-memory, per-node, default. Zero-config, fast, lost on restart, NOT cluster-safe.
  • CouncilEx.Registry.Ecto — Ecto-backed, multi-replica safe. Add :ecto_sql + :postgrex (or another adapter) to your deps.
  • CouncilEx.Registry.Redis — Redis-backed, multi-replica safe. Add :redix to your deps and run a Redix connection.

Ecto and Redis backends encode stored values via term_to_binary and decode in :safe mode; runtime-registered modules must be loaded on every replica (same code, same release).

Selecting a backend

config :council_ex,
  :registry_backend,
  CouncilEx.Registry.Ecto

Defaults to CouncilEx.Registry.ETS.

Summary

Types

kind()

@type kind() :: atom()

name()

@type name() :: String.t()

Callbacks

all(kind)

@callback all(kind()) :: %{required(name()) => term()}

delete(kind, name)

@callback delete(kind(), name()) :: :ok | {:error, term()}

get(kind, name)

@callback get(kind(), name()) :: term() | nil

put(kind, name, term)

@callback put(kind(), name(), term()) :: :ok | {:error, term()}

reset()

@callback reset() :: :ok | {:error, term()}