Upstash
Upstash ↗ is a serverless database with Redis* and Kafka API. Upstash also offers QStash, a task queue/scheduler designed for the serverless.
To set up an integration with Upstash:
-
You need an existing Upstash database to connect to. Create an Upstash database ↗ or load data from an existing database to Upstash ↗.
-
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 ↗ locally and run the following commands.
Terminal window set GB "Ey up?"OKTerminal window set US "Yo, what’s up?"OKTerminal window set NL "Hoi, hoe gaat het?"OK -
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 ↗ under your database details, then add them as secrets using Wrangler:
Terminal window # Add the Upstash Redis URL as a secretnpx wrangler secret put UPSTASH_REDIS_REST_URL# When prompted, paste your Upstash Redis REST URL# Add the Upstash Redis token as a secretnpx wrangler secret put UPSTASH_REDIS_REST_TOKEN# When prompted, paste your Upstash Redis REST token -
In your Worker, install the
@upstash/redis, a HTTP client to connect to your database and start manipulating data:Terminal window npm i @upstash/redisTerminal window yarn add @upstash/redisTerminal window pnpm add @upstash/redis -
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!");},};
To learn more about Upstash, refer to the Upstash documentation ↗.
To set up an integration with Upstash QStash:
-
Configure the publicly available HTTP endpoint ↗ that you want to send your messages to.
-
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 ↗ under QStash settings, then add it as a secret using Wrangler:
Terminal window # Add the QStash token as a secretnpx wrangler secret put QSTASH_TOKEN# When prompted, paste your QStash token -
In your Worker, install the
@upstash/qstash, a HTTP client to connect to your database QStash endpoint:Terminal window npm i @upstash/qstashTerminal window yarn add @upstash/qstashTerminal window pnpm add @upstash/qstash -
Refer to the Upstash documentation on how to receive webhooks from QStash in your Cloudflare Worker ↗.
* 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.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark
-