View Source Jetstream.API.KV (jetstream v0.0.5)

API for interacting with the Key/Value store functionality in Nats Jetstream.

Learn about the Key/Value store: https://docs.nats.io/nats-concepts/jetstream/key-value-store

Link to this section Summary

Functions

Get all the non-deleted key-value pairs for a Bucket

Create a new Key/Value bucket. Can include the following options

Create a Key in a Key/Value Bucket

Delete a Key/Value bucket

Delete a Key from a K/V Bucket

Get the value for a key in a particular K/V bucket

Purge a Key from a K/V bucket. This will remove any revision history the key had

Put a value into a Key in a K/V Bucket

Link to this section Types

Specs

bucket_options() ::
  {:history, non_neg_integer()}
  | {:ttl, non_neg_integer()}
  | {:max_bucket_size, non_neg_integer()}
  | {:max_value_size, non_neg_integer()}
  | {:description, binary()}
  | {:replicas, non_neg_integer()}
  | {:storage, :file | :memory}
  | {:placement, Jetstream.API.Stream.placement()}

Link to this section Functions

Link to this function

contents(conn, bucket_name)

View Source

Specs

contents(conn :: Gnat.t(), bucket_name :: binary()) ::
  {:ok, map()} | {:error, binary()}

Get all the non-deleted key-value pairs for a Bucket

Examples

iex>{:ok, %{"key1" => "value1"}} = Jetstream.API.KV.contents(:gnat, "my_bucket")
Link to this function

create_bucket(conn, bucket_name, params \\ [])

View Source

Specs

create_bucket(
  conn :: Gnat.t(),
  bucket_name :: binary(),
  params :: [bucket_options()]
) :: {:ok, Jetstream.API.Stream.info()} | {:error, any()}

Create a new Key/Value bucket. Can include the following options

  • :history - How many historic values to keep per key (defaults to 1, max of 64)
  • :ttl - How long to keep values for (in nanoseconds)
  • :max_bucket_size - The max number of bytes the bucket can hold
  • :max_value_size - The max number of bytes a value may be
  • :description - A description for the bucket
  • :replicas - How many replicas of the data to store
  • :storage - Storage backend to use (:file, :memory)
  • :placement - A map with :cluster (required) and :tags (optional)

Examples

iex>{:ok, info} = Jetstream.API.KV.create_bucket(:gnat, "my_bucket")

Link to this function

create_key(conn, bucket_name, key, value)

View Source

Specs

create_key(
  conn :: Gnat.t(),
  bucket_name :: binary(),
  key :: binary(),
  value :: binary()
) :: :ok

Create a Key in a Key/Value Bucket

Examples

iex>:ok = Jetstream.API.KV.create_key(:gnat, "my_bucket", "my_key", "my_value")
Link to this function

delete_bucket(conn, bucket_name)

View Source

Specs

delete_bucket(conn :: Gnat.t(), bucket_name :: binary()) ::
  :ok | {:error, any()}

Delete a Key/Value bucket

Examples

iex>:ok = Jetstream.API.KV.delete_bucket(:gnat, "my_bucket")

Link to this function

delete_key(conn, bucket_name, key)

View Source

Specs

delete_key(conn :: Gnat.t(), bucket_name :: binary(), key :: binary()) :: :ok

Delete a Key from a K/V Bucket

Examples

iex>:ok = Jetstream.API.KV.delete_key(:gnat, "my_bucket", "my_key")
Link to this function

get_value(conn, bucket_name, key)

View Source

Specs

get_value(conn :: Gnat.t(), bucket_name :: binary(), key :: binary()) ::
  binary() | {:error, any()}

Get the value for a key in a particular K/V bucket

Examples

iex>"my_value" = Jetstream.API.KV.get_value(:gnat, "my_bucket", "my_key")
Link to this function

purge_key(conn, bucket_name, key)

View Source

Specs

purge_key(conn :: Gnat.t(), bucket_name :: binary(), key :: binary()) :: :ok

Purge a Key from a K/V bucket. This will remove any revision history the key had

Examples

iex>:ok = Jetstream.API.KV.purge_key(:gnat, "my_bucket", "my_key")
Link to this function

put_value(conn, bucket_name, key, value)

View Source

Specs

put_value(
  conn :: Gnat.t(),
  bucket_name :: binary(),
  key :: binary(),
  value :: binary()
) :: :ok

Put a value into a Key in a K/V Bucket

Examples

iex>:ok = Jetstream.API.KV.put_value(:gnat, "my_bucket", "my_key", "my_value")