diff --git a/CHANGELOG.md b/CHANGELOG.md index 655939fdd3..99329d1d7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ #### Changes +* Node: Added binary variant to HSCAN command ([#2240](https://github.com/valkey-io/valkey-glide/pull/2240)) * Node: Added binary variant to sorted set commands ([#2190](https://github.com/valkey-io/valkey-glide/pull/2190), [#2210](https://github.com/valkey-io/valkey-glide/pull/2210)) * Node: Added binary variant to HASH commands ([#2194](https://github.com/valkey-io/valkey-glide/pull/2194)) * Node: Added binary variant to server management commands ([#2179](https://github.com/valkey-io/valkey-glide/pull/2179)) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 8b394586a4..bb0e174eed 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -2106,11 +2106,14 @@ export class BaseClient { * ``` */ public async hscan( - key: string, + key: GlideString, cursor: string, - options?: HScanOptions, - ): Promise<[string, string[]]> { - return this.createWritePromise(createHScan(key, cursor, options)); + options?: HScanOptions & DecoderOption, + ): Promise<[string, GlideString[]]> { + return this.createWritePromise<[GlideString, GlideString[]]>( + createHScan(key, cursor, options), + options, + ).then((res) => [res[0].toString(), res[1]]); // convert cursor back to string } /** diff --git a/node/src/Commands.ts b/node/src/Commands.ts index 2d26178332..9f38141842 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -3667,7 +3667,7 @@ export function createHRandField( * @internal */ export function createHScan( - key: string, + key: GlideString, cursor: string, options?: HScanOptions, ): command_request.Command { diff --git a/node/src/Transaction.ts b/node/src/Transaction.ts index 87d86f8db3..2189d81064 100644 --- a/node/src/Transaction.ts +++ b/node/src/Transaction.ts @@ -1007,7 +1007,7 @@ export class BaseTransaction> { * where the value is at even indices and the value is at odd indices. * If `options.noValues` is set to `true`, the second element will only contain the fields without the values. */ - public hscan(key: string, cursor: string, options?: HScanOptions): T { + public hscan(key: GlideString, cursor: string, options?: HScanOptions): T { return this.addAndReturn(createHScan(key, cursor, options)); } diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index 28cd31d95b..eb1c4ba591 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -1451,8 +1451,8 @@ export function runBaseTests(config: { const resultValues: string[] = []; for (let i = 0; i < resultArray.length; i += 2) { - resultKeys.push(resultArray[i]); - resultValues.push(resultArray[i + 1]); + resultKeys.push(resultArray[i].toString()); + resultValues.push(resultArray[i + 1].toString()); } // Verify if all keys from charMap are in resultKeys @@ -1469,13 +1469,16 @@ export function runBaseTests(config: { // Test hscan with match result = await client.hscan(key1, initialCursor, { match: "a", + decoder: Decoder.Bytes, }); expect(result[resultCursorIndex]).toEqual(initialCursor); - expect(result[resultCollectionIndex]).toEqual(["a", "0"]); + expect(result[resultCollectionIndex]).toEqual( + ["a", "0"].map(Buffer.from), + ); // Set up testing data with the numberMap set to be used for the next set test keys and test results. - expect(await client.hset(key1, numberMap)).toEqual( + expect(await client.hset(Buffer.from(key1), numberMap)).toEqual( Object.keys(numberMap).length, ); @@ -1490,8 +1493,10 @@ export function runBaseTests(config: { const resultEntry = result[resultCollectionIndex]; for (let i = 0; i < resultEntry.length; i += 2) { - secondResultAllKeys.push(resultEntry[i]); - secondResultAllValues.push(resultEntry[i + 1]); + secondResultAllKeys.push(resultEntry[i].toString()); + secondResultAllValues.push( + resultEntry[i + 1].toString(), + ); } if (isFirstLoop) { @@ -1515,8 +1520,12 @@ export function runBaseTests(config: { ); for (let i = 0; i < secondResultEntry.length; i += 2) { - secondResultAllKeys.push(secondResultEntry[i]); - secondResultAllValues.push(secondResultEntry[i + 1]); + secondResultAllKeys.push( + secondResultEntry[i].toString(), + ); + secondResultAllValues.push( + secondResultEntry[i + 1].toString(), + ); } } while (resultCursor != initialCursor); // 0 is returned for the cursor of the last iteration.