Complete the code to get a substring from a Redis string key using GETRANGE.
GETRANGE mykey [1] 4
The GETRANGE command extracts a substring from the string stored at the key. The first argument after the key is the start index. Using 0 starts from the beginning.
Complete the code to set a substring in a Redis string key starting at offset 3 using SETRANGE.
SETRANGE mykey [1] "abc"
The SETRANGE command overwrites part of the string stored at the key, starting at the specified offset. Offset 3 means the substring starts at the fourth character.
Fix the error in the GETRANGE command to correctly get characters from index 2 to 5.
GETRANGE mykey [1] 5
The start index should be 2 to get characters from index 2 to 5 inclusive.
Fill both blanks to set the substring "xyz" starting at offset 1 and then get the substring from index 0 to 3.
SETRANGE mykey [1] "xyz" GETRANGE mykey 0 [2]
SETRANGE uses offset 1 to start replacing at the second character. GETRANGE uses 3 to get characters from index 0 to 3 inclusive.
Fill all three blanks to set "123" at offset 0, then "abc" at offset 3, and finally get substring from 0 to 5.
SETRANGE mykey [1] "123" SETRANGE mykey [2] "abc" GETRANGE mykey 0 [3]
First SETRANGE starts at offset 0 to set "123". Second SETRANGE starts at offset 3 to set "abc" after the first three characters. GETRANGE from 0 to 5 gets the first six characters.