Skip to content

Commit dd00d7a

Browse files
author
Artem
committed
#RI-3926 workaround for pika db when there is no keys displayed due to dbsize = 0
1 parent 336ee27 commit dd00d7a

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,17 @@ describe('Standalone Scanner Strategy', () => {
229229
]);
230230
expect(strategy.getKeysInfo).toHaveBeenCalledTimes(0);
231231
});
232-
it('should not call scan when total is 0', async () => {
233-
jest.spyOn(Utils, 'getTotal').mockResolvedValue(mockGetTotalResponse_3);
232+
it('should call scan N times until threshold exceeds (even when total 0)', async () => {
233+
jest.spyOn(Utils, 'getTotal').mockResolvedValue(0);
234+
235+
when(browserTool.execCommand)
236+
.calledWith(
237+
mockBrowserClientMetadata,
238+
BrowserToolKeysCommands.Scan,
239+
expect.anything(),
240+
null,
241+
)
242+
.mockResolvedValue(['1', []]);
234243

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

@@ -239,10 +248,16 @@ describe('Standalone Scanner Strategy', () => {
239248
expect(result).toEqual([
240249
{
241250
...mockNodeEmptyResult,
251+
cursor: 1,
252+
total: null,
253+
scanned:
254+
Math.trunc(REDIS_SCAN_CONFIG.countThreshold / getKeysDto.count)
255+
* getKeysDto.count
256+
+ getKeysDto.count,
257+
keys: [],
242258
},
243259
]);
244-
expect(browserTool.execCommand).toBeCalledTimes(0);
245-
expect(strategy.getKeysInfo).toBeCalledTimes(0);
260+
expect(strategy.getKeysInfo).toHaveBeenCalledTimes(0);
246261
});
247262
it('should call scan with required args', async () => {
248263
jest.spyOn(Utils, 'getTotal').mockResolvedValue(mockGetTotalResponse_3);

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export class StandaloneStrategy extends AbstractStrategy {
7272
node.keys = node.keys.map((name) => ({ name }));
7373
}
7474

75+
// workaround for "pika" databases
76+
if (!node.total && (node.cursor > 0 || node.keys?.length)) {
77+
node.total = null;
78+
}
79+
7580
return [node];
7681
}
7782

@@ -86,12 +91,11 @@ export class StandaloneStrategy extends AbstractStrategy {
8691
// todo: remove settings from here. threshold should be part of query?
8792
const settings = await this.settingsService.getAppSettings('1');
8893
while (
89-
(node.total > 0 || isNull(node.total))
94+
(node.total >= 0 || isNull(node.total))
9095
&& !fullScanned
9196
&& node.keys.length < count
9297
&& (
93-
(node.total < settings.scanThreshold && node.cursor)
94-
|| node.scanned < settings.scanThreshold
98+
node.scanned < settings.scanThreshold
9599
)
96100
) {
97101
let commandArgs = [`${node.cursor}`, 'MATCH', match, 'COUNT', count];

0 commit comments

Comments
 (0)