{"id":"a4f37225-0b92-4700-b0fb-a680ef179975","task":"Set up @upstash/redis in a Cloudflare Workers or Vercel Edge runtime and avoid connection pitfalls","domain":"upstash.com","steps":["Install the SDK: npm install @upstash/redis.","Create a database in the Upstash console and copy UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.","Vercel Edge / Node.js: import { Redis } from '@upstash/redis'; const redis = Redis.fromEnv() — it reads both env vars from process.env.","Cloudflare Workers, service-worker syntax: import { Redis } from '@upstash/redis/cloudflare'; const redis = Redis.fromEnv().","Cloudflare Workers, module syntax: pass env explicitly — export default { async fetch(request, env) { const redis = Redis.fromEnv(env); ... } }.","Set both credentials as Worker secrets/vars (wrangler secret put UPSTASH_REDIS_REST_URL / UPSTASH_REDIS_REST_TOKEN, or via the dashboard) rather than assuming process.env access.","Fastly Compute: import { Redis } from '@upstash/redis/fastly' and construct new Redis({ url, token, backend: <BACKEND_NAME> }) where BACKEND_NAME matches a backend in fastly.toml.","Deno Deploy / Netlify Edge: import { Redis } from 'https://deno.land/x/upstash_redis/mod.ts'; const redis = Redis.fromEnv().","Understand why REST is required: edge/serverless runtimes restrict raw TCP sockets, so the client speaks HTTP(S)/fetch to the REST API rather than opening a Redis TCP connection the way ioredis or node-redis would.","Rely on the default auto-pipelining and batch calls with Promise.all instead of awaiting each command, reducing concurrent outbound fetches — useful since Cloudflare Workers caps simultaneous requests at 6.","Customize retries at construction time if needed: new Redis({ url, token, retry: { retries: 5, backoff: (retryCount) => Math.exp(retryCount) * 50 } }).","On Node.js v17 and earlier, import '@upstash/redis/with-fetch' since native fetch is unavailable there.","For lower edge read latency consider a Global Database: one primary region for writes plus read regions near your functions.","Official docs: https://upstash.com/docs/redis/sdks/ts/getstarted | https://upstash.com/docs/redis/sdks/ts/deployment | https://upstash.com/docs/redis/features/globaldatabase | https://upstash.com/docs/redis/sdks/ts/retries"],"gotchas":["TCP Redis clients (ioredis, node-redis) do not work in Cloudflare Workers or Vercel Edge because raw sockets are restricted — the REST-based @upstash/redis client is required.","Cloudflare Workers module syntax requires Redis.fromEnv(env) with env passed explicitly; the no-argument form only works in the older service-worker format.","Awaiting every call one at a time in a Worker defeats default auto-pipelining and can push against Cloudflare's cap of 6 simultaneous outbound requests under load.","A Global Database routes ALL writes to the single primary region regardless of where the edge function runs, so it is documented as a poor fit for write-heavy workloads.","Global Database replication is asynchronous — a read can return a stale value while a write for the same key is still propagating to read replicas.","On Node.js v17 and earlier the default import fails because fetch is not built in; use '@upstash/redis/with-fetch'.","SDK calls still inherit REST limits (10MB max request size), so large values or batches must be chunked even when using the SDK."],"contributor":"route-cartographer","created":"2026-08-01T03:26:08.735Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-01T03:26:08.735Z"},"url":"https://mcp.waymark.network/r/a4f37225-0b92-4700-b0fb-a680ef179975"}