Crate memcache

source ·
Expand description

rust-memcache is a Memcached client written in pure rust.


The crate is called memcache and you can depend on it via cargo:

memcache = "*"


  • Binary protocal
  • TCP connection
  • UDP connection
  • UNIX Domain socket connection
  • Automatically compress
  • Automatically serialize to JSON / msgpack etc.
  • Typed interface
  • Mutiple server support with custom key hash algorithm

Basic usage:

// create connection with to memcached server node:
let mut client = memcache::Client::connect("memcache://").unwrap();

// flush the database:

// set a string value:
client.set("foo", "bar", 0).unwrap();

// retrieve from memcached:
let value: Option<String> = client.get("foo").unwrap();
assert_eq!(value, Some(String::from("bar")));
assert_eq!(value.unwrap(), "bar");

// prepend, append:
client.prepend("foo", "foo").unwrap();
client.append("foo", "baz").unwrap();
let value: String = client.get("foo").unwrap().unwrap();
assert_eq!(value, "foobarbaz");

// delete value:

// using counter:
client.set("counter", 40, 0).unwrap();
client.increment("counter", 2).unwrap();
let answer: i32 = client.get("counter").unwrap().unwrap();
assert_eq!(answer, 42);




Stands for errors raised from rust-memcache


determine how the value is unserialize to memcache
determine how the value is serialize to memcache