diff options
author | Heyang Zhou <zhy20000919@hotmail.com> | 2023-09-27 13:34:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-27 13:34:09 +0800 |
commit | f58a400585020b1b4765093b791c0d79882adbbf (patch) | |
tree | 662211a2a195aa9c8ffec38efc07f9d4335ca0e0 /ext/kv/remote.rs | |
parent | f0a022bed4c8ca46c472c6361f1793cb29f73480 (diff) |
feat(ext/kv): support key expiration in remote backend (#20688)
This patch adds support for [key
expiration](https://docs.deno.com/kv/manual/key_expiration) in the
remote backend.
Diffstat (limited to 'ext/kv/remote.rs')
-rw-r--r-- | ext/kv/remote.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/ext/kv/remote.rs b/ext/kv/remote.rs index 36c4d3af2..38b233cc3 100644 --- a/ext/kv/remote.rs +++ b/ext/kv/remote.rs @@ -230,11 +230,7 @@ impl<P: RemoteDbHandlerPermissions> Database for RemoteDb<P> { }) }) .collect::<anyhow::Result<_>>()?, - kv_mutations: write - .mutations - .into_iter() - .map(|x| encode_mutation(x.key, x.kind)) - .collect(), + kv_mutations: write.mutations.into_iter().map(encode_mutation).collect(), enqueues: vec![], }; @@ -333,32 +329,41 @@ fn encode_value(value: crate::Value) -> pb::KvValue { } } -fn encode_mutation(key: Vec<u8>, mutation: MutationKind) -> pb::KvMutation { - match mutation { +fn encode_mutation(m: crate::KvMutation) -> pb::KvMutation { + let key = m.key; + let expire_at_ms = + m.expire_at.and_then(|x| i64::try_from(x).ok()).unwrap_or(0); + + match m.kind { MutationKind::Set(x) => pb::KvMutation { key, value: Some(encode_value(x)), mutation_type: pb::KvMutationType::MSet as _, + expire_at_ms, }, MutationKind::Delete => pb::KvMutation { key, value: Some(encode_value(crate::Value::Bytes(vec![]))), mutation_type: pb::KvMutationType::MClear as _, + expire_at_ms, }, MutationKind::Max(x) => pb::KvMutation { key, value: Some(encode_value(x)), mutation_type: pb::KvMutationType::MMax as _, + expire_at_ms, }, MutationKind::Min(x) => pb::KvMutation { key, value: Some(encode_value(x)), mutation_type: pb::KvMutationType::MMin as _, + expire_at_ms, }, MutationKind::Sum(x) => pb::KvMutation { key, value: Some(encode_value(x)), mutation_type: pb::KvMutationType::MSum as _, + expire_at_ms, }, } } |