REDIS config + flatten events
This commit is contained in:
parent
455ae8c0ee
commit
2a31aebb00
2 changed files with 11 additions and 7 deletions
|
@ -1,9 +1,11 @@
|
|||
import {getEvents} from "./utils";
|
||||
import {flatten} from "next/dist/shared/lib/flatten";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const events = await getEvents();
|
||||
if (events) {
|
||||
res.status(200).json(events);
|
||||
console.log(flatten(events))
|
||||
res.status(200).json(flatten(events));
|
||||
} else {
|
||||
res.status(404).json({message: "An error has occured"});
|
||||
}
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
const ENABLE_REDIS = true;
|
||||
const redis = require("redis");
|
||||
const client = redis.createClient("redis://localhost:6379");
|
||||
client.connect();
|
||||
const client = ENABLE_REDIS ? redis.createClient("redis://localhost:6379") : null;
|
||||
client?.connect();
|
||||
|
||||
|
||||
export async function getResultFromRedis(key){
|
||||
if (await client.exists(key)) {
|
||||
return await client.get(key)
|
||||
}
|
||||
if (ENABLE_REDIS)
|
||||
if (await client.exists(key)) {
|
||||
return await client.get(key)
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function addResultToRedis(key, value){
|
||||
await client.set(key, value, {EX: 600});
|
||||
if (ENABLE_REDIS) await client.set(key, value, {EX: 600});
|
||||
}
|
Loading…
Reference in a new issue