read expiration from Set command + tests
This commit is contained in:
@@ -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),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user