Skip to content

ironhack-labs/lab-redis-querying

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

logo_ironhack_blue 7

Lab | Redis: Querying the Movies Dataset

Objective

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.

Dataset Overview

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.

Lab Instructions

In this section, you will use Redis CLI and basic Redis commands (Hashes, Sets, Sorted Sets, SCAN).

1. Retrieve a Movie by ID

Fetch details of the movie with ID 1.

HGETALL movie:1

2. List All Movies

Retrieve all movie IDs stored in Redis.

KEYS movie:*

However, do not use KEYS in production. Use SCAN instead.

SCAN 0 MATCH movie:* COUNT 100

Redis CLI does not support some of the operations bellow. You must try them out in Python.

3. Find Movies by Title Prefix

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)

4. Retrieve Theaters in a Specific City

Find all theaters located in "New York".

5. Get Top-Rated Movies

Retrieve the top 5 movies based on rating.

6. Find Movies Released After 2010

Retrieve movies where the release year is greater than 2010.

7. Get Movies by Genre

Find all movies labeled as "Action".

8. Get Movies with Ratings Between 7 and 9

Find all movies that have a rating between 7.0 and 9.0.

Completion

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!

Additional Challenges

  • Modify query #5 to return the top 10 rated movies.
  • Find the 3 most recent movies added to the dataset.

Happy querying! 🚀

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors