• Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 11 years ago
  • Updated 7 months 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

pick

create curses based interactive selection list in the terminal
Python
722
star
2

libae

redis's async event loop library
C
188
star
3

vox

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

pic2ascii

convert pictrue to ascii code
Python
63
star
5

MySensors

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

multicorn

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

rust-ping

Rust
20
star
8

request

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

browsercookies

Loads cookies from your browsers
Go
10
star
10

.vim

Vim Script
10
star
11

backports.interpreters

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

Slide-Bottom-Bar

A slide bottom action bar on Android
Java
9
star
13

python-memcache

Experimental memcached client library for python.
Python
7
star
14

any

Go
6
star
15

qidong

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

pie

scheme to python-bytecode compiler
Python
5
star
17

monologue

Simple blog system based on Django.
JavaScript
4
star
18

chrysanthemum

Go
4
star
19

aisk.me

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

rust-fire

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

meowscript

JavaScript
3
star
22

presentations

HTML
3
star
23

a-byte-of-haskell

Haskell 简明教程
Python
3
star
24

awpie

Using Python as awk alternative
Python
3
star
25

leancloud-python-todo-app

HTML
2
star
26

puck

scheme implementation in C++
C++
2
star
27

Salt-Pass

Java
2
star
28

naive

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

Rhino-REPL

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

rust-filelock

Rust
2
star
31

algorithms

C++
1
star
32

leancloud-python-test-app

Python
1
star
33

boat

lodash/underscore for go
Go
1
star
34

playbook

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

test-pypi-package-build

Python
1
star
36

.emacs.d

My emacs config
Emacs Lisp
1
star
37

simpleflake.nim

Nim
1
star
38

dotfiles

my dot files
Vim Script
1
star
39

cloudcode-python-sdk

Python
1
star
40

rd-json-parser

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

obama

JavaScript
1
star
42

goblin

Go
1
star
43

leancloud-php-sdk

SDK for leancloud
PHP
1
star