Drunk-Venti-Api/utils/redis.js

17 lines
459 B
JavaScript
Raw Normal View History

2022-07-29 22:26:06 +02:00
const ENABLE_REDIS = true;
2022-01-15 18:07:08 +01:00
const redis = require("redis");
2022-07-29 22:26:06 +02:00
const client = ENABLE_REDIS ? redis.createClient("redis://localhost:6379") : null;
client?.connect();
2022-01-15 18:07:08 +01:00
export async function getResultFromRedis(key){
2022-07-29 22:26:06 +02:00
if (ENABLE_REDIS)
if (await client.exists(key)) {
return await client.get(key)
}
2022-01-15 18:07:08 +01:00
return null;
}
export async function addResultToRedis(key, value){
2022-07-29 22:26:06 +02:00
if (ENABLE_REDIS) await client.set(key, value, {EX: 600});
2022-01-15 18:07:08 +01:00
}