Challenge - 5 Problems
Redis Rename Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the result of RENAME when the new key exists?
Assume the Redis database has keys:
key1 with value 100 and key2 with value 200. What happens after running RENAME key1 key2?Redis
SET key1 100 SET key2 200 RENAME key1 key2 GET key2
Attempts:
2 left
💡 Hint
RENAME overwrites the destination key if it exists.
✗ Incorrect
The RENAME command changes the key name even if the new key exists, overwriting its value.
❓ query_result
intermediate2:00remaining
What does RENAMENX return if the new key exists?
Given keys
alpha with value foo and beta with value bar, what is the return value of RENAMENX alpha beta?Redis
SET alpha foo SET beta bar RENAMENX alpha beta
Attempts:
2 left
💡 Hint
RENAMENX only renames if the new key does not exist.
✗ Incorrect
RENAMENX returns 0 and does not rename if the new key exists.
📝 Syntax
advanced2:00remaining
Which command syntax is correct to rename a key only if the new key does not exist?
Choose the correct Redis command syntax to rename
oldkey to newkey only if newkey does not exist.Attempts:
2 left
💡 Hint
The command is RENAMENX, not RENAME with options.
✗ Incorrect
RENAMENX is the correct command to rename only if the new key does not exist.
🧠 Conceptual
advanced2:00remaining
What happens if you RENAME a key to the same key name?
If you run
RENAME mykey mykey in Redis, what is the result?Attempts:
2 left
💡 Hint
RENAME returns OK even if source and destination are the same.
✗ Incorrect
The RENAME command returns OK even when the source and destination keys are the same, and the key remains unchanged.
🔧 Debug
expert3:00remaining
Why does RENAMENX fail to rename when the new key does not exist?
You run these commands:
SET a 1
DEL b
RENAMENX a b
But RENAMENX returns 0 and does not rename. What is the most likely cause?Redis
SET a 1
DEL b
RENAMENX a bAttempts:
2 left
💡 Hint
Check if the source key exists before renaming.
✗ Incorrect
RENAMENX returns 0 if the source key does not exist, even if the destination key is missing.