Workers gain three Upstash integrations

Cloudflare has expanded its Database Integrations catalog with three new providers from Upstash: Redis, Kafka, and QStash. The integrations follow the same pattern as existing ones — pick the service, authorize via OAuth2, and the correct configuration is automatically stored as encrypted environment variables on your Worker.

The Redis integration is the clearest example of the workflow. From the Worker's Settings tab, open Integrations and select Upstash Redis. The setup page walks through granting permission for the integration to write secrets to your Worker, completing the OAuth2 connection to Upstash, and choosing which Redis database to attach. Once the database is selected, the integration retrieves the connection details and generates the credentials. Clicking "Add Integration" finishes the job, and the credentials are immediately available as environment variables in your Worker code.

A short demonstration

The integration can be exercised with a simple region-based greeting. Using the CF-IPCountry header, a Worker can return a custom greeting for visitors from Paraguay, the United States, Great Britain, and the Netherlands, with a generic fallback for everyone else.

Load the greeting messages into Upstash Redis first, using its online CLI:

➜ set PY "Mba'ẽichapa 🇵🇾"
OK
➜ set US "How are you? 🇺🇸"
OK
➜ set GB "How do you do? 🇬🇧"
OK
➜ set NL "Hoe gaat het met u? 🇳🇱"
OK

Next, install the @upstash/redis package on the Worker and upload the code:

import { Redis } from '@upstash/redis/cloudflare'
 
export default {
  async fetch(request, env, ctx) {
    const country = request.headers.get("cf-ipcountry");
    const redis = Redis.fromEnv(env);
    if (country) {
      const localizedMessage = await redis.get(country);
      if (localizedMessage) {
        return new Response(localizedMessage);
      }
    }
    return new Response("👋👋 Hello there! 👋👋");
  },
};

The Worker reads the visitor's country from the request header, looks up the corresponding greeting in Redis, and responds accordingly.

Performance considerations

For write-heavy workloads, Smart Placement can move Worker execution closer to the Upstash Redis instance, avoiding the network round trip between the Worker's default location and the database. Alternatively, an Upstash Global Database spreads multiple read replicas across regions, which helps reduce latency for read-heavy traffic patterns.

All three Upstash integrations (Redis, Kafka, and QStash) are now available to every Cloudflare user. Additional database providers are expected to be added to the catalog over time.