Bitmap data structures, which record operations based on binary bits, have only 0 and 1 states. You can think of it as an array that only has zeros or ones in it.

What can you do?

In reality, there will be such scenarios, such as user information statistics, active and inactive users, logged in and unlogged users, clocked and unclocked users, such as only two states and a large amount of data, it is suitable to use Bitmap.

I found a comparison online to help you remember the advantages of Bitmap.

A, setbit

Sets or clears the key’s value(string) bit at offset.

The bit at that location is either set or cleared, depending on the value (which can only be 0 or 1). When key does not exist, a new string value is created.

For example, now I set a user’s 7 days of clocked information, 1 is clocked, 0 is not clocked.

setbit sign 0 1
setbit sign 1 1
setbit sign 3 1
setbit sign 4 0
setbit sign 5 1
setbit sign 6 0
setbit sign 2 1
Copy the code

Second, the getbit

Gets the bit at the specified offset for the string value stored by key.

getbit sign 4
Copy the code

Third, bitcount

Count the number of bits the string is set to 1.

Nonexistent keys are treated as empty strings, so BITCOUNT on a nonexistent key results in 0.

bitcount sign
Copy the code