Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/client/lib/commands/WAITAOF.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import WAITAOF from './WAITAOF';
import { parseArgs } from './generic-transformers';

describe('WAITAOF', () => {
it('transformArguments', () => {
assert.deepEqual(
parseArgs(WAITAOF, 0, 0, 1),
['WAITAOF', '0', '0', '1']
);
});

testUtils.testWithClient('client.waitAof', async client => {
assert.deepEqual(
await client.waitAof(0, 0, 1),
[0, 0]
);
}, GLOBAL.SERVERS.OPEN);
});
22 changes: 22 additions & 0 deletions packages/client/lib/commands/WAITAOF.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { CommandParser } from '../client/parser';
import { ArrayReply, NumberReply, Command } from '../RESP/types';

export default {
NOT_KEYED_COMMAND: true,
IS_READ_ONLY: true,
/**
* Blocks the current client until all previous write commands have been
* acknowledged by the local Append-Only File and/or the specified number
* of replicas, or until the given timeout (in milliseconds) is reached.
*
* @param parser - The command parser
* @param numLocal - Number of local AOF fsyncs to wait for (`0` or `1`)
* @param numReplicas - Number of replica AOF fsyncs to wait for
* @param timeout - Maximum time to wait in milliseconds (`0` for no timeout)
* @see https://redis.io/commands/waitaof/
*/
parseCommand(parser: CommandParser, numLocal: number, numReplicas: number, timeout: number) {
parser.push('WAITAOF', numLocal.toString(), numReplicas.toString(), timeout.toString());
},
transformReply: undefined as unknown as () => ArrayReply<NumberReply>
} as const satisfies Command;
21 changes: 21 additions & 0 deletions packages/client/lib/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ import TTL from './TTL';
import TYPE from './TYPE';
import UNLINK from './UNLINK';
import WAIT from './WAIT';
import WAITAOF from './WAITAOF';
import XACK from './XACK';
import XACKDEL from './XACKDEL';
import XADD_NOMKSTREAM from './XADD_NOMKSTREAM';
Expand Down Expand Up @@ -4270,6 +4271,16 @@ export default {
* @see https://redis.io/commands/wait/
*/
WAIT,
/**
* Constructs the WAITAOF command to synchronize with the Append-Only File on the local Redis instance and replicas
*
* @param numLocal - Number of local AOF fsyncs to wait for (`0` or `1`)
* @param numReplicas - Number of replica AOF fsyncs to wait for
* @param timeout - Maximum time to wait in milliseconds (`0` for no timeout)
* @returns A two-element array `[numLocalSynced, numReplicasSynced]`
* @see https://redis.io/commands/waitaof/
*/
WAITAOF,
/**
* Constructs the WAIT command to synchronize with replicas
*
Expand All @@ -4279,6 +4290,16 @@ export default {
* @see https://redis.io/commands/wait/
*/
wait: WAIT,
/**
* Constructs the WAITAOF command to synchronize with the Append-Only File on the local Redis instance and replicas
*
* @param numLocal - Number of local AOF fsyncs to wait for (`0` or `1`)
* @param numReplicas - Number of replica AOF fsyncs to wait for
* @param timeout - Maximum time to wait in milliseconds (`0` for no timeout)
* @returns A two-element array `[numLocalSynced, numReplicasSynced]`
* @see https://redis.io/commands/waitaof/
*/
waitAof: WAITAOF,
/**
* Constructs the XACK command to acknowledge the processing of stream messages in a consumer group
*
Expand Down