1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-14 21:21:31 +03:00

add support for most of the "keys commands"

This commit is contained in:
leibale
2021-06-11 13:25:01 -04:00
parent eaefe9d80f
commit 199a94fc89
38 changed files with 897 additions and 6 deletions

View File

@@ -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
);
});
});

25
lib/commands/BITCOUNT.ts Normal file
View File

@@ -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<string> {
const args = ['BITCOUNT', key];
if (range) {
args.push(
range.start.toString(),
range.end.toString()
);
}
return args;
}
export const transformReply = transformReplyNumber;

View File

@@ -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'),
[]
);
});
});

66
lib/commands/BITFIELD.ts Normal file
View File

@@ -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;

View File

@@ -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
);
});
});

View File

@@ -1,7 +1,19 @@
import { transformReplyBoolean } from './generic-transformers'; import { transformReplyBoolean } from './generic-transformers';
export function transformArguments(...keys: Array<string>): Array<string> { export const FIRST_KEY_INDEX = 1;
return ['EXISTS', ...keys];
export const IS_READ_ONLY = true;
export function transformArguments(keys: string | Array<string>): Array<string> {
const args = ['EXISTS'];
if (typeof keys === 'string') {
args.push(keys);
} else {
args.push(...keys);
}
return args;
} }
export const transformReply = transformReplyBoolean; export const transformReply = transformReplyBoolean;

View File

@@ -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
);
});
});

19
lib/commands/MOVE.spec.ts Normal file
View File

@@ -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
);
});
});

7
lib/commands/MOVE.ts Normal file
View File

@@ -0,0 +1,7 @@
import { transformReplyBoolean } from './generic-transformers';
export function transformArguments(key: string, db: number): Array<string> {
return ['MOVE', key, db.toString()];
}
export const transformReply = transformReplyBoolean;

View File

@@ -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
);
});
});

9
lib/commands/PERSIST.ts Normal file
View File

@@ -0,0 +1,9 @@
import { transformReplyBoolean } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string): Array<string> {
return ['PERSIST', key];
}
export const transformReply = transformReplyBoolean;

View File

@@ -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
);
});
});

9
lib/commands/PEXPIRE.ts Normal file
View File

@@ -0,0 +1,9 @@
import { transformReplyBoolean } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string, milliseconds: number): Array<string> {
return ['PEXPIRE', key, milliseconds.toString()];
}
export const transformReply = transformReplyBoolean;

View File

@@ -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
);
});
});

View File

@@ -0,0 +1,9 @@
import { transformReplyBoolean } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string, millisecondsTimestamp: number): Array<string> {
return ['PEXPIREAT', key, millisecondsTimestamp.toString()];
}
export const transformReply = transformReplyBoolean;

19
lib/commands/PTTL.spec.ts Normal file
View File

@@ -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
);
});
});

11
lib/commands/PTTL.ts Normal file
View File

@@ -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<string> {
return ['PTTL', key];
}
export const transformReply = transformReplyNumber;

View File

@@ -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
);
});
});

View File

@@ -0,0 +1,9 @@
export const IS_READ_ONLY = true;
export function transformArguments(): Array<string> {
return ['RANDOMKEY'];
}
export function transformReply(reply: string | null): string | null {
return reply;
}

View File

@@ -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'
);
});
});

9
lib/commands/RENAME.ts Normal file
View File

@@ -0,0 +1,9 @@
import { transformReplyString } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string, newKey: string): Array<string> {
return ['RENAME', key, newKey];
}
export const transformReply = transformReplyString;

View File

@@ -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
);
});
});

9
lib/commands/RENAMENX.ts Normal file
View File

@@ -0,0 +1,9 @@
import { transformReplyBoolean } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string, newKey: string): Array<string> {
return ['RENAMENX', key, newKey];
}
export const transformReply = transformReplyBoolean;

106
lib/commands/SORT.spec.ts Normal file
View File

@@ -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'),
[]
);
});
});

57
lib/commands/SORT.ts Normal file
View File

@@ -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<string>;
DIRECTION?: 'ASC' | 'DESC';
ALPHA?: true;
STORE?: string;
}
export function transformArguments(key: string, options?: SortOptions): Array<string> {
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<string> | number): Array<string> | number {
return reply;
}

View File

