mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-09 03:26:38 +08:00
ioredis and redisClient
This commit is contained in:
parent
f1bb136486
commit
038c57ff0f
34
app/utils/cloud/redisClient.ts
Normal file
34
app/utils/cloud/redisClient.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// redisClient.ts
|
||||||
|
import Redis from 'ioredis';
|
||||||
|
|
||||||
|
const redis = new Redis(process.env.UPSTASH_REDIS_URL);
|
||||||
|
|
||||||
|
export const incrementSignInCount = async (email: string | undefined, dateKey: string) => {
|
||||||
|
if (!email) {
|
||||||
|
console.error('Email is undefined, cannot increment sign-in count.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await redis.hincrby(`sign_ins:${email}`, dateKey, 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const incrementSessionRefreshCount = async (email: string | undefined, dateKey: string) => {
|
||||||
|
if (!email) {
|
||||||
|
console.error('Email is undefined, cannot increment session refresh count.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await redis.hincrby(`session_refreshes:${email}`, dateKey, 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const incrementTokenCounts = async (
|
||||||
|
email: string | undefined,
|
||||||
|
dateKey: string,
|
||||||
|
completionTokens: number,
|
||||||
|
promptTokens: number
|
||||||
|
) => {
|
||||||
|
if (!email) {
|
||||||
|
console.error('Email is undefined, cannot increment token counts.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await redis.hincrby(`tokens:${email}`, `${dateKey}:completion_tokens`, completionTokens);
|
||||||
|
await redis.hincrby(`tokens:${email}`, `${dateKey}:prompt_tokens`, promptTokens);
|
||||||
|
};
|
@ -40,7 +40,8 @@
|
|||||||
"sass": "^1.59.2",
|
"sass": "^1.59.2",
|
||||||
"spark-md5": "^3.0.2",
|
"spark-md5": "^3.0.2",
|
||||||
"use-debounce": "^9.0.4",
|
"use-debounce": "^9.0.4",
|
||||||
"zustand": "^4.3.8"
|
"zustand": "^4.3.8",
|
||||||
|
"ioredis": "^5.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tauri-apps/cli": "^1.4.0",
|
"@tauri-apps/cli": "^1.4.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user