rust-memcache
rust-memcache is a memcached client written in pure rust.
Install
The crate is called memcache
and you can depend on it via cargo:
[dependencies]
memcache = "*"
Features
- All memcached supported protocols
- Binary protocol
- ASCII protocol
- All memcached supported connections
- TCP connection
- UDP connection
- UNIX Domain socket connection
- TLS connection
- Encodings
- Typed interface
- Automatically compress
- Automatically serialize to JSON / msgpack etc
- Memcached cluster support with custom key hash algorithm
- Authority
- Binary protocol (plain SASL authority plain)
- ASCII protocol
Basic usage
// create connection with to memcached server node:
let client = connect.unwrap;
// flush the database
client.flush.unwrap;
// set a string value
client.set.unwrap;
// retrieve from memcached:
let value: = client.get.unwrap;
assert_eq!;
assert_eq!;
// prepend, append:
client.prepend.unwrap;
client.append.unwrap;
let value: String = client.get.unwrap.unwrap;
assert_eq!;
// delete value:
client.delete.unwrap;
// using counter:
client.set.unwrap;
client.increment.unwrap;
let answer: i32 = client.get.unwrap.unwrap;
assert_eq!;
Custom key hash function
If you have multiple memcached server, you can create the memcache::Client
struct with a vector of urls of them. Which server will be used to store and retrive is based on what the key is.
This library have a basic rule to do this with rust's builtin hash function, and also you can use your custom function to do this, for something like you can using a have more data on one server which have more memory quota, or cluster keys with their prefix, or using consitent hash for large memcached cluster.
let mut client = connect.unwrap;
client.hash_function = ;
Contributing
Before sending pull request, please ensure:
cargo fmt
is being run;- Commit message is using gitmoji with first character is lower cased, for example:
:sparkles: rust-memcache can print money now
.
Contributors
License
MIT