GETRANGE
GETRANGE key start end
- Available since:
- Redis Open Source 2.4.0
- Time complexity:
- O(N) where N is the length of the returned string. The complexity is ultimately determined by the returned length, but because creating a substring from an existing string is very cheap, it can be considered O(1) for small strings.
- ACL categories:
-
@read,@string,@slow, - Compatibility:
- Redis Software and Redis Cloud compatibility
Returns the substring of the string value stored at key, as determined by the start and end offsets. Both offsets are inclusive.
You can use negative offsets to count backward from the end of the string. For example, -1 is the last character, -2 is the penultimate character, and so on.
The function handles out of range requests by limiting the resulting range to the actual length of the string.
Required arguments
key
The name of the key.
start
The start offset, zero-based. A negative value counts from the end of the string.
end
The end offset, zero-based and inclusive. A negative value counts from the end of the string.
Examples
Redis Software and Redis Cloud compatibility
| Redis Software |
Redis Cloud |
Notes |
|---|---|---|
| ✅ Standard |
✅ Standard |
Return information
Bulk string reply: The substring of the string value stored at key, determined by the offsets start and end (both are inclusive).