class
NATS::KV::Client
- NATS::KV::Client
- Reference
- Object
Defined in:
kv.crConstructors
Instance Method Summary
-
#create(bucket : String, key : String, value : String | Bytes) : Int64 | Nil
Create a key in the given
bucketwith the specifiedvalue. -
#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, allow_msg_ttl : Bool | Nil = nil) : Bucket
Create a
NATS::KV::Bucketto store key/value mappings in with the specifiedname. - #delete(bucket : String, key : String)
- #delete(bucket : Bucket)
- #delete_bucket(bucket : String)
- #each_key(bucket : String, pattern : String = ">", &) : Nil
-
#get(bucket : String, key : String, *, revision : Int | Nil = nil, ignore_deletes : Bool = false) : Entry | Nil
Get the
KV::Entryfor the givenkeyinbucket, ornilif the key does not exist. -
#get_bucket(name : String) : Bucket | Nil
Get the
Bucketwith the given name, ornilif that bucket does not exist. -
#history(bucket : String, key : String) : Array(Entry)
Get all of the currently retained history for the given
keyin the givenbucketname. -
#keys(bucket : String, pattern : String = ">") : Set(String)
Get all of the keys matching
patternfor the givenbucketname. - #list_buckets(pattern : String)
- #purge(bucket : String, key : String)
-
#put(bucket : String, key : String, value : String | Bytes, ttl : Time::Span | Nil = nil) : Int64
Assign
valuetokeyinbucket, returning an acknowledgement or error if the key could not be set. -
#set(bucket : String, key : String, value : Data, ttl : Time::Span | Nil = nil)
Assign
valuetokeyinbucketwithout waiting for acknowledgement from the NATS server. -
#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.
- #watch(bucket : String, key : String, *, ignore_deletes = false, include_history = false)
Constructor Detail
Instance Method Detail
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
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:fileor:memorymax_value_size: the largest number of bytes a key/value entry can hold#history: how many revisions of a key to retainttl: how long until a value or revision expiresmax_bytes: maximum size of this bucket on disk or in memoryreplicas: how many NATS nodes to store this bucket's data on
Get the KV::Entry for the given key in bucket, or nil if the key
does not exist.
Get the Bucket with the given name, or nil if that bucket does not exist.
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")
Get all of the keys matching pattern for the given bucket name.
Assign value to key in bucket, returning an acknowledgement or
error if the key could not be set. The key will expire after ttl if
it is provided.
Assign value to key in bucket without waiting for acknowledgement
from the NATS server. The key will expire after ttl if it is provided.
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