0
0
Redisquery~20 mins

RENAME and RENAMENX in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Rename Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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
AReturns an error because key2 already exists
BDeletes both keys and returns nil
CDoes nothing and returns OK; GET key2 returns 200
DRenames key1 to key2, overwriting the old key2 value; GET key2 returns 100
Attempts:
2 left
💡 Hint
RENAME overwrites the destination key if it exists.
query_result
intermediate
2: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
A0, because beta already exists and rename did not happen
B1, because the rename succeeded
CAn error because beta exists
Dnil, because alpha does not exist
Attempts:
2 left
💡 Hint
RENAMENX only renames if the new key does not exist.
📝 Syntax
advanced
2: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.
ARENAMENX oldkey newkey
BRENAME oldkey newkey NX
CRENAME IF NOT EXISTS oldkey newkey
DRENAMEX oldkey newkey
Attempts:
2 left
💡 Hint
The command is RENAMENX, not RENAME with options.
🧠 Conceptual
advanced
2: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?
AReturns an error because source and destination are the same
BDeletes the key
CReturns OK and does nothing
DRenames the key to a new random key
Attempts:
2 left
💡 Hint
RENAME returns OK even if source and destination are the same.
🔧 Debug
expert
3: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 b
AKey 'b' still exists, so RENAMENX refuses to rename
BKey 'a' does not exist at the time of RENAMENX
CRENAMENX cannot rename keys with numeric values
DRENAMENX requires both keys to exist
Attempts:
2 left
💡 Hint
Check if the source key exists before renaming.