Bitmaps —

Bitmap is not the actual data type , But in String A set of bit oriented operations defined on a type . Because strings are binary safe blob, And their maximum length is 512 MB, So they are suitable for setting 2
^ 32 Different bits .

Bit operations are divided into two groups : Constant time unit operation , If the bit is set to 1 or 0, Or get its value , And working with bitgroups , For example, calculate the number of set digits within a given positioning range ( for example , Demography ).

One of the biggest advantages of bitmaps is that they usually save a lot of space when storing information . for example , Through incremental users ID In systems representing different users , You can use only 512MB Memory of 40 Single bit information of 100 million users ( for example , Know if users want to receive newsletters ).

use SETBIT and GETBIT Command settings and retrieval bits :

> setbit key 10 1
( integer )1
> getbit key 10
( integer )1
> getbit key 11
( integer )0
SETBIT Command takes the number of digits as its first parameter , Set the second parameter as the value of this bit , Namely 1 or 0. If the addressing bit exceeds the current string length , The command will automatically enlarge the string .

GETBIT Returns only the bit value at the specified index . Out of range bits ( Addressing bits beyond the length of the string stored in the target key ) Always considered zero .

There are three sets of commands running on a set of bits :

BITOP Bitwise between different strings . The operations provided are AND,OR,XOR and NOT.
BITCOUNT Perform population count , Report set to 1 Number of digits .
BITPOS Find has specified value 0 or 1 The first bit of .
BITPOS and BITCOUNT Can use the byte range of string for operation , Instead of running over the entire length of the string . Here is BITCOUNT A simple example of a call :

> setbit key 0 1
( integer )0
> setbit key 100 1
( integer )0
> bitcount key
( integer )2
The common user cases of bitmaps are :

Various real-time analysis .
Storage and objects ID Associated space efficient but high performance Boolean information .

for example , Imagine that you want to know the longest continuity of daily visits by website users . You start counting days from zero , That is, the date you published the website , And use the SETBIT Set up some . As bit index , You just need to get the current unix time , Subtract the initial offset , Then divide by 3600
* 24.

This is for each user , You have a small string containing daily access information . use BITCOUNT Easily get the number of days a given user has visited the site , Just a few times at a time BITPOS call , Or just get and analyze the client bitmap , You can easily calculate the longest stripe .

Bitmaps are easy to split into multiple keys , For example, to segment data sets , Because it's usually best to avoid using large keys . To split bitmaps on different keys instead of setting all bits as keys , A simple strategy is to store each key M Bit and get with tag /
M Key name and N Bits are used for bit addressing within the key - number MOD M.

©2019-2020 Toolsou All rights reserved,
Vue Transfer parameters and receiving of page Jump [AndroidO] [RK3399] -- GPIO Drive and control mode C Language confession practice small program ( Suitable for beginners )keras from dataframe Read data and enhance the data for training ( classification + division )Element-UI Implementation of secondary packaging TreeSelect Tree drop-down selection component ( Essence )2020 year 7 month 15 day Wechat applet assembly Component Use of vue use THREE.js Create a cube that you can control Fiddler Simulate request sending and modifying response data ( Essence )2020 year 8 month 15 day redis database StackExchange.Redis in Set type (C# edition ) Note 14 : The second biggest obstacle to motivating others in R & D management