ExReg

Build StatusHex pmhex.pm downloads

A simple process name registry using :pg:

Small example

Let's say we define the following Agent for keeping a counter:

defmodule Counter do
  use Agent

  def start_link(options \\ []) do
    Agent.start_link(fn -> 0 end, options)
  end

  def increment(counter) do
    Agent.get_and_update(counter, &{&1, &1 + 1})
  end
end

We can now start it using ExReg as name registry:

iex(1)> name = {:via, ExReg, {"metric", :my_counter}}
iex(2)> Counter.start_link(name: name)
{:ok, #PID<0.42.0>}
iex(3)> Counter.increment(name)
1
iex(4)> Counter.increment(name)
2

Distributed systems

In a distributed environment, there are several things to notice:

Installation

Add ExReg to your list of dependencies in mix.exs:

def deps do
  [{:exreg, "~> 1.0"}]
end

Requires OTP 24 or more.

Author

Alexander de Sousa

License

ExReg is released under the MIT License. See the LICENSE file for further details.