View Source Jetstream.API.KV (jetstream v0.0.1)
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
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
@type 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
@spec 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
Examples
iex>{:ok, info} = Jetstream.API.KV.create_bucket(:gnat, "my_bucket")
@spec create_key( conn :: Gnat.t(), bucket_name :: binary(), key :: binary(), value :: binary() ) :: :ok
Create a Key in a Key/Value Bucket
examples
Examples
iex>:ok = Jetstream.API.KV.create_key(:gnat, "my_bucket", "my_key", "my_value")
Delete a Key/Value bucket
examples
Examples
iex>:ok = Jetstream.API.KV.delete_bucket(:gnat, "my_bucket")
Delete a Key from a K/V Bucket
examples
Examples
iex>:ok = Jetstream.API.KV.delete_key(:gnat, "my_bucket", "my_key")
@spec 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
Examples
iex>"my_value" = Jetstream.API.KV.get_value(:gnat, "my_bucket", "my_key")
Purge a Key from a K/V bucket. This will remove any revision history the key had
examples
Examples
iex>:ok = Jetstream.API.KV.purge_key(:gnat, "my_bucket", "my_key")
@spec 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
Examples
iex>:ok = Jetstream.API.KV.put_value(:gnat, "my_bucket", "my_key", "my_value")