diff --git a/docs/v4-to-v5.md b/docs/v4-to-v5.md index 2c8d153b08..4841ab5569 100644 --- a/docs/v4-to-v5.md +++ b/docs/v4-to-v5.md @@ -207,6 +207,7 @@ await cluster.multi() ### Search - `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 diff --git a/packages/search/lib/commands/AGGREGATE_WITHCURSOR.ts b/packages/search/lib/commands/AGGREGATE_WITHCURSOR.ts index 6591d4620f..dae5c09b2c 100644 --- a/packages/search/lib/commands/AGGREGATE_WITHCURSOR.ts +++ b/packages/search/lib/commands/AGGREGATE_WITHCURSOR.ts @@ -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 AGGREGATE, { FtAggregateOptions } from './AGGREGATE'; diff --git a/packages/search/lib/commands/CURSOR_READ.spec.ts b/packages/search/lib/commands/CURSOR_READ.spec.ts index e8ef2c3091..237d234786 100644 --- a/packages/search/lib/commands/CURSOR_READ.spec.ts +++ b/packages/search/lib/commands/CURSOR_READ.spec.ts @@ -1,45 +1,44 @@ import { strict as assert } from 'node:assert'; -import { SchemaFieldTypes } from '.'; import testUtils, { GLOBAL } from '../test-utils'; -import { transformArguments } from './CURSOR_READ'; +import CURSOR_READ from './CURSOR_READ'; -describe('CURSOR READ', () => { - 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'] - ); - }); +describe('FT.CURSOR READ', () => { + describe('transformArguments', () => { + it('without options', () => { + assert.deepEqual( + CURSOR_READ.transformArguments('index', '0'), + ['FT.CURSOR', 'READ', 'index', '0'] + ); }); - testUtils.testWithClient('client.ft.cursorRead', async client => { - const [, , { cursor }] = await Promise.all([ - client.ft.create('idx', { - field: { - type: SchemaFieldTypes.TEXT - } - }), - client.hSet('key', 'field', 'value'), - client.ft.aggregateWithCursor('idx', '*', { - COUNT: 1 - }) - ]); + it('with COUNT', () => { + assert.deepEqual( + CURSOR_READ.transformArguments('index', '0', { + COUNT: 1 + }), + ['FT.CURSOR', 'READ', 'index', '0', 'COUNT', '1'] + ); + }); + }); - assert.deepEqual( - await client.ft.cursorRead('idx', cursor), - { - total: 0, - results: [], - cursor: 0 - } - ); - }, GLOBAL.SERVERS.OPEN); + testUtils.testWithClient('client.ft.cursorRead', async client => { + const [, , { cursor }] = await Promise.all([ + client.ft.create('idx', { + field: 'TEXT' + }), + client.hSet('key', 'field', 'value'), + client.ft.aggregateWithCursor('idx', '*', { + COUNT: 1 + }) + ]); + + assert.deepEqual( + await client.ft.cursorRead('idx', cursor), + { + total: 0, + results: [], + cursor: '0' + } + ); + }, GLOBAL.SERVERS.OPEN); }); diff --git a/packages/search/lib/commands/CURSOR_READ.ts b/packages/search/lib/commands/CURSOR_READ.ts index 35cf1bc4f0..1c647303f9 100644 --- a/packages/search/lib/commands/CURSOR_READ.ts +++ b/packages/search/lib/commands/CURSOR_READ.ts @@ -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 const IS_READ_ONLY = true; - -interface CursorReadOptions { - COUNT?: number; +export interface FtCursorReadOptions { + COUNT?: number; } -export function transformArguments( - index: RedisCommandArgument, - cursor: number, - options?: CursorReadOptions -): RedisCommandArguments { - const args = [ - 'FT.CURSOR', - 'READ', - index, - cursor.toString() - ]; +export default { + FIRST_KEY_INDEX: undefined, + IS_READ_ONLY: true, + transformArguments(index: RedisArgument, cursor: RedisArgument, options?: FtCursorReadOptions) { + const args = ['FT.CURSOR', 'READ', index, cursor]; - if (options?.COUNT) { - args.push('COUNT', options.COUNT.toString()); + if (options?.COUNT !== undefined) { + args.push('COUNT', options.COUNT.toString()); } return args; -} - -export { transformReply } from './AGGREGATE_WITHCURSOR'; + }, + transformReply: AGGREGATE_WITHCURSOR.transformReply +} as const satisfies Command; diff --git a/packages/search/lib/commands/index.ts b/packages/search/lib/commands/index.ts index 978ee1b265..af51fc1bbc 100644 --- a/packages/search/lib/commands/index.ts +++ b/packages/search/lib/commands/index.ts @@ -9,7 +9,7 @@ import CONFIG_GET from './CONFIG_GET'; import CONFIG_SET from './CONFIG_SET'; import CREATE from './CREATE'; import CURSOR_DEL from './CURSOR_DEL'; -// import CURSOR_READ from './CURSOR_READ'; +import CURSOR_READ from './CURSOR_READ'; import DICTADD from './DICTADD'; import DICTDEL from './DICTDEL'; import DICTDUMP from './DICTDUMP'; @@ -61,8 +61,8 @@ export default { create: CREATE, CURSOR_DEL, cursorDel: CURSOR_DEL, - // CURSOR_READ, - // cursorRead: CURSOR_READ, + CURSOR_READ, + cursorRead: CURSOR_READ, DICTADD, dictAdd: DICTADD, DICTDEL,