How to use Redis Caching for Incredible Performance

  Рет қаралды 62,454

Josh tried coding

Josh tried coding

Күн бұрын

Caching database queries with Redis can be an incredible way to speed up your API responses. That will not only cost you less database quota but drastically improve user experience as well. Let's see you how can implement super fast caching for yourself!
My GitHub: github.com/jos...
Upstash (not sponsored): upstash.com/
I wish you a lot of fun implementing caching and seeing the results for yourself. Let me know if you build something cool with it! Cheers

Пікірлер: 77
@crypt0nerd621
@crypt0nerd621 Жыл бұрын
This is very interesting and useful. It will be great if you consider a more in depth video about Redis. For example how to update the cashed data if it is updated in the DB? How to delete cashed data if it is deleted in the DB, best practices, etc. Great video!
@codewithguillaume
@codewithguillaume Жыл бұрын
This usage Redis + Prisma is so smooth ❤
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Really is. Works super well
@JT-mr3db
@JT-mr3db Жыл бұрын
Redis is really known as a caching layer but it's also an extremely capable primary database. If you can fit your data into RAM and work with the data structures Redis gives you, you will be a happy camper.
@gamingwolf3385
@gamingwolf3385 Жыл бұрын
But i think read and write operations will be more costy ??
@youneshenni5417
@youneshenni5417 Жыл бұрын
Thanks for the tips. Quick advice: always show how to invalidate cache for these kind of tutorials (as this is an important step in any caching process).
@CanRau
@CanRau Жыл бұрын
Came here to say the same, important and can become complex in a real world production app 😅
@versaleyoutubevanced8647
@versaleyoutubevanced8647 Жыл бұрын
just delete the record?
@ScriptCodec
@ScriptCodec Жыл бұрын
Hey Josh, Great tuts! However I kind of get more curious about more advanced usage of redis. Could you make a dedicated video on redis? That would help a lot. Thanks. Great weekend!
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Great idea. Wishing you that too
@namesare4fools
@namesare4fools Жыл бұрын
​@@joshtriedcoding we need a more practical use-case than this :)
@joshtriedcoding
@joshtriedcoding Жыл бұрын
@@namesare4fools There is going to be a *very* in-depth video soon. Stay tuned
@kdiffin
@kdiffin Жыл бұрын
@@joshtriedcoding is it going to be using tRPC?
@learnwhispering
@learnwhispering Жыл бұрын
Your explanation of how it works was brilliant - thank you 💕💕 You are clearly a brilliant man. Your skills at teaching are fantastic
@mohaniya15
@mohaniya15 Жыл бұрын
Thanks for this video Josh! Loved how easily you explained the entire concept!
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Cheers man!
@adnanniaz77
@adnanniaz77 Жыл бұрын
Thanks for this short, to the point and keeping is simple video. Keep it up 👍
@eshw23
@eshw23 Жыл бұрын
Life saver, added this to my project thanks
@harrypotil860
@harrypotil860 8 ай бұрын
AWWWSOME explanation
@roncanfil
@roncanfil Жыл бұрын
how do you return NEW data from the database if it's always checking redis first?
@joshtriedcoding
@joshtriedcoding Жыл бұрын
You can fine-tune expiry times with redis
@amanfreecs
@amanfreecs 5 ай бұрын
smooth man ...... thanks
@AmanRaj-zo7bx
@AmanRaj-zo7bx Жыл бұрын
Loved this video, I am having problem with nodemon(in TS project), used ts-node but still not restarted on changes. can you please suggest a way to auto detect the file changes and compile and restart the server just like nodemon in js ?
@raymondmichael4987
@raymondmichael4987 Жыл бұрын
I really need to try this 😊, tons of usage
@GamingClubGermany
@GamingClubGermany Жыл бұрын
Its cool but it could be a lot slower than just using the database directly if you using redis on cloud. If you backend need to connect via tcp to a different server anywhere you have a fast lookup but a slower response than using the local database directly. It would only make sense if you have very large requeste. But in general in memory caching is a really good idea but you loose manually editing the database manually (which is not recommended anyway) But good video as always!
@mounis
@mounis Жыл бұрын
Great video, simple and precise!
@Ellenox147
@Ellenox147 Жыл бұрын
Clean video, thank you !
@karthiksharmaslife2323
@karthiksharmaslife2323 Жыл бұрын
Hi Josh, can we do data manipulations directly in reddis cache and push the changes to the Database table without loading data from reddis cache to data table and manipulating the data? In my case data table cannot hold tons of data.
@testtest-c4z
@testtest-c4z Жыл бұрын
Very good video, I congratulate you. I ask you a question, suppose I have an application with a mysql database, my app calls an api to query and show products to the user, if I implement you Redis to cache the busquedaby that the api first see if you have stored in cache and if not just then go to query the database, with the first user who enters the app Eedis stored in the server cache and then if another user comes and asks to see the products would be set in that cache even if they are different users? The cache has a time and then it is deleted and the search to the database is done again, right? Thank you very much
@raicubogdan8078
@raicubogdan8078 Жыл бұрын
Thanks! This was really helpful
@DinoRossYT
@DinoRossYT Жыл бұрын
Nice one on Redis! Whats if data should be checked to see if its updated at db for objects a bit more dynamic?
@zoki5388
@zoki5388 Жыл бұрын
Hey Josh 🍺, would Redis be a good place for storing the output (a very long string) of a rich text editor like React-Draft-Wysiwyg? Also, how could I store a link to it in my PostgreSQL database?
@phantazzor
@phantazzor Жыл бұрын
so you are using query on the front and redis in the back?
@dineshrout2527
@dineshrout2527 Жыл бұрын
Great explaination.
@Tyheir
@Tyheir Жыл бұрын
How useful is this with nextjs automatic caching?
@Jack-hk6kl
@Jack-hk6kl Жыл бұрын
Correct me if I’m wrong: doesnt Nextjs automatically implement this with their extended fetch API? If a fetch has the same parameters as before it would return the cached value. What’s the difference btwn that and Redis caching?
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Pretty sure the nextjs values are only cached for YOU due to the serverless architecture, meaning if you and I request the same resource, my result wont be cached for you or the other way around. With redis, if we both request the same resource, it wil be cached for the later request
@ruanxun9454
@ruanxun9454 9 ай бұрын
Has anyone used vercel KV and can't seem to set the key value pair?
@RETO_fps
@RETO_fps Жыл бұрын
but how does that work in terms of latency? one of the advantages of redis is 0ms(almost) access, but when used with upstash there surely is some ping latency. Can you tell if im right? Also what are other ways to implement redis with next, because cant find any :/ ps. gained sub
@journeyfromnothingtoeverything
@journeyfromnothingtoeverything Жыл бұрын
Can we use Redis for my next js 13 backend?
@throwaway-lo4zw
@throwaway-lo4zw 5 ай бұрын
fyi the client doesnt communciate with the db, the server does
@AzzMdA
@AzzMdA Жыл бұрын
can we use redis to cache postgresSQL (as a reading replica)?
@hakancav3661
@hakancav3661 Жыл бұрын
Is it safe to use UpStash in production ? I have a to create an real estate website, i get all the data from an external api call, so it will be very use full to cache it. Any suggestion ? Thanks
@joshtriedcoding
@joshtriedcoding Жыл бұрын
yeah for sure, give it a shot
@bennys96
@bennys96 Жыл бұрын
How does this compare to the Next.JS default caching?
@hn3m3s1s
@hn3m3s1s Жыл бұрын
Hey! Thanks for the video. You said that the Redis should be as close as possible of the users. But Actually wouldn't make more sense to have the Redis as close as possible of the Server than the users?
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Your servers should also be as close to the users as possible, the closer the entire infrastructure the better
@hn3m3s1s
@hn3m3s1s Жыл бұрын
@@joshtriedcoding sure :) thanks
@shakalbadlalega
@shakalbadlalega Жыл бұрын
How to make video for KZbin? Which software you use?
@Gutan92
@Gutan92 Жыл бұрын
Are you using a drawing pen? Can't make mine work with Excalidraw, XP-PEN
@LaklukLP
@LaklukLP Жыл бұрын
Love your videos man. I was wondering if you are looking for a position currently? I saw that you live n Germany based on your server geo selection ;) I have a startup and we are currently hiring again.
@efehanturhan6763
@efehanturhan6763 Жыл бұрын
hey josh, i wonder your toughts on t3 stack and trpc for production level development.
@joshtriedcoding
@joshtriedcoding Жыл бұрын
I've moved away from tRPC at the moment with NextJS 13 development, but have used it in production nevertheless and it held up well
@jason_v12345
@jason_v12345 Жыл бұрын
I'd be interested to see what it can do that can't be done just as easily with a global object.
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Cache queries across different clients
@jason_v12345
@jason_v12345 Жыл бұрын
@@joshtriedcoding But can't I do that with just a simple global object of key-value pairs? global.cache = { [url]: [json] }
@bnv1n
@bnv1n Жыл бұрын
@@jason_v12345persistence for example
@pokigamerop
@pokigamerop Жыл бұрын
you look like cart titan :)
@maazkhan9512
@maazkhan9512 Жыл бұрын
Nice Intro
@0xPanda1
@0xPanda1 Жыл бұрын
NICE video
@joshtriedcoding
@joshtriedcoding Жыл бұрын
thanks champ
@SupertigerDev
@SupertigerDev Жыл бұрын
You forgot to JSON.parse the cache response 😅😅
@wepieces
@wepieces Жыл бұрын
thats like %0.2 of "Redis Caching for Incredible Performance"
@crazytydoo
@crazytydoo Жыл бұрын
Josh, how can we give you money
@kag3670
@kag3670 Жыл бұрын
Very German intro👍
@joshtriedcoding
@joshtriedcoding Жыл бұрын
very "german"?? How haha
@أحمدحسين-ز1ع
@أحمدحسين-ز1ع 19 күн бұрын
Hello
@greendsnow
@greendsnow Жыл бұрын
redis and upstash are not the same thing. upstash costs a lot of money.
@basarat
@basarat 9 ай бұрын
What’s cheaper?
@peaqe2496
@peaqe2496 7 ай бұрын
Bro dieses denglisch hahaha
@loveboat
@loveboat Жыл бұрын
What? A database that stores cached values instead of... checking an actual database? What have we saved here? This is moronic.
@rumble1925
@rumble1925 Жыл бұрын
Performance
@fahadshinwari6844
@fahadshinwari6844 Жыл бұрын
Redis has no idea whether the data in DB has been updated. Normally, we use Redis to cache data as follows: 1- Client checks if the data, e.g. key-value pair, exists in Redis. 2- If the key exists, client gets the corresponding value from Redis. 3- Otherwise, it gets data from DB, and sets it to Redis. Also client sets an expiration, say 5 minutes, for the key-value pair in Redis. 4- Then any subsequent requests for the same key will be served by Redis. Although the data in Redis might be out-of-date. 5- However, after 5 minutes, this key will be removed from Redis automatically. 6- Go to step 1. So in order to keep your data in Redis update-to-date, you can set a short expiration time. However, your DB has to serve lots of requests. If you want to largely decrease requests to DB, you can set a large expiration time. So that, most of time, Redis can serve the requests with possible staled data. You should consider carefully about the trade-off between performance and staled data.
@AleksandrStrutynskyy
@AleksandrStrutynskyy 3 ай бұрын
- upstash
@asimalqasmi7316
@asimalqasmi7316 Жыл бұрын
first here ^_*
I've been using Redis wrong this whole time...
20:53
Dreams of Code
Рет қаралды 381 М.
Redis Crash Course
27:31
Web Dev Simplified
Рет қаралды 666 М.
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН
How does Caching on the Backend work? (System Design Fundamentals)
22:45
Software Developer Diaries
Рет қаралды 48 М.
Adding a cache is not as simple as it may seem...
13:29
Dreams of Code
Рет қаралды 112 М.
Why I don't use React-Query and tRPC in Next.js
18:58
ByteGrad
Рет қаралды 105 М.
Redis Crash Course
1:23:37
Piyush Garg
Рет қаралды 187 М.
“use cache” NextJS’s latest take on data caching
17:27
Jack Herrington
Рет қаралды 13 М.
.NET 8  .🚀🔥: Speedup your API with Redis Caching🚀🚀🚀
19:12
I Found a Faster Way to Build Next.js APIs
15:57
Josh tried coding
Рет қаралды 35 М.
10 common mistakes with the Next.js App Router
20:37
Vercel
Рет қаралды 243 М.
The Problem with React Server Actions
9:45
Josh tried coding
Рет қаралды 25 М.
Learn NextJS's Superpower ISR in 15 Minutes
15:35
Josh tried coding
Рет қаралды 47 М.