July 2019
Beginner to intermediate
302 pages
9h 38m
English
We will maintain a set in Redis, which will store the products visited recently. This will be populated whenever we visit a product. The entry will expire in 10 minutes. This change goes in views.py:
from my_app import redis
@catalog.route('/product/<id>')
def product(id):
product = Product.query.get_or_404(id)
product_key = 'product-%s' % product.id
redis.set(product_key, product.name)
redis.expire(product_key, 600)
return 'Product - %s, $%s' % (product.name, product.price)
In the preceding method, note the set() and expire() methods on ...