diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 450eb9f774..68156ef365 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -2030,7 +2030,10 @@ export class BaseClient { * console.log(result); // Output: 1 - Indicates that a new list was created with one element * ``` */ - public async lpush(key: string, elements: string[]): Promise { + public async lpush( + key: GlideString, + elements: GlideString[], + ): Promise { return this.createWritePromise(createLPush(key, elements)); } @@ -2059,6 +2062,8 @@ export class BaseClient { * @see {@link https://valkey.io/commands/lpop/|valkey.io} for details. * * @param key - The key of the list. + * @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. * @returns The value of the first element. * If `key` does not exist null will be returned. * @@ -2076,8 +2081,11 @@ export class BaseClient { * console.log(result); // Output: null * ``` */ - public async lpop(key: string): Promise { - return this.createWritePromise(createLPop(key)); + public async lpop( + key: GlideString, + decoder?: Decoder, + ): Promise { + return this.createWritePromise(createLPop(key), { decoder: decoder }); } /** Removes and returns up to `count` elements of the list stored at `key`, depending on the list's length. @@ -2086,6 +2094,8 @@ export class BaseClient { * * @param key - The key of the list. * @param count - The count of the elements to pop from the list. + * @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. * @returns A list of the popped elements will be returned depending on the list's length. * If `key` does not exist null will be returned. * @@ -2104,10 +2114,13 @@ export class BaseClient { * ``` */ public async lpopCount( - key: string, + key: GlideString, count: number, - ): Promise { - return this.createWritePromise(createLPop(key, count)); + decoder?: Decoder, + ): Promise { + return this.createWritePromise(createLPop(key, count), { + decoder: decoder, + }); } /** Returns the specified elements of the list stored at `key`. @@ -2120,6 +2133,8 @@ export class BaseClient { * @param key - The key of the list. * @param start - The starting point of the range. * @param end - The end of the range. + * @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. * @returns list of elements in the specified range. * If `start` exceeds the end of the list, or if `start` is greater than `end`, an empty list will be returned. * If `end` exceeds the actual end of the list, the range will stop at the actual end of the list. @@ -2147,11 +2162,14 @@ export class BaseClient { * ``` */ public async lrange( - key: string, + key: GlideString, start: number, end: number, - ): Promise { - return this.createWritePromise(createLRange(key, start, end)); + decoder?: Decoder, + ): Promise { + return this.createWritePromise(createLRange(key, start, end), { + decoder: decoder, + }); } /** Returns the length of the list stored at `key`. diff --git a/node/src/Commands.ts b/node/src/Commands.ts index 80206db1af..a75c3a7f4e 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -838,8 +838,8 @@ export function createHGetAll(key: string): command_request.Command { * @internal */ export function createLPush( - key: string, - elements: string[], + key: GlideString, + elements: GlideString[], ): command_request.Command { return createCommand(RequestType.LPush, [key].concat(elements)); } @@ -858,10 +858,11 @@ export function createLPushX( * @internal */ export function createLPop( - key: string, + key: GlideString, count?: number, ): command_request.Command { - const args: string[] = count == undefined ? [key] : [key, count.toString()]; + const args: GlideString[] = + count == undefined ? [key] : [key, count.toString()]; return createCommand(RequestType.LPop, args); } @@ -869,7 +870,7 @@ export function createLPop( * @internal */ export function createLRange( - key: string, + key: GlideString, start: number, end: number, ): command_request.Command { diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index 0443ccb837..b13af93fe7 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -1948,16 +1948,22 @@ export function runBaseTests(config: { `lpush, lpop and lrange with existing and non existing key_%p`, async (protocol) => { await runTest(async (client: BaseClient) => { - const key = uuidv4(); - const valueList = ["value4", "value3", "value2", "value1"]; - expect(await client.lpush(key, valueList)).toEqual(4); - expect(await client.lpop(key)).toEqual("value1"); - expect(await client.lrange(key, 0, -1)).toEqual([ + const key1 = uuidv4(); + const key2 = Buffer.from(uuidv4()); + const valueList1 = ["value4", "value3", "value2", "value1"]; + const valueList2 = ["value7", "value6", "value5"]; + const encodedValues = [ + Buffer.from("value6"), + Buffer.from("value7"), + ]; + expect(await client.lpush(key1, valueList1)).toEqual(4); + expect(await client.lpop(key1)).toEqual("value1"); + expect(await client.lrange(key1, 0, -1)).toEqual([ "value2", "value3", "value4", ]); - expect(await client.lpopCount(key, 2)).toEqual([ + expect(await client.lpopCount(key1, 2)).toEqual([ "value2", "value3", ]); @@ -1965,6 +1971,22 @@ export function runBaseTests(config: { [], ); expect(await client.lpop("nonExistingKey")).toEqual(null); + expect(await client.lpush(key2, valueList2)).toEqual(3); + expect(await client.lpop(key2, Decoder.Bytes)).toEqual( + Buffer.from("value5"), + ); + expect(await client.lrange(key2, 0, -1, Decoder.Bytes)).toEqual( + encodedValues, + ); + expect(await client.lpopCount(key2, 2, Decoder.Bytes)).toEqual( + encodedValues, + ); + expect( + await client.lpush(key2, [Buffer.from("value8")]), + ).toEqual(1); + expect(await client.lpop(key2, Decoder.Bytes)).toEqual( + Buffer.from("value8"), + ); }, protocol); }, config.timeout,