npx create-next-app@latest cd my-app
sst init
@upstash/redis
npm install @upstash/redis
UPSTASH_REDIS_REST_URL
UPSTASH_REDIS_REST_TOKEN
.env
UPSTASH_REDIS_REST_URL=<YOUR_URL> UPSTASH_REDIS_REST_TOKEN=<YOUR_TOKEN>
/// <reference path="./.sst/platform/config.d.ts" /> export default $config({ app(input) { return { name: "my-app", removal: input?.stage === "production" ? "retain" : "remove", home: "aws", }; }, async run() { new sst.aws.Nextjs("MyWeb", { environment: { UPSTASH_REDIS_REST_URL: process.env.UPSTASH_REDIS_REST_URL || "", UPSTASH_REDIS_REST_TOKEN: process.env.UPSTASH_REDIS_REST_TOKEN || "", }, }); }, });
/app/page.tsx
import { Redis } from "@upstash/redis"; const redis = Redis.fromEnv(); export default async function Home() { const count = await redis.incr("counter"); return ( <div className="flex h-screen w-screen items-center justify-center"> <h1 className="text-4xl font-bold">Counter: {count}</h1> </div> ) }
npm run dev
http://localhost:3000/
sst deploy
Was this page helpful?