当前位置:网站首页>Redis6 new data type - hyperloglog
Redis6 new data type - hyperloglog
2022-07-19 08:27:00 【Illusory clarity】
1. brief introduction
At work , We often encounter functional requirements related to statistics , For example, statistical websites PV (PageView Page visits ), have access to Redis Of incr、incrby Make it easy . But like UV(UniqueVisitor, Independent visitor )、 Independent IP Count 、 The number of search records needs to be de duplicated and How to solve the problem of counting ? The problem of finding the number of non repeating elements in a set is called the cardinality problem . There are many solutions to the cardinality problem :
(1) The data is stored in MySQL In the table , Use distinct count Calculate the number of non duplicates
(2) Use Redis Provided hash、set、bitmaps And other data structures
The results of the above scheme are accurate , But as the data increases , Resulting in more and more occupied space , For non Very large data sets are impractical .
Whether it can reduce a certain accuracy to balance the storage space ?Redis Launched HyperLogLog
Redis HyperLogLog It's an algorithm for cardinality statistics ,HyperLogLog The advantages of , When the number or volume of input elements is very, very large , The space needed to calculate the cardinality is always fixed 、 And it's very small Of .
stay Redis Inside , Every HyperLogLog Keys only cost 12 KB Memory , You can calculate the connection near 2^64 Cardinality of different elements . This is the same as calculating the cardinality , The more elements consume memory, the more collections there are .
however , because HyperLogLog Only the input elements will be used to calculate the cardinality , Instead of storing input elements In itself , therefore HyperLogLog It can't be like a collection , Return the various elements of the input .
What is the cardinality ?
Like data sets {1, 3, 5, 7, 5, 7, 8}, So the cardinality set of this dataset is {1, 3, 5 ,7, 8}, base ( Don't repeat elements ) by 5. Cardinality estimation is within the range of acceptable error , Fast base calculation .
2. command
1、pfadd
(1) Format pfadd <key>< element> [element ...] Add specified elements to HyperLogLog in 
(2) example

Adds all elements to the specified HyperLogLog In the data structure . If after executing the command HLL The approximate cardinality of the estimate changes , Then return to 1, Otherwise return to 0.
2、pfcount
(1) Format pfcount<key> [key ...] Calculation HLL The approximate cardinality of , Multiple can be calculated HLL, For example, use HLL Store daily UV, Calculate a week's UV have access to 7 Days of UV Consolidation calculation is enough

(2) example 
3、pfmerge
(1) Format pfmerge<destkey><sourcekey> [sourcekey ...] Put one or more HLL The merged results are stored in another HLL in , For example, monthly active users can use daily active users to consolidate and calculate the available 
(2) example 
边栏推荐
猜你喜欢

3D激光SLAM:ALOAM---帧间里程计代码解读

行为型模式之策略模式

Application of SCA on devsecops platform

Redis6新数据类型——HyperLogLog

Real case: how to check the soaring usage of CPU after the system goes online?

Bean、

Junit5

Viewing the technology stack of distributed system from the crash report of station B

Database review -- database recovery technology

黑马程序员-软件测试-16阶段3-功能测试-175-198,URL组成介绍,请求内容以及组成说明行功能测试与数据库,url组成扩展说明,客户端与服务器请求与响应,-Fiddler按照以及功能检查确认,
随机推荐
1、决策树
一款关于日常习惯打卡的小程序
Database review -- database recovery technology
Dependency injection method
Consul服务注册与发现
【flask入门系列】异常处理
OI回忆录
Interview question: outer margin folding problem (bug of block level elements in ordinary document flow)
總結的太好了!終於有人把SQL的各種連接Join都講明白了
Seaport 以及 ERC-4907 能否成为释放NFT流动性的新途径?| Tokenview
Visual studio 2022 (vs 2022) cannot read memory
SCA在得物DevSecOps平台上应用
Strategic model of behavioral model
在VSCode中设置settings.json
TextView文字上下移动
1. Flask Foundation
Stm32f103c8t6 hardware IIC control 4-pin 0.96 inch OLED display
Redis transaction
How to use curl in Jenkins pipeline and process response results
Leetcode daily question 2021/7/11-2021/7/17