import * as IORedis from "ioredis" ; import { ICacheItem , IStorage } from "node-ts-cache" ; export class IoRedisStorage implements IStorage { constructor ( private ioRedisInstance ) { } async clear ( ) { await this . ioRedisInstance . flushdb ( ) ; } async getItem ( key ) { const response = await this . ioRedisInstance . get ( key ) ; if ( response === undefined || response === null || response === "" ) { return undefined ; } return JSON . parse ( response ) ; } async setItem ( key , content ) { if ( content === undefined ) { await this . ioRedisInstance . del ( key ) ; return ; } await this . ioRedisInstance . set ( key , JSON . stringify ( content ) ) ; } }