Initial commit: Meshkee CMS API
NestJS backend with Prisma, Docker Compose for Postgres/Redis, and deploy docs for the production VM.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export const REDIS_CLIENT = 'REDIS_CLIENT';
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import Redis from 'ioredis';
|
||||
import { REDIS_CLIENT } from './redis.constants';
|
||||
import { RedisService } from './redis.service';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [
|
||||
{
|
||||
provide: REDIS_CLIENT,
|
||||
inject: [ConfigService],
|
||||
useFactory: (config: ConfigService) => {
|
||||
return new Redis(config.get<string>('REDIS_URL', 'redis://localhost:6379'));
|
||||
},
|
||||
},
|
||||
RedisService,
|
||||
],
|
||||
exports: [RedisService],
|
||||
})
|
||||
export class RedisModule {}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import Redis from 'ioredis';
|
||||
import { REDIS_CLIENT } from './redis.constants';
|
||||
|
||||
@Injectable()
|
||||
export class RedisService {
|
||||
constructor(@Inject(REDIS_CLIENT) private readonly redis: Redis) {}
|
||||
|
||||
get client(): Redis {
|
||||
return this.redis;
|
||||
}
|
||||
|
||||
async setOtp(cellNumber: string, code: string, ttlSeconds: number): Promise<void> {
|
||||
await this.redis.set(`otp:${cellNumber}`, code, 'EX', ttlSeconds);
|
||||
}
|
||||
|
||||
async getOtp(cellNumber: string): Promise<string | null> {
|
||||
return this.redis.get(`otp:${cellNumber}`);
|
||||
}
|
||||
|
||||
async deleteOtp(cellNumber: string): Promise<void> {
|
||||
await this.redis.del(`otp:${cellNumber}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user