0
0
Redisquery~20 mins

GETRANGE and SETRANGE in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis String Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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
A"World"
B"Redis"
C"Redisorld"
D"Hello"
Attempts:
2 left
💡 Hint
Remember SETRANGE replaces part of the string starting at the given offset.
query_result
intermediate
2: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
A"nAI"
B"nAI\u0000\u0000\u0000\u0000"
C"OpenAI"
D""
Attempts:
2 left
💡 Hint
GETRANGE returns substring up to the end if end index is beyond string length.
📝 Syntax
advanced
2: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".
ASETRANGE data "4" "Test"
BSETRANGE data 4 Test
CSETRANGE data 4 "Test"
DSETRANGE data 4 'Test'
Attempts:
2 left
💡 Hint
The offset must be an integer and the value a string enclosed in quotes.
optimization
advanced
2: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?
ASETRANGE bigtext 1000 "Hello"
B
GET bigtext
Modify substring in client
SET bigtext modified_string
CAPPEND bigtext "Hello"
D
GETRANGE bigtext 0 999
APPEND "Hello"
Attempts:
2 left
💡 Hint
SETRANGE modifies the string in place without transferring the whole string.
🧠 Conceptual
expert
3: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
A"abc xyz"
BError: offset out of range
C"abcxyz"
D"abc\u0000\u0000xyz"
Attempts:
2 left
💡 Hint
SETRANGE pads with zero-bytes if offset is beyond string length.