diff --git a/node/src/Transaction.ts b/node/src/Transaction.ts index 3d41ed5e39..2580833733 100644 --- a/node/src/Transaction.ts +++ b/node/src/Transaction.ts @@ -51,9 +51,9 @@ import { StreamReadOptions, StreamTrimOptions, ZAddOptions, + createBLMPop, createBLMove, createBLPop, - createBLMPop, createBRPop, createBZMPop, createBitCount, @@ -113,8 +113,8 @@ import { createLIndex, createLInsert, createLLen, - createLMove, createLMPop, + createLMove, createLPop, createLPos, createLPush, @@ -177,6 +177,7 @@ import { createUnlink, createXAdd, createXDel, + createXInfoStream, createXLen, createXRead, createXTrim, @@ -2060,6 +2061,21 @@ export class BaseTransaction> { return this.addAndReturn(createXTrim(key, options)); } + /** + * Returns information about the stream stored at `key`. + * + * @param key - The key of the stream. + * @param fullOptions - If `true`, returns verbose information with a limit of the first 10 PEL entries. + * If `number` is specified, returns verbose information limiting the returned PEL entries. + * If `0` is specified, returns verbose information with no limit. + * + * Command Response - A map of detailed stream information for the given `key`. See + * the example for a sample response. + */ + public xinfoStream(key: string, fullOptions?: boolean | number): T { + return this.addAndReturn(createXInfoStream(key, fullOptions ?? false)); + } + /** Returns the server time. * See https://valkey.io/commands/time/ for details. * diff --git a/node/tests/GlideClient.test.ts b/node/tests/GlideClient.test.ts index 11b75ef82e..9a9edd7ecb 100644 --- a/node/tests/GlideClient.test.ts +++ b/node/tests/GlideClient.test.ts @@ -1047,6 +1047,61 @@ describe("GlideClient", () => { TIMEOUT, ); + it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])( + "xinfo stream transaction test_%p", + async (protocol) => { + const client = await GlideClient.createClient( + getClientConfigurationOption(cluster.getAddresses(), protocol), + ); + + const key = uuidv4(); + + const transaction = new Transaction(); + transaction.xadd(key, [["field1", "value1"]], { id: "0-1" }); + transaction.xinfoStream(key); + transaction.xinfoStream(key, true); + const result = await client.exec(transaction); + expect(result).not.toBeNull(); + + const versionLessThan7 = + cluster.checkIfServerVersionLessThan("7.0.0"); + + const expectedXinfoStreamResult = { + length: 1, + "radix-tree-keys": 1, + "radix-tree-nodes": 2, + "last-generated-id": "0-1", + groups: 0, + "first-entry": ["0-1", ["field1", "value1"]], + "last-entry": ["0-1", ["field1", "value1"]], + "max-deleted-entry-id": versionLessThan7 ? undefined : "0-0", + "entries-added": versionLessThan7 ? undefined : 1, + "recorded-first-entry-id": versionLessThan7 ? undefined : "0-1", + }; + + const expectedXinfoStreamFullResult = { + length: 1, + "radix-tree-keys": 1, + "radix-tree-nodes": 2, + "last-generated-id": "0-1", + entries: [["0-1", ["field1", "value1"]]], + groups: [], + "max-deleted-entry-id": versionLessThan7 ? undefined : "0-0", + "entries-added": versionLessThan7 ? undefined : 1, + "recorded-first-entry-id": versionLessThan7 ? undefined : "0-1", + }; + + if (result != null) { + expect(result[0]).toEqual("0-1"); // xadd + expect(result[1]).toEqual(expectedXinfoStreamResult); + expect(result[2]).toEqual(expectedXinfoStreamFullResult); + } + + client.close(); + }, + TIMEOUT, + ); + runBaseTests({ init: async (protocol, clientName?) => { const options = getClientConfigurationOption(