memcache/
lib.rs

1/*!
2rust-memcache is a [memcached](https://memcached.org/) client written in pure rust.
3
4# Install:
5
6The crate is called `memcache` and you can depend on it via cargo:
7
8```ini
9[dependencies]
10memcache = "*"
11```
12
13# Features:
14
15- <input type="checkbox"  disabled checked /> All memcached supported protocols
16  - <input type="checkbox"  disabled checked /> Binary protocol
17  - <input type="checkbox"  disabled checked /> ASCII protocol
18- <input type="checkbox"  disabled checked /> All memcached supported connections
19  - <input type="checkbox"  disabled checked /> TCP connection
20  - <input type="checkbox"  disabled checked /> UDP connection
21  - <input type="checkbox"  disabled checked/> UNIX Domain socket connection
22  - <input type="checkbox"  disabled checked/> TLS connection
23- <input type="checkbox"  disabled /> Encodings
24  - <input type="checkbox"  disabled checked /> Typed interface
25  - <input type="checkbox"  disabled /> Automatically compress
26  - <input type="checkbox"  disabled /> Automatically serialize to JSON / msgpack etc
27- <input type="checkbox"  disabled checked /> Mutiple server support with custom key hash algorithm
28- <input type="checkbox"  disabled checked /> Authority
29  - <input type="checkbox"  disabled checked /> Binary protocol (plain SASL authority)
30  - <input type="checkbox"  disabled checked /> ASCII protocol
31
32# Basic usage:
33
34```rust
35// create connection with to memcached server node:
36let client = memcache::connect("memcache://127.0.0.1:12345?timeout=10&tcp_nodelay=true").unwrap();
37
38// flush the database:
39client.flush().unwrap();
40
41// set a string value:
42client.set("foo", "bar", 0).unwrap();
43
44// retrieve from memcached:
45let value: Option<String> = client.get("foo").unwrap();
46assert_eq!(value, Some(String::from("bar")));
47assert_eq!(value.unwrap(), "bar");
48
49// prepend, append:
50client.prepend("foo", "foo").unwrap();
51client.append("foo", "baz").unwrap();
52let value: String = client.get("foo").unwrap().unwrap();
53assert_eq!(value, "foobarbaz");
54
55// delete value:
56client.delete("foo").unwrap();
57
58// using counter:
59client.set("counter", 40, 0).unwrap();
60client.increment("counter", 2).unwrap();
61let answer: i32 = client.get("counter").unwrap().unwrap();
62assert_eq!(answer, 42);
63```
64!*/
65
66#![cfg_attr(feature = "cargo-clippy", allow(clippy::needless_return))]
67
68extern crate byteorder;
69extern crate enum_dispatch;
70#[cfg(feature = "tls")]
71extern crate openssl;
72extern crate r2d2;
73extern crate rand;
74extern crate url;
75
76mod client;
77mod connection;
78mod error;
79mod protocol;
80mod stream;
81mod value;
82
83pub use crate::client::{Client, ClientBuilder, Connectable};
84pub use crate::connection::ConnectionManager;
85pub use crate::error::{ClientError, CommandError, MemcacheError, ServerError};
86pub use crate::stream::Stream;
87pub use crate::value::{FromMemcacheValue, FromMemcacheValueExt, ToMemcacheValue};
88pub use r2d2::Error;
89pub use url::{ParseError as UrlParseError, Url};
90
91/// R2D2 connection pool
92pub type Pool = r2d2::Pool<connection::ConnectionManager>;
93
94/// Create a memcached client instance and connect to memcached server.
95///
96/// Example:
97///
98/// ```rust
99/// let client = memcache::connect("memcache://localhost:12345").unwrap();
100/// ```
101pub fn connect<C: Connectable>(target: C) -> Result<Client, MemcacheError> {
102    Client::connect(target)
103}