Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ export class ClusterScannerStrategy extends ScannerStrategy {
options: {
host,
port,
natHost,
natPort,
},
}) => host === node.host && port === node.port,
}) => (
host === node.host && port === node.port
) || (
natHost === node.host && natPort === node.port
),
);
});

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

return nodesClients.map((node) => ({
node,
host: node.options.host,
port: node.options.port,
host: node.options.natHost || node.options.host,
port: node.options.natPort || node.options.port,
cursor: 0,
keys: [],
total: 0,
Expand Down
7 changes: 4 additions & 3 deletions redisinsight/api/src/modules/browser/utils/clusterCursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { IScannerNodeKeys } from 'src/modules/browser/keys/scanner/scanner.inter

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

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

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

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

// ignore nodes with cursor -1 (fully scanned)
if (parseInt(nextCursor, 10) >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export class ExportDatabase extends PickType(Database, [
'provider',
'lastConnection',
'sentinelMaster',
'nodes',
'modules',
'tls',
'tlsServername',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ export abstract class IoredisClient extends RedisClient {
*/
async monitor(): Promise<any> {
if (this.client instanceof Redis) {
return this.client.monitor();
const monitorClient = this.client.monitor();
this.client.disconnect();
return monitorClient;
}

return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,29 @@ export abstract class RedisConnectionStrategy {
*/
static generateRedisConnectionName(clientMetadata: ClientMetadata) {
try {
return [
const items = [
CONNECTION_NAME_GLOBAL_PREFIX,
clientMetadata?.context || 'custom',
clientMetadata?.databaseId?.substring(0, 8),
clientMetadata?.db >= 0 ? clientMetadata.db : '',
clientMetadata?.uniqueId?.substring(0, 4) || '',
clientMetadata?.sessionMetadata?.userId?.substring(0, 4) || '',
clientMetadata?.sessionMetadata?.sessionId?.substring(0, 4) || '',
clientMetadata?.sessionMetadata?.uniqueId?.substring(0, 4) || '',
].join('-').toLowerCase();
];

if (clientMetadata?.uniqueId) {
items.push(clientMetadata?.uniqueId?.substring(0, 4));
}

return items.join('-').toLowerCase();

// todo: enhance client name generation based on code below
// return [
// CONNECTION_NAME_GLOBAL_PREFIX,
// clientMetadata?.context || 'custom',
// clientMetadata?.databaseId?.substring(0, 8),
// clientMetadata?.db >= 0 ? clientMetadata.db : '',
// clientMetadata?.uniqueId?.substring(0, 4) || '',
// clientMetadata?.sessionMetadata?.userId?.substring(0, 4) || '',
// clientMetadata?.sessionMetadata?.sessionId?.substring(0, 4) || '',
// clientMetadata?.sessionMetadata?.uniqueId?.substring(0, 4) || '',
// ].join('-').toLowerCase();
} catch (e) {
return CONNECTION_NAME_GLOBAL_PREFIX;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ const responseSchema = Joi.array().items(Joi.object().keys({
version: Joi.number().integer().required(),
semanticVersion: Joi.string(),
})).min(0).required(),
nodes: Joi.array().items(Joi.object().keys({
host: Joi.string().required(),
port: Joi.number().integer().required(),
})).min(0).required(),
verifyServerCert: Joi.boolean().allow(null),
sentinelMaster: Joi.object({
name: Joi.string().required(),
Expand Down