当前位置:网站首页>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 
边栏推荐
- 全志V3s学习记录(13)OV2640的使用
- Solution to sudo PIP install gevent installation failure
- 5G正当时,无人驾驶未来将驶向何方?
- Set settings in vscode json
- How to use curl in Jenkins pipeline and process response results
- Redis 概述安装
- Stm32f103c8t6 hardware IIC control 4-pin 0.96 inch OLED display
- 如何将读取列表中的str转化为float
- 5.1 vulnérabilités et précautions en matière de sécurité
- No module named 'yaml' solution
猜你喜欢

Deep learning 7 deep feedforward network 2

Hand in hand practice a DAPP, the road to Web3.0!

【flask入门系列】请求钩子与上下文

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

WPF 三维应用搭建(基础)

Use of OpenCV polar transformation function warppolar

Redis 概述安装

依赖注入方式

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

With this "programmer code interview guide" from Zuo Chengyun (Zuo Shen), I joined byte
随机推荐
New redis6 features
Super dry! Thoroughly understand golang memory management and garbage collection
没那么大的组合数
Sword finger offer 42 Maximum sum dynamic programming method for continuous subarrays
Set settings in vscode json
Unity: WebGL发布后在浏览器上运行时窗口大小自适应
Bean、
60、wsgiref手写web框架+jinja2模块初识
JS学习笔记14-15:JS数组及数组字母量
1、flask基础
812. 最大三角形面积
openpyxl跨工作簿复制sheet页
Deep learning 7 deep feedforward network
数据库写入优化:分库分表及相关问题
5.1 安全漏洞與防範
【flask入门系列】异常处理
Redis6 新数据类型——Geospatial
visual studio 2022(VS 2022)无法读取内存的问题
How to convert STR in read list to float
DP dynamic planning enterprise level template analysis (Digital triangle, rising sequence, knapsack, state machine, compressed DP)