1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00
This commit is contained in:
Leibale
2023-12-05 12:51:56 -05:00
parent b99502b874
commit cb779a3ed7
3 changed files with 43 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
import { CommandArguments, RedisScript, ReplyUnion, TransformReply } from './RESP/types';
import { ErrorReply, MultiErrorReply } from './errors';
export type MULTI_REPLY = {
GENERIC: 'generic';
@@ -46,9 +47,18 @@ export default class RedisMultiCommand {
}
transformReplies(rawReplies: Array<unknown>): Array<unknown> {
return rawReplies.map((reply, i) => {
const { transformReply, args } = this.queue[i];
return transformReply ? transformReply(reply, args.preserve) : reply;
});
const errorIndexes: Array<number> = [],
replies = rawReplies.map((reply, i) => {
if (reply instanceof ErrorReply) {
errorIndexes.push(i);
return reply;
}
const { transformReply, args } = this.queue[i];
return transformReply ? transformReply(reply, args.preserve) : reply;
});
if (errorIndexes.length) throw new MultiErrorReply(replies, errorIndexes);
return replies;
}
}