From 3f5f4cb12187f14ae9d5c39860e98b8bc5060aac Mon Sep 17 00:00:00 2001 From: Evis Cheng Date: Mon, 12 Jun 2023 12:03:18 +0800 Subject: [PATCH 1/3] Add support for WAITAOF command --- packages/client/lib/client/commands.ts | 7 ++++-- packages/client/lib/commands/WAITAOF.spec.ts | 23 ++++++++++++++++++++ packages/client/lib/commands/WAITAOF.ts | 16 ++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 packages/client/lib/commands/WAITAOF.spec.ts create mode 100644 packages/client/lib/commands/WAITAOF.ts diff --git a/packages/client/lib/client/commands.ts b/packages/client/lib/client/commands.ts index 1e2e5274c0a..e73b9632386 100644 --- a/packages/client/lib/client/commands.ts +++ b/packages/client/lib/client/commands.ts @@ -118,7 +118,8 @@ import * as SWAPDB from '../commands/SWAPDB'; import * as TIME from '../commands/TIME'; import * as UNWATCH from '../commands/UNWATCH'; import * as WAIT from '../commands/WAIT'; - +import * as WAITAOF from '../commands/WAITAOF' +; export default { ...CLUSTER_COMMANDS, ACL_CAT, @@ -358,5 +359,7 @@ export default { UNWATCH, unwatch: UNWATCH, WAIT, - wait: WAIT + wait: WAIT, + WAITAOF, + waitaof: WAITAOF }; diff --git a/packages/client/lib/commands/WAITAOF.spec.ts b/packages/client/lib/commands/WAITAOF.spec.ts new file mode 100644 index 00000000000..1515ca902f8 --- /dev/null +++ b/packages/client/lib/commands/WAITAOF.spec.ts @@ -0,0 +1,23 @@ +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import { transformArguments } from './WAITAOF'; + +describe('WAITAOF', () => { + testUtils.isVersionGreaterThanHook([7, 2]); + + describe('transformArguments', () => { + it('simple', () => { + assert.deepEqual( + transformArguments(1, 0, 0), + ['WAITAOF', '1', '0', '0'] + ); + }); + }); + + testUtils.testWithClient('client.wait', async client => { + assert.equal( + await client.waitaof(1, 0, 0), + [1, 0] + ); + }, GLOBAL.SERVERS.OPEN); +}); \ No newline at end of file diff --git a/packages/client/lib/commands/WAITAOF.ts b/packages/client/lib/commands/WAITAOF.ts new file mode 100644 index 00000000000..e9e4053e02a --- /dev/null +++ b/packages/client/lib/commands/WAITAOF.ts @@ -0,0 +1,16 @@ +import { RedisCommandArgument, RedisCommandArguments } from '.'; + +export function transformArguments( + numlocal: number, + numreplicas: number, + timeout: number +): RedisCommandArguments { + return [ + 'WAITAOF', + numlocal.toString(), + numreplicas.toString(), + timeout.toString() + ]; +} + +export declare function transformReply(): Array<[number, number]>; \ No newline at end of file From f32b93024939ca5aff05abf1c0fa9482c72bd3a7 Mon Sep 17 00:00:00 2001 From: Evis Cheng Date: Tue, 13 Jun 2023 11:50:32 +0800 Subject: [PATCH 2/3] linting --- packages/client/lib/client/commands.ts | 4 ++-- packages/client/lib/commands/WAITAOF.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/client/lib/client/commands.ts b/packages/client/lib/client/commands.ts index e73b9632386..a7958fedcab 100644 --- a/packages/client/lib/client/commands.ts +++ b/packages/client/lib/client/commands.ts @@ -118,8 +118,8 @@ import * as SWAPDB from '../commands/SWAPDB'; import * as TIME from '../commands/TIME'; import * as UNWATCH from '../commands/UNWATCH'; import * as WAIT from '../commands/WAIT'; -import * as WAITAOF from '../commands/WAITAOF' -; +import * as WAITAOF from '../commands/WAITAOF'; + export default { ...CLUSTER_COMMANDS, ACL_CAT, diff --git a/packages/client/lib/commands/WAITAOF.ts b/packages/client/lib/commands/WAITAOF.ts index e9e4053e02a..a8ee730375a 100644 --- a/packages/client/lib/commands/WAITAOF.ts +++ b/packages/client/lib/commands/WAITAOF.ts @@ -1,4 +1,4 @@ -import { RedisCommandArgument, RedisCommandArguments } from '.'; +import { RedisCommandArguments } from '.'; export function transformArguments( numlocal: number, From c3bf1767386246f7206fdf4e76bfa607dfeeb4e4 Mon Sep 17 00:00:00 2001 From: Evis Cheng Date: Wed, 28 Jun 2023 11:59:27 +0800 Subject: [PATCH 3/3] pr feedback --- packages/client/lib/client/commands.ts | 2 +- packages/client/lib/commands/WAITAOF.spec.ts | 4 ++-- packages/client/lib/commands/WAITAOF.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/client/lib/client/commands.ts b/packages/client/lib/client/commands.ts index a7958fedcab..50034209d79 100644 --- a/packages/client/lib/client/commands.ts +++ b/packages/client/lib/client/commands.ts @@ -361,5 +361,5 @@ export default { WAIT, wait: WAIT, WAITAOF, - waitaof: WAITAOF + waitAOF: WAITAOF }; diff --git a/packages/client/lib/commands/WAITAOF.spec.ts b/packages/client/lib/commands/WAITAOF.spec.ts index 1515ca902f8..3083cf954b4 100644 --- a/packages/client/lib/commands/WAITAOF.spec.ts +++ b/packages/client/lib/commands/WAITAOF.spec.ts @@ -16,8 +16,8 @@ describe('WAITAOF', () => { testUtils.testWithClient('client.wait', async client => { assert.equal( - await client.waitaof(1, 0, 0), + await client.waitAOF(1, 0, 0), [1, 0] ); }, GLOBAL.SERVERS.OPEN); -}); \ No newline at end of file +}); diff --git a/packages/client/lib/commands/WAITAOF.ts b/packages/client/lib/commands/WAITAOF.ts index a8ee730375a..080d2f251ca 100644 --- a/packages/client/lib/commands/WAITAOF.ts +++ b/packages/client/lib/commands/WAITAOF.ts @@ -13,4 +13,4 @@ export function transformArguments( ]; } -export declare function transformReply(): Array<[number, number]>; \ No newline at end of file +export declare function transformReply(): Array<[number, number]>;