nightly_async_nats::jetstream::kv

Struct Store

Source
pub struct Store {
    pub name: String,
    pub stream_name: String,
    pub prefix: String,
    pub put_prefix: Option<String>,
    pub use_jetstream_prefix: bool,
    pub stream: Stream,
}
Expand description

A struct used as a handle for the bucket.

Fields§

§name: String§stream_name: String§prefix: String§put_prefix: Option<String>§use_jetstream_prefix: bool§stream: Stream

Implementations§

Source§

impl Store

Source

pub async fn status(&self) -> Result<Status, Error>

Queries the server and returns status from the server.

§Examples
let client = async_nats::connect("demo.nats.io:4222").await?;
let jetstream = async_nats::jetstream::new(client);
let kv = jetstream.create_key_value(async_nats::jetstream::kv::Config {
    bucket: "kv".to_string(),
    history: 10,
    ..Default::default()
}).await?;
let status = kv.status().await?;
println!("status: {:?}", status);
Source

pub async fn put<T: AsRef<str>>( &self, key: T, value: Bytes, ) -> Result<u64, Error>

Puts new key value pair into the bucket. If key didn’t exist, it is created. If it did exist, a new value with a new version is added.

§Examples
let client = async_nats::connect("demo.nats.io:4222").await?;
let jetstream = async_nats::jetstream::new(client);
let kv = jetstream.create_key_value(async_nats::jetstream::kv::Config {
    bucket: "kv".to_string(),
    history: 10,
    ..Default::default()
}).await?;
let status = kv.put("key", "value".into()).await?;
Source

pub async fn entry<T: Into<String>>( &self, key: T, ) -> Result<Option<Entry>, Error>

Retrieves the last Entry for a given key from a bucket.

§Examples
let client = async_nats::connect("demo.nats.io:4222").await?;
let jetstream = async_nats::jetstream::new(client);
let kv = jetstream.create_key_value(async_nats::jetstream::kv::Config {
    bucket: "kv".to_string(),
    history: 10,
    ..Default::default()
}).await?;
let status = kv.put("key", "value".into()).await?;
let entry = kv.entry("key").await?;
println!("entry: {:?}", entry);
Source

pub async fn watch<T: AsRef<str>>(&self, key: T) -> Result<Watch<'_>, Error>

Creates a futures::Stream over Entries a given key in the bucket, which yields values whenever there are changes for that key.

§Examples
use futures::StreamExt;
let client = async_nats::connect("demo.nats.io:4222").await?;
let jetstream = async_nats::jetstream::new(client);
let kv = jetstream.create_key_value(async_nats::jetstream::kv::Config {
    bucket: "kv".to_string(),
    history: 10,
    ..Default::default()
}).await?;
let mut entries = kv.watch("kv").await?;
while let Some(entry) = entries.next().await {
    println!("entry: {:?}", entry);
}
Source

pub async fn watch_all(&self) -> Result<Watch<'_>, Error>

Creates a futures::Stream over Entries for all keys, which yields values whenever there are changes in the bucket.

§Examples
use futures::StreamExt;
let client = async_nats::connect("demo.nats.io:4222").await?;
let jetstream = async_nats::jetstream::new(client);
let kv = jetstream.create_key_value(async_nats::jetstream::kv::Config {
    bucket: "kv".to_string(),
    history: 10,
    ..Default::default()
}).await?;
let mut entries = kv.watch_all().await?;
while let Some(entry) = entries.next().await {
    println!("entry: {:?}", entry);
}
Source

pub async fn get<T: Into<String>>( &self, key: T, ) -> Result<Option<Vec<u8>>, Error>

Source

pub async fn update<T: AsRef<str>>( &self, key: T, value: Bytes, revision: u64, ) -> Result<u64, Error>

Updates a value for a given key, but only if passed revision is the last revision in the bucket.

§Examples
use futures::StreamExt;
let client = async_nats::connect("demo.nats.io:4222").await?;
let jetstream = async_nats::jetstream::new(client);
let kv = jetstream.create_key_value(async_nats::jetstream::kv::Config {
    bucket: "kv".to_string(),
    history: 10,
    ..Default::default()
}).await?;
let revision = kv.put("key", "value".into()).await?;
kv.update("key", "updated".into(), revision).await?;
Source

pub async fn delete<T: AsRef<str>>(&self, key: T) -> Result<(), Error>

Deletes a given key. This is a non-destructive operation, which sets a DELETE marker.

§Examples
use futures::StreamExt;
let client = async_nats::connect("demo.nats.io:4222").await?;
let jetstream = async_nats::jetstream::new(client);
let kv = jetstream.create_key_value(async_nats::jetstream::kv::Config {
    bucket: "kv".to_string(),
    history: 10,
    ..Default::default()
}).await?;
kv.put("key", "value".into()).await?;
kv.delete("key").await?;
Source

pub async fn purge<T: AsRef<str>>(&self, key: T) -> Result<(), Error>

Purges all the revisions of a entry destructively, leaving behind a single purge entry in-place.

§Examples
use futures::StreamExt;
let client = async_nats::connect("demo.nats.io:4222").await?;
let jetstream = async_nats::jetstream::new(client);
let kv = jetstream.create_key_value(async_nats::jetstream::kv::Config {
    bucket: "kv".to_string(),
    history: 10,
    ..Default::default()
}).await?;
kv.put("key", "value".into()).await?;
kv.put("key", "another".into()).await?;
kv.purge("key").await?;
Source

pub async fn history<T: AsRef<str>>(&self, key: T) -> Result<History<'_>, Error>

Returns a futures::Stream that allows iterating over all Operations that happen for given key.

§Examples
use futures::StreamExt;
let client = async_nats::connect("demo.nats.io:4222").await?;
let jetstream = async_nats::jetstream::new(client);
let kv = jetstream.create_key_value(async_nats::jetstream::kv::Config {
    bucket: "kv".to_string(),
    history: 10,
    ..Default::default()
}).await?;
let mut entries = kv.history("kv").await?;
while let Some(entry) = entries.next().await {
    println!("entry: {:?}", entry);
}
Source

pub async fn keys(&self) -> Result<IntoIter<String>, Error>

Returns an iterator of String over all keys in the bucket.

§Examples
use futures::StreamExt;
let client = async_nats::connect("demo.nats.io:4222").await?;
let jetstream = async_nats::jetstream::new(client);
let kv = jetstream.create_key_value(async_nats::jetstream::kv::Config {
    bucket: "kv".to_string(),
    history: 10,
    ..Default::default()
}).await?;
let mut keys = kv.keys().await?;
for key in keys {
    println!("key: {:?}", key);
}

Trait Implementations§

Source§

impl Clone for Store

Source§

fn clone(&self) -> Store

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Store

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Store

§

impl !RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl !UnwindSafe for Store

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T