mini_redis/cmd/
unknown.rs

1use crate::{Connection, Frame};
2
3use tracing::{debug, instrument};
4
5/// Represents an "unknown" command. This is not a real `Redis` command.
6#[derive(Debug)]
7pub struct Unknown {
8    command_name: String,
9}
10
11impl Unknown {
12    /// Create a new `Unknown` command which responds to unknown commands
13    /// issued by clients
14    pub(crate) fn new(key: impl ToString) -> Unknown {
15        Unknown {
16            command_name: key.to_string(),
17        }
18    }
19
20    /// Returns the command name
21    pub(crate) fn get_name(&self) -> &str {
22        &self.command_name
23    }
24
25    /// Responds to the client, indicating the command is not recognized.
26    ///
27    /// This usually means the command is not yet implemented by `mini-redis`.
28    #[instrument(skip(self, dst))]
29    pub(crate) async fn apply(self, dst: &mut Connection) -> crate::Result<()> {
30        let response = Frame::Error(format!("ERR unknown command '{}'", self.command_name));
31
32        debug!(?response);
33
34        dst.write_frame(&response).await?;
35        Ok(())
36    }
37}