mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 14:47:14 +01:00
Update redis package.
This commit is contained in:
parent
6291654748
commit
7f1f3b685a
8 changed files with 26 additions and 29 deletions
|
|
@ -2,60 +2,58 @@ import { User, Website } from '@prisma/client';
|
|||
import redis from '@umami/redis-client';
|
||||
import { getSession, getUserById, getWebsiteById } from '../queries';
|
||||
|
||||
const { fetchObject, storeObject, deleteObject, expire } = redis;
|
||||
|
||||
async function fetchWebsite(id): Promise<Website> {
|
||||
return fetchObject(`website:${id}`, () => getWebsiteById(id), 86400);
|
||||
return redis.fetchObject(`website:${id}`, () => getWebsiteById(id), 86400);
|
||||
}
|
||||
|
||||
async function storeWebsite(data) {
|
||||
const { id } = data;
|
||||
const key = `website:${id}`;
|
||||
|
||||
const obj = await storeObject(key, data);
|
||||
await expire(key, 86400);
|
||||
const obj = await redis.storeObject(key, data);
|
||||
await redis.expire(key, 86400);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
async function deleteWebsite(id) {
|
||||
return deleteObject(`website:${id}`);
|
||||
return redis.deleteObject(`website:${id}`);
|
||||
}
|
||||
|
||||
async function fetchUser(id): Promise<User> {
|
||||
return fetchObject(`user:${id}`, () => getUserById(id, { includePassword: true }), 86400);
|
||||
return redis.fetchObject(`user:${id}`, () => getUserById(id, { includePassword: true }), 86400);
|
||||
}
|
||||
|
||||
async function storeUser(data) {
|
||||
const { id } = data;
|
||||
const key = `user:${id}`;
|
||||
|
||||
const obj = await storeObject(key, data);
|
||||
await expire(key, 86400);
|
||||
const obj = await redis.storeObject(key, data);
|
||||
await redis.expire(key, 86400);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
async function deleteUser(id) {
|
||||
return deleteObject(`user:${id}`);
|
||||
return redis.deleteObject(`user:${id}`);
|
||||
}
|
||||
|
||||
async function fetchSession(id) {
|
||||
return fetchObject(`session:${id}`, () => getSession(id), 86400);
|
||||
return redis.fetchObject(`session:${id}`, () => getSession(id), 86400);
|
||||
}
|
||||
|
||||
async function storeSession(data) {
|
||||
const { id } = data;
|
||||
const key = `session:${id}`;
|
||||
|
||||
const obj = await storeObject(key, data);
|
||||
await expire(key, 86400);
|
||||
const obj = await redis.storeObject(key, data);
|
||||
await redis.expire(key, 86400);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
async function deleteSession(id) {
|
||||
return deleteObject(`session:${id}`);
|
||||
return redis.deleteObject(`session:${id}`);
|
||||
}
|
||||
|
||||
async function fetchUserBlock(userId: string) {
|
||||
|
|
@ -80,5 +78,5 @@ export default {
|
|||
deleteSession,
|
||||
fetchUserBlock,
|
||||
incrementUserBlock,
|
||||
enabled: redis.enabled,
|
||||
enabled: !!redis,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue