Next.js Discord

Discord Forum

Redis

Answered
Havana posted this in #help-forum
Open in Discord
HavanaOP
I know what redis does, I am just kind of confused as to what kind of items should be cached, and which ones shouldnt.

Should I store user objects, password reset tokens, or is this not the point of Redis?

Also how exactly does it work? I know redis stores in RAM in a single thread, but does this run locally within NextJS or are these externally?

TLDR: What kind of items should be stored in Redis?
Answered by James4u
To answer your last question:

Frequently accessed data: Items that are read often but don't change frequently are good candidates for caching. This could include:

- API responses
- Database query results
- Rendered HTML for static or rarely changing pages

Session data: Redis is often used to store session information, which can be useful in Next.js applications, especially when you need to scale across multiple servers.
Rate limiting data: If you're implementing rate limiting in your Next.js API routes, Redis can be a good place to store this information.
Temporary data with expiration: Redis supports setting expiration times on data, which makes it suitable for things like:

- Password reset tokens
- Email verification codes
- Temporary access tokens
View full answer

16 Replies

To answer your last question:

Frequently accessed data: Items that are read often but don't change frequently are good candidates for caching. This could include:

- API responses
- Database query results
- Rendered HTML for static or rarely changing pages

Session data: Redis is often used to store session information, which can be useful in Next.js applications, especially when you need to scale across multiple servers.
Rate limiting data: If you're implementing rate limiting in your Next.js API routes, Redis can be a good place to store this information.
Temporary data with expiration: Redis supports setting expiration times on data, which makes it suitable for things like:

- Password reset tokens
- Email verification codes
- Temporary access tokens
Answer
however @Havana unless you have extremely huge amount of traffic, Next.js cache should enough I believe
yeah, sort of. but still Next.js cache mechanism is super powerful
oh, you have a big audience ok
@James4u oh, you have a big audience ok
HavanaOP
For testing purposes I'll use Next-Cache but is it hard to transfer in between the two?
@Havana For testing purposes I'll use Next-Cache but is it hard to transfer in between the two?
Nope, I don't think adding cache layer is that complex
HavanaOP
Thanks for clarifying it to me 👍
great! mark solution to close the thread if you don't have any other questions 🙂
@Havana Thanks for clarifying it to me 👍
oh, you marked yours lol
@James4u oh, you marked yours lol
HavanaOP
Wait what
I clicked on the empty space and then Apps > Mark solution
Ooooh
Click on a message you think is the most appropriate
HavanaOP
I see
👍