@@ -649,19 +649,15 @@ class RedisSentinelInternal<
649
649
}
650
650
651
651
#createClient( node : RedisNode , clientOptions : RedisClientOptions , reconnectStrategy ?: undefined | false ) {
652
- const options = { ...clientOptions } as RedisClientOptions ;
653
-
654
- if ( clientOptions . socket ) {
655
- options . socket = { ...clientOptions . socket } ;
656
- } else {
657
- options . socket = { } ;
658
- }
659
-
660
- options . socket . host = node . host ;
661
- options . socket . port = node . port ;
662
- options . socket . reconnectStrategy = reconnectStrategy ;
663
-
664
- return RedisClient . create ( options ) ;
652
+ return RedisClient . create ( {
653
+ ...clientOptions ,
654
+ socket : {
655
+ ...clientOptions . socket ,
656
+ host : node . host ,
657
+ port : node . port ,
658
+ reconnectStrategy
659
+ }
660
+ } ) ;
665
661
}
666
662
667
663
getClientLease ( ) : ClientInfo | Promise < ClientInfo > {
@@ -1332,16 +1328,16 @@ export class RedisSentinelFactory extends EventEmitter {
1332
1328
1333
1329
async updateSentinelRootNodes ( ) {
1334
1330
for ( const node of this . #sentinelRootNodes) {
1335
- const options : RedisClientOptions = { ... this . options . sentinelClientOptions } ;
1336
- if ( options . socket === undefined ) {
1337
- options . socket = { } ;
1338
- }
1339
- options . socket . host = node . host ;
1340
- options . socket . port = node . port ;
1341
- options . socket . reconnectStrategy = false ;
1342
- options . modules = RedisSentinelModule ;
1343
-
1344
- const client = RedisClient . create ( options ) . on ( 'error' , ( err ) => this . emit ( `updateSentinelRootNodes: ${ err } ` ) ) ;
1331
+ const client = RedisClient . create ( {
1332
+ ... this . options . sentinelClientOptions ,
1333
+ socket : {
1334
+ ... this . options . sentinelClientOptions ?. socket ,
1335
+ host : node . host ,
1336
+ port : node . port ,
1337
+ reconnectStrategy : false
1338
+ } ,
1339
+ modules : RedisSentinelModule
1340
+ } ) . on ( 'error' , ( err ) => this . emit ( `updateSentinelRootNodes: ${ err } ` ) ) ;
1345
1341
try {
1346
1342
await client . connect ( ) ;
1347
1343
} catch {
@@ -1367,16 +1363,16 @@ export class RedisSentinelFactory extends EventEmitter {
1367
1363
let connected = false ;
1368
1364
1369
1365
for ( const node of this . #sentinelRootNodes) {
1370
- const options : RedisClientOptions = { ... this . options . sentinelClientOptions } ;
1371
- if ( options . socket === undefined ) {
1372
- options . socket = { } ;
1373
- }
1374
- options . socket . host = node . host ;
1375
- options . socket . port = node . port ;
1376
- options . socket . reconnectStrategy = false ;
1377
- options . modules = RedisSentinelModule ;
1378
-
1379
- const client = RedisClient . create ( options ) . on ( 'error' , err => this . emit ( `getMasterNode: ${ err } ` ) ) ;
1366
+ const client = RedisClient . create ( {
1367
+ ... this . options . sentinelClientOptions ,
1368
+ socket : {
1369
+ ... this . options . sentinelClientOptions ?. socket ,
1370
+ host : node . host ,
1371
+ port : node . port ,
1372
+ reconnectStrategy : false
1373
+ } ,
1374
+ modules : RedisSentinelModule
1375
+ } ) . on ( 'error' , err => this . emit ( `getMasterNode: ${ err } ` ) ) ;
1380
1376
1381
1377
try {
1382
1378
await client . connect ( ) ;
@@ -1412,30 +1408,30 @@ export class RedisSentinelFactory extends EventEmitter {
1412
1408
1413
1409
async getMasterClient ( ) {
1414
1410
const master = await this . getMasterNode ( ) ;
1415
- const options : RedisClientOptions = { ... this . options . nodeClientOptions } ;
1416
- if ( options . socket === undefined ) {
1417
- options . socket = { } ;
1418
- }
1419
- options . socket . host = master . host ;
1420
- options . socket . port = master . port ;
1421
-
1422
- return RedisClient . create ( options ) ; ;
1411
+ return RedisClient . create ( {
1412
+ ... this . options . nodeClientOptions ,
1413
+ socket : {
1414
+ ... this . options . nodeClientOptions ?. socket ,
1415
+ host : master . host ,
1416
+ port : master . port
1417
+ }
1418
+ } ) ;
1423
1419
}
1424
1420
1425
1421
async getReplicaNodes ( ) {
1426
1422
let connected = false ;
1427
1423
1428
1424
for ( const node of this . #sentinelRootNodes) {
1429
- const options : RedisClientOptions = { ... this . options . sentinelClientOptions } ;
1430
- if ( options . socket === undefined ) {
1431
- options . socket = { } ;
1432
- }
1433
- options . socket . host = node . host ;
1434
- options . socket . port = node . port ;
1435
- options . socket . reconnectStrategy = false ;
1436
- options . modules = RedisSentinelModule ;
1437
-
1438
- const client = RedisClient . create ( options ) . on ( 'error' , err => this . emit ( `getReplicaNodes: ${ err } ` ) ) ;
1425
+ const client = RedisClient . create ( {
1426
+ ... this . options . sentinelClientOptions ,
1427
+ socket : {
1428
+ ... this . options . sentinelClientOptions ?. socket ,
1429
+ host : node . host ,
1430
+ port : node . port ,
1431
+ reconnectStrategy : false
1432
+ } ,
1433
+ modules : RedisSentinelModule
1434
+ } ) . on ( 'error' , err => this . emit ( `getReplicaNodes: ${ err } ` ) ) ;
1439
1435
1440
1436
try {
1441
1437
await client . connect ( ) ;
@@ -1480,13 +1476,13 @@ export class RedisSentinelFactory extends EventEmitter {
1480
1476
this . #replicaIdx = 0 ;
1481
1477
}
1482
1478
1483
- const options : RedisClientOptions = { ... this . options . nodeClientOptions } ;
1484
- if ( options . socket === undefined ) {
1485
- options . socket = { } ;
1486
- }
1487
- options . socket . host = replicas [ this . #replicaIdx] . host ;
1488
- options . socket . port = replicas [ this . #replicaIdx] . port ;
1489
-
1490
- return RedisClient . create ( options ) ;
1479
+ return RedisClient . create ( {
1480
+ ... this . options . nodeClientOptions ,
1481
+ socket : {
1482
+ ... this . options . nodeClientOptions ?. socket ,
1483
+ host : replicas [ this . #replicaIdx] . host ,
1484
+ port : replicas [ this . #replicaIdx] . port
1485
+ }
1486
+ } ) ;
1491
1487
}
1492
1488
}
0 commit comments