You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
#2666 for v5
This commit is contained in:
@@ -3,7 +3,7 @@ import testUtils, { GLOBAL, waitTillBeenCalled } from '../test-utils';
|
|||||||
import RedisClient, { RedisClientType } from '.';
|
import RedisClient, { RedisClientType } from '.';
|
||||||
// import { RedisClientMultiCommandType } from './multi-command';
|
// import { RedisClientMultiCommandType } from './multi-command';
|
||||||
// import { RedisCommandRawReply, RedisModules, RedisFunctions, RedisScripts } from '../commands';
|
// import { RedisCommandRawReply, RedisModules, RedisFunctions, RedisScripts } from '../commands';
|
||||||
import { AbortError, ClientClosedError, ClientOfflineError, ConnectionTimeoutError, DisconnectsClientError, SocketClosedUnexpectedlyError, WatchError } from '../errors';
|
import { AbortError, ClientClosedError, ClientOfflineError, ConnectionTimeoutError, DisconnectsClientError, ErrorReply, MultiErrorReply, SocketClosedUnexpectedlyError, WatchError } from '../errors';
|
||||||
import { defineScript } from '../lua-script';
|
import { defineScript } from '../lua-script';
|
||||||
import { spy } from 'sinon';
|
import { spy } from 'sinon';
|
||||||
import { once } from 'node:events';
|
import { once } from 'node:events';
|
||||||
@@ -282,6 +282,23 @@ describe('Client', () => {
|
|||||||
// ...GLOBAL.SERVERS.OPEN,
|
// ...GLOBAL.SERVERS.OPEN,
|
||||||
// minimumDockerVersion: [6, 2] // CLIENT INFO
|
// minimumDockerVersion: [6, 2] // CLIENT INFO
|
||||||
// });
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
testUtils.testWithClient('should handle error replies (#2665)', async client => {
|
||||||
|
await assert.rejects(
|
||||||
|
client.multi()
|
||||||
|
.set('key', 'value')
|
||||||
|
.hGetAll('key')
|
||||||
|
.exec(),
|
||||||
|
err => {
|
||||||
|
assert.ok(err instanceof MultiErrorReply);
|
||||||
|
assert.equal(err.replies.length, 2);
|
||||||
|
assert.deepEqual(err.errorIndexes, [1]);
|
||||||
|
assert.ok(err.replies[1] instanceof ErrorReply);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
});
|
});
|
||||||
|
|
||||||
testUtils.testWithClient('scripts', async client => {
|
testUtils.testWithClient('scripts', async client => {
|
||||||
|
@@ -69,3 +69,14 @@ export class SimpleError extends ErrorReply {}
|
|||||||
export class BlobError extends ErrorReply {}
|
export class BlobError extends ErrorReply {}
|
||||||
|
|
||||||
export class TimeoutError extends Error {}
|
export class TimeoutError extends Error {}
|
||||||
|
|
||||||
|
export class MultiErrorReply extends ErrorReply {
|
||||||
|
replies: Array<ErrorReply>;
|
||||||
|
errorIndexes: Array<number>;
|
||||||
|
|
||||||
|
constructor(replies: Array<ErrorReply>, errorIndexes: Array<number>) {
|
||||||
|
super(`${errorIndexes.length} commands failed, see .replies and .errorIndexes for more information`);
|
||||||
|
this.replies = replies;
|
||||||
|
this.errorIndexes = errorIndexes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import { CommandArguments, RedisScript, ReplyUnion, TransformReply } from './RESP/types';
|
import { CommandArguments, RedisScript, ReplyUnion, TransformReply } from './RESP/types';
|
||||||
|
import { ErrorReply, MultiErrorReply } from './errors';
|
||||||
|
|
||||||
export type MULTI_REPLY = {
|
export type MULTI_REPLY = {
|
||||||
GENERIC: 'generic';
|
GENERIC: 'generic';
|
||||||
@@ -46,9 +47,18 @@ export default class RedisMultiCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
transformReplies(rawReplies: Array<unknown>): Array<unknown> {
|
transformReplies(rawReplies: Array<unknown>): Array<unknown> {
|
||||||
return rawReplies.map((reply, i) => {
|
const errorIndexes: Array<number> = [],
|
||||||
|
replies = rawReplies.map((reply, i) => {
|
||||||
|
if (reply instanceof ErrorReply) {
|
||||||
|
errorIndexes.push(i);
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
|
||||||
const { transformReply, args } = this.queue[i];
|
const { transformReply, args } = this.queue[i];
|
||||||
return transformReply ? transformReply(reply, args.preserve) : reply;
|
return transformReply ? transformReply(reply, args.preserve) : reply;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (errorIndexes.length) throw new MultiErrorReply(replies, errorIndexes);
|
||||||
|
return replies;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user