Struct Client

Source
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>

Source

pub async fn new(config: ClientConfig<C, P>) -> Result<Self, Error>

Create a new client using the client config provided.

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<C: Clone + Connection, P: Clone + Compressor> Clone for Client<C, P>

Source§

fn clone(&self) -> Client<C, P>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: Debug + Connection, P: Debug + Compressor> Debug for Client<C, P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C, P> Freeze for Client<C, P>
where P: Freeze,

§

impl<C, P> RefUnwindSafe for Client<C, P>

§

impl<C, P> Send for Client<C, P>

§

impl<C, P> Sync for Client<C, P>

§

impl<C, P> Unpin for Client<C, P>
where P: Unpin, C: Unpin,

§

impl<C, P> UnwindSafe for Client<C, P>
where P: UnwindSafe, C: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.