Menu

Post image 1
Post image 2
1 / 2
0

Next.js Blog View Counter with Upstash Redis (Tutorial)

DEV Community: nextjs·Iurii Rogulia·2 days ago
#jEiI7Cnw
#dev#redis#views#upstash#slug#article
Reading 0:00
15s threshold

You have a statically generated blog on Vercel. You want to show readers how many people have viewed an article. You don't want to drop Google Analytics on every page for that one number. This is a deliberately small problem — and the solution should stay small. Here's what I added to this site: an Upstash Redis counter, a single API route, one client component. Free tier covers the load, no external scripts, no cookie banners, no GDPR archaeology. And a few gotchas that aren't in the Upstash quickstart. Why Upstash, Not ioredis My first instinct was to reach for ioredis — the same client I use for rate limiting in vatnode.dev . For a long-running Node.js server that maintains persistent connections, ioredis is the right choice. If you want a deeper look at sliding window rate limiting with ioredis, I covered it in Redis Rate Limiting for APIs . For Vercel serverless functions, it is not. Vercel functions are stateless and short-lived. Each invocation initializes a new Node.js environment.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More