diff --git a/packages/client/lib/client/commands.ts b/packages/client/lib/client/commands.ts index 41c0769e296..b03cc83230a 100644 --- a/packages/client/lib/client/commands.ts +++ b/packages/client/lib/client/commands.ts @@ -24,13 +24,26 @@ import * as CLIENT_SETNAME from '../commands/CLIENT_SETNAME'; import * as CLIENT_INFO from '../commands/CLIENT_INFO'; import * as CLUSTER_ADDSLOTS from '../commands/CLUSTER_ADDSLOTS'; import * as CLUSTER_ADDSLOTSRANGE from '../commands/CLUSTER_ADDSLOTSRANGE'; +import * as CLUSTER_BUMPEPOCH from '../commands/CLUSTER_BUMPEPOCH'; +import * as CLUSTER_COUNT_FAILURE_REPORTS from '../commands/CLUSTER_COUNT-FAILURE-REPORTS'; +import * as CLUSTER_COUNTKEYSINSLOT from '../commands/CLUSTER_COUNTKEYSINSLOT'; +import * as CLUSTER_DELSLOTS from '../commands/CLUSTER_DELSLOTS'; import * as CLUSTER_DELSLOTSRANGE from '../commands/CLUSTER_DELSLOTSRANGE'; +import * as CLUSTER_FAILOVER from '../commands/CLUSTER_FAILOVER'; import * as CLUSTER_FLUSHSLOTS from '../commands/CLUSTER_FLUSHSLOTS'; +import * as CLUSTER_FORGET from '../commands/CLUSTER_FORGET'; +import * as CLUSTER_GETKEYSINSLOT from '../commands/CLUSTER_GETKEYSINSLOT'; import * as CLUSTER_INFO from '../commands/CLUSTER_INFO'; +import * as CLUSTER_KEYSLOT from '../commands/CLUSTER_KEYSLOT'; import * as CLUSTER_LINKS from '../commands/CLUSTER_LINKS'; -import * as CLUSTER_NODES from '../commands/CLUSTER_NODES'; import * as CLUSTER_MEET from '../commands/CLUSTER_MEET'; +import * as CLUSTER_MYID from '../commands/CLUSTER_MYID'; +import * as CLUSTER_NODES from '../commands/CLUSTER_NODES'; +import * as CLUSTER_REPLICAS from '../commands/CLUSTER_REPLICAS'; +import * as CLUSTER_REPLICATE from '../commands/CLUSTER_REPLICATE'; import * as CLUSTER_RESET from '../commands/CLUSTER_RESET'; +import * as CLUSTER_SAVECONFIG from '../commands/CLUSTER_SAVECONFIG'; +import * as CLUSTER_SET_CONFIG_EPOCH from '../commands/CLUSTER_SET-CONFIG-EPOCH'; import * as CLUSTER_SETSLOT from '../commands/CLUSTER_SETSLOT'; import * as CLUSTER_SLOTS from '../commands/CLUSTER_SLOTS'; import * as COMMAND_COUNT from '../commands/COMMAND_COUNT'; @@ -138,20 +151,46 @@ export default { clusterAddSlots: CLUSTER_ADDSLOTS, CLUSTER_ADDSLOTSRANGE, clusterAddSlotsRange: CLUSTER_ADDSLOTSRANGE, + CLUSTER_BUMPEPOCH, + clusterBumpEpoch: CLUSTER_BUMPEPOCH, + CLUSTER_COUNT_FAILURE_REPORTS, + clusterCountFailureReports: CLUSTER_COUNT_FAILURE_REPORTS, + CLUSTER_COUNTKEYSINSLOT, + clusterCountKeysInSlot: CLUSTER_COUNTKEYSINSLOT, + CLUSTER_DELSLOTS, + clusterDelSlots: CLUSTER_DELSLOTS, CLUSTER_DELSLOTSRANGE, clusterDelSlotsRange: CLUSTER_DELSLOTSRANGE, + CLUSTER_FAILOVER, + clusterFailover: CLUSTER_FAILOVER, CLUSTER_FLUSHSLOTS, clusterFlushSlots: CLUSTER_FLUSHSLOTS, + CLUSTER_FORGET, + clusterForget: CLUSTER_FORGET, + CLUSTER_GETKEYSINSLOT, + clusterGetKeysInSlot: CLUSTER_GETKEYSINSLOT, CLUSTER_INFO, clusterInfo: CLUSTER_INFO, + CLUSTER_KEYSLOT, + clusterKeySlot: CLUSTER_KEYSLOT, CLUSTER_LINKS, clusterLinks: CLUSTER_LINKS, - CLUSTER_NODES, - clusterNodes: CLUSTER_NODES, CLUSTER_MEET, clusterMeet: CLUSTER_MEET, + CLUSTER_MYID, + clusterMyId: CLUSTER_MYID, + CLUSTER_NODES, + clusterNodes: CLUSTER_NODES, + CLUSTER_REPLICAS, + clusterReplicas: CLUSTER_REPLICAS, + CLUSTER_REPLICATE, + clusterReplicate: CLUSTER_REPLICATE, CLUSTER_RESET, clusterReset: CLUSTER_RESET, + CLUSTER_SAVECONFIG, + clusterSaveConfig: CLUSTER_SAVECONFIG, + CLUSTER_SET_CONFIG_EPOCH, + clusterSetConfigEpoch: CLUSTER_SET_CONFIG_EPOCH, CLUSTER_SETSLOT, clusterSetSlot: CLUSTER_SETSLOT, CLUSTER_SLOTS, diff --git a/packages/client/lib/commands/CLUSTER_ADDSLOTS.ts b/packages/client/lib/commands/CLUSTER_ADDSLOTS.ts index e458b8aab91..6cd357fb823 100644 --- a/packages/client/lib/commands/CLUSTER_ADDSLOTS.ts +++ b/packages/client/lib/commands/CLUSTER_ADDSLOTS.ts @@ -1,13 +1,11 @@ -export function transformArguments(slots: number | Array): Array { - const args = ['CLUSTER', 'ADDSLOTS']; +import { RedisCommandArguments } from '.'; +import { pushVerdictNumberArguments } from './generic-transformers'; - if (typeof slots === 'number') { - args.push(slots.toString()); - } else { - args.push(...slots.map(String)); - } - - return args; +export function transformArguments(slots: number | Array): RedisCommandArguments { + return pushVerdictNumberArguments( + ['CLUSTER', 'ADDSLOTS'], + slots + ); } export declare function transformReply(): string; diff --git a/packages/client/lib/commands/CLUSTER_BUMPEPOCH.spec.ts b/packages/client/lib/commands/CLUSTER_BUMPEPOCH.spec.ts new file mode 100644 index 00000000000..f9d2f5437b2 --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_BUMPEPOCH.spec.ts @@ -0,0 +1,19 @@ +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import { transformArguments } from './CLUSTER_BUMPEPOCH'; + +describe('CLUSTER BUMPEPOCH', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments(), + ['CLUSTER', 'BUMPEPOCH'] + ); + }); + + testUtils.testWithCluster('clusterNode.clusterBumpEpoch', async cluster => { + assert.equal( + typeof await cluster.getSlotMaster(0).client.clusterBumpEpoch(), + 'string' + ); + }, GLOBAL.SERVERS.OPEN); +}); diff --git a/packages/client/lib/commands/CLUSTER_BUMPEPOCH.ts b/packages/client/lib/commands/CLUSTER_BUMPEPOCH.ts new file mode 100644 index 00000000000..7f81c8fdc42 --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_BUMPEPOCH.ts @@ -0,0 +1,5 @@ +export function transformArguments(): Array { + return ['CLUSTER', 'BUMPEPOCH']; +} + +export declare function transformReply(): 'BUMPED' | 'STILL'; diff --git a/packages/client/lib/commands/CLUSTER_COUNT-FAILURE-REPORTS.spec.ts b/packages/client/lib/commands/CLUSTER_COUNT-FAILURE-REPORTS.spec.ts new file mode 100644 index 00000000000..d84687631bc --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_COUNT-FAILURE-REPORTS.spec.ts @@ -0,0 +1,22 @@ +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import { transformArguments } from './CLUSTER_COUNT-FAILURE-REPORTS'; + +describe('CLUSTER COUNT-FAILURE-REPORTS', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('0'), + ['CLUSTER', 'COUNT-FAILURE-REPORTS', '0'] + ); + }); + + testUtils.testWithCluster('clusterNode.clusterCountFailureReports', async cluster => { + const { client } = cluster.getSlotMaster(0); + assert.equal( + typeof await client.clusterCountFailureReports( + await client.clusterMyId() + ), + 'number' + ); + }, GLOBAL.CLUSTERS.OPEN); +}); diff --git a/packages/client/lib/commands/CLUSTER_COUNT-FAILURE-REPORTS.ts b/packages/client/lib/commands/CLUSTER_COUNT-FAILURE-REPORTS.ts new file mode 100644 index 00000000000..3fbc33052f8 --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_COUNT-FAILURE-REPORTS.ts @@ -0,0 +1,5 @@ +export function transformArguments(nodeId: string): Array { + return ['CLUSTER', 'COUNT-FAILURE-REPORTS', nodeId]; +} + +export declare function transformReply(): number; diff --git a/packages/client/lib/commands/CLUSTER_COUNTKEYSINSLOT.spec.ts b/packages/client/lib/commands/CLUSTER_COUNTKEYSINSLOT.spec.ts new file mode 100644 index 00000000000..ecaed428cb7 --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_COUNTKEYSINSLOT.spec.ts @@ -0,0 +1,19 @@ +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import { transformArguments } from './CLUSTER_COUNTKEYSINSLOT'; + +describe('CLUSTER COUNTKEYSINSLOT', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments(0), + ['CLUSTER', 'COUNTKEYSINSLOT', '0'] + ); + }); + + testUtils.testWithCluster('clusterNode.clusterCountKeysInSlot', async cluster => { + assert.equal( + typeof await cluster.getSlotMaster(0).client.clusterCountKeysInSlot(0), + 'number' + ); + }, GLOBAL.CLUSTERS.OPEN); +}); diff --git a/packages/client/lib/commands/CLUSTER_COUNTKEYSINSLOT.ts b/packages/client/lib/commands/CLUSTER_COUNTKEYSINSLOT.ts new file mode 100644 index 00000000000..a5ff75e58a9 --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_COUNTKEYSINSLOT.ts @@ -0,0 +1,5 @@ +export function transformArguments(slot: number): Array { + return ['CLUSTER', 'COUNTKEYSINSLOT', slot.toString()]; +} + +export declare function transformReply(): number; diff --git a/packages/client/lib/commands/CLUSTER_DELSLOTS.spec.ts b/packages/client/lib/commands/CLUSTER_DELSLOTS.spec.ts new file mode 100644 index 00000000000..85d13f4ed3d --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_DELSLOTS.spec.ts @@ -0,0 +1,20 @@ +import { strict as assert } from 'assert'; +import { transformArguments } from './CLUSTER_DELSLOTS'; + +describe('CLUSTER DELSLOTS', () => { + describe('transformArguments', () => { + it('single', () => { + assert.deepEqual( + transformArguments(0), + ['CLUSTER', 'DELSLOTS', '0'] + ); + }); + + it('multiple', () => { + assert.deepEqual( + transformArguments([0, 1]), + ['CLUSTER', 'DELSLOTS', '0', '1'] + ); + }); + }); +}); diff --git a/packages/client/lib/commands/CLUSTER_DELSLOTS.ts b/packages/client/lib/commands/CLUSTER_DELSLOTS.ts new file mode 100644 index 00000000000..bf8d9c18900 --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_DELSLOTS.ts @@ -0,0 +1,11 @@ +import { RedisCommandArguments } from '.'; +import { pushVerdictNumberArguments } from './generic-transformers'; + +export function transformArguments(slots: number | Array): RedisCommandArguments { + return pushVerdictNumberArguments( + ['CLUSTER', 'DELSLOTS'], + slots + ); +} + +export declare function transformReply(): 'OK'; diff --git a/packages/client/lib/commands/CLUSTER_FAILOVER.spec.ts b/packages/client/lib/commands/CLUSTER_FAILOVER.spec.ts new file mode 100644 index 00000000000..578ff56b9cd --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_FAILOVER.spec.ts @@ -0,0 +1,20 @@ +import { strict as assert } from 'assert'; +import { FailoverModes, transformArguments } from './CLUSTER_FAILOVER'; + +describe('CLUSTER FAILOVER', () => { + describe('transformArguments', () => { + it('simple', () => { + assert.deepEqual( + transformArguments(), + ['CLUSTER', 'FAILOVER'] + ); + }); + + it('with mode', () => { + assert.deepEqual( + transformArguments(FailoverModes.FORCE), + ['CLUSTER', 'FAILOVER', 'FORCE'] + ); + }); + }); +}); diff --git a/packages/client/lib/commands/CLUSTER_FAILOVER.ts b/packages/client/lib/commands/CLUSTER_FAILOVER.ts new file mode 100644 index 00000000000..9bc4b69f343 --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_FAILOVER.ts @@ -0,0 +1,16 @@ +export enum FailoverModes { + FORCE = 'FORCE', + TAKEOVER = 'TAKEOVER' +} + +export function transformArguments(mode?: FailoverModes): Array { + const args = ['CLUSTER', 'FAILOVER']; + + if (mode) { + args.push(mode); + } + + return args; +} + +export declare function transformReply(): 'OK'; diff --git a/packages/client/lib/commands/CLUSTER_FLUSHSLOTS.ts b/packages/client/lib/commands/CLUSTER_FLUSHSLOTS.ts index 285c9fd26fe..dfb1e1ccde8 100644 --- a/packages/client/lib/commands/CLUSTER_FLUSHSLOTS.ts +++ b/packages/client/lib/commands/CLUSTER_FLUSHSLOTS.ts @@ -2,4 +2,4 @@ export function transformArguments(): Array { return ['CLUSTER', 'FLUSHSLOTS']; } -export declare function transformReply(): string; +export declare function transformReply(): 'OK'; diff --git a/packages/client/lib/commands/CLUSTER_FORGET.spec.ts b/packages/client/lib/commands/CLUSTER_FORGET.spec.ts new file mode 100644 index 00000000000..cadcdb678f3 --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_FORGET.spec.ts @@ -0,0 +1,11 @@ +import { strict as assert } from 'assert'; +import { transformArguments } from './CLUSTER_FORGET'; + +describe('CLUSTER FORGET', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('0'), + ['CLUSTER', 'FORGET', '0'] + ); + }); +}); diff --git a/packages/client/lib/commands/CLUSTER_FORGET.ts b/packages/client/lib/commands/CLUSTER_FORGET.ts new file mode 100644 index 00000000000..fc557073aeb --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_FORGET.ts @@ -0,0 +1,5 @@ +export function transformArguments(nodeId: string): Array { + return ['CLUSTER', 'FORGET', nodeId]; +} + +export declare function transformReply(): 'OK'; diff --git a/packages/client/lib/commands/CLUSTER_GETKEYSINSLOT.spec.ts b/packages/client/lib/commands/CLUSTER_GETKEYSINSLOT.spec.ts index bb20f7521de..7c156341301 100644 --- a/packages/client/lib/commands/CLUSTER_GETKEYSINSLOT.spec.ts +++ b/packages/client/lib/commands/CLUSTER_GETKEYSINSLOT.spec.ts @@ -1,4 +1,5 @@ import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; import { transformArguments } from './CLUSTER_GETKEYSINSLOT'; describe('CLUSTER GETKEYSINSLOT', () => { @@ -8,4 +9,12 @@ describe('CLUSTER GETKEYSINSLOT', () => { ['CLUSTER', 'GETKEYSINSLOT', '0', '10'] ); }); + + testUtils.testWithCluster('clusterNode.clusterGetKeysInSlot', async cluster => { + const reply = await cluster.getSlotMaster(0).client.clusterGetKeysInSlot(0, 1); + assert.ok(Array.isArray(reply)); + for (const item of reply) { + assert.equal(typeof item, 'string'); + } + }, GLOBAL.CLUSTERS.OPEN); }); diff --git a/packages/client/lib/commands/CLUSTER_GETKEYSINSLOT.ts b/packages/client/lib/commands/CLUSTER_GETKEYSINSLOT.ts index 67c5cbafb77..ec75b7b7336 100644 --- a/packages/client/lib/commands/CLUSTER_GETKEYSINSLOT.ts +++ b/packages/client/lib/commands/CLUSTER_GETKEYSINSLOT.ts @@ -2,4 +2,4 @@ export function transformArguments(slot: number, count: number): Array { return ['CLUSTER', 'GETKEYSINSLOT', slot.toString(), count.toString()]; } -export declare function transformReply(): string; +export declare function transformReply(): Array; diff --git a/packages/client/lib/commands/CLUSTER_INFO.spec.ts b/packages/client/lib/commands/CLUSTER_INFO.spec.ts index a4def45cb79..b770ed33616 100644 --- a/packages/client/lib/commands/CLUSTER_INFO.spec.ts +++ b/packages/client/lib/commands/CLUSTER_INFO.spec.ts @@ -1,4 +1,5 @@ import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; import { transformArguments, transformReply } from './CLUSTER_INFO'; describe('CLUSTER INFO', () => { @@ -43,4 +44,11 @@ describe('CLUSTER INFO', () => { } ); }); + + testUtils.testWithCluster('clusterNode.clusterInfo', async cluster => { + assert.notEqual( + await cluster.getSlotMaster(0).client.clusterInfo(), + null + ); + }, GLOBAL.CLUSTERS.OPEN); }); diff --git a/packages/client/lib/commands/CLUSTER_KEYSLOT.spec.ts b/packages/client/lib/commands/CLUSTER_KEYSLOT.spec.ts new file mode 100644 index 00000000000..a7a5ab9472f --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_KEYSLOT.spec.ts @@ -0,0 +1,19 @@ +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import { transformArguments } from './CLUSTER_KEYSLOT'; + +describe('CLUSTER KEYSLOT', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('key'), + ['CLUSTER', 'KEYSLOT', 'key'] + ); + }); + + testUtils.testWithCluster('clusterNode.clusterKeySlot', async cluster => { + assert.equal( + typeof await cluster.getSlotMaster(0).client.clusterKeySlot('key'), + 'number' + ); + }, GLOBAL.CLUSTERS.OPEN); +}); diff --git a/packages/client/lib/commands/CLUSTER_KEYSLOT.ts b/packages/client/lib/commands/CLUSTER_KEYSLOT.ts new file mode 100644 index 00000000000..0af524ff128 --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_KEYSLOT.ts @@ -0,0 +1,5 @@ +export function transformArguments(key: string): Array { + return ['CLUSTER', 'KEYSLOT', key]; +} + +export declare function transformReply(): number; diff --git a/packages/client/lib/commands/CLUSTER_MEET.ts b/packages/client/lib/commands/CLUSTER_MEET.ts index 54a0bf708a8..e6ce1c1fce4 100644 --- a/packages/client/lib/commands/CLUSTER_MEET.ts +++ b/packages/client/lib/commands/CLUSTER_MEET.ts @@ -2,4 +2,4 @@ export function transformArguments(ip: string, port: number): Array { return ['CLUSTER', 'MEET', ip, port.toString()]; } -export declare function transformReply(): string; +export declare function transformReply(): 'OK'; diff --git a/packages/client/lib/commands/CLUSTER_MYID.spec.ts b/packages/client/lib/commands/CLUSTER_MYID.spec.ts new file mode 100644 index 00000000000..7781c374526 --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_MYID.spec.ts @@ -0,0 +1,19 @@ +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import { transformArguments } from './CLUSTER_MYID'; + +describe('CLUSTER MYID', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments(), + ['CLUSTER', 'MYID'] + ); + }); + + testUtils.testWithCluster('clusterNode.clusterMyId', async cluster => { + assert.equal( + typeof await cluster.getSlotMaster(0).client.clusterMyId(), + 'string' + ); + }, GLOBAL.CLUSTERS.OPEN); +}); diff --git a/packages/client/lib/commands/CLUSTER_MYID.ts b/packages/client/lib/commands/CLUSTER_MYID.ts new file mode 100644 index 00000000000..2b61684634d --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_MYID.ts @@ -0,0 +1,5 @@ +export function transformArguments(): Array { + return ['CLUSTER', 'MYID']; +} + +export declare function transformReply(): string; diff --git a/packages/client/lib/commands/CLUSTER_REPLICAS.spec.ts b/packages/client/lib/commands/CLUSTER_REPLICAS.spec.ts new file mode 100644 index 00000000000..6c902dc0d82 --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_REPLICAS.spec.ts @@ -0,0 +1,11 @@ +import { strict as assert } from 'assert'; +import { transformArguments } from './CLUSTER_REPLICAS'; + +describe('CLUSTER REPLICAS', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('0'), + ['CLUSTER', 'REPLICAS', '0'] + ); + }); +}); diff --git a/packages/client/lib/commands/CLUSTER_REPLICAS.ts b/packages/client/lib/commands/CLUSTER_REPLICAS.ts new file mode 100644 index 00000000000..a4130125fbf --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_REPLICAS.ts @@ -0,0 +1,5 @@ +export function transformArguments(nodeId: string): Array { + return ['CLUSTER', 'REPLICAS', nodeId]; +} + +export { transformReply } from './CLUSTER_NODES'; diff --git a/packages/client/lib/commands/CLUSTER_REPLICATE.spec.ts b/packages/client/lib/commands/CLUSTER_REPLICATE.spec.ts new file mode 100644 index 00000000000..926b7dd0a77 --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_REPLICATE.spec.ts @@ -0,0 +1,11 @@ +import { strict as assert } from 'assert'; +import { transformArguments } from './CLUSTER_REPLICATE'; + +describe('CLUSTER REPLICATE', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('0'), + ['CLUSTER', 'REPLICATE', '0'] + ); + }); +}); diff --git a/packages/client/lib/commands/CLUSTER_REPLICATE.ts b/packages/client/lib/commands/CLUSTER_REPLICATE.ts new file mode 100644 index 00000000000..c74e1ec5960 --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_REPLICATE.ts @@ -0,0 +1,5 @@ +export function transformArguments(nodeId: string): Array { + return ['CLUSTER', 'REPLICATE', nodeId]; +} + +export declare function transformReply(): 'OK'; diff --git a/packages/client/lib/commands/CLUSTER_RESET.spec.ts b/packages/client/lib/commands/CLUSTER_RESET.spec.ts index c077e7f8874..340da7457c1 100644 --- a/packages/client/lib/commands/CLUSTER_RESET.spec.ts +++ b/packages/client/lib/commands/CLUSTER_RESET.spec.ts @@ -10,18 +10,11 @@ describe('CLUSTER RESET', () => { ); }); - it('HARD', () => { + it('with mode', () => { assert.deepEqual( transformArguments('HARD'), ['CLUSTER', 'RESET', 'HARD'] ); }); - - it('SOFT', () => { - assert.deepEqual( - transformArguments('SOFT'), - ['CLUSTER', 'RESET', 'SOFT'] - ); - }); }); }); diff --git a/packages/client/lib/commands/CLUSTER_RESET.ts b/packages/client/lib/commands/CLUSTER_RESET.ts index 3e7c5bb52fb..c6901e045dc 100644 --- a/packages/client/lib/commands/CLUSTER_RESET.ts +++ b/packages/client/lib/commands/CLUSTER_RESET.ts @@ -1,6 +1,4 @@ -export type ClusterResetModes = 'HARD' | 'SOFT'; - -export function transformArguments(mode?: ClusterResetModes): Array { +export function transformArguments(mode?: 'HARD' | 'SOFT'): Array { const args = ['CLUSTER', 'RESET']; if (mode) { diff --git a/packages/client/lib/commands/CLUSTER_SAVECONFIG.spec.ts b/packages/client/lib/commands/CLUSTER_SAVECONFIG.spec.ts new file mode 100644 index 00000000000..bcdccd90919 --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_SAVECONFIG.spec.ts @@ -0,0 +1,19 @@ +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import { transformArguments } from './CLUSTER_SAVECONFIG'; + +describe('CLUSTER SAVECONFIG', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments(), + ['CLUSTER', 'SAVECONFIG'] + ); + }); + + testUtils.testWithCluster('clusterNode.clusterSaveConfig', async cluster => { + assert.equal( + await cluster.getSlotMaster(0).client.clusterSaveConfig(), + 'OK' + ); + }, GLOBAL.CLUSTERS.OPEN); +}); diff --git a/packages/client/lib/commands/CLUSTER_SAVECONFIG.ts b/packages/client/lib/commands/CLUSTER_SAVECONFIG.ts new file mode 100644 index 00000000000..7e7fb181cc6 --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_SAVECONFIG.ts @@ -0,0 +1,5 @@ +export function transformArguments(): Array { + return ['CLUSTER', 'SAVECONFIG']; +} + +export declare function transformReply(): 'OK'; diff --git a/packages/client/lib/commands/CLUSTER_SET-CONFIG-EPOCH.spec.ts b/packages/client/lib/commands/CLUSTER_SET-CONFIG-EPOCH.spec.ts new file mode 100644 index 00000000000..dd241574168 --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_SET-CONFIG-EPOCH.spec.ts @@ -0,0 +1,11 @@ +import { strict as assert } from 'assert'; +import { transformArguments } from './CLUSTER_SET-CONFIG-EPOCH'; + +describe('CLUSTER SET-CONFIG-EPOCH', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments(0), + ['CLUSTER', 'SET-CONFIG-EPOCH', '0'] + ); + }); +}); diff --git a/packages/client/lib/commands/CLUSTER_SET-CONFIG-EPOCH.ts b/packages/client/lib/commands/CLUSTER_SET-CONFIG-EPOCH.ts new file mode 100644 index 00000000000..c50a6b9d3a5 --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_SET-CONFIG-EPOCH.ts @@ -0,0 +1,5 @@ +export function transformArguments(configEpoch: number): Array { + return ['CLUSTER', 'SET-CONFIG-EPOCH', configEpoch.toString()]; +} + +export declare function transformReply(): 'OK'; diff --git a/packages/client/lib/commands/CLUSTER_SETSLOT.ts b/packages/client/lib/commands/CLUSTER_SETSLOT.ts index 591b5fb9632..c01505c71a3 100644 --- a/packages/client/lib/commands/CLUSTER_SETSLOT.ts +++ b/packages/client/lib/commands/CLUSTER_SETSLOT.ts @@ -5,7 +5,11 @@ export enum ClusterSlotStates { NODE = 'NODE' } -export function transformArguments(slot: number, state: ClusterSlotStates, nodeId?: string): Array { +export function transformArguments( + slot: number, + state: ClusterSlotStates, + nodeId?: string +): Array { const args = ['CLUSTER', 'SETSLOT', slot.toString(), state]; if (nodeId) { @@ -15,4 +19,4 @@ export function transformArguments(slot: number, state: ClusterSlotStates, nodeI return args; } -export declare function transformReply(): string; +export declare function transformReply(): 'OK'; diff --git a/packages/client/lib/commands/CLUSTER_SLOTS.ts b/packages/client/lib/commands/CLUSTER_SLOTS.ts index afe1ebc83dd..7e1f5dcc964 100644 --- a/packages/client/lib/commands/CLUSTER_SLOTS.ts +++ b/packages/client/lib/commands/CLUSTER_SLOTS.ts @@ -6,7 +6,12 @@ export function transformArguments(): RedisCommandArguments { type ClusterSlotsRawNode = [ip: string, port: number, id: string]; -type ClusterSlotsRawReply = Array<[from: number, to: number, master: ClusterSlotsRawNode, ...replicas: Array]>; +type ClusterSlotsRawReply = Array<[ + from: number, + to: number, + master: ClusterSlotsRawNode, + ...replicas: Array +]>; type ClusterSlotsNode = { ip: string; diff --git a/packages/client/lib/commands/generic-transformers.spec.ts b/packages/client/lib/commands/generic-transformers.spec.ts index 6e286e284d9..301cab0a75c 100644 --- a/packages/client/lib/commands/generic-transformers.spec.ts +++ b/packages/client/lib/commands/generic-transformers.spec.ts @@ -19,6 +19,7 @@ import { transformPXAT, pushEvalArguments, pushVerdictArguments, + pushVerdictNumberArguments, pushVerdictArgument, pushOptionalVerdictArgument, transformCommandReply, @@ -579,6 +580,22 @@ describe('Generic Transformers', () => { }); }); + describe('pushVerdictNumberArguments', () => { + it('number', () => { + assert.deepEqual( + pushVerdictNumberArguments([], 0), + ['0'] + ); + }); + + it('array', () => { + assert.deepEqual( + pushVerdictNumberArguments([], [0, 1]), + ['0', '1'] + ); + }); + }); + describe('pushVerdictArgument', () => { it('string', () => { assert.deepEqual( diff --git a/packages/client/lib/commands/generic-transformers.ts b/packages/client/lib/commands/generic-transformers.ts index a7bc6805dde..f138cb0430b 100644 --- a/packages/client/lib/commands/generic-transformers.ts +++ b/packages/client/lib/commands/generic-transformers.ts @@ -322,6 +322,21 @@ export function pushVerdictArguments(args: RedisCommandArguments, value: RedisCo return args; } +export function pushVerdictNumberArguments( + args: RedisCommandArguments, + value: number | Array +): RedisCommandArguments { + if (Array.isArray(value)) { + for (const item of value) { + args.push(item.toString()); + } + } else { + args.push(value.toString()); + } + + return args; +} + export function pushVerdictArgument( args: RedisCommandArguments, value: RedisCommandArgument | Array