Struct MemcachedClient

Source
pub struct MemcachedClient<S = RendezvousSelector, F = TcpClientFactory>
where S: Selector + Send + Sync + 'static, F: ClientFactory<Server, Memcached> + Send + Sync + 'static,
{ /* private fields */ }
Expand description

Memcached client that operates on multiple servers, pooling connections to them, and sharding keys via a Selector implementation.

Implementations§

Source§

impl<S, F> MemcachedClient<S, F>
where S: Selector + Send + Sync + 'static, F: ClientFactory<Server, Memcached> + Send + Sync + 'static,

Source

pub fn new( config: MemcachedClientConfig, handle: Handle, selector: S, factory: F, ) -> Self

Create a new MemcachedClient instance.

handle is used to spawn multiple async tasks to fetch data from servers in parallel. selector is used to determine which server “owns” a particular key. factory is used for establishing new connections, which are pooled, to each server as needed.

Source

pub async fn raw_open( &self, server: &Server, ) -> Result<PooledClient<Server, Memcached>, MtopError>

Get a connection to a particular server from the pool if available, otherwise establish a new connection.

Source

pub async fn raw_close(&self, connection: PooledClient<Server, Memcached>)

Return a connection to a particular server to the pool if fewer than the configured number of idle connections to that server are currently in the pool, otherwise close it immediately.

Source

pub async fn stats(&self) -> Result<ServersResponse<Stats>, MtopError>

Get a Stats object with the current values of the interesting stats for each server.

A future is spawned for each server with results and any errors indexed by server. A pooled connection to each server is used if available, otherwise new connections are established.

Source

pub async fn slabs(&self) -> Result<ServersResponse<Slabs>, MtopError>

Get a Slabs object with information about each set of Slabs maintained by each server. You can think of each Slab as a class of objects that are stored together in memory. Note that Slab IDs may not be contiguous based on the size of items actually stored by the server.

A future is spawned for each server with results and any errors indexed by server. A pooled connection to each server is used if available, otherwise new connections are established.

Source

pub async fn items(&self) -> Result<ServersResponse<SlabItems>, MtopError>

Get a SlabsItems object with information about the SlabItem items stored in each slab class maintained by each server. The ID of each SlabItem corresponds to a Slab maintained by the server. Note that SlabItem IDs may not be contiguous based on the size of items actually stored by the server.

A future is spawned for each server with results and any errors indexed by server. A pooled connection to each server is used if available, otherwise new connections are established.

Source

pub async fn metas(&self) -> Result<ServersResponse<Vec<Meta>>, MtopError>

Get a Meta object for every item in the cache for each server which includes its key and expiration time as a UNIX timestamp. Expiration time will be -1 if the item was set with an infinite TTL.

A future is spawned for each server with results and any errors indexed by server. A pooled connection to each server is used if available, otherwise new connections are established.

Source

pub async fn ping(&self) -> Result<ServersResponse<()>, MtopError>

Send a simple command to verify our connection each known server.

A future is spawned for each server with results and any errors indexed by server. A pooled connection to each server is used if available, otherwise new connections are established.

Source

pub async fn flush_all( &self, wait: Option<Duration>, ) -> Result<ServersResponse<()>, MtopError>

Flush all entries in the cache for each server, optionally after a delay. When a delay is used, each server will flush entries after a delay but the calls will still return immediately.

A future is spawned for each server with results and any errors indexed by server. A pooled connection to each server is used if available, otherwise new connections are established.

Source

pub async fn get<I, K>(&self, keys: I) -> Result<ValuesResponse, MtopError>
where I: IntoIterator<Item = K>, K: Into<String>,

Get a map of the requested keys and their corresponding Value in the cache including the key, flags, and data.

This method uses a selector implementation to determine which server “owns” each of the provided keys. A future is spawned for each server and the results merged together. A pooled connection to each server is used if available, otherwise new connections are established.

Source

pub async fn incr<K>(&self, key: K, delta: u64) -> Result<u64, MtopError>
where K: Into<String>,

Increment the value of a key by the given delta if the value is numeric returning the new value. Returns an error if the value is not set or not numeric.

This method uses a selector implementation to determine which server “owns” the provided key. A pooled connection to the server is used if available, otherwise a new connection is established.

Source

pub async fn decr<K>(&self, key: K, delta: u64) -> Result<u64, MtopError>
where K: Into<String>,

Decrement the value of a key by the given delta if the value is numeric returning the new value with a minimum of 0. Returns an error if the value is not set or not numeric.

This method uses a selector implementation to determine which server “owns” the provided key. A pooled connection to the server is used if available, otherwise a new connection is established.

Source

pub async fn set<K, V>( &self, key: K, flags: u64, ttl: u32, data: V, ) -> Result<(), MtopError>
where K: Into<String>, V: AsRef<[u8]>,

Store the provided item in the cache, regardless of whether it already exists.

This method uses a selector implementation to determine which server “owns” the provided key. A pooled connection to the server is used if available, otherwise a new connection is established.

Source

pub async fn add<K, V>( &self, key: K, flags: u64, ttl: u32, data: V, ) -> Result<(), MtopError>
where K: Into<String>, V: AsRef<[u8]>,

Store the provided item in the cache only if it does not already exist.

This method uses a selector implementation to determine which server “owns” the provided key. A pooled connection to the server is used if available, otherwise a new connection is established.

Source

pub async fn replace<K, V>( &self, key: K, flags: u64, ttl: u32, data: V, ) -> Result<(), MtopError>
where K: Into<String>, V: AsRef<[u8]>,

Store the provided item in the cache only if it already exists.

This method uses a selector implementation to determine which server “owns” the provided key. A pooled connection to the server is used if available, otherwise a new connection is established.

Source

pub async fn touch<K>(&self, key: K, ttl: u32) -> Result<(), MtopError>
where K: Into<String>,

Update the TTL of an item in the cache if it exists, return an error otherwise.

This method uses a selector implementation to determine which server “owns” the provided key. A pooled connection to the server is used if available, otherwise a new connection is established.

Source

pub async fn delete<K>(&self, key: K) -> Result<(), MtopError>
where K: Into<String>,

Delete an item from the cache if it exists, return an error otherwise.

This method uses a selector implementation to determine which server “owns” the provided key. A pooled connection to the server is used if available, otherwise a new connection is established.

Trait Implementations§

Source§

impl<S, F> Debug for MemcachedClient<S, F>
where S: Selector + Send + Sync + 'static + Debug, F: ClientFactory<Server, Memcached> + Send + Sync + 'static + Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S, F> Freeze for MemcachedClient<S, F>
where S: Freeze,

§

impl<S = RendezvousSelector, F = TcpClientFactory> !RefUnwindSafe for MemcachedClient<S, F>

§

impl<S, F> Send for MemcachedClient<S, F>

§

impl<S, F> Sync for MemcachedClient<S, F>

§

impl<S, F> Unpin for MemcachedClient<S, F>
where S: Unpin,

§

impl<S = RendezvousSelector, F = TcpClientFactory> !UnwindSafe for MemcachedClient<S, F>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more