Home / Companies / Upstash / Blog / Post Details
Content Deep Dive

Redis Session Storage in Next.js and Node.js with Upstash Redis

Blog post from Upstash

Post Details
Company
Date Published
Author
Josh
Word Count
2,098
Company Posts That Month
31
Language
English
Hacker News Points
-
Summary

The text discusses the use of Redis for session storage, highlighting its advantages over cookies and databases, such as sub-millisecond reads, automatic expiry, and easy session invalidation by deleting a Redis key. It explains how Redis session storage works, where the server assigns a unique session ID stored in an HttpOnly cookie, and the session data is managed in Redis with a time-to-live (TTL) setting. The article outlines three patterns for implementing Redis-backed session storage: a custom approach for Next.js App Router, an Express/Node.js integration using Upstash, and a Better Auth method that uses Redis as secondary storage. It also covers session management techniques like expiry handling, rolling TTL, and revocation, emphasizing security practices such as using opaque IDs in cookies, HTTPS for secure data transmission, and strategies for session invalidation. The document suggests choosing a session pattern based on the level of control desired and the specific requirements of the application, with each pattern offering different trade-offs between manual logic implementation and reliance on library-managed processes.

Trends Found in this Post

No tracked trend matches for this post yet.