pub struct ShardedClient { /* private fields */ }Expand description
A ketama-sharded Memcache client.
Commands are routed to independent Memcache instances using consistent hashing. Each server has a pool of connections with round-robin dispatch and lazy reconnection.
Implementations§
Source§impl ShardedClient
impl ShardedClient
Sourcepub fn new(config: ShardedConfig) -> Self
pub fn new(config: ShardedConfig) -> Self
Create a new sharded client. All connections start disconnected.
Sourcepub async fn connect_all(&mut self) -> Result<(), Error>
pub async fn connect_all(&mut self) -> Result<(), Error>
Eagerly connect all connections on all shards.
Sourcepub fn shard_count(&self) -> usize
pub fn shard_count(&self) -> usize
Number of shards (servers).
Sourcepub async fn shard_client(&mut self, index: usize) -> Result<Client, Error>
pub async fn shard_client(&mut self, index: usize) -> Result<Client, Error>
Get a Client for a specific shard by index (for node-level commands).
Sourcepub async fn get(
&mut self,
key: impl AsRef<[u8]>,
) -> Result<Option<Value>, Error>
pub async fn get( &mut self, key: impl AsRef<[u8]>, ) -> Result<Option<Value>, Error>
Get the value of a key. Returns None on cache miss.
Sourcepub async fn gets(&mut self, keys: &[&[u8]]) -> Result<Vec<GetValue>, Error>
pub async fn gets(&mut self, keys: &[&[u8]]) -> Result<Vec<GetValue>, Error>
Get values for multiple keys. All keys must route to the same shard. Returns only hits, each with its key and CAS token.
Sourcepub async fn set(
&mut self,
key: impl AsRef<[u8]>,
value: impl AsRef<[u8]>,
) -> Result<(), Error>
pub async fn set( &mut self, key: impl AsRef<[u8]>, value: impl AsRef<[u8]>, ) -> Result<(), Error>
Set a key-value pair with default flags (0) and no expiration.
Sourcepub async fn set_with_options(
&mut self,
key: impl AsRef<[u8]>,
value: impl AsRef<[u8]>,
flags: u32,
exptime: u32,
) -> Result<(), Error>
pub async fn set_with_options( &mut self, key: impl AsRef<[u8]>, value: impl AsRef<[u8]>, flags: u32, exptime: u32, ) -> Result<(), Error>
Set a key-value pair with custom flags and expiration time.
Sourcepub async fn add(
&mut self,
key: impl AsRef<[u8]>,
value: impl AsRef<[u8]>,
) -> Result<bool, Error>
pub async fn add( &mut self, key: impl AsRef<[u8]>, value: impl AsRef<[u8]>, ) -> Result<bool, Error>
Store a key only if it does not already exist (ADD command).
Returns true if stored, false if the key already exists.
Sourcepub async fn replace(
&mut self,
key: impl AsRef<[u8]>,
value: impl AsRef<[u8]>,
) -> Result<bool, Error>
pub async fn replace( &mut self, key: impl AsRef<[u8]>, value: impl AsRef<[u8]>, ) -> Result<bool, Error>
Store a key only if it already exists (REPLACE command).
Returns true if stored, false if the key does not exist.
Sourcepub async fn incr(
&mut self,
key: impl AsRef<[u8]>,
delta: u64,
) -> Result<Option<u64>, Error>
pub async fn incr( &mut self, key: impl AsRef<[u8]>, delta: u64, ) -> Result<Option<u64>, Error>
Increment a numeric value by delta. Returns the new value after incrementing.
Returns None if the key does not exist.
Sourcepub async fn decr(
&mut self,
key: impl AsRef<[u8]>,
delta: u64,
) -> Result<Option<u64>, Error>
pub async fn decr( &mut self, key: impl AsRef<[u8]>, delta: u64, ) -> Result<Option<u64>, Error>
Decrement a numeric value by delta. Returns the new value after decrementing.
Returns None if the key does not exist.
Sourcepub async fn append(
&mut self,
key: impl AsRef<[u8]>,
value: impl AsRef<[u8]>,
) -> Result<bool, Error>
pub async fn append( &mut self, key: impl AsRef<[u8]>, value: impl AsRef<[u8]>, ) -> Result<bool, Error>
Append data to an existing item’s value.
Returns true if stored, false if the key does not exist.
Sourcepub async fn prepend(
&mut self,
key: impl AsRef<[u8]>,
value: impl AsRef<[u8]>,
) -> Result<bool, Error>
pub async fn prepend( &mut self, key: impl AsRef<[u8]>, value: impl AsRef<[u8]>, ) -> Result<bool, Error>
Prepend data to an existing item’s value.
Returns true if stored, false if the key does not exist.
Sourcepub async fn cas(
&mut self,
key: impl AsRef<[u8]>,
value: impl AsRef<[u8]>,
cas_unique: u64,
) -> Result<bool, Error>
pub async fn cas( &mut self, key: impl AsRef<[u8]>, value: impl AsRef<[u8]>, cas_unique: u64, ) -> Result<bool, Error>
Compare-and-swap: store the value only if the CAS token matches.
Returns Ok(true) if stored, Ok(false) if the CAS token didn’t match (EXISTS),
or Err if the key was not found or another error occurred.