Validate if cache exists before accessing it

This commit is contained in:
Judson Cairo 2024-08-28 09:59:40 -03:00
parent 3b9761992a
commit a19343d3e1

View File

@ -21,6 +21,9 @@ export class CacheService {
} }
public async hGet(key: string, field: string) { public async hGet(key: string, field: string) {
if (!this.cache) {
return null;
}
try { try {
const data = await this.cache.hGet(key, field); const data = await this.cache.hGet(key, field);
@ -43,6 +46,9 @@ export class CacheService {
} }
public async hSet(key: string, field: string, value: any) { public async hSet(key: string, field: string, value: any) {
if (!this.cache) {
return;
}
try { try {
const json = JSON.stringify(value, BufferJSON.replacer); const json = JSON.stringify(value, BufferJSON.replacer);
@ -67,6 +73,9 @@ export class CacheService {
} }
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;