You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
@@ -126,6 +126,10 @@ export interface AggregateOptions {
|
|||||||
DIALECT?: number;
|
DIALECT?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const FIRST_KEY_INDEX = 1;
|
||||||
|
|
||||||
|
export const IS_READ_ONLY = true;
|
||||||
|
|
||||||
export function transformArguments(
|
export function transformArguments(
|
||||||
index: string,
|
index: string,
|
||||||
query: string,
|
query: string,
|
||||||
|
37
packages/search/lib/commands/AGGREGATE_WITHCURSOR.spec.ts
Normal file
37
packages/search/lib/commands/AGGREGATE_WITHCURSOR.spec.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { strict as assert } from 'assert';
|
||||||
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
|
import { transformArguments } from './AGGREGATE_WITHCURSOR';
|
||||||
|
import { SchemaFieldTypes } from '.';
|
||||||
|
|
||||||
|
describe('AGGREGATE WITHCURSOR', () => {
|
||||||
|
describe('transformArguments', () => {
|
||||||
|
it('without options', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
transformArguments('index', '*'),
|
||||||
|
['FT.AGGREGATE', 'index', '*', 'WITHCURSOR']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('with COUNT', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
transformArguments('index', '*', { COUNT: 1 }),
|
||||||
|
['FT.AGGREGATE', 'index', '*', 'WITHCURSOR', 'COUNT', '1']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
testUtils.testWithClient('client.ft.aggregateWithCursor', async client => {
|
||||||
|
await client.ft.create('index', {
|
||||||
|
field: SchemaFieldTypes.NUMERIC
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
await client.ft.aggregateWithCursor('index', '*'),
|
||||||
|
{
|
||||||
|
total: 0,
|
||||||
|
results: [],
|
||||||
|
cursor: 0
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
});
|
44
packages/search/lib/commands/AGGREGATE_WITHCURSOR.ts
Normal file
44
packages/search/lib/commands/AGGREGATE_WITHCURSOR.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
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]
|
||||||
|
};
|
||||||
|
}
|
33
packages/search/lib/commands/CURSOR_DEL.spec.ts
Normal file
33
packages/search/lib/commands/CURSOR_DEL.spec.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { strict as assert } from 'assert';
|
||||||
|
import { SchemaFieldTypes } from '.';
|
||||||
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
|
import { transformArguments } from './CURSOR_DEL';
|
||||||
|
|
||||||
|
describe('CURSOR DEL', () => {
|
||||||
|
it('transformArguments', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
transformArguments('index', 0),
|
||||||
|
['FT.CURSOR', 'DEL', 'index', '0']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testUtils.testWithClient('client.ft.cursorDel', 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
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
await client.ft.cursorDel('idx', cursor),
|
||||||
|
'OK'
|
||||||
|
);
|
||||||
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
});
|
14
packages/search/lib/commands/CURSOR_DEL.ts
Normal file
14
packages/search/lib/commands/CURSOR_DEL.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { RedisCommandArgument } from '@redis/client/dist/lib/commands';
|
||||||
|
|
||||||
|
export const FIRST_KEY_INDEX = 1;
|
||||||
|
|
||||||
|
export function transformArguments(index: RedisCommandArgument, cursorId: number) {
|
||||||
|
return [
|
||||||
|
'FT.CURSOR',
|
||||||
|
'DEL',
|
||||||
|
index,
|
||||||
|
cursorId.toString()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
export declare function transformReply(): 'OK';
|
36
packages/search/lib/commands/CURSOR_READ.spec.ts
Normal file
36
packages/search/lib/commands/CURSOR_READ.spec.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import { strict as assert } from 'assert';
|
||||||
|
import { SchemaFieldTypes } from '.';
|
||||||
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
|
import { transformArguments } from './CURSOR_READ';
|
||||||
|
|
||||||
|
describe('CURSOR READ', () => {
|
||||||
|
it('transformArguments', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
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
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
await client.ft.cursorRead('idx', cursor),
|
||||||
|
{
|
||||||
|
total: 0,
|
||||||
|
results: [],
|
||||||
|
cursor: 0
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
});
|
19
packages/search/lib/commands/CURSOR_READ.ts
Normal file
19
packages/search/lib/commands/CURSOR_READ.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { RedisCommandArgument, RedisCommandArguments } from '@redis/client/dist/lib/commands';
|
||||||
|
|
||||||
|
export const FIRST_KEY_INDEX = 1;
|
||||||
|
|
||||||
|
export const IS_READ_ONLY = true;
|
||||||
|
|
||||||
|
export function transformArguments(
|
||||||
|
index: RedisCommandArgument,
|
||||||
|
cursor: number
|
||||||
|
): RedisCommandArguments {
|
||||||
|
return [
|
||||||
|
'FT.CURSOR',
|
||||||
|
'READ',
|
||||||
|
index,
|
||||||
|
cursor.toString()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
export { transformReply } from './AGGREGATE_WITHCURSOR';
|
@@ -1,5 +1,6 @@
|
|||||||
import * as _LIST from './_LIST';
|
import * as _LIST from './_LIST';
|
||||||
import * as ALTER from './ALTER';
|
import * as ALTER from './ALTER';
|
||||||
|
import * as AGGREGATE_WITHCURSOR from './AGGREGATE_WITHCURSOR';
|
||||||
import * as AGGREGATE from './AGGREGATE';
|
import * as AGGREGATE from './AGGREGATE';
|
||||||
import * as ALIASADD from './ALIASADD';
|
import * as ALIASADD from './ALIASADD';
|
||||||
import * as ALIASDEL from './ALIASDEL';
|
import * as ALIASDEL from './ALIASDEL';
|
||||||
@@ -7,6 +8,8 @@ import * as ALIASUPDATE from './ALIASUPDATE';
|
|||||||
import * as CONFIG_GET from './CONFIG_GET';
|
import * as CONFIG_GET from './CONFIG_GET';
|
||||||
import * as CONFIG_SET from './CONFIG_SET';
|
import * as CONFIG_SET from './CONFIG_SET';
|
||||||
import * as CREATE from './CREATE';
|
import * as CREATE from './CREATE';
|
||||||
|
import * as CURSOR_DEL from './CURSOR_DEL';
|
||||||
|
import * as CURSOR_READ from './CURSOR_READ';
|
||||||
import * as DICTADD from './DICTADD';
|
import * as DICTADD from './DICTADD';
|
||||||
import * as DICTDEL from './DICTDEL';
|
import * as DICTDEL from './DICTDEL';
|
||||||
import * as DICTDUMP from './DICTDUMP';
|
import * as DICTDUMP from './DICTDUMP';
|
||||||
@@ -37,6 +40,8 @@ export default {
|
|||||||
_list: _LIST,
|
_list: _LIST,
|
||||||
ALTER,
|
ALTER,
|
||||||
alter: ALTER,
|
alter: ALTER,
|
||||||
|
AGGREGATE_WITHCURSOR,
|
||||||
|
aggregateWithCursor: AGGREGATE_WITHCURSOR,
|
||||||
AGGREGATE,
|
AGGREGATE,
|
||||||
aggregate: AGGREGATE,
|
aggregate: AGGREGATE,
|
||||||
ALIASADD,
|
ALIASADD,
|
||||||
@@ -51,6 +56,10 @@ export default {
|
|||||||
configSet: CONFIG_SET,
|
configSet: CONFIG_SET,
|
||||||
CREATE,
|
CREATE,
|
||||||
create: CREATE,
|
create: CREATE,
|
||||||
|
CURSOR_DEL,
|
||||||
|
cursorDel: CURSOR_DEL,
|
||||||
|
CURSOR_READ,
|
||||||
|
cursorRead: CURSOR_READ,
|
||||||
DICTADD,
|
DICTADD,
|
||||||
dictAdd: DICTADD,
|
dictAdd: DICTADD,
|
||||||
DICTDEL,
|
DICTDEL,
|
||||||
|
Reference in New Issue
Block a user