Skip to main content

ClientHashRing

Struct ClientHashRing 

Source
pub struct ClientHashRing(/* private fields */);

Implementations§

Source§

impl ClientHashRing

Source

pub fn new(conns: Vec<Connection>) -> Self

§Example
use mcmc_rs::{ClientHashRing, Connection};
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);
Source

pub async fn get(&mut self, key: impl AsRef<[u8]>) -> Result<Option<Item>>

§Example
use mcmc_rs::{ClientHashRing, Connection};
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);

assert!(client.set(b"k7", 0, 0, false, b"v7").await?);
assert_eq!(client.get(b"k7").await?.unwrap().key, "k7");
Source

pub async fn gets(&mut self, key: impl AsRef<[u8]>) -> Result<Option<Item>>

§Example
use mcmc_rs::{ClientHashRing, Connection};
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);

assert!(client.set(b"k8", 0, 0, false, b"v8").await?);
assert_eq!(client.gets(b"k8").await?.unwrap().key, "k8");
Source

pub async fn gat( &mut self, exptime: i64, key: impl AsRef<[u8]>, ) -> Result<Option<Item>>

§Example
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);
assert!(client.set(b"k9", 0, 0, false, b"v9").await?);
let result = client.gat(0, b"k9").await?;
assert_eq!(result.unwrap().key, "k9");
Source

pub async fn gats( &mut self, exptime: i64, key: impl AsRef<[u8]>, ) -> Result<Option<Item>>

§Example
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);
assert!(client.set(b"k10", 0, 0, false, b"v10").await?);
let result = client.gats(0, b"k10").await?;
assert_eq!(result.unwrap().key, "k10");
Source

pub async fn set( &mut self, key: impl AsRef<[u8]>, flags: u32, exptime: i64, noreply: bool, data_block: impl AsRef<[u8]>, ) -> Result<bool>

§Example
use mcmc_rs::{ClientHashRing, Connection};
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);

assert!(client.set(b"key", 0, -1, true, b"value").await?);
Source

pub async fn add( &mut self, key: impl AsRef<[u8]>, flags: u32, exptime: i64, noreply: bool, data_block: impl AsRef<[u8]>, ) -> Result<bool>

§Example
use mcmc_rs::{ClientHashRing, Connection};
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);

assert!(client.add(b"key", 0, -1, true, b"value").await?);
Source

pub async fn replace( &mut self, key: impl AsRef<[u8]>, flags: u32, exptime: i64, noreply: bool, data_block: impl AsRef<[u8]>, ) -> Result<bool>

§Example
use mcmc_rs::{ClientHashRing, Connection};
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);

assert!(client.replace(b"key", 0, -1, true, b"value").await?);
Source

pub async fn append( &mut self, key: impl AsRef<[u8]>, flags: u32, exptime: i64, noreply: bool, data_block: impl AsRef<[u8]>, ) -> Result<bool>

§Example
use mcmc_rs::{ClientHashRing, Connection};
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);

assert!(client.append(b"key", 0, -1, true, b"value").await?);
Source

pub async fn prepend( &mut self, key: impl AsRef<[u8]>, flags: u32, exptime: i64, noreply: bool, data_block: impl AsRef<[u8]>, ) -> Result<bool>

§Example
use mcmc_rs::{ClientHashRing, Connection};
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);

assert!(client.prepend(b"key", 0, -1, true, b"value").await?);
Source

pub async fn cas( &mut self, key: impl AsRef<[u8]>, flags: u32, exptime: i64, cas_unique: u64, noreply: bool, data_block: impl AsRef<[u8]>, ) -> Result<bool>

§Example
use mcmc_rs::{ClientHashRing, Connection};
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);

assert!(client.cas(b"key", 0, -1, 0, true, b"value").await?);
Source

pub async fn delete( &mut self, key: impl AsRef<[u8]>, noreply: bool, ) -> Result<bool>

§Example
use mcmc_rs::{ClientHashRing, Connection};
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);

assert!(client.delete(b"key", true).await?);
Source

pub async fn incr( &mut self, key: impl AsRef<[u8]>, value: u64, noreply: bool, ) -> Result<Option<u64>>

§Example
use mcmc_rs::{ClientHashRing, Connection};
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);

assert!(client.incr(b"key", 1, true).await?.is_none());
Source

pub async fn decr( &mut self, key: impl AsRef<[u8]>, value: u64, noreply: bool, ) -> Result<Option<u64>>

§Example
use mcmc_rs::{ClientHashRing, Connection};
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);

assert!(client.decr(b"key", 1, true).await?.is_none());
Source

pub async fn touch( &mut self, key: impl AsRef<[u8]>, exptime: i64, noreply: bool, ) -> Result<bool>

§Example
use mcmc_rs::{ClientHashRing, Connection};
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);

assert!(client.touch(b"key", -1, true).await?);
Source

pub async fn me(&mut self, key: impl AsRef<[u8]>) -> Result<Option<String>>

