import redis from 'redis' ; const cache = redis . createClient ( { url : process . env . REDIS_URL } ) ; export const has = ( key ) : Promise < boolean > => new Promise ( ( resolve , reject ) => { if ( ! key ) { return false ; } cache . exists ( key , ( err , data ) => { if ( err ) { return reject ( err ) ; } resolve ( data === 1 ) ; } ) ; } ) ; export const get = < T = any > ( key ) : Promise < T > => new Promise ( ( resolve , reject ) => { cache . get ( key , ( err , data ) => { if ( err ) { return reject ( err ) ; } resolve ( JSON . parse ( data ) ) ; } ) ; } ) ; export const set = ( key , value , ttl ? ) : Promise < void > => new Promise ( ( resolve , reject ) => { const cb = ( err , data ) => { if ( err ) { return reject ( err ) ; } resolve ( ) ; } ; value = JSON . stringify ( value ) ; if ( ttl ) { cache . set ( key , value , 'EX' , ttl , cb ) ; } else { cache . set ( key , value , cb ) ; } } ) ;