## TL;DR

Use the Workers-specific import.

## Steps

1. Workers cannot open TCP sockets, so the HTTP-based SDK is the only way
to reach Upstash Redis from a Worker. Use the Workers-specific import.

2. import { Redis } from "@upstash/redis/cloudflare";

3. export default {
 async fetch(request, env) {
 const redis = Redis.fromEnv(env);
 const count = await redis.incr("hits");
 return new Response("hits: " + count);
 },
};

4. In a service-worker style worker, Redis.fromEnv() with no args reads
from the global scope.

5. If you use @upstash/ratelimit with analytics or multi-region sync, grab
the pending promise from limit() and hand it to context.waitUntil so the
background work finishes after the response goes out:

6. const { success, pending } = await ratelimit.limit("id");
context.waitUntil(pending);

7. Workers have a limit of 6 simultaneous subrequests. The SDKs
auto-pipelining batches your commands into fewer HTTP requests, which
matters here. Fire independent commands together with Promise.all
instead of awaiting each one.

## When to use

You are seeing this: Workers cannot open TCP sockets, so the HTTP-based SDK is the only way to reach Upstash Redis from a Worker. Use this skill when you run into "upstash/redis on Cloudflare Workers: the cloudflare import, wrangler secrets, fromEnv(env)".

## 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.
