English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Redis GEO wird hauptsächlich zur Speicherung von geografischen Positionsinformationen und zum Umgang mit diesen Informationen verwendet. Diese Funktion ist in Redis 32 Version hinzugefügt.
Die Redis GEO-Operationen sind:
geoadd: Fügt die Koordinaten der geografischen Position hinzu.
geopos: Gibt die Koordinaten der geografischen Position zurück.
geodist: Berechnet die Distanz zwischen zwei Positionen.
georadius: Gibt eine Sammlung von geografischen Positionen im angegebenen Bereich zurück, basierend auf den von Benutzer angegebenen Längen- und Breitengradkoordinaten.
georadiusbymember: Gibt eine Sammlung von geografischen Positionen im angegebenen Bereich zurück, basierend auf einem bestimmten Ort in der Positionsliste.
geohash: Gibt den geohash-Wert eines oder mehrerer Positionsobjekte zurück.
GEOADD wird verwendet, um spezifische geografische Positionen zu speichern und kann ein oder mehrere Längen (longitude), Breitengrade (latitude) und Positionsbezeichnungen (member) zu einem bestimmten Schlüssel hinzufügen.
Die Syntax des GEOADD ist wie folgt:
GEOADD key longitude latitude member [longitude latitude member ...]
Im folgenden Beispiel ist der Schlüssel Sicily und Palermo und Catania sind Positionsbezeichnungen:
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 wird verwendet, um alle angegebenen Positionen (Längen- und Breitengrade) eines bestimmten Schlüssels zurückzugeben, und gibt für nicht vorhandene Positionen nil zurück.
Die Syntax des GEOPOS ist wie folgt:
GEOPOS key member [member ...]
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 wird verwendet, um die Distanz zwischen zwei gegebenen Positionen zurückzugeben.
The syntax format of geodist is as follows:
GEODIST key member1 member2 [m|km|ft|mi]
member1 member2 For two geographical locations.
Last distance unit parameter description:
m: Meters, the default unit.
km: Kilometers.
mi: Miles.
ft: Feet.
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, which are not more than the given maximum distance from the center point given by the given latitude and longitude.
Both georadiusbymember and GEORADIUS commands can 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: Meters, the default unit.
km: Kilometers.
mi: Miles.
ft: Feet.
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: By 52 The form of a signed integer, returns the ordered set score of the position element after the original geohash encoding. This option is mainly used for low-level 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>