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

# ARSET

> Set contiguous array values from an index.

Use `ARSET` to write one or more values into an array, starting at a given index.

The first value goes to `<index>`, the next to `<index> + 1`, and so on, so a batch of readings can be placed at a known offset in one call. Any slot in the range that was empty becomes occupied, and any slot that already held a value is overwritten. The reply counts only the slots that were newly occupied, which makes it a cheap way to tell how much of a write was new data rather than a correction.

Writing past the end of the array does not shift anything: an array is sparse, so the slots between the previous highest index and the new one simply stay empty. `ARSET` never moves the append cursor used by [`ARINSERT`](/redis/commands/array/arinsert), so mixing positional writes with appends is safe.

See the [array command overview](/redis/commands/array/overview) for the data model these commands share.

## Syntax

```redis theme={null}
ARSET <key> <index> <value> [<value> ...]
```

## Arguments

| Argument  | Required | Repeatable | Description                                                                          |
| --------- | -------- | ---------- | ------------------------------------------------------------------------------------ |
| `<key>`   | Yes      | No         | Array key targeted by the command.                                                   |
| `<index>` | Yes      | No         | Zero-based index of the first value. Must be between `0` and `18446744073709551614`. |
| `<value>` | Yes      | Yes        | Value to store. Repeat to fill consecutive indexes starting at `<index>`.            |

## Important points

* The reply counts newly occupied slots only. Overwriting an existing value contributes `0`.
* An index outside the supported range, or a batch whose last index would exceed it, returns `ERR invalid array index`.

## 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    | Integer |
| RESP3    | Integer |

<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}
    ARSET my-array 0 hello world
    ```
  </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.arset("my-array", 0, "hello", "world");
    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.arSet("my-array", 0, ["hello", "world"]);
    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.arset("my-array", 0, "hello", "world")
    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.ARSet(context.Background(), "my-array", 0, "hello", "world").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.arset("my-array", 0, "hello", "world");
      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("ARSET");
        command.arg("my-array");
        command.arg("0");
        command.arg("hello");
        command.arg("world");
        let result: redis::Value = command.query(&mut connection)?;
        println!("{result:?}");
        Ok(())
    }
    ```
  </Accordion>
</AccordionGroup>
