Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

A client for interacting with a skiff cluster.

Client maintains a single gRPC connection to one cluster node. All write requests are automatically forwarded to the current leader by the node, so the client does not need to track leadership itself.

§Example

use skiff_rs::Client;

let mut client = Client::new(vec!["127.0.0.1".parse()?]);
client.connect().await?;

client.insert("key", "value").await?;
let val: Option<String> = client.get("key").await?;

Implementations§

Source§

impl Client

Source

pub fn new(cluster: Vec<Ipv4Addr>) -> Self

Create a new client that will try each address in cluster in order when connecting.

Source

pub fn with_port(self, port: u16) -> Self

Override the port used to connect to cluster nodes. Defaults to 9400.

Source

pub async fn connect(&mut self) -> Result<(), Error>

Establish a gRPC connection to the first reachable node in the cluster.

This is called automatically by the other methods, but can be called explicitly to verify connectivity before performing operations.

§Errors

Returns Error::ClientConnectFailed if no node in the cluster list can be reached.

Source

pub async fn get<T: DeserializeOwned>( &mut self, key: &str, ) -> Result<Option<T>, Error>

Retrieve the value stored at key, deserializing it as T.

Returns Ok(None) if the key does not exist.

§Errors

Returns an error if the RPC fails or the stored bytes cannot be deserialized into T.

Source

pub async fn insert<T: Serialize>( &mut self, key: &str, value: T, ) -> Result<(), Error>

Insert or overwrite key with value.

The call blocks until the entry has been committed to a majority of cluster nodes.

§Errors

Returns an error if serialization fails, the RPC fails, or the cluster does not commit the entry within the timeout.

Source

pub async fn remove(&mut self, key: &str) -> Result<(), Error>

Remove key from the store.

The call blocks until the deletion has been committed to a majority of cluster nodes. Returns Ok(()) even if the key did not exist.

§Errors

Returns an error if the RPC fails or the cluster does not commit the deletion within the timeout.

Source

pub async fn get_prefixes(&mut self) -> Result<Vec<String>, Error>

Return all key prefixes (namespace segments) currently in the store.

Keys are organised hierarchically using / as a separator. This method returns the distinct prefix segments, e.g. ["users", "posts"] for a store containing "users/alice" and "posts/hello".

§Errors

Returns an error if the RPC fails.

Source

pub async fn list_keys(&mut self, prefix: &str) -> Result<Vec<String>, Error>

Return all keys whose path starts with prefix.

Pass an empty string or "/" to list all keys at the root level.

§Errors

Returns an error if the RPC fails.

Source

pub async fn remove_node( &mut self, id: Uuid, address: Ipv4Addr, ) -> Result<(), Error>

Remove a node from the cluster configuration.

id and address must match an existing member. The removal is propagated through the Raft log so all surviving nodes eventually drop the node from their cluster view.

§Errors

Returns an error if the RPC fails or the node is not found.

Source

pub async fn watch(&mut self, prefix: &str) -> Result<Subscriber, Error>

Subscribe to changes under prefix.

Returns a Subscriber that yields a (key, value) pair each time an entry whose path starts with prefix is inserted. The stream remains open until the connection is dropped or the server closes it.

§Errors

Returns an error if the RPC fails to establish the stream.

Trait Implementations§

Source§

impl Debug for Client

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnsafeUnpin for Client

§

impl !UnwindSafe for Client

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> 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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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