Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import redis from "../api/redis";
- import { Injectable } from "@nestjs/common";
- @Injectable()
- export default class CacheModule
- {
- public CacheKey: string = "cache";
- public constructor()
- {
- this.CacheKey = process.env.CacheKey as string;
- }
- public async get(key: string)
- {
- const cachestring = await redis.hget(this.CacheKey, key);
- if (cachestring) {
- return JSON.parse(cachestring);
- }
- else {
- return null;
- }
- }
- public async set(key: string, value: any)
- {
- await redis.hset(this.CacheKey, key, JSON.stringify(value));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement