1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-03 04:01:40 +03:00
Files
node-redis/packages/client/lib/commands/XAUTOCLAIM.ts
Bobby I. 20c16e0c2c (docs) add jsdoc comments to command parsers (#2984)
* (docs) bloom: add jsdocs for all commands

* (docs) json: add jsdocs

* (docs) search: add jsdocs for all commands

* (docs) jsdocs for std commands

* (docs) jsdoc comments to time series commands
2025-06-03 14:38:07 +03:00

75 lines
2.6 KiB
TypeScript

import { CommandParser } from '../client/parser';
import { RedisArgument, TuplesReply, BlobStringReply, ArrayReply, NullReply, UnwrapReply, Command, TypeMapping } from '../RESP/types';
import { StreamMessageRawReply, transformStreamMessageNullReply } from './generic-transformers';
/**
* Options for the XAUTOCLAIM command
*
* @property COUNT - Limit the number of messages to claim
*/
export interface XAutoClaimOptions {
COUNT?: number;
}
/**
* Raw reply structure for XAUTOCLAIM command
*
* @property nextId - The ID to use for the next XAUTOCLAIM call
* @property messages - Array of claimed messages or null entries
* @property deletedMessages - Array of message IDs that no longer exist
*/
export type XAutoClaimRawReply = TuplesReply<[
nextId: BlobStringReply,
messages: ArrayReply<StreamMessageRawReply | NullReply>,
deletedMessages: ArrayReply<BlobStringReply>
]>;
export default {
IS_READ_ONLY: false,
/**
* Constructs the XAUTOCLAIM command to automatically claim pending messages in a consumer group
*
* @param parser - The command parser
* @param key - The stream key
* @param group - The consumer group name
* @param consumer - The consumer name that will claim the messages
* @param minIdleTime - Minimum idle time in milliseconds for a message to be claimed
* @param start - Message ID to start scanning from
* @param options - Additional options for the claim operation
* @returns Object containing nextId, claimed messages, and list of deleted message IDs
* @see https://redis.io/commands/xautoclaim/
*/
parseCommand(
parser: CommandParser,
key: RedisArgument,
group: RedisArgument,
consumer: RedisArgument,
minIdleTime: number,
start: RedisArgument,
options?: XAutoClaimOptions
) {
parser.push('XAUTOCLAIM');
parser.pushKey(key);
parser.push(group, consumer, minIdleTime.toString(), start);
if (options?.COUNT) {
parser.push('COUNT', options.COUNT.toString());
}
},
/**
* Transforms the raw XAUTOCLAIM reply into a structured object
*
* @param reply - Raw reply from Redis
* @param preserve - Preserve options (unused)
* @param typeMapping - Type mapping for message fields
* @returns Structured object containing nextId, messages, and deletedMessages
*/
transformReply(reply: UnwrapReply<XAutoClaimRawReply>, preserve?: any, typeMapping?: TypeMapping) {
return {
nextId: reply[0],
messages: (reply[1] as unknown as UnwrapReply<typeof reply[1]>).map(transformStreamMessageNullReply.bind(undefined, typeMapping)),
deletedMessages: reply[2]
};
}
} as const satisfies Command;