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#
| Argument | Required | Repeatable | Description |
|---|---|---|---|
<key> | Yes | No | Array key targeted by the command. |
<start> | Yes | No | First index of the range, inclusive. |
<end> | Yes | No | Last index of the range, inclusive. |
Important points#
- The range is inclusive at both ends and the reply always has
|end - start| + 1elements. - 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.
| Protocol | Reply |
|---|---|
| RESP2 | Array of bulk strings and null bulk strings |
| RESP3 | Array of bulk strings and nulls |
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
This command is not supported yet in @upstash/redis.
upstash_redis
This command is not supported yet in upstash_redis.