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-10 12:29:36 -04:00
parent 9915d67510
commit d2b0b4e5b0
12 changed files with 196 additions and 156 deletions

View File

@@ -1,30 +1,30 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ARRAPPEND'; import ARRAPPEND from './ARRAPPEND';
describe('ARRAPPEND', () => { describe('ARRAPPEND', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('single JSON', () => { it('single JSON', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', '$', 1), ARRAPPEND.transformArguments('key', '$', 1),
['JSON.ARRAPPEND', 'key', '$', '1'] ['JSON.ARRAPPEND', 'key', '$', '1']
); );
});
it('multiple JSONs', () => {
assert.deepEqual(
transformArguments('key', '$', 1, 2),
['JSON.ARRAPPEND', 'key', '$', '1', '2']
);
});
}); });
testUtils.testWithClient('client.json.arrAppend', async client => { it('multiple JSONs', () => {
await client.json.set('key', '$', []); assert.deepEqual(
ARRAPPEND.transformArguments('key', '$', 1, 2),
['JSON.ARRAPPEND', 'key', '$', '1', '2']
);
});
});
assert.deepEqual( testUtils.testWithClient('client.json.arrAppend', async client => {
await client.json.arrAppend('key', '$', 1), await client.json.set('key', '$', []);
[1]
); assert.deepEqual(
}, GLOBAL.SERVERS.OPEN); await client.json.arrAppend('key', '$', 1),
[1]
);
}, GLOBAL.SERVERS.OPEN);
}); });

View File

@@ -1,15 +1,17 @@
import { RedisJSON, transformRedisJsonArgument } from '.'; import { RedisJSON, transformRedisJsonArgument } from '.';
import { RedisArgument, ArrayReply, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
export const FIRST_KEY_INDEX = 1; export default {
FIRST_KEY_INDEX: 1,
export function transformArguments(key: string, path: string, ...jsons: Array<RedisJSON>): Array<string> { IS_READ_ONLY: false,
transformArguments(key: RedisArgument, path: RedisArgument, ...jsons: Array<RedisJSON>) {
const args = ['JSON.ARRAPPEND', key, path]; const args = ['JSON.ARRAPPEND', key, path];
for (const json of jsons) { for (const json of jsons) {
args.push(transformRedisJsonArgument(json)); args.push(transformRedisJsonArgument(json));
} }
return args; return args;
} },
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply>
export declare function transformReply(): number | Array<number>; } as const satisfies Command;

View File

@@ -1,37 +1,37 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ARRINDEX'; import ARRINDEX from './ARRINDEX';
describe('ARRINDEX', () => { describe('ARRINDEX', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('simple', () => { it('simple', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', '$', 'json'), ARRINDEX.transformArguments('key', '$', 'json'),
['JSON.ARRINDEX', 'key', '$', '"json"'] ['JSON.ARRINDEX', 'key', '$', '"json"']
); );
});
it('with start', () => {
assert.deepEqual(
transformArguments('key', '$', 'json', 1),
['JSON.ARRINDEX', 'key', '$', '"json"', '1']
);
});
it('with start, end', () => {
assert.deepEqual(
transformArguments('key', '$', 'json', 1, 2),
['JSON.ARRINDEX', 'key', '$', '"json"', '1', '2']
);
});
}); });
testUtils.testWithClient('client.json.arrIndex', async client => { it('with start', () => {
await client.json.set('key', '$', []); assert.deepEqual(
ARRINDEX.transformArguments('key', '$', 'json', 1),
['JSON.ARRINDEX', 'key', '$', '"json"', '1']
);
});
assert.deepEqual( it('with start, end', () => {
await client.json.arrIndex('key', '$', 'json'), assert.deepEqual(
[-1] ARRINDEX.transformArguments('key', '$', 'json', 1, 2),
); ['JSON.ARRINDEX', 'key', '$', '"json"', '1', '2']
}, GLOBAL.SERVERS.OPEN); );
});
});
testUtils.testWithClient('client.json.arrIndex', async client => {
await client.json.set('key', '$', []);
assert.deepEqual(
await client.json.arrIndex('key', '$', 'json'),
[-1]
);
}, GLOBAL.SERVERS.OPEN);
}); });

View File

