You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-17 19:41:06 +03:00
add some missing commands
This commit is contained in:
23
lib/commands/BGSAVE.spec.ts
Normal file
23
lib/commands/BGSAVE.spec.ts
Normal file
@@ -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']
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
17
lib/commands/BGSAVE.ts
Normal file
17
lib/commands/BGSAVE.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { transformReplyString } from './generic-transformers';
|
||||
|
||||
interface BgSaveOptions {
|
||||
SCHEDULE?: true;
|
||||
}
|
||||
|
||||
export function transformArguments(options?: BgSaveOptions): Array<string> {
|
||||
const args = ['BGSAVE'];
|
||||
|
||||
if (options?.SCHEDULE) {
|
||||
args.push('SCHEDULE');
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export const transformReply = transformReplyString;
|
35
lib/commands/BITOP.spec.ts
Normal file
35
lib/commands/BITOP.spec.ts
Normal file
@@ -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
|
||||
);
|
||||
});
|
||||
});
|
19
lib/commands/BITOP.ts
Normal file
19
lib/commands/BITOP.ts
Normal file
@@ -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<string>): Array<string> {
|
||||
const args = ['BITOP', operation, destKey];
|
||||
|
||||
if (typeof key === 'string') {
|
||||
args.push(key);
|
||||
} else {
|
||||
args.push(...key);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export const transformReply = transformReplyNumber;
|
42
lib/commands/BITPOS.spec.ts
Normal file
42
lib/commands/BITPOS.spec.ts
Normal file
@@ -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
|
||||
);
|
||||
});
|
||||
});
|
21
lib/commands/BITPOS.ts
Normal file
21
lib/commands/BITPOS.ts
Normal file
@@ -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<string> {
|
||||
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;
|
11
lib/commands/CONFIG_GET.spec.ts
Normal file
11
lib/commands/CONFIG_GET.spec.ts
Normal file
@@ -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', '*']
|
||||
);
|
||||
});
|
||||
});
|
7
lib/commands/CONFIG_GET.ts
Normal file
7
lib/commands/CONFIG_GET.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { transformReplyTuples } from './generic-transformers';
|
||||
|
||||
export function transformArguments(parameter: string): Array<string> {
|
||||
return ['CONFIG', 'GET', parameter];
|
||||
}
|
||||
|
||||
export const transformReply = transformReplyTuples;
|
11
lib/commands/CONFIG_RESETSTAT.spec.ts
Normal file
11
lib/commands/CONFIG_RESETSTAT.spec.ts
Normal file
@@ -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']
|
||||
);
|
||||
});
|
||||
});
|
7
lib/commands/CONFIG_RESETSTAT.ts
Normal file
7
lib/commands/CONFIG_RESETSTAT.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { transformReplyString } from './generic-transformers';
|
||||
|
||||
export function transformArguments(): Array<string> {
|
||||
return ['CONFIG', 'RESETSTAT'];
|
||||
}
|
||||
|
||||
export const transformReply = transformReplyString;
|
11
lib/commands/CONFIG_REWRITE.spec.ts
Normal file
11
lib/commands/CONFIG_REWRITE.spec.ts
Normal file
@@ -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']
|
||||
);
|
||||
});
|
||||
});
|
7
lib/commands/CONFIG_REWRITE.ts
Normal file
7
lib/commands/CONFIG_REWRITE.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { transformReplyString } from './generic-transformers';
|
||||
|
||||
export function transformArguments(): Array<string> {
|
||||
return ['CONFIG', 'REWRITE'];
|
||||
}
|
||||
|
||||
export const transformReply = transformReplyString;
|
11
lib/commands/CONFIG_SET.spec.ts
Normal file
11
lib/commands/CONFIG_SET.spec.ts
Normal file
@@ -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']
|
||||
);
|
||||
});
|
||||
});
|
7
lib/commands/CONFIG_SET.ts
Normal file
7
lib/commands/CONFIG_SET.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { transformReplyString } from './generic-transformers';
|
||||
|
||||
export function transformArguments(parameter: string, value: string): Array<string> {
|
||||
return ['CONFIG', 'SET', parameter, value];
|
||||
}
|
||||
|
||||
export const transformReply = transformReplyString;
|
11
lib/commands/DISCARD.spec.ts
Normal file
11
lib/commands/DISCARD.spec.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { transformArguments } from './DISCARD';
|
||||
|
||||
describe('DISCARD', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(),
|
||||
['DISCARD']
|
||||
);
|
||||
});
|
||||
});
|
7
lib/commands/DISCARD.ts
Normal file
7
lib/commands/DISCARD.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { transformReplyString } from './generic-transformers';
|
||||
|
||||
export function transformArguments(): Array<string> {
|
||||
return ['DISCARD'];
|
||||
}
|
||||
|
||||
export const transformReply = transformReplyString;
|
26
lib/commands/ECHO.spec.ts
Normal file
26
lib/commands/ECHO.spec.ts
Normal file
@@ -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'
|
||||
);
|
||||
});
|
||||
});
|
9
lib/commands/ECHO.ts
Normal file
9
lib/commands/ECHO.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { transformReplyString } from './generic-transformers';
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(message: string): Array<string> {
|
||||
return ['ECHO', message];
|
||||
}
|
||||
|
||||
export const transformReply = transformReplyString;
|
72
lib/commands/FAILOVER.spec.ts
Normal file
72
lib/commands/FAILOVER.spec.ts
Normal file
@@ -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']
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
35
lib/commands/FAILOVER.ts
Normal file
35
lib/commands/FAILOVER.ts
Normal file
@@ -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<string> {
|
||||
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;
|
26
lib/commands/GETBIT.spec.ts
Normal file
26
lib/commands/GETBIT.spec.ts
Normal file
@@ -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
|
||||
);
|
||||
});
|
||||
});
|
11
lib/commands/GETBIT.ts
Normal file
11
lib/commands/GETBIT.ts
Normal file
@@ -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<string> {
|
||||
return ['GETBIT', key, offset.toString()];
|
||||
}
|
||||
|
||||
export const transformReply = transformReplyBit;
|
27
lib/commands/GETDEL.spec.ts
Normal file
27
lib/commands/GETDEL.spec.ts
Normal file
@@ -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
|
||||
);
|
||||
});
|
||||
});
|
9
lib/commands/GETDEL.ts
Normal file
9
lib/commands/GETDEL.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { transformReplyStringNull } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(key: string): Array<string> {
|
||||
return ['GETDEL', key];
|
||||
}
|
||||
|
||||
export const transformReply = transformReplyStringNull;
|
27
lib/commands/GETRANGE.spec.ts
Normal file
27
lib/commands/GETRANGE.spec.ts
Normal file
@@ -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),
|
||||
''
|
||||
);
|
||||
});
|
||||
});
|
11
lib/commands/GETRANGE.ts
Normal file
11
lib/commands/GETRANGE.ts
Normal 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, start: number, end: number): Array<string> {
|
||||
return ['GETRANGE', key, start.toString(), end.toString()];
|
||||
}
|
||||
|
||||
export const transformReply = transformReplyString;
|
20
lib/commands/INFO.spec.ts
Normal file
20
lib/commands/INFO.spec.ts
Normal file
@@ -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']
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
15
lib/commands/INFO.ts
Normal file
15
lib/commands/INFO.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { transformReplyString } from './generic-transformers';
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(section?: string): Array<string> {
|
||||
const args = ['INFO'];
|
||||
|
||||
if (section) {
|
||||
args.push(section);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export const transformReply = transformReplyString;
|
11
lib/commands/READWRITE.spec.ts
Normal file
11
lib/commands/READWRITE.spec.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { transformArguments } from './READWRITE';
|
||||
|
||||
describe('READWRITE', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(),
|
||||
['READWRITE']
|
||||
);
|
||||
});
|
||||
});
|
7
lib/commands/READWRITE.ts
Normal file
7
lib/commands/READWRITE.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { transformReplyString } from './generic-transformers';
|
||||
|
||||
export function transformArguments(): Array<string> {
|
||||
return ['READWRITE'];
|
||||
}
|
||||
|
||||
export const transformReply = transformReplyString;
|
26
lib/commands/SETBIT.spec.ts
Normal file
26
lib/commands/SETBIT.spec.ts
Normal file
@@ -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
|
||||
);
|
||||
});
|
||||
});
|
9
lib/commands/SETBIT.ts
Normal file
9
lib/commands/SETBIT.ts
Normal file
@@ -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;
|
27
lib/commands/SHUTDOWN.spec.ts
Normal file
27
lib/commands/SHUTDOWN.spec.ts
Normal file
@@ -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']
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
13
lib/commands/SHUTDOWN.ts
Normal file
13
lib/commands/SHUTDOWN.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { transformReplyVoid } from './generic-transformers';
|
||||
|
||||
export function transformArguments(mode?: 'NOSAVE' | 'SAVE'): Array<string> {
|
||||
const args = ['SHUTDOWN'];
|
||||
|
||||
if (mode) {
|
||||
args.push(mode);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export const transformReply = transformReplyVoid;
|
19
lib/commands/SWAPDB.spec.ts
Normal file
19
lib/commands/SWAPDB.spec.ts
Normal file
@@ -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'
|
||||
);
|
||||
});
|
||||
});
|
7
lib/commands/SWAPDB.ts
Normal file
7
lib/commands/SWAPDB.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { transformReplyString } from './generic-transformers';
|
||||
|
||||
export function transformArguments(index1: number, index2: number): Array<string> {
|
||||
return ['SWAPDB', index1.toString(), index2.toString()];
|
||||
}
|
||||
|
||||
export const transformReply = transformReplyString;
|
@@ -3,7 +3,7 @@ import { TestRedisServers, itWithClient } from '../test-utils';
|
||||
import { transformArguments } from './TIME';
|
||||
|
||||
describe('TIME', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(),
|
||||
['TIME']
|
||||
|
@@ -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']
|
||||
|
@@ -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']
|
||||
|
@@ -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']
|
||||
|
@@ -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']
|
||||
|
@@ -38,6 +38,14 @@ export function transformReplyBooleanArray(reply: Array<number>): Array<boolean>
|
||||
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;
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user