Rails 7 #114 Recently viewed products with Kredis

24/02/2023 (about 1 year ago)
Coding Recently viewed products E-commerce Database Data caching Tech tutorials Software development Backend development Frontend development Ruby on Rails #114 Recently viewed products with Kredis Gem Kredis kredis ruby on rails tutorial ruby programming language SupeRails RailsFramework Kredis unique

Recently viewed products is a very common feature in Ecommerce.
Showing users a list of products they viewed is considered to increase conversion.
The least complex way of implementing this kind of list can be in Redis.
Gem Kredis allows us to associate a Redis attribute with an ActiveRecord model.
We will store and update the list of recently visited products in Redis and associate it with our Current user.

Episode source code: https://github.com/corsego/114-kredis-recently-viewed-products/commit/22cfd31ad68bbb67ebf3b5f57b976b2dff5f6d7a
Blogpost - kredis recently visited pages: https://blog.corsego.com/kredis-recently-visited-pages

0:00 Store recently visited in Redis vs Postgresql?
1:58 Kredis unique list
2:50 Add kredis attribute to User
4:00 Update recently_viewed_products
5:25 display users recently_viewed_products
7:25 Works! We can now store and display a list of 5 most recently visited products by the user

Sign in to join the conversation