@@ -353,6 +353,44 @@ describe("pipeline", function () {
353
353
} )
354
354
. catch ( done ) ;
355
355
} ) ;
356
+
357
+ it ( "should reload scripts on redis restart (reconnect)" , async function ( ) {
358
+ const redis = new Redis ( { connectionName : "load-script-on-reconnect" } ) ;
359
+ const redis2 = new Redis ( ) ;
360
+ redis . defineCommand ( "exeecafterreconnect" , {
361
+ numberOfKeys : 0 ,
362
+ lua : `return "OK"` ,
363
+ } ) ;
364
+
365
+ const [ [ err , res ] ] = await redis . multi ( [ [ "exeecafterreconnect" ] ] ) . exec ( ) ;
366
+ expect ( err ) . to . equal ( null ) ;
367
+ expect ( res ) . to . equal ( "OK" ) ;
368
+
369
+ const client = await redis . client ( "list" ) . then ( ( clients ) => {
370
+ const myInfo = clients
371
+ . split ( "\n" )
372
+ . find ( ( client ) => client . includes ( "load-script-on-reconnect" ) ) ;
373
+
374
+ const match = / a d d r = ( [ ^ ] + ) / . exec ( myInfo ) ;
375
+ if ( match ) return match [ 1 ] ;
376
+ } ) ;
377
+
378
+ await redis2 . script ( "flush" ) ;
379
+ await redis2 . client ( "kill" , "addr" , client ) ;
380
+
381
+ // Wait for reconnect, at the moment scripts are not loaded
382
+ // if the pipeline starts before ioredis reconnects
383
+ await redis . ping ( ) ;
384
+
385
+ const [ [ err2 , res2 ] ] = await redis
386
+ . multi ( [ [ "exeecafterreconnect" ] ] )
387
+ . exec ( ) ;
388
+
389
+ expect ( err2 ) . to . equal ( null ) ;
390
+ expect ( res2 ) . to . equal ( "OK" ) ;
391
+ redis . disconnect ( ) ;
392
+ redis2 . disconnect ( ) ;
393
+ } ) ;
356
394
} ) ;
357
395
358
396
describe ( "#length" , function ( ) {
0 commit comments