Skip to content

Commit c9dae34

Browse files
committed
ref #2565 - handle null message in XAUTOCLAIM
1 parent fdd1978 commit c9dae34

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

packages/client/lib/commands/XAUTOCLAIM.spec.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
22
import testUtils, { GLOBAL } from '../test-utils';
33
import XAUTOCLAIM from './XAUTOCLAIM';
44

5-
describe('XAUTOCLAIM', () => {
5+
describe.only('XAUTOCLAIM', () => {
66
testUtils.isVersionGreaterThanHook([6, 2]);
77

88
describe('transformArguments', () => {
@@ -31,26 +31,35 @@ describe('XAUTOCLAIM', () => {
3131
}
3232
});
3333

34-
const [, , id, , reply] = await Promise.all([
34+
const [, , id1, id2, , , reply] = await Promise.all([
3535
client.xGroupCreate('key', 'group', '$', {
3636
MKSTREAM: true
3737
}),
3838
client.xGroupCreateConsumer('key', 'group', 'consumer'),
3939
client.xAdd('key', '*', message),
40+
client.xAdd('key', '*', message),
4041
client.xReadGroup('group', 'consumer', {
4142
key: 'key',
4243
id: '>'
4344
}),
45+
client.xTrim('key', 'MAXLEN', 1),
4446
client.xAutoClaim('key', 'group', 'consumer', 0, '0-0')
4547
]);
4648

4749
assert.deepEqual(reply, {
4850
nextId: '0-0',
49-
messages: [{
50-
id,
51-
message
52-
}],
53-
deletedMessages: testUtils.isVersionGreaterThan([7, 0]) ? [] : undefined
51+
...(testUtils.isVersionGreaterThan([7, 0]) ? {
52+
messages: [{
53+
id: id2,
54+
message
55+
}],
56+
deletedMessages: [id1]
57+
} : {
58+
messages: [null, {
59+
id: id2,
60+
message
61+
}]
62+
})
5463
});
5564
}, {
5665
client: GLOBAL.SERVERS.OPEN,

packages/client/lib/commands/XAUTOCLAIM.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { RedisArgument, TuplesReply, BlobStringReply, ArrayReply, UnwrapReply, Command } from '../RESP/types';
2-
import { StreamMessagesRawReply, transformStreamMessagesReply } from './generic-transformers';
1+
import { RedisArgument, TuplesReply, BlobStringReply, ArrayReply, NullReply, UnwrapReply, Command } from '../RESP/types';
2+
import { StreamMessageRawReply, isNullReply, transformStreamMessageReply } from './generic-transformers';
33

44
export interface XAutoClaimOptions {
55
COUNT?: number;
66
}
77

88
export type XAutoClaimRawReply = TuplesReply<[
99
nextId: BlobStringReply,
10-
messages: StreamMessagesRawReply,
10+
messages: ArrayReply<StreamMessageRawReply | NullReply>,
1111
deletedMessages: ArrayReply<BlobStringReply>
1212
]>;
1313

@@ -40,7 +40,9 @@ export default {
4040
transformReply(reply: UnwrapReply<XAutoClaimRawReply>) {
4141
return {
4242
nextId: reply[0],
43-
messages: transformStreamMessagesReply(reply[1]),
43+
messages: (reply[1] as unknown as UnwrapReply<typeof reply[1]>).map(message => {
44+
return isNullReply(message) ? null : transformStreamMessageReply(message);
45+
}),
4446
deletedMessages: reply[2]
4547
};
4648
}

packages/client/lib/commands/generic-transformers.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { UnwrapReply, ArrayReply, BlobStringReply, BooleanReply, CommandArguments, DoubleReply, MapReply, NullReply, NumberReply, RedisArgument, TuplesReply } from '../RESP/types';
1+
import { UnwrapReply, ArrayReply, BlobStringReply, BooleanReply, CommandArguments, DoubleReply, MapReply, NullReply, NumberReply, RedisArgument, TuplesReply, RespType } from '../RESP/types';
2+
3+
export function isNullReply(reply: unknown): reply is NullReply {
4+
return reply === null;
5+
}
26

37
export const transformBooleanReply = {
48
2: (reply: NumberReply<0 | 1>) => reply as unknown as UnwrapReply<typeof reply> === 1,

0 commit comments

Comments
 (0)