Skip to content

Commit 470cfe0

Browse files
fix scan threshold
1 parent 0c8c4c1 commit 470cfe0

File tree

7 files changed

+21
-16
lines changed

7 files changed

+21
-16
lines changed

redisinsight/api/config/default.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ export default {
114114
},
115115
redis_scan: {
116116
countDefault: parseInt(process.env.RI_SCAN_COUNT_DEFAULT, 10) || 200,
117-
countThreshold: parseInt(process.env.RI_SCAN_COUNT_THRESHOLD, 10) || 10000,
118-
countThresholdMax: parseInt(process.env.RI_SCAN_COUNT_THRESHOLD_MAX, 10) || Number.MAX_VALUE,
117+
scanThreshold: parseInt(process.env.RI_SCAN_THRESHOLD, 10) || 10000,
118+
scanThresholdMax: parseInt(process.env.RI_SCAN_THRESHOLD_MAX, 10) || Number.MAX_VALUE,
119119
},
120120
modules: {
121121
json: {

redisinsight/api/src/modules/browser/keys/dto/get.keys.dto.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import config, { Config } from 'src/utils/config';
77
import { RedisDataType } from './key.dto';
88

99
const scanConfig = config.get('redis_scan') as Config['redis_scan'];
10-
const { countThreshold, countThresholdMax } = scanConfig;
10+
const { scanThreshold, scanThresholdMax } = scanConfig;
1111

1212
export class GetKeysDto {
1313
@ApiProperty({
@@ -67,12 +67,12 @@ export class GetKeysDto {
6767
keysInfo?: boolean = true;
6868

6969
@ApiPropertyOptional({
70-
description: 'The maximum number of iterations when performing a Redis SCAN operation.',
70+
description: 'The maximum number of keys to scan',
7171
type: Number,
7272
default: true,
7373
})
7474
@IsOptional()
7575
@IsInt()
76-
@Max(countThresholdMax)
77-
countThreshold: number = countThreshold;
76+
@Max(scanThresholdMax)
77+
scanThreshold: number = scanThreshold;
7878
}

redisinsight/api/src/modules/browser/keys/scanner/scanner.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface IScannerGetKeysArgs {
88
match?: string;
99
type?: RedisDataType;
1010
keysInfo?: boolean;
11-
countThreshold: number;
11+
scanThreshold: number;
1212
}
1313

1414
export interface IScannerNodeKeys {

redisinsight/api/src/modules/browser/keys/scanner/strategies/cluster.scanner.strategy.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ describe('Cluster Scanner Strategy', () => {
8787
});
8888

8989
describe('getKeys', () => {
90-
const getKeysDto: GetKeysDto = { cursor: '0', count: 15, keysInfo: true, countThreshold: 1000 };
90+
const getKeysDto: GetKeysDto = {
91+
cursor: '0', count: 15, keysInfo: true, scanThreshold: 1000,
92+
};
9193

9294
it('should return appropriate value with filter by type', async () => {
9395
const args = { ...getKeysDto, type: RedisDataType.String, match: 'pattern*' };
@@ -330,7 +332,7 @@ describe('Cluster Scanner Strategy', () => {
330332
const expectedNode3CallsBeforeThreshold = Math.trunc(
331333
// -5 is number of scans for node1 (3) and node2 (2)
332334
// since threshold applied for sum of all nodes scanned
333-
getKeysDto.countThreshold / args.count - 5,
335+
getKeysDto.scanThreshold / args.count - 5,
334336
);
335337

336338
jest.spyOn(Utils, 'getTotalKeys').mockResolvedValueOnce(mockGetTotalResponse3000);
@@ -393,7 +395,7 @@ describe('Cluster Scanner Strategy', () => {
393395
total: mockGetTotalResponse1000000,
394396
cursor: 1,
395397
scanned:
396-
Math.trunc(getKeysDto.countThreshold / args.count)
398+
Math.trunc(getKeysDto.scanThreshold / args.count)
397399
* args.count
398400
- 5 * args.count, // 5 = scan for other shards (3 and 2)
399401
keys: [],

redisinsight/api/src/modules/browser/keys/scanner/strategies/cluster.scanner.strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class ClusterScannerStrategy extends ScannerStrategy {
108108
public async getKeys(client: RedisClient, args: IScannerGetKeysArgs): Promise<GetKeysWithDetailsResponse[]> {
109109
const match = args.match !== undefined ? args.match : '*';
110110
const count = args.count || REDIS_SCAN_CONFIG.countDefault;
111-
const scanThreshold = args.countThreshold || REDIS_SCAN_CONFIG.countThreshold;
111+
const scanThreshold = args.scanThreshold || REDIS_SCAN_CONFIG.scanThreshold;
112112
const nodes = await this.getNodesToScan(client, args.cursor);
113113

114114
await this.calculateNodesTotalKeys(nodes);

redisinsight/api/src/modules/browser/keys/scanner/strategies/standalone.scanner.strategy.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ describe('StandaloneScannerStrategy', () => {
5555
});
5656

5757
describe('getKeys', () => {
58-
const getKeysDto: GetKeysDto = { cursor: '0', count: 15, keysInfo: true, countThreshold: 1000 };
58+
const getKeysDto: GetKeysDto = {
59+
cursor: '0', count: 15, keysInfo: true, scanThreshold: 1000,
60+
};
5961
it('should return appropriate value with filter by type', async () => {
6062
const args = { ...getKeysDto, type: RedisDataType.String, match: 'pattern*' };
6163
jest.spyOn(Utils, 'getTotalKeys').mockResolvedValue(mockGetTotalResponse1);
@@ -212,7 +214,7 @@ describe('StandaloneScannerStrategy', () => {
212214
cursor: 1,
213215
total: 1000000,
214216
scanned:
215-
Math.trunc(getKeysDto.countThreshold / getKeysDto.count)
217+
Math.trunc(getKeysDto.scanThreshold / getKeysDto.count)
216218
* getKeysDto.count
217219
+ getKeysDto.count,
218220
keys: [],
@@ -237,7 +239,7 @@ describe('StandaloneScannerStrategy', () => {
237239
cursor: 1,
238240
total: null,
239241
scanned:
240-
Math.trunc(getKeysDto.countThreshold / getKeysDto.count)
242+
Math.trunc(getKeysDto.scanThreshold / getKeysDto.count)
241243
* getKeysDto.count
242244
+ getKeysDto.count,
243245
keys: [],
@@ -254,7 +256,7 @@ describe('StandaloneScannerStrategy', () => {
254256
const result = await strategy.getKeys(mockStandaloneRedisClient, {
255257
cursor: '0',
256258
type: RedisDataType.String,
257-
countThreshold: 1000,
259+
scanThreshold: 1000,
258260
});
259261

260262
expect(strategy['scan']).toHaveBeenLastCalledWith(

redisinsight/api/src/modules/browser/keys/scanner/strategies/standalone.scanner.strategy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export class StandaloneScannerStrategy extends ScannerStrategy {
111111
public async getKeys(client: RedisClient, args: IScannerGetKeysArgs): Promise<GetKeysWithDetailsResponse[]> {
112112
const match = args.match !== undefined ? args.match : '*';
113113
const count = args.count || REDIS_SCAN_CONFIG.countDefault;
114+
const scanThreshold = args.scanThreshold || REDIS_SCAN_CONFIG.scanThreshold;
114115

115116
const node = {
116117
total: 0,
@@ -138,7 +139,7 @@ export class StandaloneScannerStrategy extends ScannerStrategy {
138139
return [node];
139140
}
140141

141-
await this.scan(client, node, match, count, args.countThreshold, args.type);
142+
await this.scan(client, node, match, count, scanThreshold, args.type);
142143

143144
if (node.keys.length && args.keysInfo) {
144145
node.keys = await this.getKeysInfo(client, node.keys, args.type);

0 commit comments

Comments
 (0)