1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

ref #2565 - handle null message in XAUTOCLAIM

This commit is contained in:
Leibale
2023-07-19 13:59:44 -04:00
parent fdd1978d92
commit c9dae346a2
3 changed files with 27 additions and 12 deletions

View File

@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import XAUTOCLAIM from './XAUTOCLAIM'; import XAUTOCLAIM from './XAUTOCLAIM';
describe('XAUTOCLAIM', () => { describe.only('XAUTOCLAIM', () => {
testUtils.isVersionGreaterThanHook([6, 2]); testUtils.isVersionGreaterThanHook([6, 2]);
describe('transformArguments', () => { describe('transformArguments', () => {
@@ -31,26 +31,35 @@ describe('XAUTOCLAIM', () => {
} }
}); });
const [, , id, , reply] = await Promise.all([ const [, , id1, id2, , , reply] = await Promise.all([
client.xGroupCreate('key', 'group', '$', { client.xGroupCreate('key', 'group', '$', {
MKSTREAM: true MKSTREAM: true
}), }),
client.xGroupCreateConsumer('key', 'group', 'consumer'), client.xGroupCreateConsumer('key', 'group', 'consumer'),
client.xAdd('key', '*', message), client.xAdd('key', '*', message),
client.xAdd('key', '*', message),
client.xReadGroup('group', 'consumer', { client.xReadGroup('group', 'consumer', {
key: 'key', key: 'key',
id: '>' id: '>'
}), }),
client.xTrim('key', 'MAXLEN', 1),
client.xAutoClaim('key', 'group', 'consumer', 0, '0-0') client.xAutoClaim('key', 'group', 'consumer', 0, '0-0')
]); ]);
assert.deepEqual(reply, { assert.deepEqual(reply, {
nextId: '0-0', nextId: '0-0',
messages: [{ ...(testUtils.isVersionGreaterThan([7, 0]) ? {
id, messages: [{
message id: id2,
}], message
deletedMessages: testUtils.isVersionGreaterThan([7, 0]) ? [] : undefined }],
deletedMessages: [id1]
} : {
messages: [null, {
id: id2,
message
}]
})
}); });
}, { }, {
client: GLOBAL.SERVERS.OPEN, client: GLOBAL.SERVERS.OPEN,

View File

@@ -1,5 +1,5 @@
import { RedisArgument, TuplesReply, BlobStringReply, ArrayReply, UnwrapReply, Command } from '../RESP/types'; import { RedisArgument, TuplesReply, BlobStringReply, ArrayReply, NullReply, UnwrapReply, Command } from '../RESP/types';
import { StreamMessagesRawReply, transformStreamMessagesReply } from './generic-transformers'; import { StreamMessageRawReply, isNullReply, transformStreamMessageReply } from './generic-transformers';
export interface XAutoClaimOptions { export interface XAutoClaimOptions {
COUNT?: number; COUNT?: number;
@@ -7,7 +7,7 @@ export interface XAutoClaimOptions {
export type XAutoClaimRawReply = TuplesReply<[ export type XAutoClaimRawReply = TuplesReply<[
nextId: BlobStringReply, nextId: BlobStringReply,
messages: StreamMessagesRawReply, messages: ArrayReply<StreamMessageRawReply | NullReply>,
deletedMessages: ArrayReply<BlobStringReply> deletedMessages: ArrayReply<BlobStringReply>
]>; ]>;
@@ -40,7 +40,9 @@ export default {
transformReply(reply: UnwrapReply<XAutoClaimRawReply>) { transformReply(reply: UnwrapReply<XAutoClaimRawReply>) {
return { return {
nextId: reply[0], nextId: reply[0],
messages: transformStreamMessagesReply(reply[1]), messages: (reply[1] as unknown as UnwrapReply<typeof reply[1]>).map(message => {
return isNullReply(message) ? null : transformStreamMessageReply(message);
}),
deletedMessages: reply[2] deletedMessages: reply[2]
}; };
} }

View File

@@ -1,4 +1,8 @@
import { UnwrapReply, ArrayReply, BlobStringReply, BooleanReply, CommandArguments, DoubleReply, MapReply, NullReply, NumberReply, RedisArgument, TuplesReply } from '../RESP/types'; import { UnwrapReply, ArrayReply, BlobStringReply, BooleanReply, CommandArguments, DoubleReply, MapReply, NullReply, NumberReply, RedisArgument, TuplesReply, RespType } from '../RESP/types';
export function isNullReply(reply: unknown): reply is NullReply {
return reply === null;
}
export const transformBooleanReply = { export const transformBooleanReply = {
2: (reply: NumberReply<0 | 1>) => reply as unknown as UnwrapReply<typeof reply> === 1, 2: (reply: NumberReply<0 | 1>) => reply as unknown as UnwrapReply<typeof reply> === 1,