1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

FT.CURSOR READ

This commit is contained in:
Leibale
2023-11-06 14:06:54 -05:00
parent ebca66d6f6
commit 98970fab2e
5 changed files with 55 additions and 109 deletions

View File

@@ -207,6 +207,7 @@ await cluster.multi()
### Search ### Search
- `FT.SUGDEL`: [^boolean-to-number] - `FT.SUGDEL`: [^boolean-to-number]
- `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).
### Time Series ### Time Series

View File

@@ -1,48 +1,3 @@
// import {
// AggregateOptions,
// AggregateRawReply,
// AggregateReply,
// transformArguments as transformAggregateArguments,
// transformReply as transformAggregateReply
// } from './AGGREGATE';
// export { FIRST_KEY_INDEX, IS_READ_ONLY } from './AGGREGATE';
// interface AggregateWithCursorOptions extends AggregateOptions {
// COUNT?: number;
// }
// export function transformArguments(
// index: string,
// query: string,
// options?: AggregateWithCursorOptions
// ) {
// const args = transformAggregateArguments(index, query, options);
// args.push('WITHCURSOR');
// if (options?.COUNT) {
// args.push('COUNT', options.COUNT.toString());
// }
// return args;
// }
// type AggregateWithCursorRawReply = [
// result: AggregateRawReply,
// cursor: number
// ];
// interface AggregateWithCursorReply extends AggregateReply {
// cursor: number;
// }
// export function transformReply(reply: AggregateWithCursorRawReply): AggregateWithCursorReply {
// return {
// ...transformAggregateReply(reply[0]),
// cursor: reply[1]
// };
// }
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types'; import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
import AGGREGATE, { FtAggregateOptions } from './AGGREGATE'; import AGGREGATE, { FtAggregateOptions } from './AGGREGATE';

View File

@@ -1,45 +1,44 @@
import { strict as assert } from 'node:assert'; import { strict as assert } from 'node:assert';
import { SchemaFieldTypes } from '.';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './CURSOR_READ'; import CURSOR_READ from './CURSOR_READ';
describe('CURSOR READ', () => { describe('FT.CURSOR READ', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('without options', () => { it('without options', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('index', 0), CURSOR_READ.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 => { it('with COUNT', () => {
const [, , { cursor }] = await Promise.all([ assert.deepEqual(
client.ft.create('idx', { CURSOR_READ.transformArguments('index', '0', {
field: { COUNT: 1
type: SchemaFieldTypes.TEXT }),
} ['FT.CURSOR', 'READ', 'index', '0', 'COUNT', '1']
}), );
client.hSet('key', 'field', 'value'), });
client.ft.aggregateWithCursor('idx', '*', { });
COUNT: 1
})
]);
assert.deepEqual( testUtils.testWithClient('client.ft.cursorRead', async client => {
await client.ft.cursorRead('idx', cursor), const [, , { cursor }] = await Promise.all([
{ client.ft.create('idx', {
total: 0, field: 'TEXT'
results: [], }),
cursor: 0 client.hSet('key', 'field', 'value'),
} client.ft.aggregateWithCursor('idx', '*', {
); COUNT: 1
}, GLOBAL.SERVERS.OPEN); })
]);
assert.deepEqual(
await client.ft.cursorRead('idx', cursor),
{
total: 0,
results: [],
cursor: '0'
}
);
}, GLOBAL.SERVERS.OPEN);
}); });

View File

@@ -1,30 +1,21 @@
import { RedisCommandArgument, RedisCommandArguments } from '@redis/client/dist/lib/commands'; import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
import AGGREGATE_WITHCURSOR from './AGGREGATE_WITHCURSOR';
export const FIRST_KEY_INDEX = 1; export interface FtCursorReadOptions {
COUNT?: number;
export const IS_READ_ONLY = true;
interface CursorReadOptions {
COUNT?: number;
} }
export function transformArguments( export default {
index: RedisCommandArgument, FIRST_KEY_INDEX: undefined,
cursor: number, IS_READ_ONLY: true,
options?: CursorReadOptions transformArguments(index: RedisArgument, cursor: RedisArgument, options?: FtCursorReadOptions) {
): RedisCommandArguments { const args = ['FT.CURSOR', 'READ', index, cursor];
const args = [
'FT.CURSOR',
'READ',
index,
cursor.toString()
];
if (options?.COUNT) { if (options?.COUNT !== undefined) {
args.push('COUNT', options.COUNT.toString()); args.push('COUNT', options.COUNT.toString());
} }
return args; return args;
} },
transformReply: AGGREGATE_WITHCURSOR.transformReply
export { transformReply } from './AGGREGATE_WITHCURSOR'; } as const satisfies Command;

View File

@@ -9,7 +9,7 @@ import CONFIG_GET from './CONFIG_GET';
import CONFIG_SET from './CONFIG_SET'; import CONFIG_SET from './CONFIG_SET';
import CREATE from './CREATE'; import CREATE from './CREATE';
import CURSOR_DEL from './CURSOR_DEL'; import CURSOR_DEL from './CURSOR_DEL';
// import CURSOR_READ from './CURSOR_READ'; import CURSOR_READ from './CURSOR_READ';
import DICTADD from './DICTADD'; import DICTADD from './DICTADD';
import DICTDEL from './DICTDEL'; import DICTDEL from './DICTDEL';
import DICTDUMP from './DICTDUMP'; import DICTDUMP from './DICTDUMP';
@@ -61,8 +61,8 @@ export default {
create: CREATE, create: CREATE,
CURSOR_DEL, CURSOR_DEL,
cursorDel: CURSOR_DEL, cursorDel: CURSOR_DEL,
// CURSOR_READ, CURSOR_READ,
// cursorRead: CURSOR_READ, cursorRead: CURSOR_READ,
DICTADD, DICTADD,
dictAdd: DICTADD, dictAdd: DICTADD,
DICTDEL, DICTDEL,