impl redis cloud

This commit is contained in:
JurTI-BR
2025-04-01 16:42:05 -03:00
parent f8bea4114f
commit 28a1cee876
14 changed files with 819 additions and 6 deletions

View File

@@ -17,6 +17,10 @@ export class DataConsultService {
private readonly SELLERS_CACHE_KEY = 'data-consult:sellers';
private readonly SELLERS_TTL = 3600; // 1 hora
private readonly STORES_TTL = 3600;
private readonly BILLINGS_TTL = 3600;
private readonly ALL_PRODUCTS_CACHE_KEY = 'data-consult:products:all';
private readonly ALL_PRODUCTS_TTL = 600; // 10 minutos (ajustável)
constructor(
@@ -59,8 +63,11 @@ export class DataConsultService {
async billings(): Promise<BillingDto[]> {
this.logger.log('Buscando todos os faturamentos');
return this.repository.findBillings();
}
/**
* Obter clientes filtrados por termo de pesquisa
* @param filter - Termo de pesquisa para filtrar clientes
@@ -95,4 +102,17 @@ export class DataConsultService {
);
}
}
async getAllProducts(): Promise<ProductDto[]> {
this.logger.log('Buscando produtos com cache Redis...');
return getOrSetCache<ProductDto[]>(
this.redisClient,
this.ALL_PRODUCTS_CACHE_KEY,
this.ALL_PRODUCTS_TTL,
async () => {
this.logger.log('Cache de produtos vazio. Buscando no banco...');
return this.repository.findAllProducts();
}
);
}
}