@@ -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
);
});
});

17
lib/commands/TOUCH.ts Normal file
View File

@@ -0,0 +1,17 @@
import { transformReplyNumber } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string | Array<string>): Array<string> {
const args = ['TOUCH'];
if (typeof key === 'string') {
args.push(key);
} else {
args.push(...key);
}
return args;
}
export const transformReply = transformReplyNumber;

19
lib/commands/TTL.spec.ts Normal file
View File

@@ -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
);
});
});

11
lib/commands/TTL.ts Normal file
View File

@@ -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<string> {
return ['TTL', key];
}
export const transformReply = transformReplyNumber;

19
lib/commands/TYPE.spec.ts Normal file
View File

@@ -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'
);
});
});

11
lib/commands/TYPE.ts Normal file
View File

@@ -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<string> {
return ['TYPE', key];
}
export const transformReply = transformReplyString;

View File

@@ -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
);
});
});

17
lib/commands/UNLINK.ts Normal file
View File

@@ -0,0 +1,17 @@
import { transformReplyNumber } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string | Array<string>): Array<string> {
const args = ['UNLINK'];
if (typeof key === 'string') {
args.push(key);
} else {
args.push(...key);
}
return args;
}
export const transformReply = transformReplyNumber;

19
lib/commands/WAIT.spec.ts Normal file
View File

@@ -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
);
});
});

9
lib/commands/WAIT.ts Normal file
View File

@@ -0,0 +1,9 @@
import { transformReplyNumber } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(numberOfReplicas: number, timeout: number): Array<string> {
return ['WAIT', numberOfReplicas.toString(), timeout.toString()];
}
export const transformReply = transformReplyNumber;

View File

@@ -1,5 +1,8 @@
import COMMON_COMMANDS from './index'; import COMMON_COMMANDS from './index';
import * as MOVE from './MOVE';
export default { export default {
...COMMON_COMMANDS ...COMMON_COMMANDS,
MOVE,
move: MOVE
}; };

View File

