SHARE
TWEET

Untitled

a guest Jun 17th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import redis from "../api/redis";
  2. import { Injectable } from "@nestjs/common";
  3.  
  4. @Injectable()
  5. export default class CacheModule
  6. {
  7.     public CacheKey: string = "cache";
  8.  
  9.     public constructor()
  10.     {
  11.         this.CacheKey = process.env.CacheKey as string;
  12.     }
  13.  
  14.     public async get(key: string)
  15.     {
  16.         const cachestring = await redis.hget(this.CacheKey, key);
  17.         if (cachestring) {
  18.             return JSON.parse(cachestring);
  19.         }
  20.         else {
  21.             return null;
  22.         }
  23.     }
  24.  
  25.     public async set(key: string, value: any)
  26.     {
  27.         await redis.hset(this.CacheKey, key, JSON.stringify(value));
  28.     }
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top