Use ARINSERT to append one or more values to the end of an array.
Each array keeps an append cursor holding the last index written by an append, so ARINSERT does not need to look up where the data ends: the first value goes to the slot after the cursor, the rest follow it, and the cursor moves to the last one. The reply is the index that last value received, which is what a producer records to point at what it just wrote.
Because the cursor is separate from the contents, appending is unaffected by deletions: freeing slots with ARDEL never causes a later append to reuse an index. Use ARSEEK to move the cursor deliberately and ARNEXT to read where the next append would land.
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. |
<value> | Yes | Yes | Value to append. Repeat to append several values in one call. |
Important points#
- The reply is the index of the last value written, not the number of values written.
- Appending past the highest supported index returns
ERR insert index overflow.
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, or bulk string when the index exceeds the signed 64-bit range |
| RESP3 | Integer, or Big number when the index exceeds the signed 64-bit range |
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.