Skip to content

Commit

Permalink
Decoder Options added for hget (valkey-io#2215)
Browse files Browse the repository at this point in the history
Signed-off-by: Prateek Kumar <[email protected]>
  • Loading branch information
prateek-kumar-improving authored Aug 30, 2024
1 parent 7e8525b commit 1f7e55f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
9 changes: 3 additions & 6 deletions node/src/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1649,8 +1649,7 @@ export class BaseClient {
*
* @param key - The key of the hash.
* @param field - The field in the hash stored at `key` to retrieve from the database.
* @param decoder - (Optional) {@link Decoder} type which defines how to handle the response.
* If not set, the {@link BaseClientConfiguration.defaultDecoder|default decoder} will be used.
* @param options - (Optional) See {@link DecoderOption}.
* @returns the value associated with `field`, or null when `field` is not present in the hash or `key` does not exist.
*
* @example
Expand All @@ -1671,11 +1670,9 @@ export class BaseClient {
public async hget(
key: GlideString,
field: GlideString,
decoder?: Decoder,
options?: DecoderOption,
): Promise<GlideString | null> {
return this.createWritePromise(createHGet(key, field), {
decoder: decoder,
});
return this.createWritePromise(createHGet(key, field), options);
}

/** Sets the specified fields to their respective values in the hash stored at `key`.
Expand Down
16 changes: 9 additions & 7 deletions node/tests/SharedTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1356,14 +1356,16 @@ export function runBaseTests(config: {
);

//hget with binary buffer
expect(await client.hget(key, field1, Decoder.Bytes)).toEqual(
valueEncoded,
);
expect(await client.hget(key, field2, Decoder.Bytes)).toEqual(
valueEncoded,
);
expect(
await client.hget(key, "nonExistingField", Decoder.Bytes),
await client.hget(key, field1, { decoder: Decoder.Bytes }),
).toEqual(valueEncoded);
expect(
await client.hget(key, field2, { decoder: Decoder.Bytes }),
).toEqual(valueEncoded);
expect(
await client.hget(key, "nonExistingField", {
decoder: Decoder.Bytes,
}),
).toEqual(null);
}, protocol);
},
Expand Down

0 comments on commit 1f7e55f

Please sign in to comment.