1
- pub const DEFAULT_PORT : & str = "6379" ;
1
+ //! A minimal (i.e. very incomplete) implementation of a Redis server and
2
+ //! client.
3
+ //!
4
+ //! The purpose of this project is to provide a larger example of an
5
+ //! asynchronous Rust project built with Tokio. Do not attempt to run this in
6
+ //! production... seriously.
7
+ //!
8
+ //! # Layout
9
+ //!
10
+ //! The library is structured such that it can be used with guides. There are
11
+ //! modules that are public that probably would not be public in a "real" redis
12
+ //! client library.
13
+ //!
14
+ //! The major components are:
15
+ //!
16
+ //! * `server`: Redis server implementation. Includes a single `run` function
17
+ //! that takes a `TcpListener` and starts accepting redis client connections.
18
+ //!
19
+ //! * `client`: an asynchronous Redis client implementation. Demonstrates how to
20
+ //! build clients with Tokio.
21
+ //!
22
+ //! * `cmd`: implementations of the supported Redis commands.
23
+ //!
24
+ //! * `frame`: represents a single Redis protocol frame. A frame is used as an
25
+ //! intermediate representation between a "command" and the byte
26
+ //! representation.
2
27
3
28
pub mod client;
4
29
@@ -22,8 +47,25 @@ pub mod server;
22
47
mod shutdown;
23
48
use shutdown:: Shutdown ;
24
49
50
+ /// Default port that a redis server listens on.
51
+ ///
52
+ /// Used if no port is specified.
53
+ pub const DEFAULT_PORT : & str = "6379" ;
54
+
25
55
/// Error returned by most functions.
56
+ ///
57
+ /// When writing a real application, one might want to consider a specialized
58
+ /// errror handling crate or defining an error type as an `enum` of causes.
59
+ /// However, for our example, using a boxed `std::error::Error` is sufficient.
60
+ ///
61
+ /// For performance reasons, boxing is avoided in any hot path. For example, in
62
+ /// `parse`, a custom error `enum` is defined. This is because the error is hit
63
+ /// and handled during normal execution when a partial frame is received on a
64
+ /// socket. `std::error::Error` is implemented for `parse::Error` which allows
65
+ /// it to be converted to `Box<dyn std::error::Error>`.
26
66
pub type Error = Box < dyn std:: error:: Error + Send + Sync > ;
27
67
28
68
/// A specialized `Result` type for mini-redis operations.
69
+ ///
70
+ /// This is defined as a convenience.
29
71
pub type Result < T > = std:: result:: Result < T , Error > ;
0 commit comments