import * as redis from 'redis' ; import { REDIS_HOST } from '@auth/constants' ; import { promisify } from 'util' ; import { logger } from '@auth/logger' ; let redisClient ; export interface IDatabaseConnector { stop : ( ) => void ; start : ( ) => void ; set : ( key : string , value : string ) => Promise < void > ; setex : ( key : string , ttl : number , value : string ) => Promise < void > ; get : ( key : string ) => Promise < string | null > ; del : ( key : string ) => Promise < number > ; } export async function stop ( ) { redisClient . quit ( ) ; } export async function start ( ) { logger . info ( 'REDIS_HOST' , REDIS_HOST ) ; redisClient = redis . createClient ( { host : REDIS_HOST , retry_strategy : options => { return 1000 ; } } ) ; } export const get = ( key ) => promisify ( redisClient . get ) . bind ( redisClient ) ( key ) ; export const set = ( key , value ) => promisify ( redisClient . set ) . bind ( redisClient ) ( key , value ) ; export const setex = ( key , ttl , value ) => promisify ( redisClient . setex ) . bind ( redisClient ) ( key , ttl , value ) ; export const del = ( key ) => promisify ( redisClient . del ) . bind ( redisClient ) ( key ) ;