SUBSTR
Deprecated
As of Redis version 2.0.0, this command is regarded as deprecated.
It can be replaced by GETRANGE when migrating or writing new code.
SUBSTR key start end
- Available since:
- Redis Open Source 1.0.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, determined by the
offsets start and end (both are inclusive).
Negative offsets can be used in order to provide an offset starting 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 |
Deprecated as of Redis v2.0.0. |
Return information
Bulk string reply: the substring of the string value stored at key, determined by the offsets start and end (both are inclusive).