0
0
RedisConceptBeginner · 3 min read

What is Geospatial in Redis: Explanation and Examples

In Redis, geospatial refers to commands and data structures that store and query geographic locations like latitude and longitude. Redis lets you add, search, and calculate distances between points efficiently using GEOADD, GEORADIUS, and related commands.
⚙️

How It Works

Redis geospatial features work by storing geographic points as longitude and latitude coordinates inside a special sorted set. Each point has a name and a position on Earth.

Think of it like placing pins on a map. Redis keeps these pins organized so you can quickly find all pins near a certain location or calculate the distance between two pins.

Under the hood, Redis uses a geohash technique to encode locations into a format that allows fast searching and sorting by proximity.

💻

Example

This example shows how to add locations and find nearby places using Redis geospatial commands.

redis
GEOADD places 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"
GEORADIUS places 15 37 200 km WITHDIST
Output
1) "Palermo" 2) "Catania", 56.4413
🎯

When to Use

Use Redis geospatial features when you need to store and query location data quickly. It is great for apps like delivery services, ride-sharing, or finding nearby stores.

For example, a food delivery app can find restaurants within 5 km of a user’s location instantly. Or a social app can show nearby friends on a map.

Key Points

  • Redis geospatial stores locations as longitude and latitude in sorted sets.
  • Commands like GEOADD, GEORADIUS, and GEODIST help add, search, and measure distances.
  • It uses geohashing internally for fast queries.
  • Ideal for location-based apps needing quick proximity searches.

Key Takeaways

Redis geospatial stores and queries geographic points using longitude and latitude.
Use GEOADD to add locations and GEORADIUS to find nearby points.
It is perfect for apps needing fast location-based searches like delivery or social apps.
Redis uses geohashing internally for efficient spatial queries.
Geospatial commands return distances and nearby locations quickly.