Skip to main content

Database Setup

Create a Redis database using Upstash Console or Upstash CLI.

Project Setup

We will use C3 (create-cloudflare-cli) command-line tool to create our application. You can open a new terminal window and run C3 using the prompt below.
This will create a new Cloudflare Workers project:
We will also install the Upstash Redis SDK to connect to Redis.

The Code

Here is a Worker template to configure and test Upstash Redis connection.

Configure Credentials

Navigate to Upstash Console and copy/paste your UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN to your wrangler.toml as below.

Test and Deploy

You can test the function locally with npx wrangler dev Deploy your function to Cloudflare with npx wrangler deploy The endpoint of the function will be provided to you, once the deployment is done.

Repositories

Javascript: https://github.com/upstash/upstash-redis/tree/main/examples/cloudflare-workers Typescript: https://github.com/upstash/upstash-redis/tree/main/examples/cloudflare-workers-with-typescript