当前位置:网站首页>10_ Redis_ geospatial_ command
10_ Redis_ geospatial_ command
2022-07-02 15:19:00 【Listen to the rain】
geospatial( Location )
geospatial The related documents
purpose :
Friends' positioning , The man near the , Taxi distance calculation ?
Redis Of Geo stay Redis3.2 The version was launched ! This function can calculate the location information , The distance between the two places , People in a few miles around !
Relevant command ( Only 6 An order )
- GEOADD
- GEODIST
- GEOHASH
- GEOPOS
- GEORADIUS
- GEORADIUSBYMEMBER
geoadd
geoadd // Add location
The rules : Two levels cannot be added directly , We usually download city data , Directly read the configuration file and import it at one time !
127.0.0.1:6379> geoadd china:city 39.90 116.40 beijing
(error) ERR invalid longitude,latitude pair 39.900000,116.400000 // The reason for the error is that the longitude and latitude are written backwards
Parameters key - - - value ( longitude 、 latitude 、 name )
Effective longitude from -180 C to 180 degree .
Effective latitude from -85.05112878 C to 85.05112878 degree
127.0.0.1:6379> geoadd china:city 116.40 39.40 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 106.50 29.53 chongqing 114.05 22.52 shengzhen
(integer) 2
127.0.0.1:6379> geoadd china:city 120.16 30.24 hangzhou 108.96 34.26 xian
(integer) 2
GEOPOS
geopos
Get the current location : It must be a coordinate value !
geopos // Gets the longitude and latitude of the specified city
127.0.0.1:6379> geopos china:city beijing
1 ) 1) “116.39999896287918091”
2) “39.40000099577971326”
127.0.0.1:6379> geopos china:city beijing chongqing // Get the longitude and latitude of Beijing and Chongqing
1 ) 1) “116.39999896287918091”
2 ) “39.40000099577971326”
2 ) 1 ) “106.49999767541885376”
2 ) “29.52999957900659211”
geodist
geodist
Returns the distance between two given positions .
Company :
- m Expressed in meters .
- km Expressed in kilometers .
- mi In miles .
- ft In feet
127.0.0.1:6379> GEODIST china:city beijing shanghai
“1018116.5434”
127.0.0.1:6379> GEODIST china:city beijing shanghai km // The straight distance from Beijing to Shanghai : Company km
“1018.1165”
GEORADIUS
georadius
Centered on a given latitude and longitude , Return key contains position elements , All position elements whose distance from the center does not exceed the given maximum distance
The man near the : First, get the addresses of all people nearby , location !
127.0.0.1:6379> GEORADIUS china:city 110 30 1000 km // Query longitude is 110, Latitude is 30, radius 1000km Cities within range
1 ) “chongqing”
2 ) “xian”
3 ) “shengzhen”
4 ) “hangzhou”
GEORADIUSBYMEMBER
GEORADIUSBYMEMBER
Find other elements around the specified element !
This command and GEORADIUS command , Can find the elements in the specified range , however The center point of is determined by a given location element , Not like it GEORADIUS like that , Use the entered longitude and latitude to determine the center point GEORADIUSBYMEMBER
The location of the specified member is used as the center of the query .
127.0.0.1:6379> GEORADIUSBYMEMBER china:city beijing 1000 km // Find a radius centered on Beijing 1000km Cities within range
1 ) “beijing”
2 ) “xian”
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 , So the closer we get !
127.0.0.1:6379> GEOHASH china:city beijing
1 ) “wx4b0sxcss0”
127.0.0.1:6379> GEOHASH china:city beijing chongqing // Returns the longitude and latitude hash values of Beijing and Chongqing
1 ) “wx4b0sxcss0”
2 ) “wm5xzrybty0”
GEO The underlying implementation principle is actually Zset ! We can use Zset Command to operate geo !
127.0.0.1:6379> zrange china:city 0 -1 // Look at all the elements in the map
1 ) “chongqing”
2 ) “xian”
3 ) “shengzhen”
4 ) “hangzhou”
5 ) “shanghai”
6 ) “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 ) “chongqing”
2 ) “xian”
3 ) “shengzhen”
4 ) “hangzhou”
5 ) “shanghai”
边栏推荐
- Tidb environment and system configuration check
- MFC 控制台打印,弹出对话框
- 19_Redis_宕机后手动配置主机
- CDN 在游戏领域的应用
- Implementation of n queen in C language
- Tidb data migration scenario overview
- 面对“缺芯”挑战,飞凌如何为客户产能提供稳定强大的保障?
- MFC CString to char*
- Recommended configuration of tidb software and hardware environment
- [C language] explain the initial and advanced levels of the pointer and points for attention (1)
猜你喜欢
随机推荐
Base64 coding can be understood this way
btrace-(字节码)动态跟踪工具
基于RZ/G2L | OK-G2LD-C开发板存储读写速度与网络实测
Btrace- (bytecode) dynamic tracking tool
19_Redis_宕机后手动配置主机
List集合&UML图
21_Redis_浅析Redis缓存穿透和雪崩
05_队列
Application of CDN in game field
05_ queue
Points clés de l'examen de principe de compilation pour l'année scolaire 2021 - 2022 [Université chinoise d'outre - mer]
vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)
TiDB跨数据中心部署拓扑
原则、语言、编译、解释
【C语音】详解指针进阶和注意点(2)
.NET Core 日志系统
TiDB 集群最小部署的拓扑架构
实用调试技巧
Tidb cross data center deployment topology
MFC CString to char*









