refactor option write / reads
This commit is contained in:
@@ -2,7 +2,7 @@ use std::io::Cursor;
|
||||
|
||||
use bytes::{Buf as _, Bytes};
|
||||
|
||||
use crate::{Result, buffer::try_get_string, connection::Connection, database::Database};
|
||||
use crate::{Result, buffer::ArchiveBuf as _, connection::Connection, database::Database};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Expire {
|
||||
@@ -12,18 +12,18 @@ pub struct Expire {
|
||||
|
||||
impl Expire {
|
||||
pub async fn execute(self, db: &Database, connection: &mut Connection) -> Result<()> {
|
||||
let value = db.expire(&self.key, self.seconds).await?;
|
||||
let success = db.expire(&self.key, self.seconds).await?;
|
||||
|
||||
connection
|
||||
.write(Bytes::from_static(if value { &[1] } else { &[0] }))
|
||||
.write(Bytes::from_static(if success { &[1] } else { &[0] }))
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn parse(bytes: &mut Cursor<&[u8]>) -> Result<Self> {
|
||||
let key = try_get_string(bytes)?;
|
||||
let seconds = bytes.try_get_u64()?;
|
||||
pub fn parse(buf: &mut Cursor<&[u8]>) -> Result<Self> {
|
||||
let key = buf.try_get_string()?;
|
||||
let seconds = buf.try_get_u64()?;
|
||||
|
||||
Ok(Self { key, seconds })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user