basic expiration (values still need to serialize expiration)

This commit is contained in:
2025-06-16 20:51:48 +02:00
parent 39dd27378a
commit 28b42c786c
4 changed files with 143 additions and 19 deletions

View File

@@ -6,7 +6,7 @@ use tokio::{net::TcpListener, sync::Semaphore};
use crate::Result;
use crate::config::ServerConfig;
use crate::connection::Connection;
use crate::database::Database;
use crate::database::{Database, key_expiration_manager};
use crate::handler::Handler;
#[derive(Debug)]
@@ -25,8 +25,12 @@ impl Server {
async fn _new<Addr: ToSocketAddrs>(addr: Addr, max_connections: usize) -> Result<Self> {
let listener = TcpListener::bind(addr).await?;
let db = Database::new();
tokio::spawn(key_expiration_manager(db.clone()));
Ok(Self {
db: Database::new(),
db,
connection_limit: Arc::new(Semaphore::const_new(max_connections)),
listener,
})
@@ -48,7 +52,7 @@ impl Server {
tokio::spawn(async move {
log::debug!("Spawned a new connection handler: {addr}");
if let Err(e) = handler.run().await {
println!("Handler::run error: {e:?}");
log::debug!("Handler::run error: {e:?}");
}
log::debug!("Connection handler ended: {addr}");