Safe, typed Redis operations with env validation, timeout handling and diagnostics for serverless environments.
// Source: https://github.com/mperkins0155/llms-txt-hub | License: MIT | Copyright 2025 David Dias
// Provided via justclaw.it.com; keep this notice with the code.
import { logger } from '@thedaviddias/logging'
import type { Redis } from '@upstash/redis'
/**
* Upstash Redis client configuration with security and error handling
* HTTP-based Redis client optimized for serverless environments
*/
// Validate required environment variables
const requiredEnvVars = {
KV_REST_API_URL: process.env.KV_REST_API_URL,
KV_REST_API_TOKEN: process.env.KV_REST_API_TOKEN
}
// Check for missing environment variables
const missingEnvVars = Object.entries(requiredEnvVars)
.filter(([_, value]) => !value)
.map(([key, _]) => key)
const REDIS_OPERATION_TIMEOUT_MS = 1_500
let redisUnavailableLogged =
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key