1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

fix returnBuffers, add some tests

This commit is contained in:
leibale
2021-12-29 17:09:59 -05:00
parent 74daee3023
commit 77022209bd
11 changed files with 149 additions and 25 deletions

View File

@@ -360,11 +360,15 @@ export default class RedisCommandsQueue {
return toSend?.args;
}
parseResponse(data: Buffer): void {
#setReturnBuffers() {
this.#parser.setReturnBuffers(
!!this.#waitingForReply.head?.value.returnBuffers ||
!!this.#pubSubState?.subscribed
);
}
parseResponse(data: Buffer): void {
this.#setReturnBuffers();
this.#parser.execute(data);
}
@@ -372,8 +376,12 @@ export default class RedisCommandsQueue {
if (!this.#waitingForReply.length) {
throw new Error('Got an unexpected reply from Redis');
}
return this.#waitingForReply.shift()!;
const waitingForReply = this.#waitingForReply.shift()!;
this.#setReturnBuffers();
return waitingForReply;
}
flushWaitingForReply(err: Error): void {
RedisCommandsQueue.#flushQueue(this.#waitingForReply, err);
if (!this.#chainInExecution) {
@@ -384,6 +392,7 @@ export default class RedisCommandsQueue {
}
this.#chainInExecution = undefined;
}
flushAll(err: Error): void {
RedisCommandsQueue.#flushQueue(this.#waitingForReply, err);
RedisCommandsQueue.#flushQueue(this.#waitingToBeSent, err);

View File

@@ -89,6 +89,8 @@ export default class RedisClient<M extends RedisModules, S extends RedisScripts>
return commandOptions(options);
}
commandOptions = RedisClient.commandOptions;
static extend<M extends RedisModules, S extends RedisScripts>(plugins?: RedisPlugins<M, S>): InstantiableRedisClient<M, S> {
const Client = <any>extendWithModulesAndScripts({
BaseClass: RedisClient,

View File

@@ -93,5 +93,18 @@ describe('CLIENT KILL', () => {
);
});
});
it('TYPE & SKIP_ME', () => {
assert.deepEqual(
transformArguments([
{
filter: ClientKillFilters.TYPE,
type: 'master'
},
ClientKillFilters.SKIP_ME
]),
['CLIENT', 'KILL', 'TYPE', 'master', 'SKIPME']
);
});
});
});

View File

@@ -12,19 +12,53 @@ describe('XPENDING', () => {
});
});
testUtils.testWithClient('client.xPending', async client => {
await client.xGroupCreate('key', 'group', '$', {
MKSTREAM: true
});
describe('client.xPending', () => {
testUtils.testWithClient('simple', async client => {
await Promise.all([
client.xGroupCreate('key', 'group', '$', {
MKSTREAM: true
}),
client.xGroupCreateConsumer('key', 'group', 'consumer')
]);
assert.deepEqual(
await client.xPending('key', 'group'),
{
pending: 0,
firstId: null,
lastId: null,
consumers: null
}
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('with consumers', async client => {
const [,, id] = await Promise.all([
client.xGroupCreate('key', 'group', '$', {
MKSTREAM: true
}),
client.xGroupCreateConsumer('key', 'group', 'consumer'),
client.xAdd('key', '*', { field: 'value' }),
client.xReadGroup('group', 'consumer', {
key: 'key',
id: '>'
})
]);
assert.deepEqual(
await client.xPending('key', 'group'),
{
pending: 1,
firstId: id,
lastId: id,
consumers: [{
name: 'consumer',
deliveriesCounter: 1
}]
}
);
}, GLOBAL.SERVERS.OPEN);
});
assert.deepEqual(
await client.xPending('key', 'group'),
{
pending: 0,
firstId: null,
lastId: null,
consumers: null
}
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -17,17 +17,17 @@ type XPendingRawReply = [
lastId: RedisCommandArgument | null,
consumers: Array<[
name: RedisCommandArgument,
deliveriesCounter: number
deliveriesCounter: RedisCommandArgument
]> | null
]
];
interface XPendingReply {
pending: number;
firstId: RedisCommandArgument | null;
lastId: RedisCommandArgument | null
lastId: RedisCommandArgument | null;
consumers: Array<{
name: RedisCommandArgument,
deliveriesCounter: number
name: RedisCommandArgument;
deliveriesCounter: number;
}> | null;
}
@@ -38,7 +38,7 @@ export function transformReply(reply: XPendingRawReply): XPendingReply {
lastId: reply[2],
consumers: reply[3] === null ? null : reply[3].map(([name, deliveriesCounter]) => ({
name,
deliveriesCounter
deliveriesCounter: Number(deliveriesCounter)
}))
};
}