Database Setup
Create a Redis database using Upstash Console or Upstash CLI. Select the global to minimize the latency from all edge locations.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.create-cloudflare
package, and lead you through setup. C3 will also install Wrangler in projects by default, which helps us testing and deploying the application.
The Code
Here is a Worker template to configure and test Upstash Redis connection.Configure Credentials
There are two methods for setting up the credentials for Upstash Redis client. The recommended way is to use Cloudflare Upstash Integration. Alternatively, you can add the credentials manually.Using the Cloudflare Integration
Access to the Cloudflare Dashboard and login with the same account that you’ve used while setting up the Worker application. Then, navigate to Workers & Pages > Overview section on the sidebar. Here, you’ll find your application listed.

Please don’t make any changes in the secret names on the Configure secrets
step. These credentials will be automatically picked up by
Redis.fromEnv(env)
line in the code as UPSTASH_REDIS_REST_URL
and
UPSTASH_REDIS_REST_TOKEN
.
Setting up Manually
Navigate to Upstash Console and copy/paste yourUPSTASH_REDIS_REST_URL
and UPSTASH_REDIS_REST_TOKEN
to your wrangler.toml
as below.
Test and Deploy
You can test the function locally withnpx 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.