Upstash Documentation

AROP

Aggregate array values in an index range.
3 min read

Use AROP to reduce the values in an index range to a single number, on the server.

SUM, MIN, and MAX treat the values as numbers; AND, OR, and XOR fold them together as 64-bit integers, with fractional values truncated. All six ignore values that cannot be parsed as a number, and reply with null when the range contains nothing they could use, which distinguishes "no data" from a real result of 0. USED counts the occupied slots in the range and MATCH counts the slots whose value equals a given string; both always reply with an integer.

Running the reduction where the data lives keeps a range scan off the wire, which is the point when the array is a window of samples and you only need its total, extremes, or population.

See the array command overview for the data model these commands share.

Syntax#

Arguments#

ArgumentRequiredRepeatableDescription
<key>YesNoArray key targeted by the command.
<start>YesNoFirst index of the range, inclusive.
<end>YesNoLast index of the range, inclusive.
SUMNoNoSum of the numeric values in the range.
MINNoNoSmallest numeric value in the range.
MAXNoNoLargest numeric value in the range.
ANDNoNoBitwise AND of the values in the range, as 64-bit integers.
ORNoNoBitwise OR of the values in the range, as 64-bit integers.
XORNoNoBitwise XOR of the values in the range, as 64-bit integers.
USEDNoNoNumber of occupied slots in the range.
MATCH <value>NoNoNumber of slots in the range whose value equals <value>.

Important points#

  • Exactly one operation must be given.
  • Values that are not numbers are skipped by SUM, MIN, MAX, AND, OR, and XOR, and counted normally by USED and MATCH.
  • SUM, MIN, MAX, AND, OR, and XOR reply with null when no value in the range could be used. USED and MATCH reply with 0.

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.

ProtocolReply
RESP2Bulk string for SUM, MIN, and MAX; Integer for AND, OR, XOR, USED, and MATCH; Null bulk string when there is nothing to aggregate
RESP3Bulk string for SUM, MIN, and MAX; Integer for AND, OR, XOR, USED, and MATCH; Null when there is nothing to aggregate
Note

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
Note

This command is not supported yet in @upstash/redis.

upstash_redis
Note

This command is not supported yet in upstash_redis.

ioredis
node-redis
redis-py
go-redis
jedis
redis-rs