Redis for Maps and Locations: Understanding Geospatial Indexing



This content originally appeared on DEV Community and was authored by Rijul Rajesh

If you’ve ever used an app to find the nearest ATM, track a delivery, or hail a ride, you’re benefiting from something called geospatial indexing.

But how do systems like Redis handle that kind of location-based data so efficiently? That’s where Geospatial Indexes come into play.

What Are Geospatial Indexes?

Geospatial indexes allow databases to store and query geographic data like longitude and latitude. In Redis, this capability is built right into the database—no external plugin or GIS system required.

With geospatial indexes, you can:

  • Store the location of items on a map
  • Search for places nearby a given point
  • Calculate distances between two coordinates

This makes it useful for real-time applications like food delivery apps, fleet tracking, store locators, and more.

How Redis Handles Geospatial Data

Redis uses a data structure called a Sorted Set (ZSET) to manage geospatial data.

Each item in the set is a location. Redis internally converts the longitude and latitude into a unique number using something called geohashing—a technique that encodes geographic coordinates into a single value.

1. GEOADD: Add Locations

To store a location in Redis, you use GEOADD.

GEOADD stores:locations 77.5946 12.9716 "Bangalore"
GEOADD stores:locations 72.8777 19.0760 "Mumbai"

This adds two cities with their longitude and latitude.

2. GEOSEARCH: Find Nearby Places

To search for nearby locations, use GEOSEARCH.

GEOSEARCH stores:locations
  FROMLONLAT 77.5946 12.9716
  BYRADIUS 500 km

This finds all stored locations within 500 km of Bangalore’s coordinates.

You can also sort results by distance or limit the number of results—great for building fast, responsive applications.

3. GEODIST: Calculate Distance

If you just want to know how far two locations are from each other:

GEODIST stores:locations Bangalore Mumbai km

Redis returns the distance in the unit you specify—meters, kilometers, miles, or feet.

When Should You Use Redis Geospatial Indexes?

Redis geospatial support is lightweight and fast—ideal when you need:

  • Fast lookups for nearby locations
  • Simple location storage and retrieval
  • Real-time geospatial querying at scale

It works especially well in:

  • Food and package delivery systems
  • Store or dealer locators
  • Ride-hailing and cab tracking apps
  • Games that use map-based movement

A Few Things to Keep in Mind

  • Redis geospatial commands don’t support complex geofencing or polygons.
  • Precision depends on the geohashing method and the size of your search area.
  • It’s not meant to replace full-featured GIS systems like PostGIS, but it’s great for many real-time use cases.

Wrapping up

Geospatial indexes in Redis are a powerful tool that can turn your application into a location-aware service with just a few commands. Whether you’re building a location-based search or just need to calculate distances, Redis makes it simple and blazing fast.

If you’re a software developer who enjoys exploring different technologies and techniques like this one, check out LiveAPI. It’s a super-convenient tool that lets you generate interactive API docs instantly.

LiveAPI helps you discover, understand and use APIs in large tech infrastructures with ease!

So, if you’re working with a codebase that lacks documentation, just use LiveAPI to generate it and save time!

You can instantly try it out here! 🚀


This content originally appeared on DEV Community and was authored by Rijul Rajesh