Skip to main content

Project Setup

We will create a new Next.js application and install the redis package.

The Code

Update /app/page.tsx with the following code:
/app/page.tsx
Redis.fromEnv() automatically loads UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN from the environment variables. We’ll set them later.

Database Setup

Create a Redis database using Upstash Console or Upstash CLI and copy the UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN into your .env file. Let’s quickly add some data to redis. Go to the CLI tab and run the following commands

Run & Deploy

You can run the app locally: npm run dev and check http://localhost:3000/ Deploy your app with npx vercel
You can also integrate your Vercel projects with Upstash using Vercel Integration module. Check this article.