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
impl ReadWriteClient
Sourcepub fn connect(primary: (&str, u16), replicas: &[(&str, u16)]) -> Result<Self>
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).
Sourcepub fn replica_count(&self) -> usize
pub fn replica_count(&self) -> usize
Number of replica connections.
Sourcepub fn request_write(&mut self, args: &[Vec<u8>]) -> Result<Reply>
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.
Sourcepub fn request_read(
&mut self,
args: &[Vec<u8>],
consistent: bool,
) -> Result<Reply>
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.
Sourcepub fn request(&mut self, args: &[Vec<u8>]) -> Result<Reply>
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.