Skip to content

Commit 7730ef7

Browse files
author
Artem
authored
Merge pull request #3059 from RedisInsight/be/feature/RI-4643-move-to-node-redis-bugfixing
Be/feature/ri 4643 move to node redis bugfixing
2 parents cc22a1f + 3aa065b commit 7730ef7

File tree

6 files changed

+36
-19
lines changed

6 files changed

+36
-19
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,14 @@ export class ClusterScannerStrategy extends ScannerStrategy {
3131
options: {
3232
host,
3333
port,
34+
natHost,
35+
natPort,
3436
},
35-
}) => host === node.host && port === node.port,
37+
}) => (
38+
host === node.host && port === node.port
39+
) || (
40+
natHost === node.host && natPort === node.port
41+
),
3642
);
3743
});
3844

@@ -41,8 +47,8 @@ export class ClusterScannerStrategy extends ScannerStrategy {
4147

4248
return nodesClients.map((node) => ({
4349
node,
44-
host: node.options.host,
45-
port: node.options.port,
50+
host: node.options.natHost || node.options.host,
51+
port: node.options.natPort || node.options.port,
4652
cursor: 0,
4753
keys: [],
4854
total: 0,

redisinsight/api/src/modules/browser/utils/clusterCursor.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { IScannerNodeKeys } from 'src/modules/browser/keys/scanner/scanner.inter
33

44
const NODES_SEPARATOR = '||';
55
const CURSOR_SEPARATOR = '@';
6-
// Correct format 172.17.0.1:7001@-1||172.17.0.1:7002@33
7-
const CLUSTER_CURSOR_REGEX = /^(([a-z0-9.-])+:[0-9]+(@-?\d+)(?:\|{2}(?!$)|$))+$/;
6+
// Correct format 172.17.0.1:7001@-1||172.17.0.1:7002@33||:::4554@1423
7+
const CLUSTER_CURSOR_REGEX = /^(([a-z0-9.:-])+:[0-9]+(@-?\d+)(?:\|{2}(?!$)|$))+$/;
88

99
export const isClusterCursorValid = (cursor: string) => CLUSTER_CURSOR_REGEX.test(cursor);
1010

1111
/**
1212
* Parses composed custom cursor from FE and returns nodes
1313
* Format: 172.17.0.1:7001@22||172.17.0.1:7002@33
14+
* Also ipv6 is supported :::6379@22:::7001@33
1415
*/
1516
export const parseClusterCursor = (cursor: string): IScannerNodeKeys[] => {
1617
if (!isClusterCursorValid(cursor)) {
@@ -21,7 +22,7 @@ export const parseClusterCursor = (cursor: string): IScannerNodeKeys[] => {
2122

2223
nodeStrings.forEach((item: string) => {
2324
const [address, nextCursor] = item.split(CURSOR_SEPARATOR);
24-
const [host, port] = address.split(':');
25+
const [, host, port] = address.match(/(.+):(\d+)$/);
2526

2627
// ignore nodes with cursor -1 (fully scanned)
2728
if (parseInt(nextCursor, 10) >= 0) {

redisinsight/api/src/modules/database/models/export-database.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export class ExportDatabase extends PickType(Database, [
1414
'provider',
1515
'lastConnection',
1616
'sentinelMaster',
17-
'nodes',
1817
'modules',
1918
'tls',
2019
'tlsServername',

redisinsight/api/src/modules/redis/client/ioredis/ioredis.client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ export abstract class IoredisClient extends RedisClient {
142142
*/
143143
async monitor(): Promise<any> {
144144
if (this.client instanceof Redis) {
145-
return this.client.monitor();
145+
const monitorClient = this.client.monitor();
146+
this.client.disconnect();
147+
return monitorClient;
146148
}
147149

148150
return undefined;

redisinsight/api/src/modules/redis/connection/redis.connection.strategy.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,29 @@ export abstract class RedisConnectionStrategy {
6060
*/
6161
static generateRedisConnectionName(clientMetadata: ClientMetadata) {
6262
try {
63-
return [
63+
const items = [
6464
CONNECTION_NAME_GLOBAL_PREFIX,
6565
clientMetadata?.context || 'custom',
6666
clientMetadata?.databaseId?.substring(0, 8),
67-
clientMetadata?.db >= 0 ? clientMetadata.db : '',
68-
clientMetadata?.uniqueId?.substring(0, 4) || '',
69-
clientMetadata?.sessionMetadata?.userId?.substring(0, 4) || '',
70-
clientMetadata?.sessionMetadata?.sessionId?.substring(0, 4) || '',
71-
clientMetadata?.sessionMetadata?.uniqueId?.substring(0, 4) || '',
72-
].join('-').toLowerCase();
67+
];
68+
69+
if (clientMetadata?.uniqueId) {
70+
items.push(clientMetadata?.uniqueId?.substring(0, 4));
71+
}
72+
73+
return items.join('-').toLowerCase();
74+
75+
// todo: enhance client name generation based on code below
76+
// return [
77+
// CONNECTION_NAME_GLOBAL_PREFIX,
78+
// clientMetadata?.context || 'custom',
79+
// clientMetadata?.databaseId?.substring(0, 8),
80+
// clientMetadata?.db >= 0 ? clientMetadata.db : '',
81+
// clientMetadata?.uniqueId?.substring(0, 4) || '',
82+
// clientMetadata?.sessionMetadata?.userId?.substring(0, 4) || '',
83+
// clientMetadata?.sessionMetadata?.sessionId?.substring(0, 4) || '',
84+
// clientMetadata?.sessionMetadata?.uniqueId?.substring(0, 4) || '',
85+
// ].join('-').toLowerCase();
7386
} catch (e) {
7487
return CONNECTION_NAME_GLOBAL_PREFIX;
7588
}

redisinsight/api/test/api/database/POST-databases-export.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ const responseSchema = Joi.array().items(Joi.object().keys({
2424
version: Joi.number().integer().required(),
2525
semanticVersion: Joi.string(),
2626
})).min(0).required(),
27-
nodes: Joi.array().items(Joi.object().keys({
28-
host: Joi.string().required(),
29-
port: Joi.number().integer().required(),
30-
})).min(0).required(),
3127
verifyServerCert: Joi.boolean().allow(null),
3228
sentinelMaster: Joi.object({
3329
name: Joi.string().required(),

0 commit comments

Comments
 (0)