modelagem – Using Redis in practice

Question:

I'm having difficulties in realizing in practice where to use Redis in an ecommerce, for example.

I'm reading a book but I can't figure out what I have to take into account when deciding whether to use Redis or not.

Should Redis be used for static data?

In the case of ecommerce, use Redis to record login or shopping cart data and then record definitively in a database such as MongoDB or MySql, etc…?

Answer:

Friend, I use Redis in an ecommerce and I think I can give you a very simple and practical idea of ​​its use. Before using Redis I used memcached so let's try to understand how it helped me.

1st My store had a lot of access and I couldn't load the product from the database every time the user went to the catalog or detail page so I created a very simple and common "cache" implementation that is:

1st The user asks for the product page of id 14325 2nd My data adapter of my application sees if there is a key in redis called product_id_14325 (the name I am defining), if there is, I return the content of redis, that is, I do not consult in the bank. 3rd If the key does not exist in redis then I search in my database and the return I pass to the user, serialize it and persist in redis. Ready any user who access this detail page it is cached.

There are other approaches such as creating a process to write all your products in the cache and leave them with an expiration of 1 day, and small updates for modified products, but this depends on your caching strategy, what matters is that redis has a serial of utilities.

Scroll to Top