当前位置:网站首页>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 抗锯齿(线,边框等)
- Description du format geojson (détails du format)
- Dynamic Host Configuration Protocol
- Wangxinling, tanweiwei Shanhai (extended version of Chorus) online audition lossless FLAC Download
- Solve the problem that the page cannot scroll when ionic4 uses the hammerjs gesture press event
- SQL injection bypass (3)
- 1382. balancing binary search tree - General method
- OS module and os Learning of path module
- Dynamic Host Configuration Protocol
- Geojson format description (detailed format)
猜你喜欢
MySQL优化小技巧
SQL 注入繞過(二)
Embedded must learn, detailed explanation of hardware resource interface -- Based on arm am335x development board (Part 1)
SQL 注入绕过(五)
Anonymous Mount & named mount
SQL 注入绕过(二)
To understand what is synchronous, asynchronous, serial, parallel, concurrent, process, thread, and coroutine
Use code binding DataGridView control to display tables in program interface
架构高可靠性应用知识图谱 ----- 架构演进之路
SQL injection bypass (IV)
随机推荐
Leetcode topic [array] -228- summary interval
利用redis bitmap实现人员在线情况监控
mysql面试百题集
Cesium 抗锯齿(线,边框等)
What are the risks of opening a compass stock account? Is it safe to open a compass account
后勤事务繁杂低效?三步骤解决企业行政管理难题
There appears to be a failure with your network connection Retrying.
[Yocto RM]9 - QA Error and Warning Messages
SQL injection bypass (2)
JS 数组随机取值(随机数组取值)
Solve the problem that the page cannot scroll when ionic4 uses the hammerjs gesture press event
Jenkins - Pipeline 概念及创建方式
[Yongyi XY chair] trial experience
Mysql大合集,你要内容的这里全都有
geojson 格式说明(格式详解)
SQL 注入绕过(五)
云平台kvm迁移本地虚拟机记录
ShardingSphere-proxy-5.0.0建立mysql读写分离的连接(六)
General timer and interrupt of stm32
stm32f1中断介绍