1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

more commands

This commit is contained in:
dovi
2023-07-06 15:51:12 -04:00
parent d986ff52b6
commit e64946566a
20 changed files with 295 additions and 261 deletions

View File

@@ -1,28 +1,28 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './DEBUG_MEMORY';
import DEBUG_MEMORY from './DEBUG_MEMORY';
describe('DEBUG MEMORY', () => {
describe('transformArguments', () => {
it('without path', () => {
assert.deepEqual(
transformArguments('key'),
['JSON.DEBUG', 'MEMORY', 'key']
);
});
it('with path', () => {
assert.deepEqual(
transformArguments('key', '$'),
['JSON.DEBUG', 'MEMORY', 'key', '$']
);
});
describe('transformArguments', () => {
it('without path', () => {
assert.deepEqual(
DEBUG_MEMORY.transformArguments('key'),
['JSON.DEBUG', 'MEMORY', 'key']
);
});
testUtils.testWithClient('client.json.arrTrim', async client => {
assert.deepEqual(
await client.json.debugMemory('key', '$'),
[]
);
}, GLOBAL.SERVERS.OPEN);
it('with path', () => {
assert.deepEqual(
DEBUG_MEMORY.transformArguments('key', '$'),
['JSON.DEBUG', 'MEMORY', 'key', '$']
);
});
});
testUtils.testWithClient('client.json.arrTrim', async client => {
assert.deepEqual(
await client.json.debugMemory('key', '$'),
[]
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,13 +1,16 @@
export const FIRST_KEY_INDEX = 2;
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
export function transformArguments(key: string, path?: string): Array<string> {
export default {
FIRST_KEY_INDEX: 2,
IS_READ_ONLY: false,
transformArguments(key: RedisArgument, path?: RedisArgument) {
const args = ['JSON.DEBUG', 'MEMORY', key];
if (path) {
args.push(path);
args.push(path);
}
return args;
}
export declare function transformReply(): number;
},
transformReply: undefined as unknown as () => NumberReply
} as const satisfies Command;

View File

@@ -1,28 +1,29 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './DEL';
import DEL from './DEL';
describe('DEL', () => {
describe('transformArguments', () => {
it('key', () => {
assert.deepEqual(
transformArguments('key'),
['JSON.DEL', 'key']
);
});
it('key, path', () => {
assert.deepEqual(
transformArguments('key', '$.path'),
['JSON.DEL', 'key', '$.path']
);
});
describe('transformArguments', () => {
it('key', () => {
assert.deepEqual(
DEL.transformArguments('key'),
['JSON.DEL', 'key']
);
});
testUtils.testWithClient('client.json.del', async client => {
assert.deepEqual(
await client.json.del('key'),
0
);
}, GLOBAL.SERVERS.OPEN);
it('key, path', () => {
assert.deepEqual(
DEL.transformArguments('key', '$.path'),
['JSON.DEL', 'key', '$.path']
);
});
});
testUtils.testWithClient('client.json.del', async client => {
assert.deepEqual(
await client.json.del('key'),
0
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,13 +1,16 @@
export const FIRST_KEY_INDEX = 1;
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
export function transformArguments(key: string, path?: string): Array<string> {
export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: false,
transformArguments(key: RedisArgument, path?: RedisArgument) {
const args = ['JSON.DEL', key];
if (path) {
args.push(path);
args.push(path);
}
return args;
}
export declare function transformReply(): number;
},
transformReply: undefined as unknown as () => NumberReply
} as const satisfies Command;

View File

@@ -1,28 +1,28 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './FORGET';
import FORGET from './FORGET';
describe('FORGET', () => {
describe('transformArguments', () => {
it('key', () => {
assert.deepEqual(
transformArguments('key'),
['JSON.FORGET', 'key']
);
});
it('key, path', () => {
assert.deepEqual(
transformArguments('key', '$.path'),
['JSON.FORGET', 'key', '$.path']
);
});
describe('transformArguments', () => {
it('key', () => {
assert.deepEqual(
FORGET.transformArguments('key'),
['JSON.FORGET', 'key']
);
});
testUtils.testWithClient('client.json.forget', async client => {
assert.deepEqual(
await client.json.forget('key'),
0
);
}, GLOBAL.SERVERS.OPEN);
it('key, path', () => {
assert.deepEqual(
FORGET.transformArguments('key', '$.path'),
['JSON.FORGET', 'key', '$.path']
);
});
});
testUtils.testWithClient('client.json.forget', async client => {
assert.deepEqual(
await client.json.forget('key'),
0
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,13 +1,16 @@
export const FIRST_KEY_INDEX = 1;
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
export function transformArguments(key: string, path?: string): Array<string> {
export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: false,
transformArguments(key: RedisArgument, path?: RedisArgument) {
const args = ['JSON.FORGET', key];
if (path) {
args.push(path);
args.push(path);
}
return args;
}
export declare function transformReply(): number;
},
transformReply: undefined as unknown as () => NumberReply
} as const satisfies Command;

View File

@@ -1,28 +1,28 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './DICTADD';
import DICTADD from './DICTADD';
describe('DICTADD', () => {
describe('transformArguments', () => {
it('string', () => {
assert.deepEqual(
transformArguments('dictionary', 'term'),
['FT.DICTADD', 'dictionary', 'term']
);
});
it('Array', () => {
assert.deepEqual(
transformArguments('dictionary', ['1', '2']),
['FT.DICTADD', 'dictionary', '1', '2']
);
});
describe('transformArguments', () => {
it('string', () => {
assert.deepEqual(
DICTADD.transformArguments('dictionary', 'term'),
['FT.DICTADD', 'dictionary', 'term']
);
});
testUtils.testWithClient('client.ft.dictAdd', async client => {
assert.equal(
await client.ft.dictAdd('dictionary', 'term'),
1
);
}, GLOBAL.SERVERS.OPEN);
it('Array', () => {
assert.deepEqual(
DICTADD.transformArguments('dictionary', ['1', '2']),
['FT.DICTADD', 'dictionary', '1', '2']
);
});
});
testUtils.testWithClient('client.ft.dictAdd', async client => {
assert.equal(
await client.ft.dictAdd('dictionary', 'term'),
1
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,8 +1,11 @@
import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
import { pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers';
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
import { pushVariadicArguments, RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
export function transformArguments(dictionary: string, term: string | Array<string>): RedisCommandArguments {
export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: false,
transformArguments(dictionary: RedisArgument, term: RedisVariadicArgument) {
return pushVariadicArguments(['FT.DICTADD', dictionary], term);
}
export declare function transformReply(): number;
},
transformReply: undefined as unknown as () => NumberReply
} as const satisfies Command;

View File

@@ -1,28 +1,28 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './DICTDEL';
import DICTDEL from './DICTDEL';
describe('DICTDEL', () => {
describe('transformArguments', () => {
it('string', () => {
assert.deepEqual(
transformArguments('dictionary', 'term'),
['FT.DICTDEL', 'dictionary', 'term']
);
});
it('Array', () => {
assert.deepEqual(
transformArguments('dictionary', ['1', '2']),
['FT.DICTDEL', 'dictionary', '1', '2']
);
});
describe('transformArguments', () => {
it('string', () => {
assert.deepEqual(
DICTDEL.transformArguments('dictionary', 'term'),
['FT.DICTDEL', 'dictionary', 'term']
);
});
testUtils.testWithClient('client.ft.dictDel', async client => {
assert.equal(
await client.ft.dictDel('dictionary', 'term'),
0
);
}, GLOBAL.SERVERS.OPEN);
it('Array', () => {
assert.deepEqual(
DICTDEL.transformArguments('dictionary', ['1', '2']),
['FT.DICTDEL', 'dictionary', '1', '2']
);
});
});
testUtils.testWithClient('client.ft.dictDel', async client => {
assert.equal(
await client.ft.dictDel('dictionary', 'term'),
0
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,8 +1,11 @@
import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
import { pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers';
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
import { pushVariadicArguments, RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
export function transformArguments(dictionary: string, term: string | Array<string>): RedisCommandArguments {
export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: false,
transformArguments(dictionary: RedisArgument, term: RedisVariadicArgument) {
return pushVariadicArguments(['FT.DICTDEL', dictionary], term);
}
export declare function transformReply(): number;
},
transformReply: undefined as unknown as () => NumberReply
} as const satisfies Command;

View File

@@ -1,33 +1,33 @@
import { strict as assert } from 'assert';
import { transformArguments } from './EXPLAIN';
import EXPLAIN from './EXPLAIN';
describe('EXPLAIN', () => {
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
transformArguments('index', '*'),
['FT.EXPLAIN', 'index', '*']
);
});
it('with PARAMS', () => {
assert.deepEqual(
transformArguments('index', '*', {
PARAMS: {
param: 'value'
}
}),
['FT.EXPLAIN', 'index', '*', 'PARAMS', '2', 'param', 'value']
);
});
it('with DIALECT', () => {
assert.deepEqual(
transformArguments('index', '*', {
DIALECT: 1
}),
['FT.EXPLAIN', 'index', '*', 'DIALECT', '1']
);
});
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
EXPLAIN.transformArguments('index', '*'),
['FT.EXPLAIN', 'index', '*']
);
});
it('with PARAMS', () => {
assert.deepEqual(
EXPLAIN.transformArguments('index', '*', {
PARAMS: {
param: 'value'
}
}),
['FT.EXPLAIN', 'index', '*', 'PARAMS', '2', 'param', 'value']
);
});
it('with DIALECT', () => {
assert.deepEqual(
EXPLAIN.transformArguments('index', '*', {
DIALECT: 1
}),
['FT.EXPLAIN', 'index', '*', 'DIALECT', '1']
);
});
});
});

View File

@@ -1,26 +1,28 @@
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
import { Params, pushParamsArgs } from ".";
export const IS_READ_ONLY = true;
interface ExplainOptions {
PARAMS?: Params;
DIALECT?: number;
export interface FtExplainOptions {
PARAMS?: Params;
DIALECT?: number;
}
export function transformArguments(
index: string,
query: string,
options?: ExplainOptions
): Array<string> {
export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: true,
transformArguments(
index: RedisArgument,
query: RedisArgument,
options?: FtExplainOptions
) {
const args = ['FT.EXPLAIN', index, query];
pushParamsArgs(args, options?.PARAMS);
if (options?.DIALECT) {
args.push('DIALECT', options.DIALECT.toString());
args.push('DIALECT', options.DIALECT.toString());
}
return args;
}
export declare function transformReply(): string;
},
transformReply: undefined as unknown as () => SimpleStringReply
} as const satisfies Command;

View File

@@ -1,11 +1,11 @@
import { strict as assert } from 'assert';
import { transformArguments } from './EXPLAINCLI';
import EXPLAINCLI from './EXPLAINCLI';
describe('EXPLAINCLI', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('index', '*'),
['FT.EXPLAINCLI', 'index', '*']
);
});
it('transformArguments', () => {
assert.deepEqual(
EXPLAINCLI.transformArguments('index', '*'),
['FT.EXPLAINCLI', 'index', '*']
);
});
});

View File

@@ -1,7 +1,10 @@
export const IS_READ_ONLY = true;
import { RedisArgument, ArrayReply, BlobStringReply, Command } from '@redis/client/dist/lib/RESP/types';
export function transformArguments(index: string, query: string): Array<string> {
export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: true,
transformArguments(index: RedisArgument, query: RedisArgument) {
return ['FT.EXPLAINCLI', index, query];
}
export declare function transformReply(): Array<string>;
},
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply>
} as const satisfies Command;

View File

@@ -1,35 +1,35 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SUGADD';
import SUGADD from './SUGADD';
describe('SUGADD', () => {
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(
transformArguments('key', 'string', 1),
['FT.SUGADD', 'key', 'string', '1']
);
});
it('with INCR', () => {
assert.deepEqual(
transformArguments('key', 'string', 1, { INCR: true }),
['FT.SUGADD', 'key', 'string', '1', 'INCR']
);
});
it('with PAYLOAD', () => {
assert.deepEqual(
transformArguments('key', 'string', 1, { PAYLOAD: 'payload' }),
['FT.SUGADD', 'key', 'string', '1', 'PAYLOAD', 'payload']
);
});
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(
SUGADD.transformArguments('key', 'string', 1),
['FT.SUGADD', 'key', 'string', '1']
);
});
testUtils.testWithClient('client.ft.sugAdd', async client => {
assert.equal(
await client.ft.sugAdd('key', 'string', 1),
1
);
}, GLOBAL.SERVERS.OPEN);
it('with INCR', () => {
assert.deepEqual(
SUGADD.transformArguments('key', 'string', 1, { INCR: true }),
['FT.SUGADD', 'key', 'string', '1', 'INCR']
);
});
it('with PAYLOAD', () => {
assert.deepEqual(
SUGADD.transformArguments('key', 'string', 1, { PAYLOAD: 'payload' }),
['FT.SUGADD', 'key', 'string', '1', 'PAYLOAD', 'payload']
);
});
});
testUtils.testWithClient('client.ft.sugAdd', async client => {
assert.equal(
await client.ft.sugAdd('key', 'string', 1),
1
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,20 +1,25 @@
interface SugAddOptions {
INCR?: true;
PAYLOAD?: string;
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
export interface FtSugAddOptions {
INCR?: boolean;
PAYLOAD?: RedisArgument;
}
export function transformArguments(key: string, string: string, score: number, options?: SugAddOptions): Array<string> {
export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: false,
transformArguments(key: RedisArgument, string: RedisArgument, score: number, options?: FtSugAddOptions) {
const args = ['FT.SUGADD', key, string, score.toString()];
if (options?.INCR) {
args.push('INCR');
args.push('INCR');
}
if (options?.PAYLOAD) {
args.push('PAYLOAD', options.PAYLOAD);
args.push('PAYLOAD', options.PAYLOAD);
}
return args;
}
export declare function transformReply(): number;
},
transformReply: undefined as unknown as () => NumberReply
} as const satisfies Command;

View File

@@ -1,19 +1,19 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SUGDEL';
import SUGDEL from './SUGDEL';
describe('SUGDEL', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key', 'string'),
['FT.SUGDEL', 'key', 'string']
);
});
it('transformArguments', () => {
assert.deepEqual(
SUGDEL.transformArguments('key', 'string'),
['FT.SUGDEL', 'key', 'string']
);
});
testUtils.testWithClient('client.ft.sugDel', async client => {
assert.equal(
await client.ft.sugDel('key', 'string'),
false
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('client.ft.sugDel', async client => {
assert.equal(
await client.ft.sugDel('key', 'string'),
false
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,5 +1,10 @@
export function transformArguments(key: string, string: string): Array<string> {
return ['FT.SUGDEL', key, string];
}
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
export { transformBooleanReply as transformReply } from '@redis/client/dist/lib/commands/generic-transformers';
export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: false,
transformArguments(key: RedisArgument, string: RedisArgument) {
return ['FT.SUGDEL', key, string];
},
transformReply: undefined as unknown as () => NumberReply<0 | 1>
} as const satisfies Command;

View File

@@ -1,19 +1,19 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SUGLEN';
import SUGLEN from './SUGLEN';
describe('SUGLEN', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key'),
['FT.SUGLEN', 'key']
);
});
it('transformArguments', () => {
assert.deepEqual(
SUGLEN.transformArguments('key'),
['FT.SUGLEN', 'key']
);
});
testUtils.testWithClient('client.ft.sugLen', async client => {
assert.equal(
await client.ft.sugLen('key'),
0
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('client.ft.sugLen', async client => {
assert.equal(
await client.ft.sugLen('key'),
0
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,7 +1,10 @@
export const IS_READ_ONLY = true;
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
export function transformArguments(key: string): Array<string> {
export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: true,
transformArguments(key: RedisArgument) {
return ['FT.SUGLEN', key];
}
export declare function transformReply(): number;
},
transformReply: undefined as unknown as () => NumberReply
} as const satisfies Command;