SUBSTR
Deprecated: use GETRANGE instead.
SUBSTR key start end
- Group
- String
- Complexity
- O(N) where N is the length of the returned substring
- Arity
- 4 (exactly, counting the command name)
- Flags
- read-only
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
SUBSTR is an older name for GETRANGE and behaves the
same way: it returns the bytes from start to end, both included, with
negative offsets counting from the end. Use GETRANGE in new code.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Always | Bulk string: the substring (possibly empty) | Bulk string |
The errors are those of GETRANGE.
Examples
Section titled “Examples”127.0.0.1:6379> SET phrase "hotkv rocks"OK127.0.0.1:6379> SUBSTR phrase 0 4"hotkv"Compatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8, where it is also deprecated.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.