implement COMMAND
This commit is contained in:
		| @@ -40,6 +40,7 @@ pub enum Cmd { | ||||
|     Client(Vec<String>), | ||||
|     ClientSetName(String), | ||||
|     ClientGetName, | ||||
|     Command(Vec<String>), | ||||
|     // List commands | ||||
|     LPush(String, Vec<String>), | ||||
|     RPush(String, Vec<String>), | ||||
| @@ -345,6 +346,10 @@ impl Cmd { | ||||
|                                 Cmd::Client(vec![]) | ||||
|                             } | ||||
|                         } | ||||
|                         "command" => { | ||||
|                             let args = if cmd.len() > 1 { cmd[1..].to_vec() } else { vec![] }; | ||||
|                             Cmd::Command(args) | ||||
|                         } | ||||
|                         "lpush" => { | ||||
|                             if cmd.len() < 3 { | ||||
|                                 return Err(DBError(format!("wrong number of arguments for LPUSH command"))); | ||||
| @@ -540,6 +545,7 @@ impl Cmd { | ||||
|             Cmd::Client(_) => Ok(Protocol::SimpleString("OK".to_string())), | ||||
|             Cmd::ClientSetName(name) => client_setname_cmd(server, &name).await, | ||||
|             Cmd::ClientGetName => client_getname_cmd(server).await, | ||||
|             Cmd::Command(_) => Ok(Protocol::Array(vec![])), | ||||
|             // List commands | ||||
|             Cmd::LPush(key, elements) => lpush_cmd(server, &key, &elements).await, | ||||
|             Cmd::RPush(key, elements) => rpush_cmd(server, &key, &elements).await, | ||||
| @@ -862,17 +868,19 @@ async fn info_cmd(server: &Server, section: &Option<String>) -> Result<Protocol, | ||||
|     info_string.push_str(&format!("# Keyspace\n")); | ||||
|     info_string.push_str(&format!("db{}:keys=0,expires=0,avg_ttl=0\n", info.selected_db)); | ||||
|  | ||||
|  | ||||
|     match section { | ||||
|         Some(s) => match s.as_str() { | ||||
|             "replication" => Ok(Protocol::BulkString( | ||||
|                 "role:master\nmaster_replid:8371b4fb1155b71f4a04d3e1bc3e18c4a990aeea\nmaster_repl_offset:0\n".to_string() | ||||
|             )), | ||||
|             _ => Err(DBError(format!("unsupported section {:?}", s))), | ||||
|         }, | ||||
|         None => { | ||||
|             Ok(Protocol::BulkString(info_string)) | ||||
|         Some(s) => { | ||||
|             let sl = s.to_lowercase(); | ||||
|             if sl == "replication" { | ||||
|                 Ok(Protocol::BulkString( | ||||
|                     "role:master\nmaster_replid:8371b4fb1155b71f4a04d3e1bc3e18c4a990aeea\nmaster_repl_offset:0\n".to_string() | ||||
|                 )) | ||||
|             } else { | ||||
|                 // Return general info for unknown sections (e.g., SERVER) | ||||
|                 Ok(Protocol::BulkString(info_string)) | ||||
|             } | ||||
|         } | ||||
|         None => Ok(Protocol::BulkString(info_string)), | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user