diff --git a/packages/client/lib/commands/XINFO_GROUPS.spec.ts b/packages/client/lib/commands/XINFO_GROUPS.spec.ts index a1196f4957..2a2f67ff2f 100644 --- a/packages/client/lib/commands/XINFO_GROUPS.spec.ts +++ b/packages/client/lib/commands/XINFO_GROUPS.spec.ts @@ -11,6 +11,44 @@ describe('XINFO GROUPS', () => { ); }); + it('transformReply', () => { + assert.deepEqual( + XINFO_GROUPS.transformReply[2]([[ + 'name', 'group', + 'consumers', 0, + 'pending', 0, + 'last-delivered-id', '0-0' + ]]), + [Object.assign(Object.create(null), { + name: 'group', + consumers: 0, + pending: 0, + 'last-delivered-id': '0-0' + })] + ); + }); + + it('transformReply - Redis 7 fields', () => { + assert.deepEqual( + XINFO_GROUPS.transformReply[2]([[ + 'name', 'group', + 'consumers', 0, + 'pending', 0, + 'last-delivered-id', '0-0', + 'entries-read', null, + 'lag', null + ]]), + [Object.assign(Object.create(null), { + name: 'group', + consumers: 0, + pending: 0, + 'last-delivered-id': '0-0', + 'entries-read': null, + lag: null + })] + ); + }); + testUtils.testAll('xInfoGroups', async client => { const [, reply] = await Promise.all([ client.xGroupCreate('key', 'group', '$', { diff --git a/packages/client/lib/commands/XINFO_GROUPS.ts b/packages/client/lib/commands/XINFO_GROUPS.ts index b2469c8551..fb473a4e39 100644 --- a/packages/client/lib/commands/XINFO_GROUPS.ts +++ b/packages/client/lib/commands/XINFO_GROUPS.ts @@ -1,5 +1,6 @@ import { CommandParser } from '../client/parser'; -import { RedisArgument, ArrayReply, TuplesToMapReply, BlobStringReply, NumberReply, NullReply, UnwrapReply, Resp2Reply, Command } from '../RESP/types'; +import { RedisArgument, ArrayReply, TuplesToMapReply, BlobStringReply, NumberReply, NullReply, Command } from '../RESP/types'; +import { transformTuplesReply } from './generic-transformers'; /** * Reply structure for XINFO GROUPS command containing information about consumer groups @@ -8,11 +9,11 @@ export type XInfoGroupsReply = ArrayReply, BlobStringReply], [BlobStringReply<'consumers'>, NumberReply], [BlobStringReply<'pending'>, NumberReply], - [BlobStringReply<'last-delivered-id'>, NumberReply], + [BlobStringReply<'last-delivered-id'>, BlobStringReply], /** added in 7.0 */ [BlobStringReply<'entries-read'>, NumberReply | NullReply], /** added in 7.0 */ - [BlobStringReply<'lag'>, NumberReply], + [BlobStringReply<'lag'>, NumberReply | NullReply], ]>>; export default { @@ -34,19 +35,8 @@ export default { * entries-read - Number of entries read in the group (Redis 7.0+) * lag - Number of entries not read by the group (Redis 7.0+) */ - 2: (reply: UnwrapReply>) => { - return reply.map(group => { - const unwrapped = group as unknown as UnwrapReply; - return { - name: unwrapped[1], - consumers: unwrapped[3], - pending: unwrapped[5], - 'last-delivered-id': unwrapped[7], - 'entries-read': unwrapped[9], - lag: unwrapped[11] - }; - }); - }, + 2: (reply: Array>) => + reply.map(group => transformTuplesReply(group as unknown as ArrayReply)) as unknown as XInfoGroupsReply['DEFAULT'], 3: undefined as unknown as () => XInfoGroupsReply } } as const satisfies Command;