diff --git a/CHANGELOG.md b/CHANGELOG.md index 730c391284..b6305dafe4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ #### Changes +* Node: Added binary variant to HYPERLOGLOG commands ([#2176](https://github.com/valkey-io/valkey-glide/pull/2176)) * Node: Added FUNCTION DUMP and FUNCTION RESTORE commands (transaction) ([#2173](https://github.com/valkey-io/valkey-glide/pull/2173)) * Node: Added FUNCTION DUMP and FUNCTION RESTORE commands ([#2129](https://github.com/valkey-io/valkey-glide/pull/2129), [#2173](https://github.com/valkey-io/valkey-glide/pull/2173)) * Node: Added ZUNIONSTORE command ([#2145](https://github.com/valkey-io/valkey-glide/pull/2145)) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 9ece045d89..a0894ea191 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -5493,7 +5493,10 @@ export class BaseClient { * console.log(result); // Output: 1 - Indicates that a new empty data structure was created * ``` */ - public async pfadd(key: string, elements: string[]): Promise { + public async pfadd( + key: GlideString, + elements: GlideString[], + ): Promise { return this.createWritePromise(createPfAdd(key, elements)); } @@ -5512,7 +5515,7 @@ export class BaseClient { * console.log(result); // Output: 4 - The approximated cardinality of the union of "hll_1" and "hll_2" * ``` */ - public async pfcount(keys: string[]): Promise { + public async pfcount(keys: GlideString[]): Promise { return this.createWritePromise(createPfCount(keys)); } @@ -5538,10 +5541,12 @@ export class BaseClient { * ``` */ public async pfmerge( - destination: string, - sourceKeys: string[], + destination: GlideString, + sourceKeys: GlideString[], ): Promise<"OK"> { - return this.createWritePromise(createPfMerge(destination, sourceKeys)); + return this.createWritePromise(createPfMerge(destination, sourceKeys), { + decoder: Decoder.String, + }); } /** Returns the internal encoding for the Valkey object stored at `key`. diff --git a/node/src/Commands.ts b/node/src/Commands.ts index eadbe48175..3d65bf6cd6 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -2826,8 +2826,8 @@ export function createRenameNX( * @internal */ export function createPfAdd( - key: string, - elements: string[], + key: GlideString, + elements: GlideString[], ): command_request.Command { const args = [key, ...elements]; return createCommand(RequestType.PfAdd, args); @@ -2836,7 +2836,7 @@ export function createPfAdd( /** * @internal */ -export function createPfCount(keys: string[]): command_request.Command { +export function createPfCount(keys: GlideString[]): command_request.Command { return createCommand(RequestType.PfCount, keys); } @@ -2844,8 +2844,8 @@ export function createPfCount(keys: string[]): command_request.Command { * @internal */ export function createPfMerge( - destination: string, - sourceKey: string[], + destination: GlideString, + sourceKey: GlideString[], ): command_request.Command { return createCommand(RequestType.PfMerge, [destination, ...sourceKey]); } diff --git a/node/src/Transaction.ts b/node/src/Transaction.ts index 212d40f670..0ee31d892f 100644 --- a/node/src/Transaction.ts +++ b/node/src/Transaction.ts @@ -219,6 +219,7 @@ import { createXGroupCreateConsumer, createXGroupDelConsumer, createXGroupDestroy, + createXGroupSetid, createXInfoConsumers, createXInfoGroups, createXInfoStream, @@ -259,7 +260,6 @@ import { createZScore, createZUnion, createZUnionStore, - createXGroupSetid, } from "./Commands"; import { command_request } from "./ProtobufMessage"; @@ -3017,7 +3017,7 @@ export class BaseTransaction> { * Command Response - If the HyperLogLog is newly created, or if the HyperLogLog approximated cardinality is * altered, then returns `1`. Otherwise, returns `0`. */ - public pfadd(key: string, elements: string[]): T { + public pfadd(key: GlideString, elements: GlideString[]): T { return this.addAndReturn(createPfAdd(key, elements)); } @@ -3030,7 +3030,7 @@ export class BaseTransaction> { * Command Response - The approximated cardinality of given HyperLogLog data structures. * The cardinality of a key that does not exist is `0`. */ - public pfcount(keys: string[]): T { + public pfcount(keys: GlideString[]): T { return this.addAndReturn(createPfCount(keys)); } @@ -3044,7 +3044,7 @@ export class BaseTransaction> { * @param sourceKeys - The keys of the HyperLogLog structures to be merged. * Command Response - A simple "OK" response. */ - public pfmerge(destination: string, sourceKeys: string[]): T { + public pfmerge(destination: GlideString, sourceKeys: GlideString[]): T { return this.addAndReturn(createPfMerge(destination, sourceKeys)); } diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index b157452d04..d2b63bb502 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -6976,7 +6976,9 @@ export function runBaseTests(config: { const key = uuidv4(); expect(await client.pfadd(key, [])).toEqual(1); expect(await client.pfadd(key, ["one", "two"])).toEqual(1); - expect(await client.pfadd(key, ["two"])).toEqual(0); + expect( + await client.pfadd(Buffer.from(key), [Buffer.from("two")]), + ).toEqual(0); expect(await client.pfadd(key, [])).toEqual(0); // key exists, but it is not a HyperLogLog @@ -7000,7 +7002,7 @@ export function runBaseTests(config: { expect(await client.pfadd(key1, ["a", "b", "c"])).toEqual(1); expect(await client.pfadd(key2, ["b", "c", "d"])).toEqual(1); expect(await client.pfcount([key1])).toEqual(3); - expect(await client.pfcount([key2])).toEqual(3); + expect(await client.pfcount([Buffer.from(key2)])).toEqual(3); expect(await client.pfcount([key1, key2])).toEqual(4); expect( await client.pfcount([key1, key2, nonExistingKey]), @@ -7041,11 +7043,15 @@ export function runBaseTests(config: { expect(await client.pfadd(key2, ["b", "c", "d"])).toEqual(1); // merge into new HyperLogLog data set - expect(await client.pfmerge(key3, [key1, key2])).toEqual("OK"); + expect( + await client.pfmerge(Buffer.from(key3), [key1, key2]), + ).toEqual("OK"); expect(await client.pfcount([key3])).toEqual(4); // merge into existing HyperLogLog data set - expect(await client.pfmerge(key1, [key2])).toEqual("OK"); + expect(await client.pfmerge(key1, [Buffer.from(key2)])).toEqual( + "OK", + ); expect(await client.pfcount([key1])).toEqual(4); // non-existing source key