Skip to content

Commit 85091cd

Browse files
fast-factsleibale
andauthored
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>
1 parent d4f1943 commit 85091cd

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

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

+15-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,24 @@ import testUtils, { GLOBAL } from '../test-utils';
44
import { transformArguments } from './CURSOR_READ';
55

66
describe('CURSOR READ', () => {
7-
it('transformArguments', () => {
8-
assert.deepEqual(
9-
transformArguments('index', 0),
10-
['FT.CURSOR', 'READ', 'index', '0']
11-
);
7+
describe('transformArguments', () => {
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

+13-2
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)