You've already forked node-redis
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:
@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import XAUTOCLAIM from './XAUTOCLAIM';
|
||||
|
||||
describe('XAUTOCLAIM', () => {
|
||||
describe.only('XAUTOCLAIM', () => {
|
||||
testUtils.isVersionGreaterThanHook([6, 2]);
|
||||
|
||||
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', '$', {
|
||||
MKSTREAM: true
|
||||
}),
|
||||
client.xGroupCreateConsumer('key', 'group', 'consumer'),
|
||||
client.xAdd('key', '*', message),
|
||||
client.xAdd('key', '*', message),
|
||||
client.xReadGroup('group', 'consumer', {
|
||||
key: 'key',
|
||||
id: '>'
|
||||
}),
|
||||
client.xTrim('key', 'MAXLEN', 1),
|
||||
client.xAutoClaim('key', 'group', 'consumer', 0, '0-0')
|
||||
]);
|
||||
|
||||
assert.deepEqual(reply, {
|
||||
nextId: '0-0',
|
||||
messages: [{
|
||||
id,
|
||||
message
|
||||
}],
|
||||
deletedMessages: testUtils.isVersionGreaterThan([7, 0]) ? [] : undefined
|
||||
...(testUtils.isVersionGreaterThan([7, 0]) ? {
|
||||
messages: [{
|
||||
id: id2,
|
||||
message
|
||||
}],
|
||||
deletedMessages: [id1]
|
||||
} : {
|
||||
messages: [null, {
|
||||
id: id2,
|
||||
message
|
||||
}]
|
||||
})
|
||||
});
|
||||
}, {
|
||||
client: GLOBAL.SERVERS.OPEN,
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { RedisArgument, TuplesReply, BlobStringReply, ArrayReply, UnwrapReply, Command } from '../RESP/types';
|
||||
import { StreamMessagesRawReply, transformStreamMessagesReply } from './generic-transformers';
|
||||
import { RedisArgument, TuplesReply, BlobStringReply, ArrayReply, NullReply, UnwrapReply, Command } from '../RESP/types';
|
||||
import { StreamMessageRawReply, isNullReply, transformStreamMessageReply } from './generic-transformers';
|
||||
|
||||
export interface XAutoClaimOptions {
|
||||
COUNT?: number;
|
||||
@@ -7,7 +7,7 @@ export interface XAutoClaimOptions {
|
||||
|
||||
export type XAutoClaimRawReply = TuplesReply<[
|
||||
nextId: BlobStringReply,
|
||||
messages: StreamMessagesRawReply,
|
||||
messages: ArrayReply<StreamMessageRawReply | NullReply>,
|
||||
deletedMessages: ArrayReply<BlobStringReply>
|
||||
]>;
|
||||
|
||||
@@ -40,7 +40,9 @@ export default {
|
||||
transformReply(reply: UnwrapReply<XAutoClaimRawReply>) {
|
||||
return {
|
||||
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]
|
||||
};
|
||||
}
|
||||
|
@@ -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 = {
|
||||
2: (reply: NumberReply<0 | 1>) => reply as unknown as UnwrapReply<typeof reply> === 1,
|
||||
|
Reference in New Issue
Block a user