GEOADD key [NX | XX] [CH] longitude latitude member [longitude latitude member ...]
Time complexity: O(log(N)) for each item added, where N is the number of elements in the geospatial index represented by the sorted set.
ACL categories: @write, @geo, @slow
Adds the specified geospatial items (longitude, latitude, name) to the specified key.
Data is stored into the key as a sorted set, in a way that makes it possible to query the items with the
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 index-able.
GEOADD also provides the following options:
XX-- Only update elements that already exist. Never add elements.
NX-- Don't update already existing elements. Always add new elements.
CH-- Modify the return value from the number of new elements added, to the total number of elements changed (
CHis an abbreviation of changed). Changed elements are new elements added and elements already existing for which the coordinates were updated. So elements specified in the command line having the same score as they had in the past are not counted. Normally, the return value of
GEOADDonly counts the number of new elements added.
NX options are mutually exclusive.
Integer reply, specifically:
- When used without optional arguments, the number of elements added to the sorted set (excluding score updates).
- If the
CHoption is specified, the number of elements that were changed (added or updated).
dragonfly> GEOADD Sicily 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"
dragonfly> GEODIST Sicily Palermo Catania