getrange
GETRANGE
Get a substring
Specify start and end.
The leftmost (front) character of the string starts at 0.
The specified indexes are inclusive.
end is a position, not the length of the string.
Example
| Command> | set key "This is Redis Server"
|
| Result> | OK
|
| Command> | getrange key 0 3
|
| Result> | This
|
| Command> | getrange key 8 12
|
| Result> | Redis
|
| Command> | getrange key 8 100
|
| Result> | Redis Server
|
Negative indexes are allowed
Use a negative index to read from the end of the string.
The last character starts at -1.
Example
| Command> | getrange key -6 -1
|
| Result> | Server
|
| Command> | getrange key 0 -1 Use 0 -1 to get the entire string
|
| Result> | This is Redis Server
|
Syntax
GETRANGE key start end
- Available since version 2.4.0.
- Added as SUBSTR in version 2.0 and renamed to GETRANGE in 2.4.
- Time complexity depends on the returned string.
Treat it as O(N) when the returned string is long, and O(1) when it is short.