• Stars
    star
    124
  • Rank 278,214 (Top 6 %)
  • Language
    Rust
  • License
    MIT License
  • Created almost 11 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

memcache client for rust

rust-memcache

Build Status Codecov Status Crates.io MIT licensed Docs Gitter chat

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

logo

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 = memcache::connect("memcache://127.0.0.1:12345?timeout=10&tcp_nodelay=true").unwrap();

// flush the database
client.flush().unwrap();

// 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:
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 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 = memcache::connect(vec!["memcache://127.0.0.1:12345", "memcache:///tmp/memcached.sock"]).unwrap();
client.hash_function = |key: &str| -> u64 {
    // your custom hashing function here
    return 1;
};

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

More Repositories

1

libae

redis's async event loop library
C
187
star
2

vox

Simple and lightweight Go web framework inspired by koa
Go
84
star
3

pic2ascii

convert pictrue to ascii code
Python
63
star
4

MySensors

Show macOS's chip tempratures and fan speeds on menu bar.
Swift
35
star
5

multicorn

Multicorn is a multi-interpreter server for Python.
Python
34
star
6

rust-ping

Rust
16
star
7

request

HTTP client for haskell, inpired by requests and http-dispatch.
Haskell
11
star
8

browsercookies

Loads cookies from your browsers
Go
10
star
9

.vim

Vim Script
10
star
10

backports.interpreters

interpreters module in python which is backported from the future
Python
9
star
11

Slide-Bottom-Bar

A slide bottom action bar on Android
Java
9
star
12

python-memcache

Experimental memcached client library for python.
Python
7
star
13

any

Go
6
star
14

pie

scheme to python-bytecode compiler
Python
5
star
15

qidong

Young, simple, sometimes naïve miHoYo / HoYoverse games launcher.
Python
4
star
16

monologue

Simple blog system based on Django.
JavaScript
4
star
17

chrysanthemum

Go
4
star
18

aisk.me

A blog for http://aisk.me runs on racket
4
star
19

rust-fire

Turn your function(s) to a command line app with one line of code.
Rust
4
star
20

meowscript

JavaScript
3
star
21

a-byte-of-haskell

Haskell 简明教程
Python
3
star
22

presentations

HTML
3
star
23

awpie

Using Python as awk alternative
Python
3
star
24

leancloud-python-todo-app

HTML
2
star
25

puck

scheme implementation in C++
C++
2
star
26

Salt-Pass

Java
2
star
27

naive

Naive is a too young too simple template engine
Python
2
star
28

Rhino-REPL

A JavaScript REPL using Rhino runs on Android
Java
2
star
29

rust-filelock

Rust
2
star
30

algorithms

C++
1
star
31

leancloud-python-test-app

Python
1
star
32

boat

lodash/underscore for go
Go
1
star
33

playbook

A ansible playbook to deploy a vps server.
1
star
34

test-pypi-package-build

Python
1
star
35

.emacs.d

My emacs config
Emacs Lisp
1
star
36

simpleflake.nim

Nim
1
star
37

dotfiles

my dot files
Vim Script
1
star
38

cloudcode-python-sdk

Python
1
star
39

rd-json-parser

A simple recursive descent parser parser
C++
1
star
40

obama

JavaScript
1
star
41

goblin

Go
1
star
42

leancloud-php-sdk

SDK for leancloud
PHP
1
star