§Example
use mcmc_rs::{ClientHashRing, Connection};
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);
assert!(client.set(b"k11", 0, 0, false, b"v11").await?);
assert!(client.me(b"k11").await?.is_some());
Source

pub async fn mg( &mut self, key: impl AsRef<[u8]>, flags: &[MgFlag], ) -> Result<MgItem>

§Example
use mcmc_rs::{ClientHashRing, Connection, MgFlag, MgItem};
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);
let result = client
    .mg(
        b"44OG44K544OI",
        &[
            MgFlag::Base64Key,
            MgFlag::ReturnCas,
            MgFlag::ReturnFlags,
            MgFlag::ReturnHit,
            MgFlag::ReturnKey,
            MgFlag::ReturnLastAccess,
            MgFlag::Opaque("opaque".to_string()),
            MgFlag::ReturnSize,
            MgFlag::ReturnTtl,
            MgFlag::UnBump,
            MgFlag::ReturnValue,
            MgFlag::NewCas(0),
            MgFlag::Autovivify(-1),
            MgFlag::RecacheTtl(-1),
            MgFlag::UpdateTtl(-1),
        ],
    )
    .await?;
assert_eq!(
    result,
    MgItem {
        success: true,
        base64_key: false,
        cas: Some(0),
        flags: Some(0),
        hit: Some(0),
        key: Some("テスト".to_string()),
        last_access_ttl: Some(0),
        opaque: Some("opaque".to_string()),
        size: Some(0),
        ttl: Some(-1),
        data_block: Some(vec![]),
        already_win: false,
        won_recache: true,
        stale: false,
    }
);
Source

pub async fn ms( &mut self, key: impl AsRef<[u8]>, flags: &[MsFlag], data_block: impl AsRef<[u8]>, ) -> Result<MsItem>

§Example
use mcmc_rs::{ClientHashRing, Connection, MsFlag, MsItem, MsMode};
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);
let result = client
    .ms(
        b"44OG44K544OI",
        &[
            MsFlag::Base64Key,
            MsFlag::ReturnCas,
            MsFlag::CompareCas(0),
            MsFlag::NewCas(0),
            MsFlag::SetFlags(0),
            MsFlag::Invalidate,
            MsFlag::ReturnKey,
            MsFlag::Opaque("opaque".to_string()),
            MsFlag::ReturnSize,
            MsFlag::Ttl(-1),
            MsFlag::Mode(MsMode::Set),
            MsFlag::Autovivify(0),
        ],
        b"hi",
    )
    .await?;
assert_eq!(
    result,
    MsItem {
        success: false,
        cas: Some(0),
        key: Some("44OG44K544OI".to_string()),
        opaque: Some("opaque".to_string()),
        size: Some(2),
        base64_key: true
    }
);
Source

pub async fn md( &mut self, key: impl AsRef<[u8]>, flags: &[MdFlag], ) -> Result<MdItem>

§Example
use mcmc_rs::{ClientHashRing, Connection, MdFlag, MdItem};
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);
let result = client
    .md(
        b"44OG44K544OI",
        &[
            MdFlag::Base64Key,
            MdFlag::CompareCas(0),
            MdFlag::NewCas(0),
            MdFlag::Invalidate,
            MdFlag::ReturnKey,
            MdFlag::Opaque("opaque".to_string()),
            MdFlag::UpdateTtl(-1),
            MdFlag::LeaveKey,
        ],
    )
    .await?;
assert_eq!(
    result,
    MdItem {
        success: false,
        key: Some("44OG44K544OI".to_string()),
        opaque: Some("opaque".to_string()),
        base64_key: true
    }
);
Source

pub async fn ma( &mut self, key: impl AsRef<[u8]>, flags: &[MaFlag], ) -> Result<MaItem>

§Example
use mcmc_rs::{ClientHashRing, Connection, MaFlag, MaItem, MaMode};
let mut client = ClientHashRing::new(vec![
    Connection::default().await?,
    Connection::unix_connect("/tmp/memcached0.sock").await?,
]);
let result = client
    .ma(
        b"aGk=",
        &[
            MaFlag::Base64Key,
            MaFlag::CompareCas(0),
            MaFlag::NewCas(0),
            MaFlag::AutoCreate(0),
            MaFlag::InitValue(0),
            MaFlag::DeltaApply(0),
            MaFlag::UpdateTtl(0),
            MaFlag::Mode(MaMode::Incr),
            MaFlag::Opaque("opaque".to_string()),
            MaFlag::ReturnTtl,
            MaFlag::ReturnCas,
            MaFlag::ReturnValue,
            MaFlag::ReturnKey,
        ],
    )
    .await?;
assert_eq!(
    result,
    MaItem {
        success: true,
        opaque: Some("opaque".to_string()),
        ttl: Some(-1),
        cas: Some(0),
        number: Some(0),
        key: Some("aGk=".to_string()),
        base64_key: true
    }
);

Auto Trait Implementations§

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