redis env 2

This commit is contained in:
DirkSchlossmacher 2023-11-13 15:18:57 +01:00
parent 9496f6bb4d
commit 83ed6bfc0b

View File

@ -1,18 +1,20 @@
// redisRestClient.ts // redisRestClient.ts
import { Redis } from "@upstash/redis"; import { Redis } from "@upstash/redis";
const redisUrl = process.env.UPSTASH_REDIS_URL ?? ""; // Check if the environment variables are set
const redisToken = process.env.UPSTASH_REDIS_REST_TOKEN ?? ""; const redisUrl = process.env.UPSTASH_REDIS_URL;
const redisToken = process.env.UPSTASH_REDIS_REST_TOKEN;
if (!redisUrl || !redisToken) {
throw new Error('The Upstash Redis URL and token must be provided.');
}
// Create the Redis instance with the known-to-be-defined values
const redis = new Redis({ const redis = new Redis({
url: redisUrl, url: redisUrl,
token: redisToken, token: redisToken,
}); });
if (!redis.url || !redis.token) {
console.error('The Upstash Redis URL and token must be provided.');
// Handle the lack of Redis client here, e.g., by disabling certain features
}
export const incrementSignInCount = async (email: string | undefined, dateKey: string) => { export const incrementSignInCount = async (email: string | undefined, dateKey: string) => {
if (!email) { if (!email) {