Difficulty: Advanced
What are Redis Bitmaps, and what is a good real-world use case for them?
Redis Bitmaps are not a separate type; they are bit-level operations on a regular string value, where each bit at an offset represents a yes/no fact about something with a numeric ID. The classic use case is tracking daily active users: set bit N to 1 when user N is active today, then count the ones. With 10 million users, one day's bitmap is only about 1.25 MB.
SETBIT key offset 1 sets the bit at offset. Redis grows the string automatically, padding with zeros.GETBIT key offset returns 0 or 1.BITCOUNT key counts set bits. Since Redis 7.0 you can pass a range with a BYTE or BIT unit.BITOP AND|OR|XOR|NOT destkey key1 key2 ... combines bitmaps into a new key.BITPOS key 1 finds the first set bit, and BITFIELD reads or writes multi-bit integers at arbitrary offsets.Say a Swiggy-style app has numeric user IDs from 1 to 10 million.
SETBIT dau:2026-10-12 <userId> 1. Setting a bit that is already 1 does nothing, so duplicates are free.BITCOUNT dau:2026-10-12.BITOP OR wau:2026-w41 dau:2026-10-06 ... dau:2026-10-12, then BITCOUNT wau:2026-w41.BITOP AND instead of OR.GETBIT dau:2026-10-12 42.The same idea works for attendance, feature flag rollouts, "has this user seen the onboarding", or a per-day login streak.
| Aspect | Bitmap | Set of user IDs |
|---|---|---|
| Memory for 10M users, all active | about 1.25 MB | hundreds of MB |
| Memory for 1,000 active users with IDs near 10M | still about 1.25 MB | a few KB |
| Membership check | GETBIT, O(1) | SISMEMBER, O(1) |
| List the actual members | Hard, scan bits | SMEMBERS |
| Union/intersection | BITOP, very fast | SUNION, SINTER |
Bitmaps shine when IDs are dense and the set is a large fraction of all IDs. If IDs are sparse or huge (UUIDs, or numeric IDs starting at 9,000,000,000), the bitmap wastes space and you should use a set or HyperLogLog.
SETBIT at offset 4 billion allocates a 512 MB string at once and can block the server. Keep offsets bounded and map IDs to a dense range.BITCOUNT and BITOP are O(N) in string length. For very large bitmaps, run them off-peak or on a replica.BITOP needs all keys in the same slot, so use hash tags like dau:{2026-10}:12.# Users 5, 42 and 1001 were active on Monday
redis-cli SETBIT dau:2026-10-06 5 1
redis-cli SETBIT dau:2026-10-06 42 1
redis-cli SETBIT dau:2026-10-06 1001 1
# Users 42 and 77 were active on Tuesday
redis-cli SETBIT dau:2026-10-07 42 1
redis-cli SETBIT dau:2026-10-07 77 1
redis-cli BITCOUNT dau:2026-10-06 # DAU Monday
# Active on any day, and on both days
redis-cli BITOP OR active:any dau:2026-10-06 dau:2026-10-07
redis-cli BITOP AND active:both dau:2026-10-06 dau:2026-10-07
redis-cli BITCOUNT active:any
redis-cli BITCOUNT active:both
redis-cli GETBIT dau:2026-10-07 5 # was user 5 active Tuesday?
Outputs of SETBIT and BITOP are omitted. Four users were active on at least one day (5, 42, 77, 1001), and only user 42 was active on both.
Bitmaps, SETBIT and GETBIT, BITCOUNT, BITOP, Daily Active Users