From 36833d5660ef35a6f74b056001cfac4cb64c2e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fahreddin=20=C3=96zcan?= Date: Fri, 27 Oct 2023 16:36:13 +0300 Subject: [PATCH 1/5] add hll commands: pfadd, pfcount, pfmerge --- pkg/commands/pfadd.test.ts | 122 +++++++++++++++++++++++++++++++++++ pkg/commands/pfadd.ts | 13 ++++ pkg/commands/pfcount.test.ts | 69 ++++++++++++++++++++ pkg/commands/pfcount.ts | 13 ++++ pkg/commands/pfmerge.test.ts | 95 +++++++++++++++++++++++++++ pkg/commands/pfmerge.ts | 13 ++++ 6 files changed, 325 insertions(+) create mode 100644 pkg/commands/pfadd.test.ts create mode 100644 pkg/commands/pfadd.ts create mode 100644 pkg/commands/pfcount.test.ts create mode 100644 pkg/commands/pfcount.ts create mode 100644 pkg/commands/pfmerge.test.ts create mode 100644 pkg/commands/pfmerge.ts diff --git a/pkg/commands/pfadd.test.ts b/pkg/commands/pfadd.test.ts new file mode 100644 index 00000000..5fb0ff69 --- /dev/null +++ b/pkg/commands/pfadd.test.ts @@ -0,0 +1,122 @@ +import { newHttpClient, randomID, keygen } from "../test-utils.ts"; + +import { afterEach, expect, test } from "bun:test"; + +import { PfAddCommand } from "./pfadd.ts"; +import { PfCountCommand } from "./pfcount.ts"; +import { PfMergeCommand } from "./pfmerge.ts"; + +const client = newHttpClient(); + +const { newKey, cleanup } = keygen(); +afterEach(cleanup); + +test("adding multiple elements at once", () => { + const key = newKey(); + test("returns 1 if the HLL was modified", async () => { + const value1 = randomID(); + const value2 = randomID(); + const value3 = randomID(); + + const res = await new PfAddCommand([key, value1, value2, value3]).exec( + client + ); + expect(res, 1, "Expected the HLL to be modified when adding elements"); + }); + test("returns 3 as a cardinality of the HLL", async () => { + const res = await new PfCountCommand([key]).exec(client); + + expect(res, 3, "Expected the HLL to have cardinality of 3"); + }); +}); + +test("inserting the same element multiple times", () => { + const key = newKey(); + const value1 = randomID(); + const value2 = randomID(); + + test("returns 1 if the HLL was modified with repeated elements", async () => { + const resInsert = await new PfAddCommand([ + key, + value1, + value1, + value2, + value2, + ]).exec(client); + expect( + resInsert, + 1, + "Expected the HLL to be modified when adding repeated elements" + ); + }); + + test("returns 2 as a cardinality of the HLL with repeated elements", async () => { + const resCount = await new PfCountCommand([key]).exec(client); + expect(resCount, 2, "Expected the HLL to have cardinality of 2"); + }); +}); + +test("adding the same strings on different lines doesn't modify the HLL", () => { + const key = newKey(); + + const value1 = randomID(); + const value2 = randomID(); + const value3 = randomID(); + + test("modifies the HLL on the first insertion of strings", async () => { + const res = await new PfAddCommand([key, value1, value2, value3]).exec( + client + ); + expect(res, 1, "Expected the HLL to be modified on the first insertion"); + }); + + test("doesn't modify the HLL on the second insertion of same strings", async () => { + const res = await new PfAddCommand([key, value1, value2, value3]).exec( + client + ); + expect( + res, + 0, + "Expected the HLL not to be modified on the second insertion" + ); + }); + + test("doesn't modify the HLL on the third insertion with a subset of strings", async () => { + const res = await new PfAddCommand([key, value1, value2]).exec(client); + expect( + res, + 0, + "Expected the HLL not to be modified on the third insertion" + ); + }); +}); + +test("merge HLLs with overlapping values and count", () => { + const key1 = newKey(); + const key2 = newKey(); + const mergedKey = newKey(); + const value1 = randomID(); + const value2 = randomID(); + const value3 = randomID(); + const value4 = randomID(); + + test("insert overlapping strings into two HLLs", async () => { + await new PfAddCommand([key1, value1, value2, value3]).exec(client); + const res = await new PfAddCommand([key2, value3, value4]).exec(client); + expect(res, 1, "Expected the HLL to be modified with overlapping value"); + }); + + test("merge the two HLLs with overlapping values", async () => { + const res = await new PfMergeCommand([mergedKey, key1, key2]).exec(client); + expect(res, "OK", "Expected the HLLs to be merged"); + }); + + test("count merged overlapping HLLs", async () => { + const count = await new PfCountCommand([mergedKey]).exec(client); + expect( + count, + 4, + "Expected the merged HLL to have a cardinality of 4 after overlapping values were merged" + ); + }); +}); diff --git a/pkg/commands/pfadd.ts b/pkg/commands/pfadd.ts new file mode 100644 index 00000000..ff141460 --- /dev/null +++ b/pkg/commands/pfadd.ts @@ -0,0 +1,13 @@ +import { Command, CommandOptions } from "./command.ts"; + +/** + * @see https://redis.io/commands/pfadd + */ +export class PfAddCommand extends Command { + constructor( + cmd: [key: string, ...members: TData[]], + opts?: CommandOptions + ) { + super(["pfadd", ...cmd], opts); + } +} diff --git a/pkg/commands/pfcount.test.ts b/pkg/commands/pfcount.test.ts new file mode 100644 index 00000000..4396f942 --- /dev/null +++ b/pkg/commands/pfcount.test.ts @@ -0,0 +1,69 @@ +import { newHttpClient, keygen, randomID } from "../test-utils.ts"; +import { afterEach, expect, test } from "bun:test"; + +import { PfAddCommand } from "./pfadd.ts"; +import { PfCountCommand } from "./pfcount.ts"; + +const client = newHttpClient(); + +const { newKey, cleanup } = keygen(); +afterEach(cleanup); + +test("simple cardinality check", () => { + const key = newKey(); + + test("insert multiple unique strings", async () => { + const value1 = randomID(); + const value2 = randomID(); + const value3 = randomID(); + const res = await new PfAddCommand([key, value1, value2, value3]).exec( + client + ); + expect(res, 1, "Expected the HLL to be modified"); + }); + + test("check cardinality", async () => { + const count = await new PfCountCommand([key]).exec(client); + expect(count, 3, "Expected the HLL to have cardinality of 3"); + }); +}); + +test("multiple keys cardinality check", () => { + const key1 = newKey(); + const key2 = newKey(); + const value1 = randomID(); + const value2 = randomID(); + const value3 = randomID(); + const value4 = randomID(); + const value5 = randomID(); + + test("insert unique strings into two HLLs", async () => { + await new PfAddCommand([key1, value1, value2]).exec(client); + await new PfAddCommand([key2, value3, value4, value5]).exec(client); + }); + + test("check combined cardinality", async () => { + const count = await new PfCountCommand([key1, key2]).exec(client); + expect(count, 5, "Expected the combined HLLs to have cardinality of 5"); + }); +}); + +test("cardinality after repeated insertions", () => { + const key = newKey(); + const value1 = randomID(); + const value2 = randomID(); + + test("insert strings and then re-insert them", async () => { + await new PfAddCommand([key, value1, value2]).exec(client); + await new PfAddCommand([key, value1, value2]).exec(client); + }); + + test("check cardinality after repeated insertions", async () => { + const count = await new PfCountCommand([key]).exec(client); + expect( + count, + 2, + "Expected the HLL to have cardinality of 2 even after repeated insertions" + ); + }); +}); diff --git a/pkg/commands/pfcount.ts b/pkg/commands/pfcount.ts new file mode 100644 index 00000000..1564d6dd --- /dev/null +++ b/pkg/commands/pfcount.ts @@ -0,0 +1,13 @@ +import { Command, CommandOptions } from "./command.ts"; + +/** + * @see https://redis.io/commands/pfcount + */ +export class PfCountCommand extends Command { + constructor( + cmd: [key: string, ...keys: string[]], + opts?: CommandOptions + ) { + super(["pfcount", ...cmd], opts); + } +} diff --git a/pkg/commands/pfmerge.test.ts b/pkg/commands/pfmerge.test.ts new file mode 100644 index 00000000..a9006f1c --- /dev/null +++ b/pkg/commands/pfmerge.test.ts @@ -0,0 +1,95 @@ +import { newHttpClient, randomID, keygen } from "../test-utils.ts"; + +import { afterEach, expect, test } from "bun:test"; + +import { PfAddCommand } from "./pfadd.ts"; +import { PfCountCommand } from "./pfcount.ts"; +import { PfMergeCommand } from "./pfmerge.ts"; + +const client = newHttpClient(); + +const { newKey, cleanup } = keygen(); + +afterEach(cleanup); + +test("merge HLLs with distinct values and count", () => { + const key1 = newKey(); + const key2 = newKey(); + const mergedKey = newKey(); + const value1 = randomID(); + const value2 = randomID(); + const value3 = randomID(); + const value4 = randomID(); + + test("insert distinct strings into two HLLs", async () => { + await new PfAddCommand([key1, value1, value2]).exec(client); + const res = await new PfAddCommand([key2, value3, value4]).exec(client); + expect(res, 1, "Expected the HLL to be modified with distinct values"); + }); + + test("merge the two HLLs with distinct values", async () => { + const res = await new PfMergeCommand([mergedKey, key1, key2]).exec(client); + expect(res, "OK", "Expected the HLLs with distinct values to be merged"); + }); + + test("count merged distinct HLLs", async () => { + const count = await new PfCountCommand([mergedKey]).exec(client); + expect( + count, + 4, + "Expected the merged HLL to have a cardinality of 4 with distinct values" + ); + }); +}); + +test("merge HLL with an empty HLL", () => { + const key = newKey(); + const emptyKey = newKey(); + const mergedKey = newKey(); + const value1 = randomID(); + + test("insert a string into an HLL and keep another HLL empty", async () => { + const res = await new PfAddCommand([key, value1]).exec(client); + expect(res, 1, "Expected the HLL to be modified"); + }); + + test("merge the HLL with an empty HLL", async () => { + const res = await new PfMergeCommand([mergedKey, key, emptyKey]).exec( + client + ); + expect(res, "OK", "Expected the HLL to be merged with an empty HLL"); + }); + + test("count after merging with empty HLL", async () => { + const count = await new PfCountCommand([mergedKey]).exec(client); + expect( + count, + 1, + "Expected the merged HLL to have a cardinality of 1 after merging with empty HLL" + ); + }); +}); + +test("merge two empty HLLs", () => { + const emptyKey1 = newKey(); + const emptyKey2 = newKey(); + const mergedKey = newKey(); + + test("merge two empty HLLs", async () => { + const res = await new PfMergeCommand([ + mergedKey, + emptyKey1, + emptyKey2, + ]).exec(client); + expect(res, "OK", "Expected the two empty HLLs to be merged"); + }); + + test("count merged empty HLLs", async () => { + const count = await new PfCountCommand([mergedKey]).exec(client); + expect( + count, + 0, + "Expected the merged HLL to have a cardinality of 0 after merging two empty HLLs" + ); + }); +}); diff --git a/pkg/commands/pfmerge.ts b/pkg/commands/pfmerge.ts new file mode 100644 index 00000000..5ca57a03 --- /dev/null +++ b/pkg/commands/pfmerge.ts @@ -0,0 +1,13 @@ +import { Command, CommandOptions } from "./command.ts"; + +/** + * @see https://redis.io/commands/pfmerge + */ +export class PfMergeCommand extends Command<"OK", "OK"> { + constructor( + cmd: [destination_key: string, source_key: string, ...keys: string[]], + opts?: CommandOptions<"OK", "OK"> + ) { + super(["pfmerge", ...cmd], opts); + } +} From 6bbdd3d89fa441a44af005b2de0ae9d9a212b322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fahreddin=20=C3=96zcan?= Date: Thu, 2 Nov 2023 16:32:07 +0300 Subject: [PATCH 2/5] convert tests for bun --- pkg/commands/pfadd.test.ts | 85 +++++++++++++----------------------- pkg/commands/pfcount.test.ts | 37 +++++----------- pkg/commands/pfmerge.test.ts | 64 ++++++++++----------------- 3 files changed, 64 insertions(+), 122 deletions(-) diff --git a/pkg/commands/pfadd.test.ts b/pkg/commands/pfadd.test.ts index 5fb0ff69..1e35e6ee 100644 --- a/pkg/commands/pfadd.test.ts +++ b/pkg/commands/pfadd.test.ts @@ -1,6 +1,6 @@ import { newHttpClient, randomID, keygen } from "../test-utils.ts"; -import { afterEach, expect, test } from "bun:test"; +import { afterEach, describe, expect, test } from "bun:test"; import { PfAddCommand } from "./pfadd.ts"; import { PfCountCommand } from "./pfcount.ts"; @@ -11,9 +11,9 @@ const client = newHttpClient(); const { newKey, cleanup } = keygen(); afterEach(cleanup); -test("adding multiple elements at once", () => { +describe("adding multiple elements at once", () => { const key = newKey(); - test("returns 1 if the HLL was modified", async () => { + test("returns 1 if successful, returns 3 as the cardinality", async () => { const value1 = randomID(); const value2 = randomID(); const value3 = randomID(); @@ -21,21 +21,20 @@ test("adding multiple elements at once", () => { const res = await new PfAddCommand([key, value1, value2, value3]).exec( client ); - expect(res, 1, "Expected the HLL to be modified when adding elements"); - }); - test("returns 3 as a cardinality of the HLL", async () => { - const res = await new PfCountCommand([key]).exec(client); + expect(res).toBe(1); + + const res2 = await new PfCountCommand([key]).exec(client); - expect(res, 3, "Expected the HLL to have cardinality of 3"); + expect(res2).toBe(3); }); }); -test("inserting the same element multiple times", () => { +describe("inserting the same element multiple times", () => { const key = newKey(); const value1 = randomID(); const value2 = randomID(); - test("returns 1 if the HLL was modified with repeated elements", async () => { + test("modified succesfully and returned correct cardinality for repeated elements", async () => { const resInsert = await new PfAddCommand([ key, value1, @@ -43,20 +42,14 @@ test("inserting the same element multiple times", () => { value2, value2, ]).exec(client); - expect( - resInsert, - 1, - "Expected the HLL to be modified when adding repeated elements" - ); - }); + expect(resInsert).toBe(1); - test("returns 2 as a cardinality of the HLL with repeated elements", async () => { const resCount = await new PfCountCommand([key]).exec(client); - expect(resCount, 2, "Expected the HLL to have cardinality of 2"); + expect(resCount).toBe(2); }); }); -test("adding the same strings on different lines doesn't modify the HLL", () => { +describe("adding the same strings on different lines doesn't modify the HLL", () => { const key = newKey(); const value1 = randomID(); @@ -64,34 +57,22 @@ test("adding the same strings on different lines doesn't modify the HLL", () => const value3 = randomID(); test("modifies the HLL on the first insertion of strings", async () => { - const res = await new PfAddCommand([key, value1, value2, value3]).exec( + const resAdd = await new PfAddCommand([key, value1, value2, value3]).exec( client ); - expect(res, 1, "Expected the HLL to be modified on the first insertion"); - }); - - test("doesn't modify the HLL on the second insertion of same strings", async () => { - const res = await new PfAddCommand([key, value1, value2, value3]).exec( - client - ); - expect( - res, - 0, - "Expected the HLL not to be modified on the second insertion" - ); - }); + expect(resAdd).toBe(1); - test("doesn't modify the HLL on the third insertion with a subset of strings", async () => { - const res = await new PfAddCommand([key, value1, value2]).exec(client); - expect( - res, - 0, - "Expected the HLL not to be modified on the third insertion" - ); + const resAddDuplicate = await new PfAddCommand([ + key, + value1, + value2, + value3, + ]).exec(client); + expect(resAddDuplicate).toBe(0); }); }); -test("merge HLLs with overlapping values and count", () => { +describe("merge HLLs with overlapping values and count", () => { const key1 = newKey(); const key2 = newKey(); const mergedKey = newKey(); @@ -102,21 +83,15 @@ test("merge HLLs with overlapping values and count", () => { test("insert overlapping strings into two HLLs", async () => { await new PfAddCommand([key1, value1, value2, value3]).exec(client); - const res = await new PfAddCommand([key2, value3, value4]).exec(client); - expect(res, 1, "Expected the HLL to be modified with overlapping value"); - }); - - test("merge the two HLLs with overlapping values", async () => { - const res = await new PfMergeCommand([mergedKey, key1, key2]).exec(client); - expect(res, "OK", "Expected the HLLs to be merged"); - }); + const resAdd = await new PfAddCommand([key2, value3, value4]).exec(client); + expect(resAdd).toBe(1); - test("count merged overlapping HLLs", async () => { - const count = await new PfCountCommand([mergedKey]).exec(client); - expect( - count, - 4, - "Expected the merged HLL to have a cardinality of 4 after overlapping values were merged" + const resMerge = await new PfMergeCommand([mergedKey, key1, key2]).exec( + client ); + expect(resMerge).toBe("OK"); + + const resCount = await new PfCountCommand([mergedKey]).exec(client); + expect(resCount).toBe(4); }); }); diff --git a/pkg/commands/pfcount.test.ts b/pkg/commands/pfcount.test.ts index 4396f942..e9029b0d 100644 --- a/pkg/commands/pfcount.test.ts +++ b/pkg/commands/pfcount.test.ts @@ -1,5 +1,5 @@ import { newHttpClient, keygen, randomID } from "../test-utils.ts"; -import { afterEach, expect, test } from "bun:test"; +import { afterEach, expect, test, describe } from "bun:test"; import { PfAddCommand } from "./pfadd.ts"; import { PfCountCommand } from "./pfcount.ts"; @@ -9,26 +9,21 @@ const client = newHttpClient(); const { newKey, cleanup } = keygen(); afterEach(cleanup); -test("simple cardinality check", () => { +describe("simple cardinality check", () => { const key = newKey(); test("insert multiple unique strings", async () => { const value1 = randomID(); const value2 = randomID(); const value3 = randomID(); - const res = await new PfAddCommand([key, value1, value2, value3]).exec( - client - ); - expect(res, 1, "Expected the HLL to be modified"); - }); + await new PfAddCommand([key, value1, value2, value3]).exec(client); - test("check cardinality", async () => { - const count = await new PfCountCommand([key]).exec(client); - expect(count, 3, "Expected the HLL to have cardinality of 3"); + const resCount = await new PfCountCommand([key]).exec(client); + expect(resCount).toBe(3); }); }); -test("multiple keys cardinality check", () => { +describe("multiple keys cardinality check", () => { const key1 = newKey(); const key2 = newKey(); const value1 = randomID(); @@ -39,16 +34,14 @@ test("multiple keys cardinality check", () => { test("insert unique strings into two HLLs", async () => { await new PfAddCommand([key1, value1, value2]).exec(client); - await new PfAddCommand([key2, value3, value4, value5]).exec(client); - }); + await new PfAddCommand([key2, value3, value4]).exec(client); - test("check combined cardinality", async () => { - const count = await new PfCountCommand([key1, key2]).exec(client); - expect(count, 5, "Expected the combined HLLs to have cardinality of 5"); + const resCount = await new PfCountCommand([key1, key2]).exec(client); + expect(resCount).toBe(4); }); }); -test("cardinality after repeated insertions", () => { +describe("cardinality after repeated insertions", () => { const key = newKey(); const value1 = randomID(); const value2 = randomID(); @@ -56,14 +49,8 @@ test("cardinality after repeated insertions", () => { test("insert strings and then re-insert them", async () => { await new PfAddCommand([key, value1, value2]).exec(client); await new PfAddCommand([key, value1, value2]).exec(client); - }); - test("check cardinality after repeated insertions", async () => { - const count = await new PfCountCommand([key]).exec(client); - expect( - count, - 2, - "Expected the HLL to have cardinality of 2 even after repeated insertions" - ); + const resCount = await new PfCountCommand([key]).exec(client); + expect(resCount).toBe(2); }); }); diff --git a/pkg/commands/pfmerge.test.ts b/pkg/commands/pfmerge.test.ts index a9006f1c..92ae9fcd 100644 --- a/pkg/commands/pfmerge.test.ts +++ b/pkg/commands/pfmerge.test.ts @@ -1,6 +1,6 @@ import { newHttpClient, randomID, keygen } from "../test-utils.ts"; -import { afterEach, expect, test } from "bun:test"; +import { afterEach, expect, test, describe } from "bun:test"; import { PfAddCommand } from "./pfadd.ts"; import { PfCountCommand } from "./pfcount.ts"; @@ -12,7 +12,7 @@ const { newKey, cleanup } = keygen(); afterEach(cleanup); -test("merge HLLs with distinct values and count", () => { +describe("merge HLLs with distinct values and count", () => { const key1 = newKey(); const key2 = newKey(); const mergedKey = newKey(); @@ -23,73 +23,53 @@ test("merge HLLs with distinct values and count", () => { test("insert distinct strings into two HLLs", async () => { await new PfAddCommand([key1, value1, value2]).exec(client); - const res = await new PfAddCommand([key2, value3, value4]).exec(client); - expect(res, 1, "Expected the HLL to be modified with distinct values"); - }); - - test("merge the two HLLs with distinct values", async () => { - const res = await new PfMergeCommand([mergedKey, key1, key2]).exec(client); - expect(res, "OK", "Expected the HLLs with distinct values to be merged"); - }); + const resAdd = await new PfAddCommand([key2, value3, value4]).exec(client); + expect(resAdd).toBe(1); - test("count merged distinct HLLs", async () => { - const count = await new PfCountCommand([mergedKey]).exec(client); - expect( - count, - 4, - "Expected the merged HLL to have a cardinality of 4 with distinct values" + const resMerge = await new PfMergeCommand([mergedKey, key1, key2]).exec( + client ); + expect(resMerge).toBe("OK"); + + const resCount = await new PfCountCommand([mergedKey]).exec(client); + expect(resCount).toBe(4); }); }); -test("merge HLL with an empty HLL", () => { +describe("merge HLL with an empty HLL", () => { const key = newKey(); const emptyKey = newKey(); const mergedKey = newKey(); const value1 = randomID(); test("insert a string into an HLL and keep another HLL empty", async () => { - const res = await new PfAddCommand([key, value1]).exec(client); - expect(res, 1, "Expected the HLL to be modified"); - }); + const resAdd = await new PfAddCommand([key, value1]).exec(client); + expect(resAdd).toBe(1); - test("merge the HLL with an empty HLL", async () => { - const res = await new PfMergeCommand([mergedKey, key, emptyKey]).exec( + const resMerge = await new PfMergeCommand([mergedKey, key, emptyKey]).exec( client ); - expect(res, "OK", "Expected the HLL to be merged with an empty HLL"); - }); + expect(resMerge).toBe("OK"); - test("count after merging with empty HLL", async () => { - const count = await new PfCountCommand([mergedKey]).exec(client); - expect( - count, - 1, - "Expected the merged HLL to have a cardinality of 1 after merging with empty HLL" - ); + const resCount = await new PfCountCommand([mergedKey]).exec(client); + expect(resCount).toBe(1); }); }); -test("merge two empty HLLs", () => { +describe("merge two empty HLLs", () => { const emptyKey1 = newKey(); const emptyKey2 = newKey(); const mergedKey = newKey(); test("merge two empty HLLs", async () => { - const res = await new PfMergeCommand([ + const resMerge = await new PfMergeCommand([ mergedKey, emptyKey1, emptyKey2, ]).exec(client); - expect(res, "OK", "Expected the two empty HLLs to be merged"); - }); + expect(resMerge).toBe("OK"); - test("count merged empty HLLs", async () => { - const count = await new PfCountCommand([mergedKey]).exec(client); - expect( - count, - 0, - "Expected the merged HLL to have a cardinality of 0 after merging two empty HLLs" - ); + const resCount = await new PfCountCommand([mergedKey]).exec(client); + expect(resCount).toBe(0); }); }); From 94046c5d522bdf14ce45af7aae9f5a41cec3c3f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fahreddin=20=C3=96zcan?= Date: Thu, 2 Nov 2023 16:50:41 +0300 Subject: [PATCH 3/5] type fixes --- pkg/commands/pfadd.ts | 2 +- pkg/commands/pfcount.ts | 2 +- pkg/commands/pfmerge.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/commands/pfadd.ts b/pkg/commands/pfadd.ts index ff141460..f5d2faea 100644 --- a/pkg/commands/pfadd.ts +++ b/pkg/commands/pfadd.ts @@ -5,7 +5,7 @@ import { Command, CommandOptions } from "./command.ts"; */ export class PfAddCommand extends Command { constructor( - cmd: [key: string, ...members: TData[]], + cmd: [string, ...(TData[] | TData[])], opts?: CommandOptions ) { super(["pfadd", ...cmd], opts); diff --git a/pkg/commands/pfcount.ts b/pkg/commands/pfcount.ts index 1564d6dd..ff148e38 100644 --- a/pkg/commands/pfcount.ts +++ b/pkg/commands/pfcount.ts @@ -5,7 +5,7 @@ import { Command, CommandOptions } from "./command.ts"; */ export class PfCountCommand extends Command { constructor( - cmd: [key: string, ...keys: string[]], + cmd: [string, ...(string[] | string[])], opts?: CommandOptions ) { super(["pfcount", ...cmd], opts); diff --git a/pkg/commands/pfmerge.ts b/pkg/commands/pfmerge.ts index 5ca57a03..d8e2555c 100644 --- a/pkg/commands/pfmerge.ts +++ b/pkg/commands/pfmerge.ts @@ -5,7 +5,7 @@ import { Command, CommandOptions } from "./command.ts"; */ export class PfMergeCommand extends Command<"OK", "OK"> { constructor( - cmd: [destination_key: string, source_key: string, ...keys: string[]], + cmd: [destination_key: string, ...(string[] | string[])], opts?: CommandOptions<"OK", "OK"> ) { super(["pfmerge", ...cmd], opts); From 500f5ad915fbdc87a0430f2fdc0c687dcc39b190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fahreddin=20=C3=96zcan?= Date: Thu, 9 Nov 2023 13:43:04 +0300 Subject: [PATCH 4/5] DX-21: pipeline & redis exports --- pkg/commands/mod.ts | 3 +++ pkg/pipeline.ts | 21 +++++++++++++++++++++ pkg/redis.ts | 21 +++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/pkg/commands/mod.ts b/pkg/commands/mod.ts index fc3be0e1..d7af8779 100644 --- a/pkg/commands/mod.ts +++ b/pkg/commands/mod.ts @@ -86,6 +86,9 @@ export * from "./msetnx"; export * from "./persist"; export * from "./pexpire"; export * from "./pexpireat"; +export * from './pfadd'; +export * from './pfcount'; +export * from './pfmerge'; export * from "./ping"; export * from "./psetex"; export * from "./pttl"; diff --git a/pkg/pipeline.ts b/pkg/pipeline.ts index dfbc24f2..bc3736b5 100644 --- a/pkg/pipeline.ts +++ b/pkg/pipeline.ts @@ -88,6 +88,9 @@ import { PExpireCommand, PSetEXCommand, PTtlCommand, + PfAddCommand, + PfCountCommand, + PfMergeCommand, PersistCommand, PingCommand, PublishCommand, @@ -657,6 +660,24 @@ export class Pipeline[] = []> { pexpireat = (...args: CommandArgs) => this.chain(new PExpireAtCommand(args, this.commandOptions)); + /** + * @see https://redis.io/commands/pfadd + */ + pfadd = (...args: CommandArgs) => + new PfAddCommand(args, this.commandOptions).exec(this.client); + + /** + * @see https://redis.io/commands/pfcount + */ + pfcount = (...args: CommandArgs) => + new PfCountCommand(args, this.commandOptions).exec(this.client); + + /** + * @see https://redis.io/commands/pfmerge + */ + pfmerge = (...args: CommandArgs) => + new PfMergeCommand(args, this.commandOptions).exec(this.client); + /** * @see https://redis.io/commands/ping */ diff --git a/pkg/redis.ts b/pkg/redis.ts index e70b5bd9..17403770 100644 --- a/pkg/redis.ts +++ b/pkg/redis.ts @@ -88,6 +88,9 @@ import { PExpireCommand, PSetEXCommand, PTtlCommand, + PfAddCommand, + PfCountCommand, + PfMergeCommand, PersistCommand, PingCommand, PublishCommand, @@ -803,6 +806,24 @@ export class Redis { pexpireat = (...args: CommandArgs) => new PExpireAtCommand(args, this.opts).exec(this.client); + /** + * @see https://redis.io/commands/pfadd + */ + pfadd = (...args: CommandArgs) => + new PfAddCommand(args, this.opts).exec(this.client); + + /** + * @see https://redis.io/commands/pfcount + */ + pfcount = (...args: CommandArgs) => + new PfCountCommand(args, this.opts).exec(this.client); + + /** + * @see https://redis.io/commands/pfmerge + */ + pfmerge = (...args: CommandArgs) => + new PfMergeCommand(args, this.opts).exec(this.client); + /** * @see https://redis.io/commands/ping */ From a8e954c4cdfcb7c4b398885f2980247bc3cbf2f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fahreddin=20=C3=96zcan?= Date: Thu, 9 Nov 2023 13:51:52 +0300 Subject: [PATCH 5/5] DX-21: fix pipeline --- pkg/pipeline.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/pipeline.ts b/pkg/pipeline.ts index bc3736b5..841b4fd9 100644 --- a/pkg/pipeline.ts +++ b/pkg/pipeline.ts @@ -663,20 +663,20 @@ export class Pipeline[] = []> { /** * @see https://redis.io/commands/pfadd */ - pfadd = (...args: CommandArgs) => - new PfAddCommand(args, this.commandOptions).exec(this.client); + pfadd = (...args: CommandArgs) => + this.chain(new PfAddCommand(args, this.commandOptions)); /** * @see https://redis.io/commands/pfcount */ pfcount = (...args: CommandArgs) => - new PfCountCommand(args, this.commandOptions).exec(this.client); + this.chain(new PfCountCommand(args, this.commandOptions)); /** * @see https://redis.io/commands/pfmerge */ pfmerge = (...args: CommandArgs) => - new PfMergeCommand(args, this.commandOptions).exec(this.client); + this.chain(new PfMergeCommand(args, this.commandOptions)); /** * @see https://redis.io/commands/ping