Ajuste comentario cache de departamento
This commit is contained in:
parent
b43af08d04
commit
6c324df9e9
|
|
@ -672,6 +672,7 @@ export class OrderService {
|
||||||
numeroSeq = numeroSeq + 1;
|
numeroSeq = numeroSeq + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// execute some operations on this transaction:
|
||||||
await queryRunner.manager
|
await queryRunner.manager
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.insert()
|
.insert()
|
||||||
|
|
|
||||||
|
|
@ -1123,10 +1123,9 @@ export class SalesService {
|
||||||
async getDepartments(): Promise<Esvdepartamento[]> {
|
async getDepartments(): Promise<Esvdepartamento[]> {
|
||||||
const cacheKey = 'departments';
|
const cacheKey = 'departments';
|
||||||
const lockKey = 'departments_lock';
|
const lockKey = 'departments_lock';
|
||||||
const lockTimeout = 30; // lock expira em 30 segundos
|
const lockTimeout = 30;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Tenta recuperar os departamentos do cache
|
|
||||||
const cachedDepartments = await this.redisClient.get(cacheKey);
|
const cachedDepartments = await this.redisClient.get(cacheKey);
|
||||||
if (cachedDepartments) {
|
if (cachedDepartments) {
|
||||||
console.log('Buscando departamentos no Redis');
|
console.log('Buscando departamentos no Redis');
|
||||||
|
|
@ -1134,7 +1133,6 @@ export class SalesService {
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Erro ao acessar o Redis (cache):', err);
|
console.error('Erro ao acessar o Redis (cache):', err);
|
||||||
// Se o Redis falhar, a execução continua para consultar o banco
|
|
||||||
}
|
}
|
||||||
const lockValue = Date.now() + lockTimeout * 1000 + 1;
|
const lockValue = Date.now() + lockTimeout * 1000 + 1;
|
||||||
const acquiredLock = await this.redisClient.set(lockKey, lockValue, 'NX', 'EX', lockTimeout);
|
const acquiredLock = await this.redisClient.set(lockKey, lockValue, 'NX', 'EX', lockTimeout);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue