2 Ağustos 2021 Pazartesi

Redis - Geospatial Indexes

Giriş
Açıklaması şöyle. Sorted Set Veri Yapısı yazısına bakabilirsiniz.
- Redis provides commands like GEOADD, GEORADIUS, GEORADIUSBYMEMBER, GEOSEARCH, and GEOSEARCHSTORE for geospatial indexing and searching.

- The spatial entities are stored in Sorted Sets using the coordinates to form 52-bit integers using the Geohash technique.
Açıklaması şöyle.
- Redis uses Haversine formula to calculate the distances as the model assumes that the Earth is a sphere. This can result in an error of up to 0.5%.

Valid longitudes range from -180 to 180 degrees, while valid latitudes range from -85.05112878 to 85.05112878 degrees.

GEOADD Komutu
Bir yeri eklemek için kullanılır
Örnek
Şöyle yaparız
> GEOADD places -122.419 37.774 “San Francisco”
> GEOADD places -122.143 37.441 “Palo Alto”
> GEOADD places -122.083 37.386 “Mountain View”
> GEOADD places -121.886 37.338 “San Jose”
GEORADIUS Komutu - Arama İçindir
Açıklaması şöyle
To perform a spatial search of entities GEORADIUS or GEORADIUSBYMEMBER can be used in Redis 3.2.0 (and above) and GEOSEARCH or GEOSEARCHSTORE can be used in Redis 6.2 (and above).

The time complexity for these commands is approximately O(N+log(M)) where N is the number of elements inside the bounding box of the circular area delimited by center and radius, and M is the number of items inside the index.
Örnek
Şöyle yaparız
> GEORADIUS places -122.228 37.484 50 mi COUNT 1 ASC WITHCOORD WITHDIST
1) 1) "Palo Alto" 2) "5.5294" 3) 1) "-122.14300006628036499" 2) "37.4410011922460555"
GEORADIUSBYMEMBER Komutu - Arama İçindir
Örnek
Şöyle yaparız
> GEORADIUSBYMEMBER places "Mountain View" 20 mi WITHDIST
1) 1) "Mountain View"
   2) "0.0000"
2) 1) "Palo Alto"
   2) "5.0297"
3) 1) "San Jose"
   2) "11.3186"
Örnek
Şöyle yaparız
> GEORADIUSBYMEMBER places "Mountain View" 50 mi WITHDIST
1) 1) "San Francisco" 2) "32.5234" 2) 1) "Mountain View" 2) "0.0000" 3) 1) "Palo Alto" 2) "5.0297" 4) 1) "San Jose" 2) "11.3186"
ZCARD Komutu
Açıklaması şöyle.
Since these entities are stored in a sorted set, the ZCARD command would return the total count of spatial entities.
Örnek
Şöyle yaparız
> ZCARD places
(integer) 4
ZRANGE Komutu 
Tüm elemanları gösterir
Örnek
Şöyle yaparız.
> ZRANGE places 0 -1
1) "San Francisco"
2) "Mountain View"
3) "Palo Alto"
4) "San Jose"

Hiç yorum yok:

Yorum Gönder