当前位置:网站首页>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
边栏推荐
猜你喜欢

Dynamic Host Configuration Protocol

树莓派实现温控风扇智能降温

Cesium 点击绘制多边形(动态绘制多边形)

Raspberry pie realizes intelligent cooling by temperature control fan

王心凌、谭维维 - 山海(副歌加长版) 在线试听无损FLAC下载

Jenkins - Pipeline 概念及创建方式

如何以数据驱动「客户全生命周期管理」,提高线索转化率及客户满意度?

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

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)

Cesium 多边形增加文字标签(polygon 加 label)多边形中心点偏移问题解决
随机推荐
ShardingSphere-proxy-5.0.0建立mysql读写分离的连接(六)
Four classic training modes in comparative learning
简单文件传输协议TFTP
SQL injection bypass (2)
Embedded must learn, detailed explanation of hardware resource interface -- Based on arm am335x development board (Part 1)
外盘期货哪里可以开户?哪个平台出入金比较安全?
The interviewer asked: this point of JS
Cesium 点击绘制多边形(动态绘制多边形)
Jenkins - access the Jenkins user-defined parameter variable, and handle the variable value containing spaces
文件傳輸協議--FTP
SQL 注入繞過(二)
There appears to be a failure with your network connection Retrying.
Cesium obtains the latitude and longitude range of the screen
Cloud platform KVM migration local virtual machine records
Protocole de transfert de fichiers - - FTP
Class initialization and callback usage
Scoped attribute and lang attribute in style
Wangxinling, tanweiwei Shanhai (extended version of Chorus) online audition lossless FLAC Download
[Yocto RM]3 - Yocto Project Releases and the Stable Release Process
共阳极数码管真值表