May 2018
Beginner to intermediate
526 pages
11h 57m
English
Let's build something more complex with Redis. We will create a ranking of the most viewed images in our platform. For building this ranking, we will use Redis sorted sets. A sorted set is a non-repeating collection of strings in which every member is associated with a score. Items are sorted by their score.
Edit the views.py file of the images application and make the image_detail view look as follows:
def image_detail(request, id, slug): image = get_object_or_404(Image, id=id, slug=slug) # increment total image views by 1 total_views = r.incr('image:{}:views'.format(image.id)) # increment image ranking by 1 r.zincrby('image_ranking', image.id, 1) return render(request, 'images/image/detail.html', {'section': 'images', ...Read now
Unlock full access