1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

Add count option to FT.CURSOR READ (#2492)

* feat: Add count option to FT.CURSOR READ

* Update CURSOR_READ.spec.ts

---------

Co-authored-by: Leibale Eidelman <me@leibale.com>
This commit is contained in:
fast-facts
2023-05-21 08:08:27 -04:00
committed by GitHub
parent d4f194352f
commit 85091cde5a
2 changed files with 28 additions and 8 deletions

View File

@@ -4,15 +4,24 @@ import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './CURSOR_READ'; import { transformArguments } from './CURSOR_READ';
describe('CURSOR READ', () => { describe('CURSOR READ', () => {
it('transformArguments', () => { describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('index', 0), transformArguments('index', 0),
['FT.CURSOR', 'READ', 'index', '0'] ['FT.CURSOR', 'READ', 'index', '0']
); );
}); });
it('with COUNT', () => {
assert.deepEqual(
transformArguments('index', 0, { COUNT: 1 }),
['FT.CURSOR', 'READ', 'index', '0', 'COUNT', '1']
);
});
});
testUtils.testWithClient('client.ft.cursorRead', async client => { testUtils.testWithClient('client.ft.cursorRead', async client => {
const [ ,, { cursor } ] = await Promise.all([ const [, , { cursor }] = await Promise.all([
client.ft.create('idx', { client.ft.create('idx', {
field: { field: {
type: SchemaFieldTypes.TEXT type: SchemaFieldTypes.TEXT

View File

@@ -4,16 +4,27 @@ export const FIRST_KEY_INDEX = 1;
export const IS_READ_ONLY = true; export const IS_READ_ONLY = true;
interface CursorReadOptions {
COUNT?: number;
}
export function transformArguments( export function transformArguments(
index: RedisCommandArgument, index: RedisCommandArgument,
cursor: number cursor: number,
options?: CursorReadOptions
): RedisCommandArguments { ): RedisCommandArguments {
return [ const args = [
'FT.CURSOR', 'FT.CURSOR',
'READ', 'READ',
index, index,
cursor.toString() cursor.toString()
]; ];
if (options?.COUNT) {
args.push('COUNT', options.COUNT.toString());
}
return args;
} }
export { transformReply } from './AGGREGATE_WITHCURSOR'; export { transformReply } from './AGGREGATE_WITHCURSOR';