Skip to content

Support CLUSTER commands #2015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Mar 28, 2022
45 changes: 42 additions & 3 deletions packages/client/lib/client/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,24 @@ import * as CLIENT_KILL from '../commands/CLIENT_KILL';
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_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_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_NODES from '../commands/CLUSTER_NODES';
import * as CLUSTER_KEYSLOT from '../commands/CLUSTER_KEYSLOT';
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';
Expand Down Expand Up @@ -131,16 +144,42 @@ export default {
clientInfo: CLIENT_INFO,
CLUSTER_ADDSLOTS,
clusterAddSlots: CLUSTER_ADDSLOTS,
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_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_NODES,
clusterNodes: CLUSTER_NODES,
CLUSTER_KEYSLOT,
clusterKeySlot: CLUSTER_KEYSLOT,
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,
Expand Down
19 changes: 19 additions & 0 deletions packages/client/lib/commands/CLUSTER_BUMPEPOCH.spec.ts
Original file line number Diff line number Diff line change
@@ -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('cluster.clusterBumpEpoch', async cluster => {
assert.equal(
typeof await cluster.getSlotMaster(0).client.clusterBumpEpoch(),
'string'
);
}, GLOBAL.SERVERS.OPEN);
});
5 changes: 5 additions & 0 deletions packages/client/lib/commands/CLUSTER_BUMPEPOCH.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function transformArguments(): Array<string> {
return ['CLUSTER', 'BUMPEPOCH'];
}

export declare function transformReply(): string;
20 changes: 20 additions & 0 deletions packages/client/lib/commands/CLUSTER_COUNT-FAILURE-REPORTS.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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('1'),
['CLUSTER', 'COUNT-FAILURE-REPORTS', '1']
);
});

testUtils.testWithCluster('cluster.clusterCountFailureReports', async cluster => {
const id: string = await cluster.getSlotMaster(0).client.clusterMyId();
assert.equal(
await cluster.getSlotMaster(0).client.clusterCountFailureReports(id),
0
);
}, GLOBAL.CLUSTERS.OPEN);
});
5 changes: 5 additions & 0 deletions packages/client/lib/commands/CLUSTER_COUNT-FAILURE-REPORTS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function transformArguments(nodeId: string): Array<string> {
return ['CLUSTER', 'COUNT-FAILURE-REPORTS', nodeId];
}

export declare function transformReply(): number;
19 changes: 19 additions & 0 deletions packages/client/lib/commands/CLUSTER_COUNTKEYSINSLOT.spec.ts
Original file line number Diff line number Diff line change
@@ -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(1),
['CLUSTER', 'COUNTKEYSINSLOT', '1']
);
});

testUtils.testWithCluster('cluster.clusterInfo', async cluster => {
assert.equal(
typeof await cluster.getSlotMaster(0).client.clusterCountKeysInSlot(1),
'number'
);
}, GLOBAL.CLUSTERS.OPEN);
});
5 changes: 5 additions & 0 deletions packages/client/lib/commands/CLUSTER_COUNTKEYSINSLOT.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function transformArguments(slot: number): Array<string> {
return ['CLUSTER', 'COUNTKEYSINSLOT', slot.toString()];
}

export declare function transformReply(): number;
11 changes: 11 additions & 0 deletions packages/client/lib/commands/CLUSTER_DELSLOTS.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { strict as assert } from 'assert';
import { transformArguments } from './CLUSTER_DELSLOTS';

describe('CLUSTER DELSLOTS', () => {
it('simple', () => {
assert.deepEqual(
transformArguments('1'),
['CLUSTER', 'DELSLOTS', '1']
);
});
});
7 changes: 7 additions & 0 deletions packages/client/lib/commands/CLUSTER_DELSLOTS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function transformArguments(...slots: string[]): Array<string> {
const args = ['CLUSTER', 'DELSLOTS'];
args.push(...slots);
return args;
}

export declare function transformReply(): string;
19 changes: 19 additions & 0 deletions packages/client/lib/commands/CLUSTER_FAILOVER.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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']
);
});
});
});
16 changes: 16 additions & 0 deletions packages/client/lib/commands/CLUSTER_FAILOVER.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export enum FailoverModes {
FORCE = 'FORCE',
TAKEOVER = 'TAKEOVER'
}

export function transformArguments(mode?: FailoverModes): Array<string> {
const args = ['CLUSTER', 'FAILOVER'];

if (mode) {
args.push(mode);
}

return args;
}

