Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,40 @@ describe('Standalone Scanner Strategy', () => {
null,
);
});
it('should scan 2000 items when count provided more then 2k', async () => {
const args = { ...getKeysDto, count: 10_000, match: '*' };
jest.spyOn(Utils, 'getTotal').mockResolvedValue(mockGetTotalResponse_1);

when(browserTool.execCommand)
.calledWith(
mockBrowserClientMetadata,
BrowserToolKeysCommands.Scan,
expect.anything(),
null,
)
.mockResolvedValue([0, [getKeyInfoResponse.name]]);

strategy.getKeysInfo = jest.fn().mockResolvedValue([getKeyInfoResponse]);

const result = await strategy.getKeys(mockBrowserClientMetadata, args);

expect(result).toEqual([
{
...mockNodeEmptyResult,
total: 1,
scanned: 2000,
keys: [getKeyInfoResponse],
},
]);
expect(strategy.getKeysInfo).toHaveBeenCalled();
expect(browserTool.execCommand).toHaveBeenNthCalledWith(
1,
mockBrowserClientMetadata,
BrowserToolKeysCommands.Scan,
['0', 'MATCH', args.match, 'COUNT', 2000],
null,
);
});
it('should return keys names and type only', async () => {
const args = {
...getKeysDto, type: 'string', match: 'pattern*', keysInfo: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export class StandaloneStrategy extends AbstractStrategy {
count: number,
type?: RedisDataType,
): Promise<void> {
const COUNT = Math.min(2000, count);

let fullScanned = false;
// todo: remove settings from here. threshold should be part of query?
const settings = await this.settingsService.getAppSettings('1');
Expand All @@ -97,7 +99,7 @@ export class StandaloneStrategy extends AbstractStrategy {
node.scanned < settings.scanThreshold
)
) {
let commandArgs = [`${node.cursor}`, 'MATCH', match, 'COUNT', count];
let commandArgs = [`${node.cursor}`, 'MATCH', match, 'COUNT', COUNT];
if (type) {
commandArgs = [...commandArgs, 'TYPE', type];
}
Expand All @@ -112,7 +114,7 @@ export class StandaloneStrategy extends AbstractStrategy {
// eslint-disable-next-line no-param-reassign
node.cursor = parseInt(nextCursor, 10);
// eslint-disable-next-line no-param-reassign
node.scanned += count;
node.scanned += COUNT;
node.keys.push(...keys);
fullScanned = node.cursor === 0;
}
Expand Down