Skip to content

Commit 98970fa

Browse files
committed
FT.CURSOR READ
1 parent ebca66d commit 98970fa

File tree

5 files changed

+54
-108
lines changed

5 files changed

+54
-108
lines changed

docs/v4-to-v5.md

+1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ await cluster.multi()
207207
### Search
208208

209209
- `FT.SUGDEL`: [^boolean-to-number]
210+
- `FT.CURSOR READ`: `cursor` type changed from `number` to `string` (in and out) to avoid issues when the number is bigger than `Number.MAX_SAFE_INTEGER`. See [here](https://github.com/redis/node-redis/issues/2561).
210211

211212
### Time Series
212213

packages/search/lib/commands/AGGREGATE_WITHCURSOR.ts

-45
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,3 @@
1-
// import {
2-
// AggregateOptions,
3-
// AggregateRawReply,
4-
// AggregateReply,
5-
// transformArguments as transformAggregateArguments,
6-
// transformReply as transformAggregateReply
7-
// } from './AGGREGATE';
8-
9-
// export { FIRST_KEY_INDEX, IS_READ_ONLY } from './AGGREGATE';
10-
11-
// interface AggregateWithCursorOptions extends AggregateOptions {
12-
// COUNT?: number;
13-
// }
14-
15-
// export function transformArguments(
16-
// index: string,
17-
// query: string,
18-
// options?: AggregateWithCursorOptions
19-
// ) {
20-
// const args = transformAggregateArguments(index, query, options);
21-
22-
// args.push('WITHCURSOR');
23-
// if (options?.COUNT) {
24-
// args.push('COUNT', options.COUNT.toString());
25-
// }
26-
27-
// return args;
28-
// }
29-
30-
// type AggregateWithCursorRawReply = [
31-
// result: AggregateRawReply,
32-
// cursor: number
33-
// ];
34-
35-
// interface AggregateWithCursorReply extends AggregateReply {
36-
// cursor: number;
37-
// }
38-
39-
// export function transformReply(reply: AggregateWithCursorRawReply): AggregateWithCursorReply {
40-
// return {
41-
// ...transformAggregateReply(reply[0]),
42-
// cursor: reply[1]
43-
// };
44-
// }
45-
461
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
472
import AGGREGATE, { FtAggregateOptions } from './AGGREGATE';
483

Original file line numberDiff line numberDiff line change
@@ -1,45 +1,44 @@
11
import { strict as assert } from 'node:assert';
2-
import { SchemaFieldTypes } from '.';
32
import testUtils, { GLOBAL } from '../test-utils';
4-
import { transformArguments } from './CURSOR_READ';
3+
import CURSOR_READ from './CURSOR_READ';
54

6-
describe('CURSOR READ', () => {
7-
describe('transformArguments', () => {
8-
it('without options', () => {
9-
assert.deepEqual(
10-
transformArguments('index', 0),
11-
['FT.CURSOR', 'READ', 'index', '0']
12-
);
13-
});
5+
describe('FT.CURSOR READ', () => {
6+
describe('transformArguments', () => {
7+
it('without options', () => {
8+
assert.deepEqual(
9+
CURSOR_READ.transformArguments('index', '0'),
10+
['FT.CURSOR', 'READ', 'index', '0']
11+
);
12+
});
1413

15-
it('with COUNT', () => {
16-
assert.deepEqual(
17-
transformArguments('index', 0, { COUNT: 1 }),
18-
['FT.CURSOR', 'READ', 'index', '0', 'COUNT', '1']
19-
);
20-
});
14+
it('with COUNT', () => {
15+
assert.deepEqual(
16+
CURSOR_READ.transformArguments('index', '0', {
17+
COUNT: 1
18+
}),
19+
['FT.CURSOR', 'READ', 'index', '0', 'COUNT', '1']
20+
);
2121
});
22+
});
2223

23-
testUtils.testWithClient('client.ft.cursorRead', async client => {
24-
const [, , { cursor }] = await Promise.all([
25-
client.ft.create('idx', {
26-
field: {
27-
type: SchemaFieldTypes.TEXT
28-
}
29-
}),
30-
client.hSet('key', 'field', 'value'),
31-
client.ft.aggregateWithCursor('idx', '*', {
32-
COUNT: 1
33-
})
34-
]);
24+
testUtils.testWithClient('client.ft.cursorRead', async client => {
25+
const [, , { cursor }] = await Promise.all([
26+
client.ft.create('idx', {
27+
field: 'TEXT'
28+
}),
29+
client.hSet('key', 'field', 'value'),
30+
client.ft.aggregateWithCursor('idx', '*', {
31+
COUNT: 1
32+
})
33+
]);
3534

36-
assert.deepEqual(
37-
await client.ft.cursorRead('idx', cursor),
38-
{
39-
total: 0,
40-
results: [],
41-
cursor: 0
42-
}
43-
);
44-
}, GLOBAL.SERVERS.OPEN);
35+
assert.deepEqual(
36+
await client.ft.cursorRead('idx', cursor),
37+
{
38+
total: 0,
39+
results: [],
40+
cursor: '0'
41+
}
42+
);
43+
}, GLOBAL.SERVERS.OPEN);
4544
});
+14-23
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
1-
import { RedisCommandArgument, RedisCommandArguments } from '@redis/client/dist/lib/commands';
1+
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
2+
import AGGREGATE_WITHCURSOR from './AGGREGATE_WITHCURSOR';
23

3-
export const FIRST_KEY_INDEX = 1;
4-
5-
export const IS_READ_ONLY = true;
6-
7-
interface CursorReadOptions {
8-
COUNT?: number;
4+
export interface FtCursorReadOptions {
5+
COUNT?: number;
96
}
107

11-
export function transformArguments(
12-
index: RedisCommandArgument,
13-
cursor: number,
14-
options?: CursorReadOptions
15-
): RedisCommandArguments {
16-
const args = [
17-
'FT.CURSOR',
18-
'READ',
19-
index,
20-
cursor.toString()
21-
];
8+
export default {
9+
FIRST_KEY_INDEX: undefined,
10+
IS_READ_ONLY: true,
11+
transformArguments(index: RedisArgument, cursor: RedisArgument, options?: FtCursorReadOptions) {
12+
const args = ['FT.CURSOR', 'READ', index, cursor];
2213

23-
if (options?.COUNT) {
24-
args.push('COUNT', options.COUNT.toString());
14+
if (options?.COUNT !== undefined) {
15+
args.push('COUNT', options.COUNT.toString());
2516
}
2617

2718
return args;
28-
}
29-
30-
export { transformReply } from './AGGREGATE_WITHCURSOR';
19+
},
20+
transformReply: AGGREGATE_WITHCURSOR.transformReply
21+
} as const satisfies Command;

packages/search/lib/commands/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import CONFIG_GET from './CONFIG_GET';
99
import CONFIG_SET from './CONFIG_SET';
1010
import CREATE from './CREATE';
1111
import CURSOR_DEL from './CURSOR_DEL';
12-
// import CURSOR_READ from './CURSOR_READ';
12+
import CURSOR_READ from './CURSOR_READ';
1313
import DICTADD from './DICTADD';
1414
import DICTDEL from './DICTDEL';
1515
import DICTDUMP from './DICTDUMP';
@@ -61,8 +61,8 @@ export default {
6161
create: CREATE,
6262
CURSOR_DEL,
6363
cursorDel: CURSOR_DEL,
64-
// CURSOR_READ,
65-
// cursorRead: CURSOR_READ,
64+
CURSOR_READ,
65+
cursorRead: CURSOR_READ,
6666
DICTADD,
6767
dictAdd: DICTADD,
6868
DICTDEL,

0 commit comments

Comments
 (0)