1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use crate::error::Result;
use crate::{LeaseClient, LeaseTimeToLiveOptions, LeaseTimeToLiveResponse};

pub struct LeaseClientPrefix {
    pfx: Vec<u8>,
    lease: LeaseClient,
}

impl LeaseClientPrefix {
    /// Wrap a Lease interface to filter for only keys with a prefix
    /// and remove that prefix when fetching attached keys through TimeToLive.
    pub fn new(lease: LeaseClient, pfx: Vec<u8>) -> Self {
        Self { pfx, lease }
    }

    pub async fn time_to_live(
        &mut self,
        id: i64,
        options: Option<LeaseTimeToLiveOptions>,
    ) -> Result<LeaseTimeToLiveResponse> {
        let mut resp = self.lease.time_to_live(id, options).await?;
        resp.strip_keys_prefix(&self.pfx);
        Ok(resp)
    }
}