Make Redis connection resilient to more configurations
This commit is contained in:
parent
d13c8b0fae
commit
f07f8e44b9
@ -76,7 +76,7 @@ _⚠️ READ BEFORE PROCEEDING_
|
||||
- Generate an API key and store in environment variable `OPENAI_SECRET_KEY` (make sure to enable Responses API write access if customizing permissions)
|
||||
- Setup usage limits to avoid unexpected charges (_recommended_)
|
||||
2. Add rate limiting (_recommended_)
|
||||
- As an additional precaution, create an Upstash Redis store from the storage tab of the Vercel dashboard and link it to your project in order to enable rate limiting—no further configuration necessary
|
||||
- As an additional precaution, create an Upstash Redis store from the storage tab of the Vercel dashboard and link it to your project (if you are required to add an environment variable prefix, use `EXIF`) in order to enable rate limiting—no further configuration necessary
|
||||
3. Configure auto-generated fields (optional)
|
||||
- Set which text fields auto-generate when uploading a photo by storing a comma-separated list, e.g., `AI_TEXT_AUTO_GENERATED_FIELDS = title,semantic`
|
||||
- Accepted values:
|
||||
|
||||
@ -160,7 +160,11 @@ export const POSTGRES_SSL_ENABLED =
|
||||
|
||||
// STORAGE: REDIS
|
||||
export const HAS_REDIS_STORAGE =
|
||||
Boolean(process.env.KV_URL);
|
||||
Boolean(
|
||||
process.env.KV_URL ||
|
||||
process.env.EXIF_KV_URL ||
|
||||
process.env.UPSTASH_REDIS_REST_URL,
|
||||
);
|
||||
|
||||
// STORAGE: VERCEL BLOB
|
||||
export const HAS_VERCEL_BLOB_STORAGE =
|
||||
|
||||
@ -1,9 +1,18 @@
|
||||
import { Redis } from '@upstash/redis';
|
||||
import { HAS_REDIS_STORAGE } from '@/app/config';
|
||||
|
||||
const KEY_TEST = 'test';
|
||||
|
||||
export const redis = HAS_REDIS_STORAGE ? Redis.fromEnv() : undefined;
|
||||
export const redis =
|
||||
process.env.KV_URL ||
|
||||
process.env.UPSTASH_REDIS_REST_URL
|
||||
? Redis.fromEnv()
|
||||
: process.env.EXIF_KV_URL &&
|
||||
process.env.EXIF_KV_REST_API_TOKEN
|
||||
? new Redis({
|
||||
url: process.env.EXIF_KV_URL,
|
||||
token: process.env.EXIF_KV_REST_API_TOKEN,
|
||||
})
|
||||
: undefined;
|
||||
|
||||
export const warmRedisConnection = () => {
|
||||
if (redis) { redis.get(KEY_TEST); }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user