当前位置:网站首页>11_ Redis_ Hyperloglog_ command
11_ Redis_ Hyperloglog_ command
2022-07-02 15:19:00 【Listen to the rain】
Hyperloglog
What is the cardinality ?
A{ 1,3,5,7,8,7 }
B{ 1,3,5,7,8 }
base ( Elements that don't repeat ) = 5, The error is acceptable !
brief introduction
Redis 2.8.9 The version is updated Hyperloglog data structure !
Redis Hyperloglog The algorithm of cardinality Statistics !
advantage : The memory occupied is fixed ,2^64 Different elements of Technology , Just waste 12KB Memory ! If you want to compare from the memory point of view Hyperloglog The preferred !
Web page UV( A person visits a website many times , But still count as a person ! ) 0.81% Error rate ! Statistics UV Mission , Negligible !
The traditional way ,set( Elements are not allowed to repeat ) Save the user's id, And then you can count set The number of elements in as a standard judgment !
This way, if you save a large number of users id, It will be more troublesome ! Our purpose is to count , Instead of saving users id;
127.0.0.1:6379> PFADD mykey a b c d e f g h i j k // Create the first set of elements
(integer) 1
127.0.0.1:6379> PFCOUNT mykey // Statistics mykey The cardinal number of elements
(integer) 11
127.0.0.1:6379> PFADD mykey2 i j k z d e // Create a second set of elements mykey2
(integer) 1
127.0.0.1:6379> PFCOUNT mykey2
(integer) 6
127.0.0.1:6379> PFMERGE mykey3 mykey mykey2 // Combine the two groups mykey mykey2 => mykey3 Combine
OK
127.0.0.1:6379> PFCOUNT mykey3 // Look at the number of unions !
(integer) 12
If fault tolerance is allowed , Then it must be possible to use Hyperloglog
If fault tolerance is not allowed , Just use set Or your own data type !
边栏推荐
猜你喜欢
随机推荐
871. 最低加油次数 : 简单优先队列(堆)贪心题
871. Minimum refueling times: simple priority queue (heap) greedy question
数据库内容输出有问题怎么解决
21_ Redis_ Analysis of redis cache penetration and avalanche
Base64 coding can be understood this way
C语言实现N皇后问题
Tidb cross data center deployment topology
TiDB数据迁移场景综述
学习使用php实现公历农历转换的方法代码
10_Redis_geospatial_命令
XML Configuration File
Record an interview
05_ queue
C RichTextBox controls the maximum number of lines displayed
Learn the method code example of converting timestamp to uppercase date using PHP
14_Redis_乐观锁
实用调试技巧
c语言入门--数组
21_Redis_浅析Redis缓存穿透和雪崩
forEach的错误用法,你都学废了吗