Skip to content

Commit 17099aa

Browse files
committed
feat: Add count option to FT.CURSOR READ
1 parent 3273c85 commit 17099aa

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

packages/search/lib/commands/CURSOR_READ.spec.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@ import { transformArguments } from './CURSOR_READ';
55

66
describe('CURSOR READ', () => {
77
it('transformArguments', () => {
8-
assert.deepEqual(
9-
transformArguments('index', 0),
10-
['FT.CURSOR', 'READ', 'index', '0']
11-
);
8+
it('without options', () => {
9+
assert.deepEqual(
10+
transformArguments('index', 0),
11+
['FT.CURSOR', 'READ', 'index', '0']
12+
);
13+
});
14+
15+
it('with COUNT', () => {
16+
assert.deepEqual(
17+
transformArguments('index', 0, { COUNT: 1 }),
18+
['FT.CURSOR', 'READ', 'index', '0', 'COUNT', '1']
19+
);
20+
});
1221
});
1322

1423
testUtils.testWithClient('client.ft.cursorRead', async client => {
15-
const [ ,, { cursor } ] = await Promise.all([
24+
const [, , { cursor }] = await Promise.all([
1625
client.ft.create('idx', {
1726
field: {
1827
type: SchemaFieldTypes.TEXT

packages/search/lib/commands/CURSOR_READ.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,27 @@ export const FIRST_KEY_INDEX = 1;
44

55
export const IS_READ_ONLY = true;
66

7+
interface CursorReadOptions {
8+
COUNT?: number;
9+
}
10+
711
export function transformArguments(
812
index: RedisCommandArgument,
9-
cursor: number
13+
cursor: number,
14+
options?: CursorReadOptions
1015
): RedisCommandArguments {
11-
return [
16+
const args = [
1217
'FT.CURSOR',
1318
'READ',
1419
index,
1520
cursor.toString()
1621
];
22+
23+
if (options.COUNT) {
24+
args.push('COUNT', options.COUNT.toString());
25+
}
26+
27+
return args;
1728
}
1829

1930
export { transformReply } from './AGGREGATE_WITHCURSOR';

0 commit comments

Comments
 (0)