import crypto = require ( 'crypto' ) ; import RedisKeyUtil = require ( '@app/core/redis/RedisKeyUtil' ) ; import RedisUtil = require ( '@app/core/redis/RedisUtil' ) ; import RefLecture from './model/RefLecture' ; export async function getListOfLectureListCacheFromPageList ( query , pageList ) { let queryHash = makeMd5HashFromObject ( query ) ; let keyList = pageList . map ( page => RedisKeyUtil . getLectureQueryKey ( queryHash , page ) ) ; let lectureListStringList = await RedisUtil . mget ( keyList ) ; let lectureListList = lectureListStringList . map ( parseLectureListString ) ; return lectureListList ; } function parseLectureListString ( str ) { let lectureList = JSON . parse ( str ) ; if ( ! lectureList || typeof lectureList . length !== 'number' ) { return null ; } else { return lectureList ; } } export async function setLectureListCache ( query , page , lectureList ) { let queryHash = makeMd5HashFromObject ( query ) ; let key = RedisKeyUtil . getLectureQueryKey ( queryHash , page ) ; let lectureListString = JSON . stringify ( lectureList ) ; await RedisUtil . set ( key , lectureListString ) ; } function makeMd5HashFromObject ( object ) { return crypto . createHash ( 'md5' ) . update ( JSON . stringify ( object ) ) . digest ( 'hex' ) ; }