ConsulKv

GitHub actions StatusHex.pm Version

Elixir SDK for Consul KV store.

Installation

The package could be installed as:

def deps do
  [
    {:consul_kv, "~> 0.1.0"}
  ]
end

Configuration

There are several configuration options for the client:

Usage

1. setup correct configuration

2. put kv pair

iex(1)> ConsulKv.put("consul-kv/k1", "v1")
{:ok, true}

3. get value

iex(2)> ConsulKv.get("consul-kv/k1")
{:ok,
 [
   %ConsulKv{
     create_index: 45687,
     flags: 0,
     key: "consul-kv/k1",
     lock_index: 0,
     modify_index: 45687,
     session: nil,
     value: "v1"
   }
 ]}

or use single get

iex(3)> ConsulKv.single_get("consul-kv/k1")
{:ok,
 %ConsulKv{
   create_index: 45687,
   flags: 0,
   key: "consul-kv/k1",
   lock_index: 0,
   modify_index: 45687,
   session: nil,
   value: "v1"
 }}

if you want put more than one keys share a prefix, like:

iex(4)> ConsulKv.put("consul-kv/k2", "v2")
{:ok, true}

you can also use recurse get to fetch all kvs which sharing one prefix:

iex(5)> ConsulKv.recurse_get("consul-kv")
{:ok,
 [
   %ConsulKv{
     create_index: 45687,
     flags: 0,
     key: "consul-kv/k1",
     lock_index: 0,
     modify_index: 45687,
     session: nil,
     value: "v1"
   },
   %ConsulKv{
     create_index: 45871,
     flags: 0,
     key: "consul-kv/k2",
     lock_index: 0,
     modify_index: 45871,
     session: nil,
     value: "v2"
   }
 ]}

4. delete

delete one kv:

iex(6)> ConsulKv.recurse_delete("consul-kv")
{:ok, true}

More information, you can check the function document. And more usage example, please check the unit test cases.

Contributions

Any contributions are welcomed, documentation especially.