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 how these operations will be implemented:

In this example, the UserData class is used to represent the user's information. It includes the user’s name, age, and email. Here is the definition of the UserData class:

This implementation uses the Jedis library to interact with Redis. The addUser method stores user data in Redis with a one-day expiration time using the setex method. The getUser method retrieves the user data, deserializing it back into a UserData object using Gson.

Now that you have a clear idea of what you'll be building, let’s start implementing this functionality and explore how Redis helps manage temporary data effectively. This practice will strengthen your understanding and prepare you for more complex operations in the upcoming units.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal