Back to Redis

GETRANGE

content/commands/getrange.md

latest1.5 KB
Original Source

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. So -1 means the last character, -2 the penultimate and so forth.

The function handles out of range requests by limiting the resulting range to the actual length of the string.

Examples

{{% redis-cli %}} SET mykey "This is a string" GETRANGE mykey 0 3 GETRANGE mykey -3 -1 GETRANGE mykey 0 -1 GETRANGE mykey 10 100 {{% /redis-cli %}}

Redis Software and Redis Cloud compatibility

| Redis Software | Redis Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> | |:----------------------|:-----------------|:------| | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | |

Return information

{{< multitabs id="getrange-return-info" tab1="RESP2" tab2="RESP3" >}}

Bulk string reply: The substring of the string value stored at key, determined by the offsets start and end (both are inclusive).

-tab-sep-

Bulk string reply: The substring of the string value stored at key, determined by the offsets start and end (both are inclusive).

{{< /multitabs >}}