Upstash
Upstash ↗ is a serverless database with Redis* and Kafka API. Upstash also offers QStash, a task queue/scheduler designed for the serverless.
Database Integrations allow you to connect to a database from your Worker by getting the right configuration from your database provider and adding it as secrets to your Worker.
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.
-
Add the Upstash Redis integration to your Worker:
- Log in to the Cloudflare dashboard ↗ and select your account.
- In Account Home, select Workers & Pages.
- In Overview, select your Worker.
- Select Settings > Integrations > Upstash Redis.
- Follow the setup flow, selecting the database created in step 1.
-
In your Worker, install the
@upstash/redis
, a HTTP client to connect to your database and start manipulating data: -
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 automatically added as secrets to your Worker through the integration.
To learn more about Upstash, refer to the Upstash documentation ↗.
To set up an integration with Upstash Kafka:
-
Create a Kafka cluster and topic ↗.
-
Add the Upstash Kafka integration to your Worker:
- Log in to the Cloudflare dashboard ↗ and select your account.
- In Account Home, select Workers & Pages.
- In Overview, select your Worker.
- Select Settings > Integrations > Upstash Kafka.
- Follow the setup flow, selecting the cluster and topic.
-
In your Worker, install
@upstash/kafka
, a HTTP/REST based Kafka client: -
Use the upstash-kafka ↗ JavaScript SDK to send data to Kafka.
Refer to Upstash documentation on Kafka setup with Workers ↗ for more information. Replace url
, username
and password
with the variables set by the integration.
To set up an integration with Upstash QStash:
-
Configure the publicly available HTTP endpoint ↗ that you want to send your messages to.
-
Add the Upstash QStash integration to your Worker:
- Log in to the Cloudflare dashboard ↗ and select your account.
- In Account Home, select Workers & Pages.
- In Overview, select your Worker.
- Select Integrations > Upstash QStash.
- Follow the setup flow.
-
In your Worker, install the
@upstash/qstash
, a HTTP client to connect to your database QStash endpoint: -
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.