From 592c18190250f3d9acf4f2b92dad178c01b33467 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Thu, 25 Apr 2024 11:26:10 -0700 Subject: [PATCH] Updated redis methods. --- package.json | 2 +- src/lib/cache.ts | 41 ++++++++++++++++------------------------- yarn.lock | 8 ++++---- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index c72a054f..bf5f00ae 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "@react-spring/web": "^9.7.3", "@tanstack/react-query": "^5.28.6", "@umami/prisma-client": "^0.14.0", - "@umami/redis-client": "^0.18.0", + "@umami/redis-client": "^0.20.0", "chalk": "^4.1.1", "chart.js": "^4.4.2", "chartjs-adapter-date-fns": "^3.0.0", diff --git a/src/lib/cache.ts b/src/lib/cache.ts index 97482499..cb218ba0 100644 --- a/src/lib/cache.ts +++ b/src/lib/cache.ts @@ -3,57 +3,48 @@ import redis from '@umami/redis-client'; import { getSession, getUser, getWebsite } from '../queries'; async function fetchWebsite(websiteId: string): Promise { - return redis.client.getCache(`website:${websiteId}`, () => getWebsite(websiteId), 86400); + return redis.client.fetch(`website:${websiteId}`, () => getWebsite(websiteId), 86400); } async function storeWebsite(data: { id: any }) { const { id } = data; const key = `website:${id}`; - const obj = await redis.client.setCache(key, data); - await redis.client.expire(key, 86400); - - return obj; + return redis.client.store(key, data, 86400); } -async function deleteWebsite(id) { - return redis.client.deleteCache(`website:${id}`); +async function deleteWebsite(id: any) { + return redis.client.remove(`website:${id}`); } -async function fetchUser(id): Promise { - return redis.client.getCache(`user:${id}`, () => getUser(id, { includePassword: true }), 86400); +async function fetchUser(id: string): Promise { + return redis.client.fetch(`user:${id}`, () => getUser(id, { includePassword: true }), 86400); } -async function storeUser(data) { +async function storeUser(data: { id: any }) { const { id } = data; const key = `user:${id}`; - const obj = await redis.client.setCache(key, data); - await redis.client.expire(key, 86400); - - return obj; + return redis.client.store(key, data, 86400); } -async function deleteUser(id) { - return redis.client.deleteCache(`user:${id}`); +async function deleteUser(id: any) { + return redis.client.remove(`user:${id}`); } -async function fetchSession(id) { - return redis.client.getCache(`session:${id}`, () => getSession(id), 86400); +async function fetchSession(id: string) { + return redis.client.fetch(`session:${id}`, () => getSession(id), 86400); } -async function storeSession(data) { +async function storeSession(data: { id: any }) { const { id } = data; const key = `session:${id}`; - const obj = await redis.client.setCache(key, data); - await redis.client.expire(key, 86400); - - return obj; + return redis.client.store(key, data, 86400); } -async function deleteSession(id) { - return redis.client.deleteCache(`session:${id}`); +async function deleteSession(id: any) { + return redis.client.remove(`session:${id}`); } async function fetchUserBlock(userId: string) { diff --git a/yarn.lock b/yarn.lock index 8373fbf0..38812c61 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3200,10 +3200,10 @@ chalk "^4.1.2" debug "^4.3.4" -"@umami/redis-client@^0.18.0": - version "0.18.0" - resolved "https://registry.yarnpkg.com/@umami/redis-client/-/redis-client-0.18.0.tgz#6a2315a878f2688dae162d93e88dfc4e097fc48e" - integrity sha512-uDuX5w7ydlOZWrq0h6fADG3XWOhto9fAqrUVu85FUhdijWoGlv5f8adaL8FAah5jD+/Byw2VyGQaZO4VhboEZw== +"@umami/redis-client@^0.20.0": + version "0.20.0" + resolved "https://registry.yarnpkg.com/@umami/redis-client/-/redis-client-0.20.0.tgz#93b4598d68983b1ad266a0a527c56533c6248bf2" + integrity sha512-ACpoO+M/J2eLWEtusjbslhR4le+rPN4h9x7TXjaVJ905icVE0Qgu5y+A7nxXjcYvlgkHk+8HPeVeeaw5P+rxqw== dependencies: debug "^4.3.4" redis "^4.5.1"