View Source Minikv.Registry (minikv v0.1.1)

A registry for Minikv, providing a distributed key-value store.

Summary

Functions

Returns a specification to start this module under a supervisor.

Deletes a value from the registry.

Retrieves a value from the registry.

Callback implementation for GenServer.init/1.

Lock a key in the registry.

Persist a key value in the registry.

Puts a value into the registry.

Unlock a key in the registry.

Types

@type kv() :: Minikv.Kv.t()
@type lock() :: Minikv.Kv.lock()
@type result() ::
  nil
  | %Minikv.Kv{
      exp: term(),
      lock: term(),
      node: term(),
      time: term(),
      value: term()
    }

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec delete(atom(), binary()) :: result()

Deletes a value from the registry.

Example

iex> {:ok, registry} = Minikv.Registry.start_link(name: :my_registry)
iex> Minikv.Registry.delete(registry, "my_key")
:ok
@spec get(atom(), binary()) :: result()

Retrieves a value from the registry.

Example

iex> {:ok, registry} = Minikv.Registry.start_link(name: :my_registry)
iex> Minikv.Registry.get(registry, "my_key")
%Minikv.Kv{value: "my_value", node: :node1, time: 123456789}

Callback implementation for GenServer.init/1.

@spec lock(atom(), binary()) :: result()

Lock a key in the registry.

Example

iex> {:ok, registry} = Minikv.Registry.start_link(name: :my_registry)
iex> Minikv.Registry.lock(registry, "my_key")
:ok
@spec persist(atom(), binary()) :: result()

Persist a key value in the registry.

Example

iex> {:ok, registry} = Minikv.Registry.start_link(name: :my_registry)
iex> Minikv.Registry.delete(registry, "my_key")
:ok
@spec put(atom(), binary(), kv() | any()) :: result()

Puts a value into the registry.

Example

iex> {:ok, registry} = Minikv.Registry.start_link(name: :my_registry)
iex> Minikv.Registry.put(registry, "my_key", "my_value")
:ok
@spec unlock(atom(), binary()) :: result()

Unlock a key in the registry.

Example

iex> {:ok, registry} = Minikv.Registry.start_link(name: :my_registry)
iex> Minikv.Registry.lock(registry, "my_key")
:ok
iex> Minikv.Registry.unlock(registry, "my_key")
:ok