Working Redis

This commit is contained in:
2024-02-14 14:18:40 +03:00
parent e6098c664c
commit 1c1812a44c
3 changed files with 10 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
import { Controller, Get, Param } from '@nestjs/common';
import { CacheInterceptor, CacheKey, CacheTTL } from '@nestjs/cache-manager';
import { Controller, Get, Param, UseInterceptors } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { AdminService } from './admin.service';
@@ -10,6 +11,9 @@ export class AdminController {
@ApiOperation({
description: 'Get admins from db',
})
@CacheKey('admins')
@CacheTTL({ ttl: 5 } as any)
@UseInterceptors(CacheInterceptor)
@Get('get')
async getAdmin() {
return await this.adminService.getAdmins();

View File

@@ -2,7 +2,6 @@ import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Admin } from 'libs/database/admin.entity';
import { Repository } from 'typeorm';
@Injectable()
export class AdminService {
private readonly logger: Logger = new Logger(AdminService.name);
@@ -18,7 +17,7 @@ export class AdminService {
}));
return result;
} catch (error) {
this.logger.log(`[getAdmin] ${JSON.stringify({ error })}`);
this.logger.log(`[getAdmin] ${error}`);
return [];
}
}