Skip to main content

ReadWriteClient

Struct ReadWriteClient 

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

Read/write-split cluster client. Owns one RespClient to the primary node + one per replica node. Round-robins reads across the replica fleet (fallback to primary on empty fleet or consistent = true).

Implementations§

Source§

impl ReadWriteClient

Source

pub fn connect(primary: (&str, u16), replicas: &[(&str, u16)]) -> Result<Self>

Open one connection to the primary and one per replica.

primary is the address of the kevy node running with [replication] role = "primary" (or standalone — both behave the same from the client’s perspective). replicas lists the addresses of kevy nodes running with [replication] role = "replica"; v1.18 assumes they all share the keyspace of the primary (operator-enforced — kevy has no automatic discovery in v1.18).

Source

pub fn replica_count(&self) -> usize

Number of replica connections.

Source

pub fn request_write(&mut self, args: &[Vec<u8>]) -> Result<Reply>

Route a write command (or any command that must hit the primary) to the primary connection. If the server replies -MISDIRECTED writer is <host:port> (Phase 3 / v1.21 scoped multi-writer), the client transparently opens a connection to the named writer (caching it), caches the key→writer mapping for follow-up writes on the same key, and retries once. A second -MISDIRECTED from the retry surfaces as an error.

Source

pub fn request_read( &mut self, args: &[Vec<u8>], consistent: bool, ) -> Result<Reply>

Route a read command to a replica (round-robin); fallback to the primary when no replica is configured or when consistent is true.

Source

pub fn request(&mut self, args: &[Vec<u8>]) -> Result<Reply>

Auto-routed command. Classifies args[0] via is_write_verb and dispatches to either Self::request_write or Self::request_read (consistent = false). Convenience for callers that don’t want to make the read/write decision explicit.

Auto Trait Implementations§

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, 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, 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.