From 403ffbb804196651180d0a58aaa26e1fc627ea50 Mon Sep 17 00:00:00 2001 From: cnrad Date: Fri, 25 Mar 2022 23:09:06 -0400 Subject: [PATCH] add redis again --- .env | 2 +- pages/api/[...id].ts | 16 +++++++--------- pages/api/getUserCount.ts | 11 ++++------- src/redis.ts | 9 +++------ 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/.env b/.env index 39c6aaf..139c928 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -REDIS_URL=rediss://:b608c52a48584bf584b97d7a92a9bd97@us1-excited-honeybee-34947.upstash.io:34947 \ No newline at end of file +REDIS_URL=redis://:cnredis7535@142.93.77.0:6379 \ No newline at end of file diff --git a/pages/api/[...id].ts b/pages/api/[...id].ts index 9b494ac..98e3cd5 100644 --- a/pages/api/[...id].ts +++ b/pages/api/[...id].ts @@ -2,7 +2,7 @@ import type { NextApiRequest, NextApiResponse } from "next"; import axios from "axios"; import renderCard from "../../src/renderCard"; import { isSnowflake } from "../../src/snowflake"; -// import redis from "../../src/redis"; +import redis from "../../src/redis"; type Data = { id?: string | string[]; @@ -47,14 +47,12 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< }); } - // try { - // let user = await redis.hget("users", userId); - // if (!user) await redis.hset("users", userId, "true"); - - // redis.disconnect(); - // } catch { - // null; - // } + try { + let user = await redis.hget("users", userId); + if (!user) await redis.hset("users", userId, "true"); + } catch { + null; + } res.setHeader("Content-Type", "image/svg+xml; charset=utf-8"); res.setHeader("content-security-policy", "default-src 'none'; img-src * data:; style-src 'unsafe-inline'"); diff --git a/pages/api/getUserCount.ts b/pages/api/getUserCount.ts index 81562ff..80163d3 100644 --- a/pages/api/getUserCount.ts +++ b/pages/api/getUserCount.ts @@ -1,12 +1,9 @@ import type { NextApiRequest, NextApiResponse } from "next"; -// import redis from "../../src/redis"; +import redis from "../../src/redis"; export default async function handler(req: NextApiRequest, res: NextApiResponse) { - // let users = await redis.hgetall("users"); - // let count = Object.keys(users); + let users = await redis.hgetall("users"); + let count = Object.keys(users); - // redis.disconnect(); - - // res.status(200).send({ count: count.length }); - res.status(200).send({ count: 971 }); + res.status(200).send({ count: count.length }); } diff --git a/src/redis.ts b/src/redis.ts index d9f7d42..106b727 100644 --- a/src/redis.ts +++ b/src/redis.ts @@ -1,8 +1,5 @@ -// import Redis from "ioredis"; +import Redis from "ioredis"; -// const redis = new Redis(process.env.REDIS_URL); +const redis = new Redis(process.env.REDIS_URL); -// export default redis; - -const bruh = "bruh"; -export default bruh; +export default redis;