Updated redis calls.

This commit is contained in:
Mike Cao 2023-11-27 20:47:35 -08:00
parent 4c0beaee14
commit f7dd0464e0
9 changed files with 44 additions and 45 deletions

View file

@ -3,67 +3,71 @@ import redis from '@umami/redis-client';
import { getSession, getUserById, getWebsiteById } from '../queries';
async function fetchWebsite(id): Promise<Website> {
return redis.getCache(`website:${id}`, () => getWebsiteById(id), 86400);
return redis.client.getCache(`website:${id}`, () => getWebsiteById(id), 86400);
}
async function storeWebsite(data) {
const { id } = data;
const key = `website:${id}`;
const obj = await redis.setCache(key, data);
await redis.expire(key, 86400);
const obj = await redis.client.setCache(key, data);
await redis.client.expire(key, 86400);
return obj;
}
async function deleteWebsite(id) {
return redis.deleteCache(`website:${id}`);
return redis.client.deleteCache(`website:${id}`);
}
async function fetchUser(id): Promise<User> {
return redis.getCache(`user:${id}`, () => getUserById(id, { includePassword: true }), 86400);
return redis.client.getCache(
`user:${id}`,
() => getUserById(id, { includePassword: true }),
86400,
);
}
async function storeUser(data) {
const { id } = data;
const key = `user:${id}`;
const obj = await redis.setCache(key, data);
await redis.expire(key, 86400);
const obj = await redis.client.setCache(key, data);
await redis.client.expire(key, 86400);
return obj;
}
async function deleteUser(id) {
return redis.deleteCache(`user:${id}`);
return redis.client.deleteCache(`user:${id}`);
}
async function fetchSession(id) {
return redis.getCache(`session:${id}`, () => getSession(id), 86400);
return redis.client.getCache(`session:${id}`, () => getSession(id), 86400);
}
async function storeSession(data) {
const { id } = data;
const key = `session:${id}`;
const obj = await redis.setCache(key, data);
await redis.expire(key, 86400);
const obj = await redis.client.setCache(key, data);
await redis.client.expire(key, 86400);
return obj;
}
async function deleteSession(id) {
return redis.deleteCache(`session:${id}`);
return redis.client.deleteCache(`session:${id}`);
}
async function fetchUserBlock(userId: string) {
const key = `user:block:${userId}`;
return redis.get(key);
return redis.client.get(key);
}
async function incrementUserBlock(userId: string) {
const key = `user:block:${userId}`;
return redis.incr(key);
return redis.client.incr(key);
}
export default {