当前位置:网站首页>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 多边形(polygon)extrudedHeight 和 height 的区别
- Appium automation test foundation ADB common commands (I)
- [Yocto RM]8 - OpenEmbedded Kickstart (.wks) Reference
- Where can I open an account for foreign exchange futures? Which platform is safer for cash in and out?
- Description du format geojson (détails du format)
- ShardingSphere-proxy-5.0.0建立mysql读写分离的连接(六)
- Machine learning (x) reinforcement learning
- Deep parsing of kubernetes controller runtime
- [elt.zip] openharmony paper Club - memory compression for data intensive applications
- Dynamic Host Configuration Protocol
猜你喜欢

Figure out the difference between MIT, BSD and Apache open source protocols

Mysql大合集,你要内容的这里全都有

SQL injection bypass (IV)

Using redis bitmap to realize personnel online monitoring

Cesium 获取屏幕所在经纬度范围

Numpy----np.tile()函数解析

SQL 注入绕过(二)

Protocole de transfert de fichiers - - FTP

后勤事务繁杂低效?三步骤解决企业行政管理难题

Jenkins - groovy postbuild plug-in enriches build history information
随机推荐
205. isomorphic string
Cesium 点击绘制多边形(动态绘制多边形)
【ELT.ZIP】OpenHarmony啃论文俱乐部—数据密集型应用内存压缩
[Yocto RM]1 - System Requirements
我今天忘带手机了
SQL 注入绕过(二)
The interviewer asked: this point of JS
The system administrator has set the system policy to prohibit this installation. Solution
Locust performance test - parameterization, no repetition of concurrent cyclic data sampling
匿名挂载&具名挂载
Cesium Click to draw polygons (dynamically draw polygons)
Cesium anti aliasing (lines, borders, etc.)
What is a web crawler
Numpy----np.reshape()
王心凌、谭维维 - 山海(副歌加长版) 在线试听无损FLAC下载
Embedded must learn! Detailed explanation of hardware resource interface - based on arm am335x development board (Part 2)
Domain Name System
SQL injection Bypass (2)
geojson 格式说明(格式详解)
Cloud platform KVM migration local virtual machine records