read expiration from Set command + tests

This commit is contained in:
2025-06-17 01:52:11 +02:00
parent 28b42c786c
commit 20e3fbd5d3
8 changed files with 119 additions and 41 deletions

View File

@@ -1,6 +1,7 @@
use std::io::Cursor;
use std::{io::Cursor, time::Duration};
use bytes::{Buf as _, Bytes};
use tokio::time::Instant;
use crate::{
Result,
@@ -41,9 +42,15 @@ impl Set {
let data = bytes.copy_to_bytes(value_length);
let expiration: Option<Instant> = match bytes.try_get_u8()? {
1 => Some(Instant::now() + Duration::from_secs(bytes.try_get_u64()?)),
0 => None,
_ => return Err(AppError::UnexpectedCommandData),
};
Ok(Self {
key,
value: Value::new(data, None),
value: Value::new(data, expiration),
})
}
}