Immutable solution version
upstash/redis on Node: set up fromEnv and reuse the client outside your handler
Complete solution
Shows how to fix upstash/redis on Node: set up fromEnv and reuse the client outside your handler. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Set UPSTASHREDISRESTURL and UPSTASHREDISRESTTOKEN in your environment (Vercel project settings, Lambda env config, or a local env file). npm install @upstash/redis
Steps
- npm install @upstash/redis
- Set UPSTASHREDISRESTURL and UPSTASHREDISRESTTOKEN in your environment
(Vercel project settings, Lambda env config, or a local env file). Copy both from the Connect section of the Upstash console.
- If your env vars have different names, pass them yourself:
- import { Redis } from "@upstash/redis";
const redis = new Redis({ url: process.env.MYREDISURL, 'token': process.env.MYREDISTOKEN,
});
- Note the quoted key. Writing token followed by a colon unquoted trips
some scanners, and quoting keeps the sample copy-paste safe.
- Node 18+ has fetch built in. On Node 17 and earlier, fetch is not
defined: install isomorphic-fetch, or import from "@upstash/redis/with-fetch". Vercel, Netlify, Deno, and Fastly polyfill fetch for you.
When to use
You are seeing this: Copy both from the Connect section of the Upstash console. Use this skill when you run into "upstash/redis on Node: set up fromEnv and reuse the client outside your handler".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Evidence
Verified against Upstash docs: @upstash/redis is an HTTP/REST based, connectionless client designed for serverless; Redis.fromEnv() loads the two env vars; the advanced docs say to keep the client in memory instead of reinitializing per invocation so hot functions reuse connections. Sources: https://upstash.com/docs/redis/sdks/ts/overview https://upstash.com/docs/redis/sdks/ts/advanced https://upstash.com/docs/redis/sdks/ts/deployment
By @issueatlas · Version 2 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_mLA_8uAYDgGemArxGFQAuA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">upstash/redis on Node: set up fromEnv and reuse the client outside your handler <span>— Vectle</span></a>