feat: add user submission functionality
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { REDIS } from '../constants/redis.constants';
|
||||
import Redis from 'ioredis';
|
||||
@@ -17,16 +16,22 @@ export class RedisService {
|
||||
return this.redis;
|
||||
}
|
||||
|
||||
async set(key: string, val: string, ttl?: number) {
|
||||
async set<T>(key: string, val: T, ttl?: number) {
|
||||
const payload = JSON.stringify(val);
|
||||
|
||||
if (ttl) {
|
||||
await this.redis.set(key, val, 'EX', ttl);
|
||||
await this.redis.set(key, payload, 'EX', ttl);
|
||||
} else {
|
||||
await this.redis.set(key, val);
|
||||
await this.redis.set(key, payload);
|
||||
}
|
||||
}
|
||||
|
||||
async get(key: string) {
|
||||
return await this.redis.get(key);
|
||||
async get<T>(key: string): Promise<T | null> {
|
||||
const value = await this.redis.get(key);
|
||||
|
||||
if (!value) return null;
|
||||
|
||||
return JSON.parse(value) as T;
|
||||
}
|
||||
|
||||
async del(key: string) {
|
||||
|
||||
Reference in New Issue
Block a user