From 4dca486a9ccc4d537a146919e0fea4e798a07f93 Mon Sep 17 00:00:00 2001 From: leibale Date: Tue, 13 Jul 2021 19:35:07 -0400 Subject: [PATCH] add some missing commands --- lib/commands/BGSAVE.spec.ts | 23 +++++++++ lib/commands/BGSAVE.ts | 17 +++++++ lib/commands/BITOP.spec.ts | 35 +++++++++++++ lib/commands/BITOP.ts | 19 +++++++ lib/commands/BITPOS.spec.ts | 42 ++++++++++++++++ lib/commands/BITPOS.ts | 21 ++++++++ lib/commands/CONFIG_GET.spec.ts | 11 ++++ lib/commands/CONFIG_GET.ts | 7 +++ lib/commands/CONFIG_RESETSTAT.spec.ts | 11 ++++ lib/commands/CONFIG_RESETSTAT.ts | 7 +++ lib/commands/CONFIG_REWRITE.spec.ts | 11 ++++ lib/commands/CONFIG_REWRITE.ts | 7 +++ lib/commands/CONFIG_SET.spec.ts | 11 ++++ lib/commands/CONFIG_SET.ts | 7 +++ lib/commands/DISCARD.spec.ts | 11 ++++ lib/commands/DISCARD.ts | 7 +++ lib/commands/ECHO.spec.ts | 26 ++++++++++ lib/commands/ECHO.ts | 9 ++++ lib/commands/FAILOVER.spec.ts | 72 +++++++++++++++++++++++++++ lib/commands/FAILOVER.ts | 35 +++++++++++++ lib/commands/GETBIT.spec.ts | 26 ++++++++++ lib/commands/GETBIT.ts | 11 ++++ lib/commands/GETDEL.spec.ts | 27 ++++++++++ lib/commands/GETDEL.ts | 9 ++++ lib/commands/GETRANGE.spec.ts | 27 ++++++++++ lib/commands/GETRANGE.ts | 11 ++++ lib/commands/INFO.spec.ts | 20 ++++++++ lib/commands/INFO.ts | 15 ++++++ lib/commands/READWRITE.spec.ts | 11 ++++ lib/commands/READWRITE.ts | 7 +++ lib/commands/SETBIT.spec.ts | 26 ++++++++++ lib/commands/SETBIT.ts | 9 ++++ lib/commands/SHUTDOWN.spec.ts | 27 ++++++++++ lib/commands/SHUTDOWN.ts | 13 +++++ lib/commands/SWAPDB.spec.ts | 19 +++++++ lib/commands/SWAPDB.ts | 7 +++ lib/commands/TIME.spec.ts | 2 +- lib/commands/XGROUP_DESTROY.spec.ts | 2 +- lib/commands/XGROUP_SETID.spec.ts | 2 +- lib/commands/XINFO_CONSUMERS.spec.ts | 2 +- lib/commands/XINFO_GROUPS.spec.ts | 2 +- lib/commands/generic-transformers.ts | 8 +++ lib/commands/index.ts | 54 ++++++++++++++++++++ 43 files changed, 721 insertions(+), 5 deletions(-) create mode 100644 lib/commands/BGSAVE.spec.ts create mode 100644 lib/commands/BGSAVE.ts create mode 100644 lib/commands/BITOP.spec.ts create mode 100644 lib/commands/BITOP.ts create mode 100644 lib/commands/BITPOS.spec.ts create mode 100644 lib/commands/BITPOS.ts create mode 100644 lib/commands/CONFIG_GET.spec.ts create mode 100644 lib/commands/CONFIG_GET.ts create mode 100644 lib/commands/CONFIG_RESETSTAT.spec.ts create mode 100644 lib/commands/CONFIG_RESETSTAT.ts create mode 100644 lib/commands/CONFIG_REWRITE.spec.ts create mode 100644 lib/commands/CONFIG_REWRITE.ts create mode 100644 lib/commands/CONFIG_SET.spec.ts create mode 100644 lib/commands/CONFIG_SET.ts create mode 100644 lib/commands/DISCARD.spec.ts create mode 100644 lib/commands/DISCARD.ts create mode 100644 lib/commands/ECHO.spec.ts create mode 100644 lib/commands/ECHO.ts create mode 100644 lib/commands/FAILOVER.spec.ts create mode 100644 lib/commands/FAILOVER.ts create mode 100644 lib/commands/GETBIT.spec.ts create mode 100644 lib/commands/GETBIT.ts create mode 100644 lib/commands/GETDEL.spec.ts create mode 100644 lib/commands/GETDEL.ts create mode 100644 lib/commands/GETRANGE.spec.ts create mode 100644 lib/commands/GETRANGE.ts create mode 100644 lib/commands/INFO.spec.ts create mode 100644 lib/commands/INFO.ts create mode 100644 lib/commands/READWRITE.spec.ts create mode 100644 lib/commands/READWRITE.ts create mode 100644 lib/commands/SETBIT.spec.ts create mode 100644 lib/commands/SETBIT.ts create mode 100644 lib/commands/SHUTDOWN.spec.ts create mode 100644 lib/commands/SHUTDOWN.ts create mode 100644 lib/commands/SWAPDB.spec.ts create mode 100644 lib/commands/SWAPDB.ts diff --git a/lib/commands/BGSAVE.spec.ts b/lib/commands/BGSAVE.spec.ts new file mode 100644 index 0000000000..8e4de5eef5 --- /dev/null +++ b/lib/commands/BGSAVE.spec.ts @@ -0,0 +1,23 @@ +import { strict as assert } from 'assert'; +import { describe } from 'mocha'; +import { transformArguments } from './BGSAVE'; + +describe('BGSAVE', () => { + describe('transformArguments', () => { + it('simple', () => { + assert.deepEqual( + transformArguments(), + ['BGSAVE'] + ); + }); + + it('with SCHEDULE', () => { + assert.deepEqual( + transformArguments({ + SCHEDULE: true + }), + ['BGSAVE', 'SCHEDULE'] + ); + }); + }); +}); diff --git a/lib/commands/BGSAVE.ts b/lib/commands/BGSAVE.ts new file mode 100644 index 0000000000..f09f906ade --- /dev/null +++ b/lib/commands/BGSAVE.ts @@ -0,0 +1,17 @@ +import { transformReplyString } from './generic-transformers'; + +interface BgSaveOptions { + SCHEDULE?: true; +} + +export function transformArguments(options?: BgSaveOptions): Array { + const args = ['BGSAVE']; + + if (options?.SCHEDULE) { + args.push('SCHEDULE'); + } + + return args; +} + +export const transformReply = transformReplyString; \ No newline at end of file diff --git a/lib/commands/BITOP.spec.ts b/lib/commands/BITOP.spec.ts new file mode 100644 index 0000000000..aa863e5f2d --- /dev/null +++ b/lib/commands/BITOP.spec.ts @@ -0,0 +1,35 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient, TestRedisClusters, itWithCluster } from '../test-utils'; +import { transformArguments } from './BITOP'; + +describe('BITOP', () => { + describe('transformArguments', () => { + it('single key', () => { + assert.deepEqual( + transformArguments('AND', 'destKey', 'key'), + ['BITOP', 'AND', 'destKey', 'key'] + ); + }); + + it('multiple keys', () => { + assert.deepEqual( + transformArguments('AND', 'destKey', ['1', '2']), + ['BITOP', 'AND', 'destKey', '1', '2'] + ); + }); + }); + + itWithClient(TestRedisServers.OPEN, 'client.bitOp', async client => { + assert.equal( + await client.bitOp('AND', 'destKey', 'key'), + 0 + ); + }); + + itWithCluster(TestRedisClusters.OPEN, 'cluster.bitOp', async cluster => { + assert.equal( + await cluster.bitOp('AND', '{tag}destKey', '{tag}key'), + 0 + ); + }); +}); diff --git a/lib/commands/BITOP.ts b/lib/commands/BITOP.ts new file mode 100644 index 0000000000..ba1215752e --- /dev/null +++ b/lib/commands/BITOP.ts @@ -0,0 +1,19 @@ +import { transformReplyNumber } from './generic-transformers'; + +export const FIRST_KEY_INDEX = 2; + +type BitOperations = 'AND' | 'OR' | 'XOR' | 'NOT'; + +export function transformArguments(operation: BitOperations, destKey: string, key: string | Array): Array { + const args = ['BITOP', operation, destKey]; + + if (typeof key === 'string') { + args.push(key); + } else { + args.push(...key); + } + + return args; +} + +export const transformReply = transformReplyNumber; diff --git a/lib/commands/BITPOS.spec.ts b/lib/commands/BITPOS.spec.ts new file mode 100644 index 0000000000..ad08e708c5 --- /dev/null +++ b/lib/commands/BITPOS.spec.ts @@ -0,0 +1,42 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient, TestRedisClusters, itWithCluster } from '../test-utils'; +import { transformArguments } from './BITPOS'; + +describe('BITPOS', () => { + describe('transformArguments', () => { + it('simple', () => { + assert.deepEqual( + transformArguments('key', 1), + ['BITPOS', 'key', '1'] + ); + }); + + it('with start', () => { + assert.deepEqual( + transformArguments('key', 1, 1), + ['BITPOS', 'key', '1', '1'] + ); + }); + + it('with start, end', () => { + assert.deepEqual( + transformArguments('key', 1, 1, -1), + ['BITPOS', 'key', '1', '1', '-1'] + ); + }); + }); + + itWithClient(TestRedisServers.OPEN, 'client.bitPos', async client => { + assert.equal( + await client.bitPos('key', 1, 1), + -1 + ); + }); + + itWithCluster(TestRedisClusters.OPEN, 'cluster.bitPos', async cluster => { + assert.equal( + await cluster.bitPos('key', 1, 1), + -1 + ); + }); +}); diff --git a/lib/commands/BITPOS.ts b/lib/commands/BITPOS.ts new file mode 100644 index 0000000000..bebc45b03c --- /dev/null +++ b/lib/commands/BITPOS.ts @@ -0,0 +1,21 @@ +import { BitValue, transformReplyNumber } from './generic-transformers'; + +export const FIRST_KEY_INDEX = 1; + +export const IS_READ_ONLY = true; + +export function transformArguments(key: string, bit: BitValue, start?: number, end?: number): Array { + const args = ['BITPOS', key, bit.toString()]; + + if (typeof start === 'number') { + args.push(start.toString()); + } + + if (typeof end === 'number') { + args.push(end.toString()); + } + + return args; +} + +export const transformReply = transformReplyNumber; \ No newline at end of file diff --git a/lib/commands/CONFIG_GET.spec.ts b/lib/commands/CONFIG_GET.spec.ts new file mode 100644 index 0000000000..83b5c410cf --- /dev/null +++ b/lib/commands/CONFIG_GET.spec.ts @@ -0,0 +1,11 @@ +import { strict as assert } from 'assert'; +import { transformArguments } from './CONFIG_GET'; + +describe('CONFIG GET', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('*'), + ['CONFIG', 'GET', '*'] + ); + }); +}); diff --git a/lib/commands/CONFIG_GET.ts b/lib/commands/CONFIG_GET.ts new file mode 100644 index 0000000000..423683c13a --- /dev/null +++ b/lib/commands/CONFIG_GET.ts @@ -0,0 +1,7 @@ +import { transformReplyTuples } from './generic-transformers'; + +export function transformArguments(parameter: string): Array { + return ['CONFIG', 'GET', parameter]; +} + +export const transformReply = transformReplyTuples; diff --git a/lib/commands/CONFIG_RESETSTAT.spec.ts b/lib/commands/CONFIG_RESETSTAT.spec.ts new file mode 100644 index 0000000000..d3f3048b94 --- /dev/null +++ b/lib/commands/CONFIG_RESETSTAT.spec.ts @@ -0,0 +1,11 @@ +import { strict as assert } from 'assert'; +import { transformArguments } from './CONFIG_RESETSTAT'; + +describe('CONFIG RESETSTAT', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments(), + ['CONFIG', 'RESETSTAT'] + ); + }); +}); diff --git a/lib/commands/CONFIG_RESETSTAT.ts b/lib/commands/CONFIG_RESETSTAT.ts new file mode 100644 index 0000000000..3c87b08d88 --- /dev/null +++ b/lib/commands/CONFIG_RESETSTAT.ts @@ -0,0 +1,7 @@ +import { transformReplyString } from './generic-transformers'; + +export function transformArguments(): Array { + return ['CONFIG', 'RESETSTAT']; +} + +export const transformReply = transformReplyString; diff --git a/lib/commands/CONFIG_REWRITE.spec.ts b/lib/commands/CONFIG_REWRITE.spec.ts new file mode 100644 index 0000000000..cbc3e5b59d --- /dev/null +++ b/lib/commands/CONFIG_REWRITE.spec.ts @@ -0,0 +1,11 @@ +import { strict as assert } from 'assert'; +import { transformArguments } from './CONFIG_REWRITE'; + +describe('CONFIG REWRITE', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments(), + ['CONFIG', 'REWRITE'] + ); + }); +}); diff --git a/lib/commands/CONFIG_REWRITE.ts b/lib/commands/CONFIG_REWRITE.ts new file mode 100644 index 0000000000..0624751712 --- /dev/null +++ b/lib/commands/CONFIG_REWRITE.ts @@ -0,0 +1,7 @@ +import { transformReplyString } from './generic-transformers'; + +export function transformArguments(): Array { + return ['CONFIG', 'REWRITE']; +} + +export const transformReply = transformReplyString; diff --git a/lib/commands/CONFIG_SET.spec.ts b/lib/commands/CONFIG_SET.spec.ts new file mode 100644 index 0000000000..3127e9732b --- /dev/null +++ b/lib/commands/CONFIG_SET.spec.ts @@ -0,0 +1,11 @@ +import { strict as assert } from 'assert'; +import { transformArguments } from './CONFIG_SET'; + +describe('CONFIG SET', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('parameter', 'value'), + ['CONFIG', 'SET', 'parameter', 'value'] + ); + }); +}); diff --git a/lib/commands/CONFIG_SET.ts b/lib/commands/CONFIG_SET.ts new file mode 100644 index 0000000000..894a95cb1c --- /dev/null +++ b/lib/commands/CONFIG_SET.ts @@ -0,0 +1,7 @@ +import { transformReplyString } from './generic-transformers'; + +export function transformArguments(parameter: string, value: string): Array { + return ['CONFIG', 'SET', parameter, value]; +} + +export const transformReply = transformReplyString; diff --git a/lib/commands/DISCARD.spec.ts b/lib/commands/DISCARD.spec.ts new file mode 100644 index 0000000000..b01f9d650d --- /dev/null +++ b/lib/commands/DISCARD.spec.ts @@ -0,0 +1,11 @@ +import { strict as assert } from 'assert'; +import { transformArguments } from './DISCARD'; + +describe('DISCARD', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments(), + ['DISCARD'] + ); + }); +}); diff --git a/lib/commands/DISCARD.ts b/lib/commands/DISCARD.ts new file mode 100644 index 0000000000..b5aaf45cc8 --- /dev/null +++ b/lib/commands/DISCARD.ts @@ -0,0 +1,7 @@ +import { transformReplyString } from './generic-transformers'; + +export function transformArguments(): Array { + return ['DISCARD']; +} + +export const transformReply = transformReplyString; diff --git a/lib/commands/ECHO.spec.ts b/lib/commands/ECHO.spec.ts new file mode 100644 index 0000000000..4a1bf8fe37 --- /dev/null +++ b/lib/commands/ECHO.spec.ts @@ -0,0 +1,26 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient, TestRedisClusters, itWithCluster } from '../test-utils'; +import { transformArguments } from './ECHO'; + +describe('ECHO', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('message'), + ['ECHO', 'message'] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'client.echo', async client => { + assert.equal( + await client.echo('message'), + 'message' + ); + }); + + itWithCluster(TestRedisClusters.OPEN, 'cluster.echo', async cluster => { + assert.equal( + await cluster.echo('message'), + 'message' + ); + }); +}); diff --git a/lib/commands/ECHO.ts b/lib/commands/ECHO.ts new file mode 100644 index 0000000000..007b8f2764 --- /dev/null +++ b/lib/commands/ECHO.ts @@ -0,0 +1,9 @@ +import { transformReplyString } from './generic-transformers'; + +export const IS_READ_ONLY = true; + +export function transformArguments(message: string): Array { + return ['ECHO', message]; +} + +export const transformReply = transformReplyString; diff --git a/lib/commands/FAILOVER.spec.ts b/lib/commands/FAILOVER.spec.ts new file mode 100644 index 0000000000..16094a0dbc --- /dev/null +++ b/lib/commands/FAILOVER.spec.ts @@ -0,0 +1,72 @@ +import { strict as assert } from 'assert'; +import { transformArguments } from './FAILOVER'; + +describe('FAILOVER', () => { + describe('transformArguments', () => { + it('simple', () => { + assert.deepEqual( + transformArguments(), + ['FAILOVER'] + ); + }); + + describe('with TO', () => { + it('simple', () => { + assert.deepEqual( + transformArguments({ + TO: { + host: 'host', + port: 6379 + } + }), + ['FAILOVER', 'TO', 'host', '6379'] + ); + }); + + it('with FORCE', () => { + assert.deepEqual( + transformArguments({ + TO: { + host: 'host', + port: 6379, + FORCE: true + } + }), + ['FAILOVER', 'TO', 'host', '6379', 'FORCE'] + ); + }); + }); + + it('with ABORT', () => { + assert.deepEqual( + transformArguments({ + ABORT: true + }), + ['FAILOVER', 'ABORT'] + ); + }); + + it('with TIMEOUT', () => { + assert.deepEqual( + transformArguments({ + TIMEOUT: 1 + }), + ['FAILOVER', 'TIMEOUT', '1'] + ); + }); + + it('with TO, ABORT, TIMEOUT', () => { + assert.deepEqual( + transformArguments({ + TO: { + host: 'host', + port: 6379 + }, + ABORT: true, + TIMEOUT: 1 + }), + ['FAILOVER', 'TO', 'host', '6379', 'ABORT', 'TIMEOUT', '1'] + ); + }); + }); +}); diff --git a/lib/commands/FAILOVER.ts b/lib/commands/FAILOVER.ts new file mode 100644 index 0000000000..11ccb32a5c --- /dev/null +++ b/lib/commands/FAILOVER.ts @@ -0,0 +1,35 @@ +import { transformReplyString } from './generic-transformers'; + +interface FailoverOptions { + TO?: { + host: string; + port: number; + FORCE?: true; + }; + ABORT?: true; + TIMEOUT?: number; +} + +export function transformArguments(options?: FailoverOptions): Array { + const args = ['FAILOVER']; + + if (options?.TO) { + args.push('TO', options.TO.host, options.TO.port.toString()); + + if (options.TO.FORCE) { + args.push('FORCE'); + } + } + + if (options?.ABORT) { + args.push('ABORT'); + } + + if (options?.TIMEOUT) { + args.push('TIMEOUT', options.TIMEOUT.toString()); + } + + return args; +} + +export const transformReply = transformReplyString; diff --git a/lib/commands/GETBIT.spec.ts b/lib/commands/GETBIT.spec.ts new file mode 100644 index 0000000000..7163b4ba25 --- /dev/null +++ b/lib/commands/GETBIT.spec.ts @@ -0,0 +1,26 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient, TestRedisClusters, itWithCluster } from '../test-utils'; +import { transformArguments } from './GETBIT'; + +describe('GETBIT', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('key', 0), + ['GETBIT', 'key', '0'] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'client.getBit', async client => { + assert.equal( + await client.getBit('key', 0), + 0 + ); + }); + + itWithCluster(TestRedisClusters.OPEN, 'cluster.getBit', async cluster => { + assert.equal( + await cluster.getBit('key', 0), + 0 + ); + }); +}); diff --git a/lib/commands/GETBIT.ts b/lib/commands/GETBIT.ts new file mode 100644 index 0000000000..c7e878f75a --- /dev/null +++ b/lib/commands/GETBIT.ts @@ -0,0 +1,11 @@ +import { transformReplyBit } from './generic-transformers'; + +export const FIRST_KEY_INDEX = 1; + +export const IS_READ_ONLY = true; + +export function transformArguments(key: string, offset: number): Array { + return ['GETBIT', key, offset.toString()]; +} + +export const transformReply = transformReplyBit; diff --git a/lib/commands/GETDEL.spec.ts b/lib/commands/GETDEL.spec.ts new file mode 100644 index 0000000000..df0930f9d9 --- /dev/null +++ b/lib/commands/GETDEL.spec.ts @@ -0,0 +1,27 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient, TestRedisClusters, itWithCluster } from '../test-utils'; +import { transformArguments } from './GETDEL'; + +describe('GETDEL', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('key'), + ['GETDEL', 'key'] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'client.getDel', async client => { + assert.equal( + await client.getDel('key'), + null + ); + }); + + + itWithCluster(TestRedisClusters.OPEN, 'cluster.getDel', async cluster => { + assert.equal( + await cluster.getDel('key'), + null + ); + }); +}); diff --git a/lib/commands/GETDEL.ts b/lib/commands/GETDEL.ts new file mode 100644 index 0000000000..218e057637 --- /dev/null +++ b/lib/commands/GETDEL.ts @@ -0,0 +1,9 @@ +import { transformReplyStringNull } from './generic-transformers'; + +export const FIRST_KEY_INDEX = 1; + +export function transformArguments(key: string): Array { + return ['GETDEL', key]; +} + +export const transformReply = transformReplyStringNull; diff --git a/lib/commands/GETRANGE.spec.ts b/lib/commands/GETRANGE.spec.ts new file mode 100644 index 0000000000..726311e684 --- /dev/null +++ b/lib/commands/GETRANGE.spec.ts @@ -0,0 +1,27 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient, TestRedisClusters, itWithCluster } from '../test-utils'; +import { transformArguments } from './GETRANGE'; + +describe('GETRANGE', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('key', 0, -1), + ['GETRANGE', 'key', '0', '-1'] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'client.getRange', async client => { + assert.equal( + await client.getRange('key', 0, -1), + '' + ); + }); + + + itWithCluster(TestRedisClusters.OPEN, 'cluster.lTrim', async cluster => { + assert.equal( + await cluster.getRange('key', 0, -1), + '' + ); + }); +}); diff --git a/lib/commands/GETRANGE.ts b/lib/commands/GETRANGE.ts new file mode 100644 index 0000000000..9488dd53d5 --- /dev/null +++ b/lib/commands/GETRANGE.ts @@ -0,0 +1,11 @@ +import { transformReplyString } from './generic-transformers'; + +export const FIRST_KEY_INDEX = 1; + +export const IS_READ_ONLY = true; + +export function transformArguments(key: string, start: number, end: number): Array { + return ['GETRANGE', key, start.toString(), end.toString()]; +} + +export const transformReply = transformReplyString; diff --git a/lib/commands/INFO.spec.ts b/lib/commands/INFO.spec.ts new file mode 100644 index 0000000000..118682c7da --- /dev/null +++ b/lib/commands/INFO.spec.ts @@ -0,0 +1,20 @@ +import { strict as assert } from 'assert'; +import { transformArguments } from './INFO'; + +describe('INFO', () => { + describe('transformArguments', () => { + it('simple', () => { + assert.deepEqual( + transformArguments(), + ['INFO'] + ); + }); + + it('server section', () => { + assert.deepEqual( + transformArguments('server'), + ['INFO', 'server'] + ); + }); + }); +}); diff --git a/lib/commands/INFO.ts b/lib/commands/INFO.ts new file mode 100644 index 0000000000..437b5e5b83 --- /dev/null +++ b/lib/commands/INFO.ts @@ -0,0 +1,15 @@ +import { transformReplyString } from './generic-transformers'; + +export const IS_READ_ONLY = true; + +export function transformArguments(section?: string): Array { + const args = ['INFO']; + + if (section) { + args.push(section); + } + + return args; +} + +export const transformReply = transformReplyString; diff --git a/lib/commands/READWRITE.spec.ts b/lib/commands/READWRITE.spec.ts new file mode 100644 index 0000000000..6ce4a3ee56 --- /dev/null +++ b/lib/commands/READWRITE.spec.ts @@ -0,0 +1,11 @@ +import { strict as assert } from 'assert'; +import { transformArguments } from './READWRITE'; + +describe('READWRITE', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments(), + ['READWRITE'] + ); + }); +}); diff --git a/lib/commands/READWRITE.ts b/lib/commands/READWRITE.ts new file mode 100644 index 0000000000..16f9560440 --- /dev/null +++ b/lib/commands/READWRITE.ts @@ -0,0 +1,7 @@ +import { transformReplyString } from './generic-transformers'; + +export function transformArguments(): Array { + return ['READWRITE']; +} + +export const transformReply = transformReplyString; diff --git a/lib/commands/SETBIT.spec.ts b/lib/commands/SETBIT.spec.ts new file mode 100644 index 0000000000..7347913f29 --- /dev/null +++ b/lib/commands/SETBIT.spec.ts @@ -0,0 +1,26 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient, TestRedisClusters, itWithCluster } from '../test-utils'; +import { transformArguments } from './SETBIT'; + +describe('SETBIT', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('key', 0, 1), + ['SETBIT', 'key', '0', '1'] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'client.setBit', async client => { + assert.equal( + await client.setBit('key', 0, 1), + 0 + ); + }); + + itWithCluster(TestRedisClusters.OPEN, 'cluster.setBit', async cluster => { + assert.equal( + await cluster.setBit('key', 0, 1), + 0 + ); + }); +}); diff --git a/lib/commands/SETBIT.ts b/lib/commands/SETBIT.ts new file mode 100644 index 0000000000..0cd41d1b97 --- /dev/null +++ b/lib/commands/SETBIT.ts @@ -0,0 +1,9 @@ +import { BitValue, transformReplyBit } from './generic-transformers'; + +export const FIRST_KEY_INDEX = 1; + +export function transformArguments(key: string, offset: number, value: BitValue) { + return ['SETBIT', key, offset.toString(), value.toString()]; +} + +export const transformReply = transformReplyBit; diff --git a/lib/commands/SHUTDOWN.spec.ts b/lib/commands/SHUTDOWN.spec.ts new file mode 100644 index 0000000000..d58cf4443c --- /dev/null +++ b/lib/commands/SHUTDOWN.spec.ts @@ -0,0 +1,27 @@ +import { strict as assert } from 'assert'; +import { transformArguments } from './SHUTDOWN'; + +describe('SHUTDOWN', () => { + describe('transformArguments', () => { + it('simple', () => { + assert.deepEqual( + transformArguments(), + ['SHUTDOWN'] + ); + }); + + it('NOSAVE', () => { + assert.deepEqual( + transformArguments('NOSAVE'), + ['SHUTDOWN', 'NOSAVE'] + ); + }); + + it('SAVE', () => { + assert.deepEqual( + transformArguments('SAVE'), + ['SHUTDOWN', 'SAVE'] + ); + }); + }); +}); diff --git a/lib/commands/SHUTDOWN.ts b/lib/commands/SHUTDOWN.ts new file mode 100644 index 0000000000..0dd2cf3a5b --- /dev/null +++ b/lib/commands/SHUTDOWN.ts @@ -0,0 +1,13 @@ +import { transformReplyVoid } from './generic-transformers'; + +export function transformArguments(mode?: 'NOSAVE' | 'SAVE'): Array { + const args = ['SHUTDOWN']; + + if (mode) { + args.push(mode); + } + + return args; +} + +export const transformReply = transformReplyVoid; diff --git a/lib/commands/SWAPDB.spec.ts b/lib/commands/SWAPDB.spec.ts new file mode 100644 index 0000000000..1a5637ae43 --- /dev/null +++ b/lib/commands/SWAPDB.spec.ts @@ -0,0 +1,19 @@ +import { strict as assert } from 'assert'; +import { itWithClient, TestRedisServers } from '../test-utils'; +import { transformArguments } from './SWAPDB'; + +describe('SWAPDB', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments(0, 1), + ['SWAPDB', '0', '1'] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'client.swapDb', async client => { + assert.equal( + await client.swapDb(0, 1), + 'OK' + ); + }); +}); diff --git a/lib/commands/SWAPDB.ts b/lib/commands/SWAPDB.ts new file mode 100644 index 0000000000..f0d4dacf3f --- /dev/null +++ b/lib/commands/SWAPDB.ts @@ -0,0 +1,7 @@ +import { transformReplyString } from './generic-transformers'; + +export function transformArguments(index1: number, index2: number): Array { + return ['SWAPDB', index1.toString(), index2.toString()]; +} + +export const transformReply = transformReplyString; diff --git a/lib/commands/TIME.spec.ts b/lib/commands/TIME.spec.ts index 528dc27e8e..1a07114af4 100644 --- a/lib/commands/TIME.spec.ts +++ b/lib/commands/TIME.spec.ts @@ -3,7 +3,7 @@ import { TestRedisServers, itWithClient } from '../test-utils'; import { transformArguments } from './TIME'; describe('TIME', () => { - describe('transformArguments', () => { + it('transformArguments', () => { assert.deepEqual( transformArguments(), ['TIME'] diff --git a/lib/commands/XGROUP_DESTROY.spec.ts b/lib/commands/XGROUP_DESTROY.spec.ts index 38b1e57eb1..e991bc0d66 100644 --- a/lib/commands/XGROUP_DESTROY.spec.ts +++ b/lib/commands/XGROUP_DESTROY.spec.ts @@ -3,7 +3,7 @@ import { TestRedisServers, itWithClient } from '../test-utils'; import { transformArguments } from './XGROUP_DESTROY'; describe('XGROUP DESTROY', () => { - describe('transformArguments', () => { + it('transformArguments', () => { assert.deepEqual( transformArguments('key', 'group'), ['XGROUP', 'DESTROY', 'key', 'group'] diff --git a/lib/commands/XGROUP_SETID.spec.ts b/lib/commands/XGROUP_SETID.spec.ts index 37f3afc631..0fa10cdb0b 100644 --- a/lib/commands/XGROUP_SETID.spec.ts +++ b/lib/commands/XGROUP_SETID.spec.ts @@ -3,7 +3,7 @@ import { TestRedisServers, itWithClient } from '../test-utils'; import { transformArguments } from './XGROUP_SETID'; describe('XGROUP SETID', () => { - describe('transformArguments', () => { + it('transformArguments', () => { assert.deepEqual( transformArguments('key', 'group', '0'), ['XGROUP', 'SETID', 'key', 'group', '0'] diff --git a/lib/commands/XINFO_CONSUMERS.spec.ts b/lib/commands/XINFO_CONSUMERS.spec.ts index 8316d8141b..08ef17e51a 100644 --- a/lib/commands/XINFO_CONSUMERS.spec.ts +++ b/lib/commands/XINFO_CONSUMERS.spec.ts @@ -3,7 +3,7 @@ import { TestRedisServers, itWithClient } from '../test-utils'; import { transformArguments, transformReply } from './XINFO_CONSUMERS'; describe('XINFO CONSUMERS', () => { - describe('transformArguments', () => { + it('transformArguments', () => { assert.deepEqual( transformArguments('key', 'group'), ['XINFO', 'CONSUMERS', 'key', 'group'] diff --git a/lib/commands/XINFO_GROUPS.spec.ts b/lib/commands/XINFO_GROUPS.spec.ts index 294dfd4493..8fbd86ee3e 100644 --- a/lib/commands/XINFO_GROUPS.spec.ts +++ b/lib/commands/XINFO_GROUPS.spec.ts @@ -3,7 +3,7 @@ import { TestRedisServers, itWithClient } from '../test-utils'; import { transformArguments, transformReply } from './XINFO_GROUPS'; describe('XINFO GROUPS', () => { - describe('transformArguments', () => { + it('transformArguments', () => { assert.deepEqual( transformArguments('key'), ['XINFO', 'GROUPS', 'key'] diff --git a/lib/commands/generic-transformers.ts b/lib/commands/generic-transformers.ts index 25089854cf..284bc408f0 100644 --- a/lib/commands/generic-transformers.ts +++ b/lib/commands/generic-transformers.ts @@ -38,6 +38,14 @@ export function transformReplyBooleanArray(reply: Array): Array return reply.map(transformReplyBoolean); } +export type BitValue = 0 | 1; + +export function transformReplyBit(reply: BitValue): BitValue { + return reply; +} + +export function transformReplyVoid(): void {} + export interface ScanOptions { MATCH?: string; COUNT?: number; diff --git a/lib/commands/index.ts b/lib/commands/index.ts index d86753c39c..872bfdd5a2 100644 --- a/lib/commands/index.ts +++ b/lib/commands/index.ts @@ -14,8 +14,11 @@ import * as APPEND from './APPEND'; import * as ASKING from './ASKING'; import * as AUTH from './AUTH'; import * as BGREWRITEAOF from './BGREWRITEAOF'; +import * as BGSAVE from './BGSAVE'; import * as BITCOUNT from './BITCOUNT'; import * as BITFIELD from './BITFIELD'; +import * as BITOP from './BITOP'; +import * as BITPOS from './BITPOS'; import * as BLMOVE from './BLMOVE'; import * as BLPOP from './BLPOP'; import * as BRPOP from './BRPOP'; @@ -30,17 +33,27 @@ import * as CLUSTER_NODES from './CLUSTER_NODES'; import * as CLUSTER_MEET from './CLUSTER_MEET'; import * as CLUSTER_RESET from './CLUSTER_RESET'; import * as CLUSTER_SETSLOT from './CLUSTER_SETSLOT'; +import * as CONFIG_GET from './CONFIG_GET'; +import * as CONFIG_RESETASTAT from './CONFIG_RESETSTAT'; +import * as CONFIG_REWRITE from './CONFIG_REWRITE'; +import * as CONFIG_SET from './CONFIG_SET'; import * as COPY from './COPY'; import * as DECR from './DECR'; import * as DECRBY from './DECRBY'; import * as DEL from './DEL'; +import * as DISCARD from './DISCARD'; import * as DUMP from './DUMP'; +import * as ECHO from './ECHO'; import * as EXISTS from './EXISTS'; import * as EXPIRE from './EXPIRE'; import * as EXPIREAT from './EXPIREAT'; +import * as FAILOVER from './FAILOVER'; import * as FLUSHALL from './FLUSHALL'; import * as FLUSHDB from './FLUSHDB'; import * as GET from './GET'; +import * as GETBIT from './GETBIT'; +import * as GETDEL from './GETDEL'; +import * as GETRANGE from './GETRANGE'; import * as HDEL from './HDEL'; import * as HEXISTS from './HEXISTS'; import * as HGET from './HGET'; @@ -61,6 +74,7 @@ import * as HVALS from './HVALS'; import * as INCR from './INCR'; import * as INCRBY from './INCRBY'; import * as INCRBYFLOAT from './INCRBYFLOAT'; +import * as INFO from './INFO'; import * as KEYS from './KEYS'; import * as LASTSAVE from './LASTSAVE'; import * as LINDEX from './LINDEX'; @@ -94,6 +108,7 @@ import * as PTTL from './PTTL'; import * as PUBLISH from './PUBLISH'; import * as RANDOMKEY from './RANDOMKEY'; import * as READONLY from './READONLY'; +import * as READWRITE from './READWRITE'; import * as RENAME from './RENAME'; import * as RENAMENX from './RENAMENX'; import * as REPLICAOF from './REPLICAOF'; @@ -109,7 +124,9 @@ import * as SCARD from './SCARD'; import * as SDIFF from './SDIFF'; import * as SDIFFSTORE from './SDIFFSTORE'; import * as SET from './SET'; +import * as SETBIT from './SETBIT'; import * as SETRANGE from './SETRANGE'; +import * as SHUTDOWN from './SHUTDOWN'; import * as SINTER from './SINTER'; import * as SINTERSTORE from './SINTERSTORE'; import * as SISMEMBER from './SISMEMBER'; @@ -125,6 +142,7 @@ import * as SSCAN from './SSCAN'; import * as STRLEN from './STRLEN'; import * as SUNION from './SUNION'; import * as SUNIONSTORE from './SUNIONSTORE'; +import * as SWAPDB from './SWAPDB'; import * as TIME from './TIME'; import * as TOUCH from './TOUCH'; import * as TTL from './TTL'; @@ -221,10 +239,16 @@ export default { auth: AUTH, BGREWRITEAOF, bgRewriteAof: BGREWRITEAOF, + BGSAVE, + bgSave: BGSAVE, BITCOUNT, bitCount: BITCOUNT, BITFIELD, bitField: BITFIELD, + BITOP, + bitOp: BITOP, + BITPOS, + bitPos: BITPOS, BLMOVE, blMove: BLMOVE, BLPOP, @@ -253,6 +277,14 @@ export default { clusterReset: CLUSTER_RESET, CLUSTER_SETSLOT, clusterSetSlot: CLUSTER_SETSLOT, + CONFIG_GET, + configGet: CONFIG_GET, + CONFIG_RESETASTAT, + configResetStat: CONFIG_RESETASTAT, + CONFIG_REWRITE, + configRewrite: CONFIG_REWRITE, + CONFIG_SET, + configSet: CONFIG_SET, COPY, copy: COPY, DECR, @@ -261,20 +293,32 @@ export default { decrBy: DECRBY, DEL, del: DEL, + DISCARD, + discard: DISCARD, DUMP, dump: DUMP, + ECHO, + echo: ECHO, EXISTS, exists: EXISTS, EXPIRE, expire: EXPIRE, EXPIREAT, expireAt: EXPIREAT, + FAILOVER, + failover: FAILOVER, FLUSHALL, flushAll: FLUSHALL, FLUSHDB, flushDb: FLUSHDB, GET, get: GET, + GETBIT, + getBit: GETBIT, + GETDEL, + getDel: GETDEL, + GETRANGE, + getRange: GETRANGE, HDEL, hDel: HDEL, HEXISTS, @@ -315,6 +359,8 @@ export default { incrBy: INCRBY, INCRBYFLOAT, incrByFloat: INCRBYFLOAT, + INFO, + info: INFO, KEYS, keys: KEYS, LASTSAVE, @@ -380,6 +426,8 @@ export default { randomKey: RANDOMKEY, READONLY, readonly: READONLY, + READWRITE, + readwrite: READWRITE, RENAME, rename: RENAME, RENAMENX, @@ -414,8 +462,12 @@ export default { sInterStore: SINTERSTORE, SET, set: SET, + SETBIT, + setBit: SETBIT, SETRANGE, setRange: SETRANGE, + SHUTDOWN, + shutdown: SHUTDOWN, SISMEMBER, sIsMember: SISMEMBER, SMEMBERS, @@ -442,6 +494,8 @@ export default { sUnion: SUNION, SUNIONSTORE, sUnionStore: SUNIONSTORE, + SWAPDB, + swapDb: SWAPDB, TIME, time: TIME, TOUCH,