@@ -68,7 +68,7 @@ export class SolidisConnection extends EventEmitter {
6868 return await this . #connectLock;
6969 }
7070
71- this . #connectLock = this . #tryConnectWithRetry( options ) ;
71+ this . #connectLock = this . #tryConnectWithRetry( ) ;
7272
7373 try {
7474 await this . #connectLock;
@@ -102,39 +102,37 @@ export class SolidisConnection extends EventEmitter {
102102 this . emit ( 'end' ) ;
103103 }
104104
105- async #tryConnectWithRetry( options : SolidisClientFrozenOptions ) {
105+ async #tryConnectWithRetry( ) {
106106 let attemptIndex = 0 ;
107107
108- const maxConnectionRetries = options . maxConnectionRetries ;
108+ const maxConnectionRetries = this . # options. maxConnectionRetries ;
109109
110110 while ( true ) {
111111 attemptIndex += 1 ;
112112
113113 try {
114- await this . #tryConnect( options ) ;
114+ await this . #tryConnect( ) ;
115115 return ;
116116 } catch ( error ) {
117117 if ( this . #isQuitted) {
118118 throw wrapWithSolidisConnectionError ( error ) ;
119119 }
120120
121121 if ( attemptIndex > maxConnectionRetries ) {
122- throw wrapWithSolidisConnectionError (
123- new SolidisConnectionError (
124- `SolidisClient connection failed after ${ maxConnectionRetries } retries.` ,
125- error ,
126- ) ,
122+ throw new SolidisConnectionError (
123+ `SolidisClient connection failed after ${ maxConnectionRetries } retries.` ,
124+ error ,
127125 ) ;
128126 }
129127
130128 await new Promise < void > ( ( resolve ) =>
131- setTimeout ( resolve , options . connectionRetryDelay ) ,
129+ setTimeout ( resolve , this . # options. connectionRetryDelay ) ,
132130 ) ;
133131 }
134132 }
135133 }
136134
137- async #tryConnect( options : SolidisClientFrozenOptions ) {
135+ async #tryConnect( ) {
138136 if ( this . #isQuitted) {
139137 throw new SolidisConnectionError (
140138 'Cannot connect: user quit the connection.' ,
@@ -155,7 +153,7 @@ export class SolidisConnection extends EventEmitter {
155153 } ;
156154
157155 const timeoutHandle = this . #setupConnectionTimeout(
158- options . connectionTimeout ,
156+ this . # options. connectionTimeout ,
159157 ( reason ?: unknown ) => onFail ( reason ) ,
160158 ) ;
161159
@@ -176,18 +174,20 @@ export class SolidisConnection extends EventEmitter {
176174 this . emit ( 'connect' ) ;
177175 } ;
178176
177+ const { host, port, useTLS } = this . #parseSocketOptions( ) ;
178+
179179 const socket = this . #createSocket( {
180- host : options . host ,
181- port : options . port ,
182- useTLS : options . useTLS ,
180+ host,
181+ port,
182+ useTLS,
183183 onConnect,
184184 } ) ;
185185
186186 this . #setupSocketErrorHandler( socket ) ;
187187 this . #setupSocketCloseHandler( socket , onFail ) ;
188188
189- socket . setMaxListeners ( options . maxEventListenersForSocket ) ;
190- this . setMaxListeners ( options . maxEventListenersForClient ) ;
189+ socket . setMaxListeners ( this . # options. maxEventListenersForSocket ) ;
190+ this . setMaxListeners ( this . # options. maxEventListenersForClient ) ;
191191
192192 this . #socket = socket ;
193193 } ) ;
@@ -202,7 +202,7 @@ export class SolidisConnection extends EventEmitter {
202202 return await this . #connectLock;
203203 }
204204
205- this . #connectLock = this . #tryConnectWithRetry( this . #options ) ;
205+ this . #connectLock = this . #tryConnectWithRetry( ) ;
206206
207207 try {
208208 await this . #connectLock;
@@ -302,4 +302,22 @@ export class SolidisConnection extends EventEmitter {
302302
303303 return timer ;
304304 }
305+
306+ #parseSocketOptions( ) {
307+ if ( this . #options. uri ) {
308+ const url = new URL ( this . #options. uri ) ;
309+
310+ return {
311+ host : url . hostname ,
312+ port : url . port ? Number . parseInt ( url . port ) : 6379 ,
313+ useTLS : this . #options. useTLS || url . protocol === 'rediss:' ,
314+ } ;
315+ }
316+
317+ return {
318+ host : this . #options. host ,
319+ port : this . #options. port ,
320+ useTLS : this . #options. useTLS ,
321+ } ;
322+ }
305323}
0 commit comments