diff --git a/docs/v4-to-v5.md b/docs/v4-to-v5.md index fde8e28379..8026bf28d3 100644 --- a/docs/v4-to-v5.md +++ b/docs/v4-to-v5.md @@ -165,6 +165,9 @@ Some command arguments/replies have changed to align more closely to data types - `CLUSETER SETSLOT`: `ClusterSlotStates` -> `CLUSTER_SLOT_STATES` [^enum-to-constants] - `FUNCTION RESTORE`: the second argument is `{ mode: string; }` instead of `string` [^future-proofing] - `CLUSTER RESET`: the second argument is `{ mode: string; }` instead of `string` [^future-proofing] +- `CLUSTER FAILOVER`: `enum FailoverModes` -> `const FAILOVER_MODES` [^enum-to-constants], the second argument is `{ mode: string; }` instead of `string` [^future-proofing] +- `CLUSTER LINKS`: `createTime` -> `create-time`, `sendBufferAllocated` -> `send-buffer-allocated`, `sendBufferUsed` -> `send-buffer-used` [^map-keys] +- `TIME`: `Date` -> `[unixTimestamp: string, microseconds: string]` [^enum-to-constants]: TODO diff --git a/packages/client/lib/commands/ASKING.spec.ts b/packages/client/lib/commands/ASKING.spec.ts index 3da2015199..661a5aa7c1 100644 --- a/packages/client/lib/commands/ASKING.spec.ts +++ b/packages/client/lib/commands/ASKING.spec.ts @@ -1,11 +1,11 @@ import { strict as assert } from 'assert'; -import { transformArguments } from './ASKING'; +import ASKING from './ASKING'; describe('ASKING', () => { - it('transformArguments', () => { - assert.deepEqual( - transformArguments(), - ['ASKING'] - ); - }); + it('transformArguments', () => { + assert.deepEqual( + ASKING.transformArguments(), + ['ASKING'] + ); + }); }); diff --git a/packages/client/lib/commands/BGREWRITEAOF.spec.ts b/packages/client/lib/commands/BGREWRITEAOF.spec.ts index d0e150e155..b29e90634c 100644 --- a/packages/client/lib/commands/BGREWRITEAOF.spec.ts +++ b/packages/client/lib/commands/BGREWRITEAOF.spec.ts @@ -1,11 +1,19 @@ import { strict as assert } from 'assert'; -import { transformArguments } from './BGREWRITEAOF'; +import testUtils, { GLOBAL } from '../test-utils'; +import BGREWRITEAOF from './BGREWRITEAOF'; describe('BGREWRITEAOF', () => { - it('transformArguments', () => { - assert.deepEqual( - transformArguments(), - ['BGREWRITEAOF'] - ); - }); + it('transformArguments', () => { + assert.deepEqual( + BGREWRITEAOF.transformArguments(), + ['BGREWRITEAOF'] + ); + }); + + testUtils.testWithClient('client.bgRewriteAof', async client => { + assert.equal( + typeof await client.bgRewriteAof(), + 'string' + ); + }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/client/lib/commands/BGSAVE.spec.ts b/packages/client/lib/commands/BGSAVE.spec.ts index 8e4de5eef5..b8e82e2127 100644 --- a/packages/client/lib/commands/BGSAVE.spec.ts +++ b/packages/client/lib/commands/BGSAVE.spec.ts @@ -1,23 +1,30 @@ import { strict as assert } from 'assert'; -import { describe } from 'mocha'; -import { transformArguments } from './BGSAVE'; +import testUtils, { GLOBAL } from '../test-utils'; +import BGSAVE from './BGSAVE'; describe('BGSAVE', () => { - describe('transformArguments', () => { - it('simple', () => { - assert.deepEqual( - transformArguments(), - ['BGSAVE'] - ); - }); - - it('with SCHEDULE', () => { - assert.deepEqual( - transformArguments({ - SCHEDULE: true - }), - ['BGSAVE', 'SCHEDULE'] - ); - }); + describe('transformArguments', () => { + it('simple', () => { + assert.deepEqual( + BGSAVE.transformArguments(), + ['BGSAVE'] + ); }); + + it('with SCHEDULE', () => { + assert.deepEqual( + BGSAVE.transformArguments({ + SCHEDULE: true + }), + ['BGSAVE', 'SCHEDULE'] + ); + }); + }); + + testUtils.testWithClient('client.bgSave', async client => { + assert.equal( + typeof await client.bgSave(), + 'string' + ); + }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/client/lib/commands/BGSAVE.ts b/packages/client/lib/commands/BGSAVE.ts index 1cc60cb5da..dc0f505670 100644 --- a/packages/client/lib/commands/BGSAVE.ts +++ b/packages/client/lib/commands/BGSAVE.ts @@ -1,10 +1,20 @@ import { SimpleStringReply, Command } from '../RESP/types'; +export interface BgSaveOptions { + SCHEDULE?: boolean; +} + export default { FIRST_KEY_INDEX: undefined, IS_READ_ONLY: true, - transformArguments() { - return ['BGSAVE']; + transformArguments(options?: BgSaveOptions) { + const args = ['BGSAVE']; + + if (options?.SCHEDULE) { + args.push('SCHEDULE'); + } + + return args; }, transformReply: undefined as unknown as () => SimpleStringReply } as const satisfies Command; diff --git a/packages/client/lib/commands/CLUSTER_COUNT-FAILURE-REPORTS.spec.ts b/packages/client/lib/commands/CLUSTER_COUNT-FAILURE-REPORTS.spec.ts index 558110d0a2..68b3cde620 100644 --- a/packages/client/lib/commands/CLUSTER_COUNT-FAILURE-REPORTS.spec.ts +++ b/packages/client/lib/commands/CLUSTER_COUNT-FAILURE-REPORTS.spec.ts @@ -1,22 +1,21 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; -import { transformArguments } from './CLUSTER_COUNT-FAILURE-REPORTS'; +import CLUSTER_COUNT_FAILURE_REPORTS from './CLUSTER_COUNT-FAILURE-REPORTS'; describe('CLUSTER COUNT-FAILURE-REPORTS', () => { - it('transformArguments', () => { - assert.deepEqual( - transformArguments('0'), - ['CLUSTER', 'COUNT-FAILURE-REPORTS', '0'] - ); - }); + it('transformArguments', () => { + assert.deepEqual( + CLUSTER_COUNT_FAILURE_REPORTS.transformArguments('0'), + ['CLUSTER', 'COUNT-FAILURE-REPORTS', '0'] + ); + }); - testUtils.testWithCluster('clusterNode.clusterCountFailureReports', async cluster => { - const client = await cluster.nodeClient(cluster.masters[0]); - assert.equal( - typeof await client.clusterCountFailureReports( - await client.clusterMyId() - ), - 'number' - ); - }, GLOBAL.CLUSTERS.OPEN); + testUtils.testWithCluster('clusterNode.clusterCountFailureReports', async cluster => { + const [master] = cluster.masters, + client = await cluster.nodeClient(master); + assert.equal( + typeof await client.clusterCountFailureReports(master.id), + 'number' + ); + }, GLOBAL.CLUSTERS.OPEN); }); diff --git a/packages/client/lib/commands/CLUSTER_COUNTKEYSINSLOT.spec.ts b/packages/client/lib/commands/CLUSTER_COUNTKEYSINSLOT.spec.ts index 27ecbcfffa..2faa95c080 100644 --- a/packages/client/lib/commands/CLUSTER_COUNTKEYSINSLOT.spec.ts +++ b/packages/client/lib/commands/CLUSTER_COUNTKEYSINSLOT.spec.ts @@ -1,20 +1,20 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; -import { transformArguments } from './CLUSTER_COUNTKEYSINSLOT'; +import CLUSTER_COUNTKEYSINSLOT from './CLUSTER_COUNTKEYSINSLOT'; describe('CLUSTER COUNTKEYSINSLOT', () => { - it('transformArguments', () => { - assert.deepEqual( - transformArguments(0), - ['CLUSTER', 'COUNTKEYSINSLOT', '0'] - ); - }); + it('transformArguments', () => { + assert.deepEqual( + CLUSTER_COUNTKEYSINSLOT.transformArguments(0), + ['CLUSTER', 'COUNTKEYSINSLOT', '0'] + ); + }); - testUtils.testWithCluster('clusterNode.clusterCountKeysInSlot', async cluster => { - const client = await cluster.nodeClient(cluster.masters[0]); - assert.equal( - typeof await client.clusterCountKeysInSlot(0), - 'number' - ); - }, GLOBAL.CLUSTERS.OPEN); + testUtils.testWithCluster('clusterNode.clusterCountKeysInSlot', async cluster => { + const client = await cluster.nodeClient(cluster.masters[0]); + assert.equal( + typeof await 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 index 2892c2aae2..61f46230e8 100644 --- a/packages/client/lib/commands/CLUSTER_COUNTKEYSINSLOT.ts +++ b/packages/client/lib/commands/CLUSTER_COUNTKEYSINSLOT.ts @@ -4,7 +4,7 @@ export default { FIRST_KEY_INDEX: undefined, IS_READ_ONLY: true, transformArguments(slot: number) { - return ['CLUSTER', 'COUNT-FAILURE-REPORTS', slot.toString()]; + return ['CLUSTER', 'COUNTKEYSINSLOT', slot.toString()]; }, transformReply: undefined as unknown as () => NumberReply } as const satisfies Command; diff --git a/packages/client/lib/commands/CLUSTER_DELSLOTS.spec.ts b/packages/client/lib/commands/CLUSTER_DELSLOTS.spec.ts index 85d13f4ed3..85a188c31e 100644 --- a/packages/client/lib/commands/CLUSTER_DELSLOTS.spec.ts +++ b/packages/client/lib/commands/CLUSTER_DELSLOTS.spec.ts @@ -1,20 +1,20 @@ import { strict as assert } from 'assert'; -import { transformArguments } from './CLUSTER_DELSLOTS'; +import CLUSTER_DELSLOTS 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'] - ); - }); + describe('transformArguments', () => { + it('single', () => { + assert.deepEqual( + CLUSTER_DELSLOTS.transformArguments(0), + ['CLUSTER', 'DELSLOTS', '0'] + ); }); + + it('multiple', () => { + assert.deepEqual( + CLUSTER_DELSLOTS.transformArguments([0, 1]), + ['CLUSTER', 'DELSLOTS', '0', '1'] + ); + }); + }); }); diff --git a/packages/client/lib/commands/CLUSTER_DELSLOTSRANGE.spec.ts b/packages/client/lib/commands/CLUSTER_DELSLOTSRANGE.spec.ts index 8fd50d01a5..38ee60b917 100644 --- a/packages/client/lib/commands/CLUSTER_DELSLOTSRANGE.spec.ts +++ b/packages/client/lib/commands/CLUSTER_DELSLOTSRANGE.spec.ts @@ -1,29 +1,29 @@ import { strict as assert } from 'assert'; -import { transformArguments } from './CLUSTER_DELSLOTSRANGE'; +import CLUSTER_DELSLOTSRANGE from './CLUSTER_DELSLOTSRANGE'; describe('CLUSTER DELSLOTSRANGE', () => { - describe('transformArguments', () => { - it('single', () => { - assert.deepEqual( - transformArguments({ - start: 0, - end: 1 - }), - ['CLUSTER', 'DELSLOTSRANGE', '0', '1'] - ); - }); - - it('multiple', () => { - assert.deepEqual( - transformArguments([{ - start: 0, - end: 1 - }, { - start: 2, - end: 3 - }]), - ['CLUSTER', 'DELSLOTSRANGE', '0', '1', '2', '3'] - ); - }); + describe('transformArguments', () => { + it('single', () => { + assert.deepEqual( + CLUSTER_DELSLOTSRANGE.transformArguments({ + start: 0, + end: 1 + }), + ['CLUSTER', 'DELSLOTSRANGE', '0', '1'] + ); }); + + it('multiple', () => { + assert.deepEqual( + CLUSTER_DELSLOTSRANGE.transformArguments([{ + start: 0, + end: 1 + }, { + start: 2, + end: 3 + }]), + ['CLUSTER', 'DELSLOTSRANGE', '0', '1', '2', '3'] + ); + }); + }); }); diff --git a/packages/client/lib/commands/CLUSTER_FAILOVER.spec.ts b/packages/client/lib/commands/CLUSTER_FAILOVER.spec.ts index 578ff56b9c..542e529f46 100644 --- a/packages/client/lib/commands/CLUSTER_FAILOVER.spec.ts +++ b/packages/client/lib/commands/CLUSTER_FAILOVER.spec.ts @@ -1,20 +1,22 @@ import { strict as assert } from 'assert'; -import { FailoverModes, transformArguments } from './CLUSTER_FAILOVER'; +import CLUSTER_FAILOVER, { FAILOVER_MODES } 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'] - ); - }); + describe('transformArguments', () => { + it('simple', () => { + assert.deepEqual( + CLUSTER_FAILOVER.transformArguments(), + ['CLUSTER', 'FAILOVER'] + ); }); + + it('with mode', () => { + assert.deepEqual( + CLUSTER_FAILOVER.transformArguments({ + mode: FAILOVER_MODES.FORCE + }), + ['CLUSTER', 'FAILOVER', 'FORCE'] + ); + }); + }); }); diff --git a/packages/client/lib/commands/CLUSTER_FAILOVER.ts b/packages/client/lib/commands/CLUSTER_FAILOVER.ts index 857e11f7b1..63f79a246b 100644 --- a/packages/client/lib/commands/CLUSTER_FAILOVER.ts +++ b/packages/client/lib/commands/CLUSTER_FAILOVER.ts @@ -5,16 +5,20 @@ export const FAILOVER_MODES = { TAKEOVER: 'TAKEOVER' } as const; -export type FailoverModes = typeof FAILOVER_MODES[keyof typeof FAILOVER_MODES]; +export type FailoverMode = typeof FAILOVER_MODES[keyof typeof FAILOVER_MODES]; + +export interface ClusterFailoverOptions { + mode?: FailoverMode; +} export default { FIRST_KEY_INDEX: undefined, IS_READ_ONLY: true, - transformArguments(mode?: FailoverModes) { + transformArguments(options?: ClusterFailoverOptions) { const args = ['CLUSTER', 'FAILOVER']; - if (mode) { - args.push(mode); + if (options?.mode) { + args.push(options.mode); } return args; diff --git a/packages/client/lib/commands/CLUSTER_FLUSHSLOTS.spec.ts b/packages/client/lib/commands/CLUSTER_FLUSHSLOTS.spec.ts index f91a9a70cf..7ea2c33cca 100644 --- a/packages/client/lib/commands/CLUSTER_FLUSHSLOTS.spec.ts +++ b/packages/client/lib/commands/CLUSTER_FLUSHSLOTS.spec.ts @@ -1,11 +1,11 @@ import { strict as assert } from 'assert'; -import { transformArguments } from './CLUSTER_FLUSHSLOTS'; +import CLUSTER_FLUSHSLOTS from './CLUSTER_FLUSHSLOTS'; describe('CLUSTER FLUSHSLOTS', () => { - it('transformArguments', () => { - assert.deepEqual( - transformArguments(), - ['CLUSTER', 'FLUSHSLOTS'] - ); - }); + it('transformArguments', () => { + assert.deepEqual( + CLUSTER_FLUSHSLOTS.transformArguments(), + ['CLUSTER', 'FLUSHSLOTS'] + ); + }); }); diff --git a/packages/client/lib/commands/CLUSTER_FORGET.spec.ts b/packages/client/lib/commands/CLUSTER_FORGET.spec.ts index cadcdb678f..5d144ac109 100644 --- a/packages/client/lib/commands/CLUSTER_FORGET.spec.ts +++ b/packages/client/lib/commands/CLUSTER_FORGET.spec.ts @@ -1,11 +1,11 @@ import { strict as assert } from 'assert'; -import { transformArguments } from './CLUSTER_FORGET'; +import CLUSTER_FORGET from './CLUSTER_FORGET'; describe('CLUSTER FORGET', () => { - it('transformArguments', () => { - assert.deepEqual( - transformArguments('0'), - ['CLUSTER', 'FORGET', '0'] - ); - }); + it('transformArguments', () => { + assert.deepEqual( + CLUSTER_FORGET.transformArguments('0'), + ['CLUSTER', 'FORGET', '0'] + ); + }); }); diff --git a/packages/client/lib/commands/CLUSTER_GETKEYSINSLOT.spec.ts b/packages/client/lib/commands/CLUSTER_GETKEYSINSLOT.spec.ts index 957b7de20c..cba7a384ee 100644 --- a/packages/client/lib/commands/CLUSTER_GETKEYSINSLOT.spec.ts +++ b/packages/client/lib/commands/CLUSTER_GETKEYSINSLOT.spec.ts @@ -1,21 +1,25 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; -import { transformArguments } from './CLUSTER_GETKEYSINSLOT'; +import CLUSTER_GETKEYSINSLOT from './CLUSTER_GETKEYSINSLOT'; describe('CLUSTER GETKEYSINSLOT', () => { - it('transformArguments', () => { - assert.deepEqual( - transformArguments(0, 10), - ['CLUSTER', 'GETKEYSINSLOT', '0', '10'] - ); - }); + it('transformArguments', () => { + assert.deepEqual( + CLUSTER_GETKEYSINSLOT.transformArguments(0, 10), + ['CLUSTER', 'GETKEYSINSLOT', '0', '10'] + ); + }); - testUtils.testWithCluster('clusterNode.clusterGetKeysInSlot', async cluster => { - const client = await cluster.nodeClient(cluster.masters[0]), - reply = await client.clusterGetKeysInSlot(0, 1); - assert.ok(Array.isArray(reply)); - for (const item of reply) { - assert.equal(typeof item, 'string'); - } - }, GLOBAL.CLUSTERS.OPEN); + testUtils.testWithCluster('clusterNode.clusterGetKeysInSlot', async cluster => { + const slot = 12539, // "key" slot + client = await cluster.nodeClient(cluster.slots[slot].master), + [, reply] = await Promise.all([ + client.set('key', 'value'), + client.clusterGetKeysInSlot(slot, 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_KEYSLOT.ts b/packages/client/lib/commands/CLUSTER_KEYSLOT.ts index fc68287eae..81e8443011 100644 --- a/packages/client/lib/commands/CLUSTER_KEYSLOT.ts +++ b/packages/client/lib/commands/CLUSTER_KEYSLOT.ts @@ -1,6 +1,8 @@ import { Command, NumberReply, RedisArgument } from '../RESP/types'; export default { + FIRST_KEY_INDEX: undefined, + IS_READ_ONLY: true, transformArguments(key: RedisArgument) { return ['CLUSTER', 'KEYSLOT', key]; }, diff --git a/packages/client/lib/commands/CLUSTER_LINKS.spec.ts b/packages/client/lib/commands/CLUSTER_LINKS.spec.ts index 982973e8ea..c149066393 100644 --- a/packages/client/lib/commands/CLUSTER_LINKS.spec.ts +++ b/packages/client/lib/commands/CLUSTER_LINKS.spec.ts @@ -1,28 +1,28 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; -import { transformArguments } from './CLUSTER_LINKS'; +import CLUSTER_LINKS from './CLUSTER_LINKS'; describe('CLUSTER LINKS', () => { - testUtils.isVersionGreaterThanHook([7]); + testUtils.isVersionGreaterThanHook([7]); - it('transformArguments', () => { - assert.deepEqual( - transformArguments(), - ['CLUSTER', 'LINKS'] - ); - }); + it('transformArguments', () => { + assert.deepEqual( + CLUSTER_LINKS.transformArguments(), + ['CLUSTER', 'LINKS'] + ); + }); - testUtils.testWithCluster('clusterNode.clusterLinks', async cluster => { - const client = await cluster.nodeClient(cluster.masters[0]), - links = await client.clusterLinks(); - assert.ok(Array.isArray(links)); - for (const link of links) { - assert.equal(typeof link.direction, 'string'); - assert.equal(typeof link.node, 'string'); - assert.equal(typeof link.createTime, 'number'); - assert.equal(typeof link.events, 'string'); - assert.equal(typeof link.sendBufferAllocated, 'number'); - assert.equal(typeof link.sendBufferUsed, 'number'); - } - }, GLOBAL.CLUSTERS.OPEN); + testUtils.testWithCluster('clusterNode.clusterLinks', async cluster => { + const client = await cluster.nodeClient(cluster.masters[0]), + links = await client.clusterLinks(); + assert.ok(Array.isArray(links)); + for (const link of links) { + assert.equal(typeof link.direction, 'string'); + assert.equal(typeof link.node, 'string'); + assert.equal(typeof link['create-time'], 'number'); + assert.equal(typeof link.events, 'string'); + assert.equal(typeof link['send-buffer-allocated'], 'number'); + assert.equal(typeof link['send-buffer-used'], 'number'); + } + }, GLOBAL.CLUSTERS.OPEN); }); diff --git a/packages/client/lib/commands/CLUSTER_LINKS.ts b/packages/client/lib/commands/CLUSTER_LINKS.ts index 9a5608c102..486553f9d0 100644 --- a/packages/client/lib/commands/CLUSTER_LINKS.ts +++ b/packages/client/lib/commands/CLUSTER_LINKS.ts @@ -1,38 +1,29 @@ -export function transformArguments(): Array { +import { ArrayReply, TuplesToMapReply, BlobStringReply, NumberReply, Resp2Reply, Command } from '../RESP/types'; + +type ClusterLinksReply = ArrayReply, BlobStringReply], + [BlobStringReply<'node'>, BlobStringReply], + [BlobStringReply<'create-time'>, NumberReply], + [BlobStringReply<'events'>, BlobStringReply], + [BlobStringReply<'send-buffer-allocated'>, NumberReply], + [BlobStringReply<'send-buffer-used'>, NumberReply], +]>>; + +export default { + FIRST_KEY_INDEX: undefined, + IS_READ_ONLY: true, + transformArguments() { return ['CLUSTER', 'LINKS']; -} - -type ClusterLinksRawReply = Array<[ - 'direction', - string, - 'node', - string, - 'createTime', - number, - 'events', - string, - 'send-buffer-allocated', - number, - 'send-buffer-used', - number -]>; - -type ClusterLinksReply = Array<{ - direction: string; - node: string; - createTime: number; - events: string; - sendBufferAllocated: number; - sendBufferUsed: number; -}>; - -export function transformReply(reply: ClusterLinksRawReply): ClusterLinksReply { - return reply.map(peerLink => ({ - direction: peerLink[1], - node: peerLink[3], - createTime: Number(peerLink[5]), - events: peerLink[7], - sendBufferAllocated: Number(peerLink[9]), - sendBufferUsed: Number(peerLink[11]) - })); -} + }, + transformReply: { + 2: (reply: Resp2Reply) => reply.map(link => ({ + direction: link[1], + node: link[3], + 'create-time': link[5], + events: link[7], + 'send-buffer-allocated': link[9], + 'send-buffer-used': link[11] + })), + 3: undefined as unknown as () => ClusterLinksReply + } +} as const satisfies Command; diff --git a/packages/client/lib/commands/CLUSTER_MEET.ts b/packages/client/lib/commands/CLUSTER_MEET.ts index 949412702d..df72599d40 100644 --- a/packages/client/lib/commands/CLUSTER_MEET.ts +++ b/packages/client/lib/commands/CLUSTER_MEET.ts @@ -1,6 +1,8 @@ import { SimpleStringReply, Command } from '../RESP/types'; export default { + FIRST_KEY_INDEX: undefined, + IS_READ_ONLY: true, transformArguments(host: string, port: number) { return ['CLUSTER', 'MEET', host, port.toString()]; }, diff --git a/packages/client/lib/commands/CLUSTER_MYID.ts b/packages/client/lib/commands/CLUSTER_MYID.ts index 6c682ddccf..73711b47eb 100644 --- a/packages/client/lib/commands/CLUSTER_MYID.ts +++ b/packages/client/lib/commands/CLUSTER_MYID.ts @@ -1,6 +1,8 @@ import { BlobStringReply, Command } from '../RESP/types'; export default { + FIRST_KEY_INDEX: undefined, + IS_READ_ONLY: true, transformArguments() { return ['CLUSTER', 'MYID']; }, diff --git a/packages/client/lib/commands/CLUSTER_REPLICATE.ts b/packages/client/lib/commands/CLUSTER_REPLICATE.ts index c589ad33d7..7431142024 100644 --- a/packages/client/lib/commands/CLUSTER_REPLICATE.ts +++ b/packages/client/lib/commands/CLUSTER_REPLICATE.ts @@ -1,6 +1,8 @@ import { RedisArgument, SimpleStringReply, Command } from '../RESP/types'; export default { + FIRST_KEY_INDEX: undefined, + IS_READ_ONLY: true, transformArguments(nodeId: RedisArgument) { return ['CLUSTER', 'REPLICATE', nodeId]; }, diff --git a/packages/client/lib/commands/CLUSTER_SETSLOT.ts b/packages/client/lib/commands/CLUSTER_SETSLOT.ts index e79cf88b4a..ad04513688 100644 --- a/packages/client/lib/commands/CLUSTER_SETSLOT.ts +++ b/packages/client/lib/commands/CLUSTER_SETSLOT.ts @@ -1,4 +1,4 @@ -import { SimpleStringReply, Command } from '../RESP/types'; +import { RedisArgument, SimpleStringReply, Command } from '../RESP/types'; export const CLUSTER_SLOT_STATES = { IMPORTING: 'IMPORTING', @@ -7,13 +7,13 @@ export const CLUSTER_SLOT_STATES = { NODE: 'NODE' } as const; -export type ClusterSlotStates = typeof CLUSTER_SLOT_STATES[keyof typeof CLUSTER_SLOT_STATES]; +export type ClusterSlotState = typeof CLUSTER_SLOT_STATES[keyof typeof CLUSTER_SLOT_STATES]; export default { FIRST_KEY_INDEX: undefined, IS_READ_ONLY: true, - transformArguments(slot: number, state: ClusterSlotStates, nodeId?: string) { - const args = ['CLUSTER', 'SETSLOT', slot.toString(), state]; + transformArguments(slot: number, state: ClusterSlotState, nodeId?: RedisArgument) { + const args: Array = ['CLUSTER', 'SETSLOT', slot.toString(), state]; if (nodeId) { args.push(nodeId); diff --git a/packages/client/lib/commands/CLUSTER_SLOTS.spec.ts b/packages/client/lib/commands/CLUSTER_SLOTS.spec.ts index 4650fe83b2..9010361c78 100644 --- a/packages/client/lib/commands/CLUSTER_SLOTS.spec.ts +++ b/packages/client/lib/commands/CLUSTER_SLOTS.spec.ts @@ -26,5 +26,5 @@ describe('CLUSTER SLOTS', () => { assert.equal(typeof replica.id, 'string'); } } - }, GLOBAL.CLUSTERS.OPEN); + }, GLOBAL.CLUSTERS.WITH_REPLICAS); }); diff --git a/packages/client/lib/commands/COMMAND_COUNT.spec.ts b/packages/client/lib/commands/COMMAND_COUNT.spec.ts index ca03e96ae8..63b3af4866 100644 --- a/packages/client/lib/commands/COMMAND_COUNT.spec.ts +++ b/packages/client/lib/commands/COMMAND_COUNT.spec.ts @@ -1,19 +1,19 @@ -// import { strict as assert } from 'assert'; -// import testUtils, { GLOBAL } from '../test-utils'; -// import { transformArguments } from './COMMAND_COUNT'; +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import COMMAND_COUNT from './COMMAND_COUNT'; -// describe('COMMAND COUNT', () => { -// it('transformArguments', () => { -// assert.deepEqual( -// transformArguments(), -// ['COMMAND', 'COUNT'] -// ); -// }); +describe('COMMAND COUNT', () => { + it('transformArguments', () => { + assert.deepEqual( + COMMAND_COUNT.transformArguments(), + ['COMMAND', 'COUNT'] + ); + }); -// testUtils.testWithClient('client.commandCount', async client => { -// assert.equal( -// typeof await client.commandCount(), -// 'number' -// ); -// }, GLOBAL.SERVERS.OPEN); -// }); + testUtils.testWithClient('client.commandCount', async client => { + assert.equal( + typeof await client.commandCount(), + 'number' + ); + }, GLOBAL.SERVERS.OPEN); +}); diff --git a/packages/client/lib/commands/COMMAND_COUNT.ts b/packages/client/lib/commands/COMMAND_COUNT.ts index f1cd06702e..10b0fdefe0 100644 --- a/packages/client/lib/commands/COMMAND_COUNT.ts +++ b/packages/client/lib/commands/COMMAND_COUNT.ts @@ -1,9 +1,10 @@ -// import { RedisCommandArguments } from '.'; +import { NumberReply, Command } from '../RESP/types'; -// export const IS_READ_ONLY = true; - -// export function transformArguments(): RedisCommandArguments { -// return ['COMMAND', 'COUNT']; -// } - -// export declare function transformReply(): number; +export default { + FIRST_KEY_INDEX: undefined, + IS_READ_ONLY: true, + transformArguments() { + return ['COMMAND', 'COUNT']; + }, + transformReply: undefined as unknown as () => NumberReply +} as const satisfies Command; diff --git a/packages/client/lib/commands/COMMAND_GETKEYS.spec.ts b/packages/client/lib/commands/COMMAND_GETKEYS.spec.ts index e17566e0df..a1a7bd2fc2 100644 --- a/packages/client/lib/commands/COMMAND_GETKEYS.spec.ts +++ b/packages/client/lib/commands/COMMAND_GETKEYS.spec.ts @@ -1,19 +1,19 @@ -// import { strict as assert } from 'assert'; -// import testUtils, { GLOBAL } from '../test-utils'; -// import { transformArguments } from './COMMAND_GETKEYS'; +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import COMMAND_GETKEYS from './COMMAND_GETKEYS'; -// describe('COMMAND GETKEYS', () => { -// it('transformArguments', () => { -// assert.deepEqual( -// transformArguments(['GET', 'key']), -// ['COMMAND', 'GETKEYS', 'GET', 'key'] -// ); -// }); +describe('COMMAND GETKEYS', () => { + it('transformArguments', () => { + assert.deepEqual( + COMMAND_GETKEYS.transformArguments(['GET', 'key']), + ['COMMAND', 'GETKEYS', 'GET', 'key'] + ); + }); -// testUtils.testWithClient('client.commandGetKeys', async client => { -// assert.deepEqual( -// await client.commandGetKeys(['GET', 'key']), -// ['key'] -// ); -// }, GLOBAL.SERVERS.OPEN); -// }); + testUtils.testWithClient('client.commandGetKeys', async client => { + assert.deepEqual( + await client.commandGetKeys(['GET', 'key']), + ['key'] + ); + }, GLOBAL.SERVERS.OPEN); +}); diff --git a/packages/client/lib/commands/COMMAND_GETKEYS.ts b/packages/client/lib/commands/COMMAND_GETKEYS.ts index fb43798c1b..55cca415b8 100644 --- a/packages/client/lib/commands/COMMAND_GETKEYS.ts +++ b/packages/client/lib/commands/COMMAND_GETKEYS.ts @@ -1,9 +1,10 @@ -// import { RedisCommandArgument, RedisCommandArguments } from '.'; +import { RedisArgument, ArrayReply, BlobStringReply, Command } from '../RESP/types'; -// export const IS_READ_ONLY = true; - -// export function transformArguments(args: Array): RedisCommandArguments { -// return ['COMMAND', 'GETKEYS', ...args]; -// } - -// export declare function transformReply(): Array; +export default { + FIRST_KEY_INDEX: undefined, + IS_READ_ONLY: true, + transformArguments(args: Array) { + return ['COMMAND', 'GETKEYS', ...args]; + }, + transformReply: undefined as unknown as () => ArrayReply +} as const satisfies Command; diff --git a/packages/client/lib/commands/CONFIG_GET.spec.ts b/packages/client/lib/commands/CONFIG_GET.spec.ts index 8077a093d8..ae65092e4f 100644 --- a/packages/client/lib/commands/CONFIG_GET.spec.ts +++ b/packages/client/lib/commands/CONFIG_GET.spec.ts @@ -1,11 +1,31 @@ import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; import CONFIG_GET from './CONFIG_GET'; describe('CONFIG GET', () => { - it('transformArguments', () => { - assert.deepEqual( - CONFIG_GET.transformArguments('*'), - ['CONFIG', 'GET', '*'] - ); + describe('transformArguments', () => { + it('string', () => { + assert.deepEqual( + CONFIG_GET.transformArguments('*'), + ['CONFIG', 'GET', '*'] + ); + }); + + it('Array', () => { + assert.deepEqual( + CONFIG_GET.transformArguments(['1', '2']), + ['CONFIG', 'GET', '1', '2'] + ); + }); }); + + + testUtils.testWithClient('client.configGet', async client => { + const config = await client.configGet('*'); + assert.equal(typeof config, 'object'); + for (const [key, value] of Object.entries(config)) { + assert.equal(typeof key, 'string'); + assert.equal(typeof value, 'string'); + } + }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/client/lib/commands/CONFIG_GET.ts b/packages/client/lib/commands/CONFIG_GET.ts index 0fc8229229..72fb6e56f5 100644 --- a/packages/client/lib/commands/CONFIG_GET.ts +++ b/packages/client/lib/commands/CONFIG_GET.ts @@ -1,11 +1,14 @@ -import { RedisArgument, Command } from '../RESP/types'; -import { transformTuplesReply } from './generic-transformers'; +import { MapReply, BlobStringReply, Command } from '../RESP/types'; +import { RedisVariadicArgument, pushVariadicArguments, transformTuplesReply } from './generic-transformers'; export default { FIRST_KEY_INDEX: undefined, IS_READ_ONLY: true, - transformArguments(parameter: RedisArgument) { - return ['CONFIG', 'GET', parameter]; + transformArguments(parameters: RedisVariadicArgument) { + return pushVariadicArguments(['CONFIG', 'GET'], parameters); }, - transformReply: transformTuplesReply + transformReply: { + 2: transformTuplesReply, + 3: undefined as unknown as () => MapReply + } } as const satisfies Command; diff --git a/packages/client/lib/commands/CONFIG_RESETSTAT.ts b/packages/client/lib/commands/CONFIG_RESETSTAT.ts index 119bbd6051..4d5deb18b4 100644 --- a/packages/client/lib/commands/CONFIG_RESETSTAT.ts +++ b/packages/client/lib/commands/CONFIG_RESETSTAT.ts @@ -1,6 +1,8 @@ import { SimpleStringReply, Command } from '../RESP/types'; export default { + FIRST_KEY_INDEX: undefined, + IS_READ_ONLY: true, transformArguments() { return ['CONFIG', 'RESETSTAT']; }, diff --git a/packages/client/lib/commands/CONFIG_REWRITE.ts b/packages/client/lib/commands/CONFIG_REWRITE.ts index 63f9acdb90..6fbc4b1fa2 100644 --- a/packages/client/lib/commands/CONFIG_REWRITE.ts +++ b/packages/client/lib/commands/CONFIG_REWRITE.ts @@ -1,6 +1,8 @@ import { SimpleStringReply, Command } from '../RESP/types'; export default { + FIRST_KEY_INDEX: undefined, + IS_READ_ONLY: true, transformArguments() { return ['CONFIG', 'REWRITE']; }, diff --git a/packages/client/lib/commands/CONFIG_SET.spec.ts b/packages/client/lib/commands/CONFIG_SET.spec.ts index fac5e1dbe9..86d590072c 100644 --- a/packages/client/lib/commands/CONFIG_SET.spec.ts +++ b/packages/client/lib/commands/CONFIG_SET.spec.ts @@ -1,4 +1,5 @@ import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; import CONFIG_SET from './CONFIG_SET'; describe('CONFIG SET', () => { @@ -21,4 +22,11 @@ describe('CONFIG SET', () => { ); }); }); + + testUtils.testWithClient('client.configSet', async client => { + assert.equal( + await client.configSet('maxmemory', '0'), + 'OK' + ); + }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/client/lib/commands/CONFIG_SET.ts b/packages/client/lib/commands/CONFIG_SET.ts index 58f16e9693..c7072245e2 100644 --- a/packages/client/lib/commands/CONFIG_SET.ts +++ b/packages/client/lib/commands/CONFIG_SET.ts @@ -5,6 +5,8 @@ type SingleParameter = [parameter: RedisArgument, value: RedisArgument]; type MultipleParameters = [config: Record]; export default { + FIRST_KEY_INDEX: undefined, + IS_READ_ONLY: true, transformArguments( ...[parameterOrConfig, value]: SingleParameter | MultipleParameters ) { diff --git a/packages/client/lib/commands/FLUSHALL.ts b/packages/client/lib/commands/FLUSHALL.ts index 6c814b34a4..5e6484a991 100644 --- a/packages/client/lib/commands/FLUSHALL.ts +++ b/packages/client/lib/commands/FLUSHALL.ts @@ -5,12 +5,12 @@ export const REDIS_FLUSH_MODES = { SYNC: 'SYNC' } as const; -export type RedisFlushModes = typeof REDIS_FLUSH_MODES[keyof typeof REDIS_FLUSH_MODES]; +export type RedisFlushMode = typeof REDIS_FLUSH_MODES[keyof typeof REDIS_FLUSH_MODES]; export default { FIRST_KEY_INDEX: undefined, IS_READ_ONLY: false, - transformArguments(mode?: RedisFlushModes) { + transformArguments(mode?: RedisFlushMode) { const args = ['FLUSHALL']; if (mode) { diff --git a/packages/client/lib/commands/FLUSHDB.ts b/packages/client/lib/commands/FLUSHDB.ts index cb7be1156a..75c7a66f19 100644 --- a/packages/client/lib/commands/FLUSHDB.ts +++ b/packages/client/lib/commands/FLUSHDB.ts @@ -1,10 +1,10 @@ import { SimpleStringReply, Command } from '../RESP/types'; -import { RedisFlushModes } from './FLUSHALL'; +import { RedisFlushMode } from './FLUSHALL'; export default { FIRST_KEY_INDEX: undefined, IS_READ_ONLY: false, - transformArguments(mode?: RedisFlushModes) { + transformArguments(mode?: RedisFlushMode) { const args = ['FLUSHDB']; if (mode) { diff --git a/packages/client/lib/commands/FUNCTION_FLUSH.ts b/packages/client/lib/commands/FUNCTION_FLUSH.ts index 010e9b8108..844d3586d9 100644 --- a/packages/client/lib/commands/FUNCTION_FLUSH.ts +++ b/packages/client/lib/commands/FUNCTION_FLUSH.ts @@ -1,10 +1,10 @@ import { SimpleStringReply, Command } from '../RESP/types'; -import { RedisFlushModes } from './FLUSHALL'; +import { RedisFlushMode } from './FLUSHALL'; export default { FIRST_KEY_INDEX: undefined, IS_READ_ONLY: false, - transformArguments(mode?: RedisFlushModes) { + transformArguments(mode?: RedisFlushMode) { const args = ['FUNCTION', 'FLUSH']; if (mode) { diff --git a/packages/client/lib/commands/LATENCY_DOCTOR.spec.ts b/packages/client/lib/commands/LATENCY_DOCTOR.spec.ts index 3888ff8bd3..67446270be 100644 --- a/packages/client/lib/commands/LATENCY_DOCTOR.spec.ts +++ b/packages/client/lib/commands/LATENCY_DOCTOR.spec.ts @@ -1,19 +1,19 @@ -import {strict as assert} from 'assert'; -import testUtils, {GLOBAL} from '../test-utils'; -import { transformArguments } from './LATENCY_DOCTOR'; +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import LATENCY_DOCTOR from './LATENCY_DOCTOR'; describe('LATENCY DOCTOR', () => { - it('transformArguments', () => { - assert.deepEqual( - transformArguments(), - ['LATENCY', 'DOCTOR'] - ); - }); + it('transformArguments', () => { + assert.deepEqual( + LATENCY_DOCTOR.transformArguments(), + ['LATENCY', 'DOCTOR'] + ); + }); - testUtils.testWithClient('client.latencyDoctor', async client => { - assert.equal( - typeof (await client.latencyDoctor()), - 'string' - ); - }, GLOBAL.SERVERS.OPEN); + testUtils.testWithClient('client.latencyDoctor', async client => { + assert.equal( + typeof await client.latencyDoctor(), + 'string' + ); + }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/client/lib/commands/LATENCY_DOCTOR.ts b/packages/client/lib/commands/LATENCY_DOCTOR.ts index d2106c0611..96dc6b6570 100644 --- a/packages/client/lib/commands/LATENCY_DOCTOR.ts +++ b/packages/client/lib/commands/LATENCY_DOCTOR.ts @@ -1,5 +1,10 @@ -export function transformArguments(): Array { - return ['LATENCY', 'DOCTOR']; -} +import { BlobStringReply, Command } from '../RESP/types'; -export declare function transformReply(): string; +export default { + FIRST_KEY_INDEX: undefined, + IS_READ_ONLY: true, + transformArguments() { + return ['LATENCY', 'DOCTOR']; + }, + transformReply: undefined as unknown as () => BlobStringReply +} as const satisfies Command; diff --git a/packages/client/lib/commands/LATENCY_GRAPH.spec.ts b/packages/client/lib/commands/LATENCY_GRAPH.spec.ts index 21755a253b..f4a3c66896 100644 --- a/packages/client/lib/commands/LATENCY_GRAPH.spec.ts +++ b/packages/client/lib/commands/LATENCY_GRAPH.spec.ts @@ -1,28 +1,28 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; -import { transformArguments } from './LATENCY_GRAPH'; +import LATENCY_GRAPH from './LATENCY_GRAPH'; describe('LATENCY GRAPH', () => { - it('transformArguments', () => { - assert.deepEqual( - transformArguments('command'), - [ - 'LATENCY', - 'GRAPH', - 'command' - ] - ); - }); + it('transformArguments', () => { + assert.deepEqual( + LATENCY_GRAPH.transformArguments('command'), + [ + 'LATENCY', + 'GRAPH', + 'command' + ] + ); + }); - testUtils.testWithClient('client.latencyGraph', async client => { - await Promise.all([ - client.configSet('latency-monitor-threshold', '1'), - client.sendCommand(['DEBUG', 'SLEEP', '0.001']) - ]); + testUtils.testWithClient('client.latencyGraph', async client => { + await Promise.all([ + client.configSet('latency-monitor-threshold', '1'), + client.sendCommand(['DEBUG', 'SLEEP', '0.001']) + ]); - assert.equal( - typeof await client.latencyGraph('command'), - 'string' - ); - }, GLOBAL.SERVERS.OPEN); + assert.equal( + typeof await client.latencyGraph('command'), + 'string' + ); + }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/client/lib/commands/LATENCY_GRAPH.ts b/packages/client/lib/commands/LATENCY_GRAPH.ts index a789a79075..c2fdbbd187 100644 --- a/packages/client/lib/commands/LATENCY_GRAPH.ts +++ b/packages/client/lib/commands/LATENCY_GRAPH.ts @@ -1,25 +1,31 @@ -// import { RedisCommandArguments } from '.'; +import { SimpleStringReply, Command, BlobStringReply } from '../RESP/types'; -// export type EventType = -// 'active-defrag-cycle' -// | 'aof-fsync-always' -// | 'aof-stat' -// | 'aof-rewrite-diff-write' -// | 'aof-rename' -// | 'aof-write' -// | 'aof-write-active-child' -// | 'aof-write-alone' -// | 'aof-write-pending-fsync' -// | 'command' -// | 'expire-cycle' -// | 'eviction-cycle' -// | 'eviction-del' -// | 'fast-command' -// | 'fork' -// | 'rdb-unlink-temp-file'; +export const LATENCY_EVENTS = { + ACTIVE_DEFRAG_CYCLE: 'active-defrag-cycle', + AOF_FSYNC_ALWAYS: 'aof-fsync-always', + AOF_STAT: 'aof-stat', + AOF_REWRITE_DIFF_WRITE: 'aof-rewrite-diff-write', + AOF_RENAME: 'aof-rename', + AOF_WRITE: 'aof-write', + AOF_WRITE_ACTIVE_CHILD: 'aof-write-active-child', + AOF_WRITE_ALONE: 'aof-write-alone', + AOF_WRITE_PENDING_FSYNC: 'aof-write-pending-fsync', + COMMAND: 'command', + EXPIRE_CYCLE: 'expire-cycle', + EVICTION_CYCLE: 'eviction-cycle', + EVICTION_DEL: 'eviction-del', + FAST_COMMAND: 'fast-command', + FORK: 'fork', + RDB_UNLINK_TEMP_FILE: 'rdb-unlink-temp-file' +} as const; -// export function transformArguments(event: EventType): RedisCommandArguments { -// return ['LATENCY', 'GRAPH', event]; -// } +export type LatencyEvent = typeof LATENCY_EVENTS[keyof typeof LATENCY_EVENTS]; -// export declare function transformReply(): string; +export default { + FIRST_KEY_INDEX: undefined, + IS_READ_ONLY: true, + transformArguments(event: LatencyEvent) { + return ['LATENCY', 'GRAPH', event]; + }, + transformReply: undefined as unknown as () => BlobStringReply +} as const satisfies Command; diff --git a/packages/client/lib/commands/LATENCY_LATEST.spec.ts b/packages/client/lib/commands/LATENCY_LATEST.spec.ts index 8d223ec25e..0fe8085ef6 100644 --- a/packages/client/lib/commands/LATENCY_LATEST.spec.ts +++ b/packages/client/lib/commands/LATENCY_LATEST.spec.ts @@ -1,27 +1,27 @@ -// import {strict as assert} from 'assert'; -// import testUtils, {GLOBAL} from '../test-utils'; -// import { transformArguments } from './LATENCY_LATEST'; +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import LATENCY_LATEST from './LATENCY_LATEST'; -// describe('LATENCY LATEST', () => { -// it('transformArguments', () => { -// assert.deepEqual( -// transformArguments(), -// ['LATENCY', 'LATEST'] -// ); -// }); +describe('LATENCY LATEST', () => { + it('transformArguments', () => { + assert.deepEqual( + LATENCY_LATEST.transformArguments(), + ['LATENCY', 'LATEST'] + ); + }); -// testUtils.testWithClient('client.latencyLatest', async client => { -// await Promise.all([ -// client.configSet('latency-monitor-threshold', '100'), -// client.sendCommand(['DEBUG', 'SLEEP', '1']) -// ]); -// const latency = await client.latencyLatest(); -// assert.ok(Array.isArray(latency)); -// for (const [name, timestamp, latestLatency, allTimeLatency] of latency) { -// assert.equal(typeof name, 'string'); -// assert.equal(typeof timestamp, 'number'); -// assert.equal(typeof latestLatency, 'number'); -// assert.equal(typeof allTimeLatency, 'number'); -// } -// }, GLOBAL.SERVERS.OPEN); -// }); + testUtils.testWithClient('client.latencyLatest', async client => { + await Promise.all([ + client.configSet('latency-monitor-threshold', '100'), + client.sendCommand(['DEBUG', 'SLEEP', '1']) + ]); + const latency = await client.latencyLatest(); + assert.ok(Array.isArray(latency)); + for (const [name, timestamp, latestLatency, allTimeLatency] of latency) { + assert.equal(typeof name, 'string'); + assert.equal(typeof timestamp, 'number'); + assert.equal(typeof latestLatency, 'number'); + assert.equal(typeof allTimeLatency, 'number'); + } + }, GLOBAL.SERVERS.OPEN); +}); diff --git a/packages/client/lib/commands/LATENCY_LATEST.ts b/packages/client/lib/commands/LATENCY_LATEST.ts index 2455841a20..29548af30d 100644 --- a/packages/client/lib/commands/LATENCY_LATEST.ts +++ b/packages/client/lib/commands/LATENCY_LATEST.ts @@ -1,12 +1,16 @@ -// import { RedisCommandArguments } from '.'; +import { ArrayReply, BlobStringReply, NumberReply, Command } from '../RESP/types'; -// export function transformArguments(): RedisCommandArguments { -// return ['LATENCY', 'LATEST']; -// } +export default { + FIRST_KEY_INDEX: undefined, + IS_READ_ONLY: true, + transformArguments() { + return ['LATENCY', 'LATEST']; + }, + transformReply: undefined as unknown as () => ArrayReply<[ + name: BlobStringReply, + timestamp: NumberReply, + latestLatency: NumberReply, + allTimeLatency: NumberReply + ]> +} as const satisfies Command; -// export declare function transformReply(): Array<[ -// name: string, -// timestamp: number, -// latestLatency: number, -// allTimeLatency: number -// ]>; diff --git a/packages/client/lib/commands/MEMORY_STATS.spec.ts b/packages/client/lib/commands/MEMORY_STATS.spec.ts index 6c53b61b03..28caa208b8 100644 --- a/packages/client/lib/commands/MEMORY_STATS.spec.ts +++ b/packages/client/lib/commands/MEMORY_STATS.spec.ts @@ -1,43 +1,43 @@ -// import { strict as assert } from 'assert'; -// import testUtils, { GLOBAL } from '../test-utils'; -// import MEMORY_STATS from './MEMORY_STATS'; +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import MEMORY_STATS from './MEMORY_STATS'; -// describe('MEMORY STATS', () => { -// it('transformArguments', () => { -// assert.deepEqual( -// MEMORY_STATS.transformArguments(), -// ['MEMORY', 'STATS'] -// ); -// }); +describe('MEMORY STATS', () => { + it('transformArguments', () => { + assert.deepEqual( + MEMORY_STATS.transformArguments(), + ['MEMORY', 'STATS'] + ); + }); -// testUtils.testWithClient('client.memoryStats', async client => { -// const memoryStats = await client.memoryStats(); -// assert.equal(typeof memoryStats['peak.allocated'], 'number'); -// assert.equal(typeof memoryStats['total.allocated'], 'number'); -// assert.equal(typeof memoryStats['startup.allocated'], 'number'); -// assert.equal(typeof memoryStats['replication.backlog'], 'number'); -// assert.equal(typeof memoryStats['clients.slaves'], 'number'); -// assert.equal(typeof memoryStats['clients.normal'], 'number'); -// assert.equal(typeof memoryStats['cluster.links'], 'number'); -// assert.equal(typeof memoryStats['aof.buffer'], 'number'); -// assert.equal(typeof memoryStats['lua.caches'], 'number'); -// assert.equal(typeof memoryStats['functions.caches'], 'number'); -// assert.equal(typeof memoryStats['overhead.total'], 'number'); -// assert.equal(typeof memoryStats['keys.count'], 'number'); -// assert.equal(typeof memoryStats['keys.bytes-per-key'], 'number'); -// assert.equal(typeof memoryStats['dataset.bytes'], 'number'); -// assert.equal(typeof memoryStats['dataset.percentage'], 'string'); -// assert.equal(typeof memoryStats['peak.percentage'], 'string'); -// assert.equal(typeof memoryStats['allocator.allocated'], 'number'); -// assert.equal(typeof memoryStats['allocator.active'], 'number'); -// assert.equal(typeof memoryStats['allocator.resident'], 'number'); -// assert.equal(typeof memoryStats['allocator-fragmentation.ratio'], 'string'); -// assert.equal(typeof memoryStats['allocator-fragmentation.bytes'], 'number'); -// assert.equal(typeof memoryStats['allocator-rss.ratio'], 'string'); -// assert.equal(typeof memoryStats['allocator-rss.bytes'], 'number'); -// assert.equal(typeof memoryStats['rss-overhead.ratio'], 'string'); -// assert.equal(typeof memoryStats['rss-overhead.bytes'], 'number'); -// assert.equal(typeof memoryStats['fragmentation'], 'string'); -// assert.equal(typeof memoryStats['fragmentation.bytes'], 'number'); -// }, GLOBAL.SERVERS.OPEN); -// }); + testUtils.testWithClient('client.memoryStats', async client => { + const memoryStats = await client.memoryStats(); + assert.equal(typeof memoryStats['peak.allocated'], 'number'); + assert.equal(typeof memoryStats['total.allocated'], 'number'); + assert.equal(typeof memoryStats['startup.allocated'], 'number'); + assert.equal(typeof memoryStats['replication.backlog'], 'number'); + assert.equal(typeof memoryStats['clients.slaves'], 'number'); + assert.equal(typeof memoryStats['clients.normal'], 'number'); + assert.equal(typeof memoryStats['cluster.links'], 'number'); + assert.equal(typeof memoryStats['aof.buffer'], 'number'); + assert.equal(typeof memoryStats['lua.caches'], 'number'); + assert.equal(typeof memoryStats['functions.caches'], 'number'); + assert.equal(typeof memoryStats['overhead.total'], 'number'); + assert.equal(typeof memoryStats['keys.count'], 'number'); + assert.equal(typeof memoryStats['keys.bytes-per-key'], 'number'); + assert.equal(typeof memoryStats['dataset.bytes'], 'number'); + assert.equal(typeof memoryStats['dataset.percentage'], 'string'); + assert.equal(typeof memoryStats['peak.percentage'], 'string'); + assert.equal(typeof memoryStats['allocator.allocated'], 'number'); + assert.equal(typeof memoryStats['allocator.active'], 'number'); + assert.equal(typeof memoryStats['allocator.resident'], 'number'); + assert.equal(typeof memoryStats['allocator-fragmentation.ratio'], 'string'); + assert.equal(typeof memoryStats['allocator-fragmentation.bytes'], 'number'); + assert.equal(typeof memoryStats['allocator-rss.ratio'], 'string'); + assert.equal(typeof memoryStats['allocator-rss.bytes'], 'number'); + assert.equal(typeof memoryStats['rss-overhead.ratio'], 'string'); + assert.equal(typeof memoryStats['rss-overhead.bytes'], 'number'); + assert.equal(typeof memoryStats['fragmentation'], 'string'); + assert.equal(typeof memoryStats['fragmentation.bytes'], 'number'); + }, GLOBAL.SERVERS.OPEN); +}); diff --git a/packages/client/lib/commands/MEMORY_STATS.ts b/packages/client/lib/commands/MEMORY_STATS.ts index 4cc2ca2e4d..2d798ccd2c 100644 --- a/packages/client/lib/commands/MEMORY_STATS.ts +++ b/packages/client/lib/commands/MEMORY_STATS.ts @@ -1,53 +1,53 @@ -// import { TuplesToMapReply, BlobStringReply, NumberReply, DoubleReply, Command, Resp2Reply } from '../RESP/types'; +import { TuplesToMapReply, BlobStringReply, NumberReply, DoubleReply, Command, Resp2Reply } from '../RESP/types'; -// export type MemoryStatsReply = TuplesToMapReply<[ -// [BlobStringReply<'peak.allocated'>, NumberReply], -// [BlobStringReply<'total.allocated'>, NumberReply], -// [BlobStringReply<'startup.allocated'>, NumberReply], -// [BlobStringReply<'replication.backlog'>, NumberReply], -// [BlobStringReply<'clients.slaves'>, NumberReply], -// [BlobStringReply<'clients.normal'>, NumberReply], -// [BlobStringReply<'cluster.links'>, NumberReply], -// [BlobStringReply<'aof.buffer'>, NumberReply], -// [BlobStringReply<'lua.caches'>, NumberReply], -// [BlobStringReply<'functions.caches'>, NumberReply], -// [BlobStringReply<'overhead.total'>, NumberReply], -// [BlobStringReply<'keys.count'>, NumberReply], -// [BlobStringReply<'keys.bytes-per-key'>, NumberReply], -// [BlobStringReply<'dataset.bytes'>, NumberReply], -// [BlobStringReply<'dataset.percentage'>, DoubleReply], -// [BlobStringReply<'peak.percentage'>, DoubleReply], -// [BlobStringReply<'allocator.allocated'>, NumberReply], -// [BlobStringReply<'allocator.active'>, NumberReply], -// [BlobStringReply<'allocator.resident'>, NumberReply], -// [BlobStringReply<'allocator-fragmentation.ratio'>, DoubleReply], -// [BlobStringReply<'allocator-fragmentation.bytes'>, NumberReply], -// [BlobStringReply<'allocator-rss.ratio'>, DoubleReply], -// [BlobStringReply<'allocator-rss.bytes'>, NumberReply], -// [BlobStringReply<'rss-overhead.ratio'>, DoubleReply], -// [BlobStringReply<'rss-overhead.bytes'>, NumberReply], -// [BlobStringReply<'fragmentation'>, DoubleReply], -// [BlobStringReply<'fragmentation.bytes'>, NumberReply] -// ]>; +export type MemoryStatsReply = TuplesToMapReply<[ + [BlobStringReply<'peak.allocated'>, NumberReply], + [BlobStringReply<'total.allocated'>, NumberReply], + [BlobStringReply<'startup.allocated'>, NumberReply], + [BlobStringReply<'replication.backlog'>, NumberReply], + [BlobStringReply<'clients.slaves'>, NumberReply], + [BlobStringReply<'clients.normal'>, NumberReply], + [BlobStringReply<'cluster.links'>, NumberReply], + [BlobStringReply<'aof.buffer'>, NumberReply], + [BlobStringReply<'lua.caches'>, NumberReply], + [BlobStringReply<'functions.caches'>, NumberReply], + [BlobStringReply<'overhead.total'>, NumberReply], + [BlobStringReply<'keys.count'>, NumberReply], + [BlobStringReply<'keys.bytes-per-key'>, NumberReply], + [BlobStringReply<'dataset.bytes'>, NumberReply], + [BlobStringReply<'dataset.percentage'>, DoubleReply], + [BlobStringReply<'peak.percentage'>, DoubleReply], + [BlobStringReply<'allocator.allocated'>, NumberReply], + [BlobStringReply<'allocator.active'>, NumberReply], + [BlobStringReply<'allocator.resident'>, NumberReply], + [BlobStringReply<'allocator-fragmentation.ratio'>, DoubleReply], + [BlobStringReply<'allocator-fragmentation.bytes'>, NumberReply], + [BlobStringReply<'allocator-rss.ratio'>, DoubleReply], + [BlobStringReply<'allocator-rss.bytes'>, NumberReply], + [BlobStringReply<'rss-overhead.ratio'>, DoubleReply], + [BlobStringReply<'rss-overhead.bytes'>, NumberReply], + [BlobStringReply<'fragmentation'>, DoubleReply], + [BlobStringReply<'fragmentation.bytes'>, NumberReply] +]>; -// export default { -// FIRST_KEY_INDEX: undefined, -// IS_READ_ONLY: true, -// transformArguments() { -// return ['MEMORY', 'STATS']; -// }, -// transformReply: { -// 2: (rawReply: Array) => { -// const reply: Partial> = {}; +export default { + FIRST_KEY_INDEX: undefined, + IS_READ_ONLY: true, + transformArguments() { + return ['MEMORY', 'STATS']; + }, + transformReply: { + 2: (rawReply: Array) => { + const reply: Partial> = {}; -// let i = 0; -// while (i < rawReply.length) { -// const key = rawReply[i++] as keyof MemoryStatsReply['DEFAULT']; -// reply[key] = rawReply[i++] as any; -// } + let i = 0; + while (i < rawReply.length) { + const key = rawReply[i++] as keyof MemoryStatsReply['DEFAULT']; + reply[key] = rawReply[i++] as any; + } -// return reply as MemoryStatsReply['DEFAULT']; -// }, -// 3: undefined as unknown as () => MemoryStatsReply -// } -// } as const satisfies Command; + return reply as MemoryStatsReply['DEFAULT']; + }, + 3: undefined as unknown as () => MemoryStatsReply + } +} as const satisfies Command; diff --git a/packages/client/lib/commands/ROLE.spec.ts b/packages/client/lib/commands/ROLE.spec.ts index 2e6d9b163a..85f586e441 100644 --- a/packages/client/lib/commands/ROLE.spec.ts +++ b/packages/client/lib/commands/ROLE.spec.ts @@ -1,69 +1,69 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL } from '../test-utils'; -import { transformArguments, transformReply } from './ROLE'; +import ROLE from './ROLE'; describe('ROLE', () => { - it('transformArguments', () => { - assert.deepEqual( - transformArguments(), - ['ROLE'] - ); + it('transformArguments', () => { + assert.deepEqual( + ROLE.transformArguments(), + ['ROLE'] + ); + }); + + describe('transformReply', () => { + it('master', () => { + assert.deepEqual( + ROLE.transformReply(['master', 3129659, [['127.0.0.1', '9001', '3129242'], ['127.0.0.1', '9002', '3129543']]] as any), + { + role: 'master', + replicationOffest: 3129659, + replicas: [{ + host: '127.0.0.1', + port: 9001, + replicationOffest: 3129242 + }, { + host: '127.0.0.1', + port: 9002, + replicationOffest: 3129543 + }] + } + ); }); - describe('transformReply', () => { - it('master', () => { - assert.deepEqual( - transformReply(['master', 3129659, [['127.0.0.1', '9001', '3129242'], ['127.0.0.1', '9002', '3129543']]]), - { - role: 'master', - replicationOffest: 3129659, - replicas: [{ - ip: '127.0.0.1', - port: 9001, - replicationOffest: 3129242 - }, { - ip: '127.0.0.1', - port: 9002, - replicationOffest: 3129543 - }] - } - ); - }); - - it('replica', () => { - assert.deepEqual( - transformReply(['slave', '127.0.0.1', 9000, 'connected', 3167038]), - { - role: 'slave', - master: { - ip: '127.0.0.1', - port: 9000 - }, - state: 'connected', - dataReceived: 3167038 - } - ); - }); - - it('sentinel', () => { - assert.deepEqual( - transformReply(['sentinel', ['resque-master', 'html-fragments-master', 'stats-master', 'metadata-master']]), - { - role: 'sentinel', - masterNames: ['resque-master', 'html-fragments-master', 'stats-master', 'metadata-master'] - } - ); - }); + it('replica', () => { + assert.deepEqual( + ROLE.transformReply(['slave', '127.0.0.1', 9000, 'connected', 3167038] as any), + { + role: 'slave', + master: { + host: '127.0.0.1', + port: 9000 + }, + state: 'connected', + dataReceived: 3167038 + } + ); }); - testUtils.testWithClient('client.role', async client => { - assert.deepEqual( - await client.role(), - { - role: 'master', - replicationOffest: 0, - replicas: [] - } - ); - }, GLOBAL.SERVERS.OPEN); + it('sentinel', () => { + assert.deepEqual( + ROLE.transformReply(['sentinel', ['resque-master', 'html-fragments-master', 'stats-master', 'metadata-master']] as any), + { + role: 'sentinel', + masterNames: ['resque-master', 'html-fragments-master', 'stats-master', 'metadata-master'] + } + ); + }); + }); + + testUtils.testWithClient('client.role', async client => { + assert.deepEqual( + await client.role(), + { + role: 'master', + replicationOffest: 0, + replicas: [] + } + ); + }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/client/lib/commands/ROLE.ts b/packages/client/lib/commands/ROLE.ts index 2cab0a783e..40b9d67047 100644 --- a/packages/client/lib/commands/ROLE.ts +++ b/packages/client/lib/commands/ROLE.ts @@ -3,7 +3,7 @@ import { ArrayReply, BlobStringReply, Command, NumberReply } from '../RESP/types type MasterRole = [ role: BlobStringReply<'master'>, replicationOffest: NumberReply, - replicas: ArrayReply<[host: BlobStringReply, port: NumberReply, replicationOffest: NumberReply]>, + replicas: ArrayReply<[host: BlobStringReply, port: BlobStringReply, replicationOffest: BlobStringReply]> ]; type SlaveRole = [ @@ -36,8 +36,8 @@ export default { replicationOffest, replicas: replicas.map(([host, port, replicationOffest]) => ({ host, - port, - replicationOffest, + port: Number(port), + replicationOffest: Number(replicationOffest) })), }; } @@ -48,7 +48,7 @@ export default { role, master: { host: masterHost, - port: masterPort, + port: masterPort }, state, dataReceived, @@ -59,7 +59,7 @@ export default { const [role, masterNames] = reply as SentinelRole; return { role, - masterNames, + masterNames }; } } diff --git a/packages/client/lib/commands/SHUTDOWN.spec.ts b/packages/client/lib/commands/SHUTDOWN.spec.ts index caa3a5dfd0..4d0d54dc87 100644 --- a/packages/client/lib/commands/SHUTDOWN.spec.ts +++ b/packages/client/lib/commands/SHUTDOWN.spec.ts @@ -1,27 +1,49 @@ -// import { strict as assert } from 'assert'; -// import { transformArguments } from './SHUTDOWN'; +import { strict as assert } from 'assert'; +import SHUTDOWN from './SHUTDOWN'; -// describe('SHUTDOWN', () => { -// describe('transformArguments', () => { -// it('simple', () => { -// assert.deepEqual( -// transformArguments(), -// ['SHUTDOWN'] -// ); -// }); +describe('SHUTDOWN', () => { + describe('transformArguments', () => { + it('simple', () => { + assert.deepEqual( + SHUTDOWN.transformArguments(), + ['SHUTDOWN'] + ); + }); -// it('NOSAVE', () => { -// assert.deepEqual( -// transformArguments('NOSAVE'), -// ['SHUTDOWN', 'NOSAVE'] -// ); -// }); + it('with mode', () => { + assert.deepEqual( + SHUTDOWN.transformArguments({ + mode: 'NOSAVE' + }), + ['SHUTDOWN', 'NOSAVE'] + ); + }); -// it('SAVE', () => { -// assert.deepEqual( -// transformArguments('SAVE'), -// ['SHUTDOWN', 'SAVE'] -// ); -// }); -// }); -// }); + it('with NOW', () => { + assert.deepEqual( + SHUTDOWN.transformArguments({ + NOW: true + }), + ['SHUTDOWN', 'NOW'] + ); + }); + + it('with FORCE', () => { + assert.deepEqual( + SHUTDOWN.transformArguments({ + FORCE: true + }), + ['SHUTDOWN', 'FORCE'] + ); + }); + + it('with ABORT', () => { + assert.deepEqual( + SHUTDOWN.transformArguments({ + ABORT: true + }), + ['SHUTDOWN', 'ABORT'] + ); + }); + }); +}); diff --git a/packages/client/lib/commands/SHUTDOWN.ts b/packages/client/lib/commands/SHUTDOWN.ts index e2c544c389..e0f3d08ce8 100644 --- a/packages/client/lib/commands/SHUTDOWN.ts +++ b/packages/client/lib/commands/SHUTDOWN.ts @@ -1,11 +1,35 @@ -// export function transformArguments(mode?: 'NOSAVE' | 'SAVE'): Array { -// const args = ['SHUTDOWN']; +import { SimpleStringReply, Command } from '../RESP/types'; -// if (mode) { -// args.push(mode); -// } +export interface ShutdownOptions { + mode?: 'NOSAVE' | 'SAVE'; + NOW?: boolean; + FORCE?: boolean; + ABORT?: boolean; +} -// return args; -// } +export default { + FIRST_KEY_INDEX: undefined, + IS_READ_ONLY: false, + transformArguments(options?: ShutdownOptions) { + const args = ['SHUTDOWN'] -// export declare function transformReply(): void; + if (options?.mode) { + args.push(options.mode); + } + + if (options?.NOW) { + args.push('NOW'); + } + + if (options?.FORCE) { + args.push('FORCE'); + } + + if (options?.ABORT) { + args.push('ABORT'); + } + + return args; + }, + transformReply: undefined as unknown as () => void | SimpleStringReply +} as const satisfies Command; diff --git a/packages/client/lib/commands/SWAPDB.spec.ts b/packages/client/lib/commands/SWAPDB.spec.ts index dee881b5dc..a4c6d1833a 100644 --- a/packages/client/lib/commands/SWAPDB.spec.ts +++ b/packages/client/lib/commands/SWAPDB.spec.ts @@ -1,19 +1,19 @@ -// import { strict as assert } from 'assert'; -// import testUtils, { GLOBAL } from '../test-utils'; -// import { transformArguments } from './SWAPDB'; +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import SWAPDB from './SWAPDB'; -// describe('SWAPDB', () => { -// it('transformArguments', () => { -// assert.deepEqual( -// transformArguments(0, 1), -// ['SWAPDB', '0', '1'] -// ); -// }); +describe('SWAPDB', () => { + it('transformArguments', () => { + assert.deepEqual( + SWAPDB.transformArguments(0, 1), + ['SWAPDB', '0', '1'] + ); + }); -// testUtils.testWithClient('client.swapDb', async client => { -// assert.equal( -// await client.swapDb(0, 1), -// 'OK' -// ); -// }, GLOBAL.SERVERS.OPEN); -// }); + testUtils.testWithClient('client.swapDb', async client => { + assert.equal( + await client.swapDb(0, 1), + 'OK' + ); + }, GLOBAL.SERVERS.OPEN); +}); diff --git a/packages/client/lib/commands/SWAPDB.ts b/packages/client/lib/commands/SWAPDB.ts index 0ab785fb59..f3b768e95f 100644 --- a/packages/client/lib/commands/SWAPDB.ts +++ b/packages/client/lib/commands/SWAPDB.ts @@ -1,5 +1,11 @@ -// export function transformArguments(index1: number, index2: number): Array { -// return ['SWAPDB', index1.toString(), index2.toString()]; -// } +import { SimpleStringReply, Command } from '../RESP/types'; + +export default { + FIRST_KEY_INDEX: undefined, + IS_READ_ONLY: false, + transformArguments(index1: number, index2: number) { + return ['SWAPDB', index1.toString(), index2.toString()]; + }, + transformReply: undefined as unknown as () => SimpleStringReply<'OK'> +} as const satisfies Command; -// export declare function transformReply(): string; diff --git a/packages/client/lib/commands/TIME.spec.ts b/packages/client/lib/commands/TIME.spec.ts index 5bfd1e50d9..a9e2448dbd 100644 --- a/packages/client/lib/commands/TIME.spec.ts +++ b/packages/client/lib/commands/TIME.spec.ts @@ -1,18 +1,19 @@ -// import { strict as assert } from 'assert'; -// import testUtils, { GLOBAL } from '../test-utils'; -// import { transformArguments } from './TIME'; +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import TIME from './TIME'; -// describe('TIME', () => { -// it('transformArguments', () => { -// assert.deepEqual( -// transformArguments(), -// ['TIME'] -// ); -// }); +describe('TIME', () => { + it('transformArguments', () => { + assert.deepEqual( + TIME.transformArguments(), + ['TIME'] + ); + }); -// testUtils.testWithClient('client.time', async client => { -// const reply = await client.time(); -// assert.ok(reply instanceof Date); -// assert.ok(typeof reply.microseconds === 'number'); -// }, GLOBAL.SERVERS.OPEN); -// }); + testUtils.testWithClient('client.time', async client => { + const reply = await client.time(); + assert.ok(Array.isArray(reply)); + assert.equal(typeof reply[0], 'string'); + assert.equal(typeof reply[1], 'string'); + }, GLOBAL.SERVERS.OPEN); +}); diff --git a/packages/client/lib/commands/TIME.ts b/packages/client/lib/commands/TIME.ts index 298a4d5aee..d4dc67ae48 100644 --- a/packages/client/lib/commands/TIME.ts +++ b/packages/client/lib/commands/TIME.ts @@ -1,15 +1,13 @@ -// export function transformArguments(): Array { -// return ['TIME']; -// } +import { BlobStringReply, Command } from '../RESP/types'; -// interface TimeReply extends Date { -// microseconds: number; -// } - -// export function transformReply(reply: [string, string]): TimeReply { -// const seconds = Number(reply[0]), -// microseconds = Number(reply[1]), -// d: Partial = new Date(seconds * 1000 + microseconds / 1000); -// d.microseconds = microseconds; -// return d as TimeReply; -// } +export default { + FIRST_KEY_INDEX: undefined, + IS_READ_ONLY: true, + transformArguments() { + return ['TIME']; + }, + transformReply: undefined as unknown as () => [ + unixTimestamp: BlobStringReply<`${number}`>, + microseconds: BlobStringReply<`${number}`> + ] +} as const satisfies Command; diff --git a/packages/client/lib/commands/index.ts b/packages/client/lib/commands/index.ts index aca729b4e1..73cfe3c89e 100644 --- a/packages/client/lib/commands/index.ts +++ b/packages/client/lib/commands/index.ts @@ -52,7 +52,7 @@ import CLUSTER_FORGET from './CLUSTER_FORGET'; import CLUSTER_GETKEYSINSLOT from './CLUSTER_GETKEYSINSLOT'; // import CLUSTER_INFO from './CLUSTER_INFO'; import CLUSTER_KEYSLOT from './CLUSTER_KEYSLOT'; -// import CLUSTER_LINKS from './CLUSTER_LINKS'; +import CLUSTER_LINKS from './CLUSTER_LINKS'; import CLUSTER_MEET from './CLUSTER_MEET'; import CLUSTER_MYID from './CLUSTER_MYID'; // import CLUSTER_NODES from './CLUSTER_NODES'; @@ -63,6 +63,10 @@ import CLUSTER_SAVECONFIG from './CLUSTER_SAVECONFIG'; import CLUSTER_SET_CONFIG_EPOCH from './CLUSTER_SET-CONFIG-EPOCH'; import CLUSTER_SETSLOT from './CLUSTER_SETSLOT'; import CLUSTER_SLOTS from './CLUSTER_SLOTS'; +import CONFIG_GET from './CONFIG_GET'; +import CONFIG_RESETASTAT from './CONFIG_RESETSTAT'; +import CONFIG_REWRITE from './CONFIG_REWRITE'; +import CONFIG_SET from './CONFIG_SET'; import COPY from './COPY'; import DBSIZE from './DBSIZE'; import DECR from './DECR'; @@ -138,6 +142,9 @@ import INCRBYFLOAT from './INCRBYFLOAT'; import INFO from './INFO'; import KEYS from './KEYS'; import LASTSAVE from './LASTSAVE'; +import LATENCY_DOCTOR from './LATENCY_DOCTOR'; +import LATENCY_GRAPH from './LATENCY_GRAPH'; +import LATENCY_LATEST from './LATENCY_LATEST'; import LCS_IDX_WITHMATCHLEN from './LCS_IDX_WITHMATCHLEN'; import LCS_IDX from './LCS_IDX'; import LCS_LEN from './LCS_LEN'; @@ -161,7 +168,7 @@ import LTRIM from './LTRIM'; import MEMORY_DOCTOR from './MEMORY_DOCTOR'; import MEMORY_MALLOC_STATS from './MEMORY_MALLOC-STATS'; import MEMORY_PURGE from './MEMORY_PURGE'; -// import MEMORY_STATS from './MEMORY_STATS'; +import MEMORY_STATS from './MEMORY_STATS'; import MEMORY_USAGE from './MEMORY_USAGE'; import MGET from './MGET'; import MODULE_LIST from './MODULE_LIST'; @@ -193,6 +200,7 @@ import RANDOMKEY from './RANDOMKEY'; import READONLY from './READONLY'; import RENAME from './RENAME'; import RENAMENX from './RENAMENX'; +import ROLE from './ROLE'; import RPOP_COUNT from './RPOP_COUNT'; import RPOP from './RPOP'; import RPOPLPUSH from './RPOPLPUSH'; @@ -233,6 +241,8 @@ import SSCAN from './SSCAN'; import STRLEN from './STRLEN'; import SUNION from './SUNION'; import SUNIONSTORE from './SUNIONSTORE'; +import SWAPDB from './SWAPDB'; +import TIME from './TIME'; import TOUCH from './TOUCH'; import TTL from './TTL'; import TYPE from './TYPE'; @@ -335,7 +345,7 @@ type CLUSTER_FORGET = typeof import('./CLUSTER_FORGET').default; type CLUSTER_GETKEYSINSLOT = typeof import('./CLUSTER_GETKEYSINSLOT').default; // type CLUSTER_INFO = typeof import('./CLUSTER_INFO').default; type CLUSTER_KEYSLOT = typeof import('./CLUSTER_KEYSLOT').default; -// type CLUSTER_LINKS = typeof import('./CLUSTER_LINKS').default; +type CLUSTER_LINKS = typeof import('./CLUSTER_LINKS').default; type CLUSTER_MEET = typeof import('./CLUSTER_MEET').default; type CLUSTER_MYID = typeof import('./CLUSTER_MYID').default; // type CLUSTER_NODES = typeof import('./CLUSTER_NODES').default; @@ -346,6 +356,10 @@ type CLUSTER_SAVECONFIG = typeof import('./CLUSTER_SAVECONFIG').default; type CLUSTER_SET_CONFIG_EPOCH = typeof import('./CLUSTER_SET-CONFIG-EPOCH').default; type CLUSTER_SETSLOT = typeof import('./CLUSTER_SETSLOT').default; type CLUSTER_SLOTS = typeof import('./CLUSTER_SLOTS').default; +type CONFIG_GET = typeof import('./CONFIG_GET').default; +type CONFIG_RESETASTAT = typeof import('./CONFIG_RESETSTAT').default; +type CONFIG_REWRITE = typeof import('./CONFIG_REWRITE').default; +type CONFIG_SET = typeof import('./CONFIG_SET').default; type COPY = typeof import('./COPY').default; type DBSIZE = typeof DBSIZE; type DECR = typeof import('./DECR').default; @@ -421,6 +435,9 @@ type INCRBYFLOAT = typeof import('./INCRBYFLOAT').default; type INFO = typeof import('./INFO').default; type KEYS = typeof import('./KEYS').default; type LASTSAVE = typeof import('./LASTSAVE').default; +type LATENCY_DOCTOR = typeof import('./LATENCY_DOCTOR').default; +type LATENCY_GRAPH = typeof import('./LATENCY_GRAPH').default; +type LATENCY_LATEST = typeof import('./LATENCY_LATEST').default; type LCS_IDX_WITHMATCHLEN = typeof import('./LCS_IDX_WITHMATCHLEN').default; type LCS_IDX = typeof import('./LCS_IDX').default; type LCS_LEN = typeof import('./LCS_LEN').default; @@ -444,7 +461,7 @@ type LTRIM = typeof import('./LTRIM').default; type MEMORY_DOCTOR = typeof import('./MEMORY_DOCTOR').default; type MEMORY_MALLOC_STATS = typeof import('./MEMORY_MALLOC-STATS').default; type MEMORY_PURGE = typeof import('./MEMORY_PURGE').default; -// type MEMORY_STATS = typeof import('./MEMORY_STATS').default; +type MEMORY_STATS = typeof import('./MEMORY_STATS').default; type MEMORY_USAGE = typeof import('./MEMORY_USAGE').default; type MGET = typeof import('./MGET').default; type MODULE_LIST = typeof import('./MODULE_LIST').default; @@ -477,6 +494,7 @@ type READONLY = typeof import('./READONLY').default; type RENAME = typeof import('./RENAME').default; type RENAMENX = typeof import('./RENAMENX').default; type RPOP_COUNT = typeof import('./RPOP_COUNT').default; +type ROLE = typeof import('./ROLE').default; type RPOP = typeof import('./RPOP').default; type RPOPLPUSH = typeof import('./RPOPLPUSH').default; type RPUSH = typeof import('./RPUSH').default; @@ -516,6 +534,8 @@ type SSCAN = typeof import('./SSCAN').default; type STRLEN = typeof import('./STRLEN').default; type SUNION = typeof import('./SUNION').default; type SUNIONSTORE = typeof import('./SUNIONSTORE').default; +type SWAPDB = typeof import('./SWAPDB').default; +type TIME = typeof import('./TIME').default; type TOUCH = typeof import('./TOUCH').default; type TTL = typeof import('./TTL').default; type TYPE = typeof import('./TYPE').default; @@ -672,8 +692,8 @@ type Commands = { // clusterInfo: CLUSTER_INFO; CLUSTER_KEYSLOT: CLUSTER_KEYSLOT; clusterKeySlot: CLUSTER_KEYSLOT; - // CLUSTER_LINKS: CLUSTER_LINKS; - // clusterLinks: CLUSTER_LINKS; + CLUSTER_LINKS: CLUSTER_LINKS; + clusterLinks: CLUSTER_LINKS; CLUSTER_MEET: CLUSTER_MEET; clusterMeet: CLUSTER_MEET; CLUSTER_MYID: CLUSTER_MYID; @@ -694,6 +714,14 @@ type Commands = { clusterSetSlot: CLUSTER_SETSLOT; CLUSTER_SLOTS: CLUSTER_SLOTS; clusterSlots: CLUSTER_SLOTS; + CONFIG_GET: CONFIG_GET; + configGet: CONFIG_GET; + CONFIG_RESETASTAT: CONFIG_RESETASTAT; + configResetStat: CONFIG_RESETASTAT; + CONFIG_REWRITE: CONFIG_REWRITE; + configRewrite: CONFIG_REWRITE; + CONFIG_SET: CONFIG_SET; + configSet: CONFIG_SET; COPY: COPY; copy: COPY; DBSIZE: DBSIZE; @@ -844,6 +872,12 @@ type Commands = { keys: KEYS; LASTSAVE: LASTSAVE; lastSave: LASTSAVE; + LATENCY_DOCTOR: LATENCY_DOCTOR; + latencyDoctor: LATENCY_DOCTOR; + LATENCY_GRAPH: LATENCY_GRAPH; + latencyGraph: LATENCY_GRAPH; + LATENCY_LATEST: LATENCY_LATEST; + latencyLatest: LATENCY_LATEST; LCS_IDX_WITHMATCHLEN: LCS_IDX_WITHMATCHLEN; lcsIdxWithMatchLen: LCS_IDX_WITHMATCHLEN; LCS_IDX: LCS_IDX; @@ -889,8 +923,8 @@ type Commands = { memoryMallocStats: MEMORY_MALLOC_STATS; MEMORY_PURGE: MEMORY_PURGE; memoryPurge: MEMORY_PURGE; - // MEMORY_STATS: MEMORY_STATS; - // memoryStats: MEMORY_STATS; + MEMORY_STATS: MEMORY_STATS; + memoryStats: MEMORY_STATS; MEMORY_USAGE: MEMORY_USAGE; memoryUsage: MEMORY_USAGE; MGET: MGET; @@ -958,6 +992,8 @@ type Commands = { renameNX: RENAMENX; RPOP_COUNT: RPOP_COUNT; rPopCount: RPOP_COUNT; + ROLE: ROLE; + role: ROLE; RPOP: RPOP; rPop: RPOP; RPOPLPUSH: RPOPLPUSH; @@ -1036,6 +1072,10 @@ type Commands = { sUnion: SUNION; SUNIONSTORE: SUNIONSTORE; sUnionStore: SUNIONSTORE; + SWAPDB: SWAPDB; + swapDb: SWAPDB; + TIME: TIME; + time: TIME; TOUCH: TOUCH; touch: TOUCH; TTL: TTL; @@ -1239,8 +1279,8 @@ export default { // clusterInfo: CLUSTER_INFO, CLUSTER_KEYSLOT, clusterKeySlot: CLUSTER_KEYSLOT, - // CLUSTER_LINKS, - // clusterLinks: CLUSTER_LINKS, + CLUSTER_LINKS, + clusterLinks: CLUSTER_LINKS, CLUSTER_MEET, clusterMeet: CLUSTER_MEET, CLUSTER_MYID, @@ -1261,6 +1301,14 @@ export default { clusterSetSlot: CLUSTER_SETSLOT, CLUSTER_SLOTS, clusterSlots: CLUSTER_SLOTS, + CONFIG_GET, + configGet: CONFIG_GET, + CONFIG_RESETASTAT, + configResetStat: CONFIG_RESETASTAT, + CONFIG_REWRITE, + configRewrite: CONFIG_REWRITE, + CONFIG_SET, + configSet: CONFIG_SET, COPY, copy: COPY, DBSIZE, @@ -1313,8 +1361,8 @@ export default { functionList: FUNCTION_LIST, FUNCTION_LOAD, functionLoad: FUNCTION_LOAD, - // FUNCTION_RESTORE, - // functionRestore: FUNCTION_RESTORE, + FUNCTION_RESTORE, + functionRestore: FUNCTION_RESTORE, // FUNCTION_STATS, // functionStats: FUNCTION_STATS, GEOADD, @@ -1411,6 +1459,12 @@ export default { keys: KEYS, LASTSAVE, lastSave: LASTSAVE, + LATENCY_DOCTOR, + latencyDoctor: LATENCY_DOCTOR, + LATENCY_GRAPH, + latencyGraph: LATENCY_GRAPH, + LATENCY_LATEST, + latencyLatest: LATENCY_LATEST, LCS_IDX_WITHMATCHLEN, lcsIdxWithMatchLen: LCS_IDX_WITHMATCHLEN, LCS_IDX, @@ -1456,8 +1510,8 @@ export default { memoryMallocStats: MEMORY_MALLOC_STATS, MEMORY_PURGE, memoryPurge: MEMORY_PURGE, - // MEMORY_STATS, - // memoryStats: MEMORY_STATS, + MEMORY_STATS, + memoryStats: MEMORY_STATS, MEMORY_USAGE, memoryUsage: MEMORY_USAGE, MGET, @@ -1525,6 +1579,8 @@ export default { renameNX: RENAMENX, RPOP_COUNT, rPopCount: RPOP_COUNT, + ROLE, + role: ROLE, RPOP, rPop: RPOP, RPOPLPUSH, @@ -1603,6 +1659,10 @@ export default { sUnion: SUNION, SUNIONSTORE, sUnionStore: SUNIONSTORE, + SWAPDB, + swapDb: SWAPDB, + TIME, + time: TIME, TOUCH, touch: TOUCH, TTL,