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
Important points
- Exactly one operation must be given.
- Values that are not numbers are skipped by
SUM,MIN,MAX,AND,OR, andXOR, and counted normally byUSEDandMATCH. SUM,MIN,MAX,AND,OR, andXORreply with null when no value in the range could be used.USEDandMATCHreply with0.
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 TLSREDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.
Redis CLI
Redis CLI
@upstash/redis
@upstash/redis
This command is not supported yet in
@upstash/redis.upstash_redis
upstash_redis
This command is not supported yet in
upstash_redis.ioredis
ioredis
node-redis
node-redis
redis-py
redis-py
go-redis
go-redis
jedis
jedis
redis-rs
redis-rs