diff options
| author | omagdy <omar.professional8777@gmail.com> | 2025-07-17 08:06:26 +0300 |
|---|---|---|
| committer | omagdy <omar.professional8777@gmail.com> | 2025-07-17 08:06:26 +0300 |
| commit | 38b649ea16d8ed053fd9222bfb9867e3432ee2a6 (patch) | |
| tree | a7fbde68ad869e1b74071207bdf7b7c159c7f75f /src/main.rs | |
| parent | c880c7ad3eba9546ce95bc268218c66a128d319f (diff) | |
| download | redis-rust-38b649ea16d8ed053fd9222bfb9867e3432ee2a6.tar.xz redis-rust-38b649ea16d8ed053fd9222bfb9867e3432ee2a6.zip | |
test: Moved tests to seprate files under tests folder for more structure
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 32 |
1 files changed, 3 insertions, 29 deletions
diff --git a/src/main.rs b/src/main.rs index c6c8720..6fb16b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,35 +8,9 @@ use std::{ time::{Duration, SystemTime, UNIX_EPOCH}, }; -#[macro_use] -mod macros; -mod resp_commands; -mod resp_parser; - -use resp_commands::RedisCommands; -use resp_parser::{parse, RespType}; - -#[derive(Debug, Clone)] -pub struct CacheEntry { - pub value: String, - pub expires_at: Option<u64>, // Unix timestamp in milliseconds -} - -impl CacheEntry { - pub fn is_expired(&self) -> bool { - if let Some(expiry) = self.expires_at { - let now = SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap() - .as_millis() as u64; - now > expiry - } else { - false - } - } -} - -pub type SharedCache = Arc<Mutex<HashMap<String, CacheEntry>>>; +use codecrafters_redis::resp_commands::RedisCommands; +use codecrafters_redis::resp_parser::{parse, RespType}; +use codecrafters_redis::shared_cache::*; fn spawn_cleanup_thread(cache: SharedCache) { let cache_clone = cache.clone(); |
