Not içeriği yükleniyor...
// Markdown dosyası okunuyor
// İçerik işleniyor
// Syntax highlighting hazırlanıyor
// Markdown dosyası okunuyor
// İçerik işleniyor
// Syntax highlighting hazırlanıyor
Redis Geospatial ile location-based services, proximity search ve geographic data storage. GEOADD, GEORADIUS komutları ile spatial queries.
Özellik | Açıklama | Örnek |
---|---|---|
Geospatial indexing | Longitude/latitude coordinates'leri efficient storage | GEOADD locations 13.361389 38.115556 "Palermo" |
Proximity search | Belirli point'ten belirli mesafedeki locations | GEORADIUS Sicily 15 37 200 km |
Distance calculation | İki location arasındaki gerçek mesafe hesaplama | GEODIST Sicily Palermo Catania km |
Geohash support | Base32 geohash encoding/decoding | GEOHASH Sicily Palermo |
Spherical earth model | Gerçek dünya geometrisi ile accurate calculations | Curved earth surface calculations |
Range queries | Coordinate range'ine göre filtering | GEORADIUSBYMEMBER Sicily Palermo 100 km |
Sorted set compatibility | Geo data sorted set olarak da manipüle edilebilir | ZRANGE , ZREM commands çalışır |
Memory efficient | Coordinates'ler compressed geohash olarak saklanır | Space-efficient coordinate storage |
Kullanım Alanı | Açıklama | Redis Komutu Örneği |
---|---|---|
Nearby search | Yakındaki restoran, mağaza, servis bulma | GEORADIUS restaurants 13.36 38.11 5 km |
Delivery tracking | Kurye, araç konumları ve rota optimizasyonu | GEOADD couriers 13.361 38.115 "courier1" |
Ride sharing | Driver-passenger matching ve distance calc | GEORADIUSBYMEMBER drivers passenger 2 km |
Real estate search | Belirli area'daki property'leri bulma | GEORADIUS properties 13.36 38.11 10 km |
Fleet management | Araç filosu tracking ve monitoring | GEOADD fleet 13.361 38.115 "truck1" |
Social networking | Yakındaki arkadaşlar, check-in locations | GEORADIUS users 13.36 38.11 1 km |
IoT sensor networks | Geographical sensor deployment ve monitoring | GEOADD sensors 13.361 38.115 "temp_01" |
Emergency services | En yakın hastane, polis, itfaiye bulma | GEORADIUS hospitals 13.36 38.11 50 km |
Gaming applications | Location-based gaming, AR/VR experiences | GEORADIUS players 13.36 38.11 100 m |
Retail analytics | Customer location analysis ve store coverage | GEORADIUS customers 13.36 38.11 25 km |
Geo
, aslında sorted set data structure'ının üzerine kurulan specialized bir layer'dır. Longitude ve latitude coordinate'leri geohash algoritması ile encode edilerek sorted set'in score'u olarak saklanır. Bu yaklaşım sayesinde hem geospatial queries hem de traditional sorted set operations aynı data üzerinde çalışabilir.Komut | Açıklama | Örnek |
---|---|---|
GEOADD | Longitude/latitude ile location ekler | GEOADD Sicily 13.361 38.115 "Palermo" |
GEOPOS | Location'ın coordinates'lerini getirir | GEOPOS Sicily Palermo |
GEODIST | İki location arasındaki mesafeyi hesaplar | GEODIST Sicily Palermo Catania |
GEORADIUS | Belirli point çevresindeki locations'ı bulur | GEORADIUS Sicily 15 37 200 km |
GEORADIUSBYMEMBER | Member çevresindeki locations'ı bulur | GEORADIUSBYMEMBER Sicily Palermo 100 km |
GEOHASH | Location'ların geohash'lerini döndürür | GEOHASH Sicily Palermo Catania |
GEOSEARCH | Advanced geo search operations | GEOSEARCH Sicily FROMLONLAT 15 37 BYRADIUS 200 km |
GEOSEARCHSTORE | Search results'ı yeni key'e saklar | GEOSEARCHSTORE result Sicily FROMLONLAT 15 37 |
text127.0.0.1:6379> GEOADD Sicily 13.361389 38.115556 "Palermo" // Sicily geo set'ine Palermo şehrini ekliyoruz. (integer) 1 // 1 yeni location eklendi. 127.0.0.1:6379> GEOADD Sicily 15.087269 37.502669 "Catania" // Catania şehrini ekliyoruz. (integer) 1 // 1 yeni location eklendi. 127.0.0.1:6379> GEOADD Sicily 13.583333 37.316667 "Agrigento" // Agrigento şehrini ekliyoruz. (integer) 1 // 1 yeni location eklendi. 127.0.0.1:6379> GEOADD restaurants 29.0104 41.0082 "Restaurant_A" 29.0234 41.0156 "Restaurant_B" 29.0067 40.9923 "Restaurant_C" // Birden fazla restaurant ekliyoruz. (integer) 3 // 3 yeni location eklendi. 127.0.0.1:6379> GEOADD Sicily 13.361389 38.115556 "Palermo_Updated" // Aynı coordinate'e farklı name ile location ekliyoruz. (integer) 1 // Yeni member eklendi (farklı name).
text127.0.0.1:6379> GEOADD locations 180.1 90.1 "invalid" // Geçersiz coordinates. (error) ERR invalid longitude,latitude pair 180.100000,90.100000 127.0.0.1:6379>
text127.0.0.1:6379> GEOADD Sicily 14.0 39.0 "Palermo" // Palermo'nun coordinate'leri güncelleniyor. (integer) 0 // Mevcut member güncellendi. 127.0.0.1:6379>
GEOADD
komutu ile yeni geo set oluşturulur.text127.0.0.1:6379> GEOPOS Sicily Palermo // Palermo'nun coordinates'lerini getir. 1) 1) "13.36138933897018433" // Longitude. 2) "38.11555639549629859" // Latitude. 127.0.0.1:6379> GEOPOS Sicily Catania Agrigento // Birden fazla location'ın coordinates'leri. 1) 1) "15.08726984262466431" // Catania longitude. 2) "37.50266842333162032" // Catania latitude. 2) 1) "13.58333557844161987" // Agrigento longitude. 2) "37.31666804893235718" // Agrigento latitude. 127.0.0.1:6379> GEOPOS Sicily NonExistent // Var olmayan location sorgulanıyor. 1) (nil) // Location bulunamadı. 127.0.0.1:6379> GEOPOS restaurants Restaurant_A Restaurant_D // Var olan ve olmayan karışık. 1) 1) "29.01039898395538330" // Restaurant_A coordinates. 2) "41.00820008959414748" 2) (nil) // Restaurant_D bulunamadı.
[longitude, latitude]
array döner.(nil)
döner.text127.0.0.1:6379> GEODIST Sicily Palermo Catania // Palermo-Catania arası mesafe (meter). "166274.1516" // 166.27 km (meter cinsinden). 127.0.0.1:6379> GEODIST Sicily Palermo Catania km // Kilometer cinsinden mesafe. "166.2742" // 166.27 km. 127.0.0.1:6379> GEODIST Sicily Palermo Catania mi // Mil cinsinden mesafe. "103.3182" // 103.32 mil. 127.0.0.1:6379> GEODIST Sicily Palermo Agrigento ft // Feet cinsinden mesafe. "217296.6166" // 217,296 feet. 127.0.0.1:6379> GEODIST restaurants Restaurant_A Restaurant_B km // Restaurant'lar arası mesafe. "1.7033" // 1.70 km. 127.0.0.1:6379> GEODIST Sicily Palermo NonExistent // Var olmayan location ile mesafe. (nil) // Hesaplanamadı.
m
(meter), km
(kilometer), mi
(mile), ft
(feet) - default: meter.(nil)
döner.text127.0.0.1:6379> GEORADIUS Sicily 15 37 200 km // Sicily'de 15,37 coordinate'i çevresinde 200km'deki şehirler. 1) "Agrigento" // 200km içindeki şehir. 2) "Catania" // 200km içindeki şehir. 3) "Palermo" // 200km içindeki şehir. 127.0.0.1:6379> GEORADIUS Sicily 15 37 100 km WITHDIST // Distance bilgisi ile birlikte. 1) 1) "Catania" // Şehir adı. 2) "56.4413" // Mesafe (km). 2) 1) "Agrigento" 2) "90.9778" 127.0.0.1:6379> GEORADIUS Sicily 15 37 200 km WITHCOORD WITHDIST ASC // Coordinates ve distance ile, ascending order. 1) 1) "Catania" 2) "56.4413" // Distance. 3) 1) "15.08726984262466431" // Longitude. 2) "37.50266842333162032" // Latitude. 2) 1) "Agrigento" 2) "90.9778" 3) 1) "13.58333557844161987" 2) "37.31666804893235718" 3) 1) "Palermo" 2) "190.4424" 3) 1) "13.36138933897018433" 2) "38.11555639549629859" 127.0.0.1:6379> GEORADIUS restaurants 29.01 41.01 2 km COUNT 2 // En yakın 2 restaurant'ı bul. 1) "Restaurant_A" 2) "Restaurant_B" 127.0.0.1:6379> GEORADIUS Sicily 15 37 100 km WITHCOORD WITHDIST WITHHASH DESC // Tüm ek bilgiler ile, descending order. 1) 1) "Agrigento" 2) "90.9778" // Distance. 3) (integer) 3479447370796909 // Geohash. 4) 1) "13.58333557844161987" // Coordinates. 2) "37.31666804893235718" 2) 1) "Catania" 2) "56.4413" 3) (integer) 3479447158516539 4) 1) "15.08726984262466431" 2) "37.50266842333162032"
WITHDIST
: Distance bilgisi eklerWITHCOORD
: Coordinate bilgisi eklerWITHHASH
: Geohash bilgisi eklerASC
(yakından uzağa), DESC
(uzaktan yakına)COUNT N
ile result limit belirleyebilirsiniz.text127.0.0.1:6379> 127.0.0.1:6379> GEORADIUS Sicily 15 37 200 km STORE nearby_cities // Sonuçları başka key'e kaydet. 127.0.0.1:6379>
text127.0.0.1:6379> GEORADIUSBYMEMBER Sicily Palermo 100 km // Palermo çevresinde 100km'deki şehirler. 1) "Palermo" // Kendisi de dahil. 2) "Agrigento" // 100km içindeki şehir. 127.0.0.1:6379> GEORADIUSBYMEMBER Sicily Catania 200 km WITHDIST ASC // Catania çevresinde 200km, distance ile. 1) 1) "Catania" 2) "0.0000" // Kendisine mesafe 0. 2) 1) "Agrigento" 2) "147.4133" // 147.41 km uzaklıkta. 3) 1) "Palermo" 2) "166.2742" // 166.27 km uzaklıkta. 127.0.0.1:6379> GEORADIUSBYMEMBER restaurants Restaurant_A 5 km COUNT 3 WITHDIST // Restaurant_A çevresinde 5km'de en yakın 3 restaurant. 1) 1) "Restaurant_A" 2) "0.0000" 2) 1) "Restaurant_B" 2) "1.7033" 3) 1) "Restaurant_C" 2) "1.8456" 127.0.0.1:6379> GEORADIUSBYMEMBER Sicily NonExistent 100 km // Var olmayan member çevresi. (error) ERR could not decode requested zset member // Hata: member bulunamadı.
WITHDIST
, WITHCOORD
, WITHHASH
, ASC
, DESC
, COUNT
aynı şekilde çalışır.text127.0.0.1:6379> GEOHASH Sicily Palermo // Palermo'nun geohash'i. 1) "sqc8b49rny0" // Base32 geohash string. 127.0.0.1:6379> GEOHASH Sicily Palermo Catania Agrigento // Birden fazla location'ın geohash'leri. 1) "sqc8b49rny0" // Palermo geohash. 2) "sqdtr74hyu0" // Catania geohash. 3) "sqc8b36ue20" // Agrigento geohash. 127.0.0.1:6379> GEOHASH restaurants Restaurant_A Restaurant_B // Restaurant geohash'leri. 1) "sxj7dy2ysy0" // Restaurant_A geohash. 2) "sxj7f5brkr0" // Restaurant_B geohash. 127.0.0.1:6379> GEOHASH Sicily NonExistent // Var olmayan location. 1) (nil) // Geohash bulunamadı.
0-9
ve a-z
(i,l,o,u hariç).# Palermo: sqc8b49rny0
# Agrigento: sqc8b36ue20
# Ortak prefix: sqc8b (aynı genel bölgede)
markdown127.0.0.1:6379> GEOADD drivers 29.0104 41.0082 "driver_001" 29.0234 41.0156 "driver_002" 29.0067 40.9923 "driver_003" // Şoför lokasyonları. (integer) 3 127.0.0.1:6379> GEOADD passengers 29.0180 41.0112 "passenger_123" // Yolcu lokasyonu. (integer) 1 127.0.0.1:6379> GEORADIUSBYMEMBER drivers driver_001 5 km WITHDIST // driver_001 çevresindeki diğer şoförler. 1) 1) "driver_001" 2) "0.0000" 2) 1) "driver_002" 2) "1.7033" // 1.7 km uzaklıkta. 3) 1) "driver_003" 2) "2.1456" // 2.1 km uzaklıkta. 127.0.0.1:6379> GEORADIUS drivers 29.0180 41.0112 3 km WITHDIST ASC COUNT 2 // Yolcuya en yakın 2 şoför. 1) 1) "driver_001" 2) "0.8547" // En yakın şoför: 0.85 km. 2) 1) "driver_002" 2) "1.2334" // İkinci en yakın: 1.23 km. 127.0.0.1:6379> GEODIST drivers driver_001 "29.0180,41.0112" // Şoför ile yolcu arası exact mesafe hesaplama. # Not: GEODIST member'lar arasında çalışır, coordinate ile direkt mesafe için GEORADIUS kullanın. # Şoför location update (real-time tracking): 127.0.0.1:6379> GEOADD drivers 29.0190 41.0125 "driver_001" // driver_001 yeni pozisyona hareket etti. (integer) 0 // Mevcut member güncellendi. 127.0.0.1:6379> GEOPOS drivers driver_001 // Güncel pozisyon kontrol. 1) 1) "29.01899814605712890" 2) "41.01249994710670746"
markdown127.0.0.1:6379> GEOADD restaurants 29.0104 41.0082 "Pizza_Palace" 29.0234 41.0156 "Burger_King" 29.0067 40.9923 "Sushi_Bar" // Restaurant lokasyonları. (integer) 3 127.0.0.1:6379> GEOADD customers 29.0180 41.0112 "customer_456" // Müşteri lokasyonu. (integer) 1 127.0.0.1:6379> GEORADIUS restaurants 29.0180 41.0112 5 km WITHDIST ASC // Müşteriye 5km çevresindeki restoranlar. 1) 1) "Pizza_Palace" 2) "0.8547" // En yakın: Pizza Palace (0.85 km). 2) 1) "Burger_King" 2) "1.2334" // Burger King (1.23 km). 3) 1) "Sushi_Bar" 2) "2.1891" // Sushi Bar (2.19 km). 127.0.0.1:6379> GEOADD couriers 29.0150 41.0095 "courier_A" 29.0200 41.0140 "courier_B" // Kurye lokasyonları. (integer) 2 # Pizza Palace'den teslimat için en yakın kurye: 127.0.0.1:6379> GEORADIUSBYMEMBER couriers "29.0104,41.0082" 10 km WITHDIST ASC COUNT 1 # Not: Coordinate-based query için GEORADIUS kullanmak gerekir. 127.0.0.1:6379> GEORADIUS couriers 29.0104 41.0082 10 km WITHDIST ASC COUNT 1 // Pizza Palace'ye en yakın kurye. 1) 1) "courier_A" 2) "0.6234" // courier_A en yakın (0.62 km). # Delivery route optimization: 127.0.0.1:6379> GEODIST restaurants Pizza_Palace "29.0150,41.0095" // Restaurant'tan kurye'ye mesafe. # Coordinate-based distance için alternative yaklaşım gerekir. 127.0.0.1:6379> GEOADD temp_location 29.0150 41.0095 "courier_A_pos" // Geçici location oluştur. 127.0.0.1:6379> GEODIST restaurants Pizza_Palace "courier_A_pos" // Şimdi mesafe hesaplanabilir.
markdown127.0.0.1:6379> GEOADD hospitals 29.0104 41.0082 "City_Hospital" 29.0534 41.0256 "General_Hospital" 29.0367 40.9823 "Emergency_Center" // Hastane lokasyonları. (integer) 3 127.0.0.1:6379> GEOADD police_stations 29.0184 41.0142 "Police_Station_1" 29.0067 40.9923 "Police_Station_2" // Polis karakolu lokasyonları. (integer) 2 127.0.0.1:6379> GEOADD fire_stations 29.0204 41.0172 "Fire_Station_A" 29.0344 41.0089 "Fire_Station_B" // İtfaiye lokasyonları. (integer) 2 # Acil durum lokasyonu: 127.0.0.1:6379> GEOADD emergency_call 29.0180 41.0112 "emergency_location" (integer) 1 # En yakın hastane: 127.0.0.1:6379> GEORADIUSBYMEMBER hospitals "29.0180,41.0112" 50 km WITHDIST ASC COUNT 1 # Coordinate-based query için: 127.0.0.1:6379> GEORADIUS hospitals 29.0180 41.0112 50 km WITHDIST ASC COUNT 1 1) 1) "City_Hospital" 2) "0.8547" // En yakın hastane: 0.85 km. # En yakın polis karakolu: 127.0.0.1:6379> GEORADIUS police_stations 29.0180 41.0112 50 km WITHDIST ASC COUNT 1 1) 1) "Police_Station_1" 2) "0.3421" // En yakın polis: 0.34 km. # En yakın itfaiye: 127.0.0.1:6379> GEORADIUS fire_stations 29.0180 41.0112 50 km WITHDIST ASC COUNT 1 1) 1) "Fire_Station_A" 2) "0.6789" // En yakın itfaiye: 0.68 km. # Tüm emergency services overview: 127.0.0.1:6379> GEORADIUS hospitals 29.0180 41.0112 10 km WITHDIST COUNT 3 127.0.0.1:6379> GEORADIUS police_stations 29.0180 41.0112 10 km WITHDIST COUNT 3 127.0.0.1:6379> GEORADIUS fire_stations 29.0180 41.0112 10 km WITHDIST COUNT 3 # Response time estimation (distance-based): 127.0.0.1:6379> GEORADIUS hospitals 29.0180 41.0112 5 km WITHDIST ASC // 5km çevresindeki tüm hastaneler. 1) 1) "City_Hospital" 2) "0.8547" 2) 1) "Emergency_Center" 2) "3.2891" // Backup option.
markdown127.0.0.1:6379> GEOADD stores 29.0104 41.0082 "Store_Downtown" 29.0534 41.0256 "Store_Mall" 29.0367 40.9823 "Store_Suburbs" // Mağaza lokasyonları. (integer) 3 127.0.0.1:6379> GEOADD competitors 29.0184 41.0142 "Competitor_A" 29.0267 40.9923 "Competitor_B" // Rakip mağaza lokasyonları. (integer) 2 # Customer'ın en yakın mağaza bulması: 127.0.0.1:6379> GEORADIUS stores 29.0180 41.0112 25 km WITHDIST ASC 1) 1) "Store_Downtown" 2) "0.8547" // En yakın mağaza. 2) 1) "Store_Suburbs" 2) "3.2891" // İkinci seçenek. 3) 1) "Store_Mall" 2) "4.1234" // En uzak mağaza. # Competitive analysis - her mağazanın çevresindeki rakipler: 127.0.0.1:6379> GEORADIUSBYMEMBER stores Store_Downtown 5 km 1) "Store_Downtown" 127.0.0.1:6379> GEORADIUS competitors 29.0104 41.0082 5 km WITHDIST // Store_Downtown çevresindeki rakipler. 1) 1) "Competitor_A" 2) "0.9876" // Yakın rakip: 0.99 km. # Coverage area analysis: 127.0.0.1:6379> GEORADIUS stores 29.0250 41.0150 10 km // Belirli area'da coverage kontrol. 1) "Store_Downtown" 2) "Store_Mall" // Bu area'yı 2 mağaza cover ediyor. # Store density analysis: 127.0.0.1:6379> GEORADIUS stores 29.0200 41.0100 20 km COUNT 10 // 20km çevresindeki tüm mağazalar. 1) "Store_Downtown" 2) "Store_Suburbs" 3) "Store_Mall" // Toplam 3 mağaza. # Geohash-based regional analysis: 127.0.0.1:6379> GEOHASH stores Store_Downtown Store_Mall Store_Suburbs 1) "sxj7dy4y2k0" // Downtown geohash. 2) "sxj7fgbr8q0" // Mall geohash. 3) "sxj7dpp3st0" // Suburbs geohash. # Prefix analysis: sxj7d ile başlayanlar aynı genel bölgede
GEOADD
, GEOPOS
, GEODIST
, GEORADIUS
, GEORADIUSBYMEMBER
gibi temel komutları ve gerçek dünya senaryolarında Geo kullanımını detaylı örneklerle öğrendik.
Geo'nun geospatial indexing, proximity search, distance calculations ve spherical earth model özellikleri özellikle: