0
0
Redisquery~15 mins

PERSIST to remove expiry in Redis - Mini Project: Build & Apply

Choose your learning style9 modes available
Using PERSIST to Remove Expiry from Redis Keys
📖 Scenario: You are managing a Redis database that stores temporary session data for users. Sometimes, you want to keep a session permanently by removing its expiry time.
🎯 Goal: Learn how to create a Redis key with an expiry time and then remove that expiry using the PERSIST command.
📋 What You'll Learn
Create a Redis key named session:user123 with the value active and set it to expire in 60 seconds.
Create a variable to hold the key name key_name with the value session:user123.
Use the PERSIST command on the key stored in key_name to remove its expiry.
Verify that the key no longer has an expiry time.
💡 Why This Matters
🌍 Real World
Managing user sessions or temporary data in Redis often requires setting expiry times and sometimes removing them to keep data permanently.
💼 Career
Understanding how to control key expiry in Redis is important for backend developers and system administrators working with caching and session management.
Progress0 / 4 steps
1
Create a Redis key with expiry
Create a Redis key named session:user123 with the value active and set it to expire in 60 seconds using the SET command with the EX option.
Redis
Need a hint?

Use SET key value EX seconds to set a key with expiry.

2
Create a variable for the key name
Create a variable called key_name and set it to the string session:user123.
Redis
Need a hint?

Assign the string 'session:user123' to key_name.

3
Remove expiry using PERSIST
Use the PERSIST command on the key stored in the variable key_name to remove its expiry time.
Redis
Need a hint?

Use PERSIST key to remove expiry from a key.

4
Verify the key has no expiry
Use the TTL command on the key stored in key_name to check that it no longer has an expiry time.
Redis
Need a hint?

Use TTL key to check the remaining time to live of a key. It returns -1 if the key has no expiry.