@@ -1,5 +1,7 @@
import * as APPEND from './APPEND'; import * as APPEND from './APPEND';
import * as AUTH from './AUTH'; import * as AUTH from './AUTH';
import * as BITCOUNT from './BITCOUNT';
import * as BITFIELD from './BITFIELD';
import * as BLPOP from './BLPOP'; import * as BLPOP from './BLPOP';
import * as CLIENT_INFO from './CLIENT_INFO'; import * as CLIENT_INFO from './CLIENT_INFO';
import * as CLUSTER_NODES from './CLUSTER_NODES'; import * as CLUSTER_NODES from './CLUSTER_NODES';
@@ -32,36 +34,53 @@ import * as INCRBY from './INCRBY';
import * as INCRBYFLOAT from './INCRBYFLOAT'; import * as INCRBYFLOAT from './INCRBYFLOAT';
import * as KEYS from './KEYS'; import * as KEYS from './KEYS';
import * as LPUSH from './LPUSH'; 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 PFADD from './PFADD';
import * as PFCOUNT from './PFCOUNT'; import * as PFCOUNT from './PFCOUNT';
import * as PFMERGE from './PFMERGE'; import * as PFMERGE from './PFMERGE';
import * as PING from './PING'; import * as PING from './PING';
import * as PTTL from './PTTL';
import * as PUBLISH from './PUBLISH'; import * as PUBLISH from './PUBLISH';
import * as RANDOMKEY from './RANDOMKEY';
import * as READONLY from './READONLY'; import * as READONLY from './READONLY';
import * as RENAME from './RENAME';
import * as RENAMENX from './RENAMENX';
import * as SADD from './SADD'; import * as SADD from './SADD';
import * as SCAN from './SCAN'; import * as SCAN from './SCAN';
import * as SCARD from './SCARD'; import * as SCARD from './SCARD';
import * as SDIFF from './SDIFF'; import * as SDIFF from './SDIFF';
import * as SDIFFSTORE from './SDIFFSTORE'; import * as SDIFFSTORE from './SDIFFSTORE';
import * as SET from './SET';
import * as SINTER from './SINTER'; import * as SINTER from './SINTER';
import * as SINTERSTORE from './SINTERSTORE'; import * as SINTERSTORE from './SINTERSTORE';
import * as SISMEMBER from './SISMEMBER'; import * as SISMEMBER from './SISMEMBER';
import * as SMEMBERS from './SMEMBERS'; import * as SMEMBERS from './SMEMBERS';
import * as SMISMEMBER from './SMISMEMBER'; import * as SMISMEMBER from './SMISMEMBER';
import * as SMOVE from './SMOVE'; import * as SMOVE from './SMOVE';
import * as SORT from './SORT';
import * as SPOP from './SPOP'; import * as SPOP from './SPOP';
import * as SRANDMEMBER from './SRANDMEMBER'; import * as SRANDMEMBER from './SRANDMEMBER';
import * as SREM from './SREM'; import * as SREM from './SREM';
import * as SSCAN from './SSCAN'; import * as SSCAN from './SSCAN';
import * as SUNION from './SUNION'; import * as SUNION from './SUNION';
import * as SUNIONSTORE from './SUNIONSTORE'; 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 { export default {
APPEND, APPEND,
append: APPEND, append: APPEND,
AUTH, AUTH,
auth: AUTH, auth: AUTH,
BITCOUNT,
bitCount: BITCOUNT,
BITFIELD,
bitField: BITFIELD,
BLPOP, BLPOP,
blPop: BLPOP, blPop: BLPOP,
CLIENT_INFO, CLIENT_INFO,
@@ -126,6 +145,12 @@ export default {
keys: KEYS, keys: KEYS,
LPUSH, LPUSH,
lPush: LPUSH, lPush: LPUSH,
PERSIST,
persist: PERSIST,
PEXPIRE,
pExpire: PEXPIRE,
PEXPIREAT,
pExpireAt: PEXPIREAT,
PFADD, PFADD,
pfAdd: PFADD, pfAdd: PFADD,
PFCOUNT, PFCOUNT,
@@ -134,10 +159,18 @@ export default {
pfMerge: PFMERGE, pfMerge: PFMERGE,
PING, PING,
ping: PING, ping: PING,
PTTL,
pTTL: PTTL,
PUBLISH, PUBLISH,
publish: PUBLISH, publish: PUBLISH,
RANDOMKEY,
randomKey: RANDOMKEY,
READONLY, READONLY,
readOnly: READONLY, readOnly: READONLY,
RENAME,
rename: RENAME,
RENAMENX,
renameNX: RENAMENX,
SADD, SADD,
sAdd: SADD, sAdd: SADD,
SCAN, SCAN,
@@ -152,6 +185,8 @@ export default {
sInter: SINTER, sInter: SINTER,
SINTERSTORE, SINTERSTORE,
sInterStore: SINTERSTORE, sInterStore: SINTERSTORE,
SET,
set: SET,
SISMEMBER, SISMEMBER,
sIsMember: SISMEMBER, sIsMember: SISMEMBER,
SMEMBERS, SMEMBERS,
@@ -160,6 +195,8 @@ export default {
smIsMember: SMISMEMBER, smIsMember: SMISMEMBER,
SMOVE, SMOVE,
sMove: SMOVE, sMove: SMOVE,
SORT,
sort: SORT,
SPOP, SPOP,
sPop: SPOP, sPop: SPOP,
SRANDMEMBER, SRANDMEMBER,
@@ -172,8 +209,16 @@ export default {
sUnion: SUNION, sUnion: SUNION,
SUNIONSTORE, SUNIONSTORE,
sUnionStore: SUNIONSTORE, sUnionStore: SUNIONSTORE,
SET, TOUCH,
set: SET touch: TOUCH,
TTL,
ttl: TTL,
TYPE,
type: TYPE,
UNLINK,
unlink: UNLINK,
WAIT,
wait: WAIT
}; };
export type RedisReply = string | number | Array<RedisReply> | null | undefined; export type RedisReply = string | number | Array<RedisReply> | null | undefined;

View File

@@ -41,9 +41,11 @@ export function itWithClient(type: TestRedisServers, title: string, fn: (client:
const client = RedisClient.create({ const client = RedisClient.create({
socket: TEST_REDIS_SERVERS[type] socket: TEST_REDIS_SERVERS[type]
}); });
await client.connect(); await client.connect();
try { try {
await client.flushAll();
await fn(client); await fn(client);
} finally { } finally {
await client.flushAll(); await client.flushAll();