Upstash Documentation

ARCOUNT

Count the values stored in an array.
2 min read

Use ARCOUNT to get the number of occupied slots in an array.

This is the count of values actually stored, so holes left by ARDEL or by writing to scattered indexes are not counted. It is therefore different from ARLEN, which reports how far the array extends. For a densely filled array the two agree; for a sparse one, ARCOUNT is the smaller number and the one that tracks stored data.

A key that does not exist counts as 0.

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

Syntax#

Arguments#

ArgumentRequiredRepeatableDescription
<key>YesNoArray key targeted by the command.

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
RESP2Integer
RESP3Integer
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