GEOADD key longitude latitude member [longitude latitude member …]

    Time complexity: O(log(N)) for each item added, where N is the number of elements in the sorted set.

    Adds the specified geospatial items (latitude, longitude, name) to the specified key. Data is stored into the key as a sorted set, in a way that makes it possible to later retrieve items using a query by radius with the or GEORADIUSBYMEMBER commands.

    The command takes arguments in the standard format x,y so the longitude must be specified before the latitude. There are limits to the coordinates that can be indexed: areas very near to the poles are not indexable. The exact limits, as specified by EPSG:900913 / EPSG:3785 / OSGEO:41001 are the following:

    • Valid longitudes are from -180 to 180 degrees.

    Note: there is no GEODEL command because you can use in order to remove elements. The Geo index structure is just a sorted set.

    The way the sorted set is populated is using a technique called Geohash. Latitude and Longitude bits are interleaved in order to form an unique 52 bit integer. We know that a sorted set double score can represent a 52 bit integer without losing precision.

    This format allows for radius querying by checking the 1+8 areas needed to cover the whole radius, and discarding elements outside the radius. The areas are checked by calculating the range of the box covered removing enough bits from the less significant part of the sorted set score, and computing the score range to query in the sorted set for each area.

    , specifically:

    • The number of elements added to the sorted set, not including elements already existing for which the score was updated.

    redis> GEOADD Sicily 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"

    redis> GEODIST Sicily Palermo Catania

    redis> GEORADIUS Sicily 15 37 200 km

    redis>