Upstash Documentation

ARGETRANGE

Get array values in an index range.
2 min read

Use ARGETRANGE to read every slot in an inclusive index range.

The reply always has exactly one element per index in the range, with null for the slots that are empty, so the position of a value in the reply tells you its index without sending the indexes back. That makes it the right command when the range is mostly populated; for a sparse range, ARSCAN returns only the occupied slots together with their indexes.

Passing a start greater than the end reverses the order of the reply rather than returning an error, which is how you read a window newest-first. A range wider than 1,000,000 indexes is rejected, because the reply is materialized in full.

See the array command overview for the data model these commands share.

Syntax#

Arguments#

ArgumentRequiredRepeatableDescription
<key>YesNoArray key targeted by the command.
<start>YesNoFirst index of the range, inclusive.
<end>YesNoLast index of the range, inclusive.

Important points#

  • The range is inclusive at both ends and the reply always has |end - start| + 1 elements.
  • When <start> is greater than <end>, the reply is ordered from the higher index down to the lower one.
  • A range covering more than 1,000,000 indexes returns ERR range exceeds maximum of 1000000 items.

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.

ProtocolReply
RESP2Array of bulk strings and null bulk strings
RESP3Array of bulk strings and nulls
Note

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 TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.

Redis CLI
@upstash/redis
Note

This command is not supported yet in @upstash/redis.

upstash_redis
Note

This command is not supported yet in upstash_redis.

ioredis
node-redis
redis-py
go-redis
jedis
redis-rs