mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-24 01:36:48 +08:00
incrementAPICallCount
This commit is contained in:
@@ -68,6 +68,31 @@ export const incrementSessionRefreshCount = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const incrementAPICallCount = async (
|
||||
email: string | undefined,
|
||||
modelIdentifier: string,
|
||||
dateKey: string
|
||||
): Promise<void> => {
|
||||
if (!email || !modelIdentifier) {
|
||||
console.error('Email or model identifier is undefined, cannot increment API call count.');
|
||||
return; // This is fine for a function returning Promise<void>
|
||||
}
|
||||
|
||||
const redis = getRedisClient();
|
||||
if (!redis) {
|
||||
console.error('Redis client is not initialized.');
|
||||
return; // This is fine for a function returning Promise<void>
|
||||
}
|
||||
|
||||
const key = `api_calls:${email}:${modelIdentifier}`;
|
||||
|
||||
try {
|
||||
await redis.hincrby(key, dateKey, 1);
|
||||
} catch (error) {
|
||||
console.error('Failed to increment API call count in Redis via Upstash', error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const incrementTokenCounts = async (
|
||||
email: string | undefined,
|
||||
|
||||
Reference in New Issue
Block a user