mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-09 19:46:37 +08:00
redis no error
This commit is contained in:
parent
14795c50c0
commit
993c7be12d
@ -1,20 +1,33 @@
|
|||||||
// redisRestClient.ts
|
// redisRestClient.ts
|
||||||
import { Redis } from "@upstash/redis";
|
import { Redis } from "@upstash/redis";
|
||||||
|
|
||||||
// Check if the environment variables are set
|
let redis: Redis | undefined;
|
||||||
const redisUrl = process.env.UPSTASH_REDIS_URL;
|
|
||||||
const redisToken = process.env.UPSTASH_REDIS_REST_TOKEN;
|
|
||||||
|
|
||||||
if (!redisUrl || !redisToken) {
|
const getRedisClient = () => {
|
||||||
throw new Error('The Upstash Redis URL and token must be provided.');
|
if (!redis) {
|
||||||
}
|
const redisUrl = process.env.UPSTASH_REDIS_URL;
|
||||||
|
const redisToken = process.env.UPSTASH_REDIS_REST_TOKEN;
|
||||||
|
|
||||||
// Create the Redis instance with the known-to-be-defined values
|
if (!redisUrl || !redisToken) {
|
||||||
const redis = new Redis({
|
// Handle missing environment variables more gracefully
|
||||||
url: redisUrl,
|
console.error('The Upstash Redis URL and token must be provided.');
|
||||||
token: redisToken,
|
return null; // Or throw an error if that's the desired behavior
|
||||||
});
|
}
|
||||||
|
|
||||||
|
redis = new Redis({
|
||||||
|
url: redisUrl,
|
||||||
|
token: redisToken,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return redis;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Use getRedisClient() to access the Redis client in your functions
|
||||||
|
export const incrementSignInCount = async (email: string | undefined, dateKey: string) => {
|
||||||
|
const redis = getRedisClient();
|
||||||
|
// ... rest of your function
|
||||||
|
};
|
||||||
|
|
||||||
export const incrementSignInCount = async (email: string | undefined, dateKey: string) => {
|
export const incrementSignInCount = async (email: string | undefined, dateKey: string) => {
|
||||||
if (!email) {
|
if (!email) {
|
||||||
|
Loading…
Reference in New Issue
Block a user