How to use Redis Caching for Incredible Performance

Поделиться
HTML-код
  • Опубликовано: 7 сен 2024
  • 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

Комментарии • 75

  • @crypt0nerd621
    @crypt0nerd621 Год назад +17

    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!

  • @youneshenni5417
    @youneshenni5417 Год назад +16

    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 Год назад +2

      Came here to say the same, important and can become complex in a real world production app 😅

    • @versaleyoutubevanced8647
      @versaleyoutubevanced8647 8 месяцев назад

      just delete the record?

  • @JT-mr3db
    @JT-mr3db Год назад +7

    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 9 месяцев назад

      But i think read and write operations will be more costy ??

  • @codewithguillaume
    @codewithguillaume Год назад +2

    This usage Redis + Prisma is so smooth ❤

  • @ScriptCodec
    @ScriptCodec Год назад +15

    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  Год назад +12

      Great idea. Wishing you that too

    • @namesare4fools
      @namesare4fools Год назад +2

      ​@@joshtriedcoding we need a more practical use-case than this :)

    • @joshtriedcoding
      @joshtriedcoding  Год назад +4

      @@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 Год назад +2

    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!

  • @adnanniaz77
    @adnanniaz77 Год назад

    Thanks for this short, to the point and keeping is simple video. Keep it up 👍

  • @GamingClubGermany
    @GamingClubGermany Год назад +1

    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!

  • @roncanfil
    @roncanfil Год назад +2

    how do you return NEW data from the database if it's always checking redis first?

  • @eshw23
    @eshw23 11 месяцев назад

    Life saver, added this to my project thanks

  • @AmanRaj-zo7bx
    @AmanRaj-zo7bx 11 месяцев назад +1

    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 ?

  • @ruanxun9454
    @ruanxun9454 4 месяца назад

    Has anyone used vercel KV and can't seem to set the key value pair?

  • @harrypotil860
    @harrypotil860 3 месяца назад

    AWWWSOME explanation

  • @raymondmichael4987
    @raymondmichael4987 Год назад

    I really need to try this 😊, tons of usage

  • @zoki5388
    @zoki5388 Год назад +2

    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?

  • @mounis
    @mounis Год назад

    Great video, simple and precise!

  • @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?

  • @user-rd4oo1jg5g
    @user-rd4oo1jg5g 11 месяцев назад

    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

  • @karthiksharmaslife2323
    @karthiksharmaslife2323 8 месяцев назад

    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.

  • @Jack-hk6kl
    @Jack-hk6kl Год назад +1

    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  Год назад +2

      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

  • @Ellenox147
    @Ellenox147 Год назад

    Clean video, thank you !

  • @Tyheir
    @Tyheir 11 месяцев назад

    How useful is this with nextjs automatic caching?

  • @raicubogdan8078
    @raicubogdan8078 Год назад

    Thanks! This was really helpful

  • @dineshrout2527
    @dineshrout2527 Год назад

    Great explaination.

  • @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

  • @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.

  • @AzzMdA
    @AzzMdA Год назад

    can we use redis to cache postgresSQL (as a reading replica)?

  • @bennys96
    @bennys96 Год назад

    How does this compare to the Next.JS default caching?

  • @journeyfromnothingtoeverything
    @journeyfromnothingtoeverything 11 месяцев назад

    Can we use Redis for my next js 13 backend?

  • @phantazzor
    @phantazzor Год назад

    so you are using query on the front and redis in the back?

  • @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

  • @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

  • @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

  • @pokigamerop
    @pokigamerop 7 месяцев назад

    you look like cart titan :)

  • @shakalbadlalega
    @shakalbadlalega Год назад

    How to make video for RUclips? Which software you use?

  • @throwaway-lo4zw
    @throwaway-lo4zw 25 дней назад

    fyi the client doesnt communciate with the db, the server does

  • @Gutan92
    @Gutan92 Год назад

    Are you using a drawing pen? Can't make mine work with Excalidraw, XP-PEN

  • @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

  • @SupertigerDev
    @SupertigerDev Год назад

    You forgot to JSON.parse the cache response 😅😅

  • @MerthanMerter
    @MerthanMerter 7 месяцев назад

    thats like %0.2 of "Redis Caching for Incredible Performance"

  • @maazkhan9512
    @maazkhan9512 Год назад

    Nice Intro

  • @0xPanda1
    @0xPanda1 Год назад

    NICE video

  • @ammaraateeb1914
    @ammaraateeb1914 Год назад

    Farq me its awesome

  • @crazytydoo
    @crazytydoo Год назад

    Josh, how can we give you money

  • @kag3670
    @kag3670 Год назад

    Very German intro👍

  • @peaqe2496
    @peaqe2496 2 месяца назад

    Bro dieses denglisch hahaha

  • @greendsnow
    @greendsnow 10 месяцев назад

    redis and upstash are not the same thing. upstash costs a lot of money.

    • @basarat
      @basarat 4 месяца назад

      What’s cheaper?

  • @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 11 месяцев назад

      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.

  • @asimalqasmi7316
    @asimalqasmi7316 Год назад

    first here ^_*