import mongoose from 'mongoose' ; import redis , { RedisClient } from 'redis' ; import dotenv from 'dotenv' ; dotenv . config ( ) ; export const createConnectionMongo = ( databaseObj ) => { mongoose . connect ( `mongodb://${ databaseObj . host }:${ databaseObj . port }/anime-directory` , { useNewUrlParser : true , useUnifiedTopology : true , } ) ; mongoose . connection . on ( 'error' , err => { console . log ( 'err' , err ) ; } ) ; mongoose . connection . on ( 'connected' , ( err , res ) => { console . log ( 'Database connected: mongoose.' ) ; } ) ; } ; export const redisClient = redis . createClient ( { host : process . env . REDIS_HOST , port : parseInt ( process . env . REDIS_PORT ! ) , password : process . env . REDIS_PASSWORD , retry_strategy : function ( options ) { if ( options . error && options . error . code === 'ECONNREFUSED' ) { return new Error ( 'The server refused the connection' ) ; } if ( options . total_retry_time > 1000 * 60 * 60 ) { return new Error ( 'Retry time exhausted' ) ; } if ( options . attempt > 10 ) { return undefined ; } return Math . min ( options . attempt * 100 , 3000 ) ; } , } ) ; redisClient . on ( 'connect' , ( ) => { console . log ( 'Redis connected: redis.' ) ; } ) ; redisClient . on ( 'error' , function ( err ) { console . log ( 'Redis error: ' + err ) ; } ) ;