From ab220487a0a3a32c943c84e7023ab6438ad02ac5 Mon Sep 17 00:00:00 2001 From: Andreas Thomas Date: Thu, 30 Mar 2023 18:47:20 +0200 Subject: [PATCH 1/4] test: add argument to unlink --- pkg/pipeline.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/pipeline.test.ts b/pkg/pipeline.test.ts index bcb9aa31..8f6ad3b2 100644 --- a/pkg/pipeline.test.ts +++ b/pkg/pipeline.test.ts @@ -195,7 +195,7 @@ Deno.test("use all the things", async (t) => { .touch(newKey()) .ttl(newKey()) .type(newKey()) - .unlink() + .unlink(newKey()) .zadd(newKey(), { score: 0, member: "member" }) .zcard(newKey()) .scriptExists(scriptHash) From 4c311b5b7bc13af74db92e4d6c1f716e4cd42d9b Mon Sep 17 00:00:00 2001 From: chronark Date: Sat, 13 May 2023 15:36:12 +0200 Subject: [PATCH 2/4] refactor(set): change SetCommandOptions type to intersection type test(set.test): add test for get with nx option --- pkg/commands/set.test.ts | 13 +++++++++++++ pkg/commands/set.ts | 14 +++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/pkg/commands/set.test.ts b/pkg/commands/set.test.ts index 615a9996..1121a082 100644 --- a/pkg/commands/set.test.ts +++ b/pkg/commands/set.test.ts @@ -99,6 +99,19 @@ Deno.test("get", async (t) => { assertEquals(res, old); }); }); + +Deno.test("get with nx", async (t) => { + await t.step("gets the old value", async () => { + const key = newKey(); + const old = randomID(); + const value = randomID(); + await new SetCommand([key, old]).exec(client); + + const res = await new SetCommand([key, value, { get: true, nx: true }]) + .exec(client); + assertEquals(res, old); + }); +}); Deno.test("nx", async (t) => { await t.step("when key exists", async (t) => { await t.step("does nothing", async () => { diff --git a/pkg/commands/set.ts b/pkg/commands/set.ts index 0e753055..fe3b297d 100644 --- a/pkg/commands/set.ts +++ b/pkg/commands/set.ts @@ -1,8 +1,8 @@ import { Command, CommandOptions } from "./command.ts"; export type SetCommandOptions = - | { get: boolean } - | ( + & { get: boolean } + & ( | { ex: number; px?: never; exat?: never; pxat?: never; keepTtl?: never } | { ex?: never; px: number; exat?: never; pxat?: never; keepTtl?: never } | { ex?: never; px?: never; exat: number; pxat?: never; keepTtl?: never } @@ -10,11 +10,11 @@ export type SetCommandOptions = | { ex?: never; px?: never; exat?: never; pxat?: never; keepTtl: true } | { ex?: never; px?: never; exat?: never; pxat?: never; keepTtl?: never } ) - & ( - | { nx: true; xx?: never } - | { xx: true; nx?: never } - | { xx?: never; nx?: never } - ); + & ( + | { nx: true; xx?: never } + | { xx: true; nx?: never } + | { xx?: never; nx?: never } + ); /** * @see https://redis.io/commands/set From 5515f7c308e9f1156bba877e3145cfbc14c89ba3 Mon Sep 17 00:00:00 2001 From: chronark Date: Sat, 13 May 2023 15:41:53 +0200 Subject: [PATCH 3/4] fix(set.ts): make get option optional in SetCommandOptions type definition --- pkg/commands/set.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/commands/set.ts b/pkg/commands/set.ts index fe3b297d..84b639fb 100644 --- a/pkg/commands/set.ts +++ b/pkg/commands/set.ts @@ -1,7 +1,7 @@ import { Command, CommandOptions } from "./command.ts"; export type SetCommandOptions = - & { get: boolean } + & { get?: boolean } & ( | { ex: number; px?: never; exat?: never; pxat?: never; keepTtl?: never } | { ex?: never; px: number; exat?: never; pxat?: never; keepTtl?: never } From 8953bbb6b44aa33fa14210ee4873da76d0803112 Mon Sep 17 00:00:00 2001 From: chronark Date: Sat, 13 May 2023 15:57:00 +0200 Subject: [PATCH 4/4] test(set.test.ts): change nx flag to xx flag in get with xx test fix(version.ts): add newline at end of file in VERSION constant definition --- pkg/commands/set.test.ts | 5 ++--- version.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/commands/set.test.ts b/pkg/commands/set.test.ts index 1121a082..eea4abe2 100644 --- a/pkg/commands/set.test.ts +++ b/pkg/commands/set.test.ts @@ -100,15 +100,14 @@ Deno.test("get", async (t) => { }); }); -Deno.test("get with nx", async (t) => { +Deno.test("get with xx", async (t) => { await t.step("gets the old value", async () => { const key = newKey(); const old = randomID(); const value = randomID(); await new SetCommand([key, old]).exec(client); - const res = await new SetCommand([key, value, { get: true, nx: true }]) - .exec(client); + const res = await new SetCommand([key, value, { get: true, xx: true }]).exec(client); assertEquals(res, old); }); }); diff --git a/version.ts b/version.ts index 68d3d46f..f205ce2a 100644 --- a/version.ts +++ b/version.ts @@ -1 +1 @@ -export const VERSION = "development"; +export const VERSION = "development" \ No newline at end of file