This lab will help you practice querying data in Redis using the dataset provided here. You will execute a series of progressively challenging queries to retrieve, filter, and manipulate movie-related data.
The dataset consists of the following key types:
- Movies: Stored as hashes with keys like
movie:<id> - Theaters: Stored as hashes with keys like
theater:<id> - Users: Stored as hashes with keys like
user:<id> - Ratings: Stored as sorted sets to track movie ratings
- Indexes: Secondary indexes to facilitate searching
Make sure the dataset is imported before starting the lab.
In this section, you will use Redis CLI and basic Redis commands (Hashes, Sets, Sorted Sets, SCAN).
Fetch details of the movie with ID 1.
HGETALL movie:1Retrieve all movie IDs stored in Redis.
KEYS movie:*However, do not use KEYS in production. Use SCAN instead.
SCAN 0 MATCH movie:* COUNT 100Redis CLI does not support some of the operations bellow. You must try them out in Python.
Find all movies that start with "The Lord of the Rings".
import redis
r = redis.Redis()
results = []
for key in r.scan_iter(match="movie:*"):
title = r.hget(key, "title").decode('utf-8')
if "The Lord of the Rings" in title:
results.append(title)Find all theaters located in "New York".
Retrieve the top 5 movies based on rating.
Retrieve movies where the release year is greater than 2010.
Find all movies labeled as "Action".
Find all movies that have a rating between 7.0 and 9.0.
After executing these queries, you should have a strong understanding of how to interact with Redis and retrieve relevant movie data efficiently. Try modifying the queries to experiment further!
- Modify query #5 to return the top 10 rated movies.
- Find the 3 most recent movies added to the dataset.
Happy querying! 🚀
