diff options
author | Heyang Zhou <zhy20000919@hotmail.com> | 2023-09-08 23:20:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-08 23:20:28 +0800 |
commit | 375d8a5bd50cdead2e7ede4a4a2db69b6da92876 (patch) | |
tree | e6e6cec16007e21d64367d5d89b71be9c77dfeae /ext/kv/01_db.ts | |
parent | 17276a1df9fb4926f813d2b8a5ac2a2a8bf289eb (diff) |
fix(ext/kv): same `expireIn` should generate same `expireAt` (#20396)
Co-authored-by: Luca Casonato <hello@lcas.dev>
Diffstat (limited to 'ext/kv/01_db.ts')
-rw-r--r-- | ext/kv/01_db.ts | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/ext/kv/01_db.ts b/ext/kv/01_db.ts index 4cd8744ba..a1015d55d 100644 --- a/ext/kv/01_db.ts +++ b/ext/kv/01_db.ts @@ -134,11 +134,8 @@ class Kv { value = serializeValue(value); const checks: Deno.AtomicCheck[] = []; - const expireAt = typeof options?.expireIn === "number" - ? Date.now() + options.expireIn - : undefined; const mutations = [ - [key, "set", value, expireAt], + [key, "set", value, options?.expireIn], ]; const versionstamp = await core.opAsync( @@ -340,7 +337,7 @@ class AtomicOperation { const key = mutation.key; let type: string; let value: RawValue | null; - let expireAt: number | undefined = undefined; + let expireIn: number | undefined = undefined; switch (mutation.type) { case "delete": type = "delete"; @@ -350,7 +347,7 @@ class AtomicOperation { break; case "set": if (typeof mutation.expireIn === "number") { - expireAt = Date.now() + mutation.expireIn; + expireIn = mutation.expireIn; } /* falls through */ case "sum": @@ -365,7 +362,7 @@ class AtomicOperation { default: throw new TypeError("Invalid mutation type"); } - this.#mutations.push([key, type, value, expireAt]); + this.#mutations.push([key, type, value, expireIn]); } return this; } @@ -390,10 +387,12 @@ class AtomicOperation { value: unknown, options?: { expireIn?: number }, ): this { - const expireAt = typeof options?.expireIn === "number" - ? Date.now() + options.expireIn - : undefined; - this.#mutations.push([key, "set", serializeValue(value), expireAt]); + this.#mutations.push([ + key, + "set", + serializeValue(value), + options?.expireIn, + ]); return this; } |