Skip to main content
Private Chat requires environment variables to connect to Upstash Redis for real-time messaging and data storage.

Required variables

UPSTASH_REDIS_REST_URL
string
required
The REST URL for your Upstash Redis database. This URL is used to connect to your Redis instance via HTTP.Example: https://your-database.upstash.io
UPSTASH_REDIS_REST_TOKEN
string
required
The authentication token for your Upstash Redis database. This token provides secure access to your Redis instance.Keep this token secret and never commit it to version control.

How they’re used

The application uses the @upstash/redis SDK which automatically reads these environment variables when you initialize Redis with Redis.fromEnv():
src/lib/redis.ts
import { Redis } from "@upstash/redis";

export const redis = Redis.fromEnv()
This Redis instance is then used by the real-time messaging system to:
  • Store and retrieve chat messages
  • Manage room state
  • Handle real-time subscriptions

Setting environment variables

1

Create .env.local file

In your project root, create a .env.local file:
touch .env.local
2

Add your credentials

Add your Upstash Redis credentials to the file:
.env.local
UPSTASH_REDIS_REST_URL=https://your-database.upstash.io
UPSTASH_REDIS_REST_TOKEN=your_token_here
3

Restart your development server

If your dev server is running, restart it to load the new environment variables:
npm run dev
Never commit your .env.local file to version control. Add it to your .gitignore file to prevent accidentally exposing your credentials.

Getting credentials

To get your Upstash Redis credentials, follow the Upstash setup guide.

Build docs developers (and LLMs) love