0
0
Redisquery~10 mins

GETRANGE and SETRANGE in Redis - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get a substring from a Redis string key using GETRANGE.

Redis
GETRANGE mykey [1] 4
Drag options to blanks, or click blank then click option'
A10
B0
C-1
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using a negative start index without understanding it counts from the end.
Using an index larger than the string length.
2fill in blank
medium

Complete the code to set a substring in a Redis string key starting at offset 3 using SETRANGE.

Redis
SETRANGE mykey [1] "abc"
Drag options to blanks, or click blank then click option'
A3
B-1
C0
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using negative offsets which are invalid for SETRANGE.
Confusing the offset with the length of the substring.
3fill in blank
hard

Fix the error in the GETRANGE command to correctly get characters from index 2 to 5.

Redis
GETRANGE mykey [1] 5
Drag options to blanks, or click blank then click option'
A5
B1
C3
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at index 1 which skips the first character.
Using the end index as the start index.
4fill in blank
hard

Fill both blanks to set the substring "xyz" starting at offset 1 and then get the substring from index 0 to 3.

Redis
SETRANGE mykey [1] "xyz"
GETRANGE mykey 0 [2]
Drag options to blanks, or click blank then click option'
A1
B2
C3
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using offset 0 for SETRANGE which replaces from the first character.
Using 2 as the end index in GETRANGE which returns fewer characters.
5fill in blank
hard

Fill all three blanks to set "123" at offset 0, then "abc" at offset 3, and finally get substring from 0 to 5.

Redis
SETRANGE mykey [1] "123"
SETRANGE mykey [2] "abc"
GETRANGE mykey 0 [3]
Drag options to blanks, or click blank then click option'
A0
B3
C5
D6
Attempts:
3 left
💡 Hint
Common Mistakes
Using offset 1 instead of 0 for the first SETRANGE.
Using 6 as the end index in GETRANGE which returns too many characters.