1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//! redif -- a Redis protocol server Framework
//!
//!
//! Redif is a framework, it talks the data transport in redis protocol,
//! and call user provided Handler to handle the request.
//! User should implement Handler trait, and invoke Redif with redif::run( port, handler).
//!
//! For example
//!
//! ```
//!
//! extern crate redif;
//!
//! use std::sync::{Arc,Mutex};
//! use redif::{Value, Handler};
//!
//! // implement Handler trait
//! struct Store {
//! kv : HashMap<String, String>,
//! }
//!
//! impl Handler for Store {
//!
//! fn handle(&mut self, data: &Value) -> Option<Value> {
//! /// ...
//! }
//!
//! }
//!
//!
//! fn main() {
//!
//! let port = 4344u16;
//! let store = Store::new();
//! let handler = Arc::new(Mutex::new(store));
//!
//! // call redif::run() with port and handler
//! if let Err(ref e) = redif::run( port, handler.clone() ) {
//! error!("ERROR {}", e);
//! std::process::exit(1);
//! }
//! }
//!
//! ```
//!
//!
extern crate log;
extern crate amy;
pub use Value;
pub use encode_slice;
pub use run;
/// Handler handle client's request and produce response
///
/// if there is Some(response), then redif will send response to client;
/// if there is None response, then redif would send nothing to client,
/// and client maybe starve!
///