mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-20 20:32:23 -06:00
fix: Adjusts in redis for save instances
This commit is contained in:
34
src/cache/rediscache.ts
vendored
34
src/cache/rediscache.ts
vendored
@@ -1,3 +1,4 @@
|
||||
import { BufferJSON } from '@whiskeysockets/baileys';
|
||||
import { RedisClientType } from 'redis';
|
||||
|
||||
import { ICache } from '../api/abstract/abstract.cache';
|
||||
@@ -14,7 +15,6 @@ export class RedisCache implements ICache {
|
||||
this.conf = this.configService.get<CacheConf>('CACHE')?.REDIS;
|
||||
this.client = redisClient.getConnection();
|
||||
}
|
||||
|
||||
async get(key: string): Promise<any> {
|
||||
try {
|
||||
return JSON.parse(await this.client.get(this.buildKey(key)));
|
||||
@@ -23,6 +23,20 @@ export class RedisCache implements ICache {
|
||||
}
|
||||
}
|
||||
|
||||
async hGet(key: string, field: string) {
|
||||
try {
|
||||
const data = await this.client.hGet(this.buildKey(key), field);
|
||||
|
||||
if (data) {
|
||||
return JSON.parse(data, BufferJSON.reviver);
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
async set(key: string, value: any, ttl?: number) {
|
||||
try {
|
||||
await this.client.setEx(this.buildKey(key), ttl || this.conf?.TTL, JSON.stringify(value));
|
||||
@@ -31,6 +45,16 @@ export class RedisCache implements ICache {
|
||||
}
|
||||
}
|
||||
|
||||
async hSet(key: string, field: string, value: any) {
|
||||
try {
|
||||
const json = JSON.stringify(value, BufferJSON.replacer);
|
||||
|
||||
await this.client.hSet(this.buildKey(key), field, json);
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
async has(key: string) {
|
||||
try {
|
||||
return (await this.client.exists(this.buildKey(key))) > 0;
|
||||
@@ -47,6 +71,14 @@ export class RedisCache implements ICache {
|
||||
}
|
||||
}
|
||||
|
||||
async hDelete(key: string, field: string) {
|
||||
try {
|
||||
return await this.client.hDel(this.buildKey(key), field);
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
async deleteAll(appendCriteria?: string) {
|
||||
try {
|
||||
const keys = await this.keys(appendCriteria);
|
||||
|
||||
Reference in New Issue
Block a user