View Source Minikv.Kvs (minikv v0.1.1)

A supervisor for Minikv, providing a key-value store.

Summary

Functions

A macro to use the KVS in a module.

Returns a specification to start this module under a supervisor.

Deletes a value from the KVS.

Retrieves a value from the KVS.

Callback implementation for Supervisor.init/1.

Lock a key in the registry.

Persist a key value in the registry.

Puts a value into the KVS.

Puts a value into the KVS.

Unlock a key in the registry.

Types

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

Functions

Link to this macro

__using__(opts)

View Source (macro)

A macro to use the KVS in a module.

Example

defmodule MyExampleKvs do
  use Minikv.Kvs
end
@spec child_spec(keyword()) :: map()

Returns a specification to start this module under a supervisor.

See Supervisor.

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

Deletes a value from the KVS.

Example

iex> Minikv.Kvs.delete(:my_kvs, "my_key")
:ok
@spec get(atom(), binary()) :: result()

Retrieves a value from the KVS.

Example

iex> Minikv.Kvs.get(:my_kvs, "my_key")
%Kv{value: "my_value", node: :node1, time: 123456789}

Callback implementation for Supervisor.init/1.

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

Lock a key in the registry.

Example

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

Persist a key value in the registry.

Example

iex> {:ok, registry} = Minikv.Kvs.start_link(name: :my_registry)
iex> Minikv.Kvs.delete(registry, "my_key")
:ok
Link to this function

put(name, key, value_or_opts)

View Source
@spec put(atom(), binary(), kv() | any()) :: result()

Puts a value into the KVS.

Example

iex> Minikv.Kvs.put(:my_kvs, "my_key", "my_value")
:ok
Link to this function

set(name, key, value_or_opts)

View Source
@spec set(atom(), binary(), any() | kv()) :: result()

Puts a value into the KVS.

Example

iex> Minikv.Kvs.set(:my_kvs, "my_key", "my_value")
:ok
@spec start_link(keyword()) :: {:ok, pid()}
@spec unlock(atom(), binary()) :: result()

Unlock a key in the registry.

Example

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