Struct async_memcached::Client
source · pub struct Client { /* private fields */ }
Expand description
High-level memcached client.
Client
is mapped one-to-one with a given connection to a memcached server, and provides a
high-level API for executing commands on that connection.
Implementations§
source§impl Client
impl Client
sourcepub async fn new<S: AsRef<str>>(dsn: S) -> Result<Client, Error>
pub async fn new<S: AsRef<str>>(dsn: S) -> Result<Client, Error>
Creates a new Client
based on the given data source string.
Supports UNIX domain sockets and TCP connections.
For TCP: the DSN should be in the format of tcp://<IP>:<port>
or <IP>:<port>
.
For UNIX: the DSN should be in the format of unix://<path>
.
sourcepub async fn get<K: AsRef<[u8]>>(
&mut self,
key: K,
) -> Result<Option<Value>, Error>
pub async fn get<K: AsRef<[u8]>>( &mut self, key: K, ) -> Result<Option<Value>, Error>
Gets the given key.
If the key is found, Some(Value)
is returned, describing the metadata and data of the key.
Otherwise, Error
is returned.
sourcepub async fn set<K, V>(
&mut self,
key: K,
value: V,
ttl: Option<i64>,
flags: Option<u32>,
) -> Result<(), Error>
pub async fn set<K, V>( &mut self, key: K, value: V, ttl: Option<i64>, flags: Option<u32>, ) -> Result<(), Error>
Sets the given key.
If ttl
or flags
are not specified, they will default to 0. If the value is set
successfully, ()
is returned, otherwise Error
is returned.
sourcepub async fn add<K, V>(
&mut self,
key: K,
value: V,
ttl: Option<i64>,
flags: Option<u32>,
) -> Result<(), Error>
pub async fn add<K, V>( &mut self, key: K, value: V, ttl: Option<i64>, flags: Option<u32>, ) -> Result<(), Error>
Add a key. If the value exists, Err(Protocol(NotStored)) is returned.
sourcepub async fn delete_no_reply<K>(&mut self, key: K) -> Result<(), Error>
pub async fn delete_no_reply<K>(&mut self, key: K) -> Result<(), Error>
Delete a key but don’t wait for a reply.
sourcepub async fn delete<K>(&mut self, key: K) -> Result<(), Error>
pub async fn delete<K>(&mut self, key: K) -> Result<(), Error>
Delete a key and wait for a reply
sourcepub async fn increment<K>(&mut self, key: K, amount: u64) -> Result<u64, Error>
pub async fn increment<K>(&mut self, key: K, amount: u64) -> Result<u64, Error>
Increments the given key by the specified amount. Can overflow from the max value of u64 (18446744073709551615) -> 0. Returns the new value of the key if key exists, otherwise returns KeyNotFound error.
sourcepub async fn increment_no_reply<K>(
&mut self,
key: K,
amount: u64,
) -> Result<(), Error>
pub async fn increment_no_reply<K>( &mut self, key: K, amount: u64, ) -> Result<(), Error>
Increments the given key by the specified amount with no reply from the server. /// Can overflow from the max value of u64 (18446744073709551615) -> 0.
sourcepub async fn decrement<K>(&mut self, key: K, amount: u64) -> Result<u64, Error>
pub async fn decrement<K>(&mut self, key: K, amount: u64) -> Result<u64, Error>
Decrements the given key by the specified amount. Will not decrement the counter below 0.
sourcepub async fn decrement_no_reply<K>(
&mut self,
key: K,
amount: u64,
) -> Result<(), Error>
pub async fn decrement_no_reply<K>( &mut self, key: K, amount: u64, ) -> Result<(), Error>
Decrements the given key by the specified amount with no reply from the server. Will not decrement the counter below 0. Returns the new value of the key if key exists, otherwise returns KeyNotFound error.
sourcepub async fn version(&mut self) -> Result<String, Error>
pub async fn version(&mut self) -> Result<String, Error>
Gets the version of the server.
If the version is retrieved successfully, String
is returned containing the version
component e.g. 1.6.7
, otherwise Error
is returned.
For some setups, such as those using Twemproxy, this will return an error as those intermediate proxies do not support the version command.
sourcepub async fn dump_keys(&mut self) -> Result<MetadumpIter<'_>, Error>
pub async fn dump_keys(&mut self) -> Result<MetadumpIter<'_>, Error>
Dumps all keys from the server.
This operation scans all slab classes from tail to head, in a non-blocking fashion. Thus, not all items will be found as new items could be inserted or deleted while the crawler is still running.
MetadumpIter
must be iterated over to discover whether or not the crawler successfully
started, as this call will only return Error
if the command failed to be written to the
server at all.
Available as of memcached 1.4.31.
sourcepub async fn stats(&mut self) -> Result<HashMap<String, String>, Error>
pub async fn stats(&mut self) -> Result<HashMap<String, String>, Error>
Collects statistics from the server.
The statistics that may be returned are detailed in the protocol specification for memcached, but all values returned by this method are returned as strings and are not further interpreted or validated for conformity.