Resolve Erros no cacheService caso REDIS não esteja habilitado.

This commit is contained in:
Deivison Lincoln 2024-08-27 11:26:33 -03:00
parent cb865bf5a0
commit 2a9e705800

View File

@ -17,10 +17,15 @@ export class CacheService {
if (!this.cache) { if (!this.cache) {
return; return;
} }
return this.cache.get(key); return this.cache.get(key);
} }
public async hGet(key: string, field: string) { public async hGet(key: string, field: string) {
if (!this.cache) {
return false;
}
try { try {
const data = await this.cache.hGet(key, field); const data = await this.cache.hGet(key, field);
@ -39,10 +44,15 @@ export class CacheService {
if (!this.cache) { if (!this.cache) {
return; return;
} }
this.cache.set(key, value); this.cache.set(key, value);
} }
public async hSet(key: string, field: string, value: any) { public async hSet(key: string, field: string, value: any) {
if (!this.cache) {
return false;
}
try { try {
const json = JSON.stringify(value, BufferJSON.replacer); const json = JSON.stringify(value, BufferJSON.replacer);
@ -56,6 +66,7 @@ export class CacheService {
if (!this.cache) { if (!this.cache) {
return; return;
} }
return this.cache.has(key); return this.cache.has(key);
} }
@ -63,10 +74,15 @@ export class CacheService {
if (!this.cache) { if (!this.cache) {
return; return;
} }
return this.cache.delete(key); return this.cache.delete(key);
} }
async hDelete(key: string, field: string) { async hDelete(key: string, field: string) {
if (!this.cache) {
return false;
}
try { try {
await this.cache.hDelete(key, field); await this.cache.hDelete(key, field);
return true; return true;
@ -80,6 +96,7 @@ export class CacheService {
if (!this.cache) { if (!this.cache) {
return; return;
} }
return this.cache.deleteAll(appendCriteria); return this.cache.deleteAll(appendCriteria);
} }
@ -87,6 +104,7 @@ export class CacheService {
if (!this.cache) { if (!this.cache) {
return; return;
} }
return this.cache.keys(appendCriteria); return this.cache.keys(appendCriteria);
} }
} }