aboutsummaryrefslogtreecommitdiff
path: root/src/resp_commands.rs
diff options
context:
space:
mode:
authoromagdy <omar.professional8777@gmail.com>2025-07-20 16:29:34 +0300
committeromagdy <omar.professional8777@gmail.com>2025-07-20 16:29:34 +0300
commit846479e6bcf8238879546534b09e141b9bb668f8 (patch)
treeac2e65b5842bea095107c0a750843d0cf7bc74b4 /src/resp_commands.rs
parent38b649ea16d8ed053fd9222bfb9867e3432ee2a6 (diff)
downloadredis-rust-846479e6bcf8238879546534b09e141b9bb668f8.tar.xz
redis-rust-846479e6bcf8238879546534b09e141b9bb668f8.zip
feat: Added parsing of simple command line arguments and CONFIG GET command implementation
Diffstat (limited to 'src/resp_commands.rs')
-rw-r--r--src/resp_commands.rs42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/resp_commands.rs b/src/resp_commands.rs
index 4d01507..37273f8 100644
--- a/src/resp_commands.rs
+++ b/src/resp_commands.rs
@@ -1,6 +1,6 @@
use crate::{resp_parser::*, shared_cache::*};
-use std::collections::HashMap;
-use std::time::{Duration, SystemTime, UNIX_EPOCH};
+use crate::{Config, SharedConfig};
+use std::time::{SystemTime, UNIX_EPOCH};
#[derive(Debug, Clone)]
pub enum SetCondition {
@@ -118,11 +118,12 @@ pub enum RedisCommands {
ECHO(String),
GET(String),
SET(SetCommand),
+ CONFIG_GET(String),
Invalid,
}
impl RedisCommands {
- pub fn execute(self, cache: SharedCache) -> Vec<u8> {
+ pub fn execute(self, cache: SharedCache, config: SharedConfig) -> Vec<u8> {
match self {
RedisCommands::PING => resp!("PONG"),
RedisCommands::ECHO(echo_string) => resp!(echo_string),
@@ -193,6 +194,29 @@ impl RedisCommands {
None => return resp!(null),
}
}
+ RedisCommands::CONFIG_GET(s) => {
+ use RespType as RT;
+ let config = config.clone();
+ if let Some(conf) = config.as_ref() {
+ let dir = conf.dir.clone().unwrap();
+ let dbfilename = conf.dbfilename.clone().unwrap();
+ match s.as_str() {
+ "dir" => RT::Array(vec![
+ RT::BulkString(s.as_bytes().to_vec()),
+ RT::BulkString(dir.as_bytes().to_vec()),
+ ])
+ .to_resp_bytes(),
+ "dbfilename" => RT::Array(vec![
+ RT::BulkString(s.as_bytes().to_vec()),
+ RT::BulkString(dbfilename.as_bytes().to_vec()),
+ ])
+ .to_resp_bytes(),
+ _ => unreachable!(),
+ }
+ } else {
+ unreachable!()
+ }
+ }
RedisCommands::Invalid => todo!(),
}
}
@@ -347,6 +371,18 @@ impl From<RespType> for RedisCommands {
}
}
}
+ "CONFIG" => {
+ let Some(sub_command) = args.next() else {
+ return Self::Invalid;
+ };
+ let Some(key) = args.next() else {
+ return Self::Invalid;
+ };
+ if &sub_command.to_uppercase() == &"GET" {
+ return Self::CONFIG_GET(key);
+ }
+ Self::Invalid
+ }
_ => Self::Invalid,
}
}