import { createClient } from 'redis' ; export const connect = ( options , mediator ) => { mediator . once ( 'boot.ready' , ( ) => { if ( ! options ) { mediator . emit ( 'db.error' , 'Unable to connect redis db. No config options' ) ; return ; } const db = createClient ( options ) ; db . on ( 'connect' , ( ) => { console . log ( 'Redis default connection is open' ) ; mediator . emit ( 'db.ready' , db ) ; } ) ; db . on ( 'end' , ( ) => { console . log ( 'Redis default connection is disconnected' ) ; } ) ; db . on ( 'error' , ( err ) => { console . log ( 'Redis default connection has occured ' + err + ' error' ) ; mediator . emit ( 'db.error' , err ) ; } ) ; process . on ( 'SIGINT' , ( ) => { db . quit ( ( ) => { console . log ( 'Redis default connection is disconnected due to application termination' ) ; process . exit ( 0 ) ; } ) ; } ) ; } ) ; } ;