Skip to main content
Use BITCOUNT to count the bits set to 1 in the string stored at a key. Without a range the whole value is counted. <start> and <end> restrict the count to a part of the value and are interpreted as byte offsets by default, or as bit offsets when BIT is given. Both ends are inclusive and may be negative to count backwards from the end of the value, where -1 is the last byte or bit. A missing key is treated as an empty string and returns 0. BITCOUNT is the usual way to read a bitmap built with SETBIT, for example to count how many users were active on a given day when each user has a fixed bit position.

Syntax

Arguments

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 TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.