Skip to main content
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, so mixing positional writes with appends is safe. See the array command overview for the data model these commands share.

Syntax

Arguments

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.
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.
This command is not supported yet in @upstash/redis.
This command is not supported yet in upstash_redis.