Conditionally instantiate redis

This commit is contained in:
Sam Becker 2025-02-19 18:48:29 -06:00
parent d973b95d00
commit 5f8708bd17
2 changed files with 5 additions and 4 deletions

View File

@ -10,7 +10,7 @@ import {
import { removeBase64Prefix } from '@/utility/image';
import { cleanUpAiTextResponse } from '@/photo/ai';
const redis = Redis.fromEnv();
const redis = HAS_REDIS_STORAGE ? Redis.fromEnv() : undefined;
const RATE_LIMIT_IDENTIFIER = 'openai-image-query';
const RATE_LIMIT_MAX_QUERIES_PER_HOUR = 100;
@ -20,7 +20,7 @@ const openai = AI_TEXT_GENERATION_ENABLED
? createOpenAI({ apiKey: process.env.OPENAI_SECRET_KEY })
: undefined;
const ratelimit = HAS_REDIS_STORAGE
const ratelimit = redis
? new Ratelimit({
redis,
limiter: Ratelimit.slidingWindow(RATE_LIMIT_MAX_QUERIES_PER_HOUR, '1h'),

View File

@ -1,5 +1,6 @@
import { Redis } from '@upstash/redis';
import { HAS_REDIS_STORAGE } from '@/app/config';
const redis = Redis.fromEnv();
const redis = HAS_REDIS_STORAGE ? Redis.fromEnv() : undefined;
export const testRedisConnection = () => redis.get('test');
export const testRedisConnection = () => redis?.get('test');