persist command

This commit is contained in:
2025-06-17 21:11:09 +02:00
parent c51c90b597
commit 0a9c8f81aa
5 changed files with 106 additions and 3 deletions

View File

@@ -198,6 +198,32 @@ impl Client {
Ok(success)
}
pub async fn persist(&mut self, key: &str) -> Result<bool> {
let mut bytes = BytesMut::new();
bytes.put_u16(7);
bytes.put_slice(b"persist");
let key_length: u16 = key
.len()
.try_into()
.map_err(|_| AppError::KeyLength(key.len()))?;
bytes.put_u16(key_length);
bytes.put_slice(key.as_bytes());
self.connection.write(bytes.into()).await?;
let mut r = self.get_response().await?;
let success = match r.try_get_u8()? {
1 => true,
0 => false,
_ => return Err(AppError::InvalidCommandResponse),
};
Ok(success)
}
async fn get_response(&mut self) -> Result<Bytes> {
self.connection
.read_bytes()