redisRestClient rework

This commit is contained in:
DirkSchlossmacher 2023-11-14 13:03:33 +01:00
parent c93d001be5
commit 4cb13df34f

View File

@ -24,16 +24,19 @@ const getRedisClient = () => {
export const incrementSignInCount = async (email: string | undefined, dateKey: string) => { export const incrementSignInCount = async (
email: string | undefined,
dateKey: string
): Promise<void> => {
if (!email) { if (!email) {
console.error('Email is undefined, cannot increment sign-in count.'); console.error('Email is undefined, cannot increment sign-in count.');
return; return; // This is fine for a function returning Promise<void>
} }
const redis = getRedisClient(); const redis = getRedisClient();
if (!redis) { if (!redis) {
console.error('Redis client is not initialized.'); console.error('Redis client is not initialized.');
return; return; // This is fine for a function returning Promise<void>
} }
try { try {
@ -43,16 +46,19 @@ export const incrementSignInCount = async (email: string | undefined, dateKey: s
} }
}; };
export const incrementSessionRefreshCount = async (email: string | undefined, dateKey: string) => { export const incrementSessionRefreshCount = async (
email: string | undefined,
dateKey: string
): Promise<void> => {
if (!email) { if (!email) {
console.error('Email is undefined, cannot increment session refresh count.'); console.error('Email is undefined, cannot increment session refresh count.');
return; return; // This is fine for a function returning Promise<void>
} }
const redis = getRedisClient(); const redis = getRedisClient();
if (!redis) { if (!redis) {
console.error('Redis client is not initialized.'); console.error('Redis client is not initialized.');
return; return; // This is fine for a function returning Promise<void>
} }
try { try {
@ -62,6 +68,7 @@ export const incrementSessionRefreshCount = async (email: string | undefined, da
} }
}; };
export const incrementTokenCounts = async ( export const incrementTokenCounts = async (
email: string | undefined, email: string | undefined,
dateKey: string, dateKey: string,
@ -93,7 +100,7 @@ export const getAvailableDateKeys = async (): Promise<string[]> => {
const redis = getRedisClient(); const redis = getRedisClient();
if (!redis) { if (!redis) {
console.error('Redis client is not initialized.'); console.error('Redis client is not initialized.');
return; return []; // Return an empty array explicitly
} }
try { try {
@ -139,9 +146,9 @@ export const getDetailsByUser = async (dateKey: string): Promise<Record<string,
const redis = getRedisClient(); const redis = getRedisClient();
if (!redis) { if (!redis) {
console.error('Redis client is not initialized.'); console.error('Redis client is not initialized.');
return; return {};
} }
try { try {
const rawCounts = await redis.hgetall(`signin_count:${dateKey}`); const rawCounts = await redis.hgetall(`signin_count:${dateKey}`);
const counts: Record<string, number> = {}; const counts: Record<string, number> = {};