Redis advanced data types

Bitmaps: Redis applied to information status statistics

If only one state (Y / N, 1/0) is stored, it can be stored in binary bits, with the number / id (the range / max is smaller and better) as the position

Set value bits setbit bits

Get value getbit bits position

 

Extended operation

Perform the bitwise, merge, not, exclusive OR operation on the specified key bit by bit, and save the result to destKey

bitop op destKey key1 [key2 ...]

and: pay or: and not: not xor: exclusive or

Count the number of 1s in the specified key

bitcount key [start end]

Business scene 

Movie website: count whether a movie is on demand every day; count how many movies are on demand every day; count how many movies are on demand every week / month / year; count which movies are not on demand every year

 

HyperLogLog: Count the number of unique data  Redis applies to independent information statistics

Cardinality statistics, cardinality set (set after deduplication)

Cardinality is the number of elements in the data set after deduplication. HyperLogLog is used for cardinality statistics, using the LogLog algorithm

Basic operation of HyperLogLog

Add data pfadd key element [element ...]

Statistics pfcount key [key ...]

Merge data pfmerge destkey sourcekey [sourcekey ...]

 

Description: Used for cardinality statistics, not a collection, no data is saved, only the number is recorded instead of specific data

The core is the cardinality estimation algorithm, there is a certain error in the final value

Error range: the result of cardinality estimation is an approximation with 0.81% standard error

Very small space consumption, each hyperloglog key occupies 12K of memory for marking cardinality

The pfadd command is not a one-time allocation of 12K memory, the memory will gradually increase as the cardinality increases

The storage space occupied by the pfmerge command after the merge is 12K, regardless of the amount of data before the merge

 

 

GEO  Redis is used to record geographic location information

People near WeChat / Momo

Meituan / Hungry?

Ctrip / Ma Honeycomb

Gaode / Baidu As long as it is related to offline, location-related things

 

Basic operation: key is the name of the GEO object

Geoadd key longitude latitude member [longitude latitude member ...]

Get coordinate point geopos key member [member ...]

Calculate the distance of the coordinate point geodist key member1 member2 [unit]-> only calculate the horizontal position The default unit is m-> unit

Find the data in the range according to the coordinates georadius key longitude latitude radius  

Find the data within the range according to the point georadius by member key member radius

Get the coordinate hash value corresponding to the specified point geohash key member

 

Guess you like

Origin www.cnblogs.com/liushoudong/p/12682887.html