mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-08-12 14:34:48 +00:00
add rust lang to repo by add assets/mini-redis
This commit is contained in:
37
zh-CN/assets/mini-redis/src/cmd/unknown.rs
Normal file
37
zh-CN/assets/mini-redis/src/cmd/unknown.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use crate::{Connection, Frame};
|
||||
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
/// Represents an "unknown" command. This is not a real `Redis` command.
|
||||
#[derive(Debug)]
|
||||
pub struct Unknown {
|
||||
command_name: String,
|
||||
}
|
||||
|
||||
impl Unknown {
|
||||
/// Create a new `Unknown` command which responds to unknown commands
|
||||
/// issued by clients
|
||||
pub(crate) fn new(key: impl ToString) -> Unknown {
|
||||
Unknown {
|
||||
command_name: key.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the command name
|
||||
pub(crate) fn get_name(&self) -> &str {
|
||||
&self.command_name
|
||||
}
|
||||
|
||||
/// Responds to the client, indicating the command is not recognized.
|
||||
///
|
||||
/// This usually means the command is not yet implemented by `mini-redis`.
|
||||
#[instrument(skip(self, dst))]
|
||||
pub(crate) async fn apply(self, dst: &mut Connection) -> crate::Result<()> {
|
||||
let response = Frame::Error(format!("ERR unknown command '{}'", self.command_name));
|
||||
|
||||
debug!(?response);
|
||||
|
||||
dst.write_frame(&response).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user