@suissa/universal-queues
Version:
Factory universal para mensageria (RabbitMQ, Kafka, SQS) para sistemas distribuĂdos.
36 lines • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RedisHistory = void 0;
// import { RedisClientType } from 'redis';
const redis_1 = require("./redis");
const HISTORY_PREFIX = 'llm:history:'; // Namespace das chaves
class RedisHistory {
redis;
constructor() {
this.redis = redis_1.redis;
}
async getHistory(number) {
const raw = await this.redis.get(HISTORY_PREFIX + number);
if (!raw)
return [];
try {
return JSON.parse(raw);
}
catch {
return [];
}
}
async saveHistory(number, history) {
await this.redis.set(HISTORY_PREFIX + number, JSON.stringify(history), { EX: 60 * 60 * 12 }); // expira em 12h
}
async addToHistory(number, message) {
const history = await this.getHistory(number);
history.push(message);
await this.saveHistory(number, history); // <- faltou isso!
}
async clearHistory(number) {
await this.redis.del(HISTORY_PREFIX + number);
}
}
exports.RedisHistory = RedisHistory;
//# sourceMappingURL=history.redis.js.map