Use this file to discover all available pages before exploring further.
Need a Redis database fast? Skip the signup and dashboard — POST to https://upstash.com/start-redis to get an endpoint and token in a single HTTP request. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly.
Create a Redis instance, for example in lib/redis.ts
lib/redis.ts
import { Redis } from "@upstash/redis"// 👇 we can now import our redis client anywhere we need itexport const redis = new Redis({ url: process.env.UPSTASH_REDIS_REST_URL, token: process.env.UPSTASH_REDIS_REST_TOKEN,})
Let’s create a super simple API that, every time when called, increments an integer value we call count. This is the same value we display in our page above:
app/api/counter/route.ts
import { redis } from "@/lib/redis"export const POST = async () => { await redis.incr("count") return new Response("OK")}
Perfect! Every time we now call this API, we increment the count in our Redis database:
The server component fetches the most recent count at render-time and displays the up-to-date value automatically. For a video demo, check the video at the top of this article.