14 releases

0.4.2 Jan 28, 2020
0.4.1 Dec 19, 2018
0.4.0 Nov 15, 2018
0.3.0 Jul 13, 2018
0.0.4 Mar 26, 2015

#3 in #memcached

Download history 4396/week @ 2021-09-27 3506/week @ 2021-10-04 4248/week @ 2021-10-11 4183/week @ 2021-10-18 4470/week @ 2021-10-25 3703/week @ 2021-11-01 2658/week @ 2021-11-08 2511/week @ 2021-11-15 2216/week @ 2021-11-22 2660/week @ 2021-11-29 2674/week @ 2021-12-06 2578/week @ 2021-12-13 1957/week @ 2021-12-20 1719/week @ 2021-12-27 2663/week @ 2022-01-03 2484/week @ 2022-01-10

8,920 downloads per month
Used in 2 crates

MIT/Apache

135KB
3.5K SLoC

memcached-rs

Build Status crates.io dependency status

Memcached library in Rust

Usage

use std::collections::TreeMap;

use memcached::Client;
use memcached::proto::{Operation, MultiOperation, NoReplyOperation, CasOperation, ProtoType};

fn main() {
    let servers = [
        ("tcp://127.0.0.1:11211", 1),
    ];
    let mut client = Client::connect(&servers, ProtoType::Binary).unwrap();

    client.set(b"Foo", b"Bar", 0xdeadbeef, 2).unwrap();
    let (value, flags) = client.get(b"Foo").unwrap();
    assert_eq!(value.as_slice(), b"Bar");
    assert_eq!(flags, 0xdeadbeef);

    client.set_noreply(b"key:dontreply", b"1", 0x00000001, 20).unwrap();

    let (_, cas_val) = client.increment_cas(b"key:numerical", 10, 1, 20, 0).unwrap();
    client.increment_cas(b"key:numerical", 1, 1, 20, cas_val).unwrap();
}

Run cargo doc --open for more details.

SASL authentication

TCP connections support PLAIN SASL authentication:

use memcached::proto::{Operation, ProtoType};
use memcached::Client;

fn main() {
    let servers = [
        ("tcp://my-sasl-memcached-server.com:11211", 1)
    ];
    let mut client = Client::connect_sasl(&servers, ProtoType::Binary, "my-username", "my-password").unwrap();

    client.set(b"Foo", b"Bar", 0xdeadbeef, 2).unwrap();
    let (value, flags) = client.get(b"Foo").unwrap();
    assert_eq!(&value[..], b"Bar");
    assert_eq!(flags, 0xdeadbeef);
}

TODO

  • Auto-disable failed servers

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~765KB
~14K SLoC

{0^