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