0
0
Redisquery~5 mins

GETRANGE and SETRANGE in Redis - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the Redis command GETRANGE do?
GETRANGE returns a substring of the string stored at a given key. You specify the start and end positions, and it returns the part of the string between them.
Click to reveal answer
beginner
How does SETRANGE modify a string in Redis?
SETRANGE changes part of the string stored at a key, starting at a specified offset, by overwriting it with a new substring. If the string is shorter, it is extended with zero bytes.
Click to reveal answer
intermediate
What happens if the end index in GETRANGE is beyond the string length?
GETRANGE returns the substring from the start index to the end of the string without error, even if the end index is beyond the string length.
Click to reveal answer
intermediate
If you use SETRANGE with an offset larger than the current string length, what does Redis do?
Redis pads the string with zero bytes up to the offset, then writes the new substring starting at that offset.
Click to reveal answer
intermediate
Can GETRANGE and SETRANGE be used on keys that do not exist?
GETRANGE on a non-existing key returns an empty string. SETRANGE on a non-existing key creates a new string padded with zero bytes as needed.
Click to reveal answer
What does GETRANGE key 0 4 return if the string stored is 'hello world'?
A"hell"
B"hello"
C"hello "
D"ello"
If you run SETRANGE key 6 "Redis" on the string 'hello world', what is the new string?
A"hello Redisld"
B"hello Redisd"
C"hello Redis"
D"sideR olleh"
What does GETRANGE return if the key does not exist?
AEmpty string
BError
CNull
DZero bytes
What happens if SETRANGE is used with an offset larger than the string length?
AError is returned
BString is truncated
CNothing happens
DString is padded with zero bytes up to offset
Which command would you use to get a part of a string stored in Redis?
AGETRANGE
BSET
CGET
DSETRANGE
Explain how GETRANGE works in Redis and what happens if the requested range exceeds the string length.
Think about how you would cut a piece of a rope from start to end positions.
You got /4 concepts.
    Describe how SETRANGE modifies a string in Redis and what happens if the offset is beyond the current string length.
    Imagine painting over a wall starting at a certain point, and filling empty space if needed.
    You got /4 concepts.