当前位置:网站首页>Redis~geospatial (geospatial), hyperloglog (cardinality Statistics)
Redis~geospatial (geospatial), hyperloglog (cardinality Statistics)
2022-06-28 02:31:00 【Minsk open source】
Get the coordinates of Xi'an ——GEOPOS
127.0.0.1:6379> GEOPOS CHINA xian
- “108.94683212041854858”
“34.29296115814533863”
In longitude 120 latitude 35 Position centered , Get the radius 1000 Cities within kilometers ——GEORADIUS
127.0.0.1:6379> GEORADIUS CHINA 120 35 1000 km
“beijing”
“shanghai”
Get the radius in Guangzhou 500 Cities within kilometers ——GEORADIUSBYMEMBER
127.0.0.1:6379> GEORADIUSBYMEMBER CHINA guangzhou 500 km
“shenzhen”
“guangzhou”
“hainan”
Convert the coordinates of Guangzhou and Shenzhen to 11 For the purpose of GEO Hash value ——GEOHASH
127.0.0.1:6379> GEOHASH CHINA guangzhou shenzhen
“ws0e9cb3yj0”
“ws10k0dcg10”
[](()Hyperloglog( Base Statistics )
-------------- 《 A big factory Java Analysis of interview questions + Back end development learning notes + The latest architecture explanation video + Practical project source code handout 》 Free open source Prestige search official account 【 Advanced programming 】 ------------------------------------------------------------------
After we count the number of visits to the website 、 Daily activity hours , Because we count the number of users, not the number of visits , Therefore, even if a user visits multiple times, it will only be counted once , This non repeating data is often referred to as cardinality .
In traditional practice , We usually use set To save the user's ID To count , Because it has the function of de duplication , But what we need is to count the users , If all users' ID Save the method to complete , When the number of users is large, there will be a huge pressure on the memory , And the efficiency is greatly reduced .
To solve this problem ,Redis stay 2.8.9 Version added HyperLogLog structure .
[](() Realization principle
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 .
stay Redis Inside , Every HyperLogLog Keys only cost 12KB Memory , So we can calculate the proximity 2^64 Cardinality of different elements . This is the same as calculating the cardinality , The more elements consume memory, the more collections there are .
HyperLogLog Using a probabilistic algorithm , By storing elements of hash The first one worth it 1 The location of , To calculate the number of elements , therefore HyperLogLog The element itself is not stored , There may also be some errors when the amount of data is large . But in terms of cardinality Statistics , Its effect is incomparable to other structures .
[](() Use
PFADD key value Add the specified value to Hyperloglog in
PFCONUT key Return to a given Hyperloglog The base estimate of
PFMERGE destkey sourcekey The target Hyperloglog Merge to source Hyperloglog in
127.0.0.1:6379> PFADD NUMS1 1 2 3 4 # towards NUMS1 Insert 1-4
(integer) 1
127.0.0.1:6379> PFADD NUMS1 1 # Data already exists , Don't insert
(integer) 0
127.0.0.1:6379> PFCOUNT NUMS1 # View the current base quantity
(integer) 4
127.0.0.1:6379> PFADD NUMS2 3 4 5 6 # towards NUMS2 Insert 3-6
(integer) 1
127.0.0.1:6379> PFMERGE NUMS1 NUMS2 # take NUMS2 Merge into NUMS1 in
OK
127.0.0.1:6379> PFCOUNT NUMS1 # here NUMS1 Recorded in 1-6, Six elements
(integer) 6
[](()Bitmap( Bitmap )
Bitmap is actually a deformation of hash , He processes data through hash mapping , Bitmaps themselves do not store data , Instead, store tags . By a bit , namely 0/1 To mark two states of a data
Bitmaps are usually used for large amounts of data , Mark two states of a certain data under the scenario that the data is not repeated . We can use bitmap to record the current user's Login status 、 Or punch in 、 Check in and other functions .
[](() Use
GETBIT key offset value(0/1) Set up Bitmap The middle offset is offset The value of the position of
SETBIT key offset value return Bitmap The middle offset is offset The value of the position of
BITCOUNT key Calculate how many are in the bitmap 1
127.0.0.1:6379> SETBIT TEST 1 1 # In the bitmap 1,3,5 Bit is set to 1
(integer) 0
127.0.0.1:6379> SETBIT TEST 3 1
(integer) 0
127.0.0.1:6379> SETBIT TEST 5 1
(integer) 0
127.0.0.1:6379> GETBIT TEST 1 # View the bitmap 1,2,3 The value of a
(integer) 1
127.0.0.1:6379> GETBIT TEST 2
(integer) 0
127.0.0.1:6379> GETBIT TEST 3
边栏推荐
- 《低代码解决方案》——覆盖工单、维修和财务全流程的数字化售后服务低代码解决方案
- Cesium anti aliasing (lines, borders, etc.)
- Adding text labels to cesium polygons the problem of polygon center point offset is solved
- 4G-learn from great partners
- STM32的通用定时器与中断
- 王心凌、谭维维 - 山海(副歌加长版) 在线试听无损FLAC下载
- LeetCode - Easy - 197
- Cesium 抗锯齿(线,边框等)
- Cesium Click to obtain longitude and latitude (2D coordinates)
- Ten MySQL locks, one article will give you full analysis
猜你喜欢

Jenkins - Pipeline 概念及创建方式

架构高可靠性应用知识图谱 ----- 微服务架构图谱

Jenkins - access the Jenkins user-defined parameter variable, and handle the variable value containing spaces

Numpy----np. meshgrid()

CVPR22收录论文|基于标签关系树的层级残差多粒度分类网络

To understand what is synchronous, asynchronous, serial, parallel, concurrent, process, thread, and coroutine

Appium automation test foundation - Supplement: app package name and appactivity

How to use data-driven "customer lifecycle management" to improve lead conversion rate and customer satisfaction?

Embedded must learn, detailed explanation of hardware resource interface -- Based on arm am335x development board (Part 1)

SQL injection bypass (IV)
随机推荐
SQL 注入绕过(二)
How to use data-driven "customer lifecycle management" to improve lead conversion rate and customer satisfaction?
geojson 格式說明(格式詳解)
数据治理与数据标准
Take n multiple table names of a database as the values of a column in another table (the range can be a table in another database)
Mysql大合集,你要内容的这里全都有
205. isomorphic string
KVM相关
[Yocto RM]8 - OpenEmbedded Kickstart (.wks) Reference
Jenkins - Groovy Postbuild 插件丰富 Build History 信息
Jenkins - 邮件通知 Email Notification 插件
766. toplitz matrix
JS 数组随机取值(随机数组取值)
Cesium 点击绘制多边形(动态绘制多边形)
[elt.zip] openharmony paper Club - memory compression for data intensive applications
JS random number (random number decimal)
mysql面试百题集
Cesium 点击获取经纬度(二维坐标)
Keil “st-link usb communication error“解决方法
外盘期货哪里可以开户?哪个平台出入金比较安全?