let mut ttl_ms = None; let mut i = 2; while i < args.len() if let RespValue::BulkString(Some(opt)) = &args[i] let opt_str = String::from_utf8_lossy(opt).to_uppercase(); if opt_str == "EX" && i + 1 < args.len() if let RespValue::BulkString(Some(secs_bytes)) = &args[i + 1] if let Ok(secs) = String::from_utf8_lossy(secs_bytes).parse::<u64>() ttl_ms = Some(secs * 1000); i += 2; continue; else if opt_str == "PX" && i + 1 < args.len() if let RespValue::BulkString(Some(ms_bytes)) = &args[i + 1] if let Ok(ms) = String::from_utf8_lossy(ms_bytes).parse::<u64>() ttl_ms = Some(ms); i += 2; continue; i += 1;
fn parse_bulk_string(&mut self) -> Result<Option<RespValue>, String> _ Giordani L. Rust Projects. Write a Redis Clone....
fn parse_error(&mut self) -> Result<Option<RespValue>, String> let (value, bytes_read) = self.read_until_crlf(1)?; self.buffer.advance(bytes_read); Ok(Some(RespValue::Error(value))) let mut ttl_ms = None; let mut i = 2; while i < args
Ok(()) } 1. Start the server: cargo run --release 2. Test with redis-cli (install Redis CLI first): redis-cli -p 6379 3. Or use netcat: # SET command echo "*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n" | nc localhost 6379 GET command echo "*2\r\n$3\r\nGET\r\n$3\r\nkey\r\n" | nc localhost 6379 4. Example commands to try: redis-cli -p 6379 > PING PONG PING PONG fn handle_exists(store: &Store
fn handle_exists(store: &Store, args: &[RespValue]) -> RespValue let mut count = 0; for arg in args if let RespValue::BulkString(Some(key_bytes)) = arg let key = String::from_utf8_lossy(key_bytes); if store.exists(&key) count += 1;