Challenge - 5 Problems
Redis String Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of GETRANGE after SETRANGE?
Given a Redis key
mykey with initial value "Hello World", what will be the result of GETRANGE mykey 6 10 after running SETRANGE mykey 6 "Redis"?Redis
SET mykey "Hello World" SETRANGE mykey 6 "Redis" GETRANGE mykey 6 10
Attempts:
2 left
💡 Hint
Remember SETRANGE replaces part of the string starting at the given offset.
✗ Incorrect
The SETRANGE command replaces the substring starting at index 6 with "Redis", so the string becomes "Hello Redis". Then GETRANGE from 6 to 10 returns "Redis".
❓ query_result
intermediate2:00remaining
What does GETRANGE return for out-of-bound indexes?
If the Redis key
msg has value "OpenAI", what is the result of GETRANGE msg 3 10?Redis
SET msg "OpenAI" GETRANGE msg 3 10
Attempts:
2 left
💡 Hint
GETRANGE returns substring up to the end if end index is beyond string length.
✗ Incorrect
The string "OpenAI" has length 6. GETRANGE from index 3 to 10 returns substring from 3 to end, which is "nAI".
📝 Syntax
advanced2:00remaining
Which SETRANGE command is syntactically correct?
Choose the correct syntax to replace part of the string stored at key
data starting at offset 4 with "Test".Attempts:
2 left
💡 Hint
The offset must be an integer and the value a string enclosed in quotes.
✗ Incorrect
SETRANGE requires the offset as an integer and the value as a string. Option C correctly uses integer 4 and string "Test".
❓ optimization
advanced2:00remaining
Efficiently update a substring in a large Redis string
You have a large string stored in Redis key
bigtext. You want to replace characters from position 1000 to 1004 with "Hello". Which command is the most efficient?Attempts:
2 left
💡 Hint
SETRANGE modifies the string in place without transferring the whole string.
✗ Incorrect
SETRANGE modifies the string directly on the server at the specified offset, avoiding large data transfer.
🧠 Conceptual
expert3:00remaining
What happens if SETRANGE offset is beyond current string length?
If the Redis key
key1 has value "abc", what is the result of SETRANGE key1 5 "xyz" followed by GET key1?Redis
SET key1 "abc" SETRANGE key1 5 "xyz" GET key1
Attempts:
2 left
💡 Hint
SETRANGE pads with zero-bytes if offset is beyond string length.
✗ Incorrect
SETRANGE pads the string with zero-bytes (\u0000) up to the offset before inserting the new substring.