Skip to content

Commit bd50200

Browse files
Merge pull request #4290 from RedisInsight/fe-be/feature/RI-6336-allow-to-hide-show-columns-in-browser
RI-6336 Allow to hide show columns in browser
2 parents 57e87a7 + 3548135 commit bd50200

File tree

62 files changed

+2766
-1034
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2766
-1034
lines changed

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ import { IsRedisString, RedisStringType } from 'src/common/decorators';
44
import { RedisString } from 'src/common/constants';
55
import { KeyDto, RedisDataType } from './key.dto';
66

7-
export class GetKeyInfoDto extends KeyDto {}
7+
export class GetKeyInfoDto extends KeyDto {
8+
@ApiPropertyOptional({
9+
description: 'Flag to determine if size should be requested and shown in the response',
10+
type: Boolean,
11+
default: false,
12+
})
13+
@IsOptional()
14+
includeSize?: boolean;
15+
}
816

917
export class GetKeysInfoDto {
1018
@ApiProperty({
@@ -31,4 +39,20 @@ export class GetKeysInfoDto {
3139
})
3240
@IsOptional()
3341
type?: RedisDataType;
34-
}
42+
43+
@ApiPropertyOptional({
44+
description: 'Flag to determine if keys should be requested and shown in the response',
45+
type: Boolean,
46+
default: true,
47+
})
48+
@IsOptional()
49+
includeSize?: boolean;
50+
51+
@ApiPropertyOptional({
52+
description: 'Flag to determine if TTL should be requested and shown in the response',
53+
type: Boolean,
54+
default: true,
55+
})
56+
@IsOptional()
57+
includeTTL?: boolean;
58+
}

redisinsight/api/src/modules/browser/keys/key-info/strategies/hash.key-info.strategy.spec.ts

