Redis › Strings & Bitmaps in Redis

How do you count the number of set bits within a bitmap, and how is this useful for analytics purposes?

Intermediate

Answer

You use the BITCOUNT command, which returns the total number of bits set to one within the specified range of a string, letting you efficiently calculate things like how many unique users were active on a specific day, since each active user's bit was set to one within that day's bitmap.
BITCOUNT user_active:2026-09-07
Real-world example An analytics dashboard displays the total number of active users for each day by running BITCOUNT against that day's bitmap, getting an accurate count without needing to store or iterate through an actual list of user identifiers.

Common follow-ups: How does BITCOUNT performance scale with the size of the bitmap?;Can you count bits within just a specific portion of a bitmap rather than the entire thing?