MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / get_ttl_ms

Method get_ttl_ms

nodedb/src/engine/kv/engine.rs:217–238  ·  view source on GitHub ↗

GET TTL: Returns the remaining TTL in milliseconds for a key. - `None` — key does not exist (or is expired) - `Some(-1)` — key exists but has no TTL (persistent) - `Some(remaining_ms)` — key exists and expires in `remaining_ms` milliseconds

(
        &self,
        tenant_id: u64,
        collection: &str,
        key: &[u8],
        now_ms: u64,
    )

Source from the content-addressed store, hash-verified

215 /// - `Some(-1)` — key exists but has no TTL (persistent)
216 /// - `Some(remaining_ms)` — key exists and expires in `remaining_ms` milliseconds
217 pub fn get_ttl_ms(
218 &self,
219 tenant_id: u64,
220 collection: &str,
221 key: &[u8],
222 now_ms: u64,
223 ) -> Option<i64> {
224 let tkey = table_key(tenant_id, collection);
225 let table = self.tables.get(&tkey)?;
226
227 // First check the key exists and isn't expired.
228 table.get(key, now_ms)?;
229
230 // Now get the metadata for TTL info.
231 let meta = table.get_entry_meta(key)?;
232 if !meta.has_ttl {
233 Some(-1)
234 } else {
235 let remaining = meta.expire_at_ms.saturating_sub(now_ms);
236 Some(remaining as i64)
237 }
238 }
239
240 /// BATCH GET: fetch multiple keys. Returns values in order (None for missing).
241 pub fn batch_get(

Callers 3

execute_kv_get_ttlMethod · 0.80
incr_with_ttl_new_keyFunction · 0.80

Calls 3

table_keyFunction · 0.85
get_entry_metaMethod · 0.80
getMethod · 0.45

Tested by 2

incr_with_ttl_new_keyFunction · 0.64