diff options
| author | omagdy <omar.professional8777@gmail.com> | 2025-07-23 00:44:07 +0300 |
|---|---|---|
| committer | omagdy <omar.professional8777@gmail.com> | 2025-07-23 00:44:07 +0300 |
| commit | 7dbaa99eb721748f5eff2839817c6742029ad2b3 (patch) | |
| tree | a8a34de7a44d25858d87c27b10a7d79afacd261d | |
| parent | 257330132dacc2e754a858c342be1ef2a1105c8f (diff) | |
| download | redis-rust-7dbaa99eb721748f5eff2839817c6742029ad2b3.tar.xz redis-rust-7dbaa99eb721748f5eff2839817c6742029ad2b3.zip | |
feat: Added simple response to INFO replication command
| -rw-r--r-- | src/macros.rs | 2 | ||||
| -rw-r--r-- | src/resp_commands.rs | 18 | ||||
| -rw-r--r-- | src/resp_parser.rs | 4 |
3 files changed, 19 insertions, 5 deletions
diff --git a/src/macros.rs b/src/macros.rs index 9fddef7..96b5e09 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,4 +1,3 @@ -#[macro_use] #[macro_export] macro_rules! resp { // Null: resp!(null) @@ -30,6 +29,7 @@ macro_rules! resp { }; // Array: resp!(array [resp!("one"), resp!(int 2)]) + // FIXME: this doesn't work and errors (array [$($elem:expr),*]) => { RespType::Array(vec![$($elem),*]).to_resp_bytes() }; diff --git a/src/resp_commands.rs b/src/resp_commands.rs index d61a4be..0fa6945 100644 --- a/src/resp_commands.rs +++ b/src/resp_commands.rs @@ -1,4 +1,3 @@ -use crate::rdb::RDBFile; use crate::SharedConfig; use crate::{resp_parser::*, shared_cache::*}; use regex::Regex; @@ -117,6 +116,7 @@ pub enum RedisCommands { Set(SetCommand), ConfigGet(String), Keys(String), + Info(String), Invalid, } @@ -234,6 +234,10 @@ impl RedisCommands { .collect(); RT::Array(matching_keys).to_resp_bytes() } + RC::Info(_sub_command) => { + use RespType as RT; + RT::BulkString("# Replication\r\nrole:master".as_bytes().to_vec()).to_resp_bytes() + } RC::Invalid => todo!(), } } @@ -406,10 +410,16 @@ impl From<RespType> for RedisCommands { } Self::Invalid } + "INFO" => { + let Some(sub_command) = args.next() else { + return Self::Invalid; + }; + if &sub_command.to_uppercase() == &"REPLICATION" { + return Self::Info(sub_command); + } + Self::Invalid + } _ => Self::Invalid, } } } - -#[cfg(test)] -mod tests {} diff --git a/src/resp_parser.rs b/src/resp_parser.rs index a00bc1b..952176c 100644 --- a/src/resp_parser.rs +++ b/src/resp_parser.rs @@ -7,6 +7,10 @@ use std::{ isize, }; +// TODO: [ ] Refactor this mess and find a better way to merge the RespType and RedisValue type?? +// TODO: [ ] Find a better way to convert from RespType to bytes and vice versa +// TODO: [ ] Refactor the use of Vec<u8> to the bytes crate + pub const SIMPLE_STRING: u8 = b'+'; pub const SIMPLE_ERROR: u8 = b'-'; pub const INTEGER: u8 = b':'; |
