Lesson 1
Managing User Data with Expiration
Managing User Data with Expiration

Welcome to the first step in building our Redis-based backend system. In this unit, we will focus on how to manage user data with expiration using Redis. This is a fundamental part of our project that will set the stage for more advanced features in later units.

What You'll Build

Let's take a quick look at what you'll be building in this unit. We will focus on two key operations for managing user data:

  1. Adding user data with an expiration time: This will ensure that user data is stored for a limited period and automatically deleted afterward.
  2. Retrieving user data: This operation will help us fetch the user data we previously stored.

Here’s a quick example of how we will structure these operations:

Python
1import redis 2import json 3from datetime import timedelta 4 5client = redis.Redis(host='localhost', port=6379, db=0) 6 7data = { 8 'email': 'user1@example.com' 9} 10 11# Add user data with expiration 12client.set(f'user:1', json.dumps(data), ex=timedelta(days=1)) 13 14# Retrieve user data 15data = client.get(f'user:1') 16print(data)

You might remember the ex parameter from the previous lessons. It allows us to set an expiration time for the data we store in Redis. In this case, we are setting the expiration to one day.

Now that you have a clear idea of what you'll be building let's start the practice section and implement this logic. This will solidify your understanding and prepare you for more complex tasks in the upcoming units.

Enjoy this lesson? Now it's time to practice with Cosmo!
Practice is how you turn knowledge into actual skills.