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?
IntermediateAnswer
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-07Real-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.