implementação do logger
This commit is contained in:
24
src/core/configs/cache/redis-client.adapter.ts
vendored
Normal file
24
src/core/configs/cache/redis-client.adapter.ts
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Redis } from 'ioredis';
|
||||
import { IRedisClient } from './IRedisClient';
|
||||
|
||||
@Injectable()
|
||||
export class RedisClientAdapter implements IRedisClient {
|
||||
constructor(
|
||||
@Inject('REDIS_CLIENT')
|
||||
private readonly redis: Redis
|
||||
) {}
|
||||
|
||||
async get<T>(key: string): Promise<T | null> {
|
||||
const data = await this.redis.get(key);
|
||||
return data ? JSON.parse(data) : null;
|
||||
}
|
||||
|
||||
async set<T>(key: string, value: T, ttlSeconds = 300): Promise<void> {
|
||||
await this.redis.set(key, JSON.stringify(value), 'EX', ttlSeconds);
|
||||
}
|
||||
|
||||
async del(key: string): Promise<void> {
|
||||
await this.redis.del(key);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user