> ## Documentation Index
> Fetch the complete documentation index at: https://upstash-redis-1-18.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# ARGETRANGE

> Get array values in an index range.

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`](/redis/commands/array/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](/redis/commands/array/overview) for the data model these commands share.

## Syntax

```redis theme={null}
ARGETRANGE <key> <start> <end>
```

## 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| + 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.

| Protocol | Reply                                       |
| -------- | ------------------------------------------- |
| RESP2    | Array of bulk strings and null bulk strings |
| RESP3    | Array 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.
</Note>

## Examples

TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`.

<AccordionGroup>
  <Accordion title="Redis CLI" icon="terminal">
    ```bash theme={null}
    ARGETRANGE my-array 0 9
    ```
  </Accordion>

  <Accordion title="@upstash/redis" icon="node-js" iconType="brands">
    <Note>
      This command is not supported yet in `@upstash/redis`.
    </Note>
  </Accordion>

  <Accordion title="upstash_redis" icon="python" iconType="brands">
    <Note>
      This command is not supported yet in `upstash_redis`.
    </Note>
  </Accordion>

  <Accordion title="ioredis" icon="node-js" iconType="brands">
    ```ts theme={null}
    import Redis from "ioredis";

    const redis = new Redis(process.env.REDIS_URL!);
    const result = await redis.argetrange("my-array", 0, 9);
    console.log(result);
    ```
  </Accordion>

  <Accordion title="node-redis" icon="node-js" iconType="brands">
    ```ts theme={null}
    import { createClient } from "redis";

    const client = await createClient({ url: process.env.REDIS_URL })
      .on("error", console.error)
      .connect();
    const result = await client.arGetRange("my-array", 0, 9);
    console.log(result);
    ```
  </Accordion>

  <Accordion title="redis-py" icon="python" iconType="brands">
    ```python theme={null}
    import os
    import redis

    client = redis.from_url(os.environ["REDIS_URL"])
    result = client.argetrange("my-array", 0, 9)
    print(result)
    ```
  </Accordion>

  <Accordion title="go-redis" icon="golang" iconType="brands">
    ```go theme={null}
    package main

    import (
        "context"
        "fmt"
        "os"

        "github.com/redis/go-redis/v9"
    )

    func main() {
        opts, err := redis.ParseURL(os.Getenv("REDIS_URL"))
        if err != nil {
            panic(err)
        }
        client := redis.NewClient(opts)
        result, err := client.ARGetRange(context.Background(), "my-array", 0, 9).Result()
        if err != nil {
            panic(err)
        }
        fmt.Println(result)
    }
    ```
  </Accordion>

  <Accordion title="jedis" icon="java" iconType="brands">
    ```java theme={null}
    import java.net.URI;

    import redis.clients.jedis.Jedis;

    try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) {
      Object result = jedis.argetrange("my-array", 0, 9);
      System.out.println(result);
    }
    ```
  </Accordion>

  <Accordion title="redis-rs" icon="rust" iconType="brands">
    ```rust theme={null}
    fn main() -> redis::RedisResult<()> {
        let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set");
        let client = redis::Client::open(url)?;
        let mut connection = client.get_connection()?;

        let mut command = redis::cmd("ARGETRANGE");
        command.arg("my-array");
        command.arg("0");
        command.arg("9");
        let result: redis::Value = command.query(&mut connection)?;
        println!("{result:?}");
        Ok(())
    }
    ```
  </Accordion>
</AccordionGroup>
