Building a Cache with Upstash Redis in Next.js
Vložit
- čas přidán 27. 08. 2024
- In this video we'll cache expensive API calls in Redis within our getServerSideProps function.
---------- Course
Want to go deeper with Next.js? Join me in my Next Level Next.js course where over 29 videos and 8 hours of content we'll build a full application from start to finish. We use TypeScript, GraphQL, Prisma, Apollo, Mapbox, Firebase and lots more. courses.leighh...
---------- Links
Upstash - upstash.com/
Source Code - github.com/lei...
Starter Code - github.com/lei...
---------- Connect
Join this channel - / @leighhalliday
Join me on Discord - / discord
The only time I really learn important typescript/javascript information is when it's explained here. Thanks for this amazing content!
🔥🔥🔥🔥🔥🔥 Worked perfectly!
I am really lucky that i found this channel, man you always cover important topics that most of the channel just skip.
Glad you like them!
Awesome. I don't always watch the vids because I'm not into typescript yet, but it's always very useful and clear and easy to follow along. I actually built my first website off watching your headless CMS blog video.
kudos for Purchasing power parity!
Thank you Leigh, very clear, straight to the point :)
Glad you enjoyed it Helio!
Fantastic, thank you!!
loud and clear thanks for this amazing tutorial
This video is phenomenal. Thank you.
Thanks Jake!
Great video, as usual!
BTW, you can use Promise for async functions that do not return anything :)
Haha I figured it out after shooting the video but by then it was too late! Thanks for the kind words!!
Always learning here. it's amazing!!! Thank you.
Me too my friend, me too!
This api is great, thank you
Thanks daily meow :)
Great video, thx.
love the way you teach
Thank you Lonan! Appreciate your support!
Thanks Leigh!!
Hope it helped!!
@@leighhalliday Of course it will help! Your stuff is always amazing, and more importantly, useful.
Спасибо за видео!
I had to use google translate for this hehe, but thank you!
you are so clutch
You are amazing!
Haha thanks Norfeldt! You're great too!
Great video,
what's the point of using redis when we cache using vercel caching technique ?
Hey Thank you for the content ! Btw what is your vs code theme ?
Nice tutorial, but I think I might now understand something. We are using Redis DB hosted on upstash, does this mean each time we visit a page, we have to make a call to upstash to check if value is preset? How is it different from calling out PPP endpoint to check the value?
Hey! Nope, you're not missing anything. The thesis is that Redis will be faster than the external API... you'd have to make a decision for yourself whether it is worth it for your situation, but it was also just an example that you can cache any value to avoid "expensive" calculations on each page request. Imagine inside of the fetcher function it is making 10 API requests which each take 300ms... that is 3 seconds compared to maybe just 100ms to Redis and back.
I had one more thought to add, since it's a very valid point. With Redis we can control where it is located, so if we put Next.js and Redis in the same cloud region, latency becomes a minimal concern, and in our control. When dealing with an external API, the location is out of our control so latency could fluctuate and become more of an issue.
@@leighhalliday I think in this specific case, using a local Redis setup would have been ideal. That being said, one of the main advantages of caching is the fact that you are not actually calling the external API locally. External APIs are often paid, and having a caching setup will save you huge amounts of money when done properly. Using a local setup for Redis would still be ideal in that case, but the main purpose is saving money in that case.
hi, nickel! But I guess the fetcher should return a Promise not T (fetcher: () => Promise)
Have you tried the redis pubsub with nextJS?
I have not... I've always wondered how that would work since Next.js is typically hosted serverless???
@@leighhalliday I was hoping you knew. Been using firebase real-time database but have been curious to know if the real time experience could be archived with some clever redis
Thank you
You're very welcome!