fix: Adjusts in redis for save instances

This commit is contained in:
Davidson Gomes
2024-04-18 10:39:24 -03:00
parent 4ed1335f89
commit 61bd5b3484
18 changed files with 178 additions and 208 deletions

View File

@@ -1,3 +1,5 @@
import { BufferJSON } from '@whiskeysockets/baileys';
import { Logger } from '../../config/logger.config';
import { ICache } from '../abstract/abstract.cache';
@@ -20,6 +22,21 @@ export class CacheService {
return this.cache.get(key);
}
public async hGet(key: string, field: string) {
try {
const data = await this.cache.hGet(key, field);
if (data) {
return JSON.parse(data, BufferJSON.reviver);
}
return null;
} catch (error) {
this.logger.error(error);
return null;
}
}
async set(key: string, value: any) {
if (!this.cache) {
return;
@@ -28,6 +45,16 @@ export class CacheService {
this.cache.set(key, value);
}
public async hSet(key: string, field: string, value: any) {
try {
const json = JSON.stringify(value, BufferJSON.replacer);
await this.cache.hSet(key, field, json);
} catch (error) {
this.logger.error(error);
}
}
async has(key: string) {
if (!this.cache) {
return;
@@ -44,6 +71,16 @@ export class CacheService {
return this.cache.delete(key);
}
async hDelete(key: string, field: string) {
try {
await this.cache.hDelete(key, field);
return true;
} catch (error) {
this.logger.error(error);
return false;
}
}
async deleteAll(appendCriteria?: string) {
if (!this.cache) {
return;