mset / mget commands (cli currently only supports mget)

This commit is contained in:
2025-07-01 18:33:13 +02:00
parent cff5c37a40
commit c527bb0072
14 changed files with 448 additions and 43 deletions

View File

@@ -1,8 +1,13 @@
use std::io::Cursor;
use bytes::{Buf as _, Bytes};
use bytes::{Buf as _, BufMut as _, Bytes, BytesMut};
use crate::{Result, buffer::ArchiveBuf as _, connection::Connection, database::Database};
use crate::{
Result,
buffer::{ArchiveBuf as _, ArchiveBufMut as _},
connection::Connection,
database::Database,
};
#[derive(Debug, Clone)]
pub struct Expire {
@@ -11,6 +16,10 @@ pub struct Expire {
}
impl Expire {
pub fn new(key: String, seconds: u64) -> Self {
Self { key, seconds }
}
pub async fn execute(self, db: &Database, connection: &mut Connection) -> Result<()> {
let success = db.expire(&self.key, self.seconds).await?;
@@ -27,4 +36,18 @@ impl Expire {
Ok(Self { key, seconds })
}
pub fn put(&self, buf: &mut BytesMut) -> Result<()> {
buf.put_short_string("expire")?;
self.put_without_cmd_name(buf)
}
pub fn put_without_cmd_name(&self, buf: &mut BytesMut) -> Result<()> {
buf.put_short_string(&self.key)?;
buf.put_u64(self.seconds);
Ok(())
}
}