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>
impl<S, F> MemcachedClient<S, F>
Sourcepub fn new(
config: MemcachedClientConfig,
handle: Handle,
selector: S,
factory: F,
) -> Self
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.
Sourcepub async fn raw_open(
&self,
server: &Server,
) -> Result<PooledClient<Server, Memcached>, MtopError>
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.
Sourcepub async fn raw_close(&self, connection: PooledClient<Server, Memcached>)
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.
Sourcepub async fn stats(&self) -> Result<ServersResponse<Stats>, MtopError>
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.
Sourcepub async fn slabs(&self) -> Result<ServersResponse<Slabs>, MtopError>
pub async fn slabs(&self) -> Result<ServersResponse<Slabs>, MtopError>
Get a Slabs
object with information about each set of Slab
s 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.
Sourcepub async fn items(&self) -> Result<ServersResponse<SlabItems>, MtopError>
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.
Sourcepub async fn metas(&self) -> Result<ServersResponse<Vec<Meta>>, MtopError>
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.
Sourcepub async fn ping(&self) -> Result<ServersResponse<()>, MtopError>
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.
Sourcepub async fn flush_all(
&self,
wait: Option<Duration>,
) -> Result<ServersResponse<()>, MtopError>
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.
Sourcepub async fn get<I, K>(&self, keys: I) -> Result<ValuesResponse, MtopError>
pub async fn get<I, K>(&self, keys: I) -> Result<ValuesResponse, MtopError>
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.
Sourcepub async fn incr<K>(&self, key: K, delta: u64) -> Result<u64, MtopError>
pub async fn incr<K>(&self, key: K, delta: u64) -> Result<u64, MtopError>
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.
Sourcepub async fn decr<K>(&self, key: K, delta: u64) -> Result<u64, MtopError>
pub async fn decr<K>(&self, key: K, delta: u64) -> Result<u64, MtopError>
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.
Sourcepub async fn set<K, V>(
&self,
key: K,
flags: u64,
ttl: u32,
data: V,
) -> Result<(), MtopError>
pub async fn set<K, V>( &self, key: K, flags: u64, ttl: u32, data: V, ) -> Result<(), MtopError>
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.
Sourcepub async fn add<K, V>(
&self,
key: K,
flags: u64,
ttl: u32,
data: V,
) -> Result<(), MtopError>
pub async fn add<K, V>( &self, key: K, flags: u64, ttl: u32, data: V, ) -> Result<(), MtopError>
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.
Sourcepub async fn replace<K, V>(
&self,
key: K,
flags: u64,
ttl: u32,
data: V,
) -> Result<(), MtopError>
pub async fn replace<K, V>( &self, key: K, flags: u64, ttl: u32, data: V, ) -> Result<(), MtopError>
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.
Sourcepub async fn touch<K>(&self, key: K, ttl: u32) -> Result<(), MtopError>
pub async fn touch<K>(&self, key: K, ttl: u32) -> Result<(), MtopError>
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.
Sourcepub async fn delete<K>(&self, key: K) -> Result<(), MtopError>
pub async fn delete<K>(&self, key: K) -> Result<(), MtopError>
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.