当前位置:网站首页>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 
边栏推荐
- sudo pip install gevent 安装失败的解决办法
- 手把手实践一个DAPP,通往Web3.0之路!
- C # read and write txt files
- 【flask入门系列】请求钩子与上下文
- DP dynamic planning enterprise level template analysis (Digital triangle, rising sequence, knapsack, state machine, compressed DP)
- With this "programmer code interview guide" from Zuo Chengyun (Zuo Shen), I joined byte
- 3D laser slam:aloam --- interpretation of inter frame odometer code
- Csp-2020-6- role authorization
- Error received from peer ipv4/Connection reset by peer Paddleserving服务化部署后报错
- 畅玩JVM——关于GC垃圾回收必须要掌握的知识
猜你喜欢

How does the V8 engine recycle garbage memory?
![Paddleserving服务化部署 tensorrt报错, shape of trt subgraph is [-1,-1,768],](/img/15/5dde91261a44fcfeda4d8436bb8559.png)
Paddleserving服务化部署 tensorrt报错, shape of trt subgraph is [-1,-1,768],

数组习题三

数据库写入优化:分库分表及相关问题

Redis的发布和订阅

Wvppro-zlm-gb21818-camera

OpenCV极坐标转换函数warpPolar的使用

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

最新一代互联网:WEB 3.0

Redis message subscription
随机推荐
Redis常用数据类型——Redis列表(List)和Redis 集合(Set)
最新一代互联网:WEB 3.0
Demo collection injection
65、Restful规范
[characteristic Engineering]
Will it be a little late to realize your "wonderful" 360?
Redis transaction
Wvppro-zlm-gb21818-camera
如何将读取列表中的str转化为float
5.1 security vulnerabilities and Prevention
Excellent résumé! Enfin quelqu'un a compris toutes les connexions SQL
How to use curl in Jenkins pipeline and process response results
依赖注入方式
深度学习之 7 深度前馈网络
leetcode:287. 寻找重复数【快慢指针板子】
《Flutter入门》flutter计算最近1个月、3个月、半年、12个月
Bean、
5.1 vulnérabilités et précautions en matière de sécurité
【flask入门系列】异常处理
Redis介绍