11 releases (5 breaking)

Uses new Rust 2024

new 0.6.2 May 8, 2025
0.6.1 May 8, 2025
0.5.3 May 5, 2025
0.4.0 Apr 30, 2025
0.1.0 Apr 24, 2025

#324 in Database interfaces

Download history 91/week @ 2025-04-19 495/week @ 2025-04-26 501/week @ 2025-05-03

1,087 downloads per month

MIT license

175KB
3.5K SLoC

Minimal Rust client for Memcached

ci crates.io

Example

Connection mode

use smol::{block_on, io};

use mcmc_rs::Connection;

fn main() -> io::Result<()> {
    block_on(async {
        let mut conn = Connection::default().await?;
        conn.set(b"key", 0, 0, false, b"value").await?;
        let item = conn.get(b"key").await?.unwrap();
        println!("{item:#?}");
        Ok(())
    })
}

Cluster mode

use smol::{block_on, io};

use mcmc_rs::{ClientCrc32, Connection};

fn main() -> io::Result<()> {
    block_on(async {
        let mut client = ClientCrc32::new(vec![
            Connection::default().await?,
            Connection::tcp_connect("127.0.0.1:11212").await?,
        ]);
        client.set(b"key", 0, 0, false, b"value").await?;
        let item = client.get(b"key").await?.unwrap();
        println!("{item:#?}");
        Ok(())
    })
}

Pipeline mode

use smol::{block_on, io};

use mcmc_rs::Connection;

fn main() -> io::Result<()> {
    block_on(async {
        let mut conn = Connection::default().await?;
        let r = conn
            .pipeline()
            .set("key", 0, 0, false, "A")
            .set("key2", 0, 0, false, "A")
            .get("key")
            .get("key2")
            .version()
            .execute()
            .await?;
        println!("{r:#?}");
        Ok(())
    })
}

Pool mode

use smol::{block_on, io};

use mcmc_rs::{AddrArg, Manager, Pool};

fn main() -> io::Result<()> {
    block_on(async {
        let mgr = Manager::new(AddrArg::Tcp("127.0.0.1:11211".to_string()));
        let pool = Pool::builder(mgr).build().unwrap();
        let mut conn = pool.get().await.unwrap();
        let result = conn.version().await?;
        println!("{result:#?}");
        Ok(())
    })
}

Watch mode

use smol::{block_on, io};

use mcmc_rs::{Connection, WatchArg};

fn main() -> io::Result<()> {
    block_on(async {
        let mut conn = Connection::default().await?;
        let mut w = conn.watch(&[WatchArg::Fetchers]).await?;
        let mut conn = Connection::default().await?;
        conn.get(b"key").await?;
        println!("{:#?}", w.message().await?);
        Ok(())
    })
}

Tests

podman kube play pod.yaml
podman exec podmcmc-rs-mcmc-rsmd-unix01 sh -c "chmod a+rw /tmp/memcached.sock"
cargo test
podman kube down pod.yaml

Dependencies

~6–16MB
~210K SLoC