export declare function transformReply(): string;
11 changes: 11 additions & 0 deletions packages/client/lib/commands/CLUSTER_FORGET.spec.ts
Original file line number Diff line number Diff line change
@@ -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']
);
});
});
5 changes: 5 additions & 0 deletions packages/client/lib/commands/CLUSTER_FORGET.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function transformArguments(nodeId: string): Array<string> {
return ['CLUSTER', 'FORGET', nodeId];
}

export declare function transformReply(): string;
8 changes: 8 additions & 0 deletions packages/client/lib/commands/CLUSTER_INFO.spec.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -43,4 +44,11 @@ describe('CLUSTER INFO', () => {
}
);
});

testUtils.testWithCluster('cluster.clusterInfo', async cluster => {
assert.notEqual(
await cluster.getSlotMaster(0).client.clusterInfo(),
null
);
}, GLOBAL.CLUSTERS.OPEN);
});
11 changes: 11 additions & 0 deletions packages/client/lib/commands/CLUSTER_KEYSLOT.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { strict as assert } from 'assert';
import { transformArguments } from './CLUSTER_KEYSLOT';

describe('CLUSTER KEYSLOT', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key'),
['CLUSTER', 'KEYSLOT', 'key']
);
});
});
5 changes: 5 additions & 0 deletions packages/client/lib/commands/CLUSTER_KEYSLOT.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function transformArguments(key: string): Array<string> {
return ['CLUSTER', 'KEYSLOT', key];
}

export declare function transformReply(): number;
19 changes: 19 additions & 0 deletions packages/client/lib/commands/CLUSTER_MYID.spec.ts
Original file line number Diff line number Diff line change
@@ -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('cluster.clusterMyId', async cluster => {
assert.notEqual(
await cluster.getSlotMaster(0).client.clusterMyId(),
null
);
}, GLOBAL.CLUSTERS.OPEN);
});
5 changes: 5 additions & 0 deletions packages/client/lib/commands/CLUSTER_MYID.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function transformArguments(): Array<string> {
return ['CLUSTER', 'MYID'];
}

export declare function transformReply(): string;
11 changes: 11 additions & 0 deletions packages/client/lib/commands/CLUSTER_REPLICAS.spec.ts
Original file line number Diff line number Diff line change
@@ -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']
);
});
});
5 changes: 5 additions & 0 deletions packages/client/lib/commands/CLUSTER_REPLICAS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function transformArguments(nodeId: string): Array<string> {
return ['CLUSTER', 'REPLICAS', nodeId];
}

export { transformReply } from './CLUSTER_NODES'
11 changes: 11 additions & 0 deletions packages/client/lib/commands/CLUSTER_REPLICATE.spec.ts
Original file line number Diff line number Diff line change
@@ -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']
);
});
});
5 changes: 5 additions & 0 deletions packages/client/lib/commands/CLUSTER_REPLICATE.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function transformArguments(nodeId: string): Array<string> {
return ['CLUSTER', 'REPLICATE', nodeId];
}

export declare function transformReply(): string;
19 changes: 19 additions & 0 deletions packages/client/lib/commands/CLUSTER_SAVECONFIG.spec.ts
Original file line number Diff line number Diff line change
@@ -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('cluster.clusterSaveConfig', async cluster => {
assert.equal(
await cluster.getSlotMaster(0).client.clusterSaveConfig(),
'OK'
);
}, GLOBAL.CLUSTERS.OPEN);
});
5 changes: 5 additions & 0 deletions packages/client/lib/commands/CLUSTER_SAVECONFIG.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function transformArguments(): Array<string> {
return ['CLUSTER', 'SAVECONFIG'];
}

export declare function transformReply(): string;
23 changes: 23 additions & 0 deletions packages/client/lib/commands/CLUSTER_SET-CONFIG-EPOCH.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './CLUSTER_SET-CONFIG-EPOCH';

describe('CLUSTER SET-CONFIG-EPOCH', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments(0),
['CLUSTER', 'SET-CONFIG-EPOCH', '0']
);
});

testUtils.testWithCluster('cluster.clusterSetConfigEpoch', async cluster => {
try {
assert.equal(
await cluster.getSlotMaster(0).client.clusterSetConfigEpoch(1),
'OK'
);
} catch (ReplyError) {
//?
}
}, GLOBAL.CLUSTERS.OPEN);
});
5 changes: 5 additions & 0 deletions packages/client/lib/commands/CLUSTER_SET-CONFIG-EPOCH.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function transformArguments(configEpoch: number): Array<string> {
return ['CLUSTER', 'SET-CONFIG-EPOCH', configEpoch.toString()];
}

export declare function transformReply(): string;