One nullable Redis client, three callers, and three different answers to "Redis is not configured"
The Redis helper in Nakodo is twelve lines. It returns an Upstash client when the environment has either the UPSTASH_REDIS_REST_* pair or the KV_REST_API_* pair that Vercel's integration sets, and null otherwise. Null is the default on a laptop and on a preview deployment. export function redisFromEnv ( ) : Redis | null { const configured = ( env ( "UPSTASH_REDIS_REST_URL" ) || env (…
The Redis helper in Nakodo is a short function that returns an Upstash client when specific environment variables are set, or null otherwise. This null value is the default on laptops and preview deployments. The function can return null, causing different behaviors in its three callers and one script.
1. The rate limiter, found in src/lib/ratelimit.ts, returns null when there is no Redis, allowing requests to proceed without limitation. A comment explains that this prevents sign-in from being blocked if Redis is missing or broken. In case of failure, a one-second delay allows the request to go through, with a logged error. An asymmetry exists: on a live deployment without Redis, a log message is displayed, while locally, no log is shown.
2. The place search, located in src/lib/places/geocode.ts, uses Redis to limit requests to one per second. If Redis is unavailable, a Map and timestamp are used to limit requests per process. This approach is different from the first one, as it limits requests per process instead of globally, avoiding potential issues with third-party limits.
3. The sitemap announcer, found in src/lib/seo/indexnow.ts, runs hourly and notifies search engines about pages with updated dates. When Redis is not configured, it returns a message indicating that Redis isn't configured and skips announcing pages. This approach, called "fail closed," prevents unnecessary noise in search engines' systems but may lead to re-announcing all pages every hour if Redis were available.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to
More from Dev.to on urgent.news
Report a problem with this story
Get the day's news by email. Daily, weekly or monthly. Sign up