File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -864,6 +864,7 @@ class Cluster extends Commander {
864
864
port : items [ j ] [ 1 ] ,
865
865
} ) ;
866
866
node . readOnly = j !== 2 ;
867
+ node . nodeId = items [ j ] [ 2 ] ;
867
868
nodes . push ( node ) ;
868
869
keys . push ( node . host + ":" + node . port ) ;
869
870
}
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export interface RedisOptions {
10
10
host : string ;
11
11
username ?: string ;
12
12
password ?: string ;
13
+ nodeId ?: string ;
13
14
[ key : string ] : any ;
14
15
}
15
16
@@ -25,17 +26,25 @@ export interface GroupedSrvRecords {
25
26
export function getNodeKey ( node : RedisOptions ) : NodeKey {
26
27
node . port = node . port || 6379 ;
27
28
node . host = node . host || "127.0.0.1" ;
28
- return node . host + ":" + node . port ;
29
+ node . nodeId = node . nodeId || '0'
30
+ return node . host + ":" + node . port + ":" + node . nodeId ;
29
31
}
30
32
31
33
export function nodeKeyToRedisOptions ( nodeKey : NodeKey ) : RedisOptions {
32
- const portIndex = nodeKey . lastIndexOf ( ":" ) ;
33
- if ( portIndex === - 1 ) {
34
+ const idIndex = nodeKey . lastIndexOf ( ":" ) ;
35
+ if ( idIndex === - 1 ) {
34
36
throw new Error ( `Invalid node key ${ nodeKey } ` ) ;
35
37
}
38
+
39
+ const parts = nodeKey . split ( ':' ) ;
40
+ if ( parts . length < 3 ) {
41
+ throw new Error ( `Invalid node key ${ nodeKey } ` ) ;
42
+ }
43
+
36
44
return {
37
- host : nodeKey . slice ( 0 , portIndex ) ,
38
- port : Number ( nodeKey . slice ( portIndex + 1 ) ) ,
45
+ host : parts . slice ( 0 , - 2 ) . join ( ':' ) ,
46
+ port : Number ( parts [ parts . length - 2 ] ) ,
47
+ nodeId : parts [ parts . length - 1 ] ,
39
48
} ;
40
49
}
41
50
You can’t perform that action at this time.
0 commit comments