2022-11-27 02:13:57 +01:00
|
|
|
const ENABLE_REDIS = process.env["ENABLE_REDIS"];
|
2022-01-15 18:07:08 +01:00
|
|
|
const redis = require("redis");
|
2022-11-27 02:13:57 +01:00
|
|
|
const client = redis.createClient({
|
|
|
|
url: `redis://${process.env['REDIS_HOST']}:${process.env["REDIS_PORT"]}`
|
|
|
|
});
|
|
|
|
if (ENABLE_REDIS) (client.connect().then(_ =>{console.info("Connected to redis")}));
|
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
|
|
|
}
|