memcache

Struct Client

source
pub struct Client {
    pub hash_function: fn(_: &str) -> u64,
    /* private fields */
}

Fields§

§hash_function: fn(_: &str) -> u64

Implementations§

source§

impl Client

source

pub fn new<C: Connectable>(target: C) -> Result<Self, MemcacheError>

👎Deprecated since 0.10.0: please use connect instead
source

pub fn builder() -> ClientBuilder

source

pub fn with_pool_size<C: Connectable>( target: C, size: u32, ) -> Result<Self, MemcacheError>

source

pub fn with_pool(pool: Pool<ConnectionManager>) -> Result<Self, MemcacheError>

source

pub fn with_pools( pools: Vec<Pool<ConnectionManager>>, ) -> Result<Self, MemcacheError>

source

pub fn connect<C: Connectable>(target: C) -> Result<Self, MemcacheError>

source

pub fn set_read_timeout( &self, timeout: Option<Duration>, ) -> Result<(), MemcacheError>

Set the socket read timeout for TCP connections.

Example:

let client = memcache::Client::connect("memcache://localhost:12345").unwrap();
client.set_read_timeout(Some(::std::time::Duration::from_secs(3))).unwrap();
source

pub fn set_write_timeout( &self, timeout: Option<Duration>, ) -> Result<(), MemcacheError>

Set the socket write timeout for TCP connections.

Example:

let client = memcache::Client::connect("memcache://localhost:12345?protocol=ascii").unwrap();
client.set_write_timeout(Some(::std::time::Duration::from_secs(3))).unwrap();
source

pub fn version(&self) -> Result<Vec<(String, String)>, MemcacheError>

Get the memcached server version.

Example:

let client = memcache::Client::connect("memcache://localhost:12345").unwrap();
client.version().unwrap();
source

pub fn flush(&self) -> Result<(), MemcacheError>

Flush all cache on memcached server immediately.

Example:

let client = memcache::Client::connect("memcache://localhost:12345").unwrap();
client.flush().unwrap();
source

pub fn flush_with_delay(&self, delay: u32) -> Result<(), MemcacheError>

Flush all cache on memcached server with a delay seconds.

Example:

let client = memcache::Client::connect("memcache://localhost:12345").unwrap();
client.flush_with_delay(10).unwrap();
source

pub fn get<V: FromMemcacheValueExt>( &self, key: &str, ) -> Result<Option<V>, MemcacheError>

Get a key from memcached server.

Example:

let client = memcache::Client::connect("memcache://localhost:12345").unwrap();
let _: Option<String> = client.get("foo").unwrap();
source

pub fn gets<V: FromMemcacheValueExt>( &self, keys: &[&str], ) -> Result<HashMap<String, V>, MemcacheError>

Get multiple keys from memcached server. Using this function instead of calling get multiple times can reduce network workloads.

Example:

let client = memcache::Client::connect("memcache://localhost:12345").unwrap();
client.set("foo", "42", 0).unwrap();
let result: std::collections::HashMap<String, String> = client.gets(&["foo", "bar", "baz"]).unwrap();
assert_eq!(result.len(), 1);
assert_eq!(result["foo"], "42");
source

pub fn set<V: ToMemcacheValue<Stream>>( &self, key: &str, value: V, expiration: u32, ) -> Result<(), MemcacheError>

Set a key with associate value into memcached server with expiration seconds.

Example:

let client = memcache::Client::connect("memcache://localhost:12345").unwrap();
client.set("foo", "bar", 10).unwrap();
source

pub fn cas<V: ToMemcacheValue<Stream>>( &self, key: &str, value: V, expiration: u32, cas_id: u64, ) -> Result<bool, MemcacheError>

Compare and swap a key with the associate value into memcached server with expiration seconds. cas_id should be obtained from a previous gets call.

Example:

use std::collections::HashMap;
let client = memcache::Client::connect("memcache://localhost:12345").unwrap();
client.set("foo", "bar", 10).unwrap();
let (_, _, cas) = client.get("foo").unwrap().unwrap();
let cas = cas.unwrap();
assert_eq!(true, client.cas("foo", "bar2", 10, cas).unwrap());
source

pub fn add<V: ToMemcacheValue<Stream>>( &self, key: &str, value: V, expiration: u32, ) -> Result<(), MemcacheError>

Add a key with associate value into memcached server with expiration seconds.

Example:

let client = memcache::Client::connect("memcache://localhost:12345").unwrap();
let key = "add_test";
client.delete(key).unwrap();
client.add(key, "bar", 100000000).unwrap();
source

pub fn replace<V: ToMemcacheValue<Stream>>( &self, key: &str, value: V, expiration: u32, ) -> Result<(), MemcacheError>

Replace a key with associate value into memcached server with expiration seconds.

Example:

let client = memcache::Client::connect("memcache://localhost:12345").unwrap();
let key = "replace_test";
client.set(key, "bar", 0).unwrap();
client.replace(key, "baz", 100000000).unwrap();
source

pub fn append<V: ToMemcacheValue<Stream>>( &self, key: &str, value: V, ) -> Result<(), MemcacheError>

Append value to the key.

Example:

let client = memcache::Client::connect("memcache://localhost:12345").unwrap();
let key = "key_to_append";
client.set(key, "hello", 0).unwrap();
client.append(key, ", world!").unwrap();
let result: String = client.get(key).unwrap().unwrap();
assert_eq!(result, "hello, world!");
source

pub fn prepend<V: ToMemcacheValue<Stream>>( &self, key: &str, value: V, ) -> Result<(), MemcacheError>

Prepend value to the key.

Example:

let client = memcache::Client::connect("memcache://localhost:12345").unwrap();
let key = "key_to_append";
client.set(key, "world!", 0).unwrap();
client.prepend(key, "hello, ").unwrap();
let result: String = client.get(key).unwrap().unwrap();
assert_eq!(result, "hello, world!");
source

pub fn delete(&self, key: &str) -> Result<bool, MemcacheError>

Delete a key from memcached server.

Example:

let client = memcache::Client::connect("memcache://localhost:12345").unwrap();
client.delete("foo").unwrap();
source

pub fn increment(&self, key: &str, amount: u64) -> Result<u64, MemcacheError>

Increment the value with amount.

Example:

let client = memcache::Client::connect("memcache://localhost:12345").unwrap();
client.increment("counter", 42).unwrap();
source

pub fn decrement(&self, key: &str, amount: u64) -> Result<u64, MemcacheError>

Decrement the value with amount.

Example:

let client = memcache::Client::connect("memcache://localhost:12345").unwrap();
client.decrement("counter", 42).unwrap();
source

pub fn touch(&self, key: &str, expiration: u32) -> Result<bool, MemcacheError>

Set a new expiration time for a exist key.

Example:

let client = memcache::Client::connect("memcache://localhost:12345").unwrap();
assert_eq!(client.touch("not_exists_key", 12345).unwrap(), false);
client.set("foo", "bar", 123).unwrap();
assert_eq!(client.touch("foo", 12345).unwrap(), true);
source

pub fn stats( &self, ) -> Result<Vec<(String, HashMap<String, String>)>, MemcacheError>

Get all servers’ statistics.

Example:

let client = memcache::Client::connect("memcache://localhost:12345").unwrap();
let stats = client.stats().unwrap();

Trait Implementations§

source§

impl Clone for Client

source§

fn clone(&self) -> Client

Returns a copy 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 Send for Client

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.
source§

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

source§

fn vzip(self) -> V