Skip to content

Commit e88374f

Browse files
update isRedisstack (#2192)
* update isRedisstack
1 parent 46fbb77 commit e88374f

File tree

4 files changed

+93
-95
lines changed

4 files changed

+93
-95
lines changed

redisinsight/ui/src/pages/home/components/AddInstanceForm/InstanceForm/InstanceForm.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030

3131
import { ConnectionType, InstanceType, } from 'uiSrc/slices/interfaces'
3232
import { getRedisModulesSummary, sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
33-
import { getDiffKeysOfObjectValues, checkRediStackModules } from 'uiSrc/utils'
33+
import { getDiffKeysOfObjectValues, isRediStack } from 'uiSrc/utils'
3434
import { BuildType } from 'uiSrc/constants/env'
3535

3636
import {
@@ -129,6 +129,7 @@ const AddStandaloneForm = (props: Props) => {
129129
ssh,
130130
sshPassType = SshPassType.Password,
131131
sshOptions,
132+
version,
132133
},
133134
initialValues: initialValuesProp,
134135
width,
@@ -510,7 +511,7 @@ const AddStandaloneForm = (props: Props) => {
510511
{isEditMode && name && (
511512
<div className="fluid" style={{ marginBottom: 15 }}>
512513
<DatabaseAlias
513-
isRediStack={checkRediStackModules(modules)}
514+
isRediStack={isRediStack(modules, version)}
514515
isCloneMode={isCloneMode}
515516
alias={name}
516517
database={db}

redisinsight/ui/src/slices/interfaces/instances.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface Instance extends DatabaseInstanceResponse {
4747
isDeleting?: boolean
4848
sentinelMaster?: SentinelMaster
4949
modules: AdditionalRedisModule[]
50+
version: Nullable<string>
5051
isRediStack?: boolean
5152
visible?: boolean
5253
loading?: boolean
Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,75 @@
1-
import { isArray, map } from 'lodash'
1+
import { isArray, map, concat } from 'lodash'
22
import { Instance, RedisDefaultModules } from 'uiSrc/slices/interfaces'
3+
import { isVersionHigherOrEquals, Nullable } from 'uiSrc/utils'
34

4-
export const REDISTACK_PORT = 6379
5-
export const REDISTACK_MODULES: Array<string | Array<string>> = [
5+
const REDISTACK_LOW_VERSION = '6.2.6'
6+
const REDISTACK_HIGH_VERSION = '7.2'
7+
8+
const REDISTACK_LOW_VERSION_REQUIRE_MODULES: Array<string | Array<string>> = [
69
RedisDefaultModules.ReJSON,
710
RedisDefaultModules.Bloom,
811
RedisDefaultModules.Graph,
912
[RedisDefaultModules.Search, RedisDefaultModules.SearchLight],
1013
RedisDefaultModules.TimeSeries,
1114
]
1215

13-
const checkRediStackModules = (modules: any[]) => {
14-
if (!modules?.length || modules.length !== REDISTACK_MODULES.length) return false
16+
const REDISTACK_HIGH_VERSION_REQUIRE_MODULES: Array<string | Array<string>> = [
17+
RedisDefaultModules.ReJSON,
18+
RedisDefaultModules.Bloom,
19+
[RedisDefaultModules.Search, RedisDefaultModules.SearchLight],
20+
RedisDefaultModules.TimeSeries,
21+
]
22+
23+
const REDISTACK_HIGH_VERSION_OPTIONAL_MODULES: Array<string> = [
24+
RedisDefaultModules.Gears,
25+
]
26+
27+
const checkRediStackModules = (modules: any[], required: any[], optional: any[] = []) => {
28+
if (!modules?.length) return false
1529

16-
return map(modules, 'name')
17-
.sort()
18-
.every((m, index) => (isArray(REDISTACK_MODULES[index])
19-
? (REDISTACK_MODULES[index] as Array<string>).some((rm) => rm === m)
20-
: REDISTACK_MODULES[index] === m))
30+
if (modules.length === required.length) {
31+
return map(modules, 'name')
32+
.sort()
33+
.every((m, index) => (isArray(required[index])
34+
? (required[index] as Array<string>).some((rm) => rm === m)
35+
: required[index] === m))
36+
}
37+
38+
if (modules.length === (required.length + optional.length)) {
39+
const rediStackModules = concat(required, optional).sort()
40+
return map(modules, 'name')
41+
.sort()
42+
.every((m, index) => (isArray(rediStackModules[index])
43+
? (rediStackModules[index] as Array<string>).some((rm) => rm === m)
44+
: rediStackModules[index] === m))
45+
}
46+
47+
return false
2148
}
2249

23-
const checkRediStack = (instances: Instance[]): Instance[] => {
24-
let isRediStackCheck = false
25-
26-
let newInstances = instances.map((instance) => {
27-
const isRediStack = +instance.port === REDISTACK_PORT && checkRediStackModules(instance.modules)
28-
29-
isRediStackCheck = isRediStackCheck || isRediStack
30-
return {
31-
...instance,
32-
isRediStack
33-
}
34-
})
35-
36-
// if no any database with redistack on port 6379 - mark others as redistack (with modules check)
37-
if (!isRediStackCheck) {
38-
newInstances = newInstances.map((instance) => ({
39-
...instance,
40-
isRediStack: checkRediStackModules(instance.modules)
41-
}))
50+
const isRediStack = (modules: any[], version?: Nullable<string>): boolean => {
51+
if (!version) {
52+
return checkRediStackModules(modules, REDISTACK_LOW_VERSION_REQUIRE_MODULES)
4253
}
4354

44-
return newInstances
55+
if (isVersionHigherOrEquals(version, REDISTACK_HIGH_VERSION)) {
56+
return checkRediStackModules(
57+
modules,
58+
REDISTACK_HIGH_VERSION_REQUIRE_MODULES,
59+
REDISTACK_HIGH_VERSION_OPTIONAL_MODULES
60+
)
61+
}
62+
63+
if (isVersionHigherOrEquals(version, REDISTACK_LOW_VERSION)) {
64+
return checkRediStackModules(modules, REDISTACK_LOW_VERSION_REQUIRE_MODULES)
65+
}
66+
67+
return false
4568
}
4669

47-
export { checkRediStack, checkRediStackModules }
70+
const checkRediStack = (instances: Instance[]): Instance[] => (instances.map((instance) => ({
71+
...instance,
72+
isRediStack: isRediStack(instance.modules)
73+
})))
74+
75+
export { checkRediStack, isRediStack }
Lines changed: 30 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,37 @@
11
/* eslint-disable max-len */
2-
import { checkRediStack, REDISTACK_PORT } from 'uiSrc/utils'
3-
import { RedisDefaultModules } from 'uiSrc/slices/interfaces'
2+
import { isRediStack } from 'uiSrc/utils'
43

54
const unmapWithName = (arr: any[]) => arr.map((item) => ({ name: item }))
65

7-
const REDISTACK_MODULE_DEFAULT = unmapWithName([
8-
RedisDefaultModules.ReJSON,
9-
RedisDefaultModules.Graph,
10-
RedisDefaultModules.TimeSeries,
11-
RedisDefaultModules.Search,
12-
RedisDefaultModules.Bloom,
13-
].sort())
14-
15-
const getOutputCheckRediStackTests: any[] = [
16-
[
17-
[{ port: REDISTACK_PORT, modules: REDISTACK_MODULE_DEFAULT }, { port: 12000, modules: REDISTACK_MODULE_DEFAULT }],
18-
[{ port: REDISTACK_PORT, modules: REDISTACK_MODULE_DEFAULT, isRediStack: true }, { port: 12000, modules: REDISTACK_MODULE_DEFAULT, isRediStack: false }]
19-
],
20-
[
21-
[{ port: REDISTACK_PORT, modules: REDISTACK_MODULE_DEFAULT }],
22-
[{ port: REDISTACK_PORT, modules: REDISTACK_MODULE_DEFAULT, isRediStack: true }]
23-
],
24-
[
25-
[{ port: REDISTACK_PORT, modules: unmapWithName(['']) }],
26-
[{ port: REDISTACK_PORT, modules: unmapWithName(['']), isRediStack: false }]
27-
],
28-
[
29-
[{ port: REDISTACK_PORT, modules: unmapWithName(['search']) }],
30-
[{ port: REDISTACK_PORT, modules: unmapWithName(['search']), isRediStack: false }]
31-
],
32-
[
33-
[{ port: REDISTACK_PORT, modules: unmapWithName(['bf', 'search', 'timeseries']) }],
34-
[{ port: REDISTACK_PORT, modules: unmapWithName(['bf', 'search', 'timeseries']), isRediStack: false }]
35-
],
36-
[
37-
[{ port: 12000, modules: REDISTACK_MODULE_DEFAULT }],
38-
[{ port: 12000, modules: REDISTACK_MODULE_DEFAULT, isRediStack: true }]
39-
],
40-
[
41-
[{ port: 12000, modules: unmapWithName(['search']) }],
42-
[{ port: 12000, modules: unmapWithName(['search']), isRediStack: false }]
43-
],
44-
// check searchlight - should be also marked as RediStack
45-
[
46-
[{ port: 12000, modules: unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph']) }],
47-
[{ port: 12000, modules: unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph']), isRediStack: true }]
48-
],
49-
[
50-
[{ port: 12000, modules: [] }],
51-
[{ port: 12000, modules: [], isRediStack: false }]
52-
],
53-
[
54-
[{ port: 12000, modules: unmapWithName(['ReJSON']) }],
55-
[{ port: 12000, modules: unmapWithName(['ReJSON']), isRediStack: false }]
56-
],
57-
[
58-
[{ port: 12000, modules: unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph', 'custom']) }],
59-
[{ port: 12000, modules: unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph', 'custom']), isRediStack: false }]
60-
],
6+
const isRediStackTests = [
7+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph', 'custom']), '6.2.6'], expected: false },
8+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'graph', 'custom']), '6.2.6'], expected: false },
9+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph']), '6.2.6'], expected: true },
10+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph'])], expected: true },
11+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph']), null], expected: true },
12+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search']), null], expected: false },
13+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'rg', 'search'])], expected: false },
14+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'graph']), '6.2.6'], expected: true },
15+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph']), '6.2.5'], expected: false },
16+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'graph']), '6.2.5'], expected: false },
17+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight', 'graph']), '7.2'], expected: false },
18+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'graph']), '7.2'], expected: false },
19+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'rg', 'searchlight']), '7.2'], expected: true },
20+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'rg', 'search']), '7.2'], expected: true },
21+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'searchlight']), '7.2'], expected: true },
22+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search']), '7.2'], expected: true },
23+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search']), '7.2'], expected: true },
24+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'search', 'custom']), '7.2'], expected: false },
25+
{ input: [unmapWithName(['bf', 'timeseries', 'ReJSON', 'seasearchlightrch', 'custom']), '7.2'], expected: false },
6126
]
6227

63-
describe('checkRediStack', () => {
64-
it.each(getOutputCheckRediStackTests)('for input: %s (reply), should be output: %s',
65-
(reply, expected) => {
66-
const result = checkRediStack(reply)
67-
expect(result).toStrictEqual(expected)
68-
})
28+
describe('isRediStack', () => {
29+
test.each(isRediStackTests)(
30+
'%j',
31+
({ input, expected }) => {
32+
// @ts-ignore
33+
const result = isRediStack(...input)
34+
expect(result).toEqual(expected)
35+
}
36+
)
6937
})

0 commit comments

Comments
 (0)