Lines changed: 113 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -34,52 +34,120 @@ describe('HashKeyInfoStrategy', () => {
3434

3535
describe('getInfo', () => {
3636
const key = getKeyInfoResponse.name;
37-
it('should return appropriate value', async () => {
38-
when(mockStandaloneRedisClient.sendPipeline)
39-
.calledWith([
40-
[BrowserToolKeysCommands.Ttl, key],
41-
[BrowserToolKeysCommands.MemoryUsage, key, 'samples', '0'],
42-
[BrowserToolHashCommands.HLen, key],
43-
])
44-
.mockResolvedValue([
45-
[null, -1],
46-
[null, 50],
47-
[null, 10],
48-
]);
49-
50-
const result = await strategy.getInfo(
51-
mockStandaloneRedisClient,
52-
key,
53-
RedisDataType.Hash,
54-
);
55-
56-
expect(result).toEqual(getKeyInfoResponse);
37+
38+
describe('when includeSize is true', () => {
39+
it('should return all info in single pipeline', async () => {
40+
when(mockStandaloneRedisClient.sendPipeline)
41+
.calledWith([
42+
[BrowserToolKeysCommands.Ttl, key],
43+
[BrowserToolHashCommands.HLen, key],
44+
[BrowserToolKeysCommands.MemoryUsage, key, 'samples', '0'],
45+
])
46+
.mockResolvedValueOnce([
47+
[null, -1],
48+
[null, 10],
49+
[null, 50],
50+
]);
51+
52+
const result = await strategy.getInfo(
53+
mockStandaloneRedisClient,
54+
key,
55+
RedisDataType.Hash,
56+
true,
57+
);
58+
59+
expect(result).toEqual(getKeyInfoResponse);
60+
});
5761
});
58-
it('should return size with null value', async () => {
59-
const replyError: ReplyError = {
60-
name: 'ReplyError',
61-
command: BrowserToolKeysCommands.MemoryUsage,
62-
message: "ERR unknown command 'memory'",
63-
};
64-
when(mockStandaloneRedisClient.sendPipeline)
65-
.calledWith([
66-
[BrowserToolKeysCommands.Ttl, key],
67-
[BrowserToolKeysCommands.MemoryUsage, key, 'samples', '0'],
68-
[BrowserToolHashCommands.HLen, key],
69-
])
70-
.mockResolvedValue([
71-
[null, -1],
72-
[replyError, null],
73-
[null, 10],
74-
]);
75-
76-
const result = await strategy.getInfo(
77-
mockStandaloneRedisClient,
78-
key,
79-
RedisDataType.Hash,
80-
);
81-
82-
expect(result).toEqual({ ...getKeyInfoResponse, size: null });
62+
63+
describe('when includeSize is false', () => {
64+
it('should return appropriate value', async () => {
65+
when(mockStandaloneRedisClient.sendPipeline)
66+
.calledWith([
67+
[BrowserToolKeysCommands.Ttl, key],
68+
[BrowserToolHashCommands.HLen, key],
69+
])
70+
.mockResolvedValueOnce([
71+
[null, -1],
72+
[null, 10],
73+
]);
74+
75+
when(mockStandaloneRedisClient.sendPipeline)
76+
.calledWith([
77+
[BrowserToolKeysCommands.MemoryUsage, key, 'samples', '0'],
78+
])
79+
.mockResolvedValueOnce([
80+
[null, 50],
81+
]);
82+
83+
const result = await strategy.getInfo(
84+
mockStandaloneRedisClient,
85+
key,
86+
RedisDataType.Hash,
87+
false,
88+
);
89+
90+
expect(result).toEqual(getKeyInfoResponse);
91+
});
92+
93+
it('should return size with null value when memory usage fails', async () => {
94+
const replyError: ReplyError = {
95+
name: 'ReplyError',
96+
command: BrowserToolKeysCommands.MemoryUsage,
97+
message: "ERR unknown command 'memory'",
98+
};
99+
when(mockStandaloneRedisClient.sendPipeline)
100+
.calledWith([
101+
[BrowserToolKeysCommands.Ttl, key],
102+
[BrowserToolHashCommands.HLen, key],
103+
])
104+
.mockResolvedValueOnce([
105+
[null, -1],
106+
[null, 10],
107+
]);
108+
109+
when(mockStandaloneRedisClient.sendPipeline)
110+
.calledWith([
111+
[BrowserToolKeysCommands.MemoryUsage, key, 'samples', '0'],
112+
])
113+
.mockResolvedValueOnce([
114+
[replyError, null],
115+
]);
116+
117+
const result = await strategy.getInfo(
118+
mockStandaloneRedisClient,
119+
key,
120+
RedisDataType.Hash,
121+
false,
122+
);
123+
124+
expect(result).toEqual({ ...getKeyInfoResponse, size: null });
125+
});
126+
127+
it('should not check size when length >= 50,000', async () => {
128+
when(mockStandaloneRedisClient.sendPipeline)
129+
.calledWith([
130+
[BrowserToolKeysCommands.Ttl, key],
131+
[BrowserToolHashCommands.HLen, key],
132+
])
133+
.mockResolvedValueOnce([
134+
[null, -1],
135+
[null, 50000],
136+
]);
137+
138+
const result = await strategy.getInfo(
139+
mockStandaloneRedisClient,
140+
key,
141+
RedisDataType.Hash,
142+
false,
143+
);
144+
145+
expect(result).toEqual({
146+
...getKeyInfoResponse,
147+
length: 50000,
148+
size: -1
149+
});
150+
});
83151
});
84152
});
85153
});

redisinsight/api/src/modules/browser/keys/key-info/strategies/hash.key-info.strategy.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,53 @@ export class HashKeyInfoStrategy extends KeyInfoStrategy {
1212
client: RedisClient,
1313
key: RedisString,
1414
type: string,
15+
includeSize: boolean,
1516
): Promise<GetKeyInfoResponse> {
1617
this.logger.debug(`Getting ${RedisDataType.Hash} type info.`);
1718

19+
if (includeSize !== false) {
20+
const [
21+
[, ttl = null],
22+
[, length = null],
23+
[, size = null],
24+
] = await client.sendPipeline([
25+
[BrowserToolKeysCommands.Ttl, key],
26+
[BrowserToolHashCommands.HLen, key],
27+
[BrowserToolKeysCommands.MemoryUsage, key, 'samples', '0'],
28+
]) as [any, number][];
29+
30+
return {
31+
name: key,
32+
type,
33+
ttl,
34+
size,
35+
length,
36+
};
37+
}
38+
1839
const [
1940
[, ttl = null],
20-
[, size = null],
2141
[, length = null],
2242
] = await client.sendPipeline([
2343
[BrowserToolKeysCommands.Ttl, key],
24-
[BrowserToolKeysCommands.MemoryUsage, key, 'samples', '0'],
2544
[BrowserToolHashCommands.HLen, key],
2645
]) as [any, number][];
2746

47+
let size = -1;
48+
if (length < 50_000) {
49+
const sizeData = await client.sendPipeline([
50+
[BrowserToolKeysCommands.MemoryUsage, key, 'samples', '0'],
51+
]) as [any, number][];
52+
size = sizeData && sizeData[0] && sizeData[0][1];
53+
}
54+
2855
return {
2956
name: key,
3057
type,
3158
ttl,
3259
size,
3360
length,
3461
};
62+
3563
}
3664
}

redisinsight/api/src/modules/browser/keys/key-info/strategies/key-info.strategy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ export abstract class KeyInfoStrategy {
1111
client: RedisClient,
1212
key: RedisString,
1313
type: string,
14+
includeSize: boolean,
1415
): Promise<GetKeyInfoResponse>;
1516
}

0 commit comments

Comments
 (0)