-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
8 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters