embedded_redis/commands/mod.rs
1pub mod auth;
2pub mod bgsave;
3pub mod builder;
4pub mod custom;
5pub mod get;
6pub mod hello;
7pub mod helpers;
8pub mod hget;
9pub mod hgetall;
10pub mod hset;
11pub mod ping;
12pub mod publish;
13pub mod set;
14#[cfg(test)]
15pub(crate) mod tests;
16
17/// Error in case Redis response type does not match specification
18#[derive(Debug)]
19pub struct ResponseTypeError {}
20
21/// Generic command structure. F is either [Resp2Frame](redis_protocol::resp2::types::BytesFrame) or
22/// [Resp3Frame](redis_protocol::resp3::types::BytesFrame)
23pub trait Command<F> {
24 /// Response type, either a custom evaluated "high-level" response or the original RESP frame
25 type Response;
26
27 /// Encodes the command to RESP2/RESP3 frame
28 fn encode(&self) -> F;
29
30 /// The command has the ability to evaluate the response frame and craft its own high level
31 /// response from that.
32 /// Its also possible to just return 1:1 the RESP2 frame.
33 ///
34 /// Error responses are captured upfront and converted to CommandErrors::ErrorResponse.
35 /// So error responses never reach that method.
36 ///
37 /// Returns Error only in case of protocol violation (e.g. received an array for an command
38 /// that only returns strings)
39 fn eval_response(&self, frame: F) -> Result<Self::Response, ResponseTypeError>;
40}