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!
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).
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.
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!
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 ?
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?
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.
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?
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
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
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!
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
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?
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
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.
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.
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!
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).
Came here to say the same, important and can become complex in a real world production app 😅
just delete the record?
This usage Redis + Prisma is so smooth ❤
Really is. Works super well
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.
But i think read and write operations will be more costy ??
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!
Great idea. Wishing you that too
@@joshtriedcoding we need a more practical use-case than this :)
@@namesare4fools There is going to be a *very* in-depth video soon. Stay tuned
@@joshtriedcoding is it going to be using tRPC?
Your explanation of how it works was brilliant - thank you 💕💕
You are clearly a brilliant man. Your skills at teaching are fantastic
Thanks for this video Josh! Loved how easily you explained the entire concept!
Cheers man!
how do you return NEW data from the database if it's always checking redis first?
You can fine-tune expiry times with redis
Life saver, added this to my project thanks
Thanks for this short, to the point and keeping is simple video. Keep it up 👍
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 ?
AWWWSOME explanation
smooth man ...... thanks
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?
I really need to try this 😊, tons of usage
Great video, simple and precise!
Clean video, thank you !
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.
Nice one on Redis! Whats if data should be checked to see if its updated at db for objects a bit more dynamic?
so you are using query on the front and redis in the back?
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?
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
Great explaination.
fyi the client doesnt communciate with the db, the server does
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
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!
Thanks! This was really helpful
How useful is this with nextjs automatic caching?
Can we use Redis for my next js 13 backend?
Has anyone used vercel KV and can't seem to set the key value pair?
How does this compare to the Next.JS default caching?
can we use redis to cache postgresSQL (as a reading replica)?
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
yeah for sure, give it a shot
hey josh, i wonder your toughts on t3 stack and trpc for production level development.
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
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?
Your servers should also be as close to the users as possible, the closer the entire infrastructure the better
@@joshtriedcoding sure :) thanks
How to make video for RUclips? Which software you use?
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
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.
I'd be interested to see what it can do that can't be done just as easily with a global object.
Cache queries across different clients
@@joshtriedcoding But can't I do that with just a simple global object of key-value pairs? global.cache = { [url]: [json] }
@@jason_v12345persistence for example
Are you using a drawing pen? Can't make mine work with Excalidraw, XP-PEN
You forgot to JSON.parse the cache response 😅😅
you look like cart titan :)
NICE video
thanks champ
Nice Intro
thats like %0.2 of "Redis Caching for Incredible Performance"
Josh, how can we give you money
Very German intro👍
very "german"?? How haha
Farq me its awesome
Bro dieses denglisch hahaha
redis and upstash are not the same thing. upstash costs a lot of money.
What’s cheaper?
first here ^_*
- upstash
What? A database that stores cached values instead of... checking an actual database? What have we saved here? This is moronic.
Performance
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.