Use ARRING to append values to an array that wraps around after a fixed number of slots.
The array is confined to indexes 0 through <size> - 1. Appends advance the same cursor ARINSERT uses, but wrap back to 0 on reaching the end, so the newest <size> values are kept and older ones are overwritten in place. That bounds the memory a stream of writes can consume without any trimming command, which is what makes it a fit for rolling windows such as the last N samples or the last N log lines.
The size is stored with the key and every call restates it. Calling ARRING with a different size reshapes the ring: the most recent values that still fit are kept and relaid from index 0, and anything outside the new window is dropped. The reply is the index the last value was written to; read the window back with ARLASTITEMS, which follows the cursor and returns the values in write order.
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. |
<size> | Yes | No | Number of slots in the ring. Must be greater than 0. |
<value> | Yes | Yes | Value to append. Repeat to append several values in one call. |
Important points#
- The reply is the index the last value was written to, not the number of values written.
- Calling
ARRINGwith a size different from the stored one rebuilds the ring, keeping the most recent values that fit in the new size. - Writing more values than
<size>in one call leaves only the last<size>of them.
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.