Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

memcache client for rust

License

NotificationsYou must be signed in to change notification settings

aisk/rust-memcache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Crates.ioMIT licensedDocs

rust-memcache is amemcached client written in pure rust.

logo

Install

The crate is calledmemcache 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 = memcache::connect("memcache://127.0.0.1:12345?timeout=10&tcp_nodelay=true").unwrap();// flush the databaseclient.flush().unwrap();// set a string valueclient.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");// cas(check and set):let(_, _, cas_token) = client.get("foo").unwrap().unwrap();let cas_id = cas_id.unwrap();client.cas("foo","qux",0, cas_id).unwrap();// delete value:client.delete("foo").unwrap();// 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);

Custom key hash function

If you have multiple memcached server, you can create thememcache::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.

letmut client = memcache::connect(vec!["memcache://127.0.0.1:12345","memcache:///tmp/memcached.sock"]).unwrap();client.hash_function = |key:&str| ->u64{// your custom hashing function herereturn1;};

Contributing

Before sending pull request, please ensure:

  • cargo fmt is being run;
  • Commit message is usinggitmoji with first character is lower cased, for example::sparkles: rust-memcache can print money now.

Contributors

License

MIT

About

memcache client for rust

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors20


[8]ページ先頭

©2009-2025 Movatter.jp