Challenge - 5 Problems
Redis Persist Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
What is the output of the PERSIST command?
Given a Redis key
session_token with an expiry set, what will be the output of the command PERSIST session_token if the key exists and has an expiry?Redis
SET session_token abc123
EXPIRE session_token 300
PERSIST session_tokenAttempts:
2 left
💡 Hint
PERSIST removes the expiry from a key if it exists and has a timeout.
✗ Incorrect
The PERSIST command returns 1 if the timeout was removed successfully, meaning the key existed and had an expiry. It returns 0 if the key does not exist or did not have an expiry.
❓ query_result
intermediate1:30remaining
What happens when PERSIST is called on a key without expiry?
If a Redis key
user:100 exists but has no expiry set, what will PERSIST user:100 return?Redis
SET user:100 "John Doe" PERSIST user:100
Attempts:
2 left
💡 Hint
PERSIST only removes expiry if one exists.
✗ Incorrect
Since the key exists but has no expiry, PERSIST returns 0 indicating no timeout was removed.
📝 Syntax
advanced1:30remaining
Which PERSIST command syntax is correct?
Identify the correct syntax to remove the expiry from a Redis key named
cache_data.Attempts:
2 left
💡 Hint
Redis commands do not use parentheses or extra keywords for PERSIST.
✗ Incorrect
The correct syntax is simply
PERSIST key. Parentheses or extra keywords cause syntax errors.🧠 Conceptual
advanced2:00remaining
Why use PERSIST instead of deleting and recreating a key?
Which of the following is the best reason to use
PERSIST to remove expiry from a key instead of deleting and recreating it?Attempts:
2 left
💡 Hint
Think about what happens to the key's data and connections.
✗ Incorrect
PERSIST removes expiry without deleting the key, so the value and metadata remain intact and accessible without interruption.
🔧 Debug
expert2:00remaining
Why does PERSIST return 0 unexpectedly?
You run
PERSIST mykey but it returns 0 even though you expect the key to have an expiry. Which is the most likely cause?Attempts:
2 left
💡 Hint
PERSIST returns 0 if no expiry was removed.
✗ Incorrect
If the key exists but has no expiry, PERSIST returns 0 indicating no timeout was removed. This is the most common cause of unexpected 0 returns.