GETRANGE to read part of the string stored at a key.
<start> and <end> are zero-based byte offsets, both inclusive, and may be negative to count from the end, so GETRANGE key 0 -1 returns the whole value. Offsets outside the string are clamped rather than treated as errors, and a missing key returns an empty string.
Since the range is applied on the server, this is how you read the head of a large value, or a fixed-width field inside one, without transferring the rest. SUBSTR is accepted as a deprecated alias with the same arguments and reply.
Syntax
Arguments
Important points
SUBSTRis accepted as a deprecated alias with the same arguments and reply. New code should useGETRANGE.
Response
The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.
Examples
TCP examples use the TLSREDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.
Redis CLI
Redis CLI
@upstash/redis
@upstash/redis
upstash_redis
upstash_redis
ioredis
ioredis
node-redis
node-redis
redis-py
redis-py
go-redis
go-redis
jedis
jedis
redis-rs
redis-rs