You've already forked node-redis
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:
@@ -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';
|
||||
|
||||
|
@@ -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);
|
||||
});
|
||||
|
@@ -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;
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user