From 8ecfd3ebda1efafb1ced06fca29ca1bc57d1163f Mon Sep 17 00:00:00 2001 From: Evis Cheng Date: Tue, 19 Sep 2023 07:31:03 +0800 Subject: [PATCH] Add support for `CLUSTER MYSHARDID` (#2528) * Add support for CLUSTER.MYSHARDID command * Update CLUSTER_MYSHARDID.ts * Update CLUSTER_MYSHARDID.spec.ts * add test and clean code --------- Co-authored-by: Leibale Eidelman --- packages/client/lib/client/commands.ts | 3 +++ .../lib/commands/CLUSTER_MYSHARDID.spec.ts | 22 +++++++++++++++++++ .../client/lib/commands/CLUSTER_MYSHARDID.ts | 7 ++++++ 3 files changed, 32 insertions(+) create mode 100644 packages/client/lib/commands/CLUSTER_MYSHARDID.spec.ts create mode 100644 packages/client/lib/commands/CLUSTER_MYSHARDID.ts diff --git a/packages/client/lib/client/commands.ts b/packages/client/lib/client/commands.ts index 8cab10e218..278039166e 100644 --- a/packages/client/lib/client/commands.ts +++ b/packages/client/lib/client/commands.ts @@ -46,6 +46,7 @@ import * as CLUSTER_KEYSLOT from '../commands/CLUSTER_KEYSLOT'; import * as CLUSTER_LINKS from '../commands/CLUSTER_LINKS'; import * as CLUSTER_MEET from '../commands/CLUSTER_MEET'; import * as CLUSTER_MYID from '../commands/CLUSTER_MYID'; +import * as CLUSTER_MYSHARDID from '../commands/CLUSTER_MYSHARDID'; import * as CLUSTER_NODES from '../commands/CLUSTER_NODES'; import * as CLUSTER_REPLICAS from '../commands/CLUSTER_REPLICAS'; import * as CLUSTER_REPLICATE from '../commands/CLUSTER_REPLICATE'; @@ -216,6 +217,8 @@ export default { clusterMeet: CLUSTER_MEET, CLUSTER_MYID, clusterMyId: CLUSTER_MYID, + CLUSTER_MYSHARDID, + clusterMyShardId: CLUSTER_MYSHARDID, CLUSTER_NODES, clusterNodes: CLUSTER_NODES, CLUSTER_REPLICAS, diff --git a/packages/client/lib/commands/CLUSTER_MYSHARDID.spec.ts b/packages/client/lib/commands/CLUSTER_MYSHARDID.spec.ts new file mode 100644 index 0000000000..180289870c --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_MYSHARDID.spec.ts @@ -0,0 +1,22 @@ +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import { transformArguments } from './CLUSTER_MYSHARDID'; + +describe('CLUSTER MYSHARDID', () => { + testUtils.isVersionGreaterThanHook([7, 2]); + + it('transformArguments', () => { + assert.deepEqual( + transformArguments(), + ['CLUSTER', 'MYSHARDID'] + ); + }); + + testUtils.testWithCluster('clusterNode.clusterMyShardId', async cluster => { + const client = await cluster.nodeClient(cluster.masters[0]); + assert.equal( + typeof await client.clusterMyShardId(), + 'string' + ); + }, GLOBAL.CLUSTERS.OPEN); +}); diff --git a/packages/client/lib/commands/CLUSTER_MYSHARDID.ts b/packages/client/lib/commands/CLUSTER_MYSHARDID.ts new file mode 100644 index 0000000000..1c4f8b82f5 --- /dev/null +++ b/packages/client/lib/commands/CLUSTER_MYSHARDID.ts @@ -0,0 +1,7 @@ +export const IS_READ_ONLY = true; + +export function transformArguments() { + return ['CLUSTER', 'MYSHARDID']; +} + +export declare function transformReply(): string | Buffer;