Skip to content

Commit

Permalink
Add count option to FT.CURSOR READ (#2492)
Browse files Browse the repository at this point in the history
* feat: Add count option to FT.CURSOR READ

* Update CURSOR_READ.spec.ts

---------

Co-authored-by: Leibale Eidelman <me@leibale.com>
  • Loading branch information
fast-facts and leibale committed May 21, 2023
1 parent d4f1943 commit 85091cd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
21 changes: 15 additions & 6 deletions packages/search/lib/commands/CURSOR_READ.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@ import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './CURSOR_READ';

describe('CURSOR READ', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('index', 0),
['FT.CURSOR', 'READ', 'index', '0']
);
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(
transformArguments('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 => {
const [ ,, { cursor } ] = await Promise.all([
const [, , { cursor }] = await Promise.all([
client.ft.create('idx', {
field: {
type: SchemaFieldTypes.TEXT
Expand Down
15 changes: 13 additions & 2 deletions packages/search/lib/commands/CURSOR_READ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@ export const FIRST_KEY_INDEX = 1;

export const IS_READ_ONLY = true;

interface CursorReadOptions {
COUNT?: number;
}

export function transformArguments(
index: RedisCommandArgument,
cursor: number
cursor: number,
options?: CursorReadOptions
): RedisCommandArguments {
return [
const args = [
'FT.CURSOR',
'READ',
index,
cursor.toString()
];

if (options?.COUNT) {
args.push('COUNT', options.COUNT.toString());
}

return args;
}

export { transformReply } from './AGGREGATE_WITHCURSOR';

0 comments on commit 85091cd

Please sign in to comment.