Core dataMobility

Geospatial Search

Find the nearest drivers, stores or devices in a radius or a box, with live positions updated every few seconds.

or box searches
Radius
units
km, mi, m, ft
position updates
Live
Step 1 of 4
Drivers report positions

Each update replaces the driver's previous position.

Example sessionplaying
# Drivers report positions
hotkv> GEOADD drivers:berlin 13.4050 52.5200 driver:17 13.3889 52.5170 driver:23
(integer) 0

An animated walkthrough with real HotKV commands and example replies. Click any step to jump to it.

The problem

Matching a rider to the nearest driver, or a customer to the closest store with stock, needs a fresh view of thousands of moving positions and an answer in milliseconds. A relational database with spatial indexes struggles with that many updates per second.

How HotKV handles it

Positions live in a geospatial index. Each driver updates their own position every few seconds with GEOADD, and GEOSEARCH returns everyone within a radius or a box, nearest first, with their distance. The same index answers store locator and delivery zone queries.

Step by step

What happens, command by command

  1. 01

    Drivers report positions

    Each update replaces the driver's previous position.

    GEOADD drivers:berlin 13.4050 52.5200 driver:17 13.3889 52.5170 driver:23
  2. 02

    A rider asks for a car

    Find the five nearest drivers within 3 km, nearest first.

    GEOSEARCH drivers:berlin FROMLONLAT 13.4000 52.5190 BYRADIUS 3 km ASC COUNT 5 WITHDIST
  3. 03

    Offer the ride

    Lock the driver so two riders cannot get the same car.

    SET offer:driver:17 rider:42 NX EX 15
  4. 04

    Distance to pickup

    Distance between two members of the index.

    GEODIST drivers:berlin driver:17 driver:23 km
Where it fits

Real-world scenarios

Ride-hailing and taxis

Nearby drivers are found in milliseconds, and an offer lock stops double booking.

Delivery platforms

Couriers near a restaurant are matched as orders become ready.

Store locators

Customers see the closest stores within a box around the map view.

Built in

What you get

Live positions

GEOADD adds or updates members by longitude and latitude.

GEOADD

Radius and box search

Around a point or a member, sorted by distance, limited by count.

GEOSEARCHGEOSEARCHSTORE

Distances and positions

Between members, in the unit you choose.

GEODISTGEOPOS

Plain sorted sets underneath

Remove members and count them with the sorted set commands you know.

ZREMZCARD

Common questions

How do I remove a driver who goes offline?

A geospatial index is a sorted set, so ZREM removes the member.

Can I search in a rectangle?

Yes. GEOSEARCH BYBOX takes a width and height around a point or a member.

Which units are supported?

Meters, kilometers, feet and miles.

Related use cases

Try it on your own workload

HotKV speaks the Redis protocol, so you can point an existing client at it and run these same commands.