diff options
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(); |
