---
title: Upstash
description: Connect Cloudflare Workers to Upstash for serverless Redis and Kafka integrations.
image: https://developers.cloudflare.com/dev-products-preview.png
---

> Documentation Index  
> Fetch the complete documentation index at: https://developers.cloudflare.com/workers/llms.txt  
> Use this file to discover all available pages before exploring further.

[Skip to content](#%5Ftop) 

# Upstash

[Upstash ↗](https://upstash.com/) is a serverless database with Redis\* and Kafka API. Upstash also offers QStash, a task queue/scheduler designed for the serverless.

## Upstash for Redis

To set up an integration with Upstash:

1. You need an existing Upstash database to connect to. [Create an Upstash database ↗](https://docs.upstash.com/redis#create-a-database) or [load data from an existing database to Upstash ↗](https://docs.upstash.com/redis/howto/connectclient).
2. Insert some data to your Upstash database. You can add data to your Upstash database in two ways:  
   * Use the CLI directly from your Upstash console.  
   * Alternatively, install [redis-cli ↗](https://redis.io/docs/getting-started/installation/) locally and run the following commands.  
Terminal window  
```  
set GB "Ey up?"  
```  
```  
OK  
```  
Terminal window  
```  
set US "Yo, what’s up?"  
```  
```  
OK  
```  
Terminal window  
```  
set NL "Hoi, hoe gaat het?"  
```  
```  
OK  
```
3. Configure the Upstash Redis credentials in your Worker:  
You need to add your Upstash Redis database URL and token as secrets to your Worker. Get these from your [Upstash Console ↗](https://console.upstash.com) under your database details, then add them as secrets using Wrangler:  
Terminal window  
```  
# Add the Upstash Redis URL as a secret  
npx wrangler secret put UPSTASH_REDIS_REST_URL  
# When prompted, paste your Upstash Redis REST URL  
# Add the Upstash Redis token as a secret  
npx wrangler secret put UPSTASH_REDIS_REST_TOKEN  
# When prompted, paste your Upstash Redis REST token  
```
4. In your Worker, install the `@upstash/redis`, a HTTP client to connect to your database and start manipulating data:  
 npm  yarn  pnpm  bun  
```  
npm i @upstash/redis  
```  
```  
yarn add @upstash/redis  
```  
```  
pnpm add @upstash/redis  
```  
```  
bun add @upstash/redis  
```
5. The following example shows how to make a query to your Upstash database in a Worker. The credentials needed to connect to Upstash have been added as secrets to your Worker.  
JavaScript  
```  
import { Redis } from "@upstash/redis/cloudflare";  
export default {  
  async fetch(request, env) {  
    const redis = Redis.fromEnv(env);  
    const country = request.headers.get("cf-ipcountry");  
    if (country) {  
      const greeting = await redis.get(country);  
      if (greeting) {  
        return new Response(greeting);  
      }  
    }  
    return new Response("Hello What's up!");  
  },  
};  
```  
Note  
`Redis.fromEnv(env)` automatically picks up the default `url` and `token` names created in the integration.  
If you have renamed the secrets, you must declare them explicitly like in the [Upstash basic example ↗](https://docs.upstash.com/redis/sdks/redis-ts/getstarted#basic-usage).

To learn more about Upstash, refer to the [Upstash documentation ↗](https://docs.upstash.com/redis).

## Upstash QStash

To set up an integration with Upstash QStash:

1. Configure the [publicly available HTTP endpoint ↗](https://docs.upstash.com/qstash#1-public-api) that you want to send your messages to.
2. Configure the Upstash QStash credentials in your Worker:  
You need to add your Upstash QStash token as a secret to your Worker. Get your token from your [Upstash Console ↗](https://console.upstash.com) under QStash settings, then add it as a secret using Wrangler:  
Terminal window  
```  
# Add the QStash token as a secret  
npx wrangler secret put QSTASH_TOKEN  
# When prompted, paste your QStash token  
```
3. In your Worker, install the `@upstash/qstash`, a HTTP client to connect to your database QStash endpoint:  
 npm  yarn  pnpm  bun  
```  
npm i @upstash/qstash  
```  
```  
yarn add @upstash/qstash  
```  
```  
pnpm add @upstash/qstash  
```  
```  
bun add @upstash/qstash  
```
4. Refer to the [Upstash documentation on how to receive webhooks from QStash in your Cloudflare Worker ↗](https://docs.upstash.com/qstash/quickstarts/cloudflare-workers#3-use-qstash-in-your-handler).

\* Redis is a trademark of Redis Ltd. Any rights therein are reserved to Redis Ltd. Any use by Upstash is for referential purposes only and does not indicate any sponsorship, endorsement or affiliation between Redis and Upstash.

```json
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"/directory/","name":"Directory"}},{"@type":"ListItem","position":2,"item":{"@id":"/workers/","name":"Workers"}},{"@type":"ListItem","position":3,"item":{"@id":"/workers/databases/","name":"Databases"}},{"@type":"ListItem","position":4,"item":{"@id":"/workers/databases/third-party-integrations/","name":"3rd Party Integrations"}},{"@type":"ListItem","position":5,"item":{"@id":"/workers/databases/third-party-integrations/upstash/","name":"Upstash"}}]}
```
