pub struct Client { /* private fields */ }Expand description
Main entry point for interacting with the d-engine cluster.
Derefs to GrpcClient, which implements ClientApi for all KV operations.
Created through ClientBuilder.
Implementations§
Source§impl Client
impl Client
Sourcepub fn builder(endpoints: Vec<String>) -> ClientBuilder
pub fn builder(endpoints: Vec<String>) -> ClientBuilder
Sourcepub async fn refresh(
&self,
new_endpoints: Option<Vec<String>>,
) -> Result<(), ClientApiError>
pub async fn refresh( &self, new_endpoints: Option<Vec<String>>, ) -> Result<(), ClientApiError>
Rediscover the cluster and rebuild the connection pool.
Blocks until a leader whose noop entry is committed by majority is found,
or ClientConfig::cluster_ready_timeout elapses.
What this does:
- Probes all endpoints in round-robin until one reports a ready leader
(
current_leader_idisSomeand present in the member list) - Atomically replaces the cached leader/follower connections
- After
Ok(()),get_leader_id()returns the new leader and all write/read operations are routed to the correct node
What this does NOT do:
- Does not guarantee that the caller’s in-flight requests succeeded;
requests sent before
refresh()may have failed and need to be retried - Does not implement application-level retry — the caller is responsible for re-issuing any operations that failed during the failover window
- Does not update endpoints permanently; pass
new_endpointsto change the bootstrap list for this and future refreshes
Typical usage after leader failover:
client.refresh(None).await?; // blocks until new leader ready
client.put(key, value).await?; // now safe to retry operationsMethods from Deref<Target = GrpcClient>§
pub async fn get_linearizable( &self, key: impl AsRef<[u8]>, ) -> Result<Option<ClientResult>, ClientApiError>
pub async fn get_lease( &self, key: impl AsRef<[u8]>, ) -> Result<Option<ClientResult>, ClientApiError>
pub async fn get_eventual( &self, key: impl AsRef<[u8]>, ) -> Result<Option<ClientResult>, ClientApiError>
Sourcepub async fn get_with_policy(
&self,
key: impl AsRef<[u8]>,
consistency_policy: Option<ReadConsistencyPolicy>,
) -> Result<Option<ClientResult>, ClientApiError>
pub async fn get_with_policy( &self, key: impl AsRef<[u8]>, consistency_policy: Option<ReadConsistencyPolicy>, ) -> Result<Option<ClientResult>, ClientApiError>
Retrieves a single key’s value with explicit consistency policy
Allows client to override server’s default consistency policy for this specific request. If server’s allow_client_override is false, the override will be ignored.
§Parameters
key- The key to retrieve, accepts any type implementingAsRef<[u8]>policy- Explicit consistency policy for this request
Sourcepub async fn get_multi_with_policy(
&self,
keys: impl IntoIterator<Item = impl AsRef<[u8]>>,
consistency_policy: Option<ReadConsistencyPolicy>,
) -> Result<Vec<Option<ClientResult>>, ClientApiError>
pub async fn get_multi_with_policy( &self, keys: impl IntoIterator<Item = impl AsRef<[u8]>>, consistency_policy: Option<ReadConsistencyPolicy>, ) -> Result<Vec<Option<ClientResult>>, ClientApiError>
Fetches multiple keys with explicit consistency policy override
Allows client to override server’s default consistency policy for this batch request. If server’s allow_client_override is false, the override will be ignored.
Sourcepub async fn watch(
&self,
key: impl AsRef<[u8]>,
) -> Result<Streaming<WatchResponse>, ClientApiError>
pub async fn watch( &self, key: impl AsRef<[u8]>, ) -> Result<Streaming<WatchResponse>, ClientApiError>
Watch for changes to a specific key
Returns a stream of watch events when the key’s value changes. The stream will continue until explicitly closed or a connection error occurs.
§Arguments
key- The key to watch
§Returns
A streaming response that yields WatchResponse events
§Errors
Returns error if unable to establish watch connection
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request