English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Redis GEO est principalement utilisé pour stocker des informations géographiques et pour opérer sur ces informations, cette fonctionnalité est disponible dans Redis 32 Nouvelle version.
Les méthodes d'opérations GEO de Redis sont :
geoadd : ajoute les coordonnées géographiques.
geopos : obtient les coordonnées géographiques.
geodist : calcule la distance entre deux emplacements.
georadius : obtient une collection de positions géographiques dans une plage spécifiée en fonction des coordonnées de latitude et de longitude fournies par l'utilisateur.
georadiusbymember : obtient une collection de positions géographiques dans une plage spécifiée en fonction d'un emplacement spécifique stocké dans une collection de positions.
geohash : retourne la valeur geohash d'un ou plusieurs emplacements.
geoadd est utilisé pour stocker des emplacements géographiques spécifiés, et peut ajouter un ou plusieurs noms d'emplacements (longitude, latitude, membre) à une clé spécifiée.
Le format de syntaxe de geoadd est le suivant :
GEOADD clé longitude latitude membre [longitude latitude membre ...]
Dans les exemples suivants, la clé est Sicily, et Palermo et Catania sont les noms des emplacements :
redis> GEOADD Sicily 13361389 38115556 "Palermo" 15.087269 37502669 "Catania" (integer) 2 redis> GEODIST Sicily Palermo Catania "1662741516" redis> GEORADIUS Sicily 15 37 100 km 1) "Catania" redis> GEORADIUS Sicily 15 37 200 km 1) "Palermo" 2) "Catania" redis>
geopos est utilisé pour retourner toutes les positions (longitudes et latitudes) spécifiées (membres) dans une clé donnée, nil est retourné pour les membres inexistant.
Le format de syntaxe de geopos est le suivant :
GEOPOS clé membre [membre ...]
redis> GEOADD Sicily 13361389 38115556 "Palermo" 15.087269 37502669 "Catania" (integer) 2 redis> GEOPOS Sicily Palermo Catania NonExisting 1) 1) "1336138933897018433" 2) "3811555639549629859" 2) 1) "15.08726745843887329" 2) "3750266842333162032" 3) (nil) redis>
geodist est utilisé pour retourner la distance entre deux emplacements donnés.
The syntax format of geodist is as follows:
GEODIST key member1 member2 [m|km|ft|mi]
member1 member2 For two geographical locations.
The last distance unit parameter description:
m: Meter, default unit.
km: Kilometer.
mi: Mile.
ft: Foot.
Calculate the distance between Palermo and Catania:
redis> GEOADD Sicily 13361389 38115556 "Palermo" 15.087269 37502669 "Catania" (integer) 2 redis> GEODIST Sicily Palermo Catania "1662741516" redis> GEODIST Sicily Palermo Catania km "1662742" redis> GEODIST Sicily Palermo Catania mi "1033182" redis> GEODIST Sicily Foo Bar (nil) redis>
georadius returns all position elements contained in the key with the given longitude and latitude as the center, and the distance from the center does not exceed the given maximum distance.
Like the GEORADIUS command, georadiusbymember can also find elements within a specified range, but the center point of georadiusbymember is determined by the given position element, not by latitude and longitude to determine the center point.
The syntax format of georadius and georadiusbymember is as follows:
GEORADIUS key longitude latitude radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC] [STORE key] [STOREDIST key] GEORADIUSBYMEMBER key member radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC] [STORE key] [STOREDIST key]
Parameter description:
m: Meter, default unit.
km: Kilometer.
mi: Mile.
ft: Foot.
WITHDIST: Returns the distance between the position element and the center at the same time.
WITHCOORD: Also returns the longitude and latitude of the position element.
WITHHASH: With 52 The form of signed integer, returns the sorted set score of the position element after the original geohash encoding. This option is mainly used for underlying applications or debugging, and its actual effect is not significant.
COUNT 限定返回的记录数。
ASC: 查找结果根据距离从近到远排序。
DESC: 查找结果根据从远到近排序。
georadius 示例:
redis> GEOADD Sicily 13361389 38115556 "Palermo" 15.087269 37502669 "Catania" (integer) 2 redis> GEORADIUS Sicily 15 37 200 km WITHDIST 1) 1) "Palermo" 2) "190.4424" 2) 1) "Catania" 2) "564413" redis> GEORADIUS Sicily 15 37 200 km WITHCOORD 1) 1) "Palermo" 2) 1) "1336138933897018433" 2) "3811555639549629859" 2) 1) "Catania" 2) 1) "15.08726745843887329" 2) "3750266842333162032" redis> GEORADIUS Sicily 15 37 200 km WITHDIST WITHCOORD 1) 1) "Palermo" 2) "190.4424" 3) 1) "1336138933897018433" 2) "3811555639549629859" 2) 1) "Catania" 2) "564413" 3) 1) "15.08726745843887329" 2) "3750266842333162032" redis>
georadiusbymember 示例:
redis> GEOADD Sicily 13583333 37316667 "Agrigento" (integer) 1 redis> GEOADD Sicily 13361389 38115556 "Palermo" 15.087269 37502669 "Catania" (integer) 2 redis> GEORADIUSBYMEMBER Sicily Agrigento 100 km 1) "Agrigento" 2) "Palermo" redis>
Redis GEO 使用 geohash 来保存地理位置的坐标。
geohash 用于获取一个或多个位置元素的 geohash 值。
geohash 语法格式如下:
GEOHASH key member [member ...]
示例:
redis> GEOADD Sicily 13361389 38115556 "Palermo" 15.087269 37502669 "Catania" (integer) 2 redis> GEOHASH Sicily Palermo Catania 1) "sqc8b49rny0" 2) "sqdtr74hyu0" redis>