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.
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:
Here’s a quick example of how we will structure these operations:
Python1import 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.