pub struct Client<C: Connection, P: Compressor> { /* private fields */ }
Expand description
A client manages connections to every node in a memcached cluster using consistent hashing to decide which connection to use based on the key.
Implementations§
Source§impl<C: Connection, P: Compressor> Client<C, P>
impl<C: Connection, P: Compressor> Client<C, P>
Sourcepub async fn new(config: ClientConfig<C, P>) -> Result<Self, Error>
pub async fn new(config: ClientConfig<C, P>) -> Result<Self, Error>
Create a new client using the client config provided.
Sourcepub async fn get<K: AsRef<[u8]>, V: DeserializeOwned>(
&mut self,
key: K,
) -> Result<Option<V>, Error>
pub async fn get<K: AsRef<[u8]>, V: DeserializeOwned>( &mut self, key: K, ) -> Result<Option<V>, Error>
Get a single value from memcached. Returns None when the key is not found (i.e., a miss).
Sourcepub async fn get_multi<'a, K: AsRef<[u8]>, V: DeserializeOwned>(
&mut self,
keys: &[K],
) -> BulkGetResponse<V>
pub async fn get_multi<'a, K: AsRef<[u8]>, V: DeserializeOwned>( &mut self, keys: &[K], ) -> BulkGetResponse<V>
Get multiple values from memcached at once. On success, it returns a tuple of (ok, err) responses. The error responses can be treated as misses, but should be logged for visibility. Lots of errors could be indicative of a serious problem.
Sourcepub async fn set<K: AsRef<[u8]>, V: Serialize + ?Sized>(
&mut self,
key: K,
data: &V,
expire: u32,
) -> Result<(), Error>
pub async fn set<K: AsRef<[u8]>, V: Serialize + ?Sized>( &mut self, key: K, data: &V, expire: u32, ) -> Result<(), Error>
Set a single key/value pair in memcached to expire at the desired
time. A value of 0 means “never expire”, but the value could still be
evicted by the LRU cache. Important: if expire
is set to more than 30
days in the future, then memcached will treat it as a unix timestamp
instead of a duration.
Sourcepub async fn set_multi<'a, V: Serialize, K: AsRef<[u8]> + Eq + Hash>(
&mut self,
data: HashMap<K, V>,
expire: u32,
) -> BulkUpdateResponse
pub async fn set_multi<'a, V: Serialize, K: AsRef<[u8]> + Eq + Hash>( &mut self, data: HashMap<K, V>, expire: u32, ) -> BulkUpdateResponse
Set multiple key/value pairs in memcached to expire at the desired
time. A value of 0 means “never expire”, but the value could still be
evicted by the LRU cache. Important: if expire
is set to more than 30
days in the future, then memcached will treat it as a unix timestamp
instead of a duration.
Sourcepub async fn delete<K: AsRef<[u8]>>(&mut self, key: K) -> Result<(), Error>
pub async fn delete<K: AsRef<[u8]>>(&mut self, key: K) -> Result<(), Error>
Delete a key from memcached. Does nothing if the key is not set.
Sourcepub async fn delete_multi<K: AsRef<[u8]>>(
&mut self,
keys: &[K],
) -> BulkUpdateResponse
pub async fn delete_multi<K: AsRef<[u8]>>( &mut self, keys: &[K], ) -> BulkUpdateResponse
Delete multiple keys from memcached. Does nothing when a key is unset.