@@ -1,21 +1,27 @@
import { RedisArgument, ArrayReply, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
import { RedisJSON, transformRedisJsonArgument } from '.'; import { RedisJSON, transformRedisJsonArgument } from '.';
export const FIRST_KEY_INDEX = 1; export default {
FIRST_KEY_INDEX: 1,
export const IS_READ_ONLY = true; IS_READ_ONLY: true,
transformArguments(
export function transformArguments(key: string, path: string, json: RedisJSON, start?: number, stop?: number): Array<string> { key: RedisArgument,
path: RedisArgument,
json: RedisJSON,
start?: number,
stop?: number
) {
const args = ['JSON.ARRINDEX', key, path, transformRedisJsonArgument(json)]; const args = ['JSON.ARRINDEX', key, path, transformRedisJsonArgument(json)];
if (start !== undefined && start !== null) { if (start !== undefined && start !== null) {
args.push(start.toString()); args.push(start.toString());
if (stop !== undefined && stop !== null) { if (stop !== undefined && stop !== null) {
args.push(stop.toString()); args.push(stop.toString());
} }
} }
return args; return args;
} },
transformReply: undefined as unknown as () => NumberReply | ArrayReply<NumberReply>
export declare function transformReply(): number | Array<number>; } as const satisfies Command;

View File

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

View File

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

View File

@@ -1,33 +1,33 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { SchemaFieldTypes } from '.'; import { SchemaFieldTypes } from '.';
import { transformArguments } from './DROPINDEX'; import DROPINDEX from './DROPINDEX';
describe('DROPINDEX', () => { describe('DROPINDEX', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('without options', () => { it('without options', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('index'), DROPINDEX.transformArguments('index'),
['FT.DROPINDEX', 'index'] ['FT.DROPINDEX', 'index']
); );
});
it('with DD', () => {
assert.deepEqual(
transformArguments('index', { DD: true }),
['FT.DROPINDEX', 'index', 'DD']
);
});
}); });
testUtils.testWithClient('client.ft.dropIndex', async client => { it('with DD', () => {
await client.ft.create('index', { assert.deepEqual(
field: SchemaFieldTypes.TEXT DROPINDEX.transformArguments('index', { DD: true }),
}); ['FT.DROPINDEX', 'index', 'DD']
);
});
});
assert.equal( testUtils.testWithClient('client.ft.dropIndex', async client => {
await client.ft.dropIndex('index'), await client.ft.create('index', {
'OK' field: SchemaFieldTypes.TEXT
); });
}, GLOBAL.SERVERS.OPEN);
assert.equal(
await client.ft.dropIndex('index'),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
}); });

View File

@@ -1,15 +1,23 @@
interface DropIndexOptions { import { RedisArgument, SimpleStringReply, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
DD?: true;
export interface FtDropIndexOptions {
DD?: true;
} }
export function transformArguments(index: string, options?: DropIndexOptions): Array<string> { export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: false,
transformArguments(index: RedisArgument, options?: FtDropIndexOptions) {
const args = ['FT.DROPINDEX', index]; const args = ['FT.DROPINDEX', index];
if (options?.DD) { if (options?.DD) {
args.push('DD'); args.push('DD');
} }
return args; return args;
} },
transformReply: {
export declare function transformReply(): 'OK'; 2: undefined as unknown as () => SimpleStringReply<'OK'>,
3: undefined as unknown as () => NumberReply
}
} as const satisfies Command;

View File

@@ -1,24 +1,24 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { SchemaFieldTypes } from '.'; import { SchemaFieldTypes } from '.';
import { transformArguments } from './TAGVALS'; import TAGVALS from './TAGVALS';
describe('TAGVALS', () => { describe('TAGVALS', () => {
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('index', '@field'), TAGVALS.transformArguments('index', '@field'),
['FT.TAGVALS', 'index', '@field'] ['FT.TAGVALS', 'index', '@field']
); );
});
testUtils.testWithClient('client.ft.tagVals', async client => {
await client.ft.create('index', {
field: SchemaFieldTypes.TAG
}); });
testUtils.testWithClient('client.ft.tagVals', async client => { assert.deepEqual(
await client.ft.create('index', { await client.ft.tagVals('index', 'field'),
field: SchemaFieldTypes.TAG []
}); );
}, GLOBAL.SERVERS.OPEN);
assert.deepEqual(
await client.ft.tagVals('index', 'field'),
[]
);
}, GLOBAL.SERVERS.OPEN);
}); });

View File

@@ -1,5 +1,13 @@
export function transformArguments(index: string, fieldName: string): Array<string> { import { RedisArgument, ArrayReply, SetReply, BlobStringReply, Command } from '@redis/client/dist/lib/RESP/types';
return ['FT.TAGVALS', index, fieldName];
}
export declare function transformReply(): Array<string>; export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: false,
transformArguments(index: RedisArgument, fieldName: RedisArgument) {
return ['FT.TAGVALS', index, fieldName];
},
transformReply: {
2: undefined as unknown as () => ArrayReply<BlobStringReply>,
3: undefined as unknown as () => SetReply<BlobStringReply>
}
} as const satisfies Command;

View File

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

View File

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