class NATS::KV::Client

Defined in:

kv.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(nats : NATS::Client) #

[View source]

Instance Method Detail

def create(bucket : String, key : String, value : String | Bytes) : Int64 | Nil #

Create a key in the given bucket with the specified value. On success, #create returns the new revision number for the key. If the key already exists, the value will not be set and nil is returned.

if revision = kv.create("my-bucket", "my-key", "my-value")
  # created
else
  # key already existed and value was not set
end

[View source]
def create_bucket(name : String, description : String = "", *, max_value_size : Int32 | Nil = nil, history : Int = 1, ttl : Time::Span | Nil = nil, max_bytes : Int64 | Nil = nil, storage : JetStream::StreamConfig::Storage = :file, replicas : Int32 = 1, discard_new_per_key : Bool = false, placement : JetStream::StreamConfig::Placement | Nil = nil) : Bucket #

Create a NATS::KV::Bucket to store key/value mappings in with the specified name. Options are:

  • storage: where to store the data for this bucket, either :file or :memory
  • max_value_size: the largest number of bytes a key/value entry can hold
  • #history: how many revisions of a key to retain
  • ttl: how long until a value or revision expires
  • max_bytes: maximum size of this bucket on disk or in memory
  • replicas: how many NATS nodes to store this bucket's data on

[View source]
def delete(bucket : String, key : String) #

[View source]
def delete(bucket : Bucket) #

[View source]
def delete_bucket(bucket : String) #

[View source]
def each_key(bucket : String, pattern : String = ">", &) : Nil #

[View source]
def get(bucket : String, key : String, *, revision : Int | Nil = nil, ignore_deletes : Bool = false) : Entry | Nil #

Get the KV::Entry for the given key in bucket, or nil if the key does not exist.


[View source]
def get_bucket(name : String) : Bucket | Nil #

Get the Bucket with the given name, or nil if that bucket does not exist.


[View source]
def history(bucket : String, key : String) : Array(Entry) #

Get all of the currently retained history for the given key in the given bucket name. Note that some of the history could have expired due to Bucket#ttl or Bucket#history.

kv.set "config", "name", "1"
kv.history("config", "name")

[View source]
def keys(bucket : String, pattern : String = ">") : Set(String) #

Get all of the keys matching pattern for the given bucket name.


[View source]
def purge(bucket : String, key : String) #

[View source]
def put(bucket : String, key : String, value : String | Bytes) : Int64 #

Assign value to key in bucket, returning an acknowledgement or error if the key could not be set.


[View source]
def set(bucket : String, key : String, value : Data) #

Assign value to key in bucket without waiting for acknowledgement from the NATS server.


[View source]
def update(bucket : String, key : String, value : String | Bytes, revision : Int) : Int64 | Nil #

Update a bucket's key with the specified value only if the current value is the specified revision. If this revision is the latest, the update is not performed and this method returns nil.

if revision = kv.update(bucket, key, value, revision)
  # updated
else
  # outdated revision
end

[View source]
def watch(bucket : String, key : String, *, ignore_deletes = false, include_history = false) #

[View source]