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;
pub fn ttl(&self, key: &str) -> i64 let map = self.inner.lock().unwrap(); if let Some(value) = map.get(key) if let Some(expires_at) = value.expires_at let now = SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap() .as_millis() as u64; if now >= expires_at return -2; ((expires_at - now) / 1000) as i64 else -1 else -2 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))) fn handle_exists(store: &Store
match command.as_str() { "SET" => handle_set(store, args), "GET" => handle_get(store, args), "DEL" => handle_del(store, args), "EXISTS" => handle_exists(store, args), "KEYS" => handle_keys(store, args), "EXPIRE" => handle_expire(store, args), "TTL" => handle_ttl(store, args), "DBSIZE" => handle_dbsize(store, args), "FLUSHALL" => handle_flushall(store, args), "PING" => handle_ping(args), _ => RespValue::Error(format!("ERR unknown command '{}'", command)), } } else RespValue::Error("ERR invalid command format".to_string()) } _ => RespValue::Error("ERR invalid request".to_string()), } } args: &[RespValue]) ->