Skip to content

Commit 92718d5

Browse files
committed
RI-6336 - added cluster strategy implementation. Fixed integration tests
1 parent a8c439d commit 92718d5

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

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

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class ClusterScannerStrategy extends ScannerStrategy {
121121
// eslint-disable-next-line no-param-reassign
122122
node.scanned = isNull(node.total) ? 1 : node.total;
123123
});
124-
nodes[0].keys = await this.getKeysInfo(client, [keyName]);
124+
nodes[0].keys = await this.getKeysInfo(client, [keyName], undefined, true, true);
125125
nodes[0].keys = nodes[0].keys.filter((key: GetKeyInfoResponse) => {
126126
if (key.ttl === -2) {
127127
return false;
@@ -159,6 +159,8 @@ export class ClusterScannerStrategy extends ScannerStrategy {
159159
node.node,
160160
node.keys,
161161
args.type,
162+
true,
163+
true
162164
);
163165
} else {
164166
// eslint-disable-next-line no-param-reassign
@@ -180,34 +182,44 @@ export class ClusterScannerStrategy extends ScannerStrategy {
180182
client: RedisClient,
181183
keys: RedisString[],
182184
filterType?: RedisDataType,
185+
getSize?: boolean,
186+
getTtl?: boolean
183187
): Promise<GetKeyInfoResponse[]> {
184188
return Promise.all(keys.map(async (key) => {
185-
const commands: RedisClientCommand[] = [
186-
[BrowserToolKeysCommands.Ttl, key],
187-
['memory', 'usage', key, 'samples', '0'],
188-
];
189+
const commands: RedisClientCommand[] = [];
190+
const responseMap = {
191+
ttl: null,
192+
size: null,
193+
type: null
194+
}
195+
196+
if (getTtl) {
197+
responseMap.ttl = commands.length
198+
commands.push([BrowserToolKeysCommands.Ttl, key]);
199+
}
200+
201+
if (getSize) {
202+
responseMap.size = commands.length
203+
commands.push(['memory', 'usage', key, 'samples', '0']);
204+
}
189205

190206
if (!filterType) {
207+
responseMap.type = commands.length
191208
commands.push([BrowserToolKeysCommands.Type, key]);
192209
}
193210

194211
const result = await client.sendPipeline(commands, { replyEncoding: 'utf8' }) as any[];
195212

196213
if (filterType) {
214+
responseMap.type = commands.length
197215
result.push([null, filterType]);
198216
}
199217

200-
const [
201-
[, ttl = null],
202-
[, size = null],
203-
[, type = null],
204-
] = result;
205-
206218
return {
207219
name: key,
208-
type,
209-
ttl,
210-
size,
220+
type: result[responseMap.type]?.[1],
221+
ttl: responseMap.ttl !== null ? result[responseMap.ttl][1] : null,
222+
size: responseMap.size !== null ? result[responseMap.size][1] : null,
211223
};
212224
}));
213225
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class StandaloneScannerStrategy extends ScannerStrategy {
126126
const keyName = Buffer.from(unescapeRedisGlob(match));
127127
node.cursor = 0;
128128
node.scanned = isNull(node.total) ? 1 : node.total;
129-
node.keys = await this.getKeysInfo(client, [keyName]);
129+
node.keys = await this.getKeysInfo(client, [keyName], undefined, true, true);
130130
node.keys = node.keys.filter((key: GetKeyInfoResponse) => {
131131
if (key.ttl === -2) {
132132
return false;
@@ -142,7 +142,7 @@ export class StandaloneScannerStrategy extends ScannerStrategy {
142142
await this.scan(client, node, match, count, scanThreshold, args.type);
143143

144144
if (node.keys.length && args.keysInfo) {
145-
node.keys = await this.getKeysInfo(client, node.keys, args.type);
145+
node.keys = await this.getKeysInfo(client, node.keys, args.type, true, true);
146146
} else {
147147
node.keys = node.keys.map((name) => ({ name, type: args.type || undefined }));
148148
}

redisinsight/api/test/api/keys/POST-databases-id-keys.test.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,6 @@ describe('POST /databases/:id/keys', () => {
302302
data: {
303303
cursor: '0',
304304
match: `${constants.TEST_RUN_ID}_str_key_10?`,
305-
getTtl: true,
306-
getSize: true,
307305
},
308306
responseSchema,
309307
checkFn: ({ body }) => {
@@ -337,8 +335,6 @@ describe('POST /databases/:id/keys', () => {
337335
cursor: '0',
338336
match: `${constants.TEST_RUN_ID}_str_key_10?`,
339337
keysInfo: 'false',
340-
getTtl: true,
341-
getSize: true,
342338
},
343339
responseSchema,
344340
checkFn: ({ body }) => {
@@ -592,8 +588,6 @@ describe('POST /databases/:id/keys', () => {
592588
cursor: '0',
593589
type: 'string',
594590
count: 200,
595-
getTtl: true,
596-
getSize: true,
597591
},
598592
responseSchema,
599593
checkFn: ({ body }) => {
@@ -892,8 +886,6 @@ describe('POST /databases/:id/keys', () => {
892886
cursor: '0',
893887
type: 'string',
894888
count: 200,
895-
getTtl: true,
896-
getSize: true,
897889
},
898890
responseSchema,
899891
checkFn: ({ body }) => {
@@ -976,8 +968,6 @@ describe('POST /databases/:id/keys', () => {
976968
data: {
977969
cursor: '0',
978970
count: 200,
979-
getTtl: true,
980-
getSize: true,
981971
},
982972
responseSchema,
983973
checkFn: async ({ body }) => {

0 commit comments

Comments
 (0)