Suggest an editImprove this articleRefine the answer for “What is Bitmap?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)Bitmap in Redis is a way to store and manipulate sequences of bits (0s and 1s) on top of an ordinary string (String): it's not really a separate data type, but a set of bit operations on a Redis String, letting you use it as a bitmap up to 512 MB long (up to 4 billion bits). **Key point:** the key commands are `SETBIT`/`GETBIT` for a single bit, `BITCOUNT` for counting set bits, and `BITOP` for bitwise AND/OR/XOR/NOT between several bitmaps; a typical use is tracking daily user activity or boolean flags.Shown above the full answer for quick recall.Answer (EN)Image**Bitmap** in Redis is a way to store and manipulate **sequences of bits (0s and 1s)** on top of an ordinary string (String). It's not really a separate data type, it's a **set of bit operations on a Redis String** that let you use it as a bitmap. ### The core idea A Redis String can be thought of as an array of bits up to 512 MB long → that's **up to 4 billion bits** (4×10⁹ boolean values). Every bit can be set (`1`) or cleared (`0`), then read or counted. ### Example ```bash SETBIT userlogins 5 1 GETBIT userlogins 5 ``` Result: ```javascript 1 ``` Bit 5 is set to `1`. ### Main commands | Command | Description | |---|---| | `SETBIT key offset value` | set a bit's value (0 or 1) | | `GETBIT key offset` | get a bit's value | | `BITCOUNT key [start end]` | count how many bits are set to 1 | | `BITOP operation destkey key [key ...]` | bitwise operations (AND, OR, XOR, NOT) | | `BITPOS key bit [start end]` | find the first bit with a given value | ### A counting example ```bash SETBIT active_users 1 1 SETBIT active_users 5 1 SETBIT active_users 7 1 BITCOUNT active_users ``` Result: ```javascript 3 ``` Three bits are set to `1`. ### Bitwise operations ```bash BITOP AND result key1 key2 BITOP OR result key1 key2 BITOP XOR result key1 key2 BITOP NOT result key ``` These let you intersect or union several bitmaps. ### Internal structure A Bitmap is an ordinary Redis String, where every byte is made of 8 bits. Redis doesn't preallocate memory: if you set a bit at a large offset, everything before it is filled with zeros. ### Uses - Tracking daily user activity (1, active, 0, not). - Counting unique visits. - Storing boolean flags (did/didn't perform an action). - Simple analytics and statistics systems. - Compressing binary data or feature flags. ### An activity-tracking example ```bash SETBIT logins:2025-10-21 12345 1 GETBIT logins:2025-10-21 12345 BITCOUNT logins:2025-10-21 ``` User ID 12345 is marked active for the day, and the total number of active users can be read instantly.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.