当前位置:网站首页>Three special data types, day3 and redis (geographic location, cardinality statistics and bitmap scene usage)
Three special data types, day3 and redis (geographic location, cardinality statistics and bitmap scene usage)
2022-06-11 02:37:00 【Programmer flying bird】
hello , I'm a bird , If the article is not well written, please forgive me , I will continue to study and summarize , Then give me a little attention if you can , Praise support Xiaobian , thank you
Recommended reading :
Day1、 My sister gave me a fight QQ Flying car learned Redis Introduction to
Day2、 My roommate beat the king time and I learned Redis How to get started
Start server
redis-server.exe redis.windows.conf
Start client
redis-cli.exe -h 127.0.0.1 -p 6379

1、Gaospatial Location
Friends' positioning , The man near the , How to calculate the taxi distance ?
Redis GEO It is mainly used to store geographic information , And operate the stored information , This function is available in Redis 3.2 Version added
You can query the longitude and latitude test data of the position :http://www.jsons.cn/lngcode/

GEOADD Geospatial location to be specified ( longitude 、 latitude 、 name ) Add to specified key in
GEOADD key longitude latitude member [longitude latitude member …]
longitude longitude
latitude latitude
member name
Query Shenzhen , Beijing , The longitude and latitude of Shanghai
# The rules : Two levels cannot be added directly , We usually download city data , Directly through Java The program is imported once !
127.0.0.1:6379>GEOADD china:city 114.08 22.54 shenzhen
(integer) 1
127.0.0.1:6379> GEOADD china:city 116.40 39.90 beijing
(integer) 1
127.0.0.1:6379> GEOADD china:city 121.47 31.23 shanghai
(integer) 1
127.0.0.1:6379> GEOADD china:city 120.15 30.28 hangzhou 113.28 23.12 guangzhou
(integer) 2
GEOPOS from key Returns the location of all the positioning elements ( Longitude and latitude )
- GEOPOS key member [member …]
Get the current location !
127.0.0.1:6379> GEOPOS china:city beijing
1) 1) "116.39999896287918091"
2) "39.90000009167092543"
127.0.0.1:6379> GEOPOS china:city shanghai
1) 1) "121.47000163793563843"
2) "31.22999903975783553"
GEODIST Returns the distance between two positions
GEODIST key member1 member2 [unit]
- m Expressed in meters .
- km Expressed in kilometers .
- mi In miles .
- ft In feet
The distance between Beijing and Guangzhou !
127.0.0.1:6379> GEODIST china:city beijing guangzhou
"1889326.0478"
GEORADIUS With the given latitude and longitude as the center , Find the elements in a certain radius
GEORADIUS key longitude latitude radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC
The man near the ?( Get the addresses of all people nearby , location ), Query by radius , Beijing longitude and latitude 116,39 Centered , radius 1000 km , seek 1000 Get Beijing... Within , Shanghai location
127.0.0.1:6379> GEORADIUS china:city 116 39 1000 km
1) "beijing"
2) "shanghai"
127.0.0.1:6379> GEORADIUS china:city 116 39 1000 km WITHDIST# Displays the location of the distance to the center
1) 1) "beijing"
2) "105.8343"
2) 1) "shanghai"
2) "996.7785"
127.0.0.1:6379> GEORADIUS china:city 116 39 1000 km withcoord # Show other people's location information
1) 1) "beijing"
2) 1) "116.39999896287918091"
2) "39.90000009167092543"
2) 1) "shanghai"
2) 1) "121.47000163793563843"
2) "31.22999903975783553"
GEORADIUSBYMEMBER Find the elements in the specified range , The center point is determined by a given location element
GEORADIUSBYMEMBER key member radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC] [STORE key] [
With Shanghai as the center , The radius is 500 Kilometers indicate the elements in the range
127.0.0.1:6379> GEORADIUSBYMEMBER china:city shanghai 500 km
1) "hangzhou"
2) "shanghai"
GEOHASH Returns the... Of one or more positional elements Geohash Express
The command will return 11 A character Geohash character string
Convert two-dimensional latitude and longitude into one-dimensional string , If the two strings are closer , Then the closer the distance
127.0.0.1:6379> geohash china:city shanghai hangzhou
1) "wtw3sj5zbj0"
2) "wtmkq069cc0"
geo The low-level implementation principle is Zset, We can use Zset Command to use geo
127.0.0.1:6379> ZRANGE china:city 0 -1 # View all elements in the map
1) "shenzhen"
2) "guangzhou"
3) "hangzhou"
4) "shanghai"
5) "beijing"
127.0.0.1:6379> zrem china:city beijing # Removes the specified element
(integer) 1
127.0.0.1:6379> zrange china:city 0 -1
1) "shenzhen"
2) "guangzhou"
3) "hangzhou"
4) "shanghai"
Redis GEO Operation summary methods include :
- geoadd: Add geographic coordinates .
- geopos: Get the coordinates of the geographic location .
- geodist: Calculate the distance between two positions .
- georadius: According to the longitude and latitude coordinates given by the user to obtain the geographic location set within the specified range .
- georadiusbymember: According to a location stored in the location set, get the geographic location set within the specified range .
- geohash: Returns the... Of one or more location objects geohash value .
2、HyperLogLog Base Statistics
Redis HyperLogLog It's an algorithm for cardinality statistics
advantage : When the number or volume of input elements is very, very large , The space needed to calculate the cardinality is always fixed Of 、 And it's very small .2^64 Different elements of Technology , It only costs 12kb Memory
What's up ?
Like data sets {1, 3, 5, 7, 5, 7, 8}, So the cardinality set of this dataset is {1, 3, 5 ,7, 8}, base ( Don't repeat elements ) by 5. Cardinality estimation is within the range of acceptable error , Fast base calculation .
127.0.0.1:6379> PFADD feiniao a b c d e # Create the first set of elements feiniao
(integer) 1
127.0.0.1:6379> PFCOUNT feiniao # Count the number of bases
(integer) 5
127.0.0.1:6379> PFADD feiniao1 c d f g h # Create the first set of elements feiniao
(integer) 1
127.0.0.1:6379> PFCOUNT feiniao1 ## Count the number of bases
(integer) 5
127.0.0.1:6379> PFMERGE feiniao2 feiniao feiniao1 # Combine the two groups , Combine
OK
127.0.0.1:6379> PFCOUNT feiniao2 # View base quantity
(integer) 8
3、Bitmaps Bitmap scene
Bit storage
Statistics user information , use 01 Express , For example, punch in 1, Do not punch in 0, Follow bloggers for 1, Do not pay attention to 0, You can use bitmaps!
Use bitmap To record Clock in from Monday to Sunday
Monday :0 Tuesday :1 Wednesday :0…
127.0.0.1:6379> setbit sign 1 0
(integer) 0
127.0.0.1:6379> setbit sign 2 1
(integer) 0
127.0.0.1:6379> setbit sign 3 0
(integer) 0
127.0.0.1:6379> setbit sign 4 1
(integer) 0
127.0.0.1:6379> setbit sign 5 0
(integer) 0
Check if you have clocked in one day
127.0.0.1:6379> getbit sign 3
(integer) 0
127.0.0.1:6379> getbit sign 2
(integer) 1
Count the number of clock in days
127.0.0.1:6379> bitcount sign
(integer) 2
The literature : Official Chinese documents 、 Madness up Lord 、 Novice tutorial 
A gift of rose , Fragrance in hand
边栏推荐
- Write my Ini configuration file error
- 多级介孔有机金属骨架材料ZIF-8负载乳酸氧化酶(LOD)/四氧化三铁(Fe304)/阿霉素DOX/胰岛素/cas9蛋白/甲硝唑/大黄素甲醚
- Technology sharing | quick intercom, global intercom
- Jetpack Compose Box控件
- 421. maximum XOR value of two numbers in the array
- Unity HTC and Pico are the same
- 3P5 Industrial Engineering Lecture 1-2: Method of Study
- SQL | 计算总和
- About stepping on the pit diary and the association of knowledge points
- Closing method of SQL injection
猜你喜欢

【AI周报】AI与冷冻电镜揭示「原子级」NPC结构;清华、商汤提出「SIM」方法兼顾语义对齐与空间分辨能力

Metal organic framework MOF Al (Diba), MOF Zr (Diba), MOF Fe (Diba) loaded with curcumin / carboxybenzylpenicillin /mtx methotrexate / paclitaxel ptx/ DOX / cisplatin cddp/cpt camptothecin and other d

Flat data to tree and tree data flattening

The most complete format description of clang format

Unity serial port communication

Colab reported an error: importerror: cannot import name '_ check_ savefig_ extra_ args‘ from ‘matplotlib. backend_ bases‘

ADVANCE. AI CEO Shoudong will share the compliance of cross-border e-commerce using AI technology at the 2022 emerging market brands online Summit

金属有机骨架材料Fe-MIL-53,Mg-MOF-74,Ti-KUMOF-1,Fe-MIL-100,Fe-MIL-101)负载异氟醚/甲氨蝶呤/阿霉素(DOX)/紫杉醇/布洛芬/喜树碱

ShaderGraphs

Sd3.0 notes
随机推荐
SQL | 外连接
Databinding escaping with presentation symbols
Project - redis message queue + worker thread fetches user operation logs and stores them (2)
Do tween record
Executeineditmode property details
年金保險理財產品可以複利嗎?利率是多少?
【189. 轮转数组】
CPT 102_LEC 18
C language principle explanation and code implementation of scalable / reduced thread pool
To view the data in redis, in addition to the command line and client, you have a third option
CPT 102_LEC 13-14
完成千万元A轮融资,小象生活能否成为折扣界的“永辉”?
421. maximum XOR value of two numbers in the array
CPT 102_LEC 20
app 测试 常用 adb 命令集合
Cyclodextrin metal organic framework( β- Cd-mof) loaded with dimercaptosuccinic acid / emodin / quercetin / sucralose / diflunisal / omeprazole (OME)
889. construct binary tree according to preorder and postorder traversal
Explanation of spark common parameters
[Fibonacci series]
Optimized dispatching (thermal power, wind energy and energy storage) [matlab code implementation]