diff --git a/lib/commands/BITCOUNT.spec.ts b/lib/commands/BITCOUNT.spec.ts new file mode 100644 index 0000000000..bf4cf39cab --- /dev/null +++ b/lib/commands/BITCOUNT.spec.ts @@ -0,0 +1,31 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient } from '../test-utils'; +import { transformArguments } from './BITCOUNT'; + +describe('BITCOUNT', () => { + describe('transformArguments', () => { + it('simple', () => { + assert.deepEqual( + transformArguments('key'), + ['BITCOUNT', 'key'] + ); + }); + + it('with range', () => { + assert.deepEqual( + transformArguments('key', { + start: 0, + end: 1 + }), + ['BITCOUNT', 'key', '0', '1'] + ); + }); + }); + + itWithClient(TestRedisServers.OPEN, 'client.bitCount', async client => { + assert.equal( + await client.bitCount('key'), + 0 + ); + }); +}); diff --git a/lib/commands/BITCOUNT.ts b/lib/commands/BITCOUNT.ts new file mode 100644 index 0000000000..1aececc377 --- /dev/null +++ b/lib/commands/BITCOUNT.ts @@ -0,0 +1,25 @@ +import { transformReplyNumber } from './generic-transformers'; + +export const FIRST_KEY_INDEX = 1; + +export const IS_READ_ONLY = true; + +interface BitCountRange { + start: number; + end: number; +} + +export function transformArguments(key: string, range?: BitCountRange): Array { + const args = ['BITCOUNT', key]; + + if (range) { + args.push( + range.start.toString(), + range.end.toString() + ); + } + + return args; +} + +export const transformReply = transformReplyNumber; \ No newline at end of file diff --git a/lib/commands/BITFIELD.spec.ts b/lib/commands/BITFIELD.spec.ts new file mode 100644 index 0000000000..0e43413ca3 --- /dev/null +++ b/lib/commands/BITFIELD.spec.ts @@ -0,0 +1,91 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient } from '../test-utils'; +import { transformArguments } from './BITFIELD'; + +describe('BITFIELD', () => { + describe('transformArguments', () => { + it('simple', () => { + assert.deepEqual( + transformArguments('key'), + ['BITFIELD', 'key'] + ); + }); + + it('with GET', () => { + assert.deepEqual( + transformArguments('key', { + GET: { + type: 'i8', + offset: 0 + } + }), + ['BITFIELD', 'key', 'GET', 'i8', '0'] + ); + }); + + it('with SET', () => { + assert.deepEqual( + transformArguments('key', { + SET: { + type: 'i8', + offset: 0, + value: 0 + } + }), + ['BITFIELD', 'key', 'SET', 'i8', '0', '0'] + ); + }); + + it('with INCRBY', () => { + assert.deepEqual( + transformArguments('key', { + INCRBY: { + type: 'i8', + offset: 0, + increment: 0 + } + }), + ['BITFIELD', 'key', 'INCRBY', 'i8', '0', '0'] + ); + }); + + it('with OVERFLOW', () => { + assert.deepEqual( + transformArguments('key', { + OVERFLOW: 'WRAP' + }), + ['BITFIELD', 'key', 'OVERFLOW', 'WRAP'] + ); + }); + + it('with GET, SET, INCRBY, OVERFLOW', () => { + assert.deepEqual( + transformArguments('key', { + GET: { + type: 'i8', + offset: 0 + }, + SET: { + type: 'i8', + offset: 0, + value: 0 + }, + INCRBY: { + type: 'i8', + offset: 0, + increment: 0 + }, + OVERFLOW: 'WRAP' + }), + ['BITFIELD', 'key', 'GET', 'i8', '0', 'SET', 'i8', '0', '0', 'INCRBY', 'i8', '0', '0', 'OVERFLOW', 'WRAP'] + ); + }) + }); + + itWithClient(TestRedisServers.OPEN, 'client.bitField', async client => { + assert.deepEqual( + await client.bitField('key'), + [] + ); + }); +}); diff --git a/lib/commands/BITFIELD.ts b/lib/commands/BITFIELD.ts new file mode 100644 index 0000000000..0da1fbc2e4 --- /dev/null +++ b/lib/commands/BITFIELD.ts @@ -0,0 +1,66 @@ +import { transformReplyNumber } from './generic-transformers'; + +export const FIRST_KEY_INDEX = 1; + +export const IS_READ_ONLY = true; + +type BitFieldType = string; // TODO 'i[1-64]' | 'u[1-63]' + +interface BitFieldOptions { + GET?: { + type: BitFieldType; + offset: number | string; + }; + SET?: { + type: BitFieldType; + offset: number | string; + value: number; + }; + INCRBY?: { + type: BitFieldType; + offset: number | string; + increment: number; + }; + OVERFLOW?: 'WRAP' | 'SAT' | 'FAIL'; +} + +export function transformArguments(key: string, options?: BitFieldOptions) { + const args = ['BITFIELD', key]; + + if (options?.GET) { + args.push( + 'GET', + options.GET.type, + options.GET.offset.toString() + ); + } + + if (options?.SET) { + args.push( + 'SET', + options.SET.type, + options.SET.offset.toString(), + options.SET.value.toString() + ); + } + + if (options?.INCRBY) { + args.push( + 'INCRBY', + options.INCRBY.type, + options.INCRBY.offset.toString(), + options.INCRBY.increment.toString() + ); + } + + if (options?.OVERFLOW) { + args.push( + 'OVERFLOW', + options.OVERFLOW + ); + } + + return args; +} + +export const transformReply = transformReplyNumber; diff --git a/lib/commands/EXISTS.spec.ts b/lib/commands/EXISTS.spec.ts new file mode 100644 index 0000000000..3cba44b563 --- /dev/null +++ b/lib/commands/EXISTS.spec.ts @@ -0,0 +1,28 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient } from '../test-utils'; +import { transformArguments } from './EXISTS'; + +describe('EXISTS', () => { + describe('transformArguments', () => { + it('string', () => { + assert.deepEqual( + transformArguments('key'), + ['EXISTS', 'key'] + ); + }); + + it('array', () => { + assert.deepEqual( + transformArguments(['1', '2']), + ['EXISTS', '1', '2'] + ); + }); + }); + + itWithClient(TestRedisServers.OPEN, 'client.exists', async client => { + assert.equal( + await client.exists('key'), + false + ); + }); +}); diff --git a/lib/commands/EXISTS.ts b/lib/commands/EXISTS.ts index ce26d20164..cf054dd531 100644 --- a/lib/commands/EXISTS.ts +++ b/lib/commands/EXISTS.ts @@ -1,7 +1,19 @@ import { transformReplyBoolean } from './generic-transformers'; -export function transformArguments(...keys: Array): Array { - return ['EXISTS', ...keys]; +export const FIRST_KEY_INDEX = 1; + +export const IS_READ_ONLY = true; + +export function transformArguments(keys: string | Array): Array { + const args = ['EXISTS']; + + if (typeof keys === 'string') { + args.push(keys); + } else { + args.push(...keys); + } + + return args; } export const transformReply = transformReplyBoolean; diff --git a/lib/commands/EXPIREAT.spec.ts b/lib/commands/EXPIREAT.spec.ts new file mode 100644 index 0000000000..6062adee7c --- /dev/null +++ b/lib/commands/EXPIREAT.spec.ts @@ -0,0 +1,19 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient } from '../test-utils'; +import { transformArguments } from './EXPIRE'; + +describe('EXPIREAT', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('key', 1), + ['EXPIRE', 'key', '1'] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'client.expireAt', async client => { + assert.equal( + await client.expireAt('key', 1), + false + ); + }); +}); diff --git a/lib/commands/MOVE.spec.ts b/lib/commands/MOVE.spec.ts new file mode 100644 index 0000000000..a05ca4613e --- /dev/null +++ b/lib/commands/MOVE.spec.ts @@ -0,0 +1,19 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient } from '../test-utils'; +import { transformArguments } from './MOVE'; + +describe('MOVE', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('key', 1), + ['MOVE', 'key', '1'] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'client.move', async client => { + assert.equal( + await client.move('key', 1), + false + ); + }); +}); diff --git a/lib/commands/MOVE.ts b/lib/commands/MOVE.ts new file mode 100644 index 0000000000..74bb88c5e7 --- /dev/null +++ b/lib/commands/MOVE.ts @@ -0,0 +1,7 @@ +import { transformReplyBoolean } from './generic-transformers'; + +export function transformArguments(key: string, db: number): Array { + return ['MOVE', key, db.toString()]; +} + +export const transformReply = transformReplyBoolean; \ No newline at end of file diff --git a/lib/commands/PERSIST.spec.ts b/lib/commands/PERSIST.spec.ts new file mode 100644 index 0000000000..05c0e7aed8 --- /dev/null +++ b/lib/commands/PERSIST.spec.ts @@ -0,0 +1,19 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient } from '../test-utils'; +import { transformArguments } from './PERSIST'; + +describe('PERSIST', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('key'), + ['PERSIST', 'key'] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'client.persist', async client => { + assert.equal( + await client.persist('key'), + false + ); + }); +}); diff --git a/lib/commands/PERSIST.ts b/lib/commands/PERSIST.ts new file mode 100644 index 0000000000..fc85a21c98 --- /dev/null +++ b/lib/commands/PERSIST.ts @@ -0,0 +1,9 @@ +import { transformReplyBoolean } from './generic-transformers'; + +export const FIRST_KEY_INDEX = 1; + +export function transformArguments(key: string): Array { + return ['PERSIST', key]; +} + +export const transformReply = transformReplyBoolean; diff --git a/lib/commands/PEXPIRE.spec.ts b/lib/commands/PEXPIRE.spec.ts new file mode 100644 index 0000000000..b7c4e1df46 --- /dev/null +++ b/lib/commands/PEXPIRE.spec.ts @@ -0,0 +1,19 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient } from '../test-utils'; +import { transformArguments } from './PEXPIRE'; + +describe('PEXPIRE', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('key', 1), + ['PEXPIRE', 'key', '1'] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'client.pExpire', async client => { + assert.equal( + await client.pExpire('key', 1), + false + ); + }); +}); diff --git a/lib/commands/PEXPIRE.ts b/lib/commands/PEXPIRE.ts new file mode 100644 index 0000000000..d795f2fc0d --- /dev/null +++ b/lib/commands/PEXPIRE.ts @@ -0,0 +1,9 @@ +import { transformReplyBoolean } from './generic-transformers'; + +export const FIRST_KEY_INDEX = 1; + +export function transformArguments(key: string, milliseconds: number): Array { + return ['PEXPIRE', key, milliseconds.toString()]; +} + +export const transformReply = transformReplyBoolean; diff --git a/lib/commands/PEXPIREAT.spec.ts b/lib/commands/PEXPIREAT.spec.ts new file mode 100644 index 0000000000..18e39f9403 --- /dev/null +++ b/lib/commands/PEXPIREAT.spec.ts @@ -0,0 +1,19 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient } from '../test-utils'; +import { transformArguments } from './PEXPIREAT'; + +describe('PEXPIREAT', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('key', 1), + ['PEXPIREAT', 'key', '1'] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'client.pExpireAt', async client => { + assert.equal( + await client.pExpireAt('key', 1), + false + ); + }); +}); diff --git a/lib/commands/PEXPIREAT.ts b/lib/commands/PEXPIREAT.ts new file mode 100644 index 0000000000..551b2eaa82 --- /dev/null +++ b/lib/commands/PEXPIREAT.ts @@ -0,0 +1,9 @@ +import { transformReplyBoolean } from './generic-transformers'; + +export const FIRST_KEY_INDEX = 1; + +export function transformArguments(key: string, millisecondsTimestamp: number): Array { + return ['PEXPIREAT', key, millisecondsTimestamp.toString()]; +} + +export const transformReply = transformReplyBoolean; diff --git a/lib/commands/PTTL.spec.ts b/lib/commands/PTTL.spec.ts new file mode 100644 index 0000000000..35f48c2cc3 --- /dev/null +++ b/lib/commands/PTTL.spec.ts @@ -0,0 +1,19 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient } from '../test-utils'; +import { transformArguments } from './PTTL'; + +describe('PTTL', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('key'), + ['PTTL', 'key'] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'client.pTTL', async client => { + assert.equal( + await client.pTTL('key'), + -2 + ); + }); +}); diff --git a/lib/commands/PTTL.ts b/lib/commands/PTTL.ts new file mode 100644 index 0000000000..8356c75bbd --- /dev/null +++ b/lib/commands/PTTL.ts @@ -0,0 +1,11 @@ +import { transformReplyNumber } from './generic-transformers'; + +export const FIRST_KEY_INDEX = 1; + +export const IS_READ_ONLY = true; + +export function transformArguments(key: string): Array { + return ['PTTL', key]; +} + +export const transformReply = transformReplyNumber; diff --git a/lib/commands/RANDOMKEY.spec.ts b/lib/commands/RANDOMKEY.spec.ts new file mode 100644 index 0000000000..171c42be11 --- /dev/null +++ b/lib/commands/RANDOMKEY.spec.ts @@ -0,0 +1,19 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient } from '../test-utils'; +import { transformArguments } from './RANDOMKEY'; + +describe('RANDOMKEY', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments(), + ['RANDOMKEY'] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'client.randomKey', async client => { + assert.equal( + await client.randomKey(), + null + ); + }); +}); diff --git a/lib/commands/RANDOMKEY.ts b/lib/commands/RANDOMKEY.ts new file mode 100644 index 0000000000..fad0b073c7 --- /dev/null +++ b/lib/commands/RANDOMKEY.ts @@ -0,0 +1,9 @@ +export const IS_READ_ONLY = true; + +export function transformArguments(): Array { + return ['RANDOMKEY']; +} + +export function transformReply(reply: string | null): string | null { + return reply; +} diff --git a/lib/commands/RENAME.spec.ts b/lib/commands/RENAME.spec.ts new file mode 100644 index 0000000000..9d447c600b --- /dev/null +++ b/lib/commands/RENAME.spec.ts @@ -0,0 +1,21 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient } from '../test-utils'; +import { transformArguments } from './RENAME'; + +describe('RENAME', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('from', 'to'), + ['RENAME', 'from', 'to'] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'client.rename', async client => { + await client.set('from', 'value'); + + assert.equal( + await client.rename('from', 'to'), + 'OK' + ); + }); +}); diff --git a/lib/commands/RENAME.ts b/lib/commands/RENAME.ts new file mode 100644 index 0000000000..0f9582677f --- /dev/null +++ b/lib/commands/RENAME.ts @@ -0,0 +1,9 @@ +import { transformReplyString } from './generic-transformers'; + +export const FIRST_KEY_INDEX = 1; + +export function transformArguments(key: string, newKey: string): Array { + return ['RENAME', key, newKey]; +} + +export const transformReply = transformReplyString; diff --git a/lib/commands/RENAMENX.spec.ts b/lib/commands/RENAMENX.spec.ts new file mode 100644 index 0000000000..f438834b90 --- /dev/null +++ b/lib/commands/RENAMENX.spec.ts @@ -0,0 +1,21 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient } from '../test-utils'; +import { transformArguments } from './RENAMENX'; + +describe('RENAMENX', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('from', 'to'), + ['RENAMENX', 'from', 'to'] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'client.renameNX', async client => { + await client.set('from', 'value'); + + assert.equal( + await client.renameNX('from', 'to'), + true + ); + }); +}); diff --git a/lib/commands/RENAMENX.ts b/lib/commands/RENAMENX.ts new file mode 100644 index 0000000000..883d2ca296 --- /dev/null +++ b/lib/commands/RENAMENX.ts @@ -0,0 +1,9 @@ +import { transformReplyBoolean } from './generic-transformers'; + +export const FIRST_KEY_INDEX = 1; + +export function transformArguments(key: string, newKey: string): Array { + return ['RENAMENX', key, newKey]; +} + +export const transformReply = transformReplyBoolean; diff --git a/lib/commands/SORT.spec.ts b/lib/commands/SORT.spec.ts new file mode 100644 index 0000000000..c449e0511f --- /dev/null +++ b/lib/commands/SORT.spec.ts @@ -0,0 +1,106 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient } from '../test-utils'; +import { transformArguments } from './SORT'; + +describe('SORT', () => { + describe('transformArguments', () => { + it('simple', () => { + assert.deepEqual( + transformArguments('key'), + ['SORT', 'key'] + ); + }); + + it('with BY', () => { + assert.deepEqual( + transformArguments('key', { + BY: 'pattern' + }), + ['SORT', 'key', 'BY', 'pattern'] + ); + }); + + it('with LIMIT', () => { + assert.deepEqual( + transformArguments('key', { + LIMIT: { + offset: 0, + count: 1 + } + }), + ['SORT', 'key', 'LIMIT', '0', '1'] + ); + }); + + describe('with GET', () => { + it('string', () => { + assert.deepEqual( + transformArguments('key', { + GET: 'pattern' + }), + ['SORT', 'key', 'GET', 'pattern'] + ); + }); + + it('array', () => { + assert.deepEqual( + transformArguments('key', { + GET: ['1', '2'] + }), + ['SORT', 'key', 'GET', '1', 'GET', '2'] + ); + }); + }); + + it('with DIRECTION', () => { + assert.deepEqual( + transformArguments('key', { + DIRECTION: 'ASC' + }), + ['SORT', 'key', 'ASC'] + ); + }); + + it('with ALPHA', () => { + assert.deepEqual( + transformArguments('key', { + ALPHA: true + }), + ['SORT', 'key', 'ALPHA'] + ); + }); + + it('with STORE', () => { + assert.deepEqual( + transformArguments('key', { + STORE: 'destination' + }), + ['SORT', 'key', 'STORE', 'destination'] + ); + }); + + it('with BY, LIMIT, GET, DIRECTION, ALPHA, STORE', () => { + assert.deepEqual( + transformArguments('key', { + BY: 'pattern', + LIMIT: { + offset: 0, + count: 1 + }, + GET: 'pattern', + DIRECTION: 'ASC', + ALPHA: true, + STORE: 'destination' + }), + ['SORT', 'key', 'BY', 'pattern', 'LIMIT', '0', '1', 'GET', 'pattern', 'ASC', 'ALPHA', 'STORE', 'destination'] + ); + }); + }); + + itWithClient(TestRedisServers.OPEN, 'client.sort', async client => { + assert.deepEqual( + await client.sort('key'), + [] + ); + }); +}); diff --git a/lib/commands/SORT.ts b/lib/commands/SORT.ts new file mode 100644 index 0000000000..0305d93144 --- /dev/null +++ b/lib/commands/SORT.ts @@ -0,0 +1,57 @@ +export const FIRST_KEY_INDEX = 1; + +export const IS_READ_ONLY = true; + + +interface SortOptions { + BY?: string; + LIMIT?: { + offset: number; + count: number; + }, + GET?: string | Array; + DIRECTION?: 'ASC' | 'DESC'; + ALPHA?: true; + STORE?: string; +} + +export function transformArguments(key: string, options?: SortOptions): Array { + const args = ['SORT', key]; + + if (options?.BY) { + args.push('BY', options.BY); + } + + if (options?.LIMIT) { + args.push( + 'LIMIT', + options.LIMIT.offset.toString(), + options.LIMIT.count.toString() + ); + } + + if (options?.GET) { + for (const pattern of (typeof options.GET === 'string' ? [options.GET] : options.GET)) { + args.push('GET', pattern); + } + } + + if (options?.DIRECTION) { + args.push(options.DIRECTION); + } + + if (options?.ALPHA) { + args.push('ALPHA'); + } + + if (options?.STORE) { + args.push('STORE', options.STORE); + } + + return args; +} + +// integer when using `STORE` +export function transformReply(reply: Array | number): Array | number { + return reply; +} diff --git a/lib/commands/TOUCH.spec.ts b/lib/commands/TOUCH.spec.ts new file mode 100644 index 0000000000..c4cb435629 --- /dev/null +++ b/lib/commands/TOUCH.spec.ts @@ -0,0 +1,28 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient } from '../test-utils'; +import { transformArguments } from './TOUCH'; + +describe('TOUCH', () => { + describe('transformArguments', () => { + it('string', () => { + assert.deepEqual( + transformArguments('key'), + ['TOUCH', 'key'] + ); + }); + + it('array', () => { + assert.deepEqual( + transformArguments(['1', '2']), + ['TOUCH', '1', '2'] + ); + }); + }); + + itWithClient(TestRedisServers.OPEN, 'client.touch', async client => { + assert.equal( + await client.touch('key'), + 0 + ); + }); +}); diff --git a/lib/commands/TOUCH.ts b/lib/commands/TOUCH.ts new file mode 100644 index 0000000000..a0551dcc57 --- /dev/null +++ b/lib/commands/TOUCH.ts @@ -0,0 +1,17 @@ +import { transformReplyNumber } from './generic-transformers'; + +export const FIRST_KEY_INDEX = 1; + +export function transformArguments(key: string | Array): Array { + const args = ['TOUCH']; + + if (typeof key === 'string') { + args.push(key); + } else { + args.push(...key); + } + + return args; +} + +export const transformReply = transformReplyNumber; diff --git a/lib/commands/TTL.spec.ts b/lib/commands/TTL.spec.ts new file mode 100644 index 0000000000..bcabe8d39e --- /dev/null +++ b/lib/commands/TTL.spec.ts @@ -0,0 +1,19 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient } from '../test-utils'; +import { transformArguments } from './TTL'; + +describe('TTL', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('key'), + ['TTL', 'key'] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'client.ttl', async client => { + assert.equal( + await client.ttl('key'), + -2 + ); + }); +}); diff --git a/lib/commands/TTL.ts b/lib/commands/TTL.ts new file mode 100644 index 0000000000..aa8462dfea --- /dev/null +++ b/lib/commands/TTL.ts @@ -0,0 +1,11 @@ +import { transformReplyNumber } from './generic-transformers'; + +export const FIRST_KEY_INDEX = 1; + +export const IS_READ_ONLY = true; + +export function transformArguments(key: string): Array { + return ['TTL', key]; +} + +export const transformReply = transformReplyNumber; diff --git a/lib/commands/TYPE.spec.ts b/lib/commands/TYPE.spec.ts new file mode 100644 index 0000000000..d40f724242 --- /dev/null +++ b/lib/commands/TYPE.spec.ts @@ -0,0 +1,19 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient } from '../test-utils'; +import { transformArguments } from './TYPE'; + +describe('TYPE', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments('key'), + ['TYPE', 'key'] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'client.type', async client => { + assert.equal( + await client.type('key'), + 'none' + ); + }); +}); diff --git a/lib/commands/TYPE.ts b/lib/commands/TYPE.ts new file mode 100644 index 0000000000..4f27b29d2b --- /dev/null +++ b/lib/commands/TYPE.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): Array { + return ['TYPE', key]; +} + +export const transformReply = transformReplyString; diff --git a/lib/commands/UNLINK.spec.ts b/lib/commands/UNLINK.spec.ts new file mode 100644 index 0000000000..a0dddf54f2 --- /dev/null +++ b/lib/commands/UNLINK.spec.ts @@ -0,0 +1,28 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient } from '../test-utils'; +import { transformArguments } from './UNLINK'; + +describe('UNLINK', () => { + describe('transformArguments', () => { + it('string', () => { + assert.deepEqual( + transformArguments('key'), + ['UNLINK', 'key'] + ); + }); + + it('array', () => { + assert.deepEqual( + transformArguments(['1', '2']), + ['UNLINK', '1', '2'] + ); + }); + }); + + itWithClient(TestRedisServers.OPEN, 'client.unlink', async client => { + assert.equal( + await client.unlink('key'), + 0 + ); + }); +}); diff --git a/lib/commands/UNLINK.ts b/lib/commands/UNLINK.ts new file mode 100644 index 0000000000..f6313ed9b1 --- /dev/null +++ b/lib/commands/UNLINK.ts @@ -0,0 +1,17 @@ +import { transformReplyNumber } from './generic-transformers'; + +export const FIRST_KEY_INDEX = 1; + +export function transformArguments(key: string | Array): Array { + const args = ['UNLINK']; + + if (typeof key === 'string') { + args.push(key); + } else { + args.push(...key); + } + + return args; +} + +export const transformReply = transformReplyNumber; diff --git a/lib/commands/WAIT.spec.ts b/lib/commands/WAIT.spec.ts new file mode 100644 index 0000000000..c3f53b7db7 --- /dev/null +++ b/lib/commands/WAIT.spec.ts @@ -0,0 +1,19 @@ +import { strict as assert } from 'assert'; +import { TestRedisServers, itWithClient } from '../test-utils'; +import { transformArguments } from './WAIT'; + +describe('WAIT', () => { + it('transformArguments', () => { + assert.deepEqual( + transformArguments(0, 1), + ['WAIT', '0', '1'] + ); + }); + + itWithClient(TestRedisServers.OPEN, 'client.wait', async client => { + assert.equal( + await client.wait(0, 1), + 0 + ); + }); +}); diff --git a/lib/commands/WAIT.ts b/lib/commands/WAIT.ts new file mode 100644 index 0000000000..214fb35668 --- /dev/null +++ b/lib/commands/WAIT.ts @@ -0,0 +1,9 @@ +import { transformReplyNumber } from './generic-transformers'; + +export const FIRST_KEY_INDEX = 1; + +export function transformArguments(numberOfReplicas: number, timeout: number): Array { + return ['WAIT', numberOfReplicas.toString(), timeout.toString()]; +} + +export const transformReply = transformReplyNumber; diff --git a/lib/commands/client.ts b/lib/commands/client.ts index 0c52f11e3a..2755b95beb 100644 --- a/lib/commands/client.ts +++ b/lib/commands/client.ts @@ -1,5 +1,8 @@ import COMMON_COMMANDS from './index'; +import * as MOVE from './MOVE'; export default { - ...COMMON_COMMANDS + ...COMMON_COMMANDS, + MOVE, + move: MOVE }; diff --git a/lib/commands/index.ts b/lib/commands/index.ts index 54c18eb885..196e4a2027 100644 --- a/lib/commands/index.ts +++ b/lib/commands/index.ts @@ -1,5 +1,7 @@ import * as APPEND from './APPEND'; import * as AUTH from './AUTH'; +import * as BITCOUNT from './BITCOUNT'; +import * as BITFIELD from './BITFIELD'; import * as BLPOP from './BLPOP'; import * as CLIENT_INFO from './CLIENT_INFO'; import * as CLUSTER_NODES from './CLUSTER_NODES'; @@ -32,36 +34,53 @@ import * as INCRBY from './INCRBY'; import * as INCRBYFLOAT from './INCRBYFLOAT'; import * as KEYS from './KEYS'; import * as LPUSH from './LPUSH'; +import * as PERSIST from './PERSIST'; +import * as PEXPIRE from './PEXPIRE'; +import * as PEXPIREAT from './PEXPIREAT'; import * as PFADD from './PFADD'; import * as PFCOUNT from './PFCOUNT'; import * as PFMERGE from './PFMERGE'; import * as PING from './PING'; +import * as PTTL from './PTTL'; import * as PUBLISH from './PUBLISH'; +import * as RANDOMKEY from './RANDOMKEY'; import * as READONLY from './READONLY'; +import * as RENAME from './RENAME'; +import * as RENAMENX from './RENAMENX'; import * as SADD from './SADD'; import * as SCAN from './SCAN'; import * as SCARD from './SCARD'; import * as SDIFF from './SDIFF'; import * as SDIFFSTORE from './SDIFFSTORE'; +import * as SET from './SET'; import * as SINTER from './SINTER'; import * as SINTERSTORE from './SINTERSTORE'; import * as SISMEMBER from './SISMEMBER'; import * as SMEMBERS from './SMEMBERS'; import * as SMISMEMBER from './SMISMEMBER'; import * as SMOVE from './SMOVE'; +import * as SORT from './SORT'; import * as SPOP from './SPOP'; import * as SRANDMEMBER from './SRANDMEMBER'; import * as SREM from './SREM'; import * as SSCAN from './SSCAN'; import * as SUNION from './SUNION'; import * as SUNIONSTORE from './SUNIONSTORE'; -import * as SET from './SET'; +import * as TOUCH from './TOUCH'; +import * as TTL from './TTL'; +import * as TYPE from './TYPE'; +import * as UNLINK from './UNLINK'; +import * as WAIT from './WAIT'; export default { APPEND, append: APPEND, AUTH, auth: AUTH, + BITCOUNT, + bitCount: BITCOUNT, + BITFIELD, + bitField: BITFIELD, BLPOP, blPop: BLPOP, CLIENT_INFO, @@ -126,6 +145,12 @@ export default { keys: KEYS, LPUSH, lPush: LPUSH, + PERSIST, + persist: PERSIST, + PEXPIRE, + pExpire: PEXPIRE, + PEXPIREAT, + pExpireAt: PEXPIREAT, PFADD, pfAdd: PFADD, PFCOUNT, @@ -134,10 +159,18 @@ export default { pfMerge: PFMERGE, PING, ping: PING, + PTTL, + pTTL: PTTL, PUBLISH, publish: PUBLISH, + RANDOMKEY, + randomKey: RANDOMKEY, READONLY, readOnly: READONLY, + RENAME, + rename: RENAME, + RENAMENX, + renameNX: RENAMENX, SADD, sAdd: SADD, SCAN, @@ -152,6 +185,8 @@ export default { sInter: SINTER, SINTERSTORE, sInterStore: SINTERSTORE, + SET, + set: SET, SISMEMBER, sIsMember: SISMEMBER, SMEMBERS, @@ -160,6 +195,8 @@ export default { smIsMember: SMISMEMBER, SMOVE, sMove: SMOVE, + SORT, + sort: SORT, SPOP, sPop: SPOP, SRANDMEMBER, @@ -172,8 +209,16 @@ export default { sUnion: SUNION, SUNIONSTORE, sUnionStore: SUNIONSTORE, - SET, - set: SET + TOUCH, + touch: TOUCH, + TTL, + ttl: TTL, + TYPE, + type: TYPE, + UNLINK, + unlink: UNLINK, + WAIT, + wait: WAIT }; export type RedisReply = string | number | Array | null | undefined; diff --git a/lib/test-utils.ts b/lib/test-utils.ts index e9b0f9c237..bc945e2be6 100644 --- a/lib/test-utils.ts +++ b/lib/test-utils.ts @@ -41,9 +41,11 @@ export function itWithClient(type: TestRedisServers, title: string, fn: (client: const client = RedisClient.create({ socket: TEST_REDIS_SERVERS[type] }); + await client.connect(); try { + await client.flushAll(); await fn(client); } finally { await client